generated from Dhaiwat10/react-library-starter
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
234 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { styled, css } from '../theme/stitches.config'; | ||
|
||
export const overlayStyles = css({ | ||
backgroundColor: 'rgba(0, 0, 0, .15)', | ||
}); | ||
|
||
export const Overlay = styled('div', overlayStyles); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
packages/components/src/elements/DropdownMenu/DropdownMenu.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import React from 'react'; | ||
|
||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
import { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Sheet, SheetTrigger, SheetContent } from './Sheet'; | ||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
import { Button } from '../Button'; | ||
|
||
export default { | ||
title: 'Elements/Sheet', | ||
component: Sheet, | ||
argTypes: {}, | ||
} as ComponentMeta<typeof Sheet>; | ||
|
||
const Template: ComponentStory<typeof Sheet> = (args) => ( | ||
<Sheet {...args}> | ||
<SheetTrigger asChild> | ||
<Button>Open Left</Button> | ||
</SheetTrigger> | ||
<SheetContent side="left">content here</SheetContent> | ||
</Sheet> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
children: 'Sheet', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { render } from '@testing-library/react'; | ||
|
||
import { Sheet } from './Sheet'; | ||
|
||
describe('Sheet', () => { | ||
it('renders without throwing', () => { | ||
const { container } = render(<Sheet />); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import React from 'react'; | ||
import { | ||
styled, | ||
keyframes, | ||
VariantProps, | ||
CSS, | ||
} from '../../theme/stitches.config'; | ||
import * as DialogPrimitive from '@radix-ui/react-dialog'; | ||
import { Cross1Icon } from '@radix-ui/react-icons'; | ||
import { overlayStyles } from '../../common/Overlay'; | ||
import { Button } from '../Button'; | ||
|
||
const Sheet = DialogPrimitive.Root; | ||
const SheetTrigger = DialogPrimitive.Trigger; | ||
|
||
const fadeIn = keyframes({ | ||
from: { opacity: '0' }, | ||
to: { opacity: '1' }, | ||
}); | ||
|
||
const fadeOut = keyframes({ | ||
from: { opacity: '1' }, | ||
to: { opacity: '0' }, | ||
}); | ||
|
||
const StyledOverlay = styled(DialogPrimitive.Overlay, overlayStyles, { | ||
position: 'fixed', | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
left: 0, | ||
|
||
'&[data-state="open"]': { | ||
animation: `${fadeIn} 150ms cubic-bezier(0.22, 1, 0.36, 1)`, | ||
}, | ||
|
||
'&[data-state="closed"]': { | ||
animation: `${fadeOut} 150ms cubic-bezier(0.22, 1, 0.36, 1)`, | ||
}, | ||
}); | ||
|
||
const slideIn = keyframes({ | ||
from: { transform: '$$transformValue' }, | ||
to: { transform: 'translate3d(0,0,0)' }, | ||
}); | ||
|
||
const slideOut = keyframes({ | ||
from: { transform: 'translate3d(0,0,0)' }, | ||
to: { transform: '$$transformValue' }, | ||
}); | ||
|
||
const StyledContent = styled(DialogPrimitive.Content, { | ||
backgroundColor: '$panel', | ||
boxShadow: | ||
'$colors$shadowLight 0 0 38px -10px, $colors$shadowDark 0 0 35px -15px', | ||
position: 'fixed', | ||
top: 0, | ||
bottom: 0, | ||
width: 250, | ||
|
||
// Among other things, prevents text alignment inconsistencies when dialog can't be centered in the viewport evenly. | ||
// Affects animated and non-animated dialogs alike. | ||
willChange: 'transform', | ||
|
||
// '&:focus': { | ||
// outline: 'none', | ||
// }, | ||
|
||
'&[data-state="open"]': { | ||
animation: `${slideIn} 150ms cubic-bezier(0.22, 1, 0.36, 1)`, | ||
}, | ||
|
||
'&[data-state="closed"]': { | ||
animation: `${slideOut} 150ms cubic-bezier(0.22, 1, 0.36, 1)`, | ||
}, | ||
|
||
variants: { | ||
side: { | ||
top: { | ||
$$transformValue: 'translate3d(0,-100%,0)', | ||
width: '100%', | ||
height: 300, | ||
bottom: 'auto', | ||
}, | ||
right: { | ||
$$transformValue: 'translate3d(100%,0,0)', | ||
right: 0, | ||
}, | ||
bottom: { | ||
$$transformValue: 'translate3d(0,100%,0)', | ||
width: '100%', | ||
height: 300, | ||
bottom: 0, | ||
top: 'auto', | ||
}, | ||
left: { | ||
$$transformValue: 'translate3d(-100%,0,0)', | ||
left: 0, | ||
}, | ||
}, | ||
}, | ||
|
||
defaultVariants: { | ||
side: 'right', | ||
}, | ||
}); | ||
|
||
const StyledCloseButton = styled(DialogPrimitive.Close, { | ||
position: 'absolute', | ||
top: '$2', | ||
right: '$2', | ||
}); | ||
|
||
type SheetContentVariants = VariantProps<typeof StyledContent>; | ||
type DialogContentPrimitiveProps = React.ComponentProps< | ||
typeof DialogPrimitive.Content | ||
>; | ||
type SheetContentProps = DialogContentPrimitiveProps & | ||
SheetContentVariants & { css?: CSS }; | ||
|
||
const SheetContent = React.forwardRef< | ||
React.ElementRef<typeof StyledContent>, | ||
SheetContentProps | ||
>(({ children, ...props }, forwardedRef) => ( | ||
<DialogPrimitive.Portal> | ||
<StyledOverlay /> | ||
<StyledContent {...props} ref={forwardedRef}> | ||
{children} | ||
<StyledCloseButton asChild> | ||
<Button> | ||
<Cross1Icon /> | ||
</Button> | ||
</StyledCloseButton> | ||
</StyledContent> | ||
</DialogPrimitive.Portal> | ||
)); | ||
SheetContent.displayName = 'SheetContent'; | ||
|
||
const SheetClose = DialogPrimitive.Close; | ||
const SheetTitle = DialogPrimitive.Title; | ||
const SheetDescription = DialogPrimitive.Description; | ||
|
||
export { | ||
Sheet, | ||
SheetTrigger, | ||
SheetContent, | ||
SheetClose, | ||
SheetTitle, | ||
SheetDescription, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Sheet'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.