@lerianstudio/sindarian-ui 2.0.0-beta.7 → 2.0.0-beta.9
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/dist/components/breadcrumb/index.d.ts.map +1 -1
- package/dist/components/breadcrumb/index.js +25 -1
- package/dist/components/card/account-card/index.js +5 -5
- package/dist/components/card/basic-card/index.d.ts.map +1 -1
- package/dist/components/card/basic-card/index.js +2 -2
- package/dist/components/card/entity-card/index.js +1 -1
- package/dist/components/entity-box/index.d.ts +18 -2
- package/dist/components/entity-box/index.d.ts.map +1 -1
- package/dist/components/entity-box/index.js +32 -4
- package/dist/components/form/password-field/index.d.ts +5 -1
- package/dist/components/form/password-field/index.d.ts.map +1 -1
- package/dist/components/form/password-field/index.js +2 -2
- package/dist/components/page-header/index.js +1 -1
- package/dist/components/table/id-table-cell.d.ts +5 -1
- package/dist/components/table/id-table-cell.d.ts.map +1 -1
- package/dist/components/table/id-table-cell.js +48 -6
- package/dist/components/ui/autocomplete/index.d.ts +24 -0
- package/dist/components/ui/autocomplete/index.d.ts.map +1 -1
- package/dist/components/ui/autocomplete/index.js +24 -0
- package/dist/components/ui/copy-field/index.d.ts.map +1 -1
- package/dist/components/ui/copy-field/index.js +1 -1
- package/dist/components/ui/sheet/index.d.ts.map +1 -1
- package/dist/components/ui/sheet/index.js +2 -2
- package/dist/components/ui/sidebar/index.d.ts +1 -0
- package/dist/components/ui/sidebar/index.d.ts.map +1 -1
- package/dist/components/ui/sidebar/index.js +1 -0
- package/dist/components/ui/sidebar/sidebar-expand-button.d.ts +1 -1
- package/dist/components/ui/sidebar/sidebar-expand-button.d.ts.map +1 -1
- package/dist/components/ui/sidebar/sidebar-expand-button.js +15 -1
- package/dist/components/ui/sidebar/sidebar-item.d.ts +1 -1
- package/dist/components/ui/sidebar/sidebar-item.d.ts.map +1 -1
- package/dist/components/ui/sidebar/sidebar-item.js +28 -4
- package/dist/components/ui/sidebar/sidebar-provider.d.ts +37 -0
- package/dist/components/ui/sidebar/sidebar-provider.d.ts.map +1 -1
- package/dist/components/ui/sidebar/sidebar-provider.js +125 -4
- package/dist/components/ui/sidebar/sidebar-root.d.ts +38 -1
- package/dist/components/ui/sidebar/sidebar-root.d.ts.map +1 -1
- package/dist/components/ui/sidebar/sidebar-root.js +100 -5
- package/dist/components/ui/sidebar/sidebar-trigger.d.ts +18 -0
- package/dist/components/ui/sidebar/sidebar-trigger.d.ts.map +1 -0
- package/dist/components/ui/sidebar/sidebar-trigger.js +30 -0
- package/dist/esm/components/breadcrumb/index.d.ts.map +1 -1
- package/dist/esm/components/breadcrumb/index.js +25 -1
- package/dist/esm/components/card/account-card/index.js +5 -5
- package/dist/esm/components/card/basic-card/index.d.ts.map +1 -1
- package/dist/esm/components/card/basic-card/index.js +2 -2
- package/dist/esm/components/card/entity-card/index.js +1 -1
- package/dist/esm/components/entity-box/index.d.ts +18 -2
- package/dist/esm/components/entity-box/index.d.ts.map +1 -1
- package/dist/esm/components/entity-box/index.js +29 -4
- package/dist/esm/components/form/password-field/index.d.ts +5 -1
- package/dist/esm/components/form/password-field/index.d.ts.map +1 -1
- package/dist/esm/components/form/password-field/index.js +2 -2
- package/dist/esm/components/page-header/index.js +1 -1
- package/dist/esm/components/table/id-table-cell.d.ts +5 -1
- package/dist/esm/components/table/id-table-cell.d.ts.map +1 -1
- package/dist/esm/components/table/id-table-cell.js +48 -3
- package/dist/esm/components/ui/autocomplete/index.d.ts +24 -0
- package/dist/esm/components/ui/autocomplete/index.d.ts.map +1 -1
- package/dist/esm/components/ui/autocomplete/index.js +24 -0
- package/dist/esm/components/ui/copy-field/index.d.ts.map +1 -1
- package/dist/esm/components/ui/copy-field/index.js +1 -1
- package/dist/esm/components/ui/sheet/index.d.ts.map +1 -1
- package/dist/esm/components/ui/sheet/index.js +2 -2
- package/dist/esm/components/ui/sidebar/index.d.ts +1 -0
- package/dist/esm/components/ui/sidebar/index.d.ts.map +1 -1
- package/dist/esm/components/ui/sidebar/index.js +1 -0
- package/dist/esm/components/ui/sidebar/sidebar-expand-button.d.ts +1 -1
- package/dist/esm/components/ui/sidebar/sidebar-expand-button.d.ts.map +1 -1
- package/dist/esm/components/ui/sidebar/sidebar-expand-button.js +15 -1
- package/dist/esm/components/ui/sidebar/sidebar-item.d.ts +1 -1
- package/dist/esm/components/ui/sidebar/sidebar-item.d.ts.map +1 -1
- package/dist/esm/components/ui/sidebar/sidebar-item.js +28 -4
- package/dist/esm/components/ui/sidebar/sidebar-provider.d.ts +37 -0
- package/dist/esm/components/ui/sidebar/sidebar-provider.d.ts.map +1 -1
- package/dist/esm/components/ui/sidebar/sidebar-provider.js +122 -1
- package/dist/esm/components/ui/sidebar/sidebar-root.d.ts +38 -1
- package/dist/esm/components/ui/sidebar/sidebar-root.d.ts.map +1 -1
- package/dist/esm/components/ui/sidebar/sidebar-root.js +102 -7
- package/dist/esm/components/ui/sidebar/sidebar-trigger.d.ts +18 -0
- package/dist/esm/components/ui/sidebar/sidebar-trigger.d.ts.map +1 -0
- package/dist/esm/components/ui/sidebar/sidebar-trigger.js +26 -0
- package/dist/globals.css +49 -3
- package/package.json +1 -1
|
@@ -2,7 +2,28 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { getStorage, getStorageObject } from '../../../lib/storage/index.js';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The viewport below which the rail stops being a layout and becomes a drawer.
|
|
7
|
+
*
|
|
8
|
+
* 767px rather than 768px: this is the upper bound of `max-width`, so it is the
|
|
9
|
+
* complement of Tailwind's `md` breakpoint (`min-width: 768px`) and `md:hidden`
|
|
10
|
+
* on `SidebarTrigger` flips at exactly the same pixel the query does.
|
|
11
|
+
*/
|
|
12
|
+
export const SIDEBAR_MOBILE_QUERY = '(max-width: 767px)';
|
|
13
|
+
/**
|
|
14
|
+
* Where focus goes when the rail has to receive it. The rail's own content is
|
|
15
|
+
* links and buttons, so this is deliberately the short list rather than the
|
|
16
|
+
* full tabbable grammar: a `[tabindex]` sweep would have to exclude `-1`, and
|
|
17
|
+
* nothing in a sidebar carries one.
|
|
18
|
+
*/
|
|
19
|
+
const FOCUSABLE = 'a[href], button:not([disabled])';
|
|
20
|
+
/**
|
|
21
|
+
* Exported so `SidebarRoot` can re-provide it for the drawer's subtree. That
|
|
22
|
+
* subtree is the only place `isCollapsed` and `isDrawer` differ from the
|
|
23
|
+
* provider's own values, and scoping the override to it is what keeps a
|
|
24
|
+
* consumer on `mobile="inline"` seeing exactly today's rail.
|
|
25
|
+
*/
|
|
26
|
+
export const SidebarContext = React.createContext(undefined);
|
|
6
27
|
export const useSidebar = () => {
|
|
7
28
|
const context = React.useContext(SidebarContext);
|
|
8
29
|
if (!context) {
|
|
@@ -14,6 +35,61 @@ export const SidebarProvider = ({ children }) => {
|
|
|
14
35
|
const [hydrated, setHydrated] = React.useState(false);
|
|
15
36
|
const [collapsed, setCollapsed] = React.useState(false);
|
|
16
37
|
const [items, _setItems] = React.useState({});
|
|
38
|
+
const [isMobile, setIsMobile] = React.useState(false);
|
|
39
|
+
const [openMobile, _setOpenMobile] = React.useState(false);
|
|
40
|
+
const sidebarId = React.useId();
|
|
41
|
+
/**
|
|
42
|
+
* ⛔ RADIX CANNOT RESTORE THIS FOCUS BY ITSELF. `DialogContent` preventDefaults
|
|
43
|
+
* the focus scope's own restore and focuses `triggerRef.current` instead —
|
|
44
|
+
* the ref a `SheetTrigger` would have filled. The drawer is opened from this
|
|
45
|
+
* state rather than from a trigger inside the dialog, so that ref is null and
|
|
46
|
+
* closing dropped focus onto `<body>`: a keyboard reader who opened the
|
|
47
|
+
* navigation and pressed Escape was returned to the top of the document.
|
|
48
|
+
*
|
|
49
|
+
* Captured here rather than in `SidebarTrigger` so that a consumer opening
|
|
50
|
+
* the drawer from its own control gets the same behaviour.
|
|
51
|
+
*/
|
|
52
|
+
const opener = React.useRef(null);
|
|
53
|
+
const setOpenMobile = React.useCallback((open) => {
|
|
54
|
+
if (open && typeof document !== 'undefined') {
|
|
55
|
+
opener.current = document.activeElement;
|
|
56
|
+
}
|
|
57
|
+
_setOpenMobile(open);
|
|
58
|
+
}, []);
|
|
59
|
+
/**
|
|
60
|
+
* ⛔ THE VIEWPORT AT THE MOMENT FOCUS MOVES, NOT AT THE MOMENT IT OPENED.
|
|
61
|
+
*
|
|
62
|
+
* Radix calls `restoreDrawerFocus` from the focus scope's UNMOUNT handler,
|
|
63
|
+
* which is the last thing in the commit to touch focus — later than any
|
|
64
|
+
* effect in this provider, so the decision has to be made inside the handler
|
|
65
|
+
* rather than beside it. By then `isMobile` has already flipped.
|
|
66
|
+
*/
|
|
67
|
+
const isMobileRef = React.useRef(false);
|
|
68
|
+
isMobileRef.current = isMobile;
|
|
69
|
+
const restoreDrawerFocus = React.useCallback(() => {
|
|
70
|
+
// `isConnected`: the control that opened the drawer may itself have been
|
|
71
|
+
// unmounted by whatever the reader did inside it.
|
|
72
|
+
//
|
|
73
|
+
// ⛔ AND NOT AT ALL WHEN THE VIEWPORT IS THE ONE THAT DISMISSED IT. A
|
|
74
|
+
// tablet rotated from portrait to landscape with the navigation open
|
|
75
|
+
// crosses 768px, so the drawer is replaced by the rail and the opener is
|
|
76
|
+
// `SidebarTrigger` — which the same breakpoint just hid with `md:hidden`.
|
|
77
|
+
// `.focus()` on a `display: none` element is a silent no-op, and Radix's
|
|
78
|
+
// own restore is already `preventDefault()`ed, so focus fell to `<body>`
|
|
79
|
+
// and the reader lost their place (SC 2.4.3). Measured in Chromium at
|
|
80
|
+
// 390 → 1280: `{"rails":1,"triggerDisplay":"none","focus":"BODY:"}`.
|
|
81
|
+
if (isMobileRef.current && opener.current?.isConnected) {
|
|
82
|
+
opener.current.focus();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// The rail is what the drawer became, so that is where the reader goes.
|
|
86
|
+
// Below the breakpoint there is nothing here to find — a closed drawer
|
|
87
|
+
// leaves no navigation in the DOM — and focus stays where Radix left it.
|
|
88
|
+
document
|
|
89
|
+
.getElementById(sidebarId)
|
|
90
|
+
?.querySelector(FOCUSABLE)
|
|
91
|
+
?.focus();
|
|
92
|
+
}, [sidebarId]);
|
|
17
93
|
const toggleSidebar = () => setCollapsed((collapsed) => !collapsed);
|
|
18
94
|
const getItemCollapsed = (key) => {
|
|
19
95
|
return items[key] || false;
|
|
@@ -27,6 +103,37 @@ export const SidebarProvider = ({ children }) => {
|
|
|
27
103
|
_setItems(getStorageObject('sidebar-items', {}));
|
|
28
104
|
setHydrated(true);
|
|
29
105
|
}, []);
|
|
106
|
+
/**
|
|
107
|
+
* ⚠️ FALSE UNTIL THE CLIENT SAYS OTHERWISE. There is no viewport on the
|
|
108
|
+
* server, so the first paint is always the rail and the drawer appears on
|
|
109
|
+
* hydration; starting from a guess would make the markup differ between the
|
|
110
|
+
* two renders. The `matchMedia` guard is the one `theme-provider.tsx` next
|
|
111
|
+
* door already carries: jsdom and some embedded runtimes ship without it, and
|
|
112
|
+
* a missing media API is a desktop, not a crash.
|
|
113
|
+
*/
|
|
114
|
+
React.useEffect(() => {
|
|
115
|
+
if (typeof window.matchMedia !== 'function') {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const media = window.matchMedia(SIDEBAR_MOBILE_QUERY);
|
|
119
|
+
const sync = () => setIsMobile(media.matches);
|
|
120
|
+
sync();
|
|
121
|
+
media.addEventListener('change', sync);
|
|
122
|
+
return () => media.removeEventListener('change', sync);
|
|
123
|
+
}, []);
|
|
124
|
+
/**
|
|
125
|
+
* A drawer left open while the viewport grows back would keep an overlay and
|
|
126
|
+
* a focus trap over a layout that is already showing its rail, with nothing
|
|
127
|
+
* on screen to dismiss them.
|
|
128
|
+
*
|
|
129
|
+
* Where focus goes afterwards is `restoreDrawerFocus`'s decision, not this
|
|
130
|
+
* effect's: Radix's unmount handler runs later than anything here.
|
|
131
|
+
*/
|
|
132
|
+
React.useEffect(() => {
|
|
133
|
+
if (!isMobile) {
|
|
134
|
+
_setOpenMobile(false);
|
|
135
|
+
}
|
|
136
|
+
}, [isMobile]);
|
|
30
137
|
// Only persist to localStorage after hydration to avoid overwriting stored values
|
|
31
138
|
React.useEffect(() => {
|
|
32
139
|
if (!hydrated) {
|
|
@@ -41,7 +148,21 @@ export const SidebarProvider = ({ children }) => {
|
|
|
41
148
|
localStorage.setItem('sidebar-items', JSON.stringify(items));
|
|
42
149
|
}, [items, hydrated]);
|
|
43
150
|
return (_jsx(SidebarContext.Provider, { value: {
|
|
151
|
+
/**
|
|
152
|
+
* ⚠️ A NARROW VIEWPORT DOES NOT TOUCH THIS. It used to be forced false
|
|
153
|
+
* whenever `isMobile`, which silently changed the rail for every
|
|
154
|
+
* consumer — including the ones that never asked for a drawer.
|
|
155
|
+
* `SidebarRoot` overrides it for the drawer's own subtree instead, so
|
|
156
|
+
* the stored preference reaches an inline rail unchanged at every
|
|
157
|
+
* viewport.
|
|
158
|
+
*/
|
|
44
159
|
isCollapsed: collapsed,
|
|
160
|
+
isDrawer: false,
|
|
161
|
+
isMobile,
|
|
162
|
+
openMobile,
|
|
163
|
+
setOpenMobile,
|
|
164
|
+
restoreDrawerFocus,
|
|
165
|
+
sidebarId,
|
|
45
166
|
items,
|
|
46
167
|
setItems: _setItems,
|
|
47
168
|
getItemCollapsed,
|
|
@@ -1,3 +1,40 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export
|
|
2
|
+
export type SidebarRootProps = React.ComponentProps<'nav'> & {
|
|
3
|
+
/**
|
|
4
|
+
* What this rail becomes below 768px.
|
|
5
|
+
*
|
|
6
|
+
* - `'inline'` (default): nothing changes. The rail renders at every
|
|
7
|
+
* viewport exactly as it always has, and the reader's collapsed preference
|
|
8
|
+
* is untouched.
|
|
9
|
+
* - `'drawer'`: the inline rail is not rendered below the breakpoint and the
|
|
10
|
+
* navigation moves into an overlay drawer that `SidebarTrigger` opens.
|
|
11
|
+
*
|
|
12
|
+
* ⛔ THE DEFAULT IS NOT A TASTE, IT IS A CONSUMER-SAFETY RULE. `SidebarTrigger`
|
|
13
|
+
* is the only way back into the drawer and it must render inside
|
|
14
|
+
* `SidebarProvider`. A consumer that has not placed one yet — which is every
|
|
15
|
+
* consumer at the moment this shipped — would get a phone with NO navigation
|
|
16
|
+
* rather than a rail that takes 63% of it, and that is strictly worse. Opt in
|
|
17
|
+
* once there is somewhere to put the trigger.
|
|
18
|
+
*/
|
|
19
|
+
mobile?: 'inline' | 'drawer';
|
|
20
|
+
/**
|
|
21
|
+
* The drawer's accessible name. A dialog needs one, and it is read out when
|
|
22
|
+
* the drawer opens. Unused while `mobile` is `'inline'`.
|
|
23
|
+
*/
|
|
24
|
+
mobileTitle?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* ⛔ BELOW 768px A RAIL IS NOT A LAYOUT — once a consumer opts in.
|
|
28
|
+
*
|
|
29
|
+
* The widths above are a fixed share of a flex row, so at 390px the expanded
|
|
30
|
+
* rail took 63% of the screen and left the page 146px, and the only affordance
|
|
31
|
+
* — `SidebarExpandButton` — shrinks it to 72px, which is still 18% and still
|
|
32
|
+
* permanently on screen. There was nothing that removed it.
|
|
33
|
+
*
|
|
34
|
+
* With `mobile="drawer"` the rail is replaced below the breakpoint by an
|
|
35
|
+
* overlay drawer. Escape, the backdrop click, the focus trap and returning
|
|
36
|
+
* focus to whatever opened it are Radix Dialog's, through the kit's own
|
|
37
|
+
* `Sheet`; none of that is re-implemented here.
|
|
38
|
+
*/
|
|
39
|
+
export declare const SidebarRoot: ({ className, id, mobile, mobileTitle, ...props }: SidebarRootProps) => React.JSX.Element;
|
|
3
40
|
//# sourceMappingURL=sidebar-root.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sidebar-root.d.ts","sourceRoot":"","sources":["../../../../../src/components/ui/sidebar/sidebar-root.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"sidebar-root.d.ts","sourceRoot":"","sources":["../../../../../src/components/ui/sidebar/sidebar-root.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAqEzB,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG;IAC3D;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GAAI,kDAMzB,gBAAgB,sBA0GlB,CAAA"}
|
|
@@ -1,20 +1,115 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { cva } from 'class-variance-authority';
|
|
4
|
-
import { useSidebar } from './sidebar-provider.js';
|
|
4
|
+
import { SidebarContext, useSidebar } from './sidebar-provider.js';
|
|
5
5
|
import { cn } from '../../../lib/utils.js';
|
|
6
|
+
import { Sheet, SheetContent, SheetTitle } from '../sheet/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* ⛔ THE WIDTHS ARE TOKENS, NOT LITERALS.
|
|
9
|
+
*
|
|
10
|
+
* They were `w-[72px]` and `w-[244px]`, which a consumer could only override by
|
|
11
|
+
* winning a specificity argument with `cn`. `--sidebar-width` and
|
|
12
|
+
* `--sidebar-width-collapsed` are declared in `globals.css`, so the default
|
|
13
|
+
* still ships with the stylesheet, and a consumer re-points either one with
|
|
14
|
+
* `className="[--sidebar-width:280px]"` ON THE RAIL, which moves the rail and
|
|
15
|
+
* the mobile drawer together (see `liftWidthOverrides` below), or with a rule
|
|
16
|
+
* on `:root`/`html`.
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ A DECLARATION ON A REACT-TREE ANCESTOR REACHES THE RAIL AND NOT THE
|
|
19
|
+
* DRAWER. Custom properties inherit down the DOM tree, and the drawer is
|
|
20
|
+
* portalled to `document.body`, so a layout wrapper is not an ancestor of it.
|
|
21
|
+
* `:root` is, which is why it is named above and a wrapper is not.
|
|
22
|
+
*/
|
|
6
23
|
const sidebarVariants = cva('group/sidebar shadow-sidebar relative flex flex-col transition-[width] duration-300 ease-in-out', {
|
|
7
24
|
variants: {
|
|
8
25
|
collapsed: {
|
|
9
|
-
true: 'w-[
|
|
10
|
-
false: 'w-[
|
|
26
|
+
true: 'w-[var(--sidebar-width-collapsed)]',
|
|
27
|
+
false: 'w-[var(--sidebar-width)]'
|
|
11
28
|
}
|
|
12
29
|
},
|
|
13
30
|
defaultVariants: {
|
|
14
31
|
collapsed: false
|
|
15
32
|
}
|
|
16
33
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Tailwind arbitrary-property classes that re-point the sidebar geometry, e.g.
|
|
36
|
+
* `[--sidebar-width:320px]` or `[--sidebar-width-collapsed:88px]`.
|
|
37
|
+
*
|
|
38
|
+
* ⚠️ ANCHORED TO A CLASS BOUNDARY, WHICH IS THE WHOLE POINT OF THE LOOKBEHIND.
|
|
39
|
+
* Unanchored it also matched the tail of `md:[--sidebar-width:320px]` and
|
|
40
|
+
* lifted it with the prefix stripped — an override a consumer scoped to
|
|
41
|
+
* ≥768px, applied unconditionally to the drawer that only exists below it.
|
|
42
|
+
*/
|
|
43
|
+
const WIDTH_OVERRIDE = /(?<=^|\s)\[--sidebar-width(?:-collapsed)?:[^\]]+\]/g;
|
|
44
|
+
/**
|
|
45
|
+
* ⛔ THE ONE PART OF THE CONSUMER'S className THAT HAS TO CROSS THE PORTAL.
|
|
46
|
+
*
|
|
47
|
+
* `SheetContent` mounts through `SheetPortal` into `document.body`, and custom
|
|
48
|
+
* properties inherit down the DOM tree rather than the React tree. So the
|
|
49
|
+
* documented override — a class on the rail — set `--sidebar-width` on an
|
|
50
|
+
* element the drawer is not a descendant of, and the whole className that DOES
|
|
51
|
+
* travel lands on the inner `<nav>`, which is BELOW the element that reads the
|
|
52
|
+
* variable. Measured in Chromium: rail 320px, drawer 244px. Following the
|
|
53
|
+
* instruction handed to product-console produced a 280px rail on desktop and a
|
|
54
|
+
* 244px drawer on a phone, silently.
|
|
55
|
+
*
|
|
56
|
+
* ⚠️ ONLY THE GEOMETRY TOKENS. The rest of a rail className is rail-shaped —
|
|
57
|
+
* `h-full`, and the `data-[collapsed=false]:min-w-70` all eight console
|
|
58
|
+
* sidebars pass — and putting that on the sheet would reinstate the
|
|
59
|
+
* 280px-inside-a-244px-sheet overflow from the other side.
|
|
60
|
+
*/
|
|
61
|
+
function liftWidthOverrides(className) {
|
|
62
|
+
return className?.match(WIDTH_OVERRIDE)?.join(' ');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* ⛔ BELOW 768px A RAIL IS NOT A LAYOUT — once a consumer opts in.
|
|
66
|
+
*
|
|
67
|
+
* The widths above are a fixed share of a flex row, so at 390px the expanded
|
|
68
|
+
* rail took 63% of the screen and left the page 146px, and the only affordance
|
|
69
|
+
* — `SidebarExpandButton` — shrinks it to 72px, which is still 18% and still
|
|
70
|
+
* permanently on screen. There was nothing that removed it.
|
|
71
|
+
*
|
|
72
|
+
* With `mobile="drawer"` the rail is replaced below the breakpoint by an
|
|
73
|
+
* overlay drawer. Escape, the backdrop click, the focus trap and returning
|
|
74
|
+
* focus to whatever opened it are Radix Dialog's, through the kit's own
|
|
75
|
+
* `Sheet`; none of that is re-implemented here.
|
|
76
|
+
*/
|
|
77
|
+
export const SidebarRoot = ({ className, id, mobile = 'inline', mobileTitle = 'Navigation', ...props }) => {
|
|
78
|
+
const context = useSidebar();
|
|
79
|
+
const { isCollapsed, isMobile, openMobile, setOpenMobile, restoreDrawerFocus, sidebarId } = context;
|
|
80
|
+
if (!isMobile || mobile === 'inline') {
|
|
81
|
+
return (_jsx("nav", { "data-slot": "sidebar-root", className: cn(sidebarVariants({ collapsed: isCollapsed }), className), "data-collapsed": isCollapsed, ...props, id: mobile === 'drawer' ? sidebarId : id }));
|
|
82
|
+
}
|
|
83
|
+
return (_jsx(SidebarContext.Provider, { value: { ...context, isCollapsed: false, isDrawer: true }, children: _jsx(Sheet, { open: openMobile, onOpenChange: setOpenMobile, children: _jsxs(SheetContent, { side: "left",
|
|
84
|
+
// The Sheet's own paddings are built for a form panel; a rail brings
|
|
85
|
+
// its own. `max-w-full` so a consumer widening `--sidebar-width` past
|
|
86
|
+
// the viewport still cannot push the drawer off screen. The lifted
|
|
87
|
+
// override goes LAST so it re-points the variable this element reads.
|
|
88
|
+
className: cn('w-[var(--sidebar-width)] max-w-full gap-0 p-0', liftWidthOverrides(className)), "aria-describedby": undefined,
|
|
89
|
+
// ⛔ RADIX'S OWN RESTORE GOES NOWHERE HERE. `DialogContent`
|
|
90
|
+
// preventDefaults the focus scope's restore and focuses the ref a
|
|
91
|
+
// `SheetTrigger` would have filled; this drawer is opened from provider
|
|
92
|
+
// state, so that ref is null and closing dropped focus onto `<body>`.
|
|
93
|
+
// Running first means `composeEventHandlers` skips Radix's half.
|
|
94
|
+
onCloseAutoFocus: (event) => {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
restoreDrawerFocus();
|
|
97
|
+
}, children: [_jsx(SheetTitle, { className: "sr-only", children: mobileTitle }), _jsx("nav", { "data-slot": "sidebar-root", "data-mobile": "true",
|
|
98
|
+
/* ⛔ NO `data-collapsed` HERE. The consumer className is forwarded
|
|
99
|
+
verbatim, and all eight console sidebars pass
|
|
100
|
+
`data-[collapsed=false]:min-w-70`; stamping the attribute armed
|
|
101
|
+
it, giving the navigation a 280px min-width inside a 244px sheet.
|
|
102
|
+
`min-width` resolves after `max-width`, so the sheet could not
|
|
103
|
+
claw it back and the contents were 36px wider than the drawer.
|
|
104
|
+
`data-mobile` already names this surface and a drawer is never
|
|
105
|
+
collapsed, so the attribute had nothing left to say. */
|
|
106
|
+
className: cn(sidebarVariants({ collapsed: false }), 'h-full w-full shadow-none', className), ...props,
|
|
107
|
+
/* ⛔ AFTER THE SPREAD, AND NOT THE CALLER'S. This is the target of
|
|
108
|
+
`SidebarTrigger`'s `aria-controls` and the handle the provider
|
|
109
|
+
uses to put focus back into the navigation when the viewport
|
|
110
|
+
grows. Spread first, a caller that set `id` replaced it and left
|
|
111
|
+
a dangling `aria-controls` — which axe reports as a CRITICAL
|
|
112
|
+
`aria-valid-attr-value` — and a focus restore that lands on
|
|
113
|
+
`<body>`. Both silent. */
|
|
114
|
+
id: sidebarId })] }) }) }));
|
|
20
115
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IconButton } from '../icon-button/index.js';
|
|
3
|
+
export type SidebarTriggerProps = React.ComponentProps<typeof IconButton>;
|
|
4
|
+
/**
|
|
5
|
+
* The control that opens the mobile drawer.
|
|
6
|
+
*
|
|
7
|
+
* `md:hidden` by default because above 768px the rail is already on screen and
|
|
8
|
+
* a second way to reach it is a second thing to explain; a consumer that wants
|
|
9
|
+
* it everywhere passes its own display class.
|
|
10
|
+
*
|
|
11
|
+
* ⚠️ `aria-controls` IS SET ONLY WHILE THE DRAWER EXISTS. Radix unmounts the
|
|
12
|
+
* dialog content when closed, and a reference to an element that is not in the
|
|
13
|
+
* DOM is what axe-core reports as a CRITICAL `aria-valid-attr-value` — the same
|
|
14
|
+
* defect the Autocomplete panel was repaired for (console-sdk#150). A toggle
|
|
15
|
+
* with `aria-expanded="false"` and no `aria-controls` is complete on its own.
|
|
16
|
+
*/
|
|
17
|
+
export declare const SidebarTrigger: ({ className, onClick, "aria-label": ariaLabel, ...props }: SidebarTriggerProps) => React.JSX.Element;
|
|
18
|
+
//# sourceMappingURL=sidebar-trigger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidebar-trigger.d.ts","sourceRoot":"","sources":["../../../../../src/components/ui/sidebar/sidebar-trigger.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAG3C,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,UAAU,CAAC,CAAA;AAEzE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,2DAK5B,mBAAmB,sBAqBrB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Menu } from 'lucide-react';
|
|
4
|
+
import { cn } from '../../../lib/utils.js';
|
|
5
|
+
import { IconButton } from '../icon-button/index.js';
|
|
6
|
+
import { useSidebar } from './sidebar-provider.js';
|
|
7
|
+
/**
|
|
8
|
+
* The control that opens the mobile drawer.
|
|
9
|
+
*
|
|
10
|
+
* `md:hidden` by default because above 768px the rail is already on screen and
|
|
11
|
+
* a second way to reach it is a second thing to explain; a consumer that wants
|
|
12
|
+
* it everywhere passes its own display class.
|
|
13
|
+
*
|
|
14
|
+
* ⚠️ `aria-controls` IS SET ONLY WHILE THE DRAWER EXISTS. Radix unmounts the
|
|
15
|
+
* dialog content when closed, and a reference to an element that is not in the
|
|
16
|
+
* DOM is what axe-core reports as a CRITICAL `aria-valid-attr-value` — the same
|
|
17
|
+
* defect the Autocomplete panel was repaired for (console-sdk#150). A toggle
|
|
18
|
+
* with `aria-expanded="false"` and no `aria-controls` is complete on its own.
|
|
19
|
+
*/
|
|
20
|
+
export const SidebarTrigger = ({ className, onClick, 'aria-label': ariaLabel = 'Open navigation', ...props }) => {
|
|
21
|
+
const { openMobile, setOpenMobile, sidebarId } = useSidebar();
|
|
22
|
+
return (_jsx(IconButton, { type: "button", variant: "outline", "data-slot": "sidebar-trigger", "aria-label": ariaLabel, "aria-expanded": openMobile, "aria-controls": openMobile ? sidebarId : undefined, className: cn('md:hidden', className), onClick: (event) => {
|
|
23
|
+
onClick?.(event);
|
|
24
|
+
setOpenMobile(!openMobile);
|
|
25
|
+
}, ...props, children: _jsx(Menu, { "aria-hidden": true }) }));
|
|
26
|
+
};
|
package/dist/globals.css
CHANGED
|
@@ -214,6 +214,28 @@
|
|
|
214
214
|
:root {
|
|
215
215
|
color-scheme: light; /* native widgets (form controls, scrollbars) follow the theme */
|
|
216
216
|
|
|
217
|
+
/*
|
|
218
|
+
Sidebar geometry. These were literals inside SidebarRoot's cva
|
|
219
|
+
(`w-[244px]` / `w-[72px]`), which a consumer could only override by
|
|
220
|
+
winning a specificity argument with `cn`. As custom properties the
|
|
221
|
+
default still ships with this sheet.
|
|
222
|
+
|
|
223
|
+
TWO places to re-point them, and only these two:
|
|
224
|
+
- on the rail, via `className="[--sidebar-width:280px]"`. SidebarRoot
|
|
225
|
+
copies exactly these two arbitrary-property classes onto the mobile
|
|
226
|
+
drawer's own element, so one class moves the rail AND the drawer.
|
|
227
|
+
- on `:root` or `html`, which every layout inherits from.
|
|
228
|
+
|
|
229
|
+
NOT on a React-tree wrapper above the rail: that reaches the rail, but
|
|
230
|
+
the mobile drawer is portalled into document.body, and custom properties
|
|
231
|
+
inherit down the DOM tree. A wrapper is not an ancestor of the portal;
|
|
232
|
+
`:root` is.
|
|
233
|
+
|
|
234
|
+
They are theme-independent on purpose: a rail is not wider in the dark.
|
|
235
|
+
*/
|
|
236
|
+
--sidebar-width: 244px;
|
|
237
|
+
--sidebar-width-collapsed: 72px;
|
|
238
|
+
|
|
217
239
|
/* Application tokens (from Figma ring-tokens) */
|
|
218
240
|
--body-surface: 240 5% 96%; /* base/100 = #F4F4F5 */
|
|
219
241
|
/*
|
|
@@ -602,8 +624,32 @@
|
|
|
602
624
|
--normal-border: hsl(var(--border));
|
|
603
625
|
}
|
|
604
626
|
|
|
605
|
-
|
|
606
|
-
|
|
627
|
+
/*
|
|
628
|
+
The title outranks the description, and both rules have to WIN the cascade
|
|
629
|
+
for that to mean anything. Sonner ships
|
|
630
|
+
`[data-sonner-toast][data-styled='true'] [data-title]` at font-weight 500 and
|
|
631
|
+
its description twin at 400 — both (0,3,0), both injected at runtime.
|
|
632
|
+
The title rule here was a plain `[data-sonner-toast] [data-title]` (0,2,0):
|
|
633
|
+
it declared 600 and rendered at 500, losing outright, while the description
|
|
634
|
+
carried `!important` and rendered at 600. The hierarchy came out inverted on
|
|
635
|
+
every toast in the kit, the long line heavier than the label naming it.
|
|
636
|
+
|
|
637
|
+
Both now take the compound selector plus !important — the shape the
|
|
638
|
+
close-button rules below already use against this same stylesheet, and for
|
|
639
|
+
the same reason: source order cannot settle a tie with a sheet that is
|
|
640
|
+
injected at runtime.
|
|
641
|
+
|
|
642
|
+
The description returns to 400. It is the running text of a toast, and 14px
|
|
643
|
+
semibold across a full sentence reads as emphasis with nothing left to
|
|
644
|
+
emphasise; the family ink already carries the severity. Its `color` override
|
|
645
|
+
keeps !important on its own merits — sonner hardcodes #3f3f3f there, plus a
|
|
646
|
+
dark-theme rule of its own on top.
|
|
647
|
+
|
|
648
|
+
`toast text weights` in src/__tests__/tokens-contract.test.ts holds the order
|
|
649
|
+
and the two properties that let it apply.
|
|
650
|
+
*/
|
|
651
|
+
[data-sonner-toast][data-styled='true'] [data-title] {
|
|
652
|
+
font-weight: 600 !important;
|
|
607
653
|
font-size: 0.875rem;
|
|
608
654
|
line-height: 1.25rem;
|
|
609
655
|
}
|
|
@@ -611,7 +657,7 @@
|
|
|
611
657
|
[data-sonner-toast] [data-description],
|
|
612
658
|
[data-sonner-toast][data-styled='true'] [data-description] {
|
|
613
659
|
font-size: 0.875rem;
|
|
614
|
-
font-weight:
|
|
660
|
+
font-weight: 400 !important;
|
|
615
661
|
line-height: 1.25rem;
|
|
616
662
|
color: var(--normal-text) !important;
|
|
617
663
|
}
|