Skip to content

Commit

Permalink
feat(dialog): add size variant (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILLIPS71 authored May 7, 2024
1 parent f3b79c6 commit e602926
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/components/dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ type ComponentType = <TElement extends React.ElementType = typeof __ELEMENT_TYPE
const Component: ComponentType = <TElement extends React.ElementType = typeof __ELEMENT_TYPE__>(
props: ComponentProps<TElement>
) => {
const { as, children, className, blur, placement, ...rest } = props
const { as, children, className, size, blur, placement, ...rest } = props

const Element = as ?? DialogTrigger

const context = useDialog({ blur, placement })
const context = useDialog({ size, blur, placement })

const component = React.useMemo<Omit<DialogTriggerProps, 'children'>>(
() => ({
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/dialog/use-dialog.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export type UseDialogProps = DialogVariantProps
export type UseDialogReturn = ReturnType<typeof useDialog>

export const useDialog = (props: UseDialogProps) => {
const { blur, placement } = props
const { size, blur, placement } = props

const slots = React.useMemo(() => dialog({ blur, placement }), [blur, placement])
const slots = React.useMemo(() => dialog({ size, blur, placement }), [size, blur, placement])

return {
slots,
Expand Down
14 changes: 13 additions & 1 deletion packages/theme/src/components/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ export const dialog = tv({
slots: {
dialog: [],
overlay: ['flex', 'fixed inset-0 z-50', 'bg-black/50', 'min-h-full', 'overflow-y-auto', 'p-3'],
modal: ['w-full max-w-2xl', 'overflow-hidden'],
modal: ['w-full', 'overflow-hidden'],
content: ['relative', 'outline-none'],
},
variants: {
size: {
sm: {
modal: ['max-w-2xl'],
},
md: {
modal: ['max-w-4xl'],
},
lg: {
modal: ['max-w-6xl'],
},
},
blur: {
true: {
overlay: ['backdrop-blur-sm'],
Expand All @@ -26,6 +37,7 @@ export const dialog = tv({
},
},
defaultVariants: {
size: 'md',
blur: false,
placement: 'center',
},
Expand Down

0 comments on commit e602926

Please sign in to comment.