@leitware/composables 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +387 -0
- package/dist/presets/brutalist.css +298 -0
- package/dist/presets/default.css +298 -0
- package/dist/presets/signal-pop.css +369 -0
- package/dist/styles.css +2 -0
- package/package.json +216 -0
- package/rules/composables.md +244 -0
- package/src/_internal/accordion.tsx +93 -0
- package/src/_internal/ai-elements/attachments.tsx +385 -0
- package/src/_internal/ai-elements/chain-of-thought.tsx +197 -0
- package/src/_internal/ai-elements/code-block.tsx +516 -0
- package/src/_internal/ai-elements/confirmation.tsx +150 -0
- package/src/_internal/ai-elements/conversation.tsx +148 -0
- package/src/_internal/ai-elements/inline-citation.tsx +248 -0
- package/src/_internal/ai-elements/message.tsx +292 -0
- package/src/_internal/ai-elements/plan.tsx +126 -0
- package/src/_internal/ai-elements/prompt-input.tsx +1285 -0
- package/src/_internal/ai-elements/reasoning.tsx +208 -0
- package/src/_internal/ai-elements/shimmer.tsx +72 -0
- package/src/_internal/ai-elements/sources.tsx +53 -0
- package/src/_internal/ai-elements/suggestion.tsx +48 -0
- package/src/_internal/ai-elements/task.tsx +64 -0
- package/src/_internal/ai-elements/tool.tsx +156 -0
- package/src/_internal/alert-dialog.tsx +159 -0
- package/src/_internal/alert.tsx +88 -0
- package/src/_internal/aspect-ratio.tsx +23 -0
- package/src/_internal/avatar.tsx +58 -0
- package/src/_internal/badge.tsx +60 -0
- package/src/_internal/breadcrumb.tsx +104 -0
- package/src/_internal/bubble.tsx +125 -0
- package/src/_internal/button-group.tsx +78 -0
- package/src/_internal/button.tsx +62 -0
- package/src/_internal/calendar.tsx +179 -0
- package/src/_internal/card.tsx +83 -0
- package/src/_internal/carousel.tsx +215 -0
- package/src/_internal/checkbox.tsx +26 -0
- package/src/_internal/code-block.tsx +53 -0
- package/src/_internal/collapsible.tsx +15 -0
- package/src/_internal/combobox.tsx +264 -0
- package/src/_internal/command.tsx +155 -0
- package/src/_internal/container.tsx +35 -0
- package/src/_internal/dialog.tsx +132 -0
- package/src/_internal/direction.tsx +12 -0
- package/src/_internal/divider.tsx +162 -0
- package/src/_internal/dropdown-menu.tsx +247 -0
- package/src/_internal/dropzone.tsx +481 -0
- package/src/_internal/empty.tsx +94 -0
- package/src/_internal/field.tsx +221 -0
- package/src/_internal/grid-overlay.tsx +48 -0
- package/src/_internal/grid.tsx +109 -0
- package/src/_internal/hover-card.tsx +47 -0
- package/src/_internal/icon.tsx +45 -0
- package/src/_internal/input-group.tsx +146 -0
- package/src/_internal/input.tsx +24 -0
- package/src/_internal/item.tsx +187 -0
- package/src/_internal/kbd.tsx +28 -0
- package/src/_internal/label.tsx +18 -0
- package/src/_internal/layout-bento.tsx +386 -0
- package/src/_internal/layout.tsx +174 -0
- package/src/_internal/marker.tsx +66 -0
- package/src/_internal/message.tsx +85 -0
- package/src/_internal/native-select.tsx +50 -0
- package/src/_internal/pagination.tsx +108 -0
- package/src/_internal/popover.tsx +83 -0
- package/src/_internal/progress.tsx +59 -0
- package/src/_internal/radio-group.tsx +36 -0
- package/src/_internal/resizable.tsx +44 -0
- package/src/_internal/scroll-area.tsx +48 -0
- package/src/_internal/select.tsx +187 -0
- package/src/_internal/separator.tsx +19 -0
- package/src/_internal/sheet.tsx +122 -0
- package/src/_internal/sidebar.tsx +687 -0
- package/src/_internal/skeleton.tsx +13 -0
- package/src/_internal/slider.tsx +60 -0
- package/src/_internal/sonner.tsx +51 -0
- package/src/_internal/spacer.tsx +42 -0
- package/src/_internal/spinner.tsx +16 -0
- package/src/_internal/stack.tsx +78 -0
- package/src/_internal/switch.tsx +31 -0
- package/src/_internal/table.tsx +84 -0
- package/src/_internal/tabs.tsx +74 -0
- package/src/_internal/textarea.tsx +19 -0
- package/src/_internal/toggle-group.tsx +99 -0
- package/src/_internal/toggle.tsx +42 -0
- package/src/_internal/tooltip.tsx +55 -0
- package/src/_internal/typography.tsx +129 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/hooks/use-numeric-input.ts +119 -0
- package/src/index.ts +443 -0
- package/src/lib/numeric-input.ts +88 -0
- package/src/lib/utils.ts +39 -0
- package/src/opinionated/accordion.tsx +92 -0
- package/src/opinionated/ai/attachments.tsx +27 -0
- package/src/opinionated/ai/chain-of-thought.tsx +16 -0
- package/src/opinionated/ai/code-block.tsx +22 -0
- package/src/opinionated/ai/confirmation.tsx +16 -0
- package/src/opinionated/ai/conversation.tsx +13 -0
- package/src/opinionated/ai/index.ts +15 -0
- package/src/opinionated/ai/inline-citation.tsx +30 -0
- package/src/opinionated/ai/message.tsx +26 -0
- package/src/opinionated/ai/plan.tsx +18 -0
- package/src/opinionated/ai/prompt-input.tsx +29 -0
- package/src/opinionated/ai/reasoning.tsx +9 -0
- package/src/opinionated/ai/shimmer.tsx +4 -0
- package/src/opinionated/ai/sources.tsx +10 -0
- package/src/opinionated/ai/suggestion.tsx +6 -0
- package/src/opinionated/ai/task.tsx +12 -0
- package/src/opinionated/ai/tool.tsx +14 -0
- package/src/opinionated/alert-dialog.tsx +143 -0
- package/src/opinionated/alert.tsx +99 -0
- package/src/opinionated/aspect-ratio.tsx +12 -0
- package/src/opinionated/avatar.tsx +59 -0
- package/src/opinionated/badge.tsx +33 -0
- package/src/opinionated/breadcrumb.tsx +99 -0
- package/src/opinionated/bubble.tsx +9 -0
- package/src/opinionated/button.tsx +59 -0
- package/src/opinionated/calendar.tsx +20 -0
- package/src/opinionated/card.tsx +83 -0
- package/src/opinionated/carousel.tsx +99 -0
- package/src/opinionated/checkbox.tsx +11 -0
- package/src/opinionated/code-block.tsx +12 -0
- package/src/opinionated/collapsible.tsx +123 -0
- package/src/opinionated/combobox.tsx +123 -0
- package/src/opinionated/container.tsx +12 -0
- package/src/opinionated/dialog.tsx +124 -0
- package/src/opinionated/direction.tsx +6 -0
- package/src/opinionated/divider.tsx +13 -0
- package/src/opinionated/dropdown-menu.tsx +131 -0
- package/src/opinionated/dropzone.tsx +39 -0
- package/src/opinionated/empty.tsx +191 -0
- package/src/opinionated/field.tsx +26 -0
- package/src/opinionated/form-calendar-popover.tsx +138 -0
- package/src/opinionated/form-checkbox.tsx +107 -0
- package/src/opinionated/form-combobox.tsx +181 -0
- package/src/opinionated/form-date-of-birth.tsx +193 -0
- package/src/opinionated/form-dropzone.tsx +126 -0
- package/src/opinionated/form-input-group.tsx +184 -0
- package/src/opinionated/form-input.tsx +118 -0
- package/src/opinionated/form-multi-combobox.tsx +213 -0
- package/src/opinionated/form-multi-dropzone.tsx +141 -0
- package/src/opinionated/form-radiogroup.tsx +116 -0
- package/src/opinionated/form-select.tsx +176 -0
- package/src/opinionated/form-slider.tsx +100 -0
- package/src/opinionated/form-switch.tsx +117 -0
- package/src/opinionated/form-textarea.tsx +79 -0
- package/src/opinionated/grid-overlay.tsx +11 -0
- package/src/opinionated/grid.tsx +14 -0
- package/src/opinionated/hover-card.tsx +59 -0
- package/src/opinionated/icon.tsx +14 -0
- package/src/opinionated/input-group.tsx +20 -0
- package/src/opinionated/input.tsx +11 -0
- package/src/opinionated/item.tsx +182 -0
- package/src/opinionated/kbd.tsx +16 -0
- package/src/opinionated/label.tsx +11 -0
- package/src/opinionated/layout-bento.tsx +29 -0
- package/src/opinionated/layout.tsx +26 -0
- package/src/opinionated/list.tsx +94 -0
- package/src/opinionated/marker.tsx +7 -0
- package/src/opinionated/message.tsx +8 -0
- package/src/opinionated/native-select.tsx +51 -0
- package/src/opinionated/pagination.tsx +204 -0
- package/src/opinionated/popover.tsx +68 -0
- package/src/opinionated/progress.tsx +48 -0
- package/src/opinionated/radio-group.tsx +13 -0
- package/src/opinionated/resizable.tsx +2 -0
- package/src/opinionated/scroll-area.tsx +82 -0
- package/src/opinionated/select.tsx +101 -0
- package/src/opinionated/separator.tsx +11 -0
- package/src/opinionated/sheet.tsx +120 -0
- package/src/opinionated/sidebar.tsx +68 -0
- package/src/opinionated/skeleton.tsx +246 -0
- package/src/opinionated/slider.tsx +11 -0
- package/src/opinionated/sonner.tsx +15 -0
- package/src/opinionated/spacer.tsx +11 -0
- package/src/opinionated/stack.tsx +18 -0
- package/src/opinionated/switch.tsx +11 -0
- package/src/opinionated/table.tsx +11 -0
- package/src/opinionated/tabs.tsx +68 -0
- package/src/opinionated/textarea.tsx +11 -0
- package/src/opinionated/theme-injector.tsx +31 -0
- package/src/opinionated/toggle-group.tsx +63 -0
- package/src/opinionated/toggle.tsx +75 -0
- package/src/opinionated/token-config-panel/color-editor.tsx +85 -0
- package/src/opinionated/token-config-panel/helpers.ts +31 -0
- package/src/opinionated/token-config-panel/index.tsx +398 -0
- package/src/opinionated/token-config-panel/json-import-export.tsx +89 -0
- package/src/opinionated/token-config-panel/preset-manager.ts +31 -0
- package/src/opinionated/token-config-panel/presets-data.ts +23 -0
- package/src/opinionated/token-config-panel/spacing-editor.tsx +325 -0
- package/src/opinionated/token-config-panel/types.ts +39 -0
- package/src/opinionated/token-config-panel/typography-editor.tsx +145 -0
- package/src/opinionated/tooltip.tsx +62 -0
- package/src/opinionated/typography.tsx +7 -0
- package/src/scripts/lint-no-arbitrary.ts +155 -0
- package/src/styles/composable.css +68 -0
- package/src/styles/presets/brutalist.css +298 -0
- package/src/styles/presets/default.css +298 -0
- package/src/styles/presets/signal-pop.css +369 -0
- package/src/styles/presets-data/brutalist.ts +325 -0
- package/src/styles/presets-data/default.ts +315 -0
- package/src/styles/presets-data/index.ts +45 -0
- package/src/styles/presets-data/signal-pop.ts +393 -0
- package/src/styles/tokens/base.css +71 -0
- package/src/styles/tokens/components.css +150 -0
- package/src/styles/tokens/palette.css +795 -0
- package/src/styles/tokens/registry.ts +324 -0
- package/src/styles/tokens/semantic.css +266 -0
- package/src/styles/tokens/tailwind-theme.css +247 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { mergeProps } from '@base-ui/react/merge-props'
|
|
2
|
+
import { useRender } from '@base-ui/react/use-render'
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority'
|
|
4
|
+
import type * as React from 'react'
|
|
5
|
+
import { Separator } from './separator'
|
|
6
|
+
import { cn, FOCUS_RING } from '../lib/utils'
|
|
7
|
+
|
|
8
|
+
function ItemGroup({ className, ...props }: React.ComponentProps<'div'>) {
|
|
9
|
+
return (
|
|
10
|
+
<div
|
|
11
|
+
role="list"
|
|
12
|
+
data-slot="item-group"
|
|
13
|
+
className={cn(
|
|
14
|
+
'gap-4 has-[[data-size=sm]]:gap-2.5 has-[[data-size=xs]]:gap-2 group/item-group flex w-full flex-col',
|
|
15
|
+
className,
|
|
16
|
+
)}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function ItemSeparator({ className, ...props }: React.ComponentProps<typeof Separator>) {
|
|
23
|
+
return (
|
|
24
|
+
<Separator
|
|
25
|
+
data-slot="item-separator"
|
|
26
|
+
orientation="horizontal"
|
|
27
|
+
className={cn('my-2', className)}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const itemVariants = cva(
|
|
34
|
+
`${FOCUS_RING} [a]:hover:ring-[length:var(--hover-ring-width)] [a]:hover:ring-[color:var(--hover-ring-color)]/30 rounded-md border text-xs/relaxed w-full group/item flex items-center flex-wrap outline-none duration-fast`,
|
|
35
|
+
{
|
|
36
|
+
variants: {
|
|
37
|
+
variant: {
|
|
38
|
+
default: 'border-transparent',
|
|
39
|
+
outline: 'border-stroke',
|
|
40
|
+
muted: 'bg-muted/50 border-transparent',
|
|
41
|
+
},
|
|
42
|
+
size: {
|
|
43
|
+
default: 'gap-2.5 px-3 py-2.5',
|
|
44
|
+
sm: 'gap-2.5 px-3 py-2.5',
|
|
45
|
+
xs: 'gap-2.5 px-2.5 py-2 [[data-slot=dropdown-menu-content]_&]:p-0',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
defaultVariants: {
|
|
49
|
+
variant: 'default',
|
|
50
|
+
size: 'default',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
function Item({
|
|
56
|
+
className,
|
|
57
|
+
variant = 'default',
|
|
58
|
+
size = 'default',
|
|
59
|
+
render,
|
|
60
|
+
...props
|
|
61
|
+
}: useRender.ComponentProps<'div'> & VariantProps<typeof itemVariants>) {
|
|
62
|
+
return useRender({
|
|
63
|
+
defaultTagName: 'div',
|
|
64
|
+
props: mergeProps<'div'>(
|
|
65
|
+
{
|
|
66
|
+
className: cn(itemVariants({ variant, size, className })),
|
|
67
|
+
},
|
|
68
|
+
props,
|
|
69
|
+
),
|
|
70
|
+
render,
|
|
71
|
+
state: {
|
|
72
|
+
slot: 'item',
|
|
73
|
+
variant,
|
|
74
|
+
size,
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const itemMediaVariants = cva(
|
|
80
|
+
'gap-2 group-has-[[data-slot=item-description]]/item:translate-y-0.5 group-has-[[data-slot=item-description]]/item:self-start flex shrink-0 items-center justify-center [&_svg]:pointer-events-none',
|
|
81
|
+
{
|
|
82
|
+
variants: {
|
|
83
|
+
variant: {
|
|
84
|
+
default: 'bg-transparent',
|
|
85
|
+
icon: "[&_svg:not([class*='size-'])]:size-4",
|
|
86
|
+
image:
|
|
87
|
+
'size-8 overflow-hidden rounded-sm group-data-[size=sm]/item:size-8 group-data-[size=xs]/item:size-6 [&_img]:size-full [&_img]:object-cover',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
defaultVariants: {
|
|
91
|
+
variant: 'default',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
function ItemMedia({
|
|
97
|
+
className,
|
|
98
|
+
variant = 'default',
|
|
99
|
+
...props
|
|
100
|
+
}: React.ComponentProps<'div'> & VariantProps<typeof itemMediaVariants>) {
|
|
101
|
+
return (
|
|
102
|
+
<div
|
|
103
|
+
data-slot="item-media"
|
|
104
|
+
data-variant={variant}
|
|
105
|
+
className={cn(itemMediaVariants({ variant, className }))}
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function ItemContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
112
|
+
return (
|
|
113
|
+
<div
|
|
114
|
+
data-slot="item-content"
|
|
115
|
+
className={cn(
|
|
116
|
+
'gap-1 group-data-[size=xs]/item:gap-0.5 flex flex-1 flex-col [&+[data-slot=item-content]]:flex-none',
|
|
117
|
+
className,
|
|
118
|
+
)}
|
|
119
|
+
{...props}
|
|
120
|
+
/>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function ItemTitle({ className, ...props }: React.ComponentProps<'div'>) {
|
|
125
|
+
return (
|
|
126
|
+
<div
|
|
127
|
+
data-slot="item-title"
|
|
128
|
+
className={cn(
|
|
129
|
+
'gap-2 text-xs/relaxed leading-snug font-medium underline-offset-4 line-clamp-1 flex w-fit items-center',
|
|
130
|
+
className,
|
|
131
|
+
)}
|
|
132
|
+
{...props}
|
|
133
|
+
/>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function ItemDescription({ className, ...props }: React.ComponentProps<'p'>) {
|
|
138
|
+
return (
|
|
139
|
+
<p
|
|
140
|
+
data-slot="item-description"
|
|
141
|
+
className={cn(
|
|
142
|
+
'text-muted-foreground text-left text-xs/relaxed [&>a:hover]:text-primary line-clamp-2 font-normal [&>a]:underline [&>a]:underline-offset-4',
|
|
143
|
+
className,
|
|
144
|
+
)}
|
|
145
|
+
{...props}
|
|
146
|
+
/>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function ItemActions({ className, ...props }: React.ComponentProps<'div'>) {
|
|
151
|
+
return (
|
|
152
|
+
<div data-slot="item-actions" className={cn('gap-2 flex items-center', className)} {...props} />
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function ItemHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
|
157
|
+
return (
|
|
158
|
+
<div
|
|
159
|
+
data-slot="item-header"
|
|
160
|
+
className={cn('gap-2 flex basis-full items-center justify-between', className)}
|
|
161
|
+
{...props}
|
|
162
|
+
/>
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function ItemFooter({ className, ...props }: React.ComponentProps<'div'>) {
|
|
167
|
+
return (
|
|
168
|
+
<div
|
|
169
|
+
data-slot="item-footer"
|
|
170
|
+
className={cn('gap-2 flex basis-full items-center justify-between', className)}
|
|
171
|
+
{...props}
|
|
172
|
+
/>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export {
|
|
177
|
+
Item,
|
|
178
|
+
ItemMedia,
|
|
179
|
+
ItemContent,
|
|
180
|
+
ItemActions,
|
|
181
|
+
ItemGroup,
|
|
182
|
+
ItemSeparator,
|
|
183
|
+
ItemTitle,
|
|
184
|
+
ItemDescription,
|
|
185
|
+
ItemHeader,
|
|
186
|
+
ItemFooter,
|
|
187
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import { cn } from '../lib/utils'
|
|
4
|
+
|
|
5
|
+
function Kbd({ className, ...props }: React.ComponentProps<'kbd'>) {
|
|
6
|
+
return (
|
|
7
|
+
<kbd
|
|
8
|
+
data-slot="kbd"
|
|
9
|
+
className={cn(
|
|
10
|
+
'bg-muted text-muted-foreground pointer-events-none inline-flex h-5 min-w-5 items-center justify-center gap-1 rounded-sm px-1 font-mono text-2xs font-medium select-none [&_svg:not([class*=size-])]:size-3',
|
|
11
|
+
className,
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function KbdGroup({ className, ...props }: React.ComponentProps<'span'>) {
|
|
19
|
+
return (
|
|
20
|
+
<span
|
|
21
|
+
data-slot="kbd-group"
|
|
22
|
+
className={cn('inline-flex items-center gap-1', className)}
|
|
23
|
+
{...props}
|
|
24
|
+
/>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { Kbd, KbdGroup }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import { cn } from '../lib/utils'
|
|
4
|
+
|
|
5
|
+
function Label({ className, ...props }: React.ComponentProps<'label'>) {
|
|
6
|
+
return (
|
|
7
|
+
<label
|
|
8
|
+
data-slot="label"
|
|
9
|
+
className={cn(
|
|
10
|
+
'gap-2 text-xs/relaxed leading-none font-medium group-data-[disabled=true]:opacity-disabled peer-disabled:opacity-disabled flex items-center select-none group-data-[disabled=true]:pointer-events-none peer-disabled:cursor-not-allowed',
|
|
11
|
+
className,
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { Label }
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bento Layout Primitives
|
|
3
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
+
* Opinionated grid layouts for information-dense dashboards and marketing pages.
|
|
5
|
+
* Uses a "gap-as-border" technique: the container background IS the border color;
|
|
6
|
+
* 1px gap between cells exposes it as ruled lines.
|
|
7
|
+
*
|
|
8
|
+
* Semantic tokens (set in your CSS or a preset):
|
|
9
|
+
*
|
|
10
|
+
* --bento-gap Gap between cells (default: var(--border-width, 1px))
|
|
11
|
+
*
|
|
12
|
+
* Base tokens used directly:
|
|
13
|
+
* --border Grid line color (via bg-stroke)
|
|
14
|
+
* --radius Corner radius (via rounded-lg)
|
|
15
|
+
* --border-style Border style on all components (default: solid)
|
|
16
|
+
*
|
|
17
|
+
* Layout philosophy:
|
|
18
|
+
* • Container background IS the border color
|
|
19
|
+
* • Gap exposes it as 1px lines — cells are never individually bordered
|
|
20
|
+
* • "Borders never stack" — each grid line is drawn exactly once
|
|
21
|
+
* • Mobile: single-column stack; Desktop: the designed layout
|
|
22
|
+
* • All sizing is responsive, all colors through semantic tokens
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* <BentoLeader
|
|
26
|
+
* header={<div className="p-6"><h2>Dashboard</h2></div>}
|
|
27
|
+
* columns={[<StatCell label="Users" value="1,234" />, ...]}
|
|
28
|
+
* />
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import * as React from 'react'
|
|
32
|
+
|
|
33
|
+
import { cn } from '../lib/utils'
|
|
34
|
+
|
|
35
|
+
// ─── INTERNAL CONSTANTS ───────────────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
/** Background IS the border color — gap exposes it as lines. */
|
|
38
|
+
const BENTO_CONTAINER =
|
|
39
|
+
'min-w-0 bg-stroke gap-[var(--bento-gap,var(--border-width,1px))] p-[var(--bento-gap,var(--border-width,1px))] rounded-lg'
|
|
40
|
+
|
|
41
|
+
/** Every direct cell child gets card background — it sits on top of the border bg. */
|
|
42
|
+
const BENTO_CELL = 'min-w-0 bg-card rounded-lg overflow-hidden'
|
|
43
|
+
|
|
44
|
+
// ─── STAT CELL ────────────────────────────────────────────────────────────────
|
|
45
|
+
//
|
|
46
|
+
// Compact metric cell. Participates in the gap-border system — add it as a
|
|
47
|
+
// direct child of BentoGrid, CellGrid, or the stats slot of any Bento layout.
|
|
48
|
+
// Padding is internal; the outer gap provides the grid line.
|
|
49
|
+
|
|
50
|
+
interface StatCellProps extends React.ComponentProps<'div'> {
|
|
51
|
+
label: string
|
|
52
|
+
value: string
|
|
53
|
+
/** Render value at a larger text size */
|
|
54
|
+
large?: boolean
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function StatCell({ label, value, large = false, className, ...props }: StatCellProps) {
|
|
58
|
+
return (
|
|
59
|
+
<div data-slot="bento-stat-cell" className={cn(BENTO_CELL, 'p-4', className)} {...props}>
|
|
60
|
+
<div className="text-[10px] uppercase text-muted-foreground mb-1">{label}</div>
|
|
61
|
+
<div className={cn('font-bold', large ? 'text-xl' : 'text-xs')}>{value}</div>
|
|
62
|
+
</div>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ─── BENTO GRID ───────────────────────────────────────────────────────────────
|
|
67
|
+
//
|
|
68
|
+
// General-purpose grid with configurable columns. Direct children should be
|
|
69
|
+
// BentoCell components (or anything that provides its own bg-card padding).
|
|
70
|
+
// The gap-as-border pattern means you must NOT add separate borders to cells.
|
|
71
|
+
|
|
72
|
+
interface BentoGridProps extends React.ComponentProps<'div'> {
|
|
73
|
+
cols?: 1 | 2 | 3 | 4
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const BENTO_GRID_COLS: Record<1 | 2 | 3 | 4, string> = {
|
|
77
|
+
1: 'grid-cols-1',
|
|
78
|
+
2: 'grid-cols-1 lg:grid-cols-2',
|
|
79
|
+
3: 'grid-cols-1 lg:grid-cols-3',
|
|
80
|
+
4: 'grid-cols-1 lg:grid-cols-4',
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function BentoGrid({ cols = 3, className, ...props }: BentoGridProps) {
|
|
84
|
+
return (
|
|
85
|
+
<div
|
|
86
|
+
data-slot="bento-grid"
|
|
87
|
+
className={cn('grid', BENTO_GRID_COLS[cols], BENTO_CONTAINER, className)}
|
|
88
|
+
{...props}
|
|
89
|
+
/>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ─── BENTO CELL ───────────────────────────────────────────────────────────────
|
|
94
|
+
//
|
|
95
|
+
// A single cell within BentoGrid. Controls column/row span.
|
|
96
|
+
|
|
97
|
+
interface BentoCellProps extends React.ComponentProps<'div'> {
|
|
98
|
+
/** Number of columns to span */
|
|
99
|
+
colSpan?: 1 | 2 | 3 | 4
|
|
100
|
+
/** Number of rows to span */
|
|
101
|
+
rowSpan?: 1 | 2 | 3
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const COL_SPANS: Record<1 | 2 | 3 | 4, string> = {
|
|
105
|
+
1: 'col-span-1',
|
|
106
|
+
2: 'col-span-1 lg:col-span-2',
|
|
107
|
+
3: 'col-span-1 lg:col-span-3',
|
|
108
|
+
4: 'col-span-1 lg:col-span-4',
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const ROW_SPANS: Record<1 | 2 | 3, string> = {
|
|
112
|
+
1: 'row-span-1',
|
|
113
|
+
2: 'row-span-1 lg:row-span-2',
|
|
114
|
+
3: 'row-span-1 lg:row-span-3',
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function BentoCell({ colSpan = 1, rowSpan = 1, className, ...props }: BentoCellProps) {
|
|
118
|
+
return (
|
|
119
|
+
<div
|
|
120
|
+
data-slot="bento-cell"
|
|
121
|
+
className={cn(BENTO_CELL, COL_SPANS[colSpan], ROW_SPANS[rowSpan], 'p-4', className)}
|
|
122
|
+
{...props}
|
|
123
|
+
/>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ─── BENTO SPLIT ──────────────────────────────────────────────────────────────
|
|
128
|
+
//
|
|
129
|
+
// A 2-area layout: icon panel (fixed 200px on desktop, spans both rows) |
|
|
130
|
+
// content area + stats area stacked in the second column.
|
|
131
|
+
//
|
|
132
|
+
// Mobile: single column — icon, then content, then stats.
|
|
133
|
+
// Desktop: [200px icon (row-span-2)] | [content / stats]
|
|
134
|
+
|
|
135
|
+
interface BentoSplitProps extends Omit<React.ComponentProps<'div'>, 'content'> {
|
|
136
|
+
icon: React.ReactNode
|
|
137
|
+
content: React.ReactNode
|
|
138
|
+
stats: React.ReactNode
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function BentoSplit({ icon, content, stats, className, ...props }: BentoSplitProps) {
|
|
142
|
+
return (
|
|
143
|
+
<div
|
|
144
|
+
data-slot="bento-split"
|
|
145
|
+
className={cn(
|
|
146
|
+
'grid grid-cols-1 lg:grid-cols-[minmax(0,200px)_minmax(0,1fr)]',
|
|
147
|
+
BENTO_CONTAINER,
|
|
148
|
+
className,
|
|
149
|
+
)}
|
|
150
|
+
{...props}
|
|
151
|
+
>
|
|
152
|
+
{/* Icon — spans both rows on desktop */}
|
|
153
|
+
<div
|
|
154
|
+
data-slot="bento-split-icon"
|
|
155
|
+
className={cn(BENTO_CELL, 'flex items-center justify-center p-10 lg:row-span-2')}
|
|
156
|
+
>
|
|
157
|
+
{icon}
|
|
158
|
+
</div>
|
|
159
|
+
{/* Content — auto-places into col 2, row 1 */}
|
|
160
|
+
<div data-slot="bento-split-content" className={cn(BENTO_CELL, 'p-4')}>
|
|
161
|
+
{content}
|
|
162
|
+
</div>
|
|
163
|
+
{/* Stats — auto-places into col 2, row 2 */}
|
|
164
|
+
<div data-slot="bento-split-stats" className={cn(BENTO_CELL, 'p-4')}>
|
|
165
|
+
{stats}
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ─── BENTO LEADER ─────────────────────────────────────────────────────────────
|
|
172
|
+
//
|
|
173
|
+
// A full-width header spanning all columns, then N equal columns below.
|
|
174
|
+
// Desktop column count is derived from the `columns` array length (capped 2–4).
|
|
175
|
+
//
|
|
176
|
+
// Mobile: header → columns stacked.
|
|
177
|
+
// Desktop: header (full width) | N equal columns.
|
|
178
|
+
|
|
179
|
+
const LEADER_COLS: Record<1 | 2 | 3 | 4, string> = {
|
|
180
|
+
1: 'lg:grid-cols-1',
|
|
181
|
+
2: 'lg:grid-cols-2',
|
|
182
|
+
3: 'lg:grid-cols-3',
|
|
183
|
+
4: 'lg:grid-cols-4',
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface BentoLeaderProps extends React.ComponentProps<'div'> {
|
|
187
|
+
header: React.ReactNode
|
|
188
|
+
columns: React.ReactNode[]
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function BentoLeader({ header, columns, className, ...props }: BentoLeaderProps) {
|
|
192
|
+
// Clamp to at least 1 so arrays with 0–1 items don't create ghost columns.
|
|
193
|
+
const n = Math.min(Math.max(columns.length, 1), 4) as 1 | 2 | 3 | 4
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<div
|
|
197
|
+
data-slot="bento-leader"
|
|
198
|
+
className={cn('grid grid-cols-1', LEADER_COLS[n], BENTO_CONTAINER, className)}
|
|
199
|
+
{...props}
|
|
200
|
+
>
|
|
201
|
+
{/* Header spans all columns */}
|
|
202
|
+
<div data-slot="bento-leader-header" className={cn(BENTO_CELL, 'lg:[grid-column:1/-1]')}>
|
|
203
|
+
{header}
|
|
204
|
+
</div>
|
|
205
|
+
{columns.map((col, i) => (
|
|
206
|
+
<div key={i} data-slot="bento-leader-column" className={BENTO_CELL}>
|
|
207
|
+
{col}
|
|
208
|
+
</div>
|
|
209
|
+
))}
|
|
210
|
+
</div>
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ─── BENTO QUAD ───────────────────────────────────────────────────────────────
|
|
215
|
+
//
|
|
216
|
+
// A 2×2 grid with a [2fr | 1fr] column ratio.
|
|
217
|
+
// Mobile: all four areas stacked.
|
|
218
|
+
// Desktop: 2-column, 2-row layout.
|
|
219
|
+
|
|
220
|
+
interface BentoQuadProps extends React.ComponentProps<'div'> {
|
|
221
|
+
topLeft: React.ReactNode
|
|
222
|
+
topRight: React.ReactNode
|
|
223
|
+
bottomLeft: React.ReactNode
|
|
224
|
+
bottomRight: React.ReactNode
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function BentoQuad({
|
|
228
|
+
topLeft,
|
|
229
|
+
topRight,
|
|
230
|
+
bottomLeft,
|
|
231
|
+
bottomRight,
|
|
232
|
+
className,
|
|
233
|
+
...props
|
|
234
|
+
}: BentoQuadProps) {
|
|
235
|
+
return (
|
|
236
|
+
<div
|
|
237
|
+
data-slot="bento-quad"
|
|
238
|
+
className={cn(
|
|
239
|
+
'grid grid-cols-1 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]',
|
|
240
|
+
BENTO_CONTAINER,
|
|
241
|
+
className,
|
|
242
|
+
)}
|
|
243
|
+
{...props}
|
|
244
|
+
>
|
|
245
|
+
<div data-slot="bento-quad-top-left" className={BENTO_CELL}>
|
|
246
|
+
{topLeft}
|
|
247
|
+
</div>
|
|
248
|
+
<div data-slot="bento-quad-top-right" className={BENTO_CELL}>
|
|
249
|
+
{topRight}
|
|
250
|
+
</div>
|
|
251
|
+
<div data-slot="bento-quad-bottom-left" className={BENTO_CELL}>
|
|
252
|
+
{bottomLeft}
|
|
253
|
+
</div>
|
|
254
|
+
<div data-slot="bento-quad-bottom-right" className={BENTO_CELL}>
|
|
255
|
+
{bottomRight}
|
|
256
|
+
</div>
|
|
257
|
+
</div>
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// ─── BENTO TRIPLE ─────────────────────────────────────────────────────────────
|
|
262
|
+
//
|
|
263
|
+
// 3-row layout: header (full width) | aside + body | footer (full width).
|
|
264
|
+
// Desktop: [1fr aside | 2fr body]. Header and footer span both columns.
|
|
265
|
+
// Mobile: header → aside → body → footer (natural DOM order).
|
|
266
|
+
|
|
267
|
+
interface BentoTripleProps extends React.ComponentProps<'div'> {
|
|
268
|
+
header: React.ReactNode
|
|
269
|
+
aside: React.ReactNode
|
|
270
|
+
body: React.ReactNode
|
|
271
|
+
footer: React.ReactNode
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function BentoTriple({ header, aside, body, footer, className, ...props }: BentoTripleProps) {
|
|
275
|
+
return (
|
|
276
|
+
<div
|
|
277
|
+
data-slot="bento-triple"
|
|
278
|
+
className={cn(
|
|
279
|
+
'grid grid-cols-1 lg:grid-cols-[minmax(0,1fr)_minmax(0,2fr)]',
|
|
280
|
+
BENTO_CONTAINER,
|
|
281
|
+
className,
|
|
282
|
+
)}
|
|
283
|
+
{...props}
|
|
284
|
+
>
|
|
285
|
+
{/* Header spans both columns */}
|
|
286
|
+
<div data-slot="bento-triple-header" className={cn(BENTO_CELL, 'lg:[grid-column:1/-1]')}>
|
|
287
|
+
{header}
|
|
288
|
+
</div>
|
|
289
|
+
{/* Aside — col 1, row 2 */}
|
|
290
|
+
<div
|
|
291
|
+
data-slot="bento-triple-aside"
|
|
292
|
+
className={cn(BENTO_CELL, 'flex items-center justify-center')}
|
|
293
|
+
>
|
|
294
|
+
{aside}
|
|
295
|
+
</div>
|
|
296
|
+
{/* Body — col 2, row 2 */}
|
|
297
|
+
<div data-slot="bento-triple-body" className={BENTO_CELL}>
|
|
298
|
+
{body}
|
|
299
|
+
</div>
|
|
300
|
+
{/* Footer spans both columns */}
|
|
301
|
+
<div data-slot="bento-triple-footer" className={cn(BENTO_CELL, 'lg:[grid-column:1/-1]')}>
|
|
302
|
+
{footer}
|
|
303
|
+
</div>
|
|
304
|
+
</div>
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ─── CELL GRID ────────────────────────────────────────────────────────────────
|
|
309
|
+
//
|
|
310
|
+
// Equal-column grid using the gap-as-border pattern. Direct children must
|
|
311
|
+
// provide their own `bg-card` (e.g. StatCell, or wrap in `<div className="bg-card">`).
|
|
312
|
+
//
|
|
313
|
+
// `subtle` uses the secondary border color for a lighter grid line.
|
|
314
|
+
|
|
315
|
+
const CELL_GRID_COLS: Record<2 | 3 | 4 | 5, string> = {
|
|
316
|
+
2: 'lg:grid-cols-2',
|
|
317
|
+
3: 'lg:grid-cols-3',
|
|
318
|
+
4: 'lg:grid-cols-4',
|
|
319
|
+
5: 'lg:grid-cols-5',
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
interface CellGridProps extends React.ComponentProps<'div'> {
|
|
323
|
+
cols: 2 | 3 | 4 | 5
|
|
324
|
+
/** Use a lighter (secondary) border color for the grid lines */
|
|
325
|
+
subtle?: boolean
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function CellGrid({ cols, subtle = false, className, ...props }: CellGridProps) {
|
|
329
|
+
return (
|
|
330
|
+
<div
|
|
331
|
+
data-slot="bento-cell-grid"
|
|
332
|
+
className={cn(
|
|
333
|
+
'grid grid-cols-1',
|
|
334
|
+
CELL_GRID_COLS[cols],
|
|
335
|
+
'gap-[var(--bento-gap,var(--border-width,1px))]',
|
|
336
|
+
'min-w-0',
|
|
337
|
+
subtle ? 'bg-field' : 'bg-stroke',
|
|
338
|
+
className,
|
|
339
|
+
)}
|
|
340
|
+
{...props}
|
|
341
|
+
/>
|
|
342
|
+
)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ─── CELL ROW ─────────────────────────────────────────────────────────────────
|
|
346
|
+
//
|
|
347
|
+
// Flex direction flip with gap-as-divider. Mobile/narrow panes: stacked.
|
|
348
|
+
// Wider panes: side-by-side. Children control their own widths.
|
|
349
|
+
|
|
350
|
+
function CellRow({ className, ...props }: React.ComponentProps<'div'>) {
|
|
351
|
+
return (
|
|
352
|
+
<div
|
|
353
|
+
data-slot="bento-cell-row"
|
|
354
|
+
className={cn(
|
|
355
|
+
'bg-stroke',
|
|
356
|
+
'flex min-w-0 flex-col xl:flex-row',
|
|
357
|
+
'gap-[var(--bento-gap,var(--border-width,1px))]',
|
|
358
|
+
className,
|
|
359
|
+
)}
|
|
360
|
+
{...props}
|
|
361
|
+
/>
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export {
|
|
366
|
+
BentoGrid,
|
|
367
|
+
BentoCell,
|
|
368
|
+
BentoSplit,
|
|
369
|
+
BentoLeader,
|
|
370
|
+
BentoQuad,
|
|
371
|
+
BentoTriple,
|
|
372
|
+
CellGrid,
|
|
373
|
+
CellRow,
|
|
374
|
+
StatCell,
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export type {
|
|
378
|
+
BentoGridProps,
|
|
379
|
+
BentoCellProps,
|
|
380
|
+
BentoSplitProps,
|
|
381
|
+
BentoLeaderProps,
|
|
382
|
+
BentoQuadProps,
|
|
383
|
+
BentoTripleProps,
|
|
384
|
+
CellGridProps,
|
|
385
|
+
StatCellProps,
|
|
386
|
+
}
|