@entry-ui/qwik 0.3.0 → 0.5.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.
Files changed (72) hide show
  1. package/lib/_internal/components/primitive/primitive.d.ts +2 -1
  2. package/lib/_internal/components/primitive/primitive.qwik.mjs +1 -0
  3. package/lib/_internal/components/primitive/primitive.types.d.ts +5 -0
  4. package/lib/_internal/index.d.ts +1 -0
  5. package/lib/_internal/utilities/error/error.d.ts +8 -0
  6. package/lib/_internal/utilities/error/index.d.ts +1 -0
  7. package/lib/_internal/utilities/fail/fail.d.ts +8 -0
  8. package/lib/_internal/utilities/fail/fail.qwik.mjs +10 -0
  9. package/lib/_internal/utilities/fail/index.d.ts +1 -0
  10. package/lib/_internal/utilities/index.d.ts +3 -0
  11. package/lib/_internal/utilities/warn/index.d.ts +1 -0
  12. package/lib/_internal/utilities/warn/warn.d.ts +7 -0
  13. package/lib/components/alert/parts/alert-root/alert-root.types.d.ts +4 -0
  14. package/lib/components/index.d.ts +1 -0
  15. package/lib/components/separator/parts/separator-root/separator-root.types.d.ts +4 -0
  16. package/lib/components/toggle/contexts/index.d.ts +1 -0
  17. package/lib/components/toggle/contexts/toggle-root-context/index.d.ts +2 -0
  18. package/lib/components/toggle/contexts/toggle-root-context/toggle-root-context.d.ts +6 -0
  19. package/lib/components/toggle/contexts/toggle-root-context/toggle-root-context.qwik.mjs +5 -0
  20. package/lib/components/toggle/contexts/toggle-root-context/toggle-root-context.types.d.ts +22 -0
  21. package/lib/components/toggle/hooks/index.d.ts +1 -0
  22. package/lib/components/toggle/hooks/use-toggle-root-context/index.d.ts +2 -0
  23. package/lib/components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.d.ts +7 -0
  24. package/lib/components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.qwik.mjs +13 -0
  25. package/lib/components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.types.d.ts +22 -0
  26. package/lib/components/toggle/index.d.ts +2 -0
  27. package/lib/components/toggle/index.qwik.mjs +6 -0
  28. package/lib/components/toggle/parts/index.d.ts +2 -0
  29. package/lib/components/toggle/parts/index.qwik.mjs +4 -0
  30. package/lib/components/toggle/parts/toggle-root/index.d.ts +2 -0
  31. package/lib/components/toggle/parts/toggle-root/toggle-root.d.ts +7 -0
  32. package/lib/components/toggle/parts/toggle-root/toggle-root.qwik.mjs +43 -0
  33. package/lib/components/toggle/parts/toggle-root/toggle-root.types.d.ts +41 -0
  34. package/lib/hooks/index.d.ts +3 -0
  35. package/lib/hooks/use-boolean/index.d.ts +2 -0
  36. package/lib/hooks/use-boolean/index.qwik.mjs +4 -0
  37. package/lib/hooks/use-boolean/use-boolean.d.ts +12 -0
  38. package/lib/hooks/use-boolean/use-boolean.qwik.mjs +22 -0
  39. package/lib/hooks/use-boolean/use-boolean.types.d.ts +22 -0
  40. package/lib/hooks/use-controllable/index.d.ts +2 -0
  41. package/lib/hooks/use-controllable/index.qwik.mjs +4 -0
  42. package/lib/hooks/use-controllable/use-controllable.d.ts +14 -0
  43. package/lib/hooks/use-controllable/use-controllable.qwik.mjs +35 -0
  44. package/lib/hooks/use-controllable/use-controllable.types.d.ts +52 -0
  45. package/lib/hooks/use-cycle/index.d.ts +2 -0
  46. package/lib/hooks/use-cycle/index.qwik.mjs +4 -0
  47. package/lib/hooks/use-cycle/use-cycle.d.ts +11 -0
  48. package/lib/hooks/use-cycle/use-cycle.qwik.mjs +54 -0
  49. package/lib/hooks/use-cycle/use-cycle.types.d.ts +63 -0
  50. package/lib/index.d.ts +3 -0
  51. package/lib/index.qwik.mjs +17 -1
  52. package/lib/types/entry-ui-qwik-event/entry-ui-qwik-event.types.d.ts +22 -0
  53. package/lib/types/entry-ui-qwik-event/index.d.ts +1 -0
  54. package/lib/types/entry-ui-qwik-event-state/entry-ui-qwik-event-state.types.d.ts +17 -0
  55. package/lib/types/entry-ui-qwik-event-state/index.d.ts +1 -0
  56. package/lib/types/index.d.ts +2 -0
  57. package/lib/utilities/index.d.ts +3 -0
  58. package/lib/utilities/make-event-preventable/index.d.ts +1 -0
  59. package/lib/utilities/make-event-preventable/index.qwik.mjs +4 -0
  60. package/lib/utilities/make-event-preventable/make-event-preventable.d.ts +20 -0
  61. package/lib/utilities/make-event-preventable/make-event-preventable.qwik.mjs +10 -0
  62. package/lib/utilities/merge-refs/index.d.ts +2 -0
  63. package/lib/utilities/merge-refs/index.qwik.mjs +4 -0
  64. package/lib/utilities/merge-refs/merge-refs.d.ts +15 -0
  65. package/lib/utilities/merge-refs/merge-refs.qwik.mjs +17 -0
  66. package/lib/utilities/merge-refs/merge-refs.types.d.ts +14 -0
  67. package/lib/utilities/merge-styles/index.d.ts +2 -0
  68. package/lib/utilities/merge-styles/index.qwik.mjs +4 -0
  69. package/lib/utilities/merge-styles/merge-styles.d.ts +13 -0
  70. package/lib/utilities/merge-styles/merge-styles.qwik.mjs +7 -0
  71. package/lib/utilities/merge-styles/merge-styles.types.d.ts +15 -0
  72. package/package.json +34 -2
@@ -4,7 +4,7 @@ import type { Component } from '@qwik.dev/core';
4
4
  * List of HTML elements that can be created as primitive components.
5
5
  * Each node in this array will have a corresponding component in the `Primitive` object.
6
6
  */
7
- declare const NODES: readonly ["div", "span"];
7
+ declare const NODES: readonly ["button", "div", "span"];
8
8
  /**
9
9
  * A factory function that creates a polymorphic Qwik component for a specific HTML tag.
10
10
  */
@@ -20,6 +20,7 @@ export declare const createPrimitive: <Node extends (typeof NODES)[number]>(node
20
20
  */
21
21
  export declare const Primitive: {
22
22
  div: Component<PrimitiveProps<"div">>;
23
+ button: Component<PrimitiveProps<"button">>;
23
24
  span: Component<PrimitiveProps<"span">>;
24
25
  };
25
26
  export {};
@@ -1,6 +1,7 @@
1
1
  import { jsx } from "@qwik.dev/core/jsx-runtime";
2
2
  import { component$, Slot } from "@qwik.dev/core";
3
3
  const NODES = [
4
+ "button",
4
5
  "div",
5
6
  "span"
6
7
  ];
@@ -1,4 +1,9 @@
1
1
  import type { Component, PropsOf } from '@qwik.dev/core';
2
+ /**
3
+ * Props for polymorphic primitive components.
4
+ * Combines the standard attributes of the specified HTML element (`Node`)
5
+ * with the `as` prop to allow component composition and semantic overrides.
6
+ */
2
7
  export type PrimitiveProps<Node> = {
3
8
  /**
4
9
  * The element or component this component should render as.
@@ -1 +1,2 @@
1
1
  export * from './components';
2
+ export * from './utilities';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Logs an error message to the console with a standardized `"[Entry UI Qwik]"` prefix.
3
+ *
4
+ * This utility function simplifies error reporting by automatically
5
+ * prepending a consistent prefix to all messages originating
6
+ * from the Entry UI Qwik library.
7
+ */
8
+ export declare const error: (messages: string[]) => void;
@@ -0,0 +1 @@
1
+ export { error } from './error';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Throws an error message with a standardized `"[Entry UI Qwik]"` prefix.
3
+ *
4
+ * This utility function simplifies error reporting by automatically
5
+ * prepending a consistent prefix to all messages originating
6
+ * from the Entry UI Qwik library, ensuring immediate execution termination.
7
+ */
8
+ export declare const fail: (messages: string[]) => never;
@@ -0,0 +1,10 @@
1
+ import { fail as fail$1 } from "@entry-ui/utilities/fail";
2
+ const fail = (messages) => {
3
+ fail$1({
4
+ prefix: "[Entry UI Qwik]",
5
+ messages
6
+ });
7
+ };
8
+ export {
9
+ fail
10
+ };
@@ -0,0 +1 @@
1
+ export { fail } from './fail';
@@ -0,0 +1,3 @@
1
+ export * from './error';
2
+ export * from './fail';
3
+ export * from './warn';
@@ -0,0 +1 @@
1
+ export { warn } from './warn';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Logs a warning message to the console with a standardized `"[Entry UI Qwik]"` prefix.
3
+ *
4
+ * This utility serves as a wrapper around the core warning function, ensuring that
5
+ * all logs originating from this library are easily identifiable and consistent.
6
+ */
7
+ export declare const warn: (messages: string[]) => void;
@@ -1,4 +1,8 @@
1
1
  import type { Component, PropsOf } from '@qwik.dev/core';
2
+ /**
3
+ * Props for the `Alert.Root` component.
4
+ * Extends the standard HTML attributes for a `div` element.
5
+ */
2
6
  export interface AlertRootProps extends PropsOf<'div'> {
3
7
  /**
4
8
  * The element or component this component should render as.
@@ -1,2 +1,3 @@
1
1
  export * from './alert';
2
2
  export * from './separator';
3
+ export * from './toggle';
@@ -1,4 +1,8 @@
1
1
  import type { Component, PropsOf } from '@qwik.dev/core';
2
+ /**
3
+ * Props for the `Separator.Root` component.
4
+ * Extends the standard HTML attributes for a `div` element.
5
+ */
2
6
  export interface SeparatorRootProps extends PropsOf<'div'> {
3
7
  /**
4
8
  * The element or component this component should render as.
@@ -0,0 +1 @@
1
+ export * from './toggle-root-context';
@@ -0,0 +1,2 @@
1
+ export type { ToggleRootContextValue } from './toggle-root-context.types';
2
+ export { ToggleRootContext } from './toggle-root-context';
@@ -0,0 +1,6 @@
1
+ import type { ToggleRootContextValue } from './toggle-root-context.types';
2
+ /**
3
+ * Provides the context for the `Toggle.Root` component, allowing descendant
4
+ * components to access readonly signals and `QRL` functions without prop drilling.
5
+ */
6
+ export declare const ToggleRootContext: import("@qwik.dev/core").ContextId<ToggleRootContextValue>;
@@ -0,0 +1,5 @@
1
+ import { createContextId } from "@qwik.dev/core";
2
+ const ToggleRootContext = createContextId("entry-ui-qwik-toggle-root-context");
3
+ export {
4
+ ToggleRootContext
5
+ };
@@ -0,0 +1,22 @@
1
+ import type { ReadonlySignal, QRL } from '@qwik.dev/core';
2
+ /**
3
+ * The value provided by the `Toggle.Root` context.
4
+ * Contains the readonly signals and `QRL` functions shared with descendant components.
5
+ */
6
+ export interface ToggleRootContextValue {
7
+ /**
8
+ * A readonly signal whose value indicates the toggle's current pressed state.
9
+ * It is `true` when the toggle is on, and `false` when off.
10
+ */
11
+ pressed: ReadonlySignal<boolean>;
12
+ /**
13
+ * A `QRL` function used to programmatically set the pressed state of the toggle.
14
+ * When invoked with `true`, the toggle will be on; with `false`, it will be off.
15
+ */
16
+ setPressed$: QRL<(pressed: boolean) => void>;
17
+ /**
18
+ * A readonly signal that indicates whether the toggle is disabled.
19
+ * Its value is `true` if the toggle is disabled, preventing user interaction.
20
+ */
21
+ disabled: ReadonlySignal<boolean>;
22
+ }
@@ -0,0 +1 @@
1
+ export * from './use-toggle-root-context';
@@ -0,0 +1,2 @@
1
+ export type { UseToggleRootContextReturnValue } from './use-toggle-root-context.types';
2
+ export { useToggleRootContext } from './use-toggle-root-context';
@@ -0,0 +1,7 @@
1
+ import type { UseToggleRootContextReturnValue } from './use-toggle-root-context.types';
2
+ /**
3
+ * A hook that provides access to the `Toggle.Root` component's internal state.
4
+ * It exposes readonly signals and `QRL` functions to interact with the toggle's state,
5
+ * allowing descendant components to control or react to its pressed/unpressed state.
6
+ */
7
+ export declare const useToggleRootContext: () => UseToggleRootContextReturnValue;
@@ -0,0 +1,13 @@
1
+ import { useContext } from "@qwik.dev/core";
2
+ import { ToggleRootContext } from "../../contexts/toggle-root-context/toggle-root-context.qwik.mjs";
3
+ const useToggleRootContext = () => {
4
+ const { pressed, setPressed$, disabled } = useContext(ToggleRootContext);
5
+ return {
6
+ pressed,
7
+ setPressed$,
8
+ disabled
9
+ };
10
+ };
11
+ export {
12
+ useToggleRootContext
13
+ };
@@ -0,0 +1,22 @@
1
+ import type { ReadonlySignal, QRL } from '@qwik.dev/core';
2
+ /**
3
+ * The value returned by the `useToggleRootContext` hook.
4
+ * Provides access to the toggle's readonly signals and `QRL` functions for descendant components.
5
+ */
6
+ export interface UseToggleRootContextReturnValue {
7
+ /**
8
+ * A readonly signal whose value indicates the toggle's current pressed state.
9
+ * It is `true` when the toggle is on, and `false` when off.
10
+ */
11
+ pressed: ReadonlySignal<boolean>;
12
+ /**
13
+ * A `QRL` function used to programmatically set the pressed state of the toggle.
14
+ * When invoked with `true`, the toggle will be on; with `false`, it will be off.
15
+ */
16
+ setPressed$: QRL<(pressed: boolean) => void>;
17
+ /**
18
+ * A readonly signal that indicates whether the toggle is disabled.
19
+ * Its value is `true` if the toggle is disabled, preventing user interaction.
20
+ */
21
+ disabled: ReadonlySignal<boolean>;
22
+ }
@@ -0,0 +1,2 @@
1
+ export * as Toggle from './parts';
2
+ export * from './hooks';
@@ -0,0 +1,6 @@
1
+ import * as index from "./parts/index.qwik.mjs";
2
+ import { useToggleRootContext } from "./hooks/use-toggle-root-context/use-toggle-root-context.qwik.mjs";
3
+ export {
4
+ index as Toggle,
5
+ useToggleRootContext
6
+ };
@@ -0,0 +1,2 @@
1
+ export type { ToggleRootProps as RootProps } from './toggle-root';
2
+ export { ToggleRoot as Root } from './toggle-root';
@@ -0,0 +1,4 @@
1
+ import { ToggleRoot } from "./toggle-root/toggle-root.qwik.mjs";
2
+ export {
3
+ ToggleRoot as Root
4
+ };
@@ -0,0 +1,2 @@
1
+ export type { ToggleRootProps } from './toggle-root.types';
2
+ export { ToggleRoot } from './toggle-root';
@@ -0,0 +1,7 @@
1
+ import type { ToggleRootProps } from './toggle-root.types';
2
+ /**
3
+ * Contains the content for the toggle.
4
+ *
5
+ * Renders a `<button>` element.
6
+ */
7
+ export declare const ToggleRoot: import("@qwik.dev/core").Component<ToggleRootProps>;
@@ -0,0 +1,43 @@
1
+ import { jsx } from "@qwik.dev/core/jsx-runtime";
2
+ import { component$, useComputed$, $, useContextProvider, Slot } from "@qwik.dev/core";
3
+ import { useControllable } from "../../../../hooks/use-controllable/use-controllable.qwik.mjs";
4
+ import { Primitive } from "../../../../_internal/components/primitive/primitive.qwik.mjs";
5
+ import { ToggleRootContext } from "../../contexts/toggle-root-context/toggle-root-context.qwik.mjs";
6
+ const ToggleRoot = component$((props) => {
7
+ const { as = "button", defaultPressed, pressed: _pressed, onPressedChange$, disabled: _disabled = false, onClick$, ...others } = props;
8
+ const { state: pressed, setState$: setPressed$ } = useControllable({
9
+ defaultValue: defaultPressed ?? false,
10
+ controlledSignal: _pressed,
11
+ onChange$: onPressedChange$
12
+ });
13
+ const disabled = useComputed$(() => _disabled);
14
+ const handleClick$ = $((event) => {
15
+ const entryUIQwikEvent = event;
16
+ if (!entryUIQwikEvent.entryUIQwikHandlerPrevented && !disabled.value) {
17
+ setPressed$(!pressed.value);
18
+ }
19
+ });
20
+ useContextProvider(ToggleRootContext, {
21
+ pressed,
22
+ setPressed$,
23
+ disabled
24
+ });
25
+ return /* @__PURE__ */ jsx(Primitive.button, {
26
+ as,
27
+ type: "button",
28
+ disabled: disabled.value,
29
+ "aria-pressed": pressed.value,
30
+ "data-entry-ui-qwik-toggle-root": "",
31
+ "data-state": pressed.value ? "on" : "off",
32
+ "data-disabled": disabled.value ? "" : void 0,
33
+ onClick$: [
34
+ onClick$,
35
+ handleClick$
36
+ ],
37
+ ...others,
38
+ children: /* @__PURE__ */ jsx(Slot, {})
39
+ });
40
+ });
41
+ export {
42
+ ToggleRoot
43
+ };
@@ -0,0 +1,41 @@
1
+ import type { PropsOf, Component, Signal, QRL } from '@qwik.dev/core';
2
+ /**
3
+ * Props for the `Toggle.Root` component.
4
+ * Extends the standard HTML attributes for a `button` element.
5
+ */
6
+ export interface ToggleRootProps 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
+ * The pressed state of the toggle when it is initially rendered.
17
+ * Use when you do not need to control its pressed state.
18
+ *
19
+ * @default undefined
20
+ */
21
+ defaultPressed?: boolean;
22
+ /**
23
+ * The controlled pressed state of the toggle.
24
+ * Must be used in conjunction with `onPressedChange$`.
25
+ *
26
+ * @default undefined
27
+ */
28
+ pressed?: Signal<boolean>;
29
+ /**
30
+ * A `QRL` callback function that is called when the pressed state of the toggle changes.
31
+ *
32
+ * @default undefined
33
+ */
34
+ onPressedChange$?: QRL<(pressed: boolean) => void>;
35
+ /**
36
+ * When `true`, prevents the user from interacting with the toggle.
37
+ *
38
+ * @default false
39
+ */
40
+ disabled?: boolean;
41
+ }
@@ -0,0 +1,3 @@
1
+ export * from './use-boolean';
2
+ export * from './use-controllable';
3
+ export * from './use-cycle';
@@ -0,0 +1,2 @@
1
+ export type { UseBooleanReturnValue } from './use-boolean.types';
2
+ export { useBoolean } from './use-boolean';
@@ -0,0 +1,4 @@
1
+ import { useBoolean } from "./use-boolean.qwik.mjs";
2
+ export {
3
+ useBoolean
4
+ };
@@ -0,0 +1,12 @@
1
+ import type { UseBooleanReturnValue } from './use-boolean.types';
2
+ /**
3
+ * A hook that manages a boolean state with common utility methods.
4
+ *
5
+ * The hook accepts a single `initialState` parameter, which defaults to `false`.
6
+ * It simplifies the management of boolean flags (toggles, modals, drawers) by
7
+ * encapsulating a boolean signal and exposing it as a readonly signal.
8
+ *
9
+ * State mutations are performed exclusively through the provided `QRL`
10
+ * functions (`setFalse$` ,`setTrue$`, `toggle$`), promoting a predictable data flow.
11
+ */
12
+ export declare const useBoolean: (initialState?: boolean) => UseBooleanReturnValue;
@@ -0,0 +1,22 @@
1
+ import { useSignal, $ } from "@qwik.dev/core";
2
+ const useBoolean = (initialState = false) => {
3
+ const state = useSignal(initialState);
4
+ const setFalse$ = $(() => {
5
+ state.value = false;
6
+ });
7
+ const setTrue$ = $(() => {
8
+ state.value = true;
9
+ });
10
+ const toggle$ = $(() => {
11
+ state.value = !state.value;
12
+ });
13
+ return {
14
+ state,
15
+ setFalse$,
16
+ setTrue$,
17
+ toggle$
18
+ };
19
+ };
20
+ export {
21
+ useBoolean
22
+ };
@@ -0,0 +1,22 @@
1
+ import type { ReadonlySignal, QRL } from '@qwik.dev/core';
2
+ /**
3
+ * Represents the object returned by the `useBoolean` hook.
4
+ */
5
+ export interface UseBooleanReturnValue {
6
+ /**
7
+ * A readonly signal whose value indicates the current boolean state.
8
+ */
9
+ state: ReadonlySignal<boolean>;
10
+ /**
11
+ * A `QRL` function to set the boolean state to `false`.
12
+ */
13
+ setFalse$: QRL<() => void>;
14
+ /**
15
+ * A `QRL` function to set the boolean state to `true`.
16
+ */
17
+ setTrue$: QRL<() => void>;
18
+ /**
19
+ * A `QRL` function to toggle the boolean state.
20
+ */
21
+ toggle$: QRL<() => void>;
22
+ }
@@ -0,0 +1,2 @@
1
+ export type { UseControllableParams, UseControllableReturnValue } from './use-controllable.types';
2
+ export { useControllable } from './use-controllable';
@@ -0,0 +1,4 @@
1
+ import { useControllable } from "./use-controllable.qwik.mjs";
2
+ export {
3
+ useControllable
4
+ };
@@ -0,0 +1,14 @@
1
+ import type { UseControllableParams, UseControllableReturnValue } from './use-controllable.types';
2
+ /**
3
+ * A hook that manages state in either controlled or uncontrolled mode.
4
+ *
5
+ * It provides a unified interface for handling state updates, regardless of whether
6
+ * the data is managed internally or by a parent component. This pattern is essential
7
+ * for building flexible UI components that need to support both "set-and-forget"
8
+ * usage and tight integration with external state.
9
+ *
10
+ * State synchronization is handled automatically:
11
+ * - **Controlled**: Uses the provided `controlledSignal` and requests changes via `onChange$`.
12
+ * - **Uncontrolled**: Manages an internal signal initialized by `defaultValue`.
13
+ */
14
+ export declare const useControllable: <T>(params?: UseControllableParams<T>) => UseControllableReturnValue<T>;
@@ -0,0 +1,35 @@
1
+ import { $, useSignal } from "@qwik.dev/core";
2
+ import { isDev } from "@qwik.dev/core/build";
3
+ import { fail } from "../../_internal/utilities/fail/fail.qwik.mjs";
4
+ const useControllable = (params = {}) => {
5
+ const { defaultValue, controlledSignal, onChange$ } = params;
6
+ if (controlledSignal !== void 0) {
7
+ const handleExternalStateChange$ = $((value) => {
8
+ onChange$?.(value);
9
+ });
10
+ return {
11
+ state: controlledSignal,
12
+ setState$: handleExternalStateChange$,
13
+ controlled: true
14
+ };
15
+ }
16
+ if (isDev && defaultValue === void 0) {
17
+ fail([
18
+ `The 'defaultValue' parameter in 'useControllable' hook is required when 'controlledSignal' is not provided.`,
19
+ `Either provide a 'defaultValue' for uncontrolled mode, or pass a 'controlledSignal' for controlled mode.`
20
+ ]);
21
+ }
22
+ const internalState = useSignal(defaultValue);
23
+ const handleInternalStateChange$ = $((value) => {
24
+ internalState.value = value;
25
+ onChange$?.(value);
26
+ });
27
+ return {
28
+ state: internalState,
29
+ setState$: handleInternalStateChange$,
30
+ controlled: false
31
+ };
32
+ };
33
+ export {
34
+ useControllable
35
+ };
@@ -0,0 +1,52 @@
1
+ import type { Signal, QRL, ReadonlySignal } from '@qwik.dev/core';
2
+ /**
3
+ * Configuration parameters for the `useControllable` hook.
4
+ * This interface defines the inputs required to initialize the hook in either
5
+ * controlled or uncontrolled mode, allowing for flexible state management
6
+ * strategies within the same component.
7
+ */
8
+ export interface UseControllableParams<T> {
9
+ /**
10
+ * The initial value used when the component is in uncontrolled mode.
11
+ * This value is only used to initialize the internal state if `controlledSignal` is not provided.
12
+ */
13
+ defaultValue?: T;
14
+ /**
15
+ * An optional external signal for controlled state management.
16
+ * If provided, the hook operates in controlled mode, delegating state authority to the parent.
17
+ * If omitted, the hook operates in uncontrolled mode using internal state.
18
+ */
19
+ controlledSignal?: Signal<T>;
20
+ /**
21
+ * An optional `QRL` callback invoked whenever the state value changes.
22
+ * In controlled mode, it notifies the parent to update the external signal.
23
+ * In uncontrolled mode, it acts as a listener for internal state changes.
24
+ */
25
+ onChange$?: QRL<(value: T) => void>;
26
+ }
27
+ /**
28
+ * The stable interface returned by the `useControllable` hook.
29
+ * It provides a unified way to access the current state and perform updates,
30
+ * abstracting away the complexity of switching between controlled and
31
+ * uncontrolled internal logic.
32
+ */
33
+ export interface UseControllableReturnValue<T> {
34
+ /**
35
+ * A readonly signal representing the current state.
36
+ * Provides the value from the `controlledSignal` in controlled mode,
37
+ * or the internal signal in uncontrolled mode.
38
+ */
39
+ state: ReadonlySignal<T>;
40
+ /**
41
+ * A `QRL` function to update the state.
42
+ * In controlled mode, it triggers `onChange$` to request a change from the parent.
43
+ * In uncontrolled mode, it updates the internal signal and then invokes `onChange$`.
44
+ */
45
+ setState$: QRL<(value: T) => void>;
46
+ /**
47
+ * A boolean flag indicating the current management mode.
48
+ * Returns `true` if the state is managed externally via `controlledSignal`,
49
+ * and `false` if managed internally.
50
+ */
51
+ controlled: boolean;
52
+ }
@@ -0,0 +1,2 @@
1
+ export type { UseCycleParams, UseCycleReturnValue } from './use-cycle.types';
2
+ export { useCycle } from './use-cycle';
@@ -0,0 +1,4 @@
1
+ import { useCycle } from "./use-cycle.qwik.mjs";
2
+ export {
3
+ useCycle
4
+ };
@@ -0,0 +1,11 @@
1
+ import type { UseCycleParams, UseCycleReturnValue } from './use-cycle.types';
2
+ /**
3
+ * A hook that manages navigation through a predefined sequence of options.
4
+ *
5
+ * This hook provides a robust way to handle multi-state logic by rotating through an array of values.
6
+ * It features advanced navigation controls, allowing for forward and backward movement,
7
+ * direct jumps to the start or end of the sequence, and configurable looping behavior.
8
+ * It is particularly useful for building components such as carousels, steppers,
9
+ * multi-state switches, or any UI element requiring sequential state transitions.
10
+ */
11
+ export declare const useCycle: <T>(params: UseCycleParams<T>) => UseCycleReturnValue<T>;
@@ -0,0 +1,54 @@
1
+ import { useSignal, $ } from "@qwik.dev/core";
2
+ const useCycle = (params) => {
3
+ const { options, defaultOption, loop = true } = params;
4
+ const option = useSignal(() => {
5
+ if (defaultOption !== void 0 && options.includes(defaultOption)) {
6
+ return defaultOption;
7
+ }
8
+ return options[0];
9
+ });
10
+ const next$ = $(() => {
11
+ const currentIndex = options.indexOf(option.value);
12
+ const nextIndex = currentIndex + 1;
13
+ if (loop) {
14
+ option.value = options[nextIndex % options.length];
15
+ } else {
16
+ if (nextIndex < options.length) {
17
+ option.value = options[nextIndex];
18
+ }
19
+ }
20
+ });
21
+ const previous$ = $(() => {
22
+ const currentIndex = options.indexOf(option.value);
23
+ const prevIndex = currentIndex - 1;
24
+ if (loop) {
25
+ option.value = options[(prevIndex + options.length) % options.length];
26
+ } else {
27
+ if (prevIndex >= 0) {
28
+ option.value = options[prevIndex];
29
+ }
30
+ }
31
+ });
32
+ const first$ = $(() => {
33
+ option.value = options[0];
34
+ });
35
+ const last$ = $(() => {
36
+ option.value = options[options.length - 1];
37
+ });
38
+ const set$ = $((value) => {
39
+ if (options.includes(value)) {
40
+ option.value = value;
41
+ }
42
+ });
43
+ return {
44
+ option,
45
+ next$,
46
+ previous$,
47
+ first$,
48
+ last$,
49
+ set$
50
+ };
51
+ };
52
+ export {
53
+ useCycle
54
+ };
@@ -0,0 +1,63 @@
1
+ import type { ReadonlySignal, QRL } from '@qwik.dev/core';
2
+ /**
3
+ * Configuration parameters for the `useCycle` hook.
4
+ */
5
+ export interface UseCycleParams<T> {
6
+ /**
7
+ * A readonly array of values to cycle through.
8
+ * This defines the sequence and the scope of all possible states the hook can manage.
9
+ */
10
+ options: readonly T[];
11
+ /**
12
+ * The initial value to be set when the hook is first initialized.
13
+ * If provided, it must be present in the `options` array.
14
+ * If the provided value is not found within the `options` array,
15
+ * the hook will fall back to the first element of the array.
16
+ *
17
+ * @default options[0]
18
+ */
19
+ defaultOption?: T;
20
+ /**
21
+ * Determines the behavior when navigating past the boundaries of the `options` array.
22
+ * If set to `true`, the sequence will wrap around (e.g., from last to first).
23
+ * If `false`, navigation will stop at the first or last element.
24
+ *
25
+ * @default true
26
+ */
27
+ loop?: boolean;
28
+ }
29
+ /**
30
+ * Represents the object returned by the `useCycle` hook.
31
+ */
32
+ export interface UseCycleReturnValue<T> {
33
+ /**
34
+ * A readonly signal whose value represents the currently active option from the provided array.
35
+ * This signal is read-only, which means its value can only be changed by calling navigation `QRL` functions
36
+ * like `next$`, `previous$`, or `set$`, ensuring predictable state transitions.
37
+ */
38
+ option: ReadonlySignal<T>;
39
+ /**
40
+ * A `QRL` function that advances the value to the next option in the sequence.
41
+ * If `loop` is enabled, it cycles back to the first item upon reaching the end.
42
+ */
43
+ next$: QRL<() => void>;
44
+ /**
45
+ * A `QRL` function that moves the value to the previous option in the sequence.
46
+ * If `loop` is enabled, it cycles back to the last item upon reaching the start.
47
+ */
48
+ previous$: QRL<() => void>;
49
+ /**
50
+ * A `QRL` function that jumps directly to the first item in the `options` array.
51
+ */
52
+ first$: QRL<() => void>;
53
+ /**
54
+ * A `QRL` function that jumps directly to the last item in the `options` array.
55
+ */
56
+ last$: QRL<() => void>;
57
+ /**
58
+ * A `QRL` function that directly sets the `option` to a new value.
59
+ * This function includes a built-in validation check; the value will only be updated
60
+ * if it is present in the original `options` array.
61
+ */
62
+ set$: QRL<(value: T) => void>;
63
+ }
package/lib/index.d.ts CHANGED
@@ -1 +1,4 @@
1
1
  export * from './components';
2
+ export * from './hooks';
3
+ export * from './types';
4
+ export * from './utilities';
@@ -1,6 +1,22 @@
1
1
  import * as index from "./components/alert/parts/index.qwik.mjs";
2
2
  import * as index$1 from "./components/separator/parts/index.qwik.mjs";
3
+ import * as index$2 from "./components/toggle/parts/index.qwik.mjs";
4
+ import { useToggleRootContext } from "./components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.qwik.mjs";
5
+ import { useBoolean } from "./hooks/use-boolean/use-boolean.qwik.mjs";
6
+ import { useControllable } from "./hooks/use-controllable/use-controllable.qwik.mjs";
7
+ import { useCycle } from "./hooks/use-cycle/use-cycle.qwik.mjs";
8
+ import { makeEventPreventable } from "./utilities/make-event-preventable/make-event-preventable.qwik.mjs";
9
+ import { mergeRefs } from "./utilities/merge-refs/merge-refs.qwik.mjs";
10
+ import { mergeStyles } from "./utilities/merge-styles/merge-styles.qwik.mjs";
3
11
  export {
4
12
  index as Alert,
5
- index$1 as Separator
13
+ index$1 as Separator,
14
+ index$2 as Toggle,
15
+ makeEventPreventable,
16
+ mergeRefs,
17
+ mergeStyles,
18
+ useBoolean,
19
+ useControllable,
20
+ useCycle,
21
+ useToggleRootContext
6
22
  };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Represents a Qwik event augmented with Entry UI Qwik's custom prevention logic.
3
+ *
4
+ * This type extends the standard DOM event with additional methods and properties
5
+ * that allow for granular control over internal component handlers within the
6
+ * Entry UI Qwik library.
7
+ */
8
+ export type EntryUIQwikEvent<EV extends Event> = EV & {
9
+ /**
10
+ * Prevents the internal Entry UI Qwik handler from executing for this event.
11
+ * When called, this method sets the `entryUIQwikHandlerPrevented` flag to `true`.
12
+ * Use this when you want to handle the event manually in a consumer-provided
13
+ * handler and prevent the component's default state updates or logic from firing.
14
+ */
15
+ preventEntryUIQwikHandler: () => void;
16
+ /**
17
+ * Indicates whether the internal Entry UI Qwik logic has been prevented for this event.
18
+ * This property is read-only and is typically checked by internal component
19
+ * handlers to determine if they should skip their default execution logic.
20
+ */
21
+ readonly entryUIQwikHandlerPrevented?: boolean;
22
+ };
@@ -0,0 +1 @@
1
+ export type { EntryUIQwikEvent } from './entry-ui-qwik-event.types';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Represents the state of a Qwik event within the Entry UI Qwik system.
3
+ *
4
+ * This type is a specialized version of the event object that includes only the
5
+ * state flag. It is typically used in internal component handlers to check
6
+ * if a previous handler in the execution chain has requested to prevent
7
+ * the default Entry UI Qwik logic.
8
+ */
9
+ export type EntryUIQwikEventState<EV extends Event> = EV & {
10
+ /**
11
+ * Indicates whether the internal Entry UI Qwik logic has been prevented for this event.
12
+ * When `true`, it signals that a consumer or a preceding handler has invoked
13
+ * the prevention mechanism, and the current handler should likely skip
14
+ * its default state updates or behaviors.
15
+ */
16
+ readonly entryUIQwikHandlerPrevented?: boolean;
17
+ };
@@ -0,0 +1 @@
1
+ export type { EntryUIQwikEventState } from './entry-ui-qwik-event-state.types';
@@ -0,0 +1,2 @@
1
+ export * from './entry-ui-qwik-event';
2
+ export * from './entry-ui-qwik-event-state';
@@ -0,0 +1,3 @@
1
+ export * from './make-event-preventable';
2
+ export * from './merge-refs';
3
+ export * from './merge-styles';
@@ -0,0 +1 @@
1
+ export { makeEventPreventable } from './make-event-preventable';
@@ -0,0 +1,4 @@
1
+ import { makeEventPreventable } from "./make-event-preventable.qwik.mjs";
2
+ export {
3
+ makeEventPreventable
4
+ };
@@ -0,0 +1,20 @@
1
+ import type { EntryUIQwikEvent } from '@/types';
2
+ /**
3
+ * Augments a standard event with internal handler prevention capabilities.
4
+ *
5
+ * This utility function transforms a standard event object into an `EntryUIQwikEvent`.
6
+ * It adds a `preventEntryUIQwikHandler` method, allowing developers to flag
7
+ * an event during its execution. This flag can then be checked by subsequent
8
+ * handlers in any Qwik event chain (such as `onClick$`, `onKeyDown$`, or `onInput$`)
9
+ * to determine if the internal component logic should be bypassed.
10
+ *
11
+ * It is particularly useful when a consumer needs to intercept an event and
12
+ * conditionally prevent the component's default behavior or state updates
13
+ * (like toggling a state or closing a dialog) without necessarily stopping
14
+ * native event propagation or other DOM-level behaviors.
15
+ *
16
+ * When `preventEntryUIQwikHandler()` is called:
17
+ * - The internal property `entryUIQwikHandlerPrevented` is set to `true`.
18
+ * - Subsequent handlers in the event array can verify this flag to skip their logic.
19
+ */
20
+ export declare const makeEventPreventable: <EV extends Event>(event: EV) => EntryUIQwikEvent<EV>;
@@ -0,0 +1,10 @@
1
+ const makeEventPreventable = (event) => {
2
+ const entryUIQwikEvent = event;
3
+ entryUIQwikEvent.preventEntryUIQwikHandler = () => {
4
+ entryUIQwikEvent.entryUIQwikHandlerPrevented = true;
5
+ };
6
+ return entryUIQwikEvent;
7
+ };
8
+ export {
9
+ makeEventPreventable
10
+ };
@@ -0,0 +1,2 @@
1
+ export type { PossibleRef } from './merge-refs.types';
2
+ export { mergeRefs } from './merge-refs';
@@ -0,0 +1,4 @@
1
+ import { mergeRefs } from "./merge-refs.qwik.mjs";
2
+ export {
3
+ mergeRefs
4
+ };
@@ -0,0 +1,15 @@
1
+ import type { PossibleRef } from './merge-refs.types';
2
+ /**
3
+ * Combines multiple references into a single callback ref.
4
+ *
5
+ * This utility function allows you to assign a single DOM element to multiple
6
+ * reference handlers (both Qwik Signals and callback functions). It is particularly
7
+ * useful when a component needs to maintain its own internal reference to an element
8
+ * while also forwarding a reference to a consumer via props.
9
+ *
10
+ * When the returned callback is executed, it iterates through all provided refs and:
11
+ * - Updates the `.value` property if the ref is a `Signal`.
12
+ * - Invokes the function if the `ref` is a callback.
13
+ * - Gracefully ignores `undefined` values.
14
+ */
15
+ export declare const mergeRefs: <T extends Element>(refs: PossibleRef<T>[]) => import("@qwik.dev/core").QRL<(node: T) => void>;
@@ -0,0 +1,17 @@
1
+ import { noSerialize, $, isSignal } from "@qwik.dev/core";
2
+ const mergeRefs = (refs) => {
3
+ const _refs = noSerialize(refs);
4
+ return $((node) => {
5
+ _refs?.forEach((ref) => {
6
+ if (!ref) return;
7
+ if (isSignal(ref)) {
8
+ ref.value = node;
9
+ } else if (typeof ref === "function") {
10
+ ref(node);
11
+ }
12
+ });
13
+ });
14
+ };
15
+ export {
16
+ mergeRefs
17
+ };
@@ -0,0 +1,14 @@
1
+ import type { Signal } from '@qwik.dev/core';
2
+ /**
3
+ * Represents the various ways a reference can be assigned to a DOM element in Qwik.
4
+ *
5
+ * This type provides flexibility for handling references, supporting:
6
+ *
7
+ * - `Signal<T | undefined>` or `Signal<Element | undefined>`: The standard Qwik approach using `useSignal`.
8
+ * It allows the element to be reactively tracked within the `.value` property.
9
+ *
10
+ * - `(node: T) => void`: A callback ref (ref-callback) that provides direct access to the DOM node upon mounting.
11
+ *
12
+ * - `undefined`: Designed for optional references. This allows you to pass component props directly into the utility without manual null-checks.
13
+ */
14
+ export type PossibleRef<T> = Signal<Element | undefined> | Signal<T | undefined> | ((node: T) => void) | undefined;
@@ -0,0 +1,2 @@
1
+ export type { PossibleStyle } from './merge-styles.types';
2
+ export { mergeStyles } from './merge-styles';
@@ -0,0 +1,4 @@
1
+ import { mergeStyles } from "./merge-styles.qwik.mjs";
2
+ export {
3
+ mergeStyles
4
+ };
@@ -0,0 +1,13 @@
1
+ import type { PossibleStyle } from './merge-styles.types';
2
+ import type { CSSProperties } from '@qwik.dev/core';
3
+ /**
4
+ * Merges multiple style values into a single, unified style object.
5
+ *
6
+ * This function consolidates a variety of style formats (inline strings, CSS objects,
7
+ * or undefined) into a single `CSSProperties` object. It ensures that all property
8
+ * keys are normalized to camelCase (preserving CSS variables and handling vendor
9
+ * prefixes appropriately) to remain compatible with JavaScript-based styling engines.
10
+ * The merging process follows the CSS cascade principle: styles appearing later in
11
+ * the array will override matching properties from earlier styles.
12
+ */
13
+ export declare const mergeStyles: (styles: PossibleStyle[]) => CSSProperties;
@@ -0,0 +1,7 @@
1
+ import { mergeStyles as mergeStyles$1 } from "@entry-ui/utilities/merge-styles";
2
+ const mergeStyles = (styles) => {
3
+ return mergeStyles$1(styles);
4
+ };
5
+ export {
6
+ mergeStyles
7
+ };
@@ -0,0 +1,15 @@
1
+ import type { CSSProperties } from '@qwik.dev/core';
2
+ /**
3
+ * Represents the accepted formats for style declarations.
4
+ *
5
+ * This type allows for flexibility in how styles are defined, supporting:
6
+ *
7
+ * - `string`: Standard inline CSS strings (e.g., `"color: red; padding: 10px"`).
8
+ *
9
+ * - `CSSProperties`: A structured object of CSS declarations (e.g., `{ color: "red" }`).
10
+ *
11
+ * - `undefined`: Useful for conditional styling where a style might not be present.
12
+ * Since `boolean` is not accepted, use ternary operators or logical OR
13
+ * to ensure a valid type (e.g., `isActive ? "color: red" : undefined`).
14
+ */
15
+ export type PossibleStyle = string | CSSProperties | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entry-ui/qwik",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/ZAHON/entry-ui#readme",
@@ -22,6 +22,37 @@
22
22
  "./separator": {
23
23
  "types": "./lib/components/separator/index.d.ts",
24
24
  "import": "./lib/components/separator/index.qwik.mjs"
25
+ },
26
+ "./toggle": {
27
+ "types": "./lib/components/toggle/index.d.ts",
28
+ "import": "./lib/components/toggle/index.qwik.mjs"
29
+ },
30
+ "./use-boolean": {
31
+ "types": "./lib/hooks/use-boolean/index.d.ts",
32
+ "import": "./lib/hooks/use-boolean/index.qwik.mjs"
33
+ },
34
+ "./use-controllable": {
35
+ "types": "./lib/hooks/use-controllable/index.d.ts",
36
+ "import": "./lib/hooks/use-controllable/index.qwik.mjs"
37
+ },
38
+ "./use-cycle": {
39
+ "types": "./lib/hooks/use-cycle/index.d.ts",
40
+ "import": "./lib/hooks/use-cycle/index.qwik.mjs"
41
+ },
42
+ "./make-event-preventable": {
43
+ "types": "./lib/utilities/make-event-preventable/index.d.ts",
44
+ "import": "./lib/utilities/make-event-preventable/index.qwik.mjs"
45
+ },
46
+ "./merge-refs": {
47
+ "types": "./lib/utilities/merge-refs/index.d.ts",
48
+ "import": "./lib/utilities/merge-refs/index.qwik.mjs"
49
+ },
50
+ "./merge-styles": {
51
+ "types": "./lib/utilities/merge-styles/index.d.ts",
52
+ "import": "./lib/utilities/merge-styles/index.qwik.mjs"
53
+ },
54
+ "./types": {
55
+ "types": "./lib/types/index.d.ts"
25
56
  }
26
57
  },
27
58
  "files": [
@@ -61,7 +92,7 @@
61
92
  "qwik": "qwik"
62
93
  },
63
94
  "dependencies": {
64
- "@entry-ui/utilities": "workspace:*"
95
+ "@entry-ui/utilities": "^0.3.0"
65
96
  },
66
97
  "devDependencies": {
67
98
  "@entry-ui/eslint": "workspace:*",
@@ -75,6 +106,7 @@
75
106
  "jsdom": "^27.4.0",
76
107
  "prettier": "^3.7.4",
77
108
  "typescript": "^5.9.3",
109
+ "typescript-plugin-css-modules": "^5.2.0",
78
110
  "undici": "^7.18.2",
79
111
  "vite": "^7.3.1",
80
112
  "vite-tsconfig-paths": "^6.0.4",