@entry-ui/qwik 0.6.0 → 0.7.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/lib/_internal/components/primitive/primitive.d.ts +2 -1
- package/lib/_internal/components/primitive/primitive.qwik.mjs +1 -0
- package/lib/_internal/hooks/index.d.ts +1 -0
- package/lib/_internal/hooks/use-id/index.d.ts +2 -0
- package/lib/_internal/hooks/use-id/use-id.d.ts +21 -0
- package/lib/_internal/hooks/use-id/use-id.qwik.mjs +10 -0
- package/lib/_internal/hooks/use-id/use-id.types.d.ts +22 -0
- package/lib/components/accordion/contexts/accordion-item-context/accordion-item-context.d.ts +11 -0
- package/lib/components/accordion/contexts/accordion-item-context/accordion-item-context.qwik.mjs +10 -0
- package/lib/components/accordion/contexts/accordion-item-context/accordion-item-context.types.d.ts +64 -0
- package/lib/components/accordion/contexts/accordion-item-context/index.d.ts +2 -0
- package/lib/components/accordion/contexts/accordion-item-trigger-context/accordion-item-trigger-context.d.ts +6 -0
- package/lib/components/accordion/contexts/accordion-item-trigger-context/accordion-item-trigger-context.qwik.mjs +5 -0
- package/lib/components/accordion/contexts/accordion-item-trigger-context/accordion-item-trigger-context.types.d.ts +13 -0
- package/lib/components/accordion/contexts/accordion-item-trigger-context/index.d.ts +2 -0
- package/lib/components/accordion/contexts/accordion-root-context/accordion-root-context.d.ts +11 -0
- package/lib/components/accordion/contexts/accordion-root-context/accordion-root-context.qwik.mjs +10 -0
- package/lib/components/accordion/contexts/accordion-root-context/accordion-root-context.types.d.ts +34 -0
- package/lib/components/accordion/contexts/accordion-root-context/index.d.ts +2 -0
- package/lib/components/accordion/contexts/index.d.ts +3 -0
- package/lib/components/accordion/hooks/index.d.ts +3 -0
- package/lib/components/accordion/hooks/use-accordion-item-context/index.d.ts +2 -0
- package/lib/components/accordion/hooks/use-accordion-item-context/use-accordion-item-context.d.ts +7 -0
- package/lib/components/accordion/hooks/use-accordion-item-context/use-accordion-item-context.qwik.mjs +14 -0
- package/lib/components/accordion/hooks/use-accordion-item-context/use-accordion-item-context.types.d.ts +28 -0
- package/lib/components/accordion/hooks/use-accordion-item-trigger-context/index.d.ts +2 -0
- package/lib/components/accordion/hooks/use-accordion-item-trigger-context/use-accordion-item-trigger-context.d.ts +7 -0
- package/lib/components/accordion/hooks/use-accordion-item-trigger-context/use-accordion-item-trigger-context.qwik.mjs +11 -0
- package/lib/components/accordion/hooks/use-accordion-item-trigger-context/use-accordion-item-trigger-context.types.d.ts +13 -0
- package/lib/components/accordion/hooks/use-accordion-root-context/index.d.ts +2 -0
- package/lib/components/accordion/hooks/use-accordion-root-context/use-accordion-root-context.d.ts +8 -0
- package/lib/components/accordion/hooks/use-accordion-root-context/use-accordion-root-context.qwik.mjs +13 -0
- package/lib/components/accordion/hooks/use-accordion-root-context/use-accordion-root-context.types.d.ts +22 -0
- package/lib/components/accordion/index.d.ts +2 -0
- package/lib/components/accordion/index.qwik.mjs +10 -0
- package/lib/components/accordion/parts/accordion-item/accordion-item.d.ts +7 -0
- package/lib/components/accordion/parts/accordion-item/accordion-item.qwik.mjs +49 -0
- package/lib/components/accordion/parts/accordion-item/accordion-item.types.d.ts +29 -0
- package/lib/components/accordion/parts/accordion-item/index.d.ts +2 -0
- package/lib/components/accordion/parts/accordion-item-header/accordion-item-header.d.ts +11 -0
- package/lib/components/accordion/parts/accordion-item-header/accordion-item-header.qwik.mjs +19 -0
- package/lib/components/accordion/parts/accordion-item-header/accordion-item-header.types.d.ts +15 -0
- package/lib/components/accordion/parts/accordion-item-header/index.d.ts +2 -0
- package/lib/components/accordion/parts/accordion-item-indicator/accordion-item-indicator.d.ts +8 -0
- package/lib/components/accordion/parts/accordion-item-indicator/accordion-item-indicator.qwik.mjs +27 -0
- package/lib/components/accordion/parts/accordion-item-indicator/accordion-item-indicator.types.d.ts +15 -0
- package/lib/components/accordion/parts/accordion-item-indicator/index.d.ts +2 -0
- package/lib/components/accordion/parts/accordion-item-panel/accordion-item-panel.d.ts +7 -0
- package/lib/components/accordion/parts/accordion-item-panel/accordion-item-panel.qwik.mjs +199 -0
- package/lib/components/accordion/parts/accordion-item-panel/accordion-item-panel.types.d.ts +31 -0
- package/lib/components/accordion/parts/accordion-item-panel/index.d.ts +2 -0
- package/lib/components/accordion/parts/accordion-item-trigger/accordion-item-trigger.d.ts +7 -0
- package/lib/components/accordion/parts/accordion-item-trigger/accordion-item-trigger.qwik.mjs +52 -0
- package/lib/components/accordion/parts/accordion-item-trigger/accordion-item-trigger.types.d.ts +23 -0
- package/lib/components/accordion/parts/accordion-item-trigger/index.d.ts +2 -0
- package/lib/components/accordion/parts/accordion-root/accordion-root.d.ts +7 -0
- package/lib/components/accordion/parts/accordion-root/accordion-root.qwik.mjs +137 -0
- package/lib/components/accordion/parts/accordion-root/accordion-root.types.d.ts +68 -0
- package/lib/components/accordion/parts/accordion-root/index.d.ts +2 -0
- package/lib/components/accordion/parts/index.d.ts +12 -0
- package/lib/components/accordion/parts/index.qwik.mjs +14 -0
- package/lib/components/collapsible/contexts/collapsible-trigger-context/collapsible-trigger-context.types.d.ts +2 -2
- package/lib/components/collapsible/hooks/use-collapsible-trigger-context/use-collapsible-trigger-context.types.d.ts +2 -2
- package/lib/components/collapsible/parts/collapsible-panel/collapsible-panel.qwik.mjs +53 -30
- package/lib/components/index.d.ts +1 -0
- package/lib/index.qwik.mjs +16 -8
- package/lib/utilities/merge-refs/merge-refs.d.ts +1 -1
- package/package.json +6 -2
package/lib/components/accordion/parts/accordion-item-indicator/accordion-item-indicator.qwik.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx } from "@qwik.dev/core/jsx-runtime";
|
|
2
|
+
import { component$, Slot } from "@qwik.dev/core";
|
|
3
|
+
import { mergeStyles } from "../../../../utilities/merge-styles/merge-styles.qwik.mjs";
|
|
4
|
+
import { Primitive } from "../../../../_internal/components/primitive/primitive.qwik.mjs";
|
|
5
|
+
import { useAccordionItemContext } from "../../contexts/accordion-item-context/accordion-item-context.qwik.mjs";
|
|
6
|
+
const AccordionItemIndicator = component$((props) => {
|
|
7
|
+
const { style, ...others } = props;
|
|
8
|
+
const { open, disabled } = useAccordionItemContext();
|
|
9
|
+
return /* @__PURE__ */ jsx(Primitive.span, {
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
"data-entry-ui-qwik-accordion-item-indicator": "",
|
|
12
|
+
"data-state": open.value ? "open" : "closed",
|
|
13
|
+
"data-disabled": disabled.value ? "" : void 0,
|
|
14
|
+
style: mergeStyles([
|
|
15
|
+
{
|
|
16
|
+
pointerEvents: "none",
|
|
17
|
+
userSelect: "none"
|
|
18
|
+
},
|
|
19
|
+
style
|
|
20
|
+
]),
|
|
21
|
+
...others,
|
|
22
|
+
children: /* @__PURE__ */ jsx(Slot, {})
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
export {
|
|
26
|
+
AccordionItemIndicator
|
|
27
|
+
};
|
package/lib/components/accordion/parts/accordion-item-indicator/accordion-item-indicator.types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PropsOf, Component } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the `Accordion.ItemIndicator` component.
|
|
4
|
+
* Extends the standard HTML attributes for a `<span>` element.
|
|
5
|
+
*/
|
|
6
|
+
export interface AccordionItemIndicatorProps extends PropsOf<'span'> {
|
|
7
|
+
/**
|
|
8
|
+
* The element or component this component should render as.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://github.com/ZAHON/entry-ui/tree/main/packages/qwik/docs/guides/composition.md Composition} guide for more details.
|
|
11
|
+
*
|
|
12
|
+
* @default "span"
|
|
13
|
+
*/
|
|
14
|
+
as?: string | Component;
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AccordionItemPanelProps } from './accordion-item-panel.types';
|
|
2
|
+
/**
|
|
3
|
+
* A collapsible panel with the accordion item contents.
|
|
4
|
+
*
|
|
5
|
+
* Renders a `<div>` element.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AccordionItemPanel: import("@qwik.dev/core").Component<AccordionItemPanelProps>;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { jsx } from "@qwik.dev/core/jsx-runtime";
|
|
2
|
+
import { component$, useSignal, useComputed$, $, useTask$, isBrowser, isDev, sync$, Slot } from "@qwik.dev/core";
|
|
3
|
+
import { getComputedStyle } from "@entry-ui/utilities/get-computed-style";
|
|
4
|
+
import { getHiddenElementHeight } from "@entry-ui/utilities/get-hidden-element-height";
|
|
5
|
+
import { addEventListenerOnce } from "@entry-ui/utilities/add-event-listener-once";
|
|
6
|
+
import { useLifecycle } from "../../../../hooks/use-lifecycle/use-lifecycle.qwik.mjs";
|
|
7
|
+
import { mergeStyles } from "../../../../utilities/merge-styles/merge-styles.qwik.mjs";
|
|
8
|
+
import { mergeRefs } from "../../../../utilities/merge-refs/merge-refs.qwik.mjs";
|
|
9
|
+
import { warn } from "../../../../_internal/utilities/warn/warn.qwik.mjs";
|
|
10
|
+
import { Primitive } from "../../../../_internal/components/primitive/primitive.qwik.mjs";
|
|
11
|
+
import { useAccordionRootContext } from "../../contexts/accordion-root-context/accordion-root-context.qwik.mjs";
|
|
12
|
+
import { useAccordionItemContext } from "../../contexts/accordion-item-context/accordion-item-context.qwik.mjs";
|
|
13
|
+
const AccordionItemPanel = component$((props) => {
|
|
14
|
+
const { as = "div", ref: _ref, id, hiddenUntilFound: _hiddenUntilFound = false, onOpenChangeComplete$, onBeforematch$, style, ...others } = props;
|
|
15
|
+
const { hiddenUntilFound: rootHiddenUntilFound } = useAccordionRootContext();
|
|
16
|
+
const { open, setOpen$, disabled, panelId, triggerId } = useAccordionItemContext();
|
|
17
|
+
const ref = useSignal(void 0);
|
|
18
|
+
const hidden = useSignal(!open.value);
|
|
19
|
+
const state = useSignal(open.value ? "open" : "closed");
|
|
20
|
+
const height = useSignal(() => {
|
|
21
|
+
if (open.value) {
|
|
22
|
+
return "auto";
|
|
23
|
+
}
|
|
24
|
+
return _hiddenUntilFound || rootHiddenUntilFound.value ? disabled.value ? "0px" : "none" : "0px";
|
|
25
|
+
});
|
|
26
|
+
const isBeforeMatch = useSignal(false);
|
|
27
|
+
const preventInitialAnimation = useSignal(true);
|
|
28
|
+
const hiddenUntilFound = useComputed$(() => disabled.value ? false : _hiddenUntilFound || rootHiddenUntilFound.value);
|
|
29
|
+
const mergedStyles = useComputed$(() => mergeStyles([
|
|
30
|
+
{
|
|
31
|
+
display: hidden.value ? hiddenUntilFound.value ? void 0 : "none !important" : void 0,
|
|
32
|
+
transitionDuration: preventInitialAnimation.value ? "0s" : void 0,
|
|
33
|
+
animationDuration: preventInitialAnimation.value ? "0s" : void 0,
|
|
34
|
+
"--entry-ui-qwik-accordion-item-panel-height": height.value
|
|
35
|
+
},
|
|
36
|
+
style
|
|
37
|
+
]));
|
|
38
|
+
useLifecycle({
|
|
39
|
+
element: ref,
|
|
40
|
+
onMount$: $(() => panelId.set$(id)),
|
|
41
|
+
onUnmount$: $(() => panelId.delete$())
|
|
42
|
+
});
|
|
43
|
+
useTask$(({ track }) => {
|
|
44
|
+
const isHiddenUntilFound = track(() => hiddenUntilFound.value);
|
|
45
|
+
const panelRef = ref.value;
|
|
46
|
+
if (isBrowser && panelRef) {
|
|
47
|
+
const panelHeight = open.value ? "auto" : isHiddenUntilFound ? "none" : "0px";
|
|
48
|
+
height.value = panelHeight;
|
|
49
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", panelHeight);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
useTask$(({ track, cleanup }) => {
|
|
53
|
+
const isOpen = track(() => open.value);
|
|
54
|
+
const panelRef = ref.value;
|
|
55
|
+
if (isBrowser && panelRef) {
|
|
56
|
+
if (preventInitialAnimation.value && !isBeforeMatch.value) {
|
|
57
|
+
preventInitialAnimation.value = false;
|
|
58
|
+
panelRef.style.removeProperty("transition-duration");
|
|
59
|
+
panelRef.style.removeProperty("animation-duration");
|
|
60
|
+
}
|
|
61
|
+
if (isOpen) {
|
|
62
|
+
hidden.value = false;
|
|
63
|
+
panelRef.removeAttribute("hidden");
|
|
64
|
+
if (hiddenUntilFound.value) {
|
|
65
|
+
isBeforeMatch.value = false;
|
|
66
|
+
} else {
|
|
67
|
+
panelRef.style.removeProperty("display");
|
|
68
|
+
}
|
|
69
|
+
state.value = "open";
|
|
70
|
+
panelRef.setAttribute("data-state", "open");
|
|
71
|
+
const { animationDuration: animationDuration2, transitionDuration: transitionDuration2 } = getComputedStyle(panelRef);
|
|
72
|
+
const panelHeight = getHiddenElementHeight(panelRef);
|
|
73
|
+
if (animationDuration2 === "0s" && transitionDuration2 !== "0s") {
|
|
74
|
+
if (height.value === "none") {
|
|
75
|
+
height.value = "0px";
|
|
76
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", "0px");
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
height.value = `${panelHeight}px`;
|
|
79
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", `${panelHeight}px`);
|
|
80
|
+
}, 0);
|
|
81
|
+
} else {
|
|
82
|
+
height.value = `${panelHeight}px`;
|
|
83
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", `${panelHeight}px`);
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
height.value = `${panelHeight}px`;
|
|
87
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", `${panelHeight}px`);
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
state.value = "closed";
|
|
91
|
+
panelRef.setAttribute("data-state", "closed");
|
|
92
|
+
const { animationDuration: animationDuration2, transitionDuration: transitionDuration2 } = getComputedStyle(panelRef);
|
|
93
|
+
const panelHeight = getHiddenElementHeight(panelRef);
|
|
94
|
+
if (animationDuration2 === "0s" && transitionDuration2 !== "0s") {
|
|
95
|
+
if (height.value === "auto") {
|
|
96
|
+
height.value = `${panelHeight}px`;
|
|
97
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", `${panelHeight}px`);
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
height.value = "0px";
|
|
100
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", "0px");
|
|
101
|
+
}, 0);
|
|
102
|
+
} else {
|
|
103
|
+
height.value = "0px";
|
|
104
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", "0px");
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
height.value = `${panelHeight}px`;
|
|
108
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", `${panelHeight}px`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const applyFinalState = () => {
|
|
112
|
+
if (isOpen) {
|
|
113
|
+
height.value = "auto";
|
|
114
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", "auto");
|
|
115
|
+
} else {
|
|
116
|
+
hidden.value = true;
|
|
117
|
+
if (hiddenUntilFound.value) {
|
|
118
|
+
height.value = "none";
|
|
119
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", "none");
|
|
120
|
+
} else {
|
|
121
|
+
height.value = "0px";
|
|
122
|
+
panelRef.style.setProperty("--entry-ui-qwik-accordion-item-panel-height", "0px");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (onOpenChangeComplete$) {
|
|
126
|
+
onOpenChangeComplete$(isOpen);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const { transitionDuration, animationDuration } = getComputedStyle(panelRef);
|
|
130
|
+
if (isDev && transitionDuration !== "0s" && animationDuration !== "0s") {
|
|
131
|
+
warn([
|
|
132
|
+
`Both CSS transitions and CSS animations are detected on 'Accordion.ItemPanel' component.`,
|
|
133
|
+
`Using both at the same time may cause unpredictable behavior.`,
|
|
134
|
+
`Please use only one animation method.`
|
|
135
|
+
]);
|
|
136
|
+
applyFinalState();
|
|
137
|
+
} else if (transitionDuration !== "0s") {
|
|
138
|
+
const removeTransitionEndListener = addEventListenerOnce({
|
|
139
|
+
target: panelRef,
|
|
140
|
+
type: "transitionend",
|
|
141
|
+
listener: applyFinalState
|
|
142
|
+
});
|
|
143
|
+
cleanup(() => {
|
|
144
|
+
removeTransitionEndListener();
|
|
145
|
+
});
|
|
146
|
+
} else if (animationDuration !== "0s") {
|
|
147
|
+
const removeAnimationEndListener = addEventListenerOnce({
|
|
148
|
+
target: panelRef,
|
|
149
|
+
type: "animationend",
|
|
150
|
+
listener: applyFinalState
|
|
151
|
+
});
|
|
152
|
+
cleanup(() => {
|
|
153
|
+
removeAnimationEndListener();
|
|
154
|
+
});
|
|
155
|
+
} else {
|
|
156
|
+
applyFinalState();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
const handleBeforeMatchSync$ = sync$((event) => {
|
|
161
|
+
const entryUIQwikEvent = event;
|
|
162
|
+
if (!entryUIQwikEvent.entryUIQwikHandlerPrevented) {
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
const handleBeforeMatch$ = $((event) => {
|
|
167
|
+
const entryUIQwikEvent = event;
|
|
168
|
+
if (!entryUIQwikEvent.entryUIQwikHandlerPrevented) {
|
|
169
|
+
isBeforeMatch.value = true;
|
|
170
|
+
preventInitialAnimation.value = true;
|
|
171
|
+
setOpen$(true);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return /* @__PURE__ */ jsx(Primitive.div, {
|
|
175
|
+
as,
|
|
176
|
+
ref: mergeRefs([
|
|
177
|
+
_ref,
|
|
178
|
+
ref
|
|
179
|
+
]),
|
|
180
|
+
id: panelId.id.value,
|
|
181
|
+
role: triggerId.id.value ? "region" : void 0,
|
|
182
|
+
hidden: hidden.value ? hiddenUntilFound.value ? "until-found" : "hidden" : void 0,
|
|
183
|
+
"aria-labelledby": triggerId.id.value,
|
|
184
|
+
"data-entry-ui-qwik-accordion-item-panel": "",
|
|
185
|
+
"data-state": state.value,
|
|
186
|
+
"data-disabled": disabled.value ? "" : void 0,
|
|
187
|
+
onBeforematch$: [
|
|
188
|
+
onBeforematch$,
|
|
189
|
+
handleBeforeMatchSync$,
|
|
190
|
+
handleBeforeMatch$
|
|
191
|
+
],
|
|
192
|
+
style: mergedStyles.value,
|
|
193
|
+
...others,
|
|
194
|
+
children: /* @__PURE__ */ jsx(Slot, {})
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
export {
|
|
198
|
+
AccordionItemPanel
|
|
199
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PropsOf, Component, QRL } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the `Accordion.ItemPanel` component.
|
|
4
|
+
* Extends the standard HTML attributes for a `<div>` element.
|
|
5
|
+
*/
|
|
6
|
+
export interface AccordionItemPanelProps extends PropsOf<'div'> {
|
|
7
|
+
/**
|
|
8
|
+
* The element or component this component should render as.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://github.com/ZAHON/entry-ui/tree/main/packages/qwik/docs/guides/composition.md Composition} guide for more details.
|
|
11
|
+
*
|
|
12
|
+
* @default "div"
|
|
13
|
+
*/
|
|
14
|
+
as?: string | Component;
|
|
15
|
+
/**
|
|
16
|
+
* When `true`, the panel uses the `hidden="until-found"` attribute when closed.
|
|
17
|
+
* This allows the browser to search and reveal content within the panel
|
|
18
|
+
* even before it is manually opened.
|
|
19
|
+
*
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
hiddenUntilFound?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* A `QRL` callback invoked once the panel's expansion or collapse has fully settled.
|
|
25
|
+
* If CSS transitions or animations are present, it triggers after they finish;
|
|
26
|
+
* otherwise, it executes immediately upon the state change.
|
|
27
|
+
*
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
onOpenChangeComplete$?: QRL<(open: boolean) => void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AccordionItemTriggerProps } from './accordion-item-trigger.types';
|
|
2
|
+
/**
|
|
3
|
+
* A button that opens and closes the corresponding panel.
|
|
4
|
+
*
|
|
5
|
+
* Renders a `<button>` element.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AccordionItemTrigger: import("@qwik.dev/core").Component<AccordionItemTriggerProps>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx } from "@qwik.dev/core/jsx-runtime";
|
|
2
|
+
import { component$, useSignal, useComputed$, $, useContextProvider, Slot } from "@qwik.dev/core";
|
|
3
|
+
import { useLifecycle } from "../../../../hooks/use-lifecycle/use-lifecycle.qwik.mjs";
|
|
4
|
+
import { mergeRefs } from "../../../../utilities/merge-refs/merge-refs.qwik.mjs";
|
|
5
|
+
import { Primitive } from "../../../../_internal/components/primitive/primitive.qwik.mjs";
|
|
6
|
+
import { useAccordionItemContext } from "../../contexts/accordion-item-context/accordion-item-context.qwik.mjs";
|
|
7
|
+
import { AccordionItemTriggerContext } from "../../contexts/accordion-item-trigger-context/accordion-item-trigger-context.qwik.mjs";
|
|
8
|
+
const AccordionItemTrigger = component$((props) => {
|
|
9
|
+
const { as = "button", ref: _ref, id, disabled: _disabled, onClick$, ...others } = props;
|
|
10
|
+
const { open, setOpen$, disabled: itemDisabled, triggerId, panelId } = useAccordionItemContext();
|
|
11
|
+
const ref = useSignal(void 0);
|
|
12
|
+
const disabled = useComputed$(() => _disabled ?? itemDisabled.value);
|
|
13
|
+
useLifecycle({
|
|
14
|
+
element: ref,
|
|
15
|
+
onMount$: $(() => triggerId.set$(id)),
|
|
16
|
+
onUnmount$: $(() => triggerId.delete$())
|
|
17
|
+
});
|
|
18
|
+
const handleClick$ = $((event) => {
|
|
19
|
+
const entryUIQwikEvent = event;
|
|
20
|
+
if (!entryUIQwikEvent.entryUIQwikHandlerPrevented && !disabled.value) {
|
|
21
|
+
setOpen$(!open.value);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
useContextProvider(AccordionItemTriggerContext, {
|
|
25
|
+
disabled
|
|
26
|
+
});
|
|
27
|
+
return /* @__PURE__ */ jsx(Primitive.button, {
|
|
28
|
+
as,
|
|
29
|
+
ref: mergeRefs([
|
|
30
|
+
_ref,
|
|
31
|
+
ref
|
|
32
|
+
]),
|
|
33
|
+
type: "button",
|
|
34
|
+
id: triggerId.id.value,
|
|
35
|
+
disabled: disabled.value,
|
|
36
|
+
"aria-controls": panelId.id.value && open.value ? panelId.id.value : void 0,
|
|
37
|
+
"aria-expanded": panelId.id.value ? open.value : void 0,
|
|
38
|
+
"data-entry-ui-qwik-accordion-item-trigger": "",
|
|
39
|
+
"data-state": open.value ? "open" : "closed",
|
|
40
|
+
// Present when the accordion item component is in a disabled state.
|
|
41
|
+
"data-disabled": itemDisabled.value ? "" : void 0,
|
|
42
|
+
onClick$: [
|
|
43
|
+
onClick$,
|
|
44
|
+
handleClick$
|
|
45
|
+
],
|
|
46
|
+
...others,
|
|
47
|
+
children: /* @__PURE__ */ jsx(Slot, {})
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
export {
|
|
51
|
+
AccordionItemTrigger
|
|
52
|
+
};
|
package/lib/components/accordion/parts/accordion-item-trigger/accordion-item-trigger.types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PropsOf, Component } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the `Accordion.ItemTrigger` component.
|
|
4
|
+
* Extends the standard HTML attributes for a `<button>` element.
|
|
5
|
+
*/
|
|
6
|
+
export interface AccordionItemTriggerProps extends PropsOf<'button'> {
|
|
7
|
+
/**
|
|
8
|
+
* The element or component this component should render as.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://github.com/ZAHON/entry-ui/tree/main/packages/qwik/docs/guides/composition.md Composition} guide for more details.
|
|
11
|
+
*
|
|
12
|
+
* @default "button"
|
|
13
|
+
*/
|
|
14
|
+
as?: string | Component;
|
|
15
|
+
/**
|
|
16
|
+
* When `true`, prevents the user from interacting with the trigger.
|
|
17
|
+
* If left `undefined`, this state will be inherited from the `disabled`
|
|
18
|
+
* prop of the `Accordion.Item` component.
|
|
19
|
+
*
|
|
20
|
+
* @default undefined
|
|
21
|
+
*/
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { jsx } from "@qwik.dev/core/jsx-runtime";
|
|
2
|
+
import { component$, useComputed$, $, sync$, useContextProvider, Slot } from "@qwik.dev/core";
|
|
3
|
+
import { isDev } from "@qwik.dev/core/build";
|
|
4
|
+
import { useControllable } from "../../../../hooks/use-controllable/use-controllable.qwik.mjs";
|
|
5
|
+
import { mergeStyles } from "../../../../utilities/merge-styles/merge-styles.qwik.mjs";
|
|
6
|
+
import { warn } from "../../../../_internal/utilities/warn/warn.qwik.mjs";
|
|
7
|
+
import { Primitive } from "../../../../_internal/components/primitive/primitive.qwik.mjs";
|
|
8
|
+
import { AccordionRootContext } from "../../contexts/accordion-root-context/accordion-root-context.qwik.mjs";
|
|
9
|
+
const AccordionRoot = component$((props) => {
|
|
10
|
+
const { as = "div", defaultValue, value: _value, onValueChange$, multiple = false, loopFocus = true, hiddenUntilFound: _hiddenUntilFound = false, disabled: _disabled = false, onKeyDown$, style, ...others } = props;
|
|
11
|
+
const { state: value, setState$: setValue$ } = useControllable({
|
|
12
|
+
defaultValue: defaultValue ?? [],
|
|
13
|
+
controlledSignal: _value,
|
|
14
|
+
onChange$: onValueChange$
|
|
15
|
+
});
|
|
16
|
+
const hiddenUntilFound = useComputed$(() => _hiddenUntilFound);
|
|
17
|
+
const disabled = useComputed$(() => _disabled);
|
|
18
|
+
if (isDev && !multiple && value.value.length > 1) {
|
|
19
|
+
warn([
|
|
20
|
+
`The 'Accordion.Root' component is in single-selection mode,`,
|
|
21
|
+
`but received ${value.value.length} open items in 'value' or 'defaultValue'.`,
|
|
22
|
+
`This may lead to unpredictable behavior.`
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
const onItemOpen$ = $((itemValue) => {
|
|
26
|
+
if (!multiple) {
|
|
27
|
+
setValue$([
|
|
28
|
+
itemValue
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
if (multiple) {
|
|
32
|
+
setValue$([
|
|
33
|
+
...value.value,
|
|
34
|
+
itemValue
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const onItemClose$ = $((itemValue) => {
|
|
39
|
+
if (!multiple) {
|
|
40
|
+
setValue$([]);
|
|
41
|
+
}
|
|
42
|
+
if (multiple) {
|
|
43
|
+
setValue$(value.value.filter((value2) => value2 !== itemValue));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const handleKeyDownSync$ = sync$((event) => {
|
|
47
|
+
const entryUIQwikEvent = event;
|
|
48
|
+
if (!entryUIQwikEvent.entryUIQwikHandlerPrevented && [
|
|
49
|
+
"ArrowDown",
|
|
50
|
+
"ArrowUp",
|
|
51
|
+
"Home",
|
|
52
|
+
"End"
|
|
53
|
+
].includes(event.key)) {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const handleKeyDown$ = $((event, currentTarget) => {
|
|
58
|
+
const entryUIQwikEvent = event;
|
|
59
|
+
if (!entryUIQwikEvent.entryUIQwikHandlerPrevented && [
|
|
60
|
+
"ArrowDown",
|
|
61
|
+
"ArrowUp",
|
|
62
|
+
"Home",
|
|
63
|
+
"End"
|
|
64
|
+
].includes(event.key)) {
|
|
65
|
+
const target = event.target;
|
|
66
|
+
const ENABLED_TRIGGERS_SELECTOR = "[data-entry-ui-qwik-accordion-item-trigger]:not([disabled])";
|
|
67
|
+
const enabledTriggers = Array.from(currentTarget.querySelectorAll(ENABLED_TRIGGERS_SELECTOR));
|
|
68
|
+
const thisIndex = enabledTriggers.indexOf(target);
|
|
69
|
+
const lastIndex = enabledTriggers.length - 1;
|
|
70
|
+
let nextIndex = -1;
|
|
71
|
+
switch (event.key) {
|
|
72
|
+
case "ArrowDown":
|
|
73
|
+
if (loopFocus) {
|
|
74
|
+
nextIndex = thisIndex + 1 > lastIndex ? 0 : thisIndex + 1;
|
|
75
|
+
} else {
|
|
76
|
+
nextIndex = Math.min(thisIndex + 1, lastIndex);
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case "ArrowUp":
|
|
80
|
+
if (loopFocus) {
|
|
81
|
+
nextIndex = thisIndex === 0 ? lastIndex : thisIndex - 1;
|
|
82
|
+
} else {
|
|
83
|
+
nextIndex = thisIndex - 1;
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case "Home":
|
|
87
|
+
nextIndex = 0;
|
|
88
|
+
break;
|
|
89
|
+
case "End":
|
|
90
|
+
nextIndex = lastIndex;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (nextIndex > -1) {
|
|
94
|
+
enabledTriggers[nextIndex]?.focus();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
useContextProvider(AccordionRootContext, {
|
|
99
|
+
value,
|
|
100
|
+
setValue$,
|
|
101
|
+
hiddenUntilFound,
|
|
102
|
+
disabled,
|
|
103
|
+
onItemOpen$,
|
|
104
|
+
onItemClose$
|
|
105
|
+
});
|
|
106
|
+
return /* @__PURE__ */ jsx(Primitive.div, {
|
|
107
|
+
as,
|
|
108
|
+
"data-entry-ui-qwik-accordion-root": "",
|
|
109
|
+
"data-disabled": disabled.value ? "" : void 0,
|
|
110
|
+
onKeyDown$: [
|
|
111
|
+
onKeyDown$,
|
|
112
|
+
handleKeyDownSync$,
|
|
113
|
+
handleKeyDown$
|
|
114
|
+
],
|
|
115
|
+
style: mergeStyles([
|
|
116
|
+
{
|
|
117
|
+
// Performance optimization
|
|
118
|
+
// The `contain: layout style;` CSS property is used here to improve rendering performance.
|
|
119
|
+
// `contain: layout;` tells the browser that the internal layout of this accordion
|
|
120
|
+
// is self-contained and does not affect the layout of elements outside of it. This prevents
|
|
121
|
+
// costly re-calculations of the entire page layout when an accordion item expands or collapses,
|
|
122
|
+
// which is especially beneficial during animations.
|
|
123
|
+
// `contain: style;` ensures that CSS properties that can affect the rest of the page,
|
|
124
|
+
// like counters, are isolated to this element.
|
|
125
|
+
// Together, these properties create a performance "bubble", allowing the browser to optimize
|
|
126
|
+
// rendering by treating the accordion component as an independent unit.
|
|
127
|
+
contain: "layout style"
|
|
128
|
+
},
|
|
129
|
+
style
|
|
130
|
+
]),
|
|
131
|
+
...others,
|
|
132
|
+
children: /* @__PURE__ */ jsx(Slot, {})
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
export {
|
|
136
|
+
AccordionRoot
|
|
137
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { PropsOf, Component, Signal, QRL } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the `Accordion.Root` component.
|
|
4
|
+
* Extends the standard HTML attributes for a `<div>` element.
|
|
5
|
+
*/
|
|
6
|
+
export interface AccordionRootProps extends PropsOf<'div'> {
|
|
7
|
+
/**
|
|
8
|
+
* The element or component this component should render as.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://github.com/ZAHON/entry-ui/tree/main/packages/qwik/docs/guides/composition.md Composition} guide for more details.
|
|
11
|
+
*
|
|
12
|
+
* @default "div"
|
|
13
|
+
*/
|
|
14
|
+
as?: string | Component;
|
|
15
|
+
/**
|
|
16
|
+
* The value of the accordion item or items to expand when initially rendered.
|
|
17
|
+
* When `multiple` is `false`, this array should contain at most one element.
|
|
18
|
+
* Use when you do not need to control the state of the accordion items.
|
|
19
|
+
*
|
|
20
|
+
* @default []
|
|
21
|
+
*/
|
|
22
|
+
defaultValue?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* The controlled value of the accordion item or items to expand.
|
|
25
|
+
* When `multiple` is `false`, this array should contain at most one element.
|
|
26
|
+
* Must be used in conjunction with `onValueChange$`.
|
|
27
|
+
*
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
value?: Signal<string[]>;
|
|
31
|
+
/**
|
|
32
|
+
* A `QRL` callback function that is called when the expanded state of an accordion item or items changes.
|
|
33
|
+
*
|
|
34
|
+
* @default undefined
|
|
35
|
+
*/
|
|
36
|
+
onValueChange$?: QRL<(value: string[]) => void>;
|
|
37
|
+
/**
|
|
38
|
+
* Whether or not multiple accordion items can be expanded at the same time.
|
|
39
|
+
* When `false`, expanding one item will automatically collapse the others.
|
|
40
|
+
*
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
multiple?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the keyboard focus should wrap back to the first or last item trigger
|
|
46
|
+
* when navigating through the accordion.
|
|
47
|
+
* When `true`, pressing `ArrowDown` on the last enabled trigger moves focus to the
|
|
48
|
+
* first one, and `ArrowUp` on the first enabled trigger moves focus to the last one.
|
|
49
|
+
*
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
loopFocus?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* When `true`, all collapsed accordion panels will use the `hidden="until-found"`
|
|
55
|
+
* attribute. This allows the browser's "Find in page" feature to
|
|
56
|
+
* search through collapsed content and automatically expand the item when
|
|
57
|
+
* a match is found.
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
hiddenUntilFound?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* When `true`, prevents the user from interacting with the accordion and all its items.
|
|
64
|
+
*
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
disabled?: boolean;
|
|
68
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { AccordionRootProps as RootProps } from './accordion-root';
|
|
2
|
+
export type { AccordionItemProps as ItemProps } from './accordion-item';
|
|
3
|
+
export type { AccordionItemHeaderProps as ItemHeaderProps } from './accordion-item-header';
|
|
4
|
+
export type { AccordionItemTriggerProps as ItemTriggerProps } from './accordion-item-trigger';
|
|
5
|
+
export type { AccordionItemPanelProps as ItemPanelProps } from './accordion-item-panel';
|
|
6
|
+
export type { AccordionItemIndicatorProps as ItemIndicatorProps } from './accordion-item-indicator';
|
|
7
|
+
export { AccordionRoot as Root } from './accordion-root';
|
|
8
|
+
export { AccordionItem as Item } from './accordion-item';
|
|
9
|
+
export { AccordionItemHeader as ItemHeader } from './accordion-item-header';
|
|
10
|
+
export { AccordionItemTrigger as ItemTrigger } from './accordion-item-trigger';
|
|
11
|
+
export { AccordionItemPanel as ItemPanel } from './accordion-item-panel';
|
|
12
|
+
export { AccordionItemIndicator as ItemIndicator } from './accordion-item-indicator';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AccordionRoot } from "./accordion-root/accordion-root.qwik.mjs";
|
|
2
|
+
import { AccordionItem } from "./accordion-item/accordion-item.qwik.mjs";
|
|
3
|
+
import { AccordionItemHeader } from "./accordion-item-header/accordion-item-header.qwik.mjs";
|
|
4
|
+
import { AccordionItemTrigger } from "./accordion-item-trigger/accordion-item-trigger.qwik.mjs";
|
|
5
|
+
import { AccordionItemPanel } from "./accordion-item-panel/accordion-item-panel.qwik.mjs";
|
|
6
|
+
import { AccordionItemIndicator } from "./accordion-item-indicator/accordion-item-indicator.qwik.mjs";
|
|
7
|
+
export {
|
|
8
|
+
AccordionItem as Item,
|
|
9
|
+
AccordionItemHeader as ItemHeader,
|
|
10
|
+
AccordionItemIndicator as ItemIndicator,
|
|
11
|
+
AccordionItemPanel as ItemPanel,
|
|
12
|
+
AccordionItemTrigger as ItemTrigger,
|
|
13
|
+
AccordionRoot as Root
|
|
14
|
+
};
|
|
@@ -6,8 +6,8 @@ import type { ReadonlySignal } from '@qwik.dev/core';
|
|
|
6
6
|
export interface CollapsibleTriggerContextValue {
|
|
7
7
|
/**
|
|
8
8
|
* A readonly signal representing the effective disabled state of the trigger.
|
|
9
|
-
* This value is computed by prioritizing the trigger's own
|
|
10
|
-
* falling back to the
|
|
9
|
+
* This value is computed by prioritizing the trigger's own `disabled` prop,
|
|
10
|
+
* falling back to the `Collapsible.Root` disabled state if not explicitly set.
|
|
11
11
|
*/
|
|
12
12
|
disabled: ReadonlySignal<boolean>;
|
|
13
13
|
}
|
|
@@ -6,8 +6,8 @@ import type { ReadonlySignal } from '@qwik.dev/core';
|
|
|
6
6
|
export interface UseCollapsibleTriggerContextReturnValue {
|
|
7
7
|
/**
|
|
8
8
|
* A readonly signal representing the effective disabled state of the trigger.
|
|
9
|
-
* This value is computed by prioritizing the trigger's own
|
|
10
|
-
* falling back to the
|
|
9
|
+
* This value is computed by prioritizing the trigger's own `disabled` prop,
|
|
10
|
+
* falling back to the `Collapsible.Root` disabled state if not explicitly set.
|
|
11
11
|
*/
|
|
12
12
|
disabled: ReadonlySignal<boolean>;
|
|
13
13
|
}
|