menhir 0.0.0 → 0.1.0
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 +44 -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,14 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface ToggleGroupItemProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** Identifies the item in the group's value. */
|
|
5
|
+
value: string;
|
|
6
|
+
/** Whether the item ignores the user. It cannot be focused either. */
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
render?: RenderProp;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* One toggle button of the group: a `<button aria-pressed>`. Place it
|
|
12
|
+
* inside `ToggleGroup.Root`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ToggleGroupItem(props: ToggleGroupItemProps): JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { merge, omit, onSettled, untrack } from "solid-js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
4
|
+
import { toggleButtonProps } from "../../core/toggleButton.js";
|
|
5
|
+
import { useToggleGroupRootContext } from "../root/ToggleGroupRootContext.js";
|
|
6
|
+
/**
|
|
7
|
+
* One toggle button of the group: a `<button aria-pressed>`. Place it
|
|
8
|
+
* inside `ToggleGroup.Root`.
|
|
9
|
+
*/
|
|
10
|
+
export function ToggleGroupItem(props) {
|
|
11
|
+
const group = useToggleGroupRootContext();
|
|
12
|
+
let element;
|
|
13
|
+
const own = toggleButtonProps({
|
|
14
|
+
get value() {
|
|
15
|
+
return group.pressed(props.value);
|
|
16
|
+
},
|
|
17
|
+
get disabled() {
|
|
18
|
+
return !!(group.disabled() || props.disabled);
|
|
19
|
+
},
|
|
20
|
+
setValue: (pressed) => group.press(props.value, pressed),
|
|
21
|
+
}, "ToggleGroup.Item");
|
|
22
|
+
// Read once: the tab stop of the server HTML, and of the first render.
|
|
23
|
+
const first = group.claimTabStop(untrack(() => own.disabled));
|
|
24
|
+
const itemProps = merge(own, {
|
|
25
|
+
get tabindex() {
|
|
26
|
+
return group.isTabStop(element, first) ? 0 : -1;
|
|
27
|
+
},
|
|
28
|
+
onFocus: () => group.setActive(element),
|
|
29
|
+
onKeyDown: (event) => group.navigate(event, element),
|
|
30
|
+
ref: (el) => {
|
|
31
|
+
element = el;
|
|
32
|
+
own.ref(el);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
// Mounted, so its place in the document is known.
|
|
36
|
+
onSettled(() => group.register({ element: element, disabled: () => own.disabled }));
|
|
37
|
+
const elementProps = mergeElementProps(itemProps, omit(props, "render", "value", "disabled"));
|
|
38
|
+
return renderElement(props, elementProps, (p) => <button {...p}/>);
|
|
39
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface ToggleGroupRootProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** The values of the pressed items, when controlled. */
|
|
5
|
+
value?: string[];
|
|
6
|
+
/** The values of the items pressed at first, when uncontrolled. */
|
|
7
|
+
defaultValue?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Called with the new values when the user presses or releases an item.
|
|
10
|
+
* When controlled, the group changes only if `value` does.
|
|
11
|
+
*/
|
|
12
|
+
onValueChange?: (value: string[]) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Whether several items can be pressed at once. Otherwise pressing an
|
|
15
|
+
* item releases the one pressed before.
|
|
16
|
+
*/
|
|
17
|
+
multiple?: boolean;
|
|
18
|
+
/** Whether every item ignores the user. They cannot be focused either. */
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
/** Whether the items are laid out side by side, or stacked. */
|
|
21
|
+
orientation?: "horizontal" | "vertical";
|
|
22
|
+
render?: RenderProp;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A set of toggle buttons that share one value: a `<div role="group">`
|
|
26
|
+
* around `ToggleGroup.Item`s, with one tab stop among them.
|
|
27
|
+
*/
|
|
28
|
+
export declare function ToggleGroupRoot(props: ToggleGroupRootProps): JSX.Element;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createSignal, omit } from "solid-js";
|
|
2
|
+
import { createListValue } from "../../core/listValue.js";
|
|
3
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
4
|
+
import { createRovingFocus } from "../../core/rovingFocus.js";
|
|
5
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
6
|
+
import { ToggleGroupRootContext } from "./ToggleGroupRootContext.js";
|
|
7
|
+
/**
|
|
8
|
+
* A set of toggle buttons that share one value: a `<div role="group">`
|
|
9
|
+
* around `ToggleGroup.Item`s, with one tab stop among them.
|
|
10
|
+
*/
|
|
11
|
+
export function ToggleGroupRoot(props) {
|
|
12
|
+
const pressed = createListValue({
|
|
13
|
+
get value() {
|
|
14
|
+
return props.value;
|
|
15
|
+
},
|
|
16
|
+
get defaultValue() {
|
|
17
|
+
return props.defaultValue;
|
|
18
|
+
},
|
|
19
|
+
get multiple() {
|
|
20
|
+
return props.multiple;
|
|
21
|
+
},
|
|
22
|
+
onChange: (value) => props.onValueChange?.(value),
|
|
23
|
+
});
|
|
24
|
+
const vertical = () => props.orientation === "vertical";
|
|
25
|
+
// The item that last had focus has the tab stop, else the first enabled
|
|
26
|
+
// one.
|
|
27
|
+
const [active, setActive] = createSignal();
|
|
28
|
+
const roving = createRovingFocus({
|
|
29
|
+
get vertical() {
|
|
30
|
+
return vertical();
|
|
31
|
+
},
|
|
32
|
+
focusable: (item) => !item.disabled(),
|
|
33
|
+
preferred: (item) => item.element === active(),
|
|
34
|
+
});
|
|
35
|
+
// Whether an item has claimed the tab stop of the server HTML.
|
|
36
|
+
let claimed = false;
|
|
37
|
+
const context = {
|
|
38
|
+
...roving,
|
|
39
|
+
pressed: pressed.has,
|
|
40
|
+
press: pressed.set,
|
|
41
|
+
disabled: () => props.disabled,
|
|
42
|
+
// Before any item has registered, as on the server, the first enabled
|
|
43
|
+
// item created has the tab stop, so the server HTML has one too.
|
|
44
|
+
claimTabStop: (disabled) => !disabled && !claimed && (claimed = true),
|
|
45
|
+
setActive: (element) => setActive(element),
|
|
46
|
+
};
|
|
47
|
+
const ownProps = {
|
|
48
|
+
role: "group",
|
|
49
|
+
// The group role takes no orientation; a toolbar does, horizontal unless
|
|
50
|
+
// it says otherwise.
|
|
51
|
+
get "aria-orientation"() {
|
|
52
|
+
return props.role === "toolbar" && vertical() ? "vertical" : undefined;
|
|
53
|
+
},
|
|
54
|
+
get "data-horizontal"() {
|
|
55
|
+
return vertical() ? undefined : "";
|
|
56
|
+
},
|
|
57
|
+
get "data-vertical"() {
|
|
58
|
+
return vertical() ? "" : undefined;
|
|
59
|
+
},
|
|
60
|
+
get "data-disabled"() {
|
|
61
|
+
return props.disabled ? "" : undefined;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "defaultValue", "onValueChange", "multiple", "disabled", "orientation"));
|
|
65
|
+
return (<ToggleGroupRootContext value={context}>
|
|
66
|
+
{renderElement(props, elementProps, (p) => (<div {...p}/>))}
|
|
67
|
+
</ToggleGroupRootContext>);
|
|
68
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RovingFocus } from "../../core/rovingFocus.ts";
|
|
2
|
+
/** An item as the group knows it, for focus order and the tab stop. */
|
|
3
|
+
export interface ToggleGroupItemEntry {
|
|
4
|
+
readonly element: HTMLElement;
|
|
5
|
+
readonly disabled: () => boolean;
|
|
6
|
+
}
|
|
7
|
+
/** What the group shares with its items, with their roving focus. */
|
|
8
|
+
export interface ToggleGroupRootContextValue extends RovingFocus<ToggleGroupItemEntry> {
|
|
9
|
+
/** Whether the item with this value is pressed. */
|
|
10
|
+
pressed(value: string): boolean;
|
|
11
|
+
/** Asks to press or release the item with this value. */
|
|
12
|
+
press(value: string, pressed: boolean): void;
|
|
13
|
+
/** Whether the whole group is disabled. */
|
|
14
|
+
disabled(): boolean | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Whether the item being created is the group's first enabled item, which
|
|
17
|
+
* has the tab stop before any item has registered, as on the server.
|
|
18
|
+
* Called once per item, in its body.
|
|
19
|
+
*/
|
|
20
|
+
claimTabStop(disabled: boolean): boolean;
|
|
21
|
+
/** Records the item that received focus, which takes the tab stop. */
|
|
22
|
+
setActive(element: HTMLElement): void;
|
|
23
|
+
}
|
|
24
|
+
export declare const ToggleGroupRootContext: import("solid-js").Context<ToggleGroupRootContextValue | null>;
|
|
25
|
+
export declare function useToggleGroupRootContext(): ToggleGroupRootContextValue;
|
|
@@ -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 ToggleGroupRootContext = createContext(null);
|
|
6
|
+
export function useToggleGroupRootContext() {
|
|
7
|
+
const context = useContext(ToggleGroupRootContext);
|
|
8
|
+
// Production builds drop the check, and its message, with `isDev`.
|
|
9
|
+
if (isDev && !context) {
|
|
10
|
+
throw new Error("[menhir] ToggleGroup parts must be placed within <ToggleGroup.Root>.");
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { warnUnlessButton } from "../../core/button.js";
|
|
2
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
3
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
4
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
5
|
+
import { SwitchRootContext } from "./SwitchRootContext.js";
|
|
6
|
+
import { createComponent, effect, heldRead, isDev, memo, ref, setAttribute, setProperty, spread, template } from "@solidjs/web";
|
|
7
|
+
import { merge, omit, onFlush, onSettled, untrack } from "solid-js";
|
|
8
|
+
// src/switch/root/SwitchRoot.tsx
|
|
9
|
+
var _tmpl$ = /* @__PURE__ */ template(`<input type=checkbox aria-hidden=true tabindex=-1 style=position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none>`);
|
|
10
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<button>`);
|
|
11
|
+
/**
|
|
12
|
+
* The switch itself: a `<button role="switch">`.
|
|
13
|
+
*/
|
|
14
|
+
function SwitchRoot(props) {
|
|
15
|
+
const [checked, setChecked] = createControllableSignal({
|
|
16
|
+
get value() {
|
|
17
|
+
return props.checked;
|
|
18
|
+
},
|
|
19
|
+
get defaultValue() {
|
|
20
|
+
return props.defaultChecked ?? false;
|
|
21
|
+
},
|
|
22
|
+
onChange: (value) => props.onCheckedChange?.(value)
|
|
23
|
+
});
|
|
24
|
+
const stateAttributes = {
|
|
25
|
+
get "data-checked"() {
|
|
26
|
+
return checked() ? "" : void 0;
|
|
27
|
+
},
|
|
28
|
+
get "data-unchecked"() {
|
|
29
|
+
return checked() ? void 0 : "";
|
|
30
|
+
},
|
|
31
|
+
get "data-disabled"() {
|
|
32
|
+
return props.disabled ? "" : void 0;
|
|
33
|
+
},
|
|
34
|
+
get "data-readonly"() {
|
|
35
|
+
return props.readOnly ? "" : void 0;
|
|
36
|
+
},
|
|
37
|
+
get "data-required"() {
|
|
38
|
+
return props.required ? "" : void 0;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const buttonProps = {
|
|
42
|
+
role: "switch",
|
|
43
|
+
type: "button",
|
|
44
|
+
get disabled() {
|
|
45
|
+
return props.disabled;
|
|
46
|
+
},
|
|
47
|
+
get "aria-checked"() {
|
|
48
|
+
return checked() ? "true" : "false";
|
|
49
|
+
},
|
|
50
|
+
get "aria-readonly"() {
|
|
51
|
+
return props.readOnly ? "true" : void 0;
|
|
52
|
+
},
|
|
53
|
+
get "aria-required"() {
|
|
54
|
+
return props.required ? "true" : void 0;
|
|
55
|
+
},
|
|
56
|
+
onClick: () => input?.click(),
|
|
57
|
+
ref: (element) => {
|
|
58
|
+
button = element;
|
|
59
|
+
if (isDev) warnUnlessButton(element, "Switch.Root");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
let button;
|
|
63
|
+
let input;
|
|
64
|
+
const syncInput = () => {
|
|
65
|
+
if (input) input.checked = untrack(checked);
|
|
66
|
+
};
|
|
67
|
+
const onInputChange = () => {
|
|
68
|
+
if (!input) return;
|
|
69
|
+
setChecked(input.checked);
|
|
70
|
+
onFlush(syncInput);
|
|
71
|
+
};
|
|
72
|
+
const onInputClick = (event) => {
|
|
73
|
+
event.stopPropagation();
|
|
74
|
+
if (props.readOnly) event.preventDefault();
|
|
75
|
+
};
|
|
76
|
+
onSettled(() => {
|
|
77
|
+
const form = input?.form;
|
|
78
|
+
if (!form) return;
|
|
79
|
+
const onReset = () => {
|
|
80
|
+
setChecked(props.defaultChecked ?? false);
|
|
81
|
+
onFlush(syncInput);
|
|
82
|
+
};
|
|
83
|
+
form.addEventListener("reset", onReset);
|
|
84
|
+
return () => form.removeEventListener("reset", onReset);
|
|
85
|
+
});
|
|
86
|
+
const elementProps = mergeElementProps(merge(stateAttributes, buttonProps), omit(props, "render", "checked", "defaultChecked", "onCheckedChange", "name", "value", "disabled", "readOnly", "required", "form"));
|
|
87
|
+
return createComponent(SwitchRootContext, {
|
|
88
|
+
value: stateAttributes,
|
|
89
|
+
get children() {
|
|
90
|
+
return [memo(() => {
|
|
91
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
92
|
+
var _el$2 = _tmpl$2();
|
|
93
|
+
spread(_el$2, p, false);
|
|
94
|
+
return _el$2;
|
|
95
|
+
})());
|
|
96
|
+
}), (() => {
|
|
97
|
+
var _el$ = _tmpl$();
|
|
98
|
+
_el$.addEventListener("focus", () => button?.focus());
|
|
99
|
+
_el$.addEventListener("change", onInputChange);
|
|
100
|
+
ref(() => {
|
|
101
|
+
return (element) => {
|
|
102
|
+
input = element;
|
|
103
|
+
element.addEventListener("click", onInputClick);
|
|
104
|
+
};
|
|
105
|
+
}, _el$);
|
|
106
|
+
effect(() => {
|
|
107
|
+
return {
|
|
108
|
+
e: props.name,
|
|
109
|
+
t: props.value,
|
|
110
|
+
a: props.disabled,
|
|
111
|
+
o: props.required,
|
|
112
|
+
i: props.form,
|
|
113
|
+
n: checked(),
|
|
114
|
+
s: heldRead()
|
|
115
|
+
};
|
|
116
|
+
}, ({ e, t, a, o, i, n, s }, _p$) => {
|
|
117
|
+
e !== _p$?.e && setAttribute(_el$, "name", e);
|
|
118
|
+
(t !== _p$?.t || !s) && setProperty(_el$, "value", t);
|
|
119
|
+
a !== _p$?.a && setAttribute(_el$, "disabled", a);
|
|
120
|
+
o !== _p$?.o && setAttribute(_el$, "required", o);
|
|
121
|
+
i !== _p$?.i && setAttribute(_el$, "form", i);
|
|
122
|
+
(n !== _p$?.n || !s) && (_el$.checked = n);
|
|
123
|
+
});
|
|
124
|
+
return _el$;
|
|
125
|
+
})()];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
export { SwitchRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/switch/root/SwitchRootContext.ts
|
|
4
|
+
var SwitchRootContext = createContext(null);
|
|
5
|
+
function useSwitchRootContext() {
|
|
6
|
+
const context = useContext(SwitchRootContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Switch parts must be placed within <Switch.Root>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { SwitchRootContext, useSwitchRootContext };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useSwitchRootContext } from "../root/SwitchRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { omit } from "solid-js";
|
|
6
|
+
// src/switch/thumb/SwitchThumb.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<span>`);
|
|
8
|
+
/**
|
|
9
|
+
* The part of the switch that slides between off and on: a `<span>` with
|
|
10
|
+
* the Root's `data-*` attributes. Place it inside `Switch.Root`.
|
|
11
|
+
*/
|
|
12
|
+
function SwitchThumb(props) {
|
|
13
|
+
const elementProps = mergeElementProps(useSwitchRootContext(), omit(props, "render"));
|
|
14
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
15
|
+
var _el$ = _tmpl$();
|
|
16
|
+
spread(_el$, p, false);
|
|
17
|
+
return _el$;
|
|
18
|
+
})());
|
|
19
|
+
}
|
|
20
|
+
export { SwitchThumb };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TabsRoot } from "./root/TabsRoot.js";
|
|
2
|
+
import { TabsList } from "./list/TabsList.js";
|
|
3
|
+
import { TabsTab } from "./tab/TabsTab.js";
|
|
4
|
+
import { TabsPanel } from "./panel/TabsPanel.js";
|
|
5
|
+
export { TabsList as List, TabsPanel as Panel, TabsRoot as Root, TabsTab as Tab };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useTabsRootContext } from "../root/TabsRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { omit } from "solid-js";
|
|
6
|
+
// src/tabs/list/TabsList.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
8
|
+
/**
|
|
9
|
+
* The list of tabs: a `<div role="tablist">` around `Tabs.Tab`s, with one
|
|
10
|
+
* tab stop among them. Name it with `aria-label` or `aria-labelledby`.
|
|
11
|
+
* Place it inside `Tabs.Root`.
|
|
12
|
+
*/
|
|
13
|
+
function TabsList(props) {
|
|
14
|
+
const root = useTabsRootContext();
|
|
15
|
+
const elementProps = mergeElementProps({
|
|
16
|
+
role: "tablist",
|
|
17
|
+
get "aria-orientation"() {
|
|
18
|
+
return root.vertical() ? "vertical" : void 0;
|
|
19
|
+
},
|
|
20
|
+
get "data-horizontal"() {
|
|
21
|
+
return root.vertical() ? void 0 : "";
|
|
22
|
+
},
|
|
23
|
+
get "data-vertical"() {
|
|
24
|
+
return root.vertical() ? "" : void 0;
|
|
25
|
+
}
|
|
26
|
+
}, omit(props, "render"));
|
|
27
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
28
|
+
var _el$ = _tmpl$();
|
|
29
|
+
spread(_el$, p, false);
|
|
30
|
+
return _el$;
|
|
31
|
+
})());
|
|
32
|
+
}
|
|
33
|
+
export { TabsList };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useTabsRootContext } from "../root/TabsRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { omit } from "solid-js";
|
|
6
|
+
// src/tabs/panel/TabsPanel.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
8
|
+
/**
|
|
9
|
+
* The content its tab shows: a `<div role="tabpanel">` named by the tab,
|
|
10
|
+
* `hidden` unless the tab is selected. Place it inside `Tabs.Root`.
|
|
11
|
+
*/
|
|
12
|
+
function TabsPanel(props) {
|
|
13
|
+
const root = useTabsRootContext();
|
|
14
|
+
const selected = () => root.selected(props.value);
|
|
15
|
+
const elementProps = mergeElementProps({
|
|
16
|
+
role: "tabpanel",
|
|
17
|
+
get id() {
|
|
18
|
+
return root.panelId(props.value);
|
|
19
|
+
},
|
|
20
|
+
get "aria-labelledby"() {
|
|
21
|
+
return root.tabId(props.value);
|
|
22
|
+
},
|
|
23
|
+
tabindex: 0,
|
|
24
|
+
get hidden() {
|
|
25
|
+
return !selected();
|
|
26
|
+
},
|
|
27
|
+
get "data-selected"() {
|
|
28
|
+
return selected() ? "" : void 0;
|
|
29
|
+
},
|
|
30
|
+
get "data-unselected"() {
|
|
31
|
+
return selected() ? void 0 : "";
|
|
32
|
+
}
|
|
33
|
+
}, omit(props, "render", "value", "id"));
|
|
34
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
35
|
+
var _el$ = _tmpl$();
|
|
36
|
+
spread(_el$, p, false);
|
|
37
|
+
return _el$;
|
|
38
|
+
})());
|
|
39
|
+
}
|
|
40
|
+
export { TabsPanel };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { createRovingFocus } from "../../core/rovingFocus.js";
|
|
5
|
+
import { TabsRootContext } from "./TabsRootContext.js";
|
|
6
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
7
|
+
import { createSignal, createUniqueId, omit } from "solid-js";
|
|
8
|
+
// src/tabs/root/TabsRoot.tsx
|
|
9
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
10
|
+
/**
|
|
11
|
+
* Layered sections of content, one shown at a time: a `<div>` around a
|
|
12
|
+
* `Tabs.List` of `Tabs.Tab`s and their `Tabs.Panel`s.
|
|
13
|
+
*/
|
|
14
|
+
function TabsRoot(props) {
|
|
15
|
+
const [value, setValue] = createControllableSignal({
|
|
16
|
+
get value() {
|
|
17
|
+
return props.value;
|
|
18
|
+
},
|
|
19
|
+
get defaultValue() {
|
|
20
|
+
return props.defaultValue;
|
|
21
|
+
},
|
|
22
|
+
onChange: (value) => props.onValueChange?.(value)
|
|
23
|
+
});
|
|
24
|
+
let first;
|
|
25
|
+
const selected = () => {
|
|
26
|
+
const current = value();
|
|
27
|
+
return current === void 0 ? first : current;
|
|
28
|
+
};
|
|
29
|
+
const vertical = () => props.orientation === "vertical";
|
|
30
|
+
const id = createUniqueId();
|
|
31
|
+
const [focused, setFocused] = createSignal();
|
|
32
|
+
const context = {
|
|
33
|
+
...createRovingFocus({
|
|
34
|
+
get vertical() {
|
|
35
|
+
return vertical();
|
|
36
|
+
},
|
|
37
|
+
focusable: () => true,
|
|
38
|
+
preferred: (tab) => focused() ? tab.element === focused() : selected() === tab.value()
|
|
39
|
+
}),
|
|
40
|
+
selected: (tab) => selected() === tab,
|
|
41
|
+
select: (tab) => {
|
|
42
|
+
if (selected() !== tab) setValue(tab);
|
|
43
|
+
},
|
|
44
|
+
claimFirst: (tab, disabled) => {
|
|
45
|
+
if (!disabled) first ??= tab;
|
|
46
|
+
},
|
|
47
|
+
vertical,
|
|
48
|
+
automatic: () => props.activation !== "manual",
|
|
49
|
+
generatedTabId: (tab) => `${id}-tab-${tab}`,
|
|
50
|
+
tabId: (tab) => context.tabIds[tab]?.() ?? context.generatedTabId(tab),
|
|
51
|
+
tabIds: {},
|
|
52
|
+
panelId: (tab) => `${id}-panel-${tab}`,
|
|
53
|
+
setFocused: (element) => setFocused(element)
|
|
54
|
+
};
|
|
55
|
+
const elementProps = mergeElementProps({
|
|
56
|
+
get "data-horizontal"() {
|
|
57
|
+
return vertical() ? void 0 : "";
|
|
58
|
+
},
|
|
59
|
+
get "data-vertical"() {
|
|
60
|
+
return vertical() ? "" : void 0;
|
|
61
|
+
}
|
|
62
|
+
}, omit(props, "render", "value", "defaultValue", "onValueChange", "orientation", "activation"));
|
|
63
|
+
return createComponent(TabsRootContext, {
|
|
64
|
+
value: context,
|
|
65
|
+
get children() {
|
|
66
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
67
|
+
var _el$ = _tmpl$();
|
|
68
|
+
spread(_el$, p, false);
|
|
69
|
+
return _el$;
|
|
70
|
+
})());
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export { TabsRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/tabs/root/TabsRootContext.ts
|
|
4
|
+
var TabsRootContext = createContext(null);
|
|
5
|
+
function useTabsRootContext() {
|
|
6
|
+
const context = useContext(TabsRootContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Tabs parts must be placed within <Tabs.Root>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { TabsRootContext, useTabsRootContext };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { warnUnlessButton } from "../../core/button.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { useTabsRootContext } from "../root/TabsRootContext.js";
|
|
5
|
+
import { isDev, spread, template } from "@solidjs/web";
|
|
6
|
+
import { omit, onSettled, untrack } from "solid-js";
|
|
7
|
+
// src/tabs/tab/TabsTab.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* One tab, which shows its `Tabs.Panel` when selected: a
|
|
11
|
+
* `<button role="tab" aria-selected>`. Place it inside `Tabs.List`.
|
|
12
|
+
*/
|
|
13
|
+
function TabsTab(props) {
|
|
14
|
+
const root = useTabsRootContext();
|
|
15
|
+
let element;
|
|
16
|
+
const selected = () => root.selected(props.value);
|
|
17
|
+
const select = () => {
|
|
18
|
+
if (!props.disabled) root.select(props.value);
|
|
19
|
+
};
|
|
20
|
+
const value = untrack(() => props.value);
|
|
21
|
+
root.claimFirst(value, untrack(() => !!props.disabled));
|
|
22
|
+
const id = () => props.id ?? root.generatedTabId(props.value);
|
|
23
|
+
root.tabIds[value] = id;
|
|
24
|
+
const ownProps = {
|
|
25
|
+
type: "button",
|
|
26
|
+
role: "tab",
|
|
27
|
+
get id() {
|
|
28
|
+
return id();
|
|
29
|
+
},
|
|
30
|
+
get "aria-selected"() {
|
|
31
|
+
return selected() ? "true" : "false";
|
|
32
|
+
},
|
|
33
|
+
get "aria-controls"() {
|
|
34
|
+
return root.panelId(props.value);
|
|
35
|
+
},
|
|
36
|
+
get "aria-disabled"() {
|
|
37
|
+
return props.disabled ? "true" : void 0;
|
|
38
|
+
},
|
|
39
|
+
get tabindex() {
|
|
40
|
+
return root.isTabStop(element, selected()) ? 0 : -1;
|
|
41
|
+
},
|
|
42
|
+
get "data-selected"() {
|
|
43
|
+
return selected() ? "" : void 0;
|
|
44
|
+
},
|
|
45
|
+
get "data-unselected"() {
|
|
46
|
+
return selected() ? void 0 : "";
|
|
47
|
+
},
|
|
48
|
+
get "data-disabled"() {
|
|
49
|
+
return props.disabled ? "" : void 0;
|
|
50
|
+
},
|
|
51
|
+
onClick: select,
|
|
52
|
+
onFocus: () => {
|
|
53
|
+
root.setFocused(element);
|
|
54
|
+
if (root.automatic()) select();
|
|
55
|
+
},
|
|
56
|
+
onBlur: () => root.setFocused(void 0),
|
|
57
|
+
onKeyDown: (event) => root.navigate(event, element),
|
|
58
|
+
ref: (el) => {
|
|
59
|
+
element = el;
|
|
60
|
+
if (isDev) warnUnlessButton(el, "Tabs.Tab");
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
onSettled(() => root.register({
|
|
64
|
+
element,
|
|
65
|
+
value: () => props.value
|
|
66
|
+
}));
|
|
67
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "disabled", "id"));
|
|
68
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
69
|
+
var _el$ = _tmpl$();
|
|
70
|
+
spread(_el$, p, false);
|
|
71
|
+
return _el$;
|
|
72
|
+
})());
|
|
73
|
+
}
|
|
74
|
+
export { TabsTab };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { cookiePreference, cookieValue } from "../../core/preference/cookiePreference.js";
|
|
2
|
+
import { createThemeWithStorage, parseTheme, themeScriptWithStorage } from "../theme.js";
|
|
3
|
+
// src/theme/cookie/cookie.ts
|
|
4
|
+
var storage = cookiePreference;
|
|
5
|
+
/**
|
|
6
|
+
* The reader's choice of theme, saved in a cookie and applied to
|
|
7
|
+
* `<html>` (`ThemeOptions.attribute`). Stays in step with the other
|
|
8
|
+
* instances in this tab, and with other tabs once they are shown again.
|
|
9
|
+
*
|
|
10
|
+
* Call it in a component. The cookie is read during the first render, on
|
|
11
|
+
* the server from the request (`getRequestEvent()`), so the server's HTML
|
|
12
|
+
* shows the theme and hydration agrees. The page has to be rendered for
|
|
13
|
+
* each request: a prerendered page has no cookie to read.
|
|
14
|
+
*/
|
|
15
|
+
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 the cookie, or the default, before the page first paints. Pass
|
|
21
|
+
* the options given to `createTheme`. Render it inline, before any styles
|
|
22
|
+
* that depend on the theme. With the theme rendered on the server, it only
|
|
23
|
+
* applies what the server rendered, and can be left out.
|
|
24
|
+
*
|
|
25
|
+
* ```tsx
|
|
26
|
+
* <script innerHTML={themeScript(options)} />
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Under a Content Security Policy without `'unsafe-inline'`, put the
|
|
30
|
+
* policy's nonce on the element (`<script nonce={nonce} …>`), or allow the
|
|
31
|
+
* SHA-256 hash of the returned source.
|
|
32
|
+
*/
|
|
33
|
+
function themeScript(options) {
|
|
34
|
+
return themeScriptWithStorage(storage, options);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The theme saved in a `Cookie` request header, or the default, for a
|
|
38
|
+
* server that puts the attribute on its own `<html>`. Pass the options
|
|
39
|
+
* given to `createTheme`.
|
|
40
|
+
*/
|
|
41
|
+
function themeFromCookie(cookieHeader, options) {
|
|
42
|
+
return parseTheme(cookieValue(cookieHeader, options.storageKey ?? "theme"), options);
|
|
43
|
+
}
|
|
44
|
+
export { createTheme, themeFromCookie, themeScript };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createTheme, themeFromCookie, themeScript } from "./cookie.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createTheme, themeScript } from "./localStorage.js";
|