@box/copy-input 2.1.34 → 2.1.35

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.
@@ -1,76 +1 @@
1
- import { useCopyToClipboard as e } from "../esm/lib/utils.js";
2
- import t from "../esm/lib/messages.js";
3
- import n from "clsx";
4
- import { forwardRef as r, useCallback as i } from "react";
5
- import { useIntl as a } from "react-intl";
6
- import { BaseTextInput as o, Button as s, InlineError as c, Text as l, useUniqueId as u } from "@box/blueprint-web";
7
- import { jsx as d, jsxs as f } from "react/jsx-runtime";
8
- import '../styles/copy-input.css';var p = {
9
- container: "_container_17qpw_1",
10
- hasError: "_hasError_17qpw_6",
11
- copyInput: "_copyInput_17qpw_16",
12
- input: "_input_17qpw_20",
13
- button: "_button_17qpw_28",
14
- isCopied: "_isCopied_17qpw_45",
15
- error: "_error_17qpw_66",
16
- subtext: "_subtext_17qpw_67"
17
- }, m = /*#__PURE__*/ r((r, m) => {
18
- let { ariaLive: h, "aria-describedby": g, "data-target-id": _, disabled: v, error: y, hideLabel: b, id: x, label: S, onCopy: C, subtext: w, successStateDuration: T, value: E, ...D } = r, { formatMessage: O } = a(), k = O(t.copyButtonLabel), A = O(t.copyButtonCopiedLabel), j = u("error-"), M = u("subtext-"), { copyToClipboard: N, inputRef: P, isCopied: F } = e({
19
- copyTimeout: T,
20
- isDisabled: v,
21
- onCopy: C
22
- }), I = i((e) => {
23
- e.target.select();
24
- }, []), L = i((e) => {
25
- e.target instanceof HTMLInputElement && e.target.setSelectionRange(0, e.target.value.length);
26
- }, []), R = !!y && !v, z = !y && !!w, B;
27
- return z && (B = M), R && (B = j), /* @__PURE__ */ f("div", {
28
- className: n(p.container, { [p.hasError]: R }),
29
- children: [
30
- /* @__PURE__ */ f("div", {
31
- className: n(p.copyInput, { [p.isCopied]: F }),
32
- children: [/* @__PURE__ */ d(o, {
33
- ...D,
34
- ref: P,
35
- "aria-describedby": n(g, B),
36
- "aria-invalid": R,
37
- className: p.input,
38
- disabled: v,
39
- hideLabel: b,
40
- invalid: R,
41
- label: S,
42
- onCopy: N,
43
- onFocus: I,
44
- onSelect: L,
45
- readOnly: !0,
46
- value: E
47
- }), /* @__PURE__ */ d(s, {
48
- ref: m,
49
- "aria-live": h,
50
- className: p.button,
51
- "data-target-id": _,
52
- disabled: v,
53
- onClick: N,
54
- size: "large",
55
- variant: "secondary",
56
- children: F ? A : k
57
- })]
58
- }),
59
- R && /* @__PURE__ */ d(c, {
60
- className: p.error,
61
- id: j,
62
- children: y
63
- }),
64
- z && !R && /* @__PURE__ */ d(l, {
65
- as: "p",
66
- className: p.subtext,
67
- color: "textOnLightSecondary",
68
- id: M,
69
- variant: "caption",
70
- children: w
71
- })
72
- ]
73
- });
74
- });
75
- m.displayName = "CopyInput";
76
- export { m as t };
1
+ import{useCopyToClipboard}from"../esm/lib/utils.js";import messages from"../esm/lib/messages.js";import clsx from"clsx";import{forwardRef,useCallback}from"react";import{useIntl}from"react-intl";import{BaseTextInput,Button,InlineError,Text,useUniqueId}from"@box/blueprint-web";import{jsx,jsxs}from"react/jsx-runtime";import '../styles/copy-input.css';var copy_input_module_default={container:`_container_17qpw_1`,hasError:`_hasError_17qpw_6`,copyInput:`_copyInput_17qpw_16`,input:`_input_17qpw_20`,button:`_button_17qpw_28`,isCopied:`_isCopied_17qpw_45`,error:`_error_17qpw_66`,subtext:`_subtext_17qpw_67`},CopyInput=forwardRef((props,forwardedRef)=>{let{ariaLive,"aria-describedby":ariaDescribedBy,"data-target-id":dataTargetId,disabled,error,hideLabel,id,label,onCopy,subtext,successStateDuration,value,...rest}=props,{formatMessage}=useIntl(),defaultLabel=formatMessage(messages.copyButtonLabel),copiedLabel=formatMessage(messages.copyButtonCopiedLabel),errorId=useUniqueId(`error-`),subtextId=useUniqueId(`subtext-`),{copyToClipboard,inputRef,isCopied}=useCopyToClipboard({copyTimeout:successStateDuration,isDisabled:disabled,onCopy}),handleInputFocus=useCallback(event=>{event.target.select()},[]),handleSelect=useCallback(event=>{event.target instanceof HTMLInputElement&&event.target.setSelectionRange(0,event.target.value.length)},[]),hasError=!!error&&!disabled,hasSubtext=!error&&!!subtext,describedById;return hasSubtext&&(describedById=subtextId),hasError&&(describedById=errorId),jsxs(`div`,{className:clsx(copy_input_module_default.container,{[copy_input_module_default.hasError]:hasError}),children:[jsxs(`div`,{className:clsx(copy_input_module_default.copyInput,{[copy_input_module_default.isCopied]:isCopied}),children:[jsx(BaseTextInput,{...rest,ref:inputRef,"aria-describedby":clsx(ariaDescribedBy,describedById),"aria-invalid":hasError,className:copy_input_module_default.input,disabled,hideLabel,invalid:hasError,label,onCopy:copyToClipboard,onFocus:handleInputFocus,onSelect:handleSelect,readOnly:!0,value}),jsx(Button,{ref:forwardedRef,"aria-live":ariaLive,className:copy_input_module_default.button,"data-target-id":dataTargetId,disabled,onClick:copyToClipboard,size:`large`,variant:`secondary`,children:isCopied?copiedLabel:defaultLabel})]}),hasError&&jsx(InlineError,{className:copy_input_module_default.error,id:errorId,children:error}),hasSubtext&&!hasError&&jsx(Text,{as:`p`,className:copy_input_module_default.subtext,color:`textOnLightSecondary`,id:subtextId,variant:`caption`,children:subtext})]})});CopyInput.displayName=`CopyInput`;export{CopyInput as t};
package/dist/esm/index.js CHANGED
@@ -1,2 +1 @@
1
- import { t as e } from "../chunks/copy-input.js";
2
- export { e as CopyInput };
1
+ import{t as CopyInput}from"../chunks/copy-input.js";export{CopyInput};
@@ -1,2 +1 @@
1
- import { t as e } from "../../chunks/copy-input.js";
2
- export { e as CopyInput };
1
+ import{t as CopyInput}from"../../chunks/copy-input.js";export{CopyInput};
@@ -1,12 +1 @@
1
- import { defineMessages as e } from "react-intl";
2
- var t = e({
3
- copyButtonLabel: {
4
- id: "groupSharedFeatures.copyButton.copyButtonLabel",
5
- defaultMessage: "Copy"
6
- },
7
- copyButtonCopiedLabel: {
8
- id: "groupSharedFeatures.copyButton.copyButtonCopiedLabel",
9
- defaultMessage: "Copied"
10
- }
11
- });
12
- export { t as default };
1
+ import{defineMessages}from"react-intl";var messages=defineMessages({copyButtonLabel:{id:`groupSharedFeatures.copyButton.copyButtonLabel`,defaultMessage:`Copy`},copyButtonCopiedLabel:{id:`groupSharedFeatures.copyButton.copyButtonCopiedLabel`,defaultMessage:`Copied`}});export{messages as default};
@@ -1,27 +1 @@
1
- import { useCallback as e, useRef as t, useState as n } from "react";
2
- var r = 3e3, i = ({ copyTimeout: i = r, isDisabled: a, onCopy: o }) => {
3
- let s = t(null), [c, l] = n(!1);
4
- return {
5
- copyToClipboard: e(async () => {
6
- if (!s.current || c || a) return;
7
- if (!navigator.clipboard && !document.queryCommandSupported("copy")) {
8
- o && o(/* @__PURE__ */ Error("Copying to clipboard is not supported"));
9
- return;
10
- }
11
- let e = s.current.value ?? "";
12
- try {
13
- navigator.clipboard ? (await navigator.clipboard.writeText(e), s.current.select()) : (s.current.select(), document.execCommand("copy")), o && o(e), l(!0), setTimeout(() => l(!1), i);
14
- } catch (e) {
15
- o && o(e);
16
- }
17
- }, [
18
- i,
19
- c,
20
- a,
21
- o
22
- ]),
23
- inputRef: s,
24
- isCopied: c
25
- };
26
- };
27
- export { i as useCopyToClipboard };
1
+ import{useCallback,useRef,useState}from"react";var COPY_TIMEOUT_MS=3e3,useCopyToClipboard=({copyTimeout=COPY_TIMEOUT_MS,isDisabled,onCopy})=>{let inputRef=useRef(null),[isCopied,setIsCopied]=useState(!1);return{copyToClipboard:useCallback(async()=>{if(!inputRef.current||isCopied||isDisabled)return;if(!navigator.clipboard&&!document.queryCommandSupported(`copy`)){onCopy&&onCopy(Error(`Copying to clipboard is not supported`));return}let value=inputRef.current.value??``;try{navigator.clipboard?(await navigator.clipboard.writeText(value),inputRef.current.select()):(inputRef.current.select(),document.execCommand(`copy`)),onCopy&&onCopy(value),setIsCopied(!0),setTimeout(()=>setIsCopied(!1),copyTimeout)}catch(error){onCopy&&onCopy(error)}},[copyTimeout,isCopied,isDisabled,onCopy]),inputRef,isCopied}};export{useCopyToClipboard};
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@box/copy-input",
3
- "version": "2.1.34",
3
+ "version": "2.1.35",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "peerDependencies": {
6
- "@box/blueprint-web": "^16.13.0",
7
- "@box/blueprint-web-assets": "^5.5.9",
6
+ "@box/blueprint-web": "^16.13.1",
7
+ "@box/blueprint-web-assets": "^5.5.10",
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": "^16.13.0",
14
- "@box/blueprint-web-assets": "^5.5.9",
15
- "@box/eslint-plugin-blueprint": "2.1.10",
16
- "@box/storybook-utils": "1.1.33",
13
+ "@box/blueprint-web": "^16.13.1",
14
+ "@box/blueprint-web-assets": "^5.5.10",
15
+ "@box/eslint-plugin-blueprint": "2.1.11",
16
+ "@box/storybook-utils": "1.1.34",
17
17
  "react-intl": "^6.4.2"
18
18
  },
19
19
  "publishConfig": {