Skip to main content

v0.135.0

· 4 min read
Anita

Csx multi-token resolve

You can now resolve multiple tokens at once. This is useful to compound properties like margin, padding, box-shadow, border, etc. For example:

const container = csx({
margin: '$space-10 $space-20',
padding: '$space-10',
border: '4px dotted $blue40',
})

Tokens

Space

Codemod: npx @vtex/admin-ui-codemod space-tokens-review ./

The current tokens are:

tokenvalue
space-00rem
space-050.125rem
space-10.25rem
space-20.5rem
space-30.75rem
space-41rem
space-51.25rem
space-61.5rem
space-71.75rem
space-82rem
space-102.5rem
space-123rem
space-164rem
space-205rem
space-246rem
space-287rem
space-328rem

Multi-token csx resolve

Border Radius

Codemod: npx @vtex/admin-ui-codemod radius-tokens-review ./

tokenvalue
none0
base0.25rem
pill100%

zIndices

Created tokens for elevation:

tokenvalue
z-10
z-2100
z-3200
z-4300
z-5400
z-6500
z-7600
z-8700
z-9800
z-10900

useCollapsible

Implemented the discussion: https://github.com/vtex/admin-ui/discussions/438#discussion-4527541.

Before

We use the collapsible component with a state hook.

import {
useCollapsibleState,
Collapsible,
CollapsibleHeader,
CollapsibleContent,
} from '@vtex/admin-ui'

function Example() {
const state = useCollapsibleState()

return (
<Collapsible state={state}>
<CollapsibleHeader label="your label" />
<CollapsibleContent> your content </CollapsibleContent>
</Collapsible>
)
}

After

Replace the collpasible with the useCollapsible hook, which returns the props (using the prop-getters pattern).

function Example() {
const { getToggleProps, getCollapseProps } = useCollapsible()

return (
<Card>
<CardHeader {...getToggleProps()}>
<CardTitle>Your title</CardTitle>
</CardHeader>
<CardContent {...getCollapseProps()}>Your content</CardContent>
</Card>
)
}

Abstracting

The developer can abstract the component into a stateful accordion, or whatever makes sense for the application.

// accordion.tsx
interface Props {
title: ReactNode
content: ReactNode
}

export function Accordion (props: Props) {
const { title, content } = props
const { getToggleProps, getCollapseProps } = useCollapsible()

return (
<Card>
<CardHeader {...getToggleProps()}>
<CardTitle>{title}</CardTitle>
</CardHeader>
<CardContent {...getCollapseProps()}>{content}</CardContent>
</Card>
)
}

// usage.tsx
import { Accordion } from './accordion.tsx'

<Accordion title="Your title" content="your content" />

The Modal component was reviewed to the latest design specs. The API also changed a composable and flexible approach, allowing users to take advantage of our components to create custom, but consistent, Modals.

Before

function ModalDialog() {
const modal = useModalState()

return (
<Box>
<ModalDisclosure state={modal}>
<Button>Publish</Button>
</ModalDisclosure>
<Modal aria-label="Publish modal" state={modal} size="small">
<ModalHeader title="Publish content" />
<ModalContent>
<Text>
Are you sure you want to publish this content? This action cannot be
undone.
</Text>
</ModalContent>
<ModalFooter>
<Button variant="secondary">Cancel</Button>
<Button>Confirm</Button>
</ModalFooter>
</Modal>
</Box>
)
}

After

  • ModalDisclosure is deprecated. You can use any button (or effect) to act as disclosure.
  • ModalHeader is composed of the new ModalTitle and ModalDismiss components.
function ModalDialog() {
const modal = useModalState()

return (
<Box>
<Button onClick={() => modal.open()}>Publish</Button>
<Modal aria-label="Publish modal" state={modal} size="small">
<ModalHeader>
<ModalTitle>Publish content</ModalTitle>
<ModalDismiss />
</ModalHeader>
<ModalContent>
<Text>
Are you sure you want to publish this content? This action cannot be
undone.
</Text>
</ModalContent>
<ModalFooter>
<ModalButton variant="secondary">Cancel</ModalButton>
<ModalButton>Confirm</ModalButton>
</ModalFooter>
</Modal>
</Box>
)
}

Now you are able to customize the Search placeholder when necessary by using the placeholder property.

<Search value={value} onChange={onChange} placeholder="Search for..." />