@blankways/ui 0.0.0-stage → 0.1.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 +228 -2
- package/dist/cli/cli.options.d.ts +5 -0
- package/dist/cli/cli.options.js +53 -0
- package/dist/cli/cli.registry.d.ts +6 -0
- package/dist/cli/cli.registry.js +37 -0
- package/dist/cli/cli.types.d.ts +32 -0
- package/dist/cli/cli.types.js +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +47 -0
- package/dist/commands/add.command.d.ts +2 -0
- package/dist/commands/add.command.js +101 -0
- package/dist/commands/doctor.command.d.ts +3 -0
- package/dist/commands/doctor.command.js +92 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/init.command.d.ts +2 -0
- package/dist/commands/init.command.js +38 -0
- package/dist/commands/list.command.d.ts +2 -0
- package/dist/commands/list.command.js +54 -0
- package/dist/commands/meta.command.d.ts +1 -0
- package/dist/commands/meta.command.js +19 -0
- package/dist/commands/styles.command.d.ts +6 -0
- package/dist/commands/styles.command.js +68 -0
- package/dist/config/config.helpers.d.ts +7 -0
- package/dist/config/config.helpers.js +63 -0
- package/dist/config/framework.helpers.d.ts +3 -0
- package/dist/config/framework.helpers.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/constants/cli.constants.d.ts +9 -0
- package/dist/constants/cli.constants.js +15 -0
- package/dist/constants/framework.constants.d.ts +3 -0
- package/dist/constants/framework.constants.js +2 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +2 -0
- package/dist/doctor/checks/entries.check.d.ts +1 -0
- package/dist/doctor/checks/entries.check.js +21 -0
- package/dist/doctor/checks/icons.check.d.ts +1 -0
- package/dist/doctor/checks/icons.check.js +55 -0
- package/dist/doctor/checks/imports.check.d.ts +1 -0
- package/dist/doctor/checks/imports.check.js +45 -0
- package/dist/doctor/checks/index.d.ts +7 -0
- package/dist/doctor/checks/index.js +7 -0
- package/dist/doctor/checks/motion.check.d.ts +1 -0
- package/dist/doctor/checks/motion.check.js +66 -0
- package/dist/doctor/checks/peers.check.d.ts +1 -0
- package/dist/doctor/checks/peers.check.js +55 -0
- package/dist/doctor/checks/styles.check.d.ts +1 -0
- package/dist/doctor/checks/styles.check.js +45 -0
- package/dist/doctor/checks/themes.check.d.ts +1 -0
- package/dist/doctor/checks/themes.check.js +64 -0
- package/dist/doctor/doctor.helpers.d.ts +6 -0
- package/dist/doctor/doctor.helpers.js +39 -0
- package/dist/doctor/doctor.registry.d.ts +10 -0
- package/dist/doctor/doctor.registry.js +24 -0
- package/dist/doctor/doctor.types.d.ts +27 -0
- package/dist/doctor/doctor.types.js +1 -0
- package/dist/doctor/index.d.ts +3 -0
- package/dist/doctor/index.js +3 -0
- package/dist/errors/cli-error.d.ts +3 -0
- package/dist/errors/cli-error.js +6 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/helpers/args.helpers.d.ts +4 -0
- package/dist/helpers/args.helpers.js +75 -0
- package/dist/helpers/help.helpers.d.ts +1 -0
- package/dist/helpers/help.helpers.js +30 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +5 -0
- package/dist/helpers/package.helpers.d.ts +2 -0
- package/dist/helpers/package.helpers.js +12 -0
- package/dist/helpers/path.helpers.d.ts +3 -0
- package/dist/helpers/path.helpers.js +15 -0
- package/dist/helpers/styles.helpers.d.ts +21 -0
- package/dist/helpers/styles.helpers.js +164 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.js +1 -0
- package/dist/registry/registry.helpers.d.ts +22 -0
- package/dist/registry/registry.helpers.js +328 -0
- package/dist/registry-data/README.md +71 -0
- package/dist/registry-data/avatar/Avatar.tsx +64 -0
- package/dist/registry-data/avatar/component.json +30 -0
- package/dist/registry-data/avatar/index.ts +1 -0
- package/dist/registry-data/badge/Badge.tsx +76 -0
- package/dist/registry-data/badge/component.json +30 -0
- package/dist/registry-data/badge/index.ts +1 -0
- package/dist/registry-data/brand-logo/BrandLogo.tsx +24 -0
- package/dist/registry-data/brand-logo/component.json +26 -0
- package/dist/registry-data/brand-logo/index.ts +1 -0
- package/dist/registry-data/button/Button.tsx +76 -0
- package/dist/registry-data/button/component.json +33 -0
- package/dist/registry-data/button/index.ts +1 -0
- package/dist/registry-data/button-link/ButtonLink.tsx +83 -0
- package/dist/registry-data/button-link/component.json +33 -0
- package/dist/registry-data/button-link/index.ts +5 -0
- package/dist/registry-data/button-styles/component.json +19 -0
- package/dist/registry-data/button-styles/index.ts +45 -0
- package/dist/registry-data/cn/cn.ts +6 -0
- package/dist/registry-data/cn/component.json +16 -0
- package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +134 -0
- package/dist/registry-data/confirm-dialog/component.json +34 -0
- package/dist/registry-data/confirm-dialog/index.ts +1 -0
- package/dist/registry-data/container/Container.tsx +22 -0
- package/dist/registry-data/container/component.json +28 -0
- package/dist/registry-data/container/index.ts +1 -0
- package/dist/registry-data/cursor-glow/CursorGlow.tsx +29 -0
- package/dist/registry-data/cursor-glow/component.json +28 -0
- package/dist/registry-data/cursor-glow/index.ts +1 -0
- package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +157 -0
- package/dist/registry-data/dropdown-menu/component.json +34 -0
- package/dist/registry-data/dropdown-menu/index.ts +5 -0
- package/dist/registry-data/empty-state/EmptyState.tsx +92 -0
- package/dist/registry-data/empty-state/component.json +30 -0
- package/dist/registry-data/empty-state/index.ts +5 -0
- package/dist/registry-data/eyebrow/Eyebrow.tsx +68 -0
- package/dist/registry-data/eyebrow/component.json +30 -0
- package/dist/registry-data/eyebrow/index.ts +1 -0
- package/dist/registry-data/field-styles/component.json +19 -0
- package/dist/registry-data/field-styles/index.ts +42 -0
- package/dist/registry-data/form-dialog/FormDialog.tsx +128 -0
- package/dist/registry-data/form-dialog/component.json +34 -0
- package/dist/registry-data/form-dialog/index.ts +1 -0
- package/dist/registry-data/icons/component.json +22 -0
- package/dist/registry-data/icons/index.ts +21 -0
- package/dist/registry-data/icons-form/component.json +17 -0
- package/dist/registry-data/icons-form/index.ts +1 -0
- package/dist/registry-data/icons-sidebar/component.json +17 -0
- package/dist/registry-data/icons-sidebar/index.ts +1 -0
- package/dist/registry-data/icons-theme/component.json +17 -0
- package/dist/registry-data/icons-theme/index.ts +1 -0
- package/dist/registry-data/icons-toast/component.json +17 -0
- package/dist/registry-data/icons-toast/index.ts +1 -0
- package/dist/registry-data/info-dialog/InfoDialog.tsx +119 -0
- package/dist/registry-data/info-dialog/component.json +36 -0
- package/dist/registry-data/info-dialog/index.ts +1 -0
- package/dist/registry-data/input/Input.tsx +96 -0
- package/dist/registry-data/input/component.json +33 -0
- package/dist/registry-data/input/index.ts +1 -0
- package/dist/registry-data/multi-combobox/MultiCombobox.tsx +205 -0
- package/dist/registry-data/multi-combobox/component.json +35 -0
- package/dist/registry-data/multi-combobox/index.ts +5 -0
- package/dist/registry-data/remote-provider/RemoteProvider.tsx +8 -0
- package/dist/registry-data/remote-provider/component.json +25 -0
- package/dist/registry-data/remote-provider/index.ts +3 -0
- package/dist/registry-data/reveal/Reveal.tsx +22 -0
- package/dist/registry-data/reveal/component.json +30 -0
- package/dist/registry-data/reveal/index.ts +1 -0
- package/dist/registry-data/section/Section.tsx +80 -0
- package/dist/registry-data/section/component.json +30 -0
- package/dist/registry-data/section/index.ts +1 -0
- package/dist/registry-data/section-heading/SectionHeading.tsx +105 -0
- package/dist/registry-data/section-heading/component.json +32 -0
- package/dist/registry-data/section-heading/index.ts +1 -0
- package/dist/registry-data/select/Select.tsx +197 -0
- package/dist/registry-data/select/component.json +34 -0
- package/dist/registry-data/select/index.ts +1 -0
- package/dist/registry-data/sidebar/Sidebar.tsx +432 -0
- package/dist/registry-data/sidebar/SidebarCollapsible.tsx +77 -0
- package/dist/registry-data/sidebar/SidebarParts.tsx +373 -0
- package/dist/registry-data/sidebar/component.json +47 -0
- package/dist/registry-data/sidebar/index.ts +4 -0
- package/dist/registry-data/sidebar/useSidebar.ts +29 -0
- package/dist/registry-data/styles-base/component.json +19 -0
- package/dist/registry-data/styles-base/index.css +67 -0
- package/dist/registry-data/styles-components/component.json +19 -0
- package/dist/registry-data/styles-components/index.css +30 -0
- package/dist/registry-data/styles-motion/component.json +20 -0
- package/dist/registry-data/styles-motion/index.css +381 -0
- package/dist/registry-data/styles-tokens/component.json +17 -0
- package/dist/registry-data/styles-tokens/index.css +77 -0
- package/dist/registry-data/styles-utilities/component.json +19 -0
- package/dist/registry-data/styles-utilities/index.css +29 -0
- package/dist/registry-data/switch/Switch.tsx +91 -0
- package/dist/registry-data/switch/component.json +34 -0
- package/dist/registry-data/switch/index.ts +1 -0
- package/dist/registry-data/tabs/Tabs.tsx +226 -0
- package/dist/registry-data/tabs/component.json +32 -0
- package/dist/registry-data/tabs/index.ts +1 -0
- package/dist/registry-data/textarea/Textarea.tsx +94 -0
- package/dist/registry-data/textarea/component.json +33 -0
- package/dist/registry-data/textarea/index.ts +1 -0
- package/dist/registry-data/theme-core/component.json +17 -0
- package/dist/registry-data/theme-core/theme.ts +84 -0
- package/dist/registry-data/theme-dark/component.json +19 -0
- package/dist/registry-data/theme-dark/index.ts +7 -0
- package/dist/registry-data/theme-light/component.json +19 -0
- package/dist/registry-data/theme-light/index.ts +7 -0
- package/dist/registry-data/theme-provider/ThemeContext.tsx +177 -0
- package/dist/registry-data/theme-provider/component.json +30 -0
- package/dist/registry-data/theme-provider/index.ts +2 -0
- package/dist/registry-data/theme-selector/ThemeSelector.tsx +269 -0
- package/dist/registry-data/theme-selector/component.json +35 -0
- package/dist/registry-data/theme-selector/selector.ts +1 -0
- package/dist/registry-data/theme-system/component.json +19 -0
- package/dist/registry-data/theme-system/index.ts +7 -0
- package/dist/registry-data/theme-toggle/ThemeToggle.tsx +71 -0
- package/dist/registry-data/theme-toggle/component.json +31 -0
- package/dist/registry-data/theme-toggle/toggle.ts +1 -0
- package/dist/registry-data/toast/Toast.tsx +260 -0
- package/dist/registry-data/toast/ToastTypeIcon.tsx +83 -0
- package/dist/registry-data/toast/component.json +43 -0
- package/dist/registry-data/toast/index.ts +3 -0
- package/dist/registry-data/toast/useToast.ts +47 -0
- package/dist/types/cli.types.d.ts +6 -0
- package/dist/types/cli.types.js +1 -0
- package/dist/types/config.types.d.ts +41 -0
- package/dist/types/config.types.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/registry.types.d.ts +37 -0
- package/dist/types/registry.types.js +1 -0
- package/package.json +35 -3
|
@@ -0,0 +1,432 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
}
|