Hooks
useSystemβ
Custom hook that returns functionalities from admin-ui that adds different types of customization. Must be used under a <ThemeProvider>
context.
You can check some examples and detailed info about each of these functionalities in the sections below.
cnβ
Function that transforms a valid StyleObject into a className
. It is used to style native JSX elements and support integrations with other libraries while being consistent.
Exampleβ
Do's:β
- β Use it with native elements:
function Example() {
const { cn } = useSystem()
return (
<nav
className={cn({
bg: 'muted',
'button + button': { marginLeft: 2 },
})}
/>
)
}
- β Use it with custom libraries that accepts a className:
function Example() {
const { cn } = useSystem()
return (
<Input
className={cn({
borderColor: 'muted',
':hover': {
borderColor: 'base',
},
})}
/>
)
}
Dont's:β
- π« Use it within Primitives:
// π« Wrong
<Box
csx={cn({
bg: 'muted',
'button + button': { marginLeft: 2 },
})}
/>
// β
Correct
<Box
csx={{
bg: 'muted',
'button + button': { marginLeft: 2 },
}}
/>
- π« Use it within SystemComponents:
// π« Wrong
<Button
csx={cn({
bg: 'muted',
'button + button': { marginLeft: 2 },
})}
/>
// β
Correct
<Button
csx={{
bg: 'muted',
'button + button': { marginLeft: 2 },
}}
/>
cxβ
A function that combines two or more class names generated by the cn
function or even native ones. This is an emotionβs version of the popular classnames library. The key advantage of cx
is that it detects emotion-generated class names ensuring styles are overwritten in the correct order.
Combining class namesβ
Conditional class namesβ
keyframesβ
Generates a unique animation-name that can be used to animate elements with CSS animations
.
Exampleβ
useResponsiveValueβ
Custom hook which returns the value for the current breakpoint from the provided responsive values object. It also responds to the window resizing and returning the appropriate value for the new window size.
Usageβ
useMediaQueryβ
This is a CSS media query hook for React. It listens for matches to a CSS media query. It allows the rendering of components based on whether the query matches or not.
import { useMediaQuery } from '@vtex/admin-ui'
Usageβ
Parameterβ
type | required | description |
---|---|---|
string, string[] | β | A unique media query or an array of queries |
Return Valueβ
The useMediaQuery
hook returns an array of booleans, indicating whether the given query matches or queries match.
type | description |
---|---|
boolean[] | An array of matches for each query passed |