@entry-ui/qwik 0.7.0 → 0.8.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/components/copy-button/contexts/copy-button-root-context/copy-button-root-context.d.ts +11 -0
- package/lib/components/copy-button/contexts/copy-button-root-context/copy-button-root-context.qwik.mjs +10 -0
- package/lib/components/copy-button/contexts/copy-button-root-context/copy-button-root-context.types.d.ts +24 -0
- package/lib/components/copy-button/contexts/copy-button-root-context/index.d.ts +2 -0
- package/lib/components/copy-button/contexts/index.d.ts +1 -0
- package/lib/components/copy-button/hooks/index.d.ts +1 -0
- package/lib/components/copy-button/hooks/use-copy-button-root-context/index.d.ts +2 -0
- package/lib/components/copy-button/hooks/use-copy-button-root-context/use-copy-button-root-context.d.ts +7 -0
- package/lib/components/copy-button/hooks/use-copy-button-root-context/use-copy-button-root-context.qwik.mjs +13 -0
- package/lib/components/copy-button/hooks/use-copy-button-root-context/use-copy-button-root-context.types.d.ts +24 -0
- package/lib/components/copy-button/index.d.ts +2 -0
- package/lib/components/copy-button/index.qwik.mjs +6 -0
- package/lib/components/copy-button/parts/copy-button-indicator/copy-button-indicator.d.ts +9 -0
- package/lib/components/copy-button/parts/copy-button-indicator/copy-button-indicator.qwik.mjs +29 -0
- package/lib/components/copy-button/parts/copy-button-indicator/copy-button-indicator.types.d.ts +15 -0
- package/lib/components/copy-button/parts/copy-button-indicator/index.d.ts +2 -0
- package/lib/components/copy-button/parts/copy-button-root/copy-button-root.d.ts +7 -0
- package/lib/components/copy-button/parts/copy-button-root/copy-button-root.qwik.mjs +47 -0
- package/lib/components/copy-button/parts/copy-button-root/copy-button-root.types.d.ts +52 -0
- package/lib/components/copy-button/parts/copy-button-root/index.d.ts +2 -0
- package/lib/components/copy-button/parts/index.d.ts +4 -0
- package/lib/components/copy-button/parts/index.qwik.mjs +6 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/use-clipboard/index.d.ts +2 -0
- package/lib/hooks/use-clipboard/index.qwik.mjs +4 -0
- package/lib/hooks/use-clipboard/use-clipboard.d.ts +19 -0
- package/lib/hooks/use-clipboard/use-clipboard.qwik.mjs +87 -0
- package/lib/hooks/use-clipboard/use-clipboard.types.d.ts +58 -0
- package/lib/index.qwik.mjs +10 -4
- package/package.json +10 -2
package/lib/components/copy-button/contexts/copy-button-root-context/copy-button-root-context.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CopyButtonRootContextValue } from './copy-button-root-context.types';
|
|
2
|
+
/**
|
|
3
|
+
* Provides the context for the `CopyButton.Root` component, allowing descendant
|
|
4
|
+
* components to access readonly signals without prop drilling.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CopyButtonRootContext: import("@qwik.dev/core").ContextId<CopyButtonRootContextValue>;
|
|
7
|
+
/**
|
|
8
|
+
* A hook that provides access to the `CopyButton.Root` component's internal state.
|
|
9
|
+
* It exposes readonly signals to interact with the component's state,
|
|
10
|
+
*/
|
|
11
|
+
export declare const useCopyButtonRootContext: () => CopyButtonRootContextValue;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContextId, useContext } from "@qwik.dev/core";
|
|
2
|
+
const CopyButtonRootContext = createContextId("entry-ui-qwik-copy-button-root-context");
|
|
3
|
+
const useCopyButtonRootContext = () => {
|
|
4
|
+
const context = useContext(CopyButtonRootContext);
|
|
5
|
+
return context;
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
CopyButtonRootContext,
|
|
9
|
+
useCopyButtonRootContext
|
|
10
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReadonlySignal } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* The value provided by the `CopyButtonRootContext` context.
|
|
4
|
+
* Contains the readonly signals shared with descendant components.
|
|
5
|
+
*/
|
|
6
|
+
export interface CopyButtonRootContextValue {
|
|
7
|
+
/**
|
|
8
|
+
* A readonly signal whose value indicates whether the text was successfully copied.
|
|
9
|
+
* It is `true` immediately after a successful copy operation and reverts to `false`
|
|
10
|
+
* after the specified timeout.
|
|
11
|
+
*/
|
|
12
|
+
copied: ReadonlySignal<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* A readonly signal representing the current error state of the clipboard operation.
|
|
15
|
+
* It returns `"NOT_SUPPORTED"` if the API is unavailable, `"COPY_FAILED"` if the
|
|
16
|
+
* operation was rejected, or `null` if the last operation was successful.
|
|
17
|
+
*/
|
|
18
|
+
error: ReadonlySignal<'NOT_SUPPORTED' | 'COPY_FAILED' | null>;
|
|
19
|
+
/**
|
|
20
|
+
* A readonly signal whose value indicates the copy button's current disabled state.
|
|
21
|
+
* It is `true` when the button is prevented from user interaction.
|
|
22
|
+
*/
|
|
23
|
+
disabled: ReadonlySignal<boolean>;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './copy-button-root-context';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-copy-button-root-context';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UseCopyButtonRootContextReturnValue } from './use-copy-button-root-context.types';
|
|
2
|
+
/**
|
|
3
|
+
* A hook that provides access to the `CopyButton.Root` component's internal state.
|
|
4
|
+
* It exposes readonly signals to interact with the copy button's state,
|
|
5
|
+
* allowing descendant components to react to its `copied`, `error`, or `disabled` state.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useCopyButtonRootContext: () => UseCopyButtonRootContextReturnValue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useContext } from "@qwik.dev/core";
|
|
2
|
+
import { CopyButtonRootContext } from "../../contexts/copy-button-root-context/copy-button-root-context.qwik.mjs";
|
|
3
|
+
const useCopyButtonRootContext = () => {
|
|
4
|
+
const { copied, error, disabled } = useContext(CopyButtonRootContext);
|
|
5
|
+
return {
|
|
6
|
+
copied,
|
|
7
|
+
error,
|
|
8
|
+
disabled
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
useCopyButtonRootContext
|
|
13
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReadonlySignal } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* The value returned by the `useCopyButtonRootContext` hook.
|
|
4
|
+
* Provides access to the copy button's readonly signals for descendant components.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseCopyButtonRootContextReturnValue {
|
|
7
|
+
/**
|
|
8
|
+
* A readonly signal whose value indicates whether the text was successfully copied.
|
|
9
|
+
* It is `true` immediately after a successful copy operation and reverts to `false`
|
|
10
|
+
* after the specified timeout.
|
|
11
|
+
*/
|
|
12
|
+
copied: ReadonlySignal<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* A readonly signal representing the current error state of the clipboard operation.
|
|
15
|
+
* It returns `"NOT_SUPPORTED"` if the API is unavailable, `"COPY_FAILED"` if the
|
|
16
|
+
* operation was rejected, or `null` if the last operation was successful.
|
|
17
|
+
*/
|
|
18
|
+
error: ReadonlySignal<'NOT_SUPPORTED' | 'COPY_FAILED' | null>;
|
|
19
|
+
/**
|
|
20
|
+
* A readonly signal whose value indicates the copy button's current disabled state.
|
|
21
|
+
* It is `true` when the button is prevented from user interaction.
|
|
22
|
+
*/
|
|
23
|
+
disabled: ReadonlySignal<boolean>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CopyButtonIndicatorProps } from './copy-button-indicator.types';
|
|
2
|
+
/**
|
|
3
|
+
* An optional visual indicator that reflects the copy button's state.
|
|
4
|
+
* It typically displays an icon or other visual cue to show
|
|
5
|
+
* whether the content has been successfully copied or if an error occurred.
|
|
6
|
+
*
|
|
7
|
+
* Renders a `<span>` element.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CopyButtonIndicator: import("@qwik.dev/core").Component<CopyButtonIndicatorProps>;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { useCopyButtonRootContext } from "../../contexts/copy-button-root-context/copy-button-root-context.qwik.mjs";
|
|
6
|
+
const CopyButtonIndicator = component$((props) => {
|
|
7
|
+
const { as = "span", style, ...others } = props;
|
|
8
|
+
const { copied, error, disabled } = useCopyButtonRootContext();
|
|
9
|
+
return /* @__PURE__ */ jsx(Primitive.span, {
|
|
10
|
+
as,
|
|
11
|
+
"aria-hidden": "true",
|
|
12
|
+
"data-entry-ui-qwik-copy-button-indicator": "",
|
|
13
|
+
"data-copied": copied.value ? "" : void 0,
|
|
14
|
+
"data-error": error.value ? "" : void 0,
|
|
15
|
+
"data-disabled": disabled.value ? "" : void 0,
|
|
16
|
+
style: mergeStyles([
|
|
17
|
+
{
|
|
18
|
+
pointerEvents: "none",
|
|
19
|
+
userSelect: "none"
|
|
20
|
+
},
|
|
21
|
+
style
|
|
22
|
+
]),
|
|
23
|
+
...others,
|
|
24
|
+
children: /* @__PURE__ */ jsx(Slot, {})
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
export {
|
|
28
|
+
CopyButtonIndicator
|
|
29
|
+
};
|
package/lib/components/copy-button/parts/copy-button-indicator/copy-button-indicator.types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PropsOf, Component } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the `CopyButton.Indicator` component.
|
|
4
|
+
* Extends the standard HTML attributes for a `<span>` element.
|
|
5
|
+
*/
|
|
6
|
+
export interface CopyButtonIndicatorProps 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,47 @@
|
|
|
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 { useClipboard } from "../../../../hooks/use-clipboard/use-clipboard.qwik.mjs";
|
|
5
|
+
import { Primitive } from "../../../../_internal/components/primitive/primitive.qwik.mjs";
|
|
6
|
+
import { CopyButtonRootContext } from "../../contexts/copy-button-root-context/copy-button-root-context.qwik.mjs";
|
|
7
|
+
const CopyButtonRoot = component$((props) => {
|
|
8
|
+
const { as = "button", defaultText, text: _text, onStatusChange$, timeoutMs = 3e3, disabled: _disabled = false, onClick$, ...others } = props;
|
|
9
|
+
const { state: text } = useControllable({
|
|
10
|
+
defaultValue: defaultText ?? "",
|
|
11
|
+
controlledSignal: _text
|
|
12
|
+
});
|
|
13
|
+
const { copied, error, copy$ } = useClipboard({
|
|
14
|
+
timeoutMs,
|
|
15
|
+
onStatusChange$
|
|
16
|
+
});
|
|
17
|
+
const disabled = useComputed$(() => _disabled);
|
|
18
|
+
const handleClick$ = $(async (event) => {
|
|
19
|
+
const entryUIQwikEvent = event;
|
|
20
|
+
if (!entryUIQwikEvent.entryUIQwikHandlerPrevented && !disabled.value && !copied.value) {
|
|
21
|
+
await copy$(text.value);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
useContextProvider(CopyButtonRootContext, {
|
|
25
|
+
copied,
|
|
26
|
+
error,
|
|
27
|
+
disabled
|
|
28
|
+
});
|
|
29
|
+
return /* @__PURE__ */ jsx(Primitive.button, {
|
|
30
|
+
as,
|
|
31
|
+
type: "button",
|
|
32
|
+
disabled: disabled.value,
|
|
33
|
+
"data-entry-ui-qwik-copy-button-root": "",
|
|
34
|
+
"data-copied": copied.value ? "" : void 0,
|
|
35
|
+
"data-error": error.value ? "" : void 0,
|
|
36
|
+
"data-disabled": disabled.value ? "" : void 0,
|
|
37
|
+
onClick$: [
|
|
38
|
+
onClick$,
|
|
39
|
+
handleClick$
|
|
40
|
+
],
|
|
41
|
+
...others,
|
|
42
|
+
children: /* @__PURE__ */ jsx(Slot, {})
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
export {
|
|
46
|
+
CopyButtonRoot
|
|
47
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { PropsOf, Component, Signal, QRL } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the `CopyButton.Root` component.
|
|
4
|
+
* Extends the standard HTML attributes for a `<button>` element.
|
|
5
|
+
*/
|
|
6
|
+
export interface CopyButtonRootProps 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 text value to be copied when the component is initially rendered.
|
|
17
|
+
* Use when you do not need to control the text state.
|
|
18
|
+
*
|
|
19
|
+
* @default undefined
|
|
20
|
+
*/
|
|
21
|
+
defaultText?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The controlled text value to be copied.
|
|
24
|
+
*
|
|
25
|
+
* @default undefined
|
|
26
|
+
*/
|
|
27
|
+
text?: Signal<string>;
|
|
28
|
+
/**
|
|
29
|
+
* An optional `QRL` callback function that is invoked whenever the clipboard status changes.
|
|
30
|
+
* It provides a detailed object reflecting whether the text was successfully copied
|
|
31
|
+
* or if an error occurred. This callback is also triggered when the status
|
|
32
|
+
* is automatically cleared after the `timeoutMs` duration has elapsed.
|
|
33
|
+
*
|
|
34
|
+
* @default undefined
|
|
35
|
+
*/
|
|
36
|
+
onStatusChange$?: QRL<(details: {
|
|
37
|
+
copied: boolean;
|
|
38
|
+
error: 'NOT_SUPPORTED' | 'COPY_FAILED' | null;
|
|
39
|
+
}) => void>;
|
|
40
|
+
/**
|
|
41
|
+
* The duration in milliseconds before the copied state automatically resets to `false`.
|
|
42
|
+
*
|
|
43
|
+
* @default 3000
|
|
44
|
+
*/
|
|
45
|
+
timeoutMs?: number;
|
|
46
|
+
/**
|
|
47
|
+
* When `true`, prevents the user from interacting with the copy button.
|
|
48
|
+
*
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { CopyButtonRootProps as RootProps } from './copy-button-root';
|
|
2
|
+
export type { CopyButtonIndicatorProps as IndicatorProps } from './copy-button-indicator';
|
|
3
|
+
export { CopyButtonRoot as Root } from './copy-button-root';
|
|
4
|
+
export { CopyButtonIndicator as Indicator } from './copy-button-indicator';
|
package/lib/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UseClipboardParams, UseClipboardReturnValue } from './use-clipboard.types';
|
|
2
|
+
/**
|
|
3
|
+
* A hook that provides an interface for interacting with the system clipboard.
|
|
4
|
+
*
|
|
5
|
+
* This hook encapsulates the complexity of the asynchronous Clipboard API, exposing
|
|
6
|
+
* its state through readonly signals for predictable data flow. It manages both
|
|
7
|
+
* success and error states, ensuring that UI feedback remains consistent across
|
|
8
|
+
* different browser environments.
|
|
9
|
+
*
|
|
10
|
+
* It features a built-in auto-reset mechanism via the `timeoutMs` parameter,
|
|
11
|
+
* which automatically clears the `copied` and `error` states after a specified duration.
|
|
12
|
+
* An optional `onStatusChange$` callback allows reacting to changes in the
|
|
13
|
+
* operation status from outside the hook.
|
|
14
|
+
*
|
|
15
|
+
* To ensure stability and security, the hook includes development-time checks
|
|
16
|
+
* to prevent server-side execution, as clipboard operations strictly require
|
|
17
|
+
* a browser environment and typically a user gesture.
|
|
18
|
+
*/
|
|
19
|
+
export declare const useClipboard: (params?: UseClipboardParams) => UseClipboardReturnValue;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useSignal, $ } from "@qwik.dev/core";
|
|
2
|
+
import { copyToClipboard } from "@entry-ui/utilities/copy-to-clipboard";
|
|
3
|
+
import { fail } from "../../_internal/utilities/fail/fail.qwik.mjs";
|
|
4
|
+
import { error } from "../../_internal/utilities/error/error.qwik.mjs";
|
|
5
|
+
import { isDev, isServer } from "@qwik.dev/core/build";
|
|
6
|
+
const useClipboard = (params = {}) => {
|
|
7
|
+
const { timeoutMs = 3e3, onStatusChange$ } = params;
|
|
8
|
+
const error$1 = useSignal(null);
|
|
9
|
+
const copied = useSignal(false);
|
|
10
|
+
const copyTimeout = useSignal(-1);
|
|
11
|
+
const copy$ = $(async (value) => {
|
|
12
|
+
if (isDev && isServer) {
|
|
13
|
+
fail([
|
|
14
|
+
`The 'copy$' QRL function from the 'useClipboard' hook cannot be called during server-side rendering (SSR).`,
|
|
15
|
+
`Clipboard API is only available in the browser.`,
|
|
16
|
+
`Ensure it's only invoked in the browser environment.`
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
const win = document.defaultView || window;
|
|
20
|
+
await copyToClipboard({
|
|
21
|
+
value,
|
|
22
|
+
onSuccess: () => {
|
|
23
|
+
win.clearTimeout(copyTimeout.value);
|
|
24
|
+
copyTimeout.value = win.setTimeout(() => {
|
|
25
|
+
copied.value = false;
|
|
26
|
+
error$1.value = null;
|
|
27
|
+
onStatusChange$?.({
|
|
28
|
+
copied: false,
|
|
29
|
+
error: null
|
|
30
|
+
});
|
|
31
|
+
}, timeoutMs);
|
|
32
|
+
copied.value = true;
|
|
33
|
+
error$1.value = null;
|
|
34
|
+
onStatusChange$?.({
|
|
35
|
+
copied: true,
|
|
36
|
+
error: null
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
onError: (err) => {
|
|
40
|
+
const { type, message } = err;
|
|
41
|
+
copied.value = false;
|
|
42
|
+
error$1.value = type;
|
|
43
|
+
onStatusChange$?.({
|
|
44
|
+
copied: false,
|
|
45
|
+
error: type
|
|
46
|
+
});
|
|
47
|
+
if (isDev) {
|
|
48
|
+
if (type === "NOT_SUPPORTED") {
|
|
49
|
+
error([
|
|
50
|
+
`An error occurred during the 'copy$' QRL function execution in 'useClipboard' hook.`,
|
|
51
|
+
`Clipboard API is not supported in this browser.`,
|
|
52
|
+
`Consider using a modern browser with Clipboard API support.`
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
if (type === "COPY_FAILED") {
|
|
56
|
+
error([
|
|
57
|
+
`An error occurred during the 'copy$' QRL function execution in 'useClipboard' hook.`,
|
|
58
|
+
`The copy operation failed.`,
|
|
59
|
+
...message ? [
|
|
60
|
+
`Check clipboard permissions: ${message}`
|
|
61
|
+
] : []
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
const reset$ = $(() => {
|
|
69
|
+
copied.value = false;
|
|
70
|
+
error$1.value = null;
|
|
71
|
+
const win = document.defaultView || window;
|
|
72
|
+
win.clearTimeout(copyTimeout.value);
|
|
73
|
+
onStatusChange$?.({
|
|
74
|
+
copied: false,
|
|
75
|
+
error: null
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
copied,
|
|
80
|
+
error: error$1,
|
|
81
|
+
copy$,
|
|
82
|
+
reset$
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export {
|
|
86
|
+
useClipboard
|
|
87
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ReadonlySignal, QRL } from '@qwik.dev/core';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration parameters for the `useClipboard` hook.
|
|
4
|
+
*/
|
|
5
|
+
export interface UseClipboardParams {
|
|
6
|
+
/**
|
|
7
|
+
* The duration in milliseconds before the `copied` signal automatically reverts
|
|
8
|
+
* to `false` and the `error` state is cleared after a successful copy operation.
|
|
9
|
+
*
|
|
10
|
+
* @default 3000
|
|
11
|
+
*/
|
|
12
|
+
timeoutMs?: number;
|
|
13
|
+
/**
|
|
14
|
+
* An optional `QRL` callback invoked whenever the clipboard operation status changes.
|
|
15
|
+
* It provides a detailed object containing the current `copied` state and any
|
|
16
|
+
* associated `error`. This callback is triggered upon a successful copy,
|
|
17
|
+
* when an error occurs, or when the state is reset (either automatically
|
|
18
|
+
* after `timeoutMs` or manually via `reset$`).
|
|
19
|
+
*
|
|
20
|
+
* @default undefined
|
|
21
|
+
*/
|
|
22
|
+
onStatusChange$?: QRL<(details: {
|
|
23
|
+
copied: boolean;
|
|
24
|
+
error: 'NOT_SUPPORTED' | 'COPY_FAILED' | null;
|
|
25
|
+
}) => void>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Represents the object returned by the `useClipboard` hook.
|
|
29
|
+
*/
|
|
30
|
+
export interface UseClipboardReturnValue {
|
|
31
|
+
/**
|
|
32
|
+
* A readonly signal that indicates whether a text string was successfully copied.
|
|
33
|
+
* This value is set to `true` immediately after a successful copy operation
|
|
34
|
+
* and automatically reverts to `false` after the specified `timeoutMs` duration
|
|
35
|
+
* has elapsed or if the state is manually reset.
|
|
36
|
+
*/
|
|
37
|
+
copied: ReadonlySignal<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* A readonly signal representing the current error state of the clipboard operation.
|
|
40
|
+
* Returns `"NOT_SUPPORTED"` if the Clipboard API is unavailable in the environment,
|
|
41
|
+
* `"COPY_FAILED"` if the operation was rejected (e.g., due to lack of permissions),
|
|
42
|
+
* or `null` if the last operation was successful or has been reset.
|
|
43
|
+
*/
|
|
44
|
+
error: ReadonlySignal<'NOT_SUPPORTED' | 'COPY_FAILED' | null>;
|
|
45
|
+
/**
|
|
46
|
+
* A `QRL` function that asynchronously transfers a provided string to the system clipboard.
|
|
47
|
+
* This function must be invoked in a browser environment, typically as a result
|
|
48
|
+
* of a user gesture (like a click), and updates the `copied` and `error` signals
|
|
49
|
+
* based on the outcome of the operation.
|
|
50
|
+
*/
|
|
51
|
+
copy$: QRL<(value: string) => Promise<void>>;
|
|
52
|
+
/**
|
|
53
|
+
* A `QRL` function that restores the hook's state to its initial values.
|
|
54
|
+
* It sets `copied` to `false`, clears any active `error`, and cancels any
|
|
55
|
+
* pending timeout scheduled to reset the success state.
|
|
56
|
+
*/
|
|
57
|
+
reset$: QRL<() => void>;
|
|
58
|
+
}
|
package/lib/index.qwik.mjs
CHANGED
|
@@ -6,10 +6,13 @@ import * as index$1 from "./components/alert/parts/index.qwik.mjs";
|
|
|
6
6
|
import * as index$2 from "./components/collapsible/parts/index.qwik.mjs";
|
|
7
7
|
import { useCollapsibleRootContext } from "./components/collapsible/hooks/use-collapsible-root-context/use-collapsible-root-context.qwik.mjs";
|
|
8
8
|
import { useCollapsibleTriggerContext } from "./components/collapsible/hooks/use-collapsible-trigger-context/use-collapsible-trigger-context.qwik.mjs";
|
|
9
|
-
import * as index$3 from "./components/
|
|
10
|
-
import
|
|
9
|
+
import * as index$3 from "./components/copy-button/parts/index.qwik.mjs";
|
|
10
|
+
import { useCopyButtonRootContext } from "./components/copy-button/hooks/use-copy-button-root-context/use-copy-button-root-context.qwik.mjs";
|
|
11
|
+
import * as index$4 from "./components/separator/parts/index.qwik.mjs";
|
|
12
|
+
import * as index$5 from "./components/toggle/parts/index.qwik.mjs";
|
|
11
13
|
import { useToggleRootContext } from "./components/toggle/hooks/use-toggle-root-context/use-toggle-root-context.qwik.mjs";
|
|
12
14
|
import { useBoolean } from "./hooks/use-boolean/use-boolean.qwik.mjs";
|
|
15
|
+
import { useClipboard } from "./hooks/use-clipboard/use-clipboard.qwik.mjs";
|
|
13
16
|
import { useControllable } from "./hooks/use-controllable/use-controllable.qwik.mjs";
|
|
14
17
|
import { useCounter } from "./hooks/use-counter/use-counter.qwik.mjs";
|
|
15
18
|
import { useCycle } from "./hooks/use-cycle/use-cycle.qwik.mjs";
|
|
@@ -21,8 +24,9 @@ export {
|
|
|
21
24
|
index as Accordion,
|
|
22
25
|
index$1 as Alert,
|
|
23
26
|
index$2 as Collapsible,
|
|
24
|
-
index$3 as
|
|
25
|
-
index$4 as
|
|
27
|
+
index$3 as CopyButton,
|
|
28
|
+
index$4 as Separator,
|
|
29
|
+
index$5 as Toggle,
|
|
26
30
|
makeEventPreventable,
|
|
27
31
|
mergeRefs,
|
|
28
32
|
mergeStyles,
|
|
@@ -30,9 +34,11 @@ export {
|
|
|
30
34
|
useAccordionItemTriggerContext,
|
|
31
35
|
useAccordionRootContext,
|
|
32
36
|
useBoolean,
|
|
37
|
+
useClipboard,
|
|
33
38
|
useCollapsibleRootContext,
|
|
34
39
|
useCollapsibleTriggerContext,
|
|
35
40
|
useControllable,
|
|
41
|
+
useCopyButtonRootContext,
|
|
36
42
|
useCounter,
|
|
37
43
|
useCycle,
|
|
38
44
|
useLifecycle,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entry-ui/qwik",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/ZAHON/entry-ui#readme",
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
"types": "./lib/components/collapsible/index.d.ts",
|
|
28
28
|
"import": "./lib/components/collapsible/index.qwik.mjs"
|
|
29
29
|
},
|
|
30
|
+
"./copy-button": {
|
|
31
|
+
"types": "./lib/components/copy-button/index.d.ts",
|
|
32
|
+
"import": "./lib/components/copy-button/index.qwik.mjs"
|
|
33
|
+
},
|
|
30
34
|
"./separator": {
|
|
31
35
|
"types": "./lib/components/separator/index.d.ts",
|
|
32
36
|
"import": "./lib/components/separator/index.qwik.mjs"
|
|
@@ -39,6 +43,10 @@
|
|
|
39
43
|
"types": "./lib/hooks/use-boolean/index.d.ts",
|
|
40
44
|
"import": "./lib/hooks/use-boolean/index.qwik.mjs"
|
|
41
45
|
},
|
|
46
|
+
"./use-clipboard": {
|
|
47
|
+
"types": "./lib/hooks/use-clipboard/index.d.ts",
|
|
48
|
+
"import": "./lib/hooks/use-clipboard/index.qwik.mjs"
|
|
49
|
+
},
|
|
42
50
|
"./use-controllable": {
|
|
43
51
|
"types": "./lib/hooks/use-controllable/index.d.ts",
|
|
44
52
|
"import": "./lib/hooks/use-controllable/index.qwik.mjs"
|
|
@@ -108,7 +116,7 @@
|
|
|
108
116
|
"qwik": "qwik"
|
|
109
117
|
},
|
|
110
118
|
"dependencies": {
|
|
111
|
-
"@entry-ui/utilities": "^0.
|
|
119
|
+
"@entry-ui/utilities": "^0.7.0"
|
|
112
120
|
},
|
|
113
121
|
"devDependencies": {
|
|
114
122
|
"@entry-ui/eslint": "workspace:*",
|