Skip to content

Commit

Permalink
Add LargeDialog component and story
Browse files Browse the repository at this point in the history
  • Loading branch information
alebedev committed Oct 21, 2024
1 parent 2b26d2e commit ff8ab35
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@vanilla-extract/recipes": "0.5.5",
"@vanilla-extract/sprinkles": "1.6.3",
"clsx": "2.1.1",
"framer-motion": "11.1.7",
"react": "18.3.1",
"react-dom": "18.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/Dialog/Dialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
},
} as Meta<typeof Dialog>

export const Default: StoryFn<typeof Dialog> = () => {
export const Base: StoryFn<typeof Dialog> = () => {
const [open, setOpen] = useState(false)

return (
Expand Down
37 changes: 37 additions & 0 deletions packages/ui/src/components/Dialog/LargeDialog.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { style } from '@vanilla-extract/css'
import { breakpoints, minWidth, tokens } from '../../theme'

export const closeButton = style({
position: 'absolute',
right: tokens.space.md,
top: tokens.space.md,
})

export const content = style({
display: 'flex',
width: '100%',
})

export const card = style({
position: 'relative',
marginBlock: 'auto',
marginInline: 'auto',
width: '100%',

'@media': {
// This is unusual, we normally target min-width instead
[`screen and (max-width: ${breakpoints.xs}px)`]: {
boxShadow: 'none',
borderRadius: 0,
border: 'none',
minHeight: '100vh',
},
[minWidth.sm]: {
maxWidth: '80%',
},
},
})

export const heading = style({
marginRight: tokens.space.lg,
})
38 changes: 38 additions & 0 deletions packages/ui/src/components/Dialog/LargeDialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { type Meta, type StoryFn } from '@storybook/react'
import { yStack } from '../../patterns'
import { Button } from '../Button/Button'
import { Text } from '../Text/Text'
import { LargeDialog } from './LargeDialog'

export default {
title: 'Dialog',
parameters: {
backgrounds: {
default: 'gray100',
},
layout: 'centered',
},
} as Meta<unknown>

export const Large: StoryFn = () => {
return (
<div>
<LargeDialog.Root>
<div className={yStack({ gap: 'md' })}>
Button opens dialog
<LargeDialog.Trigger asChild>
<Button variant="secondary">Click me</Button>
</LargeDialog.Trigger>
</div>

<LargeDialog.Content>
<LargeDialog.Header>Hello_world!</LargeDialog.Header>
<Text>
Lorem ipsum dolor sit amet, florrum plorrum klufs grufs glufs. Nufs ep trop. Nufs ep
trop. Lorem ipsum dolor sit amet, florrum plorrum.
</Text>
</LargeDialog.Content>
</LargeDialog.Root>
</div>
)
}
65 changes: 65 additions & 0 deletions packages/ui/src/components/Dialog/LargeDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { clsx } from 'clsx'
import { motion } from 'framer-motion'
import { type ComponentProps } from 'react'
import { CrossIcon } from '../../icons'
import { framerTransitions } from '../../theme'
import { IconButton } from '../Button/IconButton'
import { Card } from '../Card/Card'
import { Heading } from '../Heading/Heading'
import * as Dialog from './Dialog'
import { card, closeButton, content, heading } from './LargeDialog.css'

// Large modal, full-screen on mobile
function Content({
children,
centerContent = true,
className,
...forwardedProps
}: ComponentProps<typeof Dialog.Content>) {
return (
<Dialog.Content
centerContent={centerContent}
className={clsx(content, className)}
{...forwardedProps}
>
<MotionCard
className={card}
initial={{ opacity: 0, y: '2vh' }}
animate={{ opacity: 1, y: 0 }}
transition={{
...framerTransitions.easeInOutCubic,
duration: framerTransitions.defaultDuration,
}}
>
<Dialog.Close asChild>
<IconButton Icon={<CrossIcon />} className={closeButton} />
</Dialog.Close>
{children}
</MotionCard>
</Dialog.Content>
)
}

const MotionCard = motion(Card.Root)

function Header({ children, className, ...forwardedProps }: ComponentProps<typeof Heading>) {
return (
<Dialog.Title asChild>
<Heading
as="h2"
variant="standard.24"
className={clsx(heading, className)}
{...forwardedProps}
>
{children}
</Heading>
</Dialog.Title>
)
}

export const LargeDialog = {
Root: Dialog.Root,
Trigger: Dialog.Trigger,
Content,
Header,
}
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25464,6 +25464,7 @@ __metadata:
eslint-config-prettier: "npm:9.1.0"
eslint-plugin-jest: "npm:28.8.3"
eslint-plugin-testing-library: "npm:6.3.0"
framer-motion: "npm:11.1.7"
jest: "npm:29.7.0"
jest-environment-jsdom: "npm:29.7.0"
react: "npm:18.3.1"
Expand Down

0 comments on commit ff8ab35

Please sign in to comment.