menhir 0.0.0 → 0.1.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/LICENSE +0 -28
- package/README.md +53 -1
- package/dist/accordion/header/AccordionHeader.js +22 -0
- package/dist/accordion/index.js +2 -0
- package/dist/accordion/index.parts.js +6 -0
- package/dist/accordion/item/AccordionItem.js +51 -0
- package/dist/accordion/item/AccordionItemContext.js +10 -0
- package/dist/accordion/panel/AccordionPanel.js +32 -0
- package/dist/accordion/root/AccordionRoot.js +45 -0
- package/dist/accordion/root/AccordionRootContext.js +10 -0
- package/dist/accordion/trigger/AccordionTrigger.js +39 -0
- package/dist/checkbox/index.js +2 -0
- package/dist/checkbox/index.parts.js +3 -0
- package/dist/checkbox/indicator/CheckboxIndicator.js +20 -0
- package/dist/checkbox/root/CheckboxRoot.js +136 -0
- package/dist/checkbox/root/CheckboxRootContext.js +10 -0
- package/dist/collapsible/index.js +2 -0
- package/dist/collapsible/index.parts.js +4 -0
- package/dist/collapsible/panel/CollapsiblePanel.js +27 -0
- package/dist/collapsible/root/CollapsibleRoot.js +53 -0
- package/dist/collapsible/root/CollapsibleRootContext.js +10 -0
- package/dist/collapsible/trigger/CollapsibleTrigger.js +31 -0
- package/dist/color-scheme/colorScheme.js +28 -0
- package/dist/color-scheme/colorSchemeScript.js +18 -0
- package/dist/color-scheme/cookie/cookie.js +50 -0
- package/dist/color-scheme/cookie/index.js +3 -0
- package/dist/color-scheme/createColorScheme.js +41 -0
- package/dist/color-scheme/local-storage/index.js +3 -0
- package/dist/color-scheme/local-storage/localStorage.js +38 -0
- package/dist/core/button.js +56 -0
- package/dist/core/createControllableSignal.js +50 -0
- package/dist/core/listValue.js +49 -0
- package/dist/core/mergeElementProps.js +67 -0
- package/dist/core/preference/cookiePreference.js +44 -0
- package/dist/core/preference/createPreference.js +60 -0
- package/dist/core/preference/localStoragePreference.js +28 -0
- package/dist/core/preference/preference.js +21 -0
- package/dist/core/preference/preferenceScript.js +12 -0
- package/dist/core/range.js +53 -0
- package/dist/core/renderElement.js +14 -0
- package/dist/core/rovingFocus.js +50 -0
- package/dist/core/toggleButton.js +37 -0
- package/dist/meter/index.js +2 -0
- package/dist/meter/index.parts.js +3 -0
- package/dist/meter/root/MeterRoot.js +28 -0
- package/dist/meter/root/MeterRootContext.js +10 -0
- package/dist/meter/value/MeterValue.js +24 -0
- package/dist/progress/index.js +2 -0
- package/dist/progress/index.parts.js +4 -0
- package/dist/progress/indicator/ProgressIndicator.js +21 -0
- package/dist/progress/root/ProgressRoot.js +47 -0
- package/dist/progress/root/ProgressRootContext.js +10 -0
- package/dist/progress/value/ProgressValue.js +26 -0
- package/dist/separator/index.js +2 -0
- package/dist/separator/index.parts.js +1 -0
- package/dist/separator/root/SeparatorRoot.js +31 -0
- package/dist/source/accordion/header/AccordionHeader.d.ts +11 -0
- package/dist/source/accordion/header/AccordionHeader.jsx +14 -0
- package/dist/source/accordion/index.d.ts +1 -0
- package/dist/source/accordion/index.js +1 -0
- package/dist/source/accordion/index.parts.d.ts +5 -0
- package/dist/source/accordion/index.parts.js +5 -0
- package/dist/source/accordion/item/AccordionItem.d.ts +17 -0
- package/dist/source/accordion/item/AccordionItem.jsx +42 -0
- package/dist/source/accordion/item/AccordionItemContext.d.ts +33 -0
- package/dist/source/accordion/item/AccordionItemContext.js +12 -0
- package/dist/source/accordion/panel/AccordionPanel.d.ts +11 -0
- package/dist/source/accordion/panel/AccordionPanel.jsx +27 -0
- package/dist/source/accordion/root/AccordionRoot.d.ts +26 -0
- package/dist/source/accordion/root/AccordionRoot.jsx +37 -0
- package/dist/source/accordion/root/AccordionRootContext.d.ts +11 -0
- package/dist/source/accordion/root/AccordionRootContext.js +13 -0
- package/dist/source/accordion/trigger/AccordionTrigger.d.ts +10 -0
- package/dist/source/accordion/trigger/AccordionTrigger.jsx +35 -0
- package/dist/source/checkbox/index.d.ts +1 -0
- package/dist/source/checkbox/index.js +1 -0
- package/dist/source/checkbox/index.parts.d.ts +2 -0
- package/dist/source/checkbox/index.parts.js +2 -0
- package/dist/source/checkbox/indicator/CheckboxIndicator.d.ts +10 -0
- package/dist/source/checkbox/indicator/CheckboxIndicator.jsx +12 -0
- package/dist/source/checkbox/root/CheckboxRoot.d.ts +37 -0
- package/dist/source/checkbox/root/CheckboxRoot.jsx +135 -0
- package/dist/source/checkbox/root/CheckboxRootContext.d.ts +16 -0
- package/dist/source/checkbox/root/CheckboxRootContext.js +13 -0
- package/dist/source/collapsible/index.d.ts +1 -0
- package/dist/source/collapsible/index.js +1 -0
- package/dist/source/collapsible/index.parts.d.ts +3 -0
- package/dist/source/collapsible/index.parts.js +3 -0
- package/dist/source/collapsible/panel/CollapsiblePanel.d.ts +10 -0
- package/dist/source/collapsible/panel/CollapsiblePanel.jsx +22 -0
- package/dist/source/collapsible/root/CollapsibleRoot.d.ts +21 -0
- package/dist/source/collapsible/root/CollapsibleRoot.jsx +42 -0
- package/dist/source/collapsible/root/CollapsibleRootContext.d.ts +26 -0
- package/dist/source/collapsible/root/CollapsibleRootContext.js +13 -0
- package/dist/source/collapsible/trigger/CollapsibleTrigger.d.ts +10 -0
- package/dist/source/collapsible/trigger/CollapsibleTrigger.jsx +23 -0
- package/dist/source/color-scheme/colorScheme.d.ts +35 -0
- package/dist/source/color-scheme/colorScheme.js +30 -0
- package/dist/source/color-scheme/colorSchemeScript.d.ts +8 -0
- package/dist/source/color-scheme/colorSchemeScript.js +16 -0
- package/dist/source/color-scheme/cookie/cookie.d.ts +39 -0
- package/dist/source/color-scheme/cookie/cookie.js +48 -0
- package/dist/source/color-scheme/cookie/index.d.ts +4 -0
- package/dist/source/color-scheme/cookie/index.js +2 -0
- package/dist/source/color-scheme/createColorScheme.d.ts +26 -0
- package/dist/source/color-scheme/createColorScheme.js +44 -0
- package/dist/source/color-scheme/local-storage/index.d.ts +4 -0
- package/dist/source/color-scheme/local-storage/index.js +2 -0
- package/dist/source/color-scheme/local-storage/localStorage.d.ts +30 -0
- package/dist/source/color-scheme/local-storage/localStorage.js +36 -0
- package/dist/source/core/button.d.ts +53 -0
- package/dist/source/core/button.js +61 -0
- package/dist/source/core/createControllableSignal.d.ts +27 -0
- package/dist/source/core/createControllableSignal.js +74 -0
- package/dist/source/core/index.d.ts +1 -0
- package/dist/source/core/index.js +1 -0
- package/dist/source/core/listValue.d.ts +32 -0
- package/dist/source/core/listValue.js +51 -0
- package/dist/source/core/mergeElementProps.d.ts +19 -0
- package/dist/source/core/mergeElementProps.js +91 -0
- package/dist/source/core/preference/cookiePreference.d.ts +10 -0
- package/dist/source/core/preference/cookiePreference.js +57 -0
- package/dist/source/core/preference/createPreference.d.ts +44 -0
- package/dist/source/core/preference/createPreference.js +60 -0
- package/dist/source/core/preference/localStoragePreference.d.ts +3 -0
- package/dist/source/core/preference/localStoragePreference.js +36 -0
- package/dist/source/core/preference/preference.d.ts +40 -0
- package/dist/source/core/preference/preference.js +22 -0
- package/dist/source/core/preference/preferenceScript.d.ts +17 -0
- package/dist/source/core/preference/preferenceScript.js +13 -0
- package/dist/source/core/range.d.ts +52 -0
- package/dist/source/core/range.js +60 -0
- package/dist/source/core/renderElement.d.ts +25 -0
- package/dist/source/core/renderElement.jsx +11 -0
- package/dist/source/core/rovingFocus.d.ts +42 -0
- package/dist/source/core/rovingFocus.js +71 -0
- package/dist/source/core/toggleButton.d.ts +22 -0
- package/dist/source/core/toggleButton.js +35 -0
- package/dist/source/meter/index.d.ts +1 -0
- package/dist/source/meter/index.js +1 -0
- package/dist/source/meter/index.parts.d.ts +2 -0
- package/dist/source/meter/index.parts.js +2 -0
- package/dist/source/meter/root/MeterRoot.d.ts +27 -0
- package/dist/source/meter/root/MeterRoot.jsx +15 -0
- package/dist/source/meter/root/MeterRootContext.d.ts +9 -0
- package/dist/source/meter/root/MeterRootContext.js +13 -0
- package/dist/source/meter/value/MeterValue.d.ts +11 -0
- package/dist/source/meter/value/MeterValue.jsx +19 -0
- package/dist/source/progress/index.d.ts +1 -0
- package/dist/source/progress/index.js +1 -0
- package/dist/source/progress/index.parts.d.ts +3 -0
- package/dist/source/progress/index.parts.js +3 -0
- package/dist/source/progress/indicator/ProgressIndicator.d.ts +11 -0
- package/dist/source/progress/indicator/ProgressIndicator.jsx +13 -0
- package/dist/source/progress/root/ProgressRoot.d.ts +30 -0
- package/dist/source/progress/root/ProgressRoot.jsx +32 -0
- package/dist/source/progress/root/ProgressRootContext.d.ts +20 -0
- package/dist/source/progress/root/ProgressRootContext.js +13 -0
- package/dist/source/progress/value/ProgressValue.d.ts +12 -0
- package/dist/source/progress/value/ProgressValue.jsx +20 -0
- package/dist/source/separator/index.d.ts +1 -0
- package/dist/source/separator/index.js +1 -0
- package/dist/source/separator/index.parts.d.ts +1 -0
- package/dist/source/separator/index.parts.js +1 -0
- package/dist/source/separator/root/SeparatorRoot.d.ts +12 -0
- package/dist/source/separator/root/SeparatorRoot.jsx +26 -0
- package/dist/source/switch/index.d.ts +1 -0
- package/dist/source/switch/index.js +1 -0
- package/dist/source/switch/index.parts.d.ts +2 -0
- package/dist/source/switch/index.parts.js +2 -0
- package/dist/source/switch/root/SwitchRoot.d.ts +31 -0
- package/dist/source/switch/root/SwitchRoot.jsx +124 -0
- package/dist/source/switch/root/SwitchRootContext.d.ts +14 -0
- package/dist/source/switch/root/SwitchRootContext.js +13 -0
- package/dist/source/switch/thumb/SwitchThumb.d.ts +10 -0
- package/dist/source/switch/thumb/SwitchThumb.jsx +12 -0
- package/dist/source/tabs/index.d.ts +1 -0
- package/dist/source/tabs/index.js +1 -0
- package/dist/source/tabs/index.parts.d.ts +4 -0
- package/dist/source/tabs/index.parts.js +4 -0
- package/dist/source/tabs/list/TabsList.d.ts +11 -0
- package/dist/source/tabs/list/TabsList.jsx +27 -0
- package/dist/source/tabs/panel/TabsPanel.d.ts +12 -0
- package/dist/source/tabs/panel/TabsPanel.jsx +38 -0
- package/dist/source/tabs/root/TabsRoot.d.ts +30 -0
- package/dist/source/tabs/root/TabsRoot.jsx +74 -0
- package/dist/source/tabs/root/TabsRootContext.d.ts +47 -0
- package/dist/source/tabs/root/TabsRootContext.js +13 -0
- package/dist/source/tabs/tab/TabsTab.d.ts +20 -0
- package/dist/source/tabs/tab/TabsTab.jsx +77 -0
- package/dist/source/theme/cookie/cookie.d.ts +34 -0
- package/dist/source/theme/cookie/cookie.js +42 -0
- package/dist/source/theme/cookie/index.d.ts +2 -0
- package/dist/source/theme/cookie/index.js +1 -0
- package/dist/source/theme/local-storage/index.d.ts +2 -0
- package/dist/source/theme/local-storage/index.js +1 -0
- package/dist/source/theme/local-storage/localStorage.d.ts +28 -0
- package/dist/source/theme/local-storage/localStorage.js +34 -0
- package/dist/source/theme/theme.d.ts +46 -0
- package/dist/source/theme/theme.js +57 -0
- package/dist/source/toggle/index.d.ts +1 -0
- package/dist/source/toggle/index.js +1 -0
- package/dist/source/toggle/index.parts.d.ts +1 -0
- package/dist/source/toggle/index.parts.js +1 -0
- package/dist/source/toggle/root/ToggleRoot.d.ts +20 -0
- package/dist/source/toggle/root/ToggleRoot.jsx +30 -0
- package/dist/source/toggle-group/index.d.ts +1 -0
- package/dist/source/toggle-group/index.js +1 -0
- package/dist/source/toggle-group/index.parts.d.ts +2 -0
- package/dist/source/toggle-group/index.parts.js +2 -0
- package/dist/source/toggle-group/item/ToggleGroupItem.d.ts +14 -0
- package/dist/source/toggle-group/item/ToggleGroupItem.jsx +39 -0
- package/dist/source/toggle-group/root/ToggleGroupRoot.d.ts +28 -0
- package/dist/source/toggle-group/root/ToggleGroupRoot.jsx +68 -0
- package/dist/source/toggle-group/root/ToggleGroupRootContext.d.ts +25 -0
- package/dist/source/toggle-group/root/ToggleGroupRootContext.js +13 -0
- package/dist/switch/index.js +2 -0
- package/dist/switch/index.parts.js +3 -0
- package/dist/switch/root/SwitchRoot.js +129 -0
- package/dist/switch/root/SwitchRootContext.js +10 -0
- package/dist/switch/thumb/SwitchThumb.js +20 -0
- package/dist/tabs/index.js +2 -0
- package/dist/tabs/index.parts.js +5 -0
- package/dist/tabs/list/TabsList.js +33 -0
- package/dist/tabs/panel/TabsPanel.js +40 -0
- package/dist/tabs/root/TabsRoot.js +74 -0
- package/dist/tabs/root/TabsRootContext.js +10 -0
- package/dist/tabs/tab/TabsTab.js +74 -0
- package/dist/theme/cookie/cookie.js +44 -0
- package/dist/theme/cookie/index.js +1 -0
- package/dist/theme/local-storage/index.js +1 -0
- package/dist/theme/local-storage/localStorage.js +36 -0
- package/dist/theme/theme.js +52 -0
- package/dist/toggle/index.js +2 -0
- package/dist/toggle/index.parts.js +1 -0
- package/dist/toggle/root/ToggleRoot.js +38 -0
- package/dist/toggle-group/index.js +2 -0
- package/dist/toggle-group/index.parts.js +3 -0
- package/dist/toggle-group/item/ToggleGroupItem.js +48 -0
- package/dist/toggle-group/root/ToggleGroupRoot.js +71 -0
- package/dist/toggle-group/root/ToggleGroupRootContext.js +10 -0
- package/package.json +99 -6
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { omit } from "solid-js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
4
|
+
import { useTabsRootContext } from "../root/TabsRootContext.js";
|
|
5
|
+
/**
|
|
6
|
+
* The content its tab shows: a `<div role="tabpanel">` named by the tab,
|
|
7
|
+
* `hidden` unless the tab is selected. Place it inside `Tabs.Root`.
|
|
8
|
+
*/
|
|
9
|
+
export function TabsPanel(props) {
|
|
10
|
+
const root = useTabsRootContext();
|
|
11
|
+
const selected = () => root.selected(props.value);
|
|
12
|
+
const ownProps = {
|
|
13
|
+
role: "tabpanel",
|
|
14
|
+
get id() {
|
|
15
|
+
return root.panelId(props.value);
|
|
16
|
+
},
|
|
17
|
+
get "aria-labelledby"() {
|
|
18
|
+
return root.tabId(props.value);
|
|
19
|
+
},
|
|
20
|
+
// The pattern's note 4: a tab stop, for a panel whose first content is
|
|
21
|
+
// not focusable.
|
|
22
|
+
tabindex: 0,
|
|
23
|
+
get hidden() {
|
|
24
|
+
return !selected();
|
|
25
|
+
},
|
|
26
|
+
get "data-selected"() {
|
|
27
|
+
return selected() ? "" : undefined;
|
|
28
|
+
},
|
|
29
|
+
get "data-unselected"() {
|
|
30
|
+
return selected() ? undefined : "";
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const elementProps = mergeElementProps(ownProps,
|
|
34
|
+
// An `id` from untyped code would break the tab's `aria-controls`, so
|
|
35
|
+
// it is dropped too.
|
|
36
|
+
omit(props, "render", "value", "id"));
|
|
37
|
+
return renderElement(props, elementProps, (p) => <div {...p}/>);
|
|
38
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface TabsRootProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** The selected tab's value, when controlled; `null` selects none. */
|
|
5
|
+
value?: string | null;
|
|
6
|
+
/**
|
|
7
|
+
* The value of the tab selected at first, when uncontrolled. Without
|
|
8
|
+
* one, the first enabled tab is selected.
|
|
9
|
+
*/
|
|
10
|
+
defaultValue?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Called with the new value when the user selects a tab. When
|
|
13
|
+
* controlled, the selection changes only if `value` does.
|
|
14
|
+
*/
|
|
15
|
+
onValueChange?: (value: string) => void;
|
|
16
|
+
/** Whether the tabs are laid out side by side, or stacked. */
|
|
17
|
+
orientation?: "horizontal" | "vertical";
|
|
18
|
+
/**
|
|
19
|
+
* Whether a tab is selected when it receives focus (`"automatic"`), or
|
|
20
|
+
* only by click, Enter or Space (`"manual"`), for panels that load their
|
|
21
|
+
* content.
|
|
22
|
+
*/
|
|
23
|
+
activation?: "automatic" | "manual";
|
|
24
|
+
render?: RenderProp;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Layered sections of content, one shown at a time: a `<div>` around a
|
|
28
|
+
* `Tabs.List` of `Tabs.Tab`s and their `Tabs.Panel`s.
|
|
29
|
+
*/
|
|
30
|
+
export declare function TabsRoot(props: TabsRootProps): JSX.Element;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createSignal, createUniqueId, omit } from "solid-js";
|
|
2
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
3
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
4
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
5
|
+
import { createRovingFocus } from "../../core/rovingFocus.js";
|
|
6
|
+
import { TabsRootContext } from "./TabsRootContext.js";
|
|
7
|
+
/**
|
|
8
|
+
* Layered sections of content, one shown at a time: a `<div>` around a
|
|
9
|
+
* `Tabs.List` of `Tabs.Tab`s and their `Tabs.Panel`s.
|
|
10
|
+
*/
|
|
11
|
+
export function TabsRoot(props) {
|
|
12
|
+
const [value, setValue] = createControllableSignal({
|
|
13
|
+
get value() {
|
|
14
|
+
return props.value;
|
|
15
|
+
},
|
|
16
|
+
get defaultValue() {
|
|
17
|
+
return props.defaultValue;
|
|
18
|
+
},
|
|
19
|
+
onChange: (value) => props.onValueChange?.(value),
|
|
20
|
+
});
|
|
21
|
+
// The first enabled tab created, selected while there is no value. Tabs
|
|
22
|
+
// are created before anything reads the selection, on the server too.
|
|
23
|
+
let first;
|
|
24
|
+
const selected = () => {
|
|
25
|
+
const current = value();
|
|
26
|
+
return current === undefined ? first : current;
|
|
27
|
+
};
|
|
28
|
+
const vertical = () => props.orientation === "vertical";
|
|
29
|
+
const id = createUniqueId();
|
|
30
|
+
// The tab stop is the tab that has focus, so Tab from it moves on to the
|
|
31
|
+
// panel, else the selected tab, which Tab into the list focuses.
|
|
32
|
+
const [focused, setFocused] = createSignal();
|
|
33
|
+
const roving = createRovingFocus({
|
|
34
|
+
get vertical() {
|
|
35
|
+
return vertical();
|
|
36
|
+
},
|
|
37
|
+
// Disabled tabs stay focusable (README, "Shape").
|
|
38
|
+
focusable: () => true,
|
|
39
|
+
preferred: (tab) => focused() ? tab.element === focused() : selected() === tab.value(),
|
|
40
|
+
});
|
|
41
|
+
const context = {
|
|
42
|
+
...roving,
|
|
43
|
+
selected: (tab) => selected() === tab,
|
|
44
|
+
// The tab selected by default is not in `value`, which would report it
|
|
45
|
+
// as a change.
|
|
46
|
+
select: (tab) => {
|
|
47
|
+
if (selected() !== tab)
|
|
48
|
+
setValue(tab);
|
|
49
|
+
},
|
|
50
|
+
claimFirst: (tab, disabled) => {
|
|
51
|
+
if (!disabled)
|
|
52
|
+
first ??= tab;
|
|
53
|
+
},
|
|
54
|
+
vertical,
|
|
55
|
+
automatic: () => props.activation !== "manual",
|
|
56
|
+
generatedTabId: (tab) => `${id}-tab-${tab}`,
|
|
57
|
+
tabId: (tab) => context.tabIds[tab]?.() ?? context.generatedTabId(tab),
|
|
58
|
+
tabIds: {},
|
|
59
|
+
panelId: (tab) => `${id}-panel-${tab}`,
|
|
60
|
+
setFocused: (element) => setFocused(element),
|
|
61
|
+
};
|
|
62
|
+
const ownProps = {
|
|
63
|
+
get "data-horizontal"() {
|
|
64
|
+
return vertical() ? undefined : "";
|
|
65
|
+
},
|
|
66
|
+
get "data-vertical"() {
|
|
67
|
+
return vertical() ? "" : undefined;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "defaultValue", "onValueChange", "orientation", "activation"));
|
|
71
|
+
return (<TabsRootContext value={context}>
|
|
72
|
+
{renderElement(props, elementProps, (p) => (<div {...p}/>))}
|
|
73
|
+
</TabsRootContext>);
|
|
74
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { RovingFocus } from "../../core/rovingFocus.ts";
|
|
2
|
+
/** A tab as the Root knows it, for focus order and the tab stop. */
|
|
3
|
+
export interface TabsTabEntry {
|
|
4
|
+
readonly element: HTMLElement;
|
|
5
|
+
readonly value: () => string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* What the Root shares with its List, Tabs and Panels, with the tabs' roving
|
|
9
|
+
* focus.
|
|
10
|
+
*/
|
|
11
|
+
export interface TabsRootContextValue extends RovingFocus<TabsTabEntry> {
|
|
12
|
+
/** Whether the tab with this value is selected. */
|
|
13
|
+
selected(value: string): boolean;
|
|
14
|
+
/** Asks to select the tab with this value. */
|
|
15
|
+
select(value: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Records the tab being created as the one selected when neither `value`
|
|
18
|
+
* nor `defaultValue` is passed, if it is the first enabled one. Called
|
|
19
|
+
* once per tab, in its body, before anything reads the selection.
|
|
20
|
+
*/
|
|
21
|
+
claimFirst(value: string, disabled: boolean): void;
|
|
22
|
+
/** Whether the List is vertical. */
|
|
23
|
+
vertical(): boolean;
|
|
24
|
+
/** Whether a tab is selected when it receives focus. */
|
|
25
|
+
automatic(): boolean;
|
|
26
|
+
/** The generated id of the tab with this value. */
|
|
27
|
+
generatedTabId(value: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* The id of the tab with this value, which its Panel names: the one the
|
|
30
|
+
* tab handed over, else the generated one.
|
|
31
|
+
*/
|
|
32
|
+
tabId(value: string): string | false;
|
|
33
|
+
/**
|
|
34
|
+
* The tabs' ids by value, each of which may be the consumer's: a tab
|
|
35
|
+
* hands its id to its Panel, created after it, here.
|
|
36
|
+
*/
|
|
37
|
+
readonly tabIds: Record<string, () => string | false>;
|
|
38
|
+
/** The id of the Panel with this value, which its tab names. */
|
|
39
|
+
panelId(value: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Records the tab that has focus, or none. While a tab has focus it has
|
|
42
|
+
* the tab stop, so Tab from it moves to the panel.
|
|
43
|
+
*/
|
|
44
|
+
setFocused(element: HTMLElement | undefined): void;
|
|
45
|
+
}
|
|
46
|
+
export declare const TabsRootContext: import("solid-js").Context<TabsRootContextValue | null>;
|
|
47
|
+
export declare function useTabsRootContext(): TabsRootContextValue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext, useContext } from "solid-js";
|
|
2
|
+
import { isDev } from "@solidjs/web";
|
|
3
|
+
// `null` outside a Root, so that the part can name what is missing. Solid's
|
|
4
|
+
// own error for a context with no provider and no default does not.
|
|
5
|
+
export const TabsRootContext = createContext(null);
|
|
6
|
+
export function useTabsRootContext() {
|
|
7
|
+
const context = useContext(TabsRootContext);
|
|
8
|
+
// Production builds drop the check, and its message, with `isDev`.
|
|
9
|
+
if (isDev && !context) {
|
|
10
|
+
throw new Error("[menhir] Tabs parts must be placed within <Tabs.Root>.");
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface TabsTabProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
/**
|
|
5
|
+
* Identifies the tab in the Root's value, and its `Tabs.Panel`. Part of
|
|
6
|
+
* both ids, so it must not contain spaces.
|
|
7
|
+
*/
|
|
8
|
+
value: string;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the tab cannot be selected. It stays focusable, with
|
|
11
|
+
* `aria-disabled`, so that the user can still find it.
|
|
12
|
+
*/
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
render?: RenderProp;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* One tab, which shows its `Tabs.Panel` when selected: a
|
|
18
|
+
* `<button role="tab" aria-selected>`. Place it inside `Tabs.List`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function TabsTab(props: TabsTabProps): JSX.Element;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { omit, onSettled, untrack } from "solid-js";
|
|
3
|
+
import { warnUnlessButton } from "../../core/button.js";
|
|
4
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
5
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
6
|
+
import { useTabsRootContext } from "../root/TabsRootContext.js";
|
|
7
|
+
/**
|
|
8
|
+
* One tab, which shows its `Tabs.Panel` when selected: a
|
|
9
|
+
* `<button role="tab" aria-selected>`. Place it inside `Tabs.List`.
|
|
10
|
+
*/
|
|
11
|
+
export function TabsTab(props) {
|
|
12
|
+
const root = useTabsRootContext();
|
|
13
|
+
let element;
|
|
14
|
+
const selected = () => root.selected(props.value);
|
|
15
|
+
const select = () => {
|
|
16
|
+
if (!props.disabled)
|
|
17
|
+
root.select(props.value);
|
|
18
|
+
};
|
|
19
|
+
// Read once, as the tab is created: the key its Panel finds its id by,
|
|
20
|
+
// and whether it is the one selected when the Root has no value.
|
|
21
|
+
const value = untrack(() => props.value);
|
|
22
|
+
root.claimFirst(value, untrack(() => !!props.disabled));
|
|
23
|
+
// The consumer's `id`, else the generated one, which the Panel, created
|
|
24
|
+
// after the tab, names. Kept out of the merge, where a wrapper's
|
|
25
|
+
// `id={undefined}` would remove it ("`undefined` is a value", PLAN.md
|
|
26
|
+
// section 8). `false`, the consumer's way to remove an attribute,
|
|
27
|
+
// removes the Panel's `aria-labelledby` too.
|
|
28
|
+
const id = () => props.id ?? root.generatedTabId(props.value);
|
|
29
|
+
root.tabIds[value] = id;
|
|
30
|
+
const ownProps = {
|
|
31
|
+
type: "button",
|
|
32
|
+
role: "tab",
|
|
33
|
+
get id() {
|
|
34
|
+
return id();
|
|
35
|
+
},
|
|
36
|
+
// Solid 2.0 removes an attribute set to false, so spell the value out.
|
|
37
|
+
get "aria-selected"() {
|
|
38
|
+
return selected() ? "true" : "false";
|
|
39
|
+
},
|
|
40
|
+
get "aria-controls"() {
|
|
41
|
+
return root.panelId(props.value);
|
|
42
|
+
},
|
|
43
|
+
get "aria-disabled"() {
|
|
44
|
+
return props.disabled ? "true" : undefined;
|
|
45
|
+
},
|
|
46
|
+
get tabindex() {
|
|
47
|
+
return root.isTabStop(element, selected()) ? 0 : -1;
|
|
48
|
+
},
|
|
49
|
+
get "data-selected"() {
|
|
50
|
+
return selected() ? "" : undefined;
|
|
51
|
+
},
|
|
52
|
+
get "data-unselected"() {
|
|
53
|
+
return selected() ? undefined : "";
|
|
54
|
+
},
|
|
55
|
+
get "data-disabled"() {
|
|
56
|
+
return props.disabled ? "" : undefined;
|
|
57
|
+
},
|
|
58
|
+
onClick: select,
|
|
59
|
+
onFocus: () => {
|
|
60
|
+
root.setFocused(element);
|
|
61
|
+
if (root.automatic())
|
|
62
|
+
select();
|
|
63
|
+
},
|
|
64
|
+
onBlur: () => root.setFocused(undefined),
|
|
65
|
+
onKeyDown: (event) => root.navigate(event, element),
|
|
66
|
+
ref: (el) => {
|
|
67
|
+
element = el;
|
|
68
|
+
// Production builds drop the check with `isDev`.
|
|
69
|
+
if (isDev)
|
|
70
|
+
warnUnlessButton(el, "Tabs.Tab");
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
// Mounted, so its place in the document is known.
|
|
74
|
+
onSettled(() => root.register({ element: element, value: () => props.value }));
|
|
75
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "disabled", "id"));
|
|
76
|
+
return renderElement(props, elementProps, (p) => <button {...p}/>);
|
|
77
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ThemeOptions, ThemeState } from "../theme.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The reader's choice of theme, saved in a cookie and applied to
|
|
4
|
+
* `<html>` (`ThemeOptions.attribute`). Stays in step with the other
|
|
5
|
+
* instances in this tab, and with other tabs once they are shown again.
|
|
6
|
+
*
|
|
7
|
+
* Call it in a component. The cookie is read during the first render, on
|
|
8
|
+
* the server from the request (`getRequestEvent()`), so the server's HTML
|
|
9
|
+
* shows the theme and hydration agrees. The page has to be rendered for
|
|
10
|
+
* each request: a prerendered page has no cookie to read.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createTheme<const T extends string>(options: ThemeOptions<T>): ThemeState<T>;
|
|
13
|
+
/**
|
|
14
|
+
* The source of a script for the document head that applies the theme
|
|
15
|
+
* saved in the cookie, or the default, before the page first paints. Pass
|
|
16
|
+
* the options given to `createTheme`. Render it inline, before any styles
|
|
17
|
+
* that depend on the theme. With the theme rendered on the server, it only
|
|
18
|
+
* applies what the server rendered, and can be left out.
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <script innerHTML={themeScript(options)} />
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Under a Content Security Policy without `'unsafe-inline'`, put the
|
|
25
|
+
* policy's nonce on the element (`<script nonce={nonce} …>`), or allow the
|
|
26
|
+
* SHA-256 hash of the returned source.
|
|
27
|
+
*/
|
|
28
|
+
export declare function themeScript<const T extends string>(options: ThemeOptions<T>): string;
|
|
29
|
+
/**
|
|
30
|
+
* The theme saved in a `Cookie` request header, or the default, for a
|
|
31
|
+
* server that puts the attribute on its own `<html>`. Pass the options
|
|
32
|
+
* given to `createTheme`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function themeFromCookie<const T extends string>(cookieHeader: string | null | undefined, options: ThemeOptions<T>): T;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { cookiePreference, cookieValue, } from "../../core/preference/cookiePreference.js";
|
|
2
|
+
import { createThemeWithStorage, defaultStorageKey, parseTheme, themeScriptWithStorage, } from "../theme.js";
|
|
3
|
+
const storage = cookiePreference;
|
|
4
|
+
/**
|
|
5
|
+
* The reader's choice of theme, saved in a cookie and applied to
|
|
6
|
+
* `<html>` (`ThemeOptions.attribute`). Stays in step with the other
|
|
7
|
+
* instances in this tab, and with other tabs once they are shown again.
|
|
8
|
+
*
|
|
9
|
+
* Call it in a component. The cookie is read during the first render, on
|
|
10
|
+
* the server from the request (`getRequestEvent()`), so the server's HTML
|
|
11
|
+
* shows the theme and hydration agrees. The page has to be rendered for
|
|
12
|
+
* each request: a prerendered page has no cookie to read.
|
|
13
|
+
*/
|
|
14
|
+
export function createTheme(options) {
|
|
15
|
+
return createThemeWithStorage(storage, options);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The source of a script for the document head that applies the theme
|
|
19
|
+
* saved in the cookie, or the default, before the page first paints. Pass
|
|
20
|
+
* the options given to `createTheme`. Render it inline, before any styles
|
|
21
|
+
* that depend on the theme. With the theme rendered on the server, it only
|
|
22
|
+
* applies what the server rendered, and can be left out.
|
|
23
|
+
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <script innerHTML={themeScript(options)} />
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Under a Content Security Policy without `'unsafe-inline'`, put the
|
|
29
|
+
* policy's nonce on the element (`<script nonce={nonce} …>`), or allow the
|
|
30
|
+
* SHA-256 hash of the returned source.
|
|
31
|
+
*/
|
|
32
|
+
export function themeScript(options) {
|
|
33
|
+
return themeScriptWithStorage(storage, options);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The theme saved in a `Cookie` request header, or the default, for a
|
|
37
|
+
* server that puts the attribute on its own `<html>`. Pass the options
|
|
38
|
+
* given to `createTheme`.
|
|
39
|
+
*/
|
|
40
|
+
export function themeFromCookie(cookieHeader, options) {
|
|
41
|
+
return parseTheme(cookieValue(cookieHeader, options.storageKey ?? defaultStorageKey), options);
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createTheme, themeFromCookie, themeScript } from "./cookie.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createTheme, themeScript } from "./localStorage.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ThemeOptions, ThemeState } from "../theme.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The reader's choice of theme, saved in `localStorage` and applied to
|
|
4
|
+
* `<html>` (`ThemeOptions.attribute`). Stays in step with the other
|
|
5
|
+
* instances in this tab, and with other tabs.
|
|
6
|
+
*
|
|
7
|
+
* Call it in a component. The saved theme is read once the page has
|
|
8
|
+
* settled, so the server's HTML and the first client render agree; until
|
|
9
|
+
* then the theme is the default. The head script from `themeScript`, with
|
|
10
|
+
* the same options, applies the saved theme before the first paint, so the
|
|
11
|
+
* page does not flash in between.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createTheme<const T extends string>(options: ThemeOptions<T>): ThemeState<T>;
|
|
14
|
+
/**
|
|
15
|
+
* The source of a script for the document head that applies the theme
|
|
16
|
+
* saved in `localStorage`, or the default, before the page first paints.
|
|
17
|
+
* Pass the options given to `createTheme`. Render it inline, before any
|
|
18
|
+
* styles that depend on the theme:
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <script innerHTML={themeScript(options)} />
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Under a Content Security Policy without `'unsafe-inline'`, put the
|
|
25
|
+
* policy's nonce on the element (`<script nonce={nonce} …>`), or allow the
|
|
26
|
+
* SHA-256 hash of the returned source.
|
|
27
|
+
*/
|
|
28
|
+
export declare function themeScript<const T extends string>(options: ThemeOptions<T>): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { localStoragePreference } from "../../core/preference/localStoragePreference.js";
|
|
2
|
+
import { createThemeWithStorage, themeScriptWithStorage } from "../theme.js";
|
|
3
|
+
const storage = localStoragePreference;
|
|
4
|
+
/**
|
|
5
|
+
* The reader's choice of theme, saved in `localStorage` and applied to
|
|
6
|
+
* `<html>` (`ThemeOptions.attribute`). Stays in step with the other
|
|
7
|
+
* instances in this tab, and with other tabs.
|
|
8
|
+
*
|
|
9
|
+
* Call it in a component. The saved theme is read once the page has
|
|
10
|
+
* settled, so the server's HTML and the first client render agree; until
|
|
11
|
+
* then the theme is the default. The head script from `themeScript`, with
|
|
12
|
+
* the same options, applies the saved theme before the first paint, so the
|
|
13
|
+
* page does not flash in between.
|
|
14
|
+
*/
|
|
15
|
+
export function createTheme(options) {
|
|
16
|
+
return createThemeWithStorage(storage, options);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The source of a script for the document head that applies the theme
|
|
20
|
+
* saved in `localStorage`, or the default, before the page first paints.
|
|
21
|
+
* Pass the options given to `createTheme`. Render it inline, before any
|
|
22
|
+
* styles that depend on the theme:
|
|
23
|
+
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <script innerHTML={themeScript(options)} />
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Under a Content Security Policy without `'unsafe-inline'`, put the
|
|
29
|
+
* policy's nonce on the element (`<script nonce={nonce} …>`), or allow the
|
|
30
|
+
* SHA-256 hash of the returned source.
|
|
31
|
+
*/
|
|
32
|
+
export function themeScript(options) {
|
|
33
|
+
return themeScriptWithStorage(storage, options);
|
|
34
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Accessor } from "solid-js";
|
|
2
|
+
import type { PreferenceAttribute, PreferenceStorage } from "../core/preference/preference.ts";
|
|
3
|
+
export interface ThemeOptions<T extends string> {
|
|
4
|
+
/** Every theme the reader can choose, such as `["paper", "nord"]`. */
|
|
5
|
+
themes: readonly T[];
|
|
6
|
+
/** The theme while the reader has chosen none. One of `themes`. */
|
|
7
|
+
defaultTheme: NoInfer<T>;
|
|
8
|
+
/**
|
|
9
|
+
* The `localStorage` key, or the cookie name, the choice is saved under.
|
|
10
|
+
* Default `"theme"`.
|
|
11
|
+
*/
|
|
12
|
+
storageKey?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Where the theme goes on `<html>`: a `data-*` attribute set to its name
|
|
15
|
+
* (default `"data-theme"`), or `"class"` for a class named after it.
|
|
16
|
+
*/
|
|
17
|
+
attribute?: PreferenceAttribute;
|
|
18
|
+
}
|
|
19
|
+
export interface ThemeState<T extends string> {
|
|
20
|
+
/**
|
|
21
|
+
* The reader's theme. The default until the page has settled, unless it
|
|
22
|
+
* is saved in a cookie (`menhir/theme/cookie`).
|
|
23
|
+
*/
|
|
24
|
+
theme: Accessor<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Saves a theme and applies it. Choosing the default removes the saved
|
|
27
|
+
* value. Call from an event handler.
|
|
28
|
+
*/
|
|
29
|
+
setTheme: (theme: T) => void;
|
|
30
|
+
}
|
|
31
|
+
export declare const defaultStorageKey = "theme";
|
|
32
|
+
export declare const defaultAttribute = "data-theme";
|
|
33
|
+
/** A saved value as a theme: one of `themes`, or else the default. */
|
|
34
|
+
export declare function parseTheme<T extends string>(value: string | null | undefined, options: ThemeOptions<T>): T;
|
|
35
|
+
/**
|
|
36
|
+
* `createTheme` of each entry point, with the entry point's storage: the
|
|
37
|
+
* reader's theme, saved in `storage` and applied to `<html>`, through
|
|
38
|
+
* `createPreference`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createThemeWithStorage<T extends string>(storage: PreferenceStorage, options: ThemeOptions<T>): ThemeState<T>;
|
|
41
|
+
/**
|
|
42
|
+
* `themeScript` of each entry point, with the entry point's storage: the
|
|
43
|
+
* source of a script for the document head that applies the saved theme,
|
|
44
|
+
* or the default, before the page first paints.
|
|
45
|
+
*/
|
|
46
|
+
export declare function themeScriptWithStorage<T extends string>(storage: PreferenceStorage, options: ThemeOptions<T>): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createPreference } from "../core/preference/createPreference.js";
|
|
3
|
+
import { parsePreference, scriptLiteral, } from "../core/preference/preference.js";
|
|
4
|
+
import { preferenceScript } from "../core/preference/preferenceScript.js";
|
|
5
|
+
export const defaultStorageKey = "theme";
|
|
6
|
+
export const defaultAttribute = "data-theme";
|
|
7
|
+
/**
|
|
8
|
+
* Throws for options the head script could not apply. Production builds
|
|
9
|
+
* drop the check, and its messages, with `isDev`.
|
|
10
|
+
*/
|
|
11
|
+
function checkThemes(options) {
|
|
12
|
+
for (const theme of options.themes) {
|
|
13
|
+
// A class cannot hold a space, and a cookie value is saved encoded,
|
|
14
|
+
// which the head script does not undo.
|
|
15
|
+
if (!/^[\w-]+$/.test(theme)) {
|
|
16
|
+
throw new Error(`[menhir] The theme ${JSON.stringify(theme)} needs a name of letters, digits, "-" and "_".`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!options.themes.includes(options.defaultTheme)) {
|
|
20
|
+
throw new Error(`[menhir] The defaultTheme ${JSON.stringify(options.defaultTheme)} is not one of themes.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** A saved value as a theme: one of `themes`, or else the default. */
|
|
24
|
+
export function parseTheme(value, options) {
|
|
25
|
+
return parsePreference(value, options.themes, options.defaultTheme);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* `createTheme` of each entry point, with the entry point's storage: the
|
|
29
|
+
* reader's theme, saved in `storage` and applied to `<html>`, through
|
|
30
|
+
* `createPreference`.
|
|
31
|
+
*/
|
|
32
|
+
export function createThemeWithStorage(storage, options) {
|
|
33
|
+
if (isDev)
|
|
34
|
+
checkThemes(options);
|
|
35
|
+
const preference = createPreference(storage, {
|
|
36
|
+
storageKey: options.storageKey ?? defaultStorageKey,
|
|
37
|
+
attribute: options.attribute ?? defaultAttribute,
|
|
38
|
+
values: options.themes,
|
|
39
|
+
unset: options.defaultTheme,
|
|
40
|
+
});
|
|
41
|
+
return { theme: preference.value, setTheme: preference.set };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* `themeScript` of each entry point, with the entry point's storage: the
|
|
45
|
+
* source of a script for the document head that applies the saved theme,
|
|
46
|
+
* or the default, before the page first paints.
|
|
47
|
+
*/
|
|
48
|
+
export function themeScriptWithStorage(storage, options) {
|
|
49
|
+
if (isDev)
|
|
50
|
+
checkThemes(options);
|
|
51
|
+
return preferenceScript(storage, {
|
|
52
|
+
storageKey: options.storageKey ?? defaultStorageKey,
|
|
53
|
+
attribute: options.attribute ?? defaultAttribute,
|
|
54
|
+
values: options.themes,
|
|
55
|
+
fallback: scriptLiteral(options.defaultTheme),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Toggle from "./index.parts.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Toggle from "./index.parts.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ToggleRoot as Root } from "./root/ToggleRoot.tsx";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ToggleRoot as Root } from "./root/ToggleRoot.jsx";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface ToggleRootProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** Whether the toggle is pressed, when controlled. */
|
|
5
|
+
pressed?: boolean;
|
|
6
|
+
/** Whether the toggle starts pressed, when uncontrolled. */
|
|
7
|
+
defaultPressed?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Called with the new value when the user presses or releases the
|
|
10
|
+
* toggle. When controlled, the toggle changes only if `pressed` does.
|
|
11
|
+
*/
|
|
12
|
+
onPressedChange?: (pressed: boolean) => void;
|
|
13
|
+
/** Whether the toggle ignores the user. It cannot be focused either. */
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
render?: RenderProp;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The toggle button itself: a `<button aria-pressed>`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ToggleRoot(props: ToggleRootProps): JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { omit } from "solid-js";
|
|
2
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
3
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
4
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
5
|
+
import { toggleButtonProps } from "../../core/toggleButton.js";
|
|
6
|
+
/**
|
|
7
|
+
* The toggle button itself: a `<button aria-pressed>`.
|
|
8
|
+
*/
|
|
9
|
+
export function ToggleRoot(props) {
|
|
10
|
+
const [pressed, setPressed] = createControllableSignal({
|
|
11
|
+
get value() {
|
|
12
|
+
return props.pressed;
|
|
13
|
+
},
|
|
14
|
+
get defaultValue() {
|
|
15
|
+
return props.defaultPressed ?? false;
|
|
16
|
+
},
|
|
17
|
+
onChange: (value) => props.onPressedChange?.(value),
|
|
18
|
+
});
|
|
19
|
+
const buttonProps = toggleButtonProps({
|
|
20
|
+
get value() {
|
|
21
|
+
return pressed();
|
|
22
|
+
},
|
|
23
|
+
get disabled() {
|
|
24
|
+
return props.disabled;
|
|
25
|
+
},
|
|
26
|
+
setValue: setPressed,
|
|
27
|
+
}, "Toggle.Root");
|
|
28
|
+
const elementProps = mergeElementProps(buttonProps, omit(props, "render", "pressed", "defaultPressed", "onPressedChange", "disabled"));
|
|
29
|
+
return renderElement(props, elementProps, (p) => <button {...p}/>);
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as ToggleGroup from "./index.parts.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as ToggleGroup from "./index.parts.js";
|