eidotter 0.46.0 → 0.46.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/dist/components/DisplayMenu/components/DisplayMenu.d.ts +8 -5
- package/dist/components/DisplayMenu/components/DisplayMenu.js +69 -10
- package/dist/components/registry.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +257 -219
- package/dist/index.umd.js +3 -3
- package/package.json +4 -4
- package/src/styles/theme.amber-mono.css +7 -7
- package/src/styles/theme.amber-paper.css +6 -6
- package/src/styles/theme.cga-amber.css +7 -7
- package/src/styles/theme.cga-mode4-p0.css +7 -7
- package/src/styles/theme.cga-mode4-p1.css +7 -7
- package/src/styles/theme.cga-mode5.css +7 -7
- package/src/styles/theme.light.css +7 -7
- package/src/styles/tokens.css +21 -21
|
@@ -17,7 +17,7 @@ export interface DisplayMenuProps {
|
|
|
17
17
|
/** One row per display option: a label and a Switch. */
|
|
18
18
|
items: DisplayMenuItem[];
|
|
19
19
|
/**
|
|
20
|
-
* Trigger label and the panel's accessible name. Default `'Display'`.
|
|
20
|
+
* Trigger label and the panel's accessible name (a `role="group"`). Default `'Display'`.
|
|
21
21
|
* Below 640px the trigger shows only the icon; the label stays its
|
|
22
22
|
* accessible name.
|
|
23
23
|
*/
|
|
@@ -42,10 +42,13 @@ export interface DisplayMenuProps {
|
|
|
42
42
|
* or the amber-paper theme. Built for Header's `end` slot so every site has
|
|
43
43
|
* one theme control instead of switches side by side.
|
|
44
44
|
*
|
|
45
|
-
* The panel is a React Aria popover
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
45
|
+
* The panel is a non-modal React Aria popover (DMNC-1629): the page behind it
|
|
46
|
+
* stays scrollable, readable and clickable, nothing is hidden from assistive
|
|
47
|
+
* technology and no scrim is drawn. It portals out of the header (so the end
|
|
48
|
+
* slot's clip never cuts it). Opening it focuses the first enabled switch;
|
|
49
|
+
* Tab moves between the switches and Tab past the last one, Escape, a click or
|
|
50
|
+
* tap outside, pressing the trigger again or scrolling the page close it, and
|
|
51
|
+
* focus returns to the trigger.
|
|
49
52
|
* Consumers own the state; DisplayMenu only renders it.
|
|
50
53
|
*/
|
|
51
54
|
export declare const DisplayMenu: React.ForwardRefExoticComponent<DisplayMenuProps & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,11 +1,65 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef, useId } from 'react';
|
|
4
|
-
import {
|
|
3
|
+
import { forwardRef, useContext, useEffect, useId, useRef } from 'react';
|
|
4
|
+
import { DialogContext, DialogTrigger as AriaDialogTrigger, OverlayTriggerStateContext, Popover as AriaPopover, useSlottedContext, } from 'react-aria-components';
|
|
5
|
+
import { useInteractOutside, useObjectRef } from 'react-aria';
|
|
5
6
|
import { Monitor } from 'pixelarticons/react/Monitor.js';
|
|
6
7
|
import { Switch } from '../../Switch/index.js';
|
|
7
8
|
import { HeaderButton } from '../../HeaderButton/index.js';
|
|
8
9
|
import { cn } from '../../../utils/cn.js';
|
|
10
|
+
/**
|
|
11
|
+
* Dismissal for the non-modal panel. React Aria's non-modal popover closes
|
|
12
|
+
* on Escape, on page scroll and when focus moves to another element, but not
|
|
13
|
+
* on a tap on empty page (no focus change) and not when Tab leaves it for the
|
|
14
|
+
* document body (the trigger was the last tabbable element). This adds both:
|
|
15
|
+
* an outside pointer interaction closes it, without a scrim or a scroll lock,
|
|
16
|
+
* and after a Tab the panel closes if focus is no longer inside it. A press on
|
|
17
|
+
* the trigger is swallowed here (as React Aria does for its modal popovers), so
|
|
18
|
+
* the trigger's own press cannot reopen the panel the focus change just closed.
|
|
19
|
+
*/
|
|
20
|
+
const NonModalDismiss = ({ popoverRef, triggerRef }) => {
|
|
21
|
+
const state = useContext(OverlayTriggerStateContext);
|
|
22
|
+
useInteractOutside({
|
|
23
|
+
ref: popoverRef,
|
|
24
|
+
isDisabled: !state?.isOpen,
|
|
25
|
+
onInteractOutsideStart: (e) => {
|
|
26
|
+
if (triggerRef.current?.contains(e.target))
|
|
27
|
+
e.stopPropagation();
|
|
28
|
+
},
|
|
29
|
+
onInteractOutside: () => state?.close(),
|
|
30
|
+
});
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const popover = popoverRef.current;
|
|
33
|
+
if (!popover || !state?.isOpen)
|
|
34
|
+
return;
|
|
35
|
+
const doc = popover.ownerDocument;
|
|
36
|
+
const onKeyDown = (e) => {
|
|
37
|
+
if (e.key !== 'Tab' || !popover.contains(e.target))
|
|
38
|
+
return;
|
|
39
|
+
// React Aria's focus scope handles this keydown at the document capture
|
|
40
|
+
// phase and stops its propagation, so listen there too and check where
|
|
41
|
+
// focus landed once it has moved.
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
const active = doc.activeElement;
|
|
44
|
+
if (!active || !popover.contains(active))
|
|
45
|
+
state.close();
|
|
46
|
+
}, 0);
|
|
47
|
+
};
|
|
48
|
+
doc.addEventListener('keydown', onKeyDown, true);
|
|
49
|
+
return () => doc.removeEventListener('keydown', onKeyDown, true);
|
|
50
|
+
}, [popoverRef, state]);
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The panel: a labelled group, not a React Aria Dialog (Dialog turns on focus
|
|
55
|
+
* containment, which would keep Tab cycling inside the panel). It carries the
|
|
56
|
+
* overlay id DialogTrigger hands down, so the trigger's `aria-controls`
|
|
57
|
+
* resolves (in non-modal mode the Popover itself no longer takes the id).
|
|
58
|
+
*/
|
|
59
|
+
const Panel = ({ label, children }) => {
|
|
60
|
+
const overlayProps = useSlottedContext(DialogContext);
|
|
61
|
+
return (_jsx("div", { id: overlayProps?.id, role: "group", "aria-label": label, className: "eidotter-display-menu__panel", children: children }));
|
|
62
|
+
};
|
|
9
63
|
/**
|
|
10
64
|
* DisplayMenu: one header control for display options (DMNC-1619).
|
|
11
65
|
*
|
|
@@ -14,20 +68,25 @@ import { cn } from '../../../utils/cn.js';
|
|
|
14
68
|
* or the amber-paper theme. Built for Header's `end` slot so every site has
|
|
15
69
|
* one theme control instead of switches side by side.
|
|
16
70
|
*
|
|
17
|
-
* The panel is a React Aria popover
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
71
|
+
* The panel is a non-modal React Aria popover (DMNC-1629): the page behind it
|
|
72
|
+
* stays scrollable, readable and clickable, nothing is hidden from assistive
|
|
73
|
+
* technology and no scrim is drawn. It portals out of the header (so the end
|
|
74
|
+
* slot's clip never cuts it). Opening it focuses the first enabled switch;
|
|
75
|
+
* Tab moves between the switches and Tab past the last one, Escape, a click or
|
|
76
|
+
* tap outside, pressing the trigger again or scrolling the page close it, and
|
|
77
|
+
* focus returns to the trigger.
|
|
21
78
|
* Consumers own the state; DisplayMenu only renders it.
|
|
22
79
|
*/
|
|
23
80
|
export const DisplayMenu = forwardRef(({ items, label = 'Display', labelDisplay = 'responsive', placement = 'bottom end', defaultOpen, className, }, ref) => {
|
|
24
81
|
const baseId = useId();
|
|
82
|
+
const triggerRef = useObjectRef(ref);
|
|
83
|
+
const popoverRef = useRef(null);
|
|
25
84
|
// Opening the panel puts focus on the first switch that can be toggled,
|
|
26
85
|
// so Space works straight away (DMNC-1619 follow-up).
|
|
27
86
|
const firstEnabled = items.findIndex((item) => !item.disabled);
|
|
28
|
-
return (_jsxs(AriaDialogTrigger, { defaultOpen: defaultOpen, children: [_jsx(HeaderButton, { ref:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
87
|
+
return (_jsxs(AriaDialogTrigger, { defaultOpen: defaultOpen, children: [_jsx(HeaderButton, { ref: triggerRef, "aria-label": label, icon: _jsx(Monitor, { className: "eidotter-display-menu__icon", focusable: "false" }), chevron: true, labelDisplay: labelDisplay, className: cn('eidotter-display-menu', `eidotter-display-menu--${labelDisplay}`, className), children: label }), _jsxs(AriaPopover, { ref: popoverRef, isNonModal: true, placement: placement, offset: 6, className: "eidotter-display-menu__popover", children: [_jsx(NonModalDismiss, { popoverRef: popoverRef, triggerRef: triggerRef }), _jsx(Panel, { label: label, children: _jsx("ul", { className: "eidotter-display-menu__list", children: items.map((item, index) => {
|
|
88
|
+
const hintId = item.hint ? `${baseId}-${item.id}-hint` : undefined;
|
|
89
|
+
return (_jsxs("li", { className: "eidotter-display-menu__row", children: [_jsx(Switch, { label: item.label, checked: item.checked, onChange: item.onChange, disabled: item.disabled, "aria-describedby": hintId, autoFocus: index === firstEnabled, className: "eidotter-display-menu__switch" }), item.hint && (_jsx("span", { id: hintId, className: "eidotter-display-menu__hint", children: item.hint }))] }, item.id));
|
|
90
|
+
}) }) })] })] }));
|
|
32
91
|
});
|
|
33
92
|
DisplayMenu.displayName = 'DisplayMenu';
|
|
@@ -813,7 +813,7 @@ export const componentRegistry = {
|
|
|
813
813
|
origin: 'eidotter',
|
|
814
814
|
consumers: [],
|
|
815
815
|
since: '0.45.0',
|
|
816
|
-
originNote: 'One header control for display options (DMNC-1619): a trigger (pixel monitor glyph, label, chevron; icon only below 640px) opens a React Aria popover
|
|
816
|
+
originNote: 'One header control for display options (DMNC-1619): a trigger (pixel monitor glyph, label, chevron; icon only below 640px) opens a non-modal React Aria popover (a labelled group, DMNC-1629) with one row per option, each an eidotter Switch. Replaces switches side by side in Header end slots; consumers own the state.',
|
|
817
817
|
variants: {
|
|
818
818
|
'labelDisplay:responsive': { description: 'Icon only below 640px, icon + label above (default)', since: '0.45.0' },
|
|
819
819
|
'labelDisplay:icon': { description: 'Always icon only (36px square)', since: '0.45.0' },
|
|
@@ -821,6 +821,7 @@ export const componentRegistry = {
|
|
|
821
821
|
},
|
|
822
822
|
platforms: { react: { path: 'src/components/DisplayMenu', status: 'canonical' } },
|
|
823
823
|
changelog: [
|
|
824
|
+
{ version: '0.46.1', type: 'changed', description: 'Non-modal panel (DMNC-1629): no scroll lock, scrim or aria-hiding of the page; Escape, outside press, the trigger, Tab out and page scroll close it, focus returns to the trigger; the panel is a labelled role=group, not a dialog' },
|
|
824
825
|
{ version: '0.46.0', type: 'changed', description: 'Trigger is a HeaderButton (same geometry, states and phone size as every header control); trigger styles moved to HeaderButton.css, the eidotter-display-menu class stays on the trigger' },
|
|
825
826
|
{ version: '0.45.1', type: 'changed', description: 'Opening the panel focuses the first enabled switch, so Space toggles it without a Tab' },
|
|
826
827
|
{ version: '0.45.0', type: 'added', description: 'Initial DisplayMenu: items ({ id, label, checked, onChange, disabled, hint }), label, labelDisplay, placement, className; stable classes eidotter-display-menu, __popover, __panel, __row, __switch, __hint (DMNC-1619)' },
|
package/dist/index.d.ts
CHANGED
|
@@ -142,4 +142,4 @@ export type { SafeHrefOptions } from './utils';
|
|
|
142
142
|
export { ZOOM_LEVELS } from './components/TimelineContainer';
|
|
143
143
|
export { componentRegistry, projects, getComponentMeta, getComponentsByOrigin, getComponentsByConsumer, getVariantsUsedBy, getVariantConsumerMap, } from './components/registry';
|
|
144
144
|
export type { ComponentMeta, ProjectId, ProjectInfo, VariantMeta, PlatformId, PlatformMeta, ChangelogEntry, } from './components/registry';
|
|
145
|
-
export declare const version = "0.46.
|
|
145
|
+
export declare const version = "0.46.1";
|