@box/copy-input 1.39.8 → 1.39.10
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/dist/esm/lib/copy-input.js +76 -73
- package/dist/esm/lib/messages.js +1 -1
- package/dist/esm/lib/utils.js +24 -16
- package/dist/styles/copy-input.css +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/lib/copy-input.d.ts +29 -1
- package/dist/types/lib/messages.d.ts +2 -1
- package/dist/types/lib/stories/shared.d.ts +3 -0
- package/dist/types/lib/utils.d.ts +9 -4
- package/package.json +6 -6
- package/dist/types/lib/types.d.ts +0 -20
|
@@ -1,96 +1,99 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { jsxs as h, jsx as
|
|
8
|
-
import '../../styles/copy-input.css';const A = "
|
|
9
|
-
|
|
1
|
+
import i from "clsx";
|
|
2
|
+
import { forwardRef as k, useCallback as _ } from "react";
|
|
3
|
+
import { useIntl as F } from "react-intl";
|
|
4
|
+
import { useUniqueId as y, BaseTextInput as M, Button as O, InlineError as z, Text as H } from "@box/blueprint-web";
|
|
5
|
+
import { useCopyToClipboard as U } from "./utils.js";
|
|
6
|
+
import f from "./messages.js";
|
|
7
|
+
import { jsxs as h, jsx as a } from "react/jsx-runtime";
|
|
8
|
+
import '../../styles/copy-input.css';const A = "_container_17qpw_1", G = "_hasError_17qpw_6", J = "_copyInput_17qpw_16", K = "_input_17qpw_20", P = "_button_17qpw_28", Q = "_isCopied_17qpw_45", V = "_error_17qpw_66", W = "_subtext_17qpw_67", t = {
|
|
9
|
+
container: A,
|
|
10
10
|
hasError: G,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
11
|
+
copyInput: J,
|
|
12
|
+
input: K,
|
|
13
|
+
button: P,
|
|
14
|
+
isCopied: Q,
|
|
15
|
+
error: V,
|
|
16
|
+
subtext: W
|
|
17
|
+
}, X = /* @__PURE__ */ k((I, x) => {
|
|
18
18
|
const {
|
|
19
|
-
ariaLive:
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
ariaLive: C,
|
|
20
|
+
"aria-describedby": g,
|
|
21
|
+
"data-target-id": q,
|
|
22
|
+
disabled: r,
|
|
23
|
+
error: s,
|
|
24
|
+
hideLabel: w,
|
|
25
|
+
id: Y,
|
|
25
26
|
label: v,
|
|
26
27
|
onCopy: L,
|
|
27
|
-
subtext:
|
|
28
|
-
successStateDuration:
|
|
28
|
+
subtext: c,
|
|
29
|
+
successStateDuration: E,
|
|
29
30
|
value: N,
|
|
30
|
-
...
|
|
31
|
-
} =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
...T
|
|
32
|
+
} = I, {
|
|
33
|
+
formatMessage: p
|
|
34
|
+
} = F(), B = p(f.copyButtonLabel), S = p(f.copyButtonCopiedLabel), d = y("error-"), l = y("subtext-"), {
|
|
35
|
+
copyToClipboard: u,
|
|
36
|
+
inputRef: D,
|
|
37
|
+
isCopied: b
|
|
38
|
+
} = U({
|
|
39
|
+
copyTimeout: E,
|
|
40
|
+
isDisabled: r,
|
|
41
|
+
onCopy: L
|
|
42
|
+
}), R = _((o) => {
|
|
43
|
+
o.target.select();
|
|
44
|
+
}, []), j = _((o) => {
|
|
45
|
+
o.target instanceof HTMLInputElement && o.target.setSelectionRange(0, o.target.value.length);
|
|
46
|
+
}, []), e = !!s && !r, m = !s && !!c;
|
|
47
|
+
let n;
|
|
48
|
+
return m && (n = l), e && (n = d), /* @__PURE__ */ h("div", {
|
|
49
|
+
className: i(t.container, {
|
|
50
|
+
[t.hasError]: e
|
|
48
51
|
}),
|
|
49
52
|
children: [/* @__PURE__ */ h("div", {
|
|
50
|
-
className:
|
|
51
|
-
[
|
|
53
|
+
className: i(t.copyInput, {
|
|
54
|
+
[t.isCopied]: b
|
|
52
55
|
}),
|
|
53
|
-
children: [/* @__PURE__ */
|
|
54
|
-
...
|
|
56
|
+
children: [/* @__PURE__ */ a(M, {
|
|
57
|
+
...T,
|
|
55
58
|
ref: D,
|
|
56
|
-
"aria-describedby":
|
|
57
|
-
"aria-invalid":
|
|
58
|
-
className:
|
|
59
|
-
disabled:
|
|
60
|
-
hideLabel:
|
|
61
|
-
invalid:
|
|
59
|
+
"aria-describedby": i(g, n),
|
|
60
|
+
"aria-invalid": e,
|
|
61
|
+
className: t.input,
|
|
62
|
+
disabled: r,
|
|
63
|
+
hideLabel: w,
|
|
64
|
+
invalid: e,
|
|
62
65
|
label: v,
|
|
63
|
-
onCopy:
|
|
64
|
-
onFocus:
|
|
65
|
-
onSelect:
|
|
66
|
+
onCopy: u,
|
|
67
|
+
onFocus: R,
|
|
68
|
+
onSelect: j,
|
|
66
69
|
readOnly: !0,
|
|
67
70
|
value: N
|
|
68
|
-
}), /* @__PURE__ */
|
|
69
|
-
ref:
|
|
70
|
-
"aria-live":
|
|
71
|
-
className:
|
|
72
|
-
"data-target-id":
|
|
73
|
-
disabled:
|
|
74
|
-
onClick:
|
|
71
|
+
}), /* @__PURE__ */ a(O, {
|
|
72
|
+
ref: x,
|
|
73
|
+
"aria-live": C,
|
|
74
|
+
className: t.button,
|
|
75
|
+
"data-target-id": q,
|
|
76
|
+
disabled: r,
|
|
77
|
+
onClick: u,
|
|
75
78
|
size: "large",
|
|
76
79
|
variant: "secondary",
|
|
77
|
-
children:
|
|
80
|
+
children: b ? S : B
|
|
78
81
|
})]
|
|
79
|
-
}),
|
|
80
|
-
className:
|
|
81
|
-
id:
|
|
82
|
-
children:
|
|
83
|
-
})
|
|
82
|
+
}), e && /* @__PURE__ */ a(z, {
|
|
83
|
+
className: t.error,
|
|
84
|
+
id: d,
|
|
85
|
+
children: s
|
|
86
|
+
}), m && !e && /* @__PURE__ */ a(H, {
|
|
84
87
|
as: "p",
|
|
85
|
-
className:
|
|
88
|
+
className: t.subtext,
|
|
86
89
|
color: "textOnLightSecondary",
|
|
87
|
-
id:
|
|
90
|
+
id: l,
|
|
88
91
|
variant: "caption",
|
|
89
|
-
children:
|
|
92
|
+
children: c
|
|
90
93
|
})]
|
|
91
94
|
});
|
|
92
95
|
});
|
|
93
|
-
|
|
96
|
+
X.displayName = "CopyInput";
|
|
94
97
|
export {
|
|
95
|
-
|
|
98
|
+
X as CopyInput
|
|
96
99
|
};
|
package/dist/esm/lib/messages.js
CHANGED
package/dist/esm/lib/utils.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
o.current?.select(), e?.(u), s(!0), setTimeout(() => s(!1), p);
|
|
9
|
-
}).catch((l) => {
|
|
10
|
-
e?.(l);
|
|
11
|
-
});
|
|
12
|
-
}, [t, r, e, n]);
|
|
1
|
+
import { useRef as n, useState as s, useCallback as l } from "react";
|
|
2
|
+
const p = 3e3, m = ({
|
|
3
|
+
copyTimeout: o = p,
|
|
4
|
+
isDisabled: c,
|
|
5
|
+
onCopy: e
|
|
6
|
+
}) => {
|
|
7
|
+
const r = n(null), [t, a] = s(!1);
|
|
13
8
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
copyToClipboard: l(async () => {
|
|
10
|
+
if (!r.current || t || c)
|
|
11
|
+
return;
|
|
12
|
+
if (!navigator.clipboard && !document.queryCommandSupported("copy")) {
|
|
13
|
+
e && e(new Error("Copying to clipboard is not supported"));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const i = r.current.value ?? "";
|
|
17
|
+
try {
|
|
18
|
+
navigator.clipboard ? (await navigator.clipboard.writeText(i), r.current.select()) : (r.current.select(), document.execCommand("copy")), e && e(i), a(!0), setTimeout(() => a(!1), o);
|
|
19
|
+
} catch (u) {
|
|
20
|
+
e && e(u);
|
|
21
|
+
}
|
|
22
|
+
}, [o, t, c, e]),
|
|
23
|
+
inputRef: r,
|
|
24
|
+
isCopied: t
|
|
17
25
|
};
|
|
18
26
|
};
|
|
19
27
|
export {
|
|
20
|
-
|
|
28
|
+
m as useCopyToClipboard
|
|
21
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.
|
|
1
|
+
._container_17qpw_1._container_17qpw_1{--border-collapsible-border: var(--border-cta-border-secondary);display:flex;flex-direction:column}._container_17qpw_1._container_17qpw_1._hasError_17qpw_6 input:not(:focus-visible){border-color:var(--bp-border-input-border-error)!important;border-width:var(--bp-border-02)!important}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16{--text-input-disabled-opacity-api: .3;display:flex}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16 ._input_17qpw_20{z-index:1;flex-grow:1}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16 ._input_17qpw_20 input{border-top-right-radius:0;border-bottom-right-radius:0}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16 ._button_17qpw_28{align-self:flex-end;margin-left:-1px;border-top-left-radius:0;border-bottom-left-radius:0}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16 ._button_17qpw_28[data-modern=true]{border-color:var(--bp-gray-20);border-top-right-radius:var(--bp-radius-06);border-bottom-right-radius:var(--bp-radius-06)}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16 ._button_17qpw_28:disabled{border-color:var(--bp-border-input-border)}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16 ._button_17qpw_28:focus-visible{z-index:1}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16._isCopied_17qpw_45{--border-collapsible-border: var(--green-light-120);--surface-cta-surface-secondary: var(--green-light-50);--surface-cta-surface-secondary-hover: var(--green-light-50)}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16._isCopied_17qpw_45 input{border-color:var(--green-light-120)!important;border-width:var(--bp-border-01)!important}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16._isCopied_17qpw_45 input:focus{border-color:var(--outline-focus-on-light)!important;border-width:var(--bp-border-02)!important}._container_17qpw_1._container_17qpw_1 ._copyInput_17qpw_16._isCopied_17qpw_45 ._button_17qpw_28{background-color:var(--green-light-50);border-color:var(--green-light-120)}._container_17qpw_1._container_17qpw_1 ._error_17qpw_66,._container_17qpw_1._container_17qpw_1 ._subtext_17qpw_67{margin-block-start:var(--bp-space-020)}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TextInputProps } from '@box/blueprint-web';
|
|
2
|
+
export interface CopyInputProps extends Omit<TextInputProps, 'onCopy'> {
|
|
3
|
+
/**
|
|
4
|
+
* The aria-live attribute for the copy button.
|
|
5
|
+
*/
|
|
6
|
+
ariaLive?: 'off' | 'assertive' | 'polite';
|
|
7
|
+
/**
|
|
8
|
+
* Focus the input when the component loads.
|
|
9
|
+
*/
|
|
10
|
+
autoFocus?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The targeting ID for the copy button.
|
|
13
|
+
*/
|
|
14
|
+
'data-target-id'?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Callback called with the result of copying to the clipboard.
|
|
17
|
+
*/
|
|
18
|
+
onCopy?: (result: string | Error) => void;
|
|
19
|
+
/**
|
|
20
|
+
* The duration in milliseconds to show the copy success state.
|
|
21
|
+
*
|
|
22
|
+
* @default 3000
|
|
23
|
+
*/
|
|
24
|
+
successStateDuration?: number;
|
|
25
|
+
/**
|
|
26
|
+
* The text value to display in the input field.
|
|
27
|
+
*/
|
|
28
|
+
value: string;
|
|
29
|
+
}
|
|
2
30
|
export declare const CopyInput: import('react').ForwardRefExoticComponent<Omit<CopyInputProps, "ref"> & import('react').RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface UseCopyToClipboardProps {
|
|
2
|
+
copyTimeout?: number;
|
|
3
|
+
isDisabled?: boolean;
|
|
4
|
+
onCopy?: (result: string | Error) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const useCopyToClipboard: ({ copyTimeout, isDisabled, onCopy }: UseCopyToClipboardProps) => {
|
|
7
|
+
copyToClipboard: () => Promise<void>;
|
|
3
8
|
inputRef: import('react').MutableRefObject<HTMLInputElement | null>;
|
|
4
|
-
|
|
5
|
-
copied: boolean;
|
|
9
|
+
isCopied: boolean;
|
|
6
10
|
};
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/copy-input",
|
|
3
|
-
"version": "1.39.
|
|
3
|
+
"version": "1.39.10",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@box/blueprint-web": "^13.5.
|
|
7
|
-
"@box/blueprint-web-assets": "^4.
|
|
6
|
+
"@box/blueprint-web": "^13.5.5",
|
|
7
|
+
"@box/blueprint-web-assets": "^4.104.0",
|
|
8
8
|
"react": "^18.0.0",
|
|
9
9
|
"react-dom": "^18.0.0",
|
|
10
10
|
"react-intl": "^6.4.2"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@box/blueprint-web": "^13.5.
|
|
14
|
-
"@box/blueprint-web-assets": "^4.
|
|
15
|
-
"@box/storybook-utils": "0.16.
|
|
13
|
+
"@box/blueprint-web": "^13.5.5",
|
|
14
|
+
"@box/blueprint-web-assets": "^4.104.0",
|
|
15
|
+
"@box/storybook-utils": "0.16.61",
|
|
16
16
|
"@box/eslint-plugin-blueprint": "1.1.1",
|
|
17
17
|
"react-intl": "^6.4.2"
|
|
18
18
|
},
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Labelable, TextInputProps } from '@box/blueprint-web';
|
|
2
|
-
export type CopyInputProps = Omit<TextInputProps, 'onCopy'> & {
|
|
3
|
-
/** Text value of the input field */
|
|
4
|
-
value: string;
|
|
5
|
-
/** Set the focus to input when component loads */
|
|
6
|
-
autoFocus?: boolean;
|
|
7
|
-
/** Label displayed for the text input */
|
|
8
|
-
label: Labelable['label'];
|
|
9
|
-
/** When true label text is hidden */
|
|
10
|
-
hideLabel?: boolean;
|
|
11
|
-
/** Aria-live for the button */
|
|
12
|
-
ariaLive?: 'off' | 'polite' | 'assertive';
|
|
13
|
-
/** Targeting id attribute for copy button */
|
|
14
|
-
'data-target-id'?: string;
|
|
15
|
-
/** Duration (milliseconds) in which to show the copy success state.
|
|
16
|
-
* @default 3000 [ms] */
|
|
17
|
-
successStateDuration?: number;
|
|
18
|
-
/** Callback called with the result of copying to clipboard */
|
|
19
|
-
onCopy?: (result: Error | string) => void;
|
|
20
|
-
};
|