@entry-ui/qwik 0.4.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 (33) hide show
  1. package/lib/components/index.d.ts +1 -0
  2. package/lib/components/toggle/contexts/index.d.ts +1 -0
  3. package/lib/components/toggle/contexts/toggle-root-context/index.d.ts +2 -0
  4. package/lib/components/toggle/contexts/toggle-root-context/toggle-root-context.d.ts +6 -0
  5. package/lib/components/toggle/contexts/toggle-root-context/toggle-root-context.qwik.mjs +5 -0
  6. package/lib/components/toggle/contexts/toggle-root-context/toggle-root-context.types.d.ts +22 -0
  7. package/lib/components/toggle/hooks/index.d.ts +1 -0
  8. package/lib/components/toggle/hooks/use-toggle-root-context/index.d.ts +2 -0
  9. package/lib/components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.d.ts +7 -0
  10. package/lib/components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.qwik.mjs +13 -0
  11. package/lib/components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.types.d.ts +22 -0
  12. package/lib/components/toggle/index.d.ts +2 -0
  13. package/lib/components/toggle/index.qwik.mjs +6 -0
  14. package/lib/components/toggle/parts/index.d.ts +2 -0
  15. package/lib/components/toggle/parts/index.qwik.mjs +4 -0
  16. package/lib/components/toggle/parts/toggle-root/index.d.ts +2 -0
  17. package/lib/components/toggle/parts/toggle-root/toggle-root.d.ts +7 -0
  18. package/lib/components/toggle/parts/toggle-root/toggle-root.qwik.mjs +43 -0
  19. package/lib/components/toggle/parts/toggle-root/toggle-root.types.d.ts +41 -0
  20. package/lib/index.d.ts +1 -0
  21. package/lib/index.qwik.mjs +7 -1
  22. package/lib/types/entry-ui-qwik-event/entry-ui-qwik-event.types.d.ts +22 -0
  23. package/lib/types/entry-ui-qwik-event/index.d.ts +1 -0
  24. package/lib/types/entry-ui-qwik-event-state/entry-ui-qwik-event-state.types.d.ts +17 -0
  25. package/lib/types/entry-ui-qwik-event-state/index.d.ts +1 -0
  26. package/lib/types/index.d.ts +2 -0
  27. package/lib/utilities/index.d.ts +1 -0
  28. package/lib/utilities/make-event-preventable/index.d.ts +1 -0
  29. package/lib/utilities/make-event-preventable/index.qwik.mjs +4 -0
  30. package/lib/utilities/make-event-preventable/make-event-preventable.d.ts +20 -0
  31. package/lib/utilities/make-event-preventable/make-event-preventable.qwik.mjs +10 -0
  32. package/lib/utilities/merge-styles/merge-styles.types.d.ts +1 -1
  33. package/package.json +14 -2
@@ -1,2 +1,3 @@
1
1
  export * from './alert';
2
2
  export * from './separator';
3
+ export * from './toggle';
@@ -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
+ }
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './components';
2
2
  export * from './hooks';
3
+ export * from './types';
3
4
  export * from './utilities';
@@ -1,16 +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";
3
5
  import { useBoolean } from "./hooks/use-boolean/use-boolean.qwik.mjs";
4
6
  import { useControllable } from "./hooks/use-controllable/use-controllable.qwik.mjs";
5
7
  import { useCycle } from "./hooks/use-cycle/use-cycle.qwik.mjs";
8
+ import { makeEventPreventable } from "./utilities/make-event-preventable/make-event-preventable.qwik.mjs";
6
9
  import { mergeRefs } from "./utilities/merge-refs/merge-refs.qwik.mjs";
7
10
  import { mergeStyles } from "./utilities/merge-styles/merge-styles.qwik.mjs";
8
11
  export {
9
12
  index as Alert,
10
13
  index$1 as Separator,
14
+ index$2 as Toggle,
15
+ makeEventPreventable,
11
16
  mergeRefs,
12
17
  mergeStyles,
13
18
  useBoolean,
14
19
  useControllable,
15
- useCycle
20
+ useCycle,
21
+ useToggleRootContext
16
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';
@@ -1,2 +1,3 @@
1
+ export * from './make-event-preventable';
1
2
  export * from './merge-refs';
2
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
+ };
@@ -6,7 +6,7 @@ import type { CSSProperties } from '@qwik.dev/core';
6
6
  *
7
7
  * - `string`: Standard inline CSS strings (e.g., `"color: red; padding: 10px"`).
8
8
  *
9
- * - `CSSProperties`: A structured object of CSS declarations (e.g., `{ color: 'red' }`).
9
+ * - `CSSProperties`: A structured object of CSS declarations (e.g., `{ color: "red" }`).
10
10
  *
11
11
  * - `undefined`: Useful for conditional styling where a style might not be present.
12
12
  * Since `boolean` is not accepted, use ternary operators or logical OR
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entry-ui/qwik",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/ZAHON/entry-ui#readme",
@@ -23,6 +23,10 @@
23
23
  "types": "./lib/components/separator/index.d.ts",
24
24
  "import": "./lib/components/separator/index.qwik.mjs"
25
25
  },
26
+ "./toggle": {
27
+ "types": "./lib/components/toggle/index.d.ts",
28
+ "import": "./lib/components/toggle/index.qwik.mjs"
29
+ },
26
30
  "./use-boolean": {
27
31
  "types": "./lib/hooks/use-boolean/index.d.ts",
28
32
  "import": "./lib/hooks/use-boolean/index.qwik.mjs"
@@ -35,6 +39,10 @@
35
39
  "types": "./lib/hooks/use-cycle/index.d.ts",
36
40
  "import": "./lib/hooks/use-cycle/index.qwik.mjs"
37
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
+ },
38
46
  "./merge-refs": {
39
47
  "types": "./lib/utilities/merge-refs/index.d.ts",
40
48
  "import": "./lib/utilities/merge-refs/index.qwik.mjs"
@@ -42,6 +50,9 @@
42
50
  "./merge-styles": {
43
51
  "types": "./lib/utilities/merge-styles/index.d.ts",
44
52
  "import": "./lib/utilities/merge-styles/index.qwik.mjs"
53
+ },
54
+ "./types": {
55
+ "types": "./lib/types/index.d.ts"
45
56
  }
46
57
  },
47
58
  "files": [
@@ -81,7 +92,7 @@
81
92
  "qwik": "qwik"
82
93
  },
83
94
  "dependencies": {
84
- "@entry-ui/utilities": "^0.2.0"
95
+ "@entry-ui/utilities": "^0.3.0"
85
96
  },
86
97
  "devDependencies": {
87
98
  "@entry-ui/eslint": "workspace:*",
@@ -95,6 +106,7 @@
95
106
  "jsdom": "^27.4.0",
96
107
  "prettier": "^3.7.4",
97
108
  "typescript": "^5.9.3",
109
+ "typescript-plugin-css-modules": "^5.2.0",
98
110
  "undici": "^7.18.2",
99
111
  "vite": "^7.3.1",
100
112
  "vite-tsconfig-paths": "^6.0.4",