@blankways/ui 0.1.0-alpha.1 → 0.2.0-alpha.1
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/README.md +157 -139
- package/dist/cli/cli.options.js +21 -1
- package/dist/cli/cli.types.d.ts +1 -0
- package/dist/cli.js +2 -1
- package/dist/commands/add.command.d.ts +2 -0
- package/dist/commands/add.command.js +30 -82
- package/dist/commands/dev.command.d.ts +3 -0
- package/dist/commands/dev.command.js +76 -0
- package/dist/commands/doctor.command.js +12 -1
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +3 -0
- package/dist/commands/init.command.js +15 -10
- package/dist/commands/install.command.d.ts +2 -0
- package/dist/commands/install.command.js +36 -0
- package/dist/commands/list.command.js +10 -5
- package/dist/commands/registry.command.d.ts +2 -0
- package/dist/commands/registry.command.js +69 -0
- package/dist/commands/styles.command.d.ts +1 -2
- package/dist/commands/styles.command.js +15 -39
- package/dist/config/config.helpers.d.ts +4 -1
- package/dist/config/config.helpers.js +61 -8
- package/dist/constants/cli.constants.d.ts +14 -3
- package/dist/constants/cli.constants.js +14 -9
- package/dist/doctor/checks/barrels.check.d.ts +1 -0
- package/dist/doctor/checks/barrels.check.js +60 -0
- package/dist/doctor/checks/contracts.check.d.ts +1 -0
- package/dist/doctor/checks/contracts.check.js +45 -0
- package/dist/doctor/checks/icons.check.js +8 -3
- package/dist/doctor/checks/index.d.ts +3 -0
- package/dist/doctor/checks/index.js +3 -0
- package/dist/doctor/checks/motion.check.js +2 -2
- package/dist/doctor/checks/namespaces.check.d.ts +1 -0
- package/dist/doctor/checks/namespaces.check.js +76 -0
- package/dist/doctor/checks/themes.check.js +18 -40
- package/dist/doctor/doctor.helpers.js +5 -1
- package/dist/doctor/doctor.types.d.ts +4 -0
- package/dist/helpers/args.helpers.d.ts +2 -0
- package/dist/helpers/args.helpers.js +9 -0
- package/dist/helpers/barrels.helpers.d.ts +15 -0
- package/dist/helpers/barrels.helpers.js +157 -0
- package/dist/index.d.ts +12 -9
- package/dist/index.js +11 -9
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.js +2 -0
- package/dist/registry/lockfile.d.ts +18 -0
- package/dist/registry/lockfile.js +32 -0
- package/dist/registry/registry.helpers.d.ts +3 -13
- package/dist/registry/registry.helpers.js +30 -116
- package/dist/registry/registry.providers.d.ts +13 -0
- package/dist/registry/registry.providers.js +159 -0
- package/dist/registry/registry.service.d.ts +14 -0
- package/dist/registry/registry.service.js +126 -0
- package/dist/types/config.types.d.ts +29 -0
- package/dist/types/registry.types.d.ts +31 -0
- package/dist/types/registry.types.js +2 -0
- package/dist/ui-api/index.d.ts +16 -0
- package/dist/ui-api/index.js +30 -0
- package/dist/ui-api/ui-api.d.ts +18 -0
- package/dist/ui-api/ui-api.js +194 -0
- package/package.json +7 -5
- package/styles.css +16 -0
- package/dist/registry-data/README.md +0 -71
- package/dist/registry-data/avatar/Avatar.tsx +0 -64
- package/dist/registry-data/avatar/component.json +0 -30
- package/dist/registry-data/avatar/index.ts +0 -1
- package/dist/registry-data/badge/Badge.tsx +0 -76
- package/dist/registry-data/badge/component.json +0 -30
- package/dist/registry-data/badge/index.ts +0 -1
- package/dist/registry-data/brand-logo/BrandLogo.tsx +0 -24
- package/dist/registry-data/brand-logo/component.json +0 -26
- package/dist/registry-data/brand-logo/index.ts +0 -1
- package/dist/registry-data/button/Button.tsx +0 -76
- package/dist/registry-data/button/component.json +0 -33
- package/dist/registry-data/button/index.ts +0 -1
- package/dist/registry-data/button-link/ButtonLink.tsx +0 -83
- package/dist/registry-data/button-link/component.json +0 -33
- package/dist/registry-data/button-link/index.ts +0 -5
- package/dist/registry-data/button-styles/component.json +0 -19
- package/dist/registry-data/button-styles/index.ts +0 -45
- package/dist/registry-data/cn/cn.ts +0 -6
- package/dist/registry-data/cn/component.json +0 -16
- package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +0 -134
- package/dist/registry-data/confirm-dialog/component.json +0 -34
- package/dist/registry-data/confirm-dialog/index.ts +0 -1
- package/dist/registry-data/container/Container.tsx +0 -22
- package/dist/registry-data/container/component.json +0 -28
- package/dist/registry-data/container/index.ts +0 -1
- package/dist/registry-data/cursor-glow/CursorGlow.tsx +0 -29
- package/dist/registry-data/cursor-glow/component.json +0 -28
- package/dist/registry-data/cursor-glow/index.ts +0 -1
- package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +0 -157
- package/dist/registry-data/dropdown-menu/component.json +0 -34
- package/dist/registry-data/dropdown-menu/index.ts +0 -5
- package/dist/registry-data/empty-state/EmptyState.tsx +0 -92
- package/dist/registry-data/empty-state/component.json +0 -30
- package/dist/registry-data/empty-state/index.ts +0 -5
- package/dist/registry-data/eyebrow/Eyebrow.tsx +0 -68
- package/dist/registry-data/eyebrow/component.json +0 -30
- package/dist/registry-data/eyebrow/index.ts +0 -1
- package/dist/registry-data/field-styles/component.json +0 -19
- package/dist/registry-data/field-styles/index.ts +0 -42
- package/dist/registry-data/form-dialog/FormDialog.tsx +0 -128
- package/dist/registry-data/form-dialog/component.json +0 -34
- package/dist/registry-data/form-dialog/index.ts +0 -1
- package/dist/registry-data/icons/component.json +0 -22
- package/dist/registry-data/icons/index.ts +0 -21
- package/dist/registry-data/icons-form/component.json +0 -17
- package/dist/registry-data/icons-form/index.ts +0 -1
- package/dist/registry-data/icons-sidebar/component.json +0 -17
- package/dist/registry-data/icons-sidebar/index.ts +0 -1
- package/dist/registry-data/icons-theme/component.json +0 -17
- package/dist/registry-data/icons-theme/index.ts +0 -1
- package/dist/registry-data/icons-toast/component.json +0 -17
- package/dist/registry-data/icons-toast/index.ts +0 -1
- package/dist/registry-data/info-dialog/InfoDialog.tsx +0 -119
- package/dist/registry-data/info-dialog/component.json +0 -36
- package/dist/registry-data/info-dialog/index.ts +0 -1
- package/dist/registry-data/input/Input.tsx +0 -96
- package/dist/registry-data/input/component.json +0 -33
- package/dist/registry-data/input/index.ts +0 -1
- package/dist/registry-data/multi-combobox/MultiCombobox.tsx +0 -205
- package/dist/registry-data/multi-combobox/component.json +0 -35
- package/dist/registry-data/multi-combobox/index.ts +0 -5
- package/dist/registry-data/remote-provider/RemoteProvider.tsx +0 -8
- package/dist/registry-data/remote-provider/component.json +0 -25
- package/dist/registry-data/remote-provider/index.ts +0 -3
- package/dist/registry-data/reveal/Reveal.tsx +0 -22
- package/dist/registry-data/reveal/component.json +0 -30
- package/dist/registry-data/reveal/index.ts +0 -1
- package/dist/registry-data/section/Section.tsx +0 -80
- package/dist/registry-data/section/component.json +0 -30
- package/dist/registry-data/section/index.ts +0 -1
- package/dist/registry-data/section-heading/SectionHeading.tsx +0 -105
- package/dist/registry-data/section-heading/component.json +0 -32
- package/dist/registry-data/section-heading/index.ts +0 -1
- package/dist/registry-data/select/Select.tsx +0 -197
- package/dist/registry-data/select/component.json +0 -34
- package/dist/registry-data/select/index.ts +0 -1
- package/dist/registry-data/sidebar/Sidebar.tsx +0 -432
- package/dist/registry-data/sidebar/SidebarCollapsible.tsx +0 -77
- package/dist/registry-data/sidebar/SidebarParts.tsx +0 -373
- package/dist/registry-data/sidebar/component.json +0 -47
- package/dist/registry-data/sidebar/index.ts +0 -4
- package/dist/registry-data/sidebar/useSidebar.ts +0 -29
- package/dist/registry-data/styles-base/component.json +0 -19
- package/dist/registry-data/styles-base/index.css +0 -67
- package/dist/registry-data/styles-components/component.json +0 -19
- package/dist/registry-data/styles-components/index.css +0 -30
- package/dist/registry-data/styles-motion/component.json +0 -20
- package/dist/registry-data/styles-motion/index.css +0 -381
- package/dist/registry-data/styles-tokens/component.json +0 -17
- package/dist/registry-data/styles-tokens/index.css +0 -77
- package/dist/registry-data/styles-utilities/component.json +0 -19
- package/dist/registry-data/styles-utilities/index.css +0 -29
- package/dist/registry-data/switch/Switch.tsx +0 -91
- package/dist/registry-data/switch/component.json +0 -34
- package/dist/registry-data/switch/index.ts +0 -1
- package/dist/registry-data/tabs/Tabs.tsx +0 -226
- package/dist/registry-data/tabs/component.json +0 -32
- package/dist/registry-data/tabs/index.ts +0 -1
- package/dist/registry-data/textarea/Textarea.tsx +0 -94
- package/dist/registry-data/textarea/component.json +0 -33
- package/dist/registry-data/textarea/index.ts +0 -1
- package/dist/registry-data/theme-core/component.json +0 -17
- package/dist/registry-data/theme-core/theme.ts +0 -84
- package/dist/registry-data/theme-dark/component.json +0 -19
- package/dist/registry-data/theme-dark/index.ts +0 -7
- package/dist/registry-data/theme-light/component.json +0 -19
- package/dist/registry-data/theme-light/index.ts +0 -7
- package/dist/registry-data/theme-provider/ThemeContext.tsx +0 -177
- package/dist/registry-data/theme-provider/component.json +0 -30
- package/dist/registry-data/theme-provider/index.ts +0 -2
- package/dist/registry-data/theme-selector/ThemeSelector.tsx +0 -269
- package/dist/registry-data/theme-selector/component.json +0 -35
- package/dist/registry-data/theme-selector/selector.ts +0 -1
- package/dist/registry-data/theme-system/component.json +0 -19
- package/dist/registry-data/theme-system/index.ts +0 -7
- package/dist/registry-data/theme-toggle/ThemeToggle.tsx +0 -71
- package/dist/registry-data/theme-toggle/component.json +0 -31
- package/dist/registry-data/theme-toggle/toggle.ts +0 -1
- package/dist/registry-data/toast/Toast.tsx +0 -260
- package/dist/registry-data/toast/ToastTypeIcon.tsx +0 -83
- package/dist/registry-data/toast/component.json +0 -43
- package/dist/registry-data/toast/index.ts +0 -3
- package/dist/registry-data/toast/useToast.ts +0 -47
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
import { State, type StateId } from '@blankways/state'
|
|
2
|
-
import {
|
|
3
|
-
Show,
|
|
4
|
-
useAttributes,
|
|
5
|
-
useCompute,
|
|
6
|
-
useMatch,
|
|
7
|
-
useState,
|
|
8
|
-
} from '@blankways/state-react'
|
|
9
|
-
import {
|
|
10
|
-
useCallback,
|
|
11
|
-
useEffect,
|
|
12
|
-
useMemo,
|
|
13
|
-
useRef,
|
|
14
|
-
useState as useReactState,
|
|
15
|
-
type ComponentProps,
|
|
16
|
-
type CSSProperties,
|
|
17
|
-
} from 'react'
|
|
18
|
-
import { cn } from '../../internals/cn.js'
|
|
19
|
-
import { PanelLeftClose, PanelLeftOpen } from '../../icons/sidebar.js'
|
|
20
|
-
import {
|
|
21
|
-
SidebarContext,
|
|
22
|
-
useSidebar,
|
|
23
|
-
type SidebarContextValue,
|
|
24
|
-
type SidebarState,
|
|
25
|
-
} from './useSidebar.js'
|
|
26
|
-
|
|
27
|
-
const SIDEBAR_WIDTH = '16rem'
|
|
28
|
-
const SIDEBAR_WIDTH_MOBILE = '18rem'
|
|
29
|
-
const SIDEBAR_WIDTH_ICON = '3.5rem'
|
|
30
|
-
|
|
31
|
-
// Module-level, stable cases for `useMatch`.
|
|
32
|
-
const SIDEBAR_STATES = ['expanded', 'collapsed'] as const
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Wraps the page. Owns the open state, the `Ctrl/Cmd + B` shortcut, mobile
|
|
36
|
-
* detection and the CSS widths used by the sidebar and its gap.
|
|
37
|
-
*/
|
|
38
|
-
export function SidebarProvider({
|
|
39
|
-
className,
|
|
40
|
-
style,
|
|
41
|
-
children,
|
|
42
|
-
...props
|
|
43
|
-
}: ComponentProps<'div'>) {
|
|
44
|
-
const open = useState<boolean>(true)
|
|
45
|
-
const openMobile = useState<boolean>(false)
|
|
46
|
-
const isMobile = useState<boolean>(false)
|
|
47
|
-
const state = useCompute<[StateId<boolean>], SidebarState>([open], ([value]) =>
|
|
48
|
-
value ? 'expanded' : 'collapsed',
|
|
49
|
-
)
|
|
50
|
-
const collapsed = useCompute<[StateId<SidebarState>], boolean>(
|
|
51
|
-
[state],
|
|
52
|
-
([value]) => value === 'collapsed',
|
|
53
|
-
)
|
|
54
|
-
const width = useCompute<[StateId<SidebarState>], string>(
|
|
55
|
-
[state],
|
|
56
|
-
([value]) => (value === 'collapsed' ? SIDEBAR_WIDTH_ICON : SIDEBAR_WIDTH),
|
|
57
|
-
)
|
|
58
|
-
const iconWidth = useState<string>(SIDEBAR_WIDTH_ICON)
|
|
59
|
-
|
|
60
|
-
// React mirror so layout branches can be chosen without extra subscriptions.
|
|
61
|
-
const [isMobileView, setIsMobileView] = useReactState(() => State.get(isMobile))
|
|
62
|
-
const rootRef = useRef<HTMLDivElement | null>(null)
|
|
63
|
-
|
|
64
|
-
useAttributes(rootRef, {
|
|
65
|
-
'data-state': state,
|
|
66
|
-
'data-collapsed': collapsed,
|
|
67
|
-
'data-mobile': isMobile,
|
|
68
|
-
style: {
|
|
69
|
-
'--sidebar-width': width,
|
|
70
|
-
'--sidebar-width-icon': iconWidth,
|
|
71
|
-
},
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
// `useAttributes` writes style subkeys directly; keep custom properties real.
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
const element = rootRef.current
|
|
77
|
-
if (!element) return
|
|
78
|
-
|
|
79
|
-
const applyWidth = () => {
|
|
80
|
-
element.style.setProperty('--sidebar-width', State.get(width))
|
|
81
|
-
element.style.setProperty('--sidebar-width-icon', State.get(iconWidth))
|
|
82
|
-
}
|
|
83
|
-
applyWidth()
|
|
84
|
-
|
|
85
|
-
const unwatchWidth = State.watch(width, () => {
|
|
86
|
-
element.style.setProperty('--sidebar-width', State.get(width))
|
|
87
|
-
})
|
|
88
|
-
const unwatchIconWidth = State.watch(iconWidth, () => {
|
|
89
|
-
element.style.setProperty('--sidebar-width-icon', State.get(iconWidth))
|
|
90
|
-
})
|
|
91
|
-
return () => {
|
|
92
|
-
State.unwatch(unwatchWidth)
|
|
93
|
-
State.unwatch(unwatchIconWidth)
|
|
94
|
-
}
|
|
95
|
-
}, [width, iconWidth])
|
|
96
|
-
|
|
97
|
-
useEffect(() => {
|
|
98
|
-
setIsMobileView(State.get(isMobile))
|
|
99
|
-
const unwatch = State.watch(isMobile, () => setIsMobileView(State.get(isMobile)))
|
|
100
|
-
return () => State.unwatch(unwatch)
|
|
101
|
-
}, [isMobile])
|
|
102
|
-
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
const media = window.matchMedia('(max-width: 767px)')
|
|
108
|
-
const sync = () => {
|
|
109
|
-
State.set(isMobile, media.matches)
|
|
110
|
-
if (!media.matches) State.set(openMobile, false)
|
|
111
|
-
}
|
|
112
|
-
sync()
|
|
113
|
-
|
|
114
|
-
if (typeof media.addEventListener === 'function') {
|
|
115
|
-
media.addEventListener('change', sync)
|
|
116
|
-
return () => media.removeEventListener('change', sync)
|
|
117
|
-
}
|
|
118
|
-
media.addListener(sync)
|
|
119
|
-
return () => media.removeListener(sync)
|
|
120
|
-
}, [isMobile, openMobile])
|
|
121
|
-
|
|
122
|
-
const setOpen = useCallback((value: boolean) => State.set(open, value), [open])
|
|
123
|
-
const setOpenMobile = useCallback(
|
|
124
|
-
(value: boolean) => State.set(openMobile, value),
|
|
125
|
-
[openMobile],
|
|
126
|
-
)
|
|
127
|
-
const toggleSidebar = useCallback(() => {
|
|
128
|
-
if (State.get(isMobile)) {
|
|
129
|
-
State.set(openMobile, !State.get(openMobile))
|
|
130
|
-
} else {
|
|
131
|
-
State.set(open, !State.get(open))
|
|
132
|
-
}
|
|
133
|
-
}, [isMobile, open, openMobile])
|
|
134
|
-
|
|
135
|
-
useEffect(() => {
|
|
136
|
-
if (typeof window === 'undefined') return
|
|
137
|
-
const onKeyDown = (event: KeyboardEvent) => {
|
|
138
|
-
if (!(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== 'b') {
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
const target = event.target as HTMLElement | null
|
|
142
|
-
if (
|
|
143
|
-
target?.isContentEditable ||
|
|
144
|
-
(target && ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName))
|
|
145
|
-
) {
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
event.preventDefault()
|
|
149
|
-
toggleSidebar()
|
|
150
|
-
}
|
|
151
|
-
window.addEventListener('keydown', onKeyDown)
|
|
152
|
-
return () => window.removeEventListener('keydown', onKeyDown)
|
|
153
|
-
}, [toggleSidebar])
|
|
154
|
-
|
|
155
|
-
const value = useMemo<SidebarContextValue>(
|
|
156
|
-
() => ({
|
|
157
|
-
open,
|
|
158
|
-
openMobile,
|
|
159
|
-
isMobile,
|
|
160
|
-
state,
|
|
161
|
-
collapsed,
|
|
162
|
-
isMobileView,
|
|
163
|
-
setOpen,
|
|
164
|
-
setOpenMobile,
|
|
165
|
-
toggleSidebar,
|
|
166
|
-
}),
|
|
167
|
-
[
|
|
168
|
-
collapsed,
|
|
169
|
-
isMobile,
|
|
170
|
-
isMobileView,
|
|
171
|
-
open,
|
|
172
|
-
openMobile,
|
|
173
|
-
setOpen,
|
|
174
|
-
setOpenMobile,
|
|
175
|
-
state,
|
|
176
|
-
toggleSidebar,
|
|
177
|
-
],
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
return (
|
|
181
|
-
<SidebarContext.Provider value={value}>
|
|
182
|
-
<div
|
|
183
|
-
ref={rootRef}
|
|
184
|
-
data-slot="sidebar-wrapper"
|
|
185
|
-
style={style}
|
|
186
|
-
className={cn(
|
|
187
|
-
'sidebar-shell group/sidebar-wrapper flex min-h-svh w-full bg-paper text-ink',
|
|
188
|
-
className,
|
|
189
|
-
)}
|
|
190
|
-
{...props}
|
|
191
|
-
>
|
|
192
|
-
{children}
|
|
193
|
-
</div>
|
|
194
|
-
</SidebarContext.Provider>
|
|
195
|
-
)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
type SidebarProps = ComponentProps<'aside'> & {
|
|
199
|
-
side?: 'left' | 'right'
|
|
200
|
-
/** `sidebar` is flush; `floating` and `inset` leave a margin around it. */
|
|
201
|
-
variant?: 'sidebar' | 'floating' | 'inset'
|
|
202
|
-
/** `icon` shrinks to icons, `offcanvas` slides away, `none` never collapses. */
|
|
203
|
-
collapsible?: 'offcanvas' | 'icon' | 'none'
|
|
204
|
-
/** Accessible name of the drawer shown on small screens. */
|
|
205
|
-
mobileTitle?: string
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* The sidebar: fixed beside the content on desktop, a native drawer with an
|
|
210
|
-
* overlay on small screens. Visual transitions use CSS, never animation libs.
|
|
211
|
-
*/
|
|
212
|
-
export function Sidebar({
|
|
213
|
-
side = 'left',
|
|
214
|
-
variant = 'sidebar',
|
|
215
|
-
collapsible = 'offcanvas',
|
|
216
|
-
mobileTitle = 'Menu',
|
|
217
|
-
className,
|
|
218
|
-
children,
|
|
219
|
-
...props
|
|
220
|
-
}: SidebarProps) {
|
|
221
|
-
const { isMobile, isMobileView, state, collapsed, openMobile, setOpenMobile } =
|
|
222
|
-
useSidebar()
|
|
223
|
-
|
|
224
|
-
const collapsibleState = useCompute<[StateId<SidebarState>], string>(
|
|
225
|
-
[state],
|
|
226
|
-
([value]) => (value === 'collapsed' ? collapsible : ''),
|
|
227
|
-
)
|
|
228
|
-
const bindDesktop = useAttributes<HTMLDivElement>({
|
|
229
|
-
'data-state': state,
|
|
230
|
-
'data-collapsed': collapsed,
|
|
231
|
-
'data-collapsible': collapsibleState,
|
|
232
|
-
})
|
|
233
|
-
const bindPanel = useAttributes<HTMLElement>({
|
|
234
|
-
'data-state': state,
|
|
235
|
-
'data-collapsible': collapsibleState,
|
|
236
|
-
})
|
|
237
|
-
const bindMobile = useAttributes<HTMLElement>({
|
|
238
|
-
'data-state': state,
|
|
239
|
-
'data-mobile': isMobile,
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
if (collapsible === 'none') {
|
|
243
|
-
return (
|
|
244
|
-
<aside
|
|
245
|
-
ref={bindMobile}
|
|
246
|
-
data-slot="sidebar"
|
|
247
|
-
data-sidebar="sidebar"
|
|
248
|
-
data-side={side}
|
|
249
|
-
className={cn(
|
|
250
|
-
'flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground',
|
|
251
|
-
className,
|
|
252
|
-
)}
|
|
253
|
-
{...props}
|
|
254
|
-
>
|
|
255
|
-
{children}
|
|
256
|
-
</aside>
|
|
257
|
-
)
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (isMobileView) {
|
|
261
|
-
return (
|
|
262
|
-
<Show when={openMobile}>
|
|
263
|
-
<div className="fixed inset-0 z-40">
|
|
264
|
-
<div
|
|
265
|
-
aria-hidden="true"
|
|
266
|
-
data-state="open"
|
|
267
|
-
className="backdrop-enter absolute inset-0 bg-black/40"
|
|
268
|
-
onClick={() => setOpenMobile(false)}
|
|
269
|
-
/>
|
|
270
|
-
<aside
|
|
271
|
-
ref={bindMobile}
|
|
272
|
-
data-slot="sidebar"
|
|
273
|
-
data-sidebar="sidebar"
|
|
274
|
-
data-mobile="true"
|
|
275
|
-
data-side={side}
|
|
276
|
-
data-state="open"
|
|
277
|
-
aria-label={mobileTitle}
|
|
278
|
-
style={
|
|
279
|
-
{
|
|
280
|
-
'--sidebar-width': SIDEBAR_WIDTH_MOBILE,
|
|
281
|
-
'--drawer-x': side === 'left' ? '-100%' : '100%',
|
|
282
|
-
} as CSSProperties
|
|
283
|
-
}
|
|
284
|
-
className={cn(
|
|
285
|
-
'sidebar-drawer absolute inset-y-0 z-50 flex w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground shadow-2xl outline-none',
|
|
286
|
-
side === 'left'
|
|
287
|
-
? 'left-0 border-r border-sidebar-border'
|
|
288
|
-
: 'right-0 border-l border-sidebar-border',
|
|
289
|
-
className,
|
|
290
|
-
)}
|
|
291
|
-
{...props}
|
|
292
|
-
>
|
|
293
|
-
<span className="sr-only">{mobileTitle}</span>
|
|
294
|
-
<div className="group flex h-full w-full flex-col">{children}</div>
|
|
295
|
-
</aside>
|
|
296
|
-
</div>
|
|
297
|
-
</Show>
|
|
298
|
-
)
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const floating = variant === 'floating' || variant === 'inset'
|
|
302
|
-
|
|
303
|
-
return (
|
|
304
|
-
<div
|
|
305
|
-
ref={bindDesktop}
|
|
306
|
-
className="group peer hidden text-sidebar-foreground md:block"
|
|
307
|
-
data-slot="sidebar-container"
|
|
308
|
-
data-variant={variant}
|
|
309
|
-
data-side={side}
|
|
310
|
-
>
|
|
311
|
-
{/* Reserves the room the fixed sidebar takes. */}
|
|
312
|
-
<div
|
|
313
|
-
data-slot="sidebar-gap"
|
|
314
|
-
className={cn(
|
|
315
|
-
'relative w-(--sidebar-width) bg-transparent',
|
|
316
|
-
'group-data-[collapsible=offcanvas]:w-0',
|
|
317
|
-
floating
|
|
318
|
-
? 'group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+--spacing(4))]'
|
|
319
|
-
: 'group-data-[collapsible=icon]:w-(--sidebar-width-icon)',
|
|
320
|
-
)}
|
|
321
|
-
/>
|
|
322
|
-
<aside
|
|
323
|
-
ref={bindPanel}
|
|
324
|
-
data-slot="sidebar"
|
|
325
|
-
data-side={side}
|
|
326
|
-
style={{ '--sidebar-hidden-x': side === 'left' ? '-100%' : '100%' } as CSSProperties}
|
|
327
|
-
className={cn(
|
|
328
|
-
'sidebar-panel fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) md:flex',
|
|
329
|
-
'data-[side=left]:left-0 data-[side=right]:right-0',
|
|
330
|
-
floating
|
|
331
|
-
? 'p-1.5 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+--spacing(4)+2px)]'
|
|
332
|
-
: 'border-sidebar-border group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l',
|
|
333
|
-
className,
|
|
334
|
-
)}
|
|
335
|
-
{...props}
|
|
336
|
-
>
|
|
337
|
-
<div
|
|
338
|
-
data-sidebar="sidebar"
|
|
339
|
-
data-slot="sidebar-inner"
|
|
340
|
-
className="flex size-full flex-col bg-sidebar group-data-[variant=floating]:rounded-2xl group-data-[variant=floating]:shadow-sm group-data-[variant=floating]:ring-1 group-data-[variant=floating]:ring-sidebar-border"
|
|
341
|
-
>
|
|
342
|
-
{children}
|
|
343
|
-
</div>
|
|
344
|
-
</aside>
|
|
345
|
-
</div>
|
|
346
|
-
)
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/** Button that opens and closes the sidebar. Place it in the page header. */
|
|
350
|
-
export function SidebarTrigger({
|
|
351
|
-
className,
|
|
352
|
-
onClick,
|
|
353
|
-
label = 'Toggle sidebar',
|
|
354
|
-
...props
|
|
355
|
-
}: ComponentProps<'button'> & { label?: string }) {
|
|
356
|
-
const { open, state, toggleSidebar } = useSidebar()
|
|
357
|
-
const [expanded, collapsed] = useMatch(state, SIDEBAR_STATES)
|
|
358
|
-
const bind = useAttributes<HTMLButtonElement>({ 'aria-expanded': open })
|
|
359
|
-
|
|
360
|
-
return (
|
|
361
|
-
<button
|
|
362
|
-
ref={bind}
|
|
363
|
-
type="button"
|
|
364
|
-
data-sidebar="trigger"
|
|
365
|
-
data-slot="sidebar-trigger"
|
|
366
|
-
aria-label={label}
|
|
367
|
-
onClick={(event) => {
|
|
368
|
-
onClick?.(event)
|
|
369
|
-
toggleSidebar()
|
|
370
|
-
}}
|
|
371
|
-
className={cn(
|
|
372
|
-
'inline-flex size-9 items-center justify-center rounded-2xl text-ink-soft motion-color hover:bg-surface-2 hover:text-ink focus-visible:outline-2 focus-visible:outline-sidebar-ring',
|
|
373
|
-
className,
|
|
374
|
-
)}
|
|
375
|
-
{...props}
|
|
376
|
-
>
|
|
377
|
-
<Show when={expanded}>
|
|
378
|
-
<span className="motion-icon-swap">
|
|
379
|
-
<PanelLeftClose className="size-4" aria-hidden="true" />
|
|
380
|
-
</span>
|
|
381
|
-
</Show>
|
|
382
|
-
<Show when={collapsed}>
|
|
383
|
-
<span className="motion-icon-swap">
|
|
384
|
-
<PanelLeftOpen className="size-4" aria-hidden="true" />
|
|
385
|
-
</span>
|
|
386
|
-
</Show>
|
|
387
|
-
</button>
|
|
388
|
-
)
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/** Slim strip on the sidebar edge: click it to collapse or expand. */
|
|
392
|
-
export function SidebarRail({
|
|
393
|
-
className,
|
|
394
|
-
label = 'Toggle sidebar',
|
|
395
|
-
...props
|
|
396
|
-
}: ComponentProps<'button'> & { label?: string }) {
|
|
397
|
-
const { toggleSidebar } = useSidebar()
|
|
398
|
-
|
|
399
|
-
return (
|
|
400
|
-
<button
|
|
401
|
-
type="button"
|
|
402
|
-
data-sidebar="rail"
|
|
403
|
-
data-slot="sidebar-rail"
|
|
404
|
-
aria-label={label}
|
|
405
|
-
tabIndex={-1}
|
|
406
|
-
onClick={toggleSidebar}
|
|
407
|
-
title={label}
|
|
408
|
-
className={cn(
|
|
409
|
-
'absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 motion-color after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex',
|
|
410
|
-
'group-data-[side=left]:-right-4 group-data-[side=right]:left-0',
|
|
411
|
-
'in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize',
|
|
412
|
-
className,
|
|
413
|
-
)}
|
|
414
|
-
{...props}
|
|
415
|
-
/>
|
|
416
|
-
)
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/** The page content next to the sidebar. */
|
|
420
|
-
export function SidebarInset({ className, ...props }: ComponentProps<'main'>) {
|
|
421
|
-
return (
|
|
422
|
-
<main
|
|
423
|
-
data-slot="sidebar-inset"
|
|
424
|
-
className={cn(
|
|
425
|
-
'relative flex min-w-0 w-full flex-1 flex-col bg-paper',
|
|
426
|
-
'md:peer-data-[variant=inset]:rounded-2xl md:peer-data-[variant=inset]:border md:peer-data-[variant=inset]:border-line',
|
|
427
|
-
className,
|
|
428
|
-
)}
|
|
429
|
-
{...props}
|
|
430
|
-
/>
|
|
431
|
-
)
|
|
432
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { State } from '@blankways/state'
|
|
2
|
-
import { useAttributes, useState } from '@blankways/state-react'
|
|
3
|
-
import type { ReactNode } from 'react'
|
|
4
|
-
import { cn } from '../../internals/cn.js'
|
|
5
|
-
import { ChevronRight } from '../../icons/sidebar.js'
|
|
6
|
-
import {
|
|
7
|
-
SIDEBAR_MENU_SUB_CLASS,
|
|
8
|
-
SidebarMenuButton,
|
|
9
|
-
SidebarMenuItem,
|
|
10
|
-
} from './SidebarParts.js'
|
|
11
|
-
import { useSidebar } from './useSidebar.js'
|
|
12
|
-
|
|
13
|
-
type SidebarCollapsibleProps = {
|
|
14
|
-
icon: ReactNode
|
|
15
|
-
label: string
|
|
16
|
-
/** Marks the entry as current, e.g. when one of its sub-entries is. */
|
|
17
|
-
isActive?: boolean
|
|
18
|
-
defaultOpen?: boolean
|
|
19
|
-
/** `SidebarMenuSubItem`s. */
|
|
20
|
-
children: ReactNode
|
|
21
|
-
className?: string
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A menu entry that opens a nested list. When the sidebar is collapsed to
|
|
26
|
-
* icons, a click expands the sidebar first because the list has no room.
|
|
27
|
-
*/
|
|
28
|
-
export function SidebarCollapsible({
|
|
29
|
-
icon,
|
|
30
|
-
label,
|
|
31
|
-
isActive,
|
|
32
|
-
defaultOpen = false,
|
|
33
|
-
children,
|
|
34
|
-
className,
|
|
35
|
-
}: SidebarCollapsibleProps) {
|
|
36
|
-
const open = useState<boolean>(defaultOpen)
|
|
37
|
-
const { state, isMobile, setOpen } = useSidebar()
|
|
38
|
-
const bind = useAttributes<HTMLSpanElement>({ 'data-open': open })
|
|
39
|
-
const bindPanel = useAttributes<HTMLDivElement>({ 'data-open': open })
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<SidebarMenuItem className={className}>
|
|
43
|
-
<SidebarMenuButton
|
|
44
|
-
isActive={isActive}
|
|
45
|
-
tooltip={label}
|
|
46
|
-
onClick={() => {
|
|
47
|
-
State.set(open, !State.get(open))
|
|
48
|
-
if (
|
|
49
|
-
State.get(state) === 'collapsed' &&
|
|
50
|
-
!State.get(isMobile)
|
|
51
|
-
) {
|
|
52
|
-
setOpen(true)
|
|
53
|
-
}
|
|
54
|
-
}}
|
|
55
|
-
>
|
|
56
|
-
{icon}
|
|
57
|
-
<span>{label}</span>
|
|
58
|
-
<span
|
|
59
|
-
ref={bind}
|
|
60
|
-
aria-hidden="true"
|
|
61
|
-
className="sidebar-chevron ml-auto group-data-[collapsible=icon]:hidden"
|
|
62
|
-
>
|
|
63
|
-
<ChevronRight className="size-4" aria-hidden="true" />
|
|
64
|
-
</span>
|
|
65
|
-
</SidebarMenuButton>
|
|
66
|
-
<div ref={bindPanel} className="accordion-panel">
|
|
67
|
-
<ul
|
|
68
|
-
data-slot="sidebar-menu-sub"
|
|
69
|
-
data-sidebar="menu-sub"
|
|
70
|
-
className={cn(SIDEBAR_MENU_SUB_CLASS)}
|
|
71
|
-
>
|
|
72
|
-
{children}
|
|
73
|
-
</ul>
|
|
74
|
-
</div>
|
|
75
|
-
</SidebarMenuItem>
|
|
76
|
-
)
|
|
77
|
-
}
|