@cerevialabs/ui 0.0.0-stage → 0.5.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/components/accordion/content/attrs.js +7 -0
- package/components/accordion/content/content.d.ts +2 -0
- package/components/accordion/content/content.js +18 -0
- package/components/accordion/content/index.d.ts +3 -0
- package/components/accordion/content/types.d.ts +3 -0
- package/components/accordion/context/context.d.ts +1 -0
- package/components/accordion/context/context.js +12 -0
- package/components/accordion/context/hooks.d.ts +3 -0
- package/components/accordion/context/hooks.js +49 -0
- package/components/accordion/context/index.d.ts +4 -0
- package/components/accordion/context/types.d.ts +14 -0
- package/components/accordion/context/utils.js +28 -0
- package/components/accordion/header/attrs.js +7 -0
- package/components/accordion/header/header.d.ts +2 -0
- package/components/accordion/header/header.js +17 -0
- package/components/accordion/header/index.d.ts +3 -0
- package/components/accordion/header/types.d.ts +3 -0
- package/components/accordion/index.d.ts +27 -0
- package/components/accordion/index.js +16 -0
- package/components/accordion/item/attrs.js +7 -0
- package/components/accordion/item/hooks.d.ts +3 -0
- package/components/accordion/item/hooks.js +22 -0
- package/components/accordion/item/index.d.ts +4 -0
- package/components/accordion/item/item.d.ts +2 -0
- package/components/accordion/item/item.js +23 -0
- package/components/accordion/item/types.d.ts +9 -0
- package/components/accordion/root/attrs.js +10 -0
- package/components/accordion/root/hooks.js +31 -0
- package/components/accordion/root/index.d.ts +3 -0
- package/components/accordion/root/root.d.ts +2 -0
- package/components/accordion/root/root.js +27 -0
- package/components/accordion/root/types.d.ts +19 -0
- package/components/accordion/trigger/attrs.js +7 -0
- package/components/accordion/trigger/index.d.ts +3 -0
- package/components/accordion/trigger/trigger.d.ts +2 -0
- package/components/accordion/trigger/trigger.js +10 -0
- package/components/accordion/trigger/types.d.ts +3 -0
- package/components/button/a11y.js +6 -0
- package/components/button/attrs.js +3 -0
- package/components/button/button.d.ts +2 -0
- package/components/button/button.js +25 -0
- package/components/button/index.d.ts +4 -0
- package/components/button/index.js +4 -0
- package/components/button/types.d.ts +5 -0
- package/components/collapsible/content/attrs.js +7 -0
- package/components/collapsible/content/content.d.ts +2 -0
- package/components/collapsible/content/content.js +18 -0
- package/components/collapsible/content/index.d.ts +3 -0
- package/components/collapsible/content/types.d.ts +3 -0
- package/components/collapsible/context/hooks.d.ts +2 -0
- package/components/collapsible/context/hooks.js +7 -0
- package/components/collapsible/context/index.d.ts +3 -0
- package/components/collapsible/context/types.d.ts +3 -0
- package/components/collapsible/index.d.ts +18 -0
- package/components/collapsible/index.js +11 -0
- package/components/collapsible/root/attrs.js +7 -0
- package/components/collapsible/root/index.d.ts +3 -0
- package/components/collapsible/root/root.d.ts +2 -0
- package/components/collapsible/root/root.js +10 -0
- package/components/collapsible/root/types.d.ts +3 -0
- package/components/collapsible/trigger/attrs.js +7 -0
- package/components/collapsible/trigger/index.d.ts +3 -0
- package/components/collapsible/trigger/trigger.d.ts +2 -0
- package/components/collapsible/trigger/trigger.js +10 -0
- package/components/collapsible/trigger/types.d.ts +3 -0
- package/components/index.d.ts +26 -0
- package/components/index.js +9 -0
- package/components/internal/disclosure/attrs.js +8 -0
- package/components/internal/disclosure/content/a11y.js +5 -0
- package/components/internal/disclosure/content/attrs.js +6 -0
- package/components/internal/disclosure/content/content.d.ts +1 -0
- package/components/internal/disclosure/content/content.js +30 -0
- package/components/internal/disclosure/content/hooks.js +81 -0
- package/components/internal/disclosure/content/index.d.ts +3 -0
- package/components/internal/disclosure/content/types.d.ts +11 -0
- package/components/internal/disclosure/content/utils.js +49 -0
- package/components/internal/disclosure/context/context.d.ts +1 -0
- package/components/internal/disclosure/context/context.js +12 -0
- package/components/internal/disclosure/context/hooks.d.ts +1 -0
- package/components/internal/disclosure/context/hooks.js +24 -0
- package/components/internal/disclosure/context/index.d.ts +4 -0
- package/components/internal/disclosure/context/types.d.ts +8 -0
- package/components/internal/disclosure/index.d.ts +9 -0
- package/components/internal/disclosure/index.js +11 -0
- package/components/internal/disclosure/root/hooks.js +23 -0
- package/components/internal/disclosure/root/index.d.ts +3 -0
- package/components/internal/disclosure/root/root.d.ts +1 -0
- package/components/internal/disclosure/root/root.js +27 -0
- package/components/internal/disclosure/root/types.d.ts +8 -0
- package/components/internal/disclosure/trigger/a11y.js +8 -0
- package/components/internal/disclosure/trigger/events.js +9 -0
- package/components/internal/disclosure/trigger/hooks.js +27 -0
- package/components/internal/disclosure/trigger/index.d.ts +3 -0
- package/components/internal/disclosure/trigger/trigger.d.ts +1 -0
- package/components/internal/disclosure/trigger/trigger.js +24 -0
- package/components/internal/disclosure/trigger/types.d.ts +3 -0
- package/components/scroll-area/content/attrs.js +21 -0
- package/components/scroll-area/content/content.d.ts +2 -0
- package/components/scroll-area/content/content.js +29 -0
- package/components/scroll-area/content/hooks.js +55 -0
- package/components/scroll-area/content/index.d.ts +3 -0
- package/components/scroll-area/content/types.d.ts +3 -0
- package/components/scroll-area/content/utils.js +34 -0
- package/components/scroll-area/context/context.d.ts +1 -0
- package/components/scroll-area/context/context.js +12 -0
- package/components/scroll-area/context/hooks.d.ts +3 -0
- package/components/scroll-area/context/hooks.js +170 -0
- package/components/scroll-area/context/index.d.ts +4 -0
- package/components/scroll-area/context/types.d.ts +47 -0
- package/components/scroll-area/context/utils.js +72 -0
- package/components/scroll-area/corner/attrs.js +10 -0
- package/components/scroll-area/corner/corner.d.ts +2 -0
- package/components/scroll-area/corner/corner.js +26 -0
- package/components/scroll-area/corner/hooks.js +12 -0
- package/components/scroll-area/corner/index.d.ts +3 -0
- package/components/scroll-area/corner/types.d.ts +3 -0
- package/components/scroll-area/index.d.ts +26 -0
- package/components/scroll-area/index.js +15 -0
- package/components/scroll-area/root/attrs.js +21 -0
- package/components/scroll-area/root/hooks.js +45 -0
- package/components/scroll-area/root/index.d.ts +3 -0
- package/components/scroll-area/root/root.d.ts +2 -0
- package/components/scroll-area/root/root.js +33 -0
- package/components/scroll-area/root/types.d.ts +8 -0
- package/components/scroll-area/scrollbar/a11y.js +12 -0
- package/components/scroll-area/scrollbar/attrs.js +12 -0
- package/components/scroll-area/scrollbar/context.d.ts +1 -0
- package/components/scroll-area/scrollbar/context.js +10 -0
- package/components/scroll-area/scrollbar/hooks.js +77 -0
- package/components/scroll-area/scrollbar/index.d.ts +4 -0
- package/components/scroll-area/scrollbar/scrollbar.d.ts +2 -0
- package/components/scroll-area/scrollbar/scrollbar.js +38 -0
- package/components/scroll-area/scrollbar/types.d.ts +8 -0
- package/components/scroll-area/thumb/attrs.js +7 -0
- package/components/scroll-area/thumb/hooks.js +75 -0
- package/components/scroll-area/thumb/index.d.ts +3 -0
- package/components/scroll-area/thumb/thumb.d.ts +2 -0
- package/components/scroll-area/thumb/thumb.js +26 -0
- package/components/scroll-area/thumb/types.d.ts +3 -0
- package/package.json +34 -4
- package/utils/apply-a11y.d.ts +5 -0
- package/utils/apply-a11y.js +11 -0
- package/utils/apply-attrs.d.ts +6 -0
- package/utils/apply-attrs.js +8 -0
- package/utils/data-attrs.d.ts +8 -0
- package/utils/data-attrs.js +21 -0
- package/utils/index.d.ts +11 -0
- package/utils/index.js +11 -0
- package/utils/merge-props.d.ts +4 -0
- package/utils/merge-props.js +68 -0
- package/utils/merge-refs.d.ts +2 -0
- package/utils/merge-refs.js +69 -0
- package/utils/prefers-reduced-motion.d.ts +1 -0
- package/utils/prefers-reduced-motion.js +19 -0
- package/utils/to-kebab-case.d.ts +1 -0
- package/utils/to-kebab-case.js +5 -0
- package/utils/use-controllable-state.d.ts +9 -0
- package/utils/use-controllable-state.js +38 -0
- package/utils/use-presence.d.ts +27 -0
- package/utils/use-presence.js +234 -0
- package/utils/use-render.d.ts +20 -0
- package/utils/use-render.js +74 -0
- package/README.md +0 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useCollapsibleContext } from "./context/hooks.js";
|
|
2
|
+
import { CollapsibleContent } from "./content/content.js";
|
|
3
|
+
import { CollapsibleRoot } from "./root/root.js";
|
|
4
|
+
import { CollapsibleTrigger } from "./trigger/trigger.js";
|
|
5
|
+
// components/collapsible/index.ts
|
|
6
|
+
const Collapsible = {
|
|
7
|
+
Root: CollapsibleRoot,
|
|
8
|
+
Trigger: CollapsibleTrigger,
|
|
9
|
+
Content: CollapsibleContent
|
|
10
|
+
};
|
|
11
|
+
export { Collapsible, useCollapsibleContext };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { applyAttrs } from "../../../utils/apply-attrs.js";
|
|
2
|
+
// components/collapsible/root/attrs.ts
|
|
3
|
+
const collapsibleRootAttrStates = [];
|
|
4
|
+
function collapsibleRootAttrs() {
|
|
5
|
+
return applyAttrs("collapsible", collapsibleRootAttrStates, {}, { part: "root" });
|
|
6
|
+
}
|
|
7
|
+
export { collapsibleRootAttrs };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Disclosure } from "../../internal/disclosure/index.js";
|
|
3
|
+
import { collapsibleRootAttrs } from "./attrs.js";
|
|
4
|
+
import { mergeProps } from "../../../utils/merge-props.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// components/collapsible/root/root.tsx
|
|
7
|
+
function CollapsibleRoot(props) {
|
|
8
|
+
return /* @__PURE__ */ jsx(Disclosure.Root, { ...mergeProps(collapsibleRootAttrs(), props) });
|
|
9
|
+
}
|
|
10
|
+
export { CollapsibleRoot };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { applyAttrs } from "../../../utils/apply-attrs.js";
|
|
2
|
+
// components/collapsible/trigger/attrs.ts
|
|
3
|
+
const collapsibleTriggerAttrStates = [];
|
|
4
|
+
function collapsibleTriggerAttrs() {
|
|
5
|
+
return applyAttrs("collapsible", collapsibleTriggerAttrStates, {}, { part: "trigger" });
|
|
6
|
+
}
|
|
7
|
+
export { collapsibleTriggerAttrs };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Disclosure } from "../../internal/disclosure/index.js";
|
|
3
|
+
import { collapsibleTriggerAttrs } from "./attrs.js";
|
|
4
|
+
import { mergeProps } from "../../../utils/merge-props.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// components/collapsible/trigger/trigger.tsx
|
|
7
|
+
function CollapsibleTrigger(props) {
|
|
8
|
+
return /* @__PURE__ */ jsx(Disclosure.Trigger, { ...mergeProps(collapsibleTriggerAttrs(), props) });
|
|
9
|
+
}
|
|
10
|
+
export { CollapsibleTrigger };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AccordionContextValue } from "./accordion/context/types.js";
|
|
2
|
+
import { useAccordionContext } from "./accordion/context/hooks.js";
|
|
3
|
+
import { AccordionContentProps } from "./accordion/content/types.js";
|
|
4
|
+
import { AccordionHeaderProps } from "./accordion/header/types.js";
|
|
5
|
+
import { AccordionItemContextValue, AccordionItemProps } from "./accordion/item/types.js";
|
|
6
|
+
import { useAccordionItemContext } from "./accordion/item/hooks.js";
|
|
7
|
+
import { AccordionRootProps } from "./accordion/root/types.js";
|
|
8
|
+
import { AccordionTriggerProps } from "./accordion/trigger/types.js";
|
|
9
|
+
import { Accordion } from "./accordion/index.js";
|
|
10
|
+
import { ButtonProps } from "./button/types.js";
|
|
11
|
+
import { Button } from "./button/index.js";
|
|
12
|
+
import { CollapsibleContextValue } from "./collapsible/context/types.js";
|
|
13
|
+
import { useCollapsibleContext } from "./collapsible/context/hooks.js";
|
|
14
|
+
import { CollapsibleContentProps } from "./collapsible/content/types.js";
|
|
15
|
+
import { CollapsibleRootProps } from "./collapsible/root/types.js";
|
|
16
|
+
import { CollapsibleTriggerProps } from "./collapsible/trigger/types.js";
|
|
17
|
+
import { Collapsible } from "./collapsible/index.js";
|
|
18
|
+
import { ScrollAreaActivityState, ScrollAreaContextValue, ScrollAreaOrientation, ScrollAreaType } from "./scroll-area/context/types.js";
|
|
19
|
+
import { useScrollAreaContext } from "./scroll-area/context/hooks.js";
|
|
20
|
+
import { ScrollAreaContentProps } from "./scroll-area/content/types.js";
|
|
21
|
+
import { ScrollAreaCornerProps } from "./scroll-area/corner/types.js";
|
|
22
|
+
import { ScrollAreaRootProps } from "./scroll-area/root/types.js";
|
|
23
|
+
import { ScrollAreaScrollbarProps } from "./scroll-area/scrollbar/types.js";
|
|
24
|
+
import { ScrollAreaThumbProps } from "./scroll-area/thumb/types.js";
|
|
25
|
+
import { ScrollArea } from "./scroll-area/index.js";
|
|
26
|
+
export { Accordion, type AccordionContentProps, type AccordionContextValue, type AccordionHeaderProps, type AccordionItemContextValue, type AccordionItemProps, type AccordionRootProps, type AccordionTriggerProps, Button, type ButtonProps, Collapsible, type CollapsibleContentProps, type CollapsibleContextValue, type CollapsibleRootProps, type CollapsibleTriggerProps, ScrollArea, type ScrollAreaActivityState, type ScrollAreaContentProps, type ScrollAreaContextValue, type ScrollAreaCornerProps, type ScrollAreaOrientation, type ScrollAreaRootProps, type ScrollAreaScrollbarProps, type ScrollAreaThumbProps, type ScrollAreaType, useAccordionContext, useAccordionItemContext, useCollapsibleContext, useScrollAreaContext };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useAccordionContext } from "./accordion/context/hooks.js";
|
|
2
|
+
import { useAccordionItemContext } from "./accordion/item/hooks.js";
|
|
3
|
+
import { Accordion } from "./accordion/index.js";
|
|
4
|
+
import { Button } from "./button/index.js";
|
|
5
|
+
import { useCollapsibleContext } from "./collapsible/context/hooks.js";
|
|
6
|
+
import { Collapsible } from "./collapsible/index.js";
|
|
7
|
+
import { useScrollAreaContext } from "./scroll-area/context/hooks.js";
|
|
8
|
+
import { ScrollArea } from "./scroll-area/index.js";
|
|
9
|
+
export { Accordion, Button, Collapsible, ScrollArea, useAccordionContext, useAccordionItemContext, useCollapsibleContext, useScrollAreaContext };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { presenceAttrs } from "../../../../utils/use-presence.js";
|
|
2
|
+
// components/internal/disclosure/content/attrs.ts
|
|
3
|
+
function disclosureContentAttrs(presenceStates) {
|
|
4
|
+
return presenceAttrs("disclosure", presenceStates, void 0, { statesOnly: true });
|
|
5
|
+
}
|
|
6
|
+
export { disclosureContentAttrs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDisclosureContentSize, useDisclosureContentState } from "./hooks.js";
|
|
3
|
+
import { mergeProps } from "../../../../utils/merge-props.js";
|
|
4
|
+
import { useMergeRefs } from "../../../../utils/merge-refs.js";
|
|
5
|
+
import { useRender } from "../../../../utils/use-render.js";
|
|
6
|
+
// components/internal/disclosure/content/content.tsx
|
|
7
|
+
function DisclosureContent({ ref, render, keepMounted = false, sizeCssVars, style, className, children, ...props }) {
|
|
8
|
+
const state = useDisclosureContentState({ keepMounted });
|
|
9
|
+
const mergedRef = useMergeRefs([ref, state.presenceRef]);
|
|
10
|
+
useDisclosureContentSize({
|
|
11
|
+
open: state.open,
|
|
12
|
+
mounted: state.mounted,
|
|
13
|
+
shouldRender: state.shouldRender,
|
|
14
|
+
elementRef: state.presenceRef,
|
|
15
|
+
sizeCssVars
|
|
16
|
+
});
|
|
17
|
+
return useRender({
|
|
18
|
+
defaultTagName: "div",
|
|
19
|
+
ref: mergedRef,
|
|
20
|
+
render,
|
|
21
|
+
enabled: state.shouldRender,
|
|
22
|
+
props: mergeProps({
|
|
23
|
+
style,
|
|
24
|
+
className,
|
|
25
|
+
children,
|
|
26
|
+
inert: state.inert
|
|
27
|
+
}, state.a11y, state.attrs, props)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export { DisclosureContent };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLayoutEffect } from "react";
|
|
3
|
+
import { useDisclosureContext } from "../context/hooks.js";
|
|
4
|
+
import { disclosureContentA11y } from "./a11y.js";
|
|
5
|
+
import { disclosureContentAttrs } from "./attrs.js";
|
|
6
|
+
import { measureContentSize } from "./utils.js";
|
|
7
|
+
import { presenceShouldRender, usePresence } from "../../../../utils/use-presence.js";
|
|
8
|
+
// components/internal/disclosure/content/hooks.ts
|
|
9
|
+
const defaultDisclosureContentSizeCssVars = {
|
|
10
|
+
width: "--disclosure-content-width",
|
|
11
|
+
height: "--disclosure-content-height"
|
|
12
|
+
};
|
|
13
|
+
function useDisclosureContentState({ keepMounted = false } = {}) {
|
|
14
|
+
const { open, contentId } = useDisclosureContext();
|
|
15
|
+
const { ref: presenceRef, mounted, presenceStates } = usePresence(open);
|
|
16
|
+
return {
|
|
17
|
+
open,
|
|
18
|
+
mounted,
|
|
19
|
+
presenceRef,
|
|
20
|
+
shouldRender: presenceShouldRender(open, mounted, keepMounted),
|
|
21
|
+
a11y: disclosureContentA11y({ contentId }),
|
|
22
|
+
attrs: disclosureContentAttrs(presenceStates),
|
|
23
|
+
inert: open ? void 0 : true
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function useDisclosureContentSize({ open, mounted, shouldRender, elementRef, sizeCssVars = defaultDisclosureContentSizeCssVars }) {
|
|
27
|
+
const widthVar = sizeCssVars.width;
|
|
28
|
+
const heightVar = sizeCssVars.height;
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
const element = elementRef.current;
|
|
31
|
+
if (!element || !shouldRender) return void 0;
|
|
32
|
+
function updateSize() {
|
|
33
|
+
if (!element) return;
|
|
34
|
+
const hasMeasured = element.style.getPropertyValue(heightVar) !== "";
|
|
35
|
+
if (hasMeasured && element.hasAttribute("data-animating")) return;
|
|
36
|
+
const { width, height } = measureContentSize(element);
|
|
37
|
+
if (width === 0 && height === 0 && hasMeasured) return;
|
|
38
|
+
const nextWidth = `${width}px`;
|
|
39
|
+
const nextHeight = `${height}px`;
|
|
40
|
+
if (element.style.getPropertyValue(widthVar) !== nextWidth) element.style.setProperty(widthVar, nextWidth);
|
|
41
|
+
if (element.style.getPropertyValue(heightVar) !== nextHeight) element.style.setProperty(heightVar, nextHeight);
|
|
42
|
+
}
|
|
43
|
+
const resizeObserver = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(updateSize);
|
|
44
|
+
const observed = /* @__PURE__ */ new Set();
|
|
45
|
+
function syncObserved() {
|
|
46
|
+
if (!element || !resizeObserver) return;
|
|
47
|
+
const current = new Set(element.children);
|
|
48
|
+
for (const child of observed) if (!current.has(child)) {
|
|
49
|
+
resizeObserver.unobserve(child);
|
|
50
|
+
observed.delete(child);
|
|
51
|
+
}
|
|
52
|
+
for (const child of current) if (!observed.has(child)) {
|
|
53
|
+
resizeObserver.observe(child);
|
|
54
|
+
observed.add(child);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
syncObserved();
|
|
58
|
+
updateSize();
|
|
59
|
+
const mutationObserver = new MutationObserver((records) => {
|
|
60
|
+
if (records.some((record) => record.type === "childList")) syncObserved();
|
|
61
|
+
updateSize();
|
|
62
|
+
});
|
|
63
|
+
mutationObserver.observe(element, {
|
|
64
|
+
childList: true,
|
|
65
|
+
attributes: true,
|
|
66
|
+
attributeFilter: ["data-animating"]
|
|
67
|
+
});
|
|
68
|
+
return () => {
|
|
69
|
+
resizeObserver?.disconnect();
|
|
70
|
+
mutationObserver.disconnect();
|
|
71
|
+
};
|
|
72
|
+
}, [
|
|
73
|
+
open,
|
|
74
|
+
mounted,
|
|
75
|
+
shouldRender,
|
|
76
|
+
elementRef,
|
|
77
|
+
widthVar,
|
|
78
|
+
heightVar
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
export { useDisclosureContentSize, useDisclosureContentState };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UseRenderComponentProps } from "../../../../utils/use-render.js";
|
|
2
|
+
import "../../../../utils/index.js";
|
|
3
|
+
interface DisclosureContentSizeCssVars {
|
|
4
|
+
width: string;
|
|
5
|
+
height: string;
|
|
6
|
+
}
|
|
7
|
+
interface DisclosureContentProps extends UseRenderComponentProps<"div"> {
|
|
8
|
+
keepMounted?: boolean;
|
|
9
|
+
sizeCssVars?: DisclosureContentSizeCssVars;
|
|
10
|
+
}
|
|
11
|
+
export type { DisclosureContentProps, DisclosureContentSizeCssVars };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// components/internal/disclosure/content/utils.ts
|
|
2
|
+
function px(value) {
|
|
3
|
+
return parseFloat(value) || 0;
|
|
4
|
+
}
|
|
5
|
+
function isInFlow(style) {
|
|
6
|
+
if (style.display === "none" || style.display === "contents") return false;
|
|
7
|
+
if (style.position === "absolute" || style.position === "fixed") return false;
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
function measureWithUnlock(element) {
|
|
11
|
+
const previousWidth = element.style.width;
|
|
12
|
+
const previousHeight = element.style.height;
|
|
13
|
+
element.style.width = "auto";
|
|
14
|
+
element.style.height = "auto";
|
|
15
|
+
const size = {
|
|
16
|
+
width: element.scrollWidth,
|
|
17
|
+
height: element.scrollHeight
|
|
18
|
+
};
|
|
19
|
+
element.style.width = previousWidth;
|
|
20
|
+
element.style.height = previousHeight;
|
|
21
|
+
return size;
|
|
22
|
+
}
|
|
23
|
+
function measureFromChildren(element) {
|
|
24
|
+
let top = 1e400;
|
|
25
|
+
let bottom = -1e400;
|
|
26
|
+
let width = 0;
|
|
27
|
+
for (const child of element.children) {
|
|
28
|
+
if (!(child instanceof HTMLElement)) continue;
|
|
29
|
+
const style = getComputedStyle(child);
|
|
30
|
+
if (!isInFlow(style)) continue;
|
|
31
|
+
const rect = child.getBoundingClientRect();
|
|
32
|
+
top = Math.min(top, rect.top - px(style.marginTop));
|
|
33
|
+
bottom = Math.max(bottom, rect.bottom + px(style.marginBottom));
|
|
34
|
+
width = Math.max(width, rect.width + px(style.marginLeft) + px(style.marginRight));
|
|
35
|
+
}
|
|
36
|
+
if (top === 1e400 || width < 1) return null;
|
|
37
|
+
return {
|
|
38
|
+
width,
|
|
39
|
+
height: bottom - top
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function measureContentSize(element) {
|
|
43
|
+
const size = (element.clientWidth >= 1 ? measureFromChildren(element) : null) ?? measureWithUnlock(element);
|
|
44
|
+
return {
|
|
45
|
+
width: Math.ceil(size.width - .01),
|
|
46
|
+
height: Math.ceil(size.height - .01)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export { measureContentSize };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// components/internal/disclosure/context/context.tsx
|
|
5
|
+
const DisclosureContext = createContext(void 0);
|
|
6
|
+
function DisclosureProvider({ contextValue, children }) {
|
|
7
|
+
return /* @__PURE__ */ jsx(DisclosureContext.Provider, {
|
|
8
|
+
value: contextValue,
|
|
9
|
+
children
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export { DisclosureContext, DisclosureProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { use, useId } from "react";
|
|
3
|
+
import { DisclosureContext } from "./context.js";
|
|
4
|
+
import { useControllableState } from "../../../../utils/use-controllable-state.js";
|
|
5
|
+
// components/internal/disclosure/context/hooks.ts
|
|
6
|
+
function useDisclosureProviderValue({ open: openProp, defaultOpen = false, onOpenChange, disabled = false }) {
|
|
7
|
+
const [open, setOpen] = useControllableState({
|
|
8
|
+
value: openProp,
|
|
9
|
+
defaultValue: defaultOpen,
|
|
10
|
+
onChange: onOpenChange
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
open,
|
|
14
|
+
setOpen,
|
|
15
|
+
disabled,
|
|
16
|
+
contentId: useId()
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function useDisclosureContext() {
|
|
20
|
+
const context = use(DisclosureContext);
|
|
21
|
+
if (!context) throw new Error("Disclosure parts must be used within Disclosure.Root");
|
|
22
|
+
return context;
|
|
23
|
+
}
|
|
24
|
+
export { useDisclosureContext, useDisclosureProviderValue };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DisclosureContextValue } from "./context/types.js";
|
|
2
|
+
import "./context/index.js";
|
|
3
|
+
import { DisclosureContentProps } from "./content/types.js";
|
|
4
|
+
import "./content/index.js";
|
|
5
|
+
import { DisclosureRootProps } from "./root/types.js";
|
|
6
|
+
import "./root/index.js";
|
|
7
|
+
import { DisclosureTriggerProps } from "./trigger/types.js";
|
|
8
|
+
import "./trigger/index.js";
|
|
9
|
+
export type { DisclosureContentProps, DisclosureContextValue, DisclosureRootProps, DisclosureTriggerProps };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useDisclosureContext } from "./context/hooks.js";
|
|
2
|
+
import { DisclosureContent } from "./content/content.js";
|
|
3
|
+
import { DisclosureRoot } from "./root/root.js";
|
|
4
|
+
import { DisclosureTrigger } from "./trigger/trigger.js";
|
|
5
|
+
// components/internal/disclosure/index.ts
|
|
6
|
+
const Disclosure = {
|
|
7
|
+
Root: DisclosureRoot,
|
|
8
|
+
Trigger: DisclosureTrigger,
|
|
9
|
+
Content: DisclosureContent
|
|
10
|
+
};
|
|
11
|
+
export { Disclosure, useDisclosureContext };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDisclosureContext, useDisclosureProviderValue } from "../context/hooks.js";
|
|
3
|
+
import { disclosureSharedAttrs } from "../attrs.js";
|
|
4
|
+
// components/internal/disclosure/root/hooks.ts
|
|
5
|
+
function useDisclosureRoot({ open, defaultOpen = false, onOpenChange, disabled = false, ...hostProps }) {
|
|
6
|
+
return {
|
|
7
|
+
contextValue: useDisclosureProviderValue({
|
|
8
|
+
open,
|
|
9
|
+
defaultOpen,
|
|
10
|
+
onOpenChange,
|
|
11
|
+
disabled
|
|
12
|
+
}),
|
|
13
|
+
hostProps
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function useDisclosureRootHost() {
|
|
17
|
+
const { open, disabled } = useDisclosureContext();
|
|
18
|
+
return { attrs: disclosureSharedAttrs({
|
|
19
|
+
open,
|
|
20
|
+
disabled
|
|
21
|
+
}) };
|
|
22
|
+
}
|
|
23
|
+
export { useDisclosureRoot, useDisclosureRootHost };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { DisclosureProvider } from "../context/context.js";
|
|
3
|
+
import { useDisclosureRoot, useDisclosureRootHost } from "./hooks.js";
|
|
4
|
+
import { mergeProps } from "../../../../utils/merge-props.js";
|
|
5
|
+
import { useRender } from "../../../../utils/use-render.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
// components/internal/disclosure/root/root.tsx
|
|
8
|
+
function DisclosureRootHost({ ref, render, className, children, ...props }) {
|
|
9
|
+
const { attrs } = useDisclosureRootHost();
|
|
10
|
+
return useRender({
|
|
11
|
+
defaultTagName: "div",
|
|
12
|
+
ref,
|
|
13
|
+
render,
|
|
14
|
+
props: mergeProps({
|
|
15
|
+
className,
|
|
16
|
+
children
|
|
17
|
+
}, attrs, props)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function DisclosureRoot(props) {
|
|
21
|
+
const { contextValue, hostProps } = useDisclosureRoot(props);
|
|
22
|
+
return /* @__PURE__ */ jsx(DisclosureProvider, {
|
|
23
|
+
contextValue,
|
|
24
|
+
children: /* @__PURE__ */ jsx(DisclosureRootHost, { ...hostProps })
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export { DisclosureRoot };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UseRenderComponentProps } from "../../../../utils/use-render.js";
|
|
2
|
+
import "../../../../utils/index.js";
|
|
3
|
+
export interface DisclosureRootProps extends UseRenderComponentProps<"div"> {
|
|
4
|
+
open?: boolean;
|
|
5
|
+
defaultOpen?: boolean;
|
|
6
|
+
onOpenChange?: (open: boolean) => void;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// components/internal/disclosure/trigger/events.ts
|
|
2
|
+
function createDisclosureTriggerOnClick({ disabled, setOpen, onClick }) {
|
|
3
|
+
return (event) => {
|
|
4
|
+
onClick?.(event);
|
|
5
|
+
if (event.defaultPrevented || disabled) return;
|
|
6
|
+
setOpen((prev) => !prev);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export { createDisclosureTriggerOnClick };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDisclosureContext } from "../context/hooks.js";
|
|
3
|
+
import { disclosureTriggerA11y } from "./a11y.js";
|
|
4
|
+
import { disclosureSharedAttrs } from "../attrs.js";
|
|
5
|
+
import { createDisclosureTriggerOnClick } from "./events.js";
|
|
6
|
+
// components/internal/disclosure/trigger/hooks.ts
|
|
7
|
+
function useDisclosureTrigger({ disabled: disabledProp, onClick }) {
|
|
8
|
+
const { open, setOpen, disabled: rootDisabled, contentId } = useDisclosureContext();
|
|
9
|
+
const disabled = rootDisabled || Boolean(disabledProp);
|
|
10
|
+
return {
|
|
11
|
+
disabled,
|
|
12
|
+
onClick: createDisclosureTriggerOnClick({
|
|
13
|
+
disabled,
|
|
14
|
+
setOpen,
|
|
15
|
+
onClick
|
|
16
|
+
}),
|
|
17
|
+
a11y: disclosureTriggerA11y({
|
|
18
|
+
open,
|
|
19
|
+
contentId
|
|
20
|
+
}),
|
|
21
|
+
attrs: disclosureSharedAttrs({
|
|
22
|
+
open,
|
|
23
|
+
disabled: rootDisabled
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export { useDisclosureTrigger };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDisclosureTrigger } from "./hooks.js";
|
|
3
|
+
import { mergeProps } from "../../../../utils/merge-props.js";
|
|
4
|
+
import { useRender } from "../../../../utils/use-render.js";
|
|
5
|
+
// components/internal/disclosure/trigger/trigger.tsx
|
|
6
|
+
function DisclosureTrigger({ ref, render, type = "button", disabled: disabledProp, className, children, onClick, ...props }) {
|
|
7
|
+
const trigger = useDisclosureTrigger({
|
|
8
|
+
disabled: disabledProp,
|
|
9
|
+
onClick
|
|
10
|
+
});
|
|
11
|
+
return useRender({
|
|
12
|
+
defaultTagName: "button",
|
|
13
|
+
ref,
|
|
14
|
+
render,
|
|
15
|
+
props: mergeProps({
|
|
16
|
+
type,
|
|
17
|
+
disabled: trigger.disabled,
|
|
18
|
+
className,
|
|
19
|
+
children,
|
|
20
|
+
onClick: trigger.onClick
|
|
21
|
+
}, trigger.a11y, trigger.attrs, props)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export { DisclosureTrigger };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { applyAttrs } from "../../../utils/apply-attrs.js";
|
|
2
|
+
// components/scroll-area/content/attrs.ts
|
|
3
|
+
const scrollAreaContentAttrStates = [
|
|
4
|
+
"overflowX",
|
|
5
|
+
"overflowY",
|
|
6
|
+
"overflowTop",
|
|
7
|
+
"overflowBottom",
|
|
8
|
+
"overflowLeft",
|
|
9
|
+
"overflowRight"
|
|
10
|
+
];
|
|
11
|
+
function scrollAreaContentAttrs({ overflowX, overflowY, overflowTop, overflowBottom, overflowLeft, overflowRight }) {
|
|
12
|
+
return applyAttrs("scroll-area", scrollAreaContentAttrStates, {
|
|
13
|
+
overflowX,
|
|
14
|
+
overflowY,
|
|
15
|
+
overflowTop,
|
|
16
|
+
overflowBottom,
|
|
17
|
+
overflowLeft,
|
|
18
|
+
overflowRight
|
|
19
|
+
}, { part: "content" });
|
|
20
|
+
}
|
|
21
|
+
export { scrollAreaContentAttrs };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { ScrollAreaContentProps } from "./types.js";
|
|
2
|
+
export declare function ScrollAreaContent({ ref, render, id, className, children, style, onScroll, ...props }: ScrollAreaContentProps): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useScrollAreaContentState } from "./hooks.js";
|
|
3
|
+
import { mergeProps } from "../../../utils/merge-props.js";
|
|
4
|
+
import { useRender } from "../../../utils/use-render.js";
|
|
5
|
+
// components/scroll-area/content/content.tsx
|
|
6
|
+
function ScrollAreaContent({ ref, render, id, className, children, style, onScroll, ...props }) {
|
|
7
|
+
const state = useScrollAreaContentState(ref, id);
|
|
8
|
+
return useRender({
|
|
9
|
+
defaultTagName: "div",
|
|
10
|
+
ref: state.ref,
|
|
11
|
+
render,
|
|
12
|
+
props: mergeProps({
|
|
13
|
+
id: state.id,
|
|
14
|
+
className,
|
|
15
|
+
children,
|
|
16
|
+
style: {
|
|
17
|
+
overflow: "auto",
|
|
18
|
+
width: "100%",
|
|
19
|
+
height: "100%",
|
|
20
|
+
...style
|
|
21
|
+
},
|
|
22
|
+
onScroll: (event) => {
|
|
23
|
+
state.onScroll(event);
|
|
24
|
+
onScroll?.(event);
|
|
25
|
+
}
|
|
26
|
+
}, state.attrs, props)
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export { ScrollAreaContent };
|