Skip to content

Commit

Permalink
fix: use compound variants & export VisuallyHidden (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
smeijer authored Nov 21, 2024
1 parent 9009ed8 commit 6d94104
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-bikes-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@darkmagic/react': minor
---

export VisuallyHidden
13 changes: 10 additions & 3 deletions packages/react/src/components/drawer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Basic.args = {
title: 'Drawer Title',
description: 'Drawer Description',
content: 'Drawer Content',
variant: 'inline',
};

export const Overlay: ComponentStoryFn<any> = (args) => (
Expand Down Expand Up @@ -95,7 +96,12 @@ ControlledOpen.args = {

export const WithActions: ComponentStoryFn<any> = (args) => (
<Tabs defaultValue="2">
<Drawer variant={args.variant} onRequestClose={action('onRequestClose')}>
<Drawer
align={args.align}
variant={args.variant}
onClickOutside={action('onClickOutside')}
onRequestClose={action('onRequestClose')}
>
<Drawer.Title>{args.title}</Drawer.Title>
<Drawer.Description>{args.description}</Drawer.Description>

Expand Down Expand Up @@ -136,7 +142,8 @@ WithActions.args = {
title: 'Drawer Title',
description: 'some description',
content: 'Content',
variant: 'inline',
variant: 'overlay',
align: 'right',
};

export const WithTabs: ComponentStoryFn<any> = (args) => (
Expand Down Expand Up @@ -202,7 +209,7 @@ WithCode.args = {
};

export const EmptyShell: ComponentStoryFn<any> = (args) => (
<Drawer variant={args.variant}>
<Drawer variant={args.variant} open onClickOutside={action('click outside')}>
<div>custom child content</div>
</Drawer>
);
Expand Down
31 changes: 22 additions & 9 deletions packages/react/src/components/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,14 @@ const StyledDialogContent = styled(DialogPrimitive.Content, {

variants: {
align: {
right: {
right: '0',
animationName: `${slideLeftAndFade}`,
},
left: {
left: '0',
animationName: `${slideRightAndFade}`,
},
left: {},
right: {},
},

variant: {
overlay: {
position: 'fixed',
top: '0',
right: '0',
zIndex: 1,
animationDuration: '400ms',
animationTimingFunction: 'cubic-bezier(0.16, 1, 0.3, 1)',
Expand All @@ -64,6 +58,25 @@ const StyledDialogContent = styled(DialogPrimitive.Content, {
},
},
},

compoundVariants: [
{
align: 'left',
variant: 'overlay',
css: {
left: '0',
animationName: `${slideRightAndFade}`,
},
},
{
align: 'right',
variant: 'overlay',
css: {
right: '0',
animationName: `${slideLeftAndFade}`,
},
},
],
});

type StyledDialogContentProps = ComponentProps<typeof StyledDialogContent>;
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ export * from './hooks/use-mousetrap.js';
export * from './hooks/use-resize-observer.js';
export * from './lib/dom.js';
export * from './lib/stitches.js';
export { VisuallyHidden } from '@radix-ui/react-visually-hidden';

0 comments on commit 6d94104

Please sign in to comment.