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
package/LICENSE
CHANGED
|
@@ -19,31 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
--------------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
Portions of this software, including component behaviour and tests, are ported
|
|
26
|
-
from Base UI (https://github.com/mui/base-ui), which is distributed under the
|
|
27
|
-
following licence:
|
|
28
|
-
|
|
29
|
-
MIT License
|
|
30
|
-
|
|
31
|
-
Copyright (c) 2019 Material-UI SAS
|
|
32
|
-
|
|
33
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
34
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
35
|
-
in the Software without restriction, including without limitation the rights
|
|
36
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
37
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
38
|
-
furnished to do so, subject to the following conditions:
|
|
39
|
-
|
|
40
|
-
The above copyright notice and this permission notice shall be included in all
|
|
41
|
-
copies or substantial portions of the Software.
|
|
42
|
-
|
|
43
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
44
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
45
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
46
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
47
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
48
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
49
|
-
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,9 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
Unstyled, accessible UI primitives for SolidJS 2.0, with small and measurable bundles.
|
|
4
4
|
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add menhir
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Menhir needs Solid 2.0: `solid-js` and `@solidjs/web` are peer dependencies.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Each component has its own entry point, so an app ships only what it imports:
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { Switch } from "menhir/switch";
|
|
19
|
+
|
|
20
|
+
export function AirplaneMode() {
|
|
21
|
+
return (
|
|
22
|
+
<label>
|
|
23
|
+
<Switch.Root name="airplane-mode" class="switch">
|
|
24
|
+
<Switch.Thumb class="thumb" />
|
|
25
|
+
</Switch.Root>
|
|
26
|
+
Airplane mode
|
|
27
|
+
</label>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Nothing is styled. Every part exposes its state as data attributes, such as `data-checked`, for your CSS to select:
|
|
33
|
+
|
|
34
|
+
```css
|
|
35
|
+
.switch[data-checked] {
|
|
36
|
+
background: steelblue;
|
|
37
|
+
}
|
|
38
|
+
.thumb[data-checked] {
|
|
39
|
+
transform: translateX(1.25rem);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The docs, with a live example and the measured size of each entry point, are at [menhir-ui.com](https://menhir-ui.com).
|
|
44
|
+
|
|
5
45
|
## Status
|
|
6
46
|
|
|
7
|
-
|
|
47
|
+
Early 0.x versions: the API may change between minor versions. Dialog, Popover and the other popups come next; the plan and roadmap are in the [repository](https://github.com/j13n/menhir). Built so far:
|
|
48
|
+
|
|
49
|
+
- Components: Accordion, Checkbox, Collapsible, Meter, Progress, Separator, Switch, Tabs, Toggle and Toggle Group.
|
|
50
|
+
- Utilities: color scheme and theme, each with local-storage and cookie storage.
|
|
8
51
|
|
|
9
52
|
## Licence
|
|
10
53
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useAccordionItemContext } from "../item/AccordionItemContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { omit } from "solid-js";
|
|
6
|
+
// src/accordion/header/AccordionHeader.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<h3>`);
|
|
8
|
+
/**
|
|
9
|
+
* The heading of a section, which holds only its `Accordion.Trigger`: an
|
|
10
|
+
* `<h3>`. Render another level with `render={(props) => <h2 {...props} />}`.
|
|
11
|
+
* Place it inside `Accordion.Item`.
|
|
12
|
+
*/
|
|
13
|
+
function AccordionHeader(props) {
|
|
14
|
+
const item = useAccordionItemContext();
|
|
15
|
+
const elementProps = mergeElementProps(item.attributes, omit(props, "render"));
|
|
16
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
17
|
+
var _el$ = _tmpl$();
|
|
18
|
+
spread(_el$, p, false);
|
|
19
|
+
return _el$;
|
|
20
|
+
})());
|
|
21
|
+
}
|
|
22
|
+
export { AccordionHeader };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AccordionRoot } from "./root/AccordionRoot.js";
|
|
2
|
+
import { AccordionItem } from "./item/AccordionItem.js";
|
|
3
|
+
import { AccordionHeader } from "./header/AccordionHeader.js";
|
|
4
|
+
import { AccordionTrigger } from "./trigger/AccordionTrigger.js";
|
|
5
|
+
import { AccordionPanel } from "./panel/AccordionPanel.js";
|
|
6
|
+
export { AccordionHeader as Header, AccordionItem as Item, AccordionPanel as Panel, AccordionRoot as Root, AccordionTrigger as Trigger };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useAccordionRootContext } from "../root/AccordionRootContext.js";
|
|
4
|
+
import { AccordionItemContext } from "./AccordionItemContext.js";
|
|
5
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
+
import { createUniqueId, omit } from "solid-js";
|
|
7
|
+
// src/accordion/item/AccordionItem.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
9
|
+
/**
|
|
10
|
+
* One section of the accordion: a `<div>` around `Accordion.Header` and
|
|
11
|
+
* `Accordion.Panel`. Place it inside `Accordion.Root`.
|
|
12
|
+
*/
|
|
13
|
+
function AccordionItem(props) {
|
|
14
|
+
const root = useAccordionRootContext();
|
|
15
|
+
const panelId = createUniqueId();
|
|
16
|
+
const generatedTriggerId = createUniqueId();
|
|
17
|
+
const value = () => props.value ?? panelId;
|
|
18
|
+
const open = () => root.open(value());
|
|
19
|
+
const disabled = () => !!(root.disabled() || props.disabled);
|
|
20
|
+
const attributes = {
|
|
21
|
+
get "data-open"() {
|
|
22
|
+
return open() ? "" : void 0;
|
|
23
|
+
},
|
|
24
|
+
get "data-closed"() {
|
|
25
|
+
return open() ? void 0 : "";
|
|
26
|
+
},
|
|
27
|
+
get "data-disabled"() {
|
|
28
|
+
return disabled() ? "" : void 0;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const context = {
|
|
32
|
+
open,
|
|
33
|
+
setOpen: (next) => root.setOpen(value(), next),
|
|
34
|
+
disabled,
|
|
35
|
+
panelId,
|
|
36
|
+
triggerId: () => generatedTriggerId,
|
|
37
|
+
attributes
|
|
38
|
+
};
|
|
39
|
+
const elementProps = mergeElementProps(attributes, omit(props, "render", "value", "disabled"));
|
|
40
|
+
return createComponent(AccordionItemContext, {
|
|
41
|
+
value: context,
|
|
42
|
+
get children() {
|
|
43
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
44
|
+
var _el$ = _tmpl$();
|
|
45
|
+
spread(_el$, p, false);
|
|
46
|
+
return _el$;
|
|
47
|
+
})());
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export { AccordionItem };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/accordion/item/AccordionItemContext.ts
|
|
4
|
+
var AccordionItemContext = createContext(null);
|
|
5
|
+
function useAccordionItemContext() {
|
|
6
|
+
const context = useContext(AccordionItemContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Accordion parts must be placed within <Accordion.Item>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { AccordionItemContext, useAccordionItemContext };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useAccordionItemContext } from "../item/AccordionItemContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { merge, omit } from "solid-js";
|
|
6
|
+
// src/accordion/panel/AccordionPanel.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
8
|
+
/**
|
|
9
|
+
* The content its section's Trigger shows and hides: a
|
|
10
|
+
* `<div role="region">` named by the Trigger, `hidden` while closed. Place
|
|
11
|
+
* it inside `Accordion.Item`, after `Accordion.Header`.
|
|
12
|
+
*/
|
|
13
|
+
function AccordionPanel(props) {
|
|
14
|
+
const item = useAccordionItemContext();
|
|
15
|
+
const ownProps = merge(item.attributes, {
|
|
16
|
+
id: item.panelId,
|
|
17
|
+
role: "region",
|
|
18
|
+
get "aria-labelledby"() {
|
|
19
|
+
return item.triggerId();
|
|
20
|
+
},
|
|
21
|
+
get hidden() {
|
|
22
|
+
return !item.open();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
26
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
27
|
+
var _el$ = _tmpl$();
|
|
28
|
+
spread(_el$, p, false);
|
|
29
|
+
return _el$;
|
|
30
|
+
})());
|
|
31
|
+
}
|
|
32
|
+
export { AccordionPanel };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createListValue } from "../../core/listValue.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { AccordionRootContext } from "./AccordionRootContext.js";
|
|
5
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
+
import { omit } from "solid-js";
|
|
7
|
+
// src/accordion/root/AccordionRoot.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
9
|
+
/**
|
|
10
|
+
* A stack of sections, each shown and hidden by its heading's button: a
|
|
11
|
+
* `<div>` around `Accordion.Item`s.
|
|
12
|
+
*/
|
|
13
|
+
function AccordionRoot(props) {
|
|
14
|
+
const open = createListValue({
|
|
15
|
+
get value() {
|
|
16
|
+
return props.value;
|
|
17
|
+
},
|
|
18
|
+
get defaultValue() {
|
|
19
|
+
return props.defaultValue;
|
|
20
|
+
},
|
|
21
|
+
get multiple() {
|
|
22
|
+
return props.multiple;
|
|
23
|
+
},
|
|
24
|
+
onChange: (value) => props.onValueChange?.(value)
|
|
25
|
+
});
|
|
26
|
+
const context = {
|
|
27
|
+
open: open.has,
|
|
28
|
+
setOpen: open.set,
|
|
29
|
+
disabled: () => props.disabled
|
|
30
|
+
};
|
|
31
|
+
const elementProps = mergeElementProps({ get "data-disabled"() {
|
|
32
|
+
return props.disabled ? "" : void 0;
|
|
33
|
+
} }, omit(props, "render", "value", "defaultValue", "onValueChange", "multiple", "disabled"));
|
|
34
|
+
return createComponent(AccordionRootContext, {
|
|
35
|
+
value: context,
|
|
36
|
+
get children() {
|
|
37
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
38
|
+
var _el$ = _tmpl$();
|
|
39
|
+
spread(_el$, p, false);
|
|
40
|
+
return _el$;
|
|
41
|
+
})());
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export { AccordionRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/accordion/root/AccordionRootContext.ts
|
|
4
|
+
var AccordionRootContext = createContext(null);
|
|
5
|
+
function useAccordionRootContext() {
|
|
6
|
+
const context = useContext(AccordionRootContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Accordion.Item must be placed within <Accordion.Root>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { AccordionRootContext, useAccordionRootContext };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { twoStateButtonProps } from "../../core/button.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { useAccordionItemContext } from "../item/AccordionItemContext.js";
|
|
5
|
+
import { spread, template } from "@solidjs/web";
|
|
6
|
+
import { merge, omit } from "solid-js";
|
|
7
|
+
// src/accordion/trigger/AccordionTrigger.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* The button that shows and hides its section's Panel: a
|
|
11
|
+
* `<button aria-expanded>`. Place it inside `Accordion.Header`.
|
|
12
|
+
*/
|
|
13
|
+
function AccordionTrigger(props) {
|
|
14
|
+
const item = useAccordionItemContext();
|
|
15
|
+
const generatedId = item.triggerId;
|
|
16
|
+
const id = () => props.id ?? generatedId();
|
|
17
|
+
item.triggerId = id;
|
|
18
|
+
const ownProps = merge(item.attributes, twoStateButtonProps({
|
|
19
|
+
get value() {
|
|
20
|
+
return item.open();
|
|
21
|
+
},
|
|
22
|
+
get disabled() {
|
|
23
|
+
return item.disabled();
|
|
24
|
+
},
|
|
25
|
+
setValue: item.setOpen
|
|
26
|
+
}, "aria-expanded", "Accordion.Trigger"), {
|
|
27
|
+
get id() {
|
|
28
|
+
return id();
|
|
29
|
+
},
|
|
30
|
+
"aria-controls": item.panelId
|
|
31
|
+
});
|
|
32
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
33
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
34
|
+
var _el$ = _tmpl$();
|
|
35
|
+
spread(_el$, p, false);
|
|
36
|
+
return _el$;
|
|
37
|
+
})());
|
|
38
|
+
}
|
|
39
|
+
export { AccordionTrigger };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useCheckboxRootContext } from "../root/CheckboxRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { omit } from "solid-js";
|
|
6
|
+
// src/checkbox/indicator/CheckboxIndicator.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<span>`);
|
|
8
|
+
/**
|
|
9
|
+
* The check mark: a `<span>` with the Root's `data-*` attributes, always
|
|
10
|
+
* rendered, so that CSS shows it by state. Place it inside `Checkbox.Root`.
|
|
11
|
+
*/
|
|
12
|
+
function CheckboxIndicator(props) {
|
|
13
|
+
const elementProps = mergeElementProps(useCheckboxRootContext(), 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 { CheckboxIndicator };
|
|
@@ -0,0 +1,136 @@
|
|
|
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 { CheckboxRootContext } from "./CheckboxRootContext.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/checkbox/root/CheckboxRoot.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 checkbox itself: a `<button role="checkbox">`.
|
|
13
|
+
*/
|
|
14
|
+
function CheckboxRoot(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 !props.indeterminate && checked() ? "" : void 0;
|
|
27
|
+
},
|
|
28
|
+
get "data-unchecked"() {
|
|
29
|
+
return !props.indeterminate && !checked() ? "" : void 0;
|
|
30
|
+
},
|
|
31
|
+
get "data-indeterminate"() {
|
|
32
|
+
return props.indeterminate ? "" : void 0;
|
|
33
|
+
},
|
|
34
|
+
get "data-disabled"() {
|
|
35
|
+
return props.disabled ? "" : void 0;
|
|
36
|
+
},
|
|
37
|
+
get "data-readonly"() {
|
|
38
|
+
return props.readOnly ? "" : void 0;
|
|
39
|
+
},
|
|
40
|
+
get "data-required"() {
|
|
41
|
+
return props.required ? "" : void 0;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const buttonProps = {
|
|
45
|
+
role: "checkbox",
|
|
46
|
+
type: "button",
|
|
47
|
+
get disabled() {
|
|
48
|
+
return props.disabled;
|
|
49
|
+
},
|
|
50
|
+
get "aria-checked"() {
|
|
51
|
+
if (props.indeterminate) return "mixed";
|
|
52
|
+
return checked() ? "true" : "false";
|
|
53
|
+
},
|
|
54
|
+
get "aria-readonly"() {
|
|
55
|
+
return props.readOnly ? "true" : void 0;
|
|
56
|
+
},
|
|
57
|
+
get "aria-required"() {
|
|
58
|
+
return props.required ? "true" : void 0;
|
|
59
|
+
},
|
|
60
|
+
onClick: () => input?.click(),
|
|
61
|
+
onKeyDown: (event) => {
|
|
62
|
+
if (event.key === "Enter") event.preventDefault();
|
|
63
|
+
},
|
|
64
|
+
ref: (element) => {
|
|
65
|
+
button = element;
|
|
66
|
+
if (isDev) warnUnlessButton(element, "Checkbox.Root");
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
let button;
|
|
70
|
+
let input;
|
|
71
|
+
const syncInput = () => {
|
|
72
|
+
if (input) input.checked = untrack(checked);
|
|
73
|
+
};
|
|
74
|
+
const onInputChange = () => {
|
|
75
|
+
if (!input) return;
|
|
76
|
+
setChecked(input.checked);
|
|
77
|
+
onFlush(syncInput);
|
|
78
|
+
};
|
|
79
|
+
const onInputClick = (event) => {
|
|
80
|
+
event.stopPropagation();
|
|
81
|
+
if (props.readOnly) event.preventDefault();
|
|
82
|
+
};
|
|
83
|
+
onSettled(() => {
|
|
84
|
+
const form = input?.form;
|
|
85
|
+
if (!form) return;
|
|
86
|
+
const onReset = () => {
|
|
87
|
+
setChecked(props.defaultChecked ?? false);
|
|
88
|
+
onFlush(syncInput);
|
|
89
|
+
};
|
|
90
|
+
form.addEventListener("reset", onReset);
|
|
91
|
+
return () => form.removeEventListener("reset", onReset);
|
|
92
|
+
});
|
|
93
|
+
const elementProps = mergeElementProps(merge(stateAttributes, buttonProps), omit(props, "render", "checked", "defaultChecked", "onCheckedChange", "indeterminate", "name", "value", "disabled", "readOnly", "required", "form"));
|
|
94
|
+
return createComponent(CheckboxRootContext, {
|
|
95
|
+
value: stateAttributes,
|
|
96
|
+
get children() {
|
|
97
|
+
return [memo(() => {
|
|
98
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
99
|
+
var _el$2 = _tmpl$2();
|
|
100
|
+
spread(_el$2, p, false);
|
|
101
|
+
return _el$2;
|
|
102
|
+
})());
|
|
103
|
+
}), (() => {
|
|
104
|
+
var _el$ = _tmpl$();
|
|
105
|
+
_el$.addEventListener("focus", () => button?.focus());
|
|
106
|
+
_el$.addEventListener("change", onInputChange);
|
|
107
|
+
ref(() => {
|
|
108
|
+
return (element) => {
|
|
109
|
+
input = element;
|
|
110
|
+
element.addEventListener("click", onInputClick);
|
|
111
|
+
};
|
|
112
|
+
}, _el$);
|
|
113
|
+
effect(() => {
|
|
114
|
+
return {
|
|
115
|
+
e: props.name,
|
|
116
|
+
t: props.value,
|
|
117
|
+
a: props.disabled,
|
|
118
|
+
o: props.required,
|
|
119
|
+
i: props.form,
|
|
120
|
+
n: checked(),
|
|
121
|
+
s: heldRead()
|
|
122
|
+
};
|
|
123
|
+
}, ({ e, t, a, o, i, n, s }, _p$) => {
|
|
124
|
+
e !== _p$?.e && setAttribute(_el$, "name", e);
|
|
125
|
+
(t !== _p$?.t || !s) && setProperty(_el$, "value", t);
|
|
126
|
+
a !== _p$?.a && setAttribute(_el$, "disabled", a);
|
|
127
|
+
o !== _p$?.o && setAttribute(_el$, "required", o);
|
|
128
|
+
i !== _p$?.i && setAttribute(_el$, "form", i);
|
|
129
|
+
(n !== _p$?.n || !s) && (_el$.checked = n);
|
|
130
|
+
});
|
|
131
|
+
return _el$;
|
|
132
|
+
})()];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
export { CheckboxRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/checkbox/root/CheckboxRootContext.ts
|
|
4
|
+
var CheckboxRootContext = createContext(null);
|
|
5
|
+
function useCheckboxRootContext() {
|
|
6
|
+
const context = useContext(CheckboxRootContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Checkbox parts must be placed within <Checkbox.Root>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { CheckboxRootContext, useCheckboxRootContext };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CollapsibleRoot } from "./root/CollapsibleRoot.js";
|
|
2
|
+
import { CollapsibleTrigger } from "./trigger/CollapsibleTrigger.js";
|
|
3
|
+
import { CollapsiblePanel } from "./panel/CollapsiblePanel.js";
|
|
4
|
+
export { CollapsiblePanel as Panel, CollapsibleRoot as Root, CollapsibleTrigger as Trigger };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useCollapsibleRootContext } from "../root/CollapsibleRootContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { merge, omit } from "solid-js";
|
|
6
|
+
// src/collapsible/panel/CollapsiblePanel.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
8
|
+
/**
|
|
9
|
+
* The content the Trigger shows and hides: a `<div>`, `hidden` while
|
|
10
|
+
* closed. Place it inside `Collapsible.Root`.
|
|
11
|
+
*/
|
|
12
|
+
function CollapsiblePanel(props) {
|
|
13
|
+
const root = useCollapsibleRootContext();
|
|
14
|
+
const ownProps = merge(root.attributes, {
|
|
15
|
+
id: root.panelId,
|
|
16
|
+
get hidden() {
|
|
17
|
+
return !root.open();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
21
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
22
|
+
var _el$ = _tmpl$();
|
|
23
|
+
spread(_el$, p, false);
|
|
24
|
+
return _el$;
|
|
25
|
+
})());
|
|
26
|
+
}
|
|
27
|
+
export { CollapsiblePanel };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { CollapsibleRootContext } from "./CollapsibleRootContext.js";
|
|
5
|
+
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
+
import { createUniqueId, omit } from "solid-js";
|
|
7
|
+
// src/collapsible/root/CollapsibleRoot.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
9
|
+
/**
|
|
10
|
+
* A section of content that a button shows and hides: a `<div>` around
|
|
11
|
+
* `Collapsible.Trigger` and `Collapsible.Panel`.
|
|
12
|
+
*/
|
|
13
|
+
function CollapsibleRoot(props) {
|
|
14
|
+
const [open, setOpen] = createControllableSignal({
|
|
15
|
+
get value() {
|
|
16
|
+
return props.open;
|
|
17
|
+
},
|
|
18
|
+
get defaultValue() {
|
|
19
|
+
return props.defaultOpen ?? false;
|
|
20
|
+
},
|
|
21
|
+
onChange: (value) => props.onOpenChange?.(value)
|
|
22
|
+
});
|
|
23
|
+
const attributes = {
|
|
24
|
+
get "data-open"() {
|
|
25
|
+
return open() ? "" : void 0;
|
|
26
|
+
},
|
|
27
|
+
get "data-closed"() {
|
|
28
|
+
return open() ? void 0 : "";
|
|
29
|
+
},
|
|
30
|
+
get "data-disabled"() {
|
|
31
|
+
return props.disabled ? "" : void 0;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const context = {
|
|
35
|
+
open,
|
|
36
|
+
setOpen,
|
|
37
|
+
disabled: () => props.disabled,
|
|
38
|
+
panelId: createUniqueId(),
|
|
39
|
+
attributes
|
|
40
|
+
};
|
|
41
|
+
const elementProps = mergeElementProps(attributes, omit(props, "render", "open", "defaultOpen", "onOpenChange", "disabled"));
|
|
42
|
+
return createComponent(CollapsibleRootContext, {
|
|
43
|
+
value: context,
|
|
44
|
+
get children() {
|
|
45
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
46
|
+
var _el$ = _tmpl$();
|
|
47
|
+
spread(_el$, p, false);
|
|
48
|
+
return _el$;
|
|
49
|
+
})());
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export { CollapsibleRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/collapsible/root/CollapsibleRootContext.ts
|
|
4
|
+
var CollapsibleRootContext = createContext(null);
|
|
5
|
+
function useCollapsibleRootContext() {
|
|
6
|
+
const context = useContext(CollapsibleRootContext);
|
|
7
|
+
if (isDev && !context) throw new Error("[menhir] Collapsible parts must be placed within <Collapsible.Root>.");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export { CollapsibleRootContext, useCollapsibleRootContext };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { twoStateButtonProps } from "../../core/button.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { useCollapsibleRootContext } from "../root/CollapsibleRootContext.js";
|
|
5
|
+
import { spread, template } from "@solidjs/web";
|
|
6
|
+
import { merge, omit } from "solid-js";
|
|
7
|
+
// src/collapsible/trigger/CollapsibleTrigger.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button>`);
|
|
9
|
+
/**
|
|
10
|
+
* The button that shows and hides the Panel: a `<button aria-expanded>`.
|
|
11
|
+
* Place it inside `Collapsible.Root`.
|
|
12
|
+
*/
|
|
13
|
+
function CollapsibleTrigger(props) {
|
|
14
|
+
const root = useCollapsibleRootContext();
|
|
15
|
+
const ownProps = merge(root.attributes, twoStateButtonProps({
|
|
16
|
+
get value() {
|
|
17
|
+
return root.open();
|
|
18
|
+
},
|
|
19
|
+
get disabled() {
|
|
20
|
+
return root.disabled();
|
|
21
|
+
},
|
|
22
|
+
setValue: root.setOpen
|
|
23
|
+
}, "aria-expanded", "Collapsible.Trigger"), { "aria-controls": root.panelId });
|
|
24
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
25
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
26
|
+
var _el$ = _tmpl$();
|
|
27
|
+
spread(_el$, p, false);
|
|
28
|
+
return _el$;
|
|
29
|
+
})());
|
|
30
|
+
}
|
|
31
|
+
export { CollapsibleTrigger };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { parsePreference } from "../core/preference/preference.js";
|
|
2
|
+
// src/color-scheme/colorScheme.ts
|
|
3
|
+
var defaultStorageKey = "color-scheme";
|
|
4
|
+
/** The fixed schemes: every value that is saved, and every look. */
|
|
5
|
+
var resolvedSchemes = ["light", "dark"];
|
|
6
|
+
var defaultAttribute = "data-color-scheme";
|
|
7
|
+
/** The media query whose match means the system prefers dark. */
|
|
8
|
+
var darkQuery = "(prefers-color-scheme: dark)";
|
|
9
|
+
/** `scheme` as it looks when the system prefers `system`. */
|
|
10
|
+
function resolveColorScheme(scheme, system) {
|
|
11
|
+
return scheme === "system" ? system : scheme;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The scheme a single cycling toggle moves to next, so that a click from
|
|
15
|
+
* `system` always changes the look: `system`, then the opposite of the
|
|
16
|
+
* system's look, then the system's look, then `system` again. Three schemes
|
|
17
|
+
* share two looks, so one click per round leaves the look as it is: the one
|
|
18
|
+
* back to `system`.
|
|
19
|
+
*/
|
|
20
|
+
function nextColorScheme(scheme, system) {
|
|
21
|
+
if (scheme === "system") return system === "dark" ? "light" : "dark";
|
|
22
|
+
return scheme === system ? "system" : system;
|
|
23
|
+
}
|
|
24
|
+
/** A stored value as a scheme; anything else, including none, is `system`. */
|
|
25
|
+
function parseColorScheme(value) {
|
|
26
|
+
return parsePreference(value, resolvedSchemes, "system");
|
|
27
|
+
}
|
|
28
|
+
export { darkQuery, defaultAttribute, defaultStorageKey, nextColorScheme, parseColorScheme, resolveColorScheme, resolvedSchemes };
|