@contentful/f36-copybutton 4.25.1 → 4.25.2

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/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import m, { useState, useCallback } from 'react';
1
+ import u, { useState, useCallback } from 'react';
2
2
  import { CopyIcon } from '@contentful/f36-icons';
3
3
  import { Tooltip } from '@contentful/f36-tooltip';
4
4
  import { Button } from '@contentful/f36-button';
5
5
  import { cx, css } from 'emotion';
6
6
 
7
- var S=Object.defineProperty,D=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var c=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable;var P=(t,o,e)=>o in t?S(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,f=(t,o)=>{for(var e in o||(o={}))b.call(o,e)&&P(t,e,o[e]);if(c)for(var e of c(o))g.call(o,e)&&P(t,e,o[e]);return t},C=(t,o)=>D(t,L(o));var h=(t,o)=>{var e={};for(var r in t)b.call(t,r)&&o.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&c)for(var r of c(t))o.indexOf(r)<0&&g.call(t,r)&&(e[r]=t[r]);return e};var T=(t,o,e)=>new Promise((r,i)=>{var p=n=>{try{s(e.next(n));}catch(a){i(a);}},l=n=>{try{s(e.throw(n));}catch(a){i(a);}},s=n=>n.done?r(n.value):Promise.resolve(n.value).then(p,l);s((e=e.apply(t,o)).next());});var v=({size:t})=>{let o=t==="small"?"32px":"40px";return {button:css({height:o,minHeight:"auto",minWidth:"auto",width:o})}};function E(q,I){var B=q,{className:t,isDisabled:o=!1,isLoading:e=!1,label:r,onBlur:i,onCopy:p,size:l="medium",testId:s="cf-ui-copy-button",tooltipCopiedText:n="Copied!",tooltipProps:a,tooltipText:H="Copy to clipboard",value:u}=B,w=h(B,["className","isDisabled","isLoading","label","onBlur","onCopy","size","testId","tooltipCopiedText","tooltipProps","tooltipText","value"]);let M=v({size:l}),[d,x]=useState(!1),k=useCallback(()=>T(this,null,function*(){try{yield window.navigator.clipboard.writeText(u);}catch(y){console.error(y);return}p==null||p(u),x(!0);}),[p,u]),z=y=>{d&&x(!1),i==null||i(y);};return m.createElement(Tooltip,C(f({content:d?n:H},a),{isDisabled:o}),m.createElement(Button,C(f({"aria-label":d?"Value copied to clipboard":r!=null?r:"Copy to clipboard","aria-live":"assertive",className:cx(M.button,t),isDisabled:e||o,isLoading:e,onBlur:z,testId:s},w),{onClick:k,ref:I,startIcon:m.createElement(CopyIcon,{variant:"muted",size:l==="small"?"tiny":"small"}),variant:"secondary"})))}E.displayName="CopyButton";var j=m.forwardRef(E);
7
+ var S=Object.defineProperty,D=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var c=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var P=(t,o,e)=>o in t?S(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,f=(t,o)=>{for(var e in o||(o={}))b.call(o,e)&&P(t,e,o[e]);if(c)for(var e of c(o))v.call(o,e)&&P(t,e,o[e]);return t},C=(t,o)=>D(t,L(o));var g=(t,o)=>{var e={};for(var r in t)b.call(t,r)&&o.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&c)for(var r of c(t))o.indexOf(r)<0&&v.call(t,r)&&(e[r]=t[r]);return e};var h=(t,o,e)=>new Promise((r,i)=>{var p=n=>{try{s(e.next(n));}catch(a){i(a);}},l=n=>{try{s(e.throw(n));}catch(a){i(a);}},s=n=>n.done?r(n.value):Promise.resolve(n.value).then(p,l);s((e=e.apply(t,o)).next());});var T=({size:t})=>{let o=t==="small"?"32px":"40px";return {button:css({height:o,minHeight:"auto",minWidth:"auto",width:o})}};function E(q,k){var B=q,{className:t,isDisabled:o=!1,isLoading:e=!1,label:r,onBlur:i,onCopy:p,size:l="medium",testId:s="cf-ui-copy-button",tooltipCopiedText:n="Copied!",tooltipProps:a,tooltipText:H="Copy to clipboard",value:m}=B,w=g(B,["className","isDisabled","isLoading","label","onBlur","onCopy","size","testId","tooltipCopiedText","tooltipProps","tooltipText","value"]);let I=T({size:l}),[d,x]=useState(!1),M=useCallback(()=>h(this,null,function*(){try{yield window.navigator.clipboard.writeText(m);}catch(y){console.error(y);return}p==null||p(m),x(!0);}),[p,m]),z=y=>{d&&x(!1),i==null||i(y);};return u.createElement(Tooltip,C(f({content:d?n:H},a),{isDisabled:o}),u.createElement(Button,C(f({"aria-label":d?"Value copied to clipboard":r!=null?r:"Copy to clipboard","aria-live":"assertive",className:cx(I.button,t),isDisabled:e||o,isLoading:e,onBlur:z,testId:s},w),{onClick:M,ref:k,startIcon:u.createElement(CopyIcon,{variant:"muted",size:l==="small"?"tiny":"small"}),variant:"secondary"})))}E.displayName="CopyButton";var j=u.forwardRef(E);
8
8
 
9
9
  export { j as CopyButton };
10
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/CopyButton.tsx","../../src/CopyButton.styles.ts"],"names":["React","useCallback","useState","CopyIcon","Tooltip","Button","css","getCopyButtonStyles","size","buttonSize","cx","_CopyButton","_a","ref","_b","className","isDisabled","isLoading","label","onBlur","onCopy","testId","tooltipCopiedText","tooltipProps","tooltipText","value","otherProps","__objRest","styles","copied","setCopied","handleClick","__async","error","handleBlur","event","__spreadProps","__spreadValues","CopyButton"],"mappings":"4xBAAA,OAAOA,GACL,eAAAC,EACA,YAAAC,MAGK,QACP,OAAS,YAAAC,MAAgB,wBAEzB,OAAS,WAAAC,MAAkC,0BAC3C,OAAS,UAAAC,MAAgC,yBCTzC,OAAS,OAAAC,MAAW,UAGb,IAAMC,EAAsB,CAAC,CAClC,KAAAC,CACF,IAAqC,CACnC,IAAMC,EAAaD,IAAS,QAAU,OAAS,OAE/C,MAAO,CACL,OAAQF,EAAI,CACV,OAAQG,EACR,UAAW,OACX,SAAU,OACV,MAAOA,CACT,CAAC,CACH,CACF,EDL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AY,YAAc,aAEnB,IAAM2B,EAAatC,EAAM,WAAWW,CAAW","sourcesContent":["import React, {\n useCallback,\n useState,\n type MouseEventHandler,\n type FocusEventHandler,\n} from 'react';\nimport { CopyIcon } from '@contentful/f36-icons';\nimport type { ExpandProps } from '@contentful/f36-core';\nimport { Tooltip, type TooltipProps } from '@contentful/f36-tooltip';\nimport { Button, type ButtonProps } from '@contentful/f36-button';\nimport { getCopyButtonStyles } from './CopyButton.styles';\nimport { cx } from 'emotion';\n\nexport type CopyButtonProps = Omit<\n ButtonProps,\n 'children' | 'endIcon' | 'onCopy' | 'startIcon' | 'isDisabed' | 'size'\n> & {\n /**\n * Function that gets called when the button is clicked\n */\n onCopy?: (string) => void;\n /**\n * Text to be shown when the button is clicked\n * @default Copied!\n */\n tooltipCopiedText?: string;\n /**\n * Text to be shown when button is hovered or focused\n * @default Copy to clipboard\n */\n tooltipText?: string;\n /**\n * Props that are passed to the tooltip component\n */\n tooltipProps?: Omit<TooltipProps, 'content' | 'children'>;\n /**\n * Label to be used on aria-label for the button\n * @default Copy to clipboard\n */\n label?: string;\n /**\n * Allows to disable the copy button, when true the tooltip would not be shown\n * @default false\n */\n isDisabled?: boolean;\n /**\n * Allows setting size of the copy button to small\n * @default medium\n */\n size?: 'small' | 'medium';\n /**\n * Value that will be copied to clipboard when the button is clicked\n */\n value: string;\n};\n\nfunction _CopyButton(\n {\n className,\n isDisabled = false,\n isLoading = false,\n label,\n onBlur,\n onCopy,\n size = 'medium',\n testId = 'cf-ui-copy-button',\n tooltipCopiedText = 'Copied!',\n tooltipProps,\n tooltipText = 'Copy to clipboard',\n value,\n ...otherProps\n }: ExpandProps<CopyButtonProps>,\n ref: React.Ref<HTMLButtonElement>,\n) {\n const styles = getCopyButtonStyles({ size });\n const [copied, setCopied] = useState(false);\n\n const handleClick = useCallback<\n MouseEventHandler<HTMLButtonElement>\n >(async () => {\n try {\n await window.navigator.clipboard.writeText(value);\n } catch (error) {\n console.error(error);\n return;\n }\n\n onCopy?.(value);\n setCopied(true);\n }, [onCopy, value]);\n\n const handleBlur: FocusEventHandler<HTMLButtonElement> = (event) => {\n if (copied) {\n setCopied(false);\n }\n\n onBlur?.(event);\n };\n\n return (\n <Tooltip\n content={copied ? tooltipCopiedText : tooltipText}\n {...tooltipProps}\n isDisabled={isDisabled}\n >\n <Button\n aria-label={\n copied ? 'Value copied to clipboard' : label ?? `Copy to clipboard`\n }\n aria-live=\"assertive\"\n className={cx(styles.button, className)}\n isDisabled={isLoading || isDisabled}\n isLoading={isLoading}\n onBlur={handleBlur}\n testId={testId}\n {...otherProps}\n onClick={handleClick}\n ref={ref}\n startIcon={\n <CopyIcon\n variant=\"muted\"\n size={size === 'small' ? 'tiny' : 'small'}\n />\n }\n variant=\"secondary\"\n />\n </Tooltip>\n );\n}\n\n_CopyButton.displayName = 'CopyButton';\n\nexport const CopyButton = React.forwardRef(_CopyButton);\n","import { css } from 'emotion';\nimport { CopyButtonProps } from './CopyButton';\n\nexport const getCopyButtonStyles = ({\n size,\n}: Pick<CopyButtonProps, 'size'>) => {\n const buttonSize = size === 'small' ? '32px' : '40px';\n\n return {\n button: css({\n height: buttonSize,\n minHeight: 'auto',\n minWidth: 'auto',\n width: buttonSize,\n }),\n };\n};\n"]}
1
+ {"version":3,"sources":["../../src/CopyButton.tsx","../../src/CopyButton.styles.ts"],"names":["React","useCallback","useState","CopyIcon","Tooltip","Button","css","getCopyButtonStyles","size","buttonSize","cx","_CopyButton","_a","ref","_b","className","isDisabled","isLoading","label","onBlur","onCopy","testId","tooltipCopiedText","tooltipProps","tooltipText","value","otherProps","__objRest","styles","copied","setCopied","handleClick","__async","error","handleBlur","event","__spreadProps","__spreadValues","CopyButton"],"mappings":"4xBAAA,OAAOA,GACL,eAAAC,EACA,YAAAC,MAGK,QACP,OAAS,YAAAC,MAAgB,wBAEzB,OAAS,WAAAC,MAAkC,0BAC3C,OAAS,UAAAC,MAAgC,yBCTzC,OAAS,OAAAC,MAAW,UAGb,IAAMC,EAA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,OAAQiB,EACR,OAAQb,GACJK,GAVL,CAWC,QAASK,EACT,IAAKlB,EACL,UACEb,EAAA,cAACG,EAAA,CACC,QAAQ,QACR,KAAMK,IAAS,QAAU,OAAS,QACpC,EAEF,QAAQ,aACV,CACF,CAEJ,CAEAG,EAAY,YAAc,aAEnB,IAAM2B,EAAatC,EAAM,WAAWW,CAAW","sourcesContent":["import React, {\n useCallback,\n useState,\n type MouseEventHandler,\n type FocusEventHandler,\n} from 'react';\nimport { CopyIcon } from '@contentful/f36-icons';\nimport type { ExpandProps } from '@contentful/f36-core';\nimport { Tooltip, type TooltipProps } from '@contentful/f36-tooltip';\nimport { Button, type ButtonProps } from '@contentful/f36-button';\nimport { getCopyButtonStyles } from './CopyButton.styles';\nimport { cx } from 'emotion';\n\nexport type CopyButtonProps = Omit<\n ButtonProps,\n | 'children'\n | 'endIcon'\n | 'onCopy'\n | 'onClick'\n | 'startIcon'\n | 'isDisabled'\n | 'size'\n | 'value'\n | 'variant'\n> & {\n /**\n * Function that gets called when the button is clicked\n */\n onCopy?: (string) => void;\n /**\n * Text to be shown when the button is clicked\n * @default Copied!\n */\n tooltipCopiedText?: string;\n /**\n * Text to be shown when button is hovered or focused\n * @default Copy to clipboard\n */\n tooltipText?: string;\n /**\n * Props that are passed to the tooltip component\n */\n tooltipProps?: Omit<TooltipProps, 'content' | 'children'>;\n /**\n * Label to be used on aria-label for the button\n * @default Copy to clipboard\n */\n label?: string;\n /**\n * Allows to disable the copy button, when true the tooltip would not be shown\n * @default false\n */\n isDisabled?: boolean;\n /**\n * Allows setting size of the copy button to small\n * @default medium\n */\n size?: 'small' | 'medium';\n /**\n * Value that will be copied to clipboard when the button is clicked\n */\n value: string;\n};\n\nfunction _CopyButton(\n {\n className,\n isDisabled = false,\n isLoading = false,\n label,\n onBlur,\n onCopy,\n size = 'medium',\n testId = 'cf-ui-copy-button',\n tooltipCopiedText = 'Copied!',\n tooltipProps,\n tooltipText = 'Copy to clipboard',\n value,\n ...otherProps\n }: ExpandProps<CopyButtonProps>,\n ref: React.Ref<HTMLButtonElement>,\n) {\n const styles = getCopyButtonStyles({ size });\n const [copied, setCopied] = useState(false);\n\n const handleClick = useCallback<\n MouseEventHandler<HTMLButtonElement>\n >(async () => {\n try {\n await window.navigator.clipboard.writeText(value);\n } catch (error) {\n console.error(error);\n return;\n }\n\n onCopy?.(value);\n setCopied(true);\n }, [onCopy, value]);\n\n const handleBlur: FocusEventHandler<HTMLButtonElement> = (event) => {\n if (copied) {\n setCopied(false);\n }\n\n onBlur?.(event);\n };\n\n return (\n <Tooltip\n content={copied ? tooltipCopiedText : tooltipText}\n {...tooltipProps}\n isDisabled={isDisabled}\n >\n <Button\n aria-label={\n copied ? 'Value copied to clipboard' : label ?? `Copy to clipboard`\n }\n aria-live=\"assertive\"\n className={cx(styles.button, className)}\n isDisabled={isLoading || isDisabled}\n isLoading={isLoading}\n onBlur={handleBlur}\n testId={testId}\n {...otherProps}\n onClick={handleClick}\n ref={ref}\n startIcon={\n <CopyIcon\n variant=\"muted\"\n size={size === 'small' ? 'tiny' : 'small'}\n />\n }\n variant=\"secondary\"\n />\n </Tooltip>\n );\n}\n\n_CopyButton.displayName = 'CopyButton';\n\nexport const CopyButton = React.forwardRef(_CopyButton);\n","import { css } from 'emotion';\nimport { CopyButtonProps } from './CopyButton';\n\nexport const getCopyButtonStyles = ({\n size,\n}: Pick<CopyButtonProps, 'size'>) => {\n const buttonSize = size === 'small' ? '32px' : '40px';\n\n return {\n button: css({\n height: buttonSize,\n minHeight: 'auto',\n minWidth: 'auto',\n width: buttonSize,\n }),\n };\n};\n"]}
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { TooltipProps } from '@contentful/f36-tooltip';
3
3
  import { ButtonProps } from '@contentful/f36-button';
4
4
 
5
- declare type CopyButtonProps = Omit<ButtonProps, 'children' | 'endIcon' | 'onCopy' | 'startIcon' | 'isDisabed' | 'size'> & {
5
+ declare type CopyButtonProps = Omit<ButtonProps, 'children' | 'endIcon' | 'onCopy' | 'onClick' | 'startIcon' | 'isDisabled' | 'size' | 'value' | 'variant'> & {
6
6
  /**
7
7
  * Function that gets called when the button is clicked
8
8
  */
@@ -41,7 +41,7 @@ declare type CopyButtonProps = Omit<ButtonProps, 'children' | 'endIcon' | 'onCop
41
41
  */
42
42
  value: string;
43
43
  };
44
- declare const CopyButton: React.ForwardRefExoticComponent<Omit<ButtonProps<"button">, "children" | "size" | "startIcon" | "endIcon" | "onCopy" | "isDisabed"> & {
44
+ declare const CopyButton: React.ForwardRefExoticComponent<Omit<ButtonProps<"button">, "children" | "variant" | "size" | "isDisabled" | "startIcon" | "endIcon" | "value" | "onCopy" | "onClick"> & {
45
45
  /**
46
46
  * Function that gets called when the button is clicked
47
47
  */
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var m = require('react');
5
+ var u = require('react');
6
6
  var f36Icons = require('@contentful/f36-icons');
7
7
  var f36Tooltip = require('@contentful/f36-tooltip');
8
8
  var f36Button = require('@contentful/f36-button');
@@ -10,9 +10,9 @@ var emotion = require('emotion');
10
10
 
11
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
12
 
13
- var m__default = /*#__PURE__*/_interopDefaultLegacy(m);
13
+ var u__default = /*#__PURE__*/_interopDefaultLegacy(u);
14
14
 
15
- var S=Object.defineProperty,D=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var c=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable;var P=(t,o,e)=>o in t?S(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,f=(t,o)=>{for(var e in o||(o={}))b.call(o,e)&&P(t,e,o[e]);if(c)for(var e of c(o))g.call(o,e)&&P(t,e,o[e]);return t},C=(t,o)=>D(t,L(o));var h=(t,o)=>{var e={};for(var r in t)b.call(t,r)&&o.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&c)for(var r of c(t))o.indexOf(r)<0&&g.call(t,r)&&(e[r]=t[r]);return e};var T=(t,o,e)=>new Promise((r,i)=>{var p=n=>{try{s(e.next(n));}catch(a){i(a);}},l=n=>{try{s(e.throw(n));}catch(a){i(a);}},s=n=>n.done?r(n.value):Promise.resolve(n.value).then(p,l);s((e=e.apply(t,o)).next());});var v=({size:t})=>{let o=t==="small"?"32px":"40px";return {button:emotion.css({height:o,minHeight:"auto",minWidth:"auto",width:o})}};function E(q,I){var B=q,{className:t,isDisabled:o=!1,isLoading:e=!1,label:r,onBlur:i,onCopy:p,size:l="medium",testId:s="cf-ui-copy-button",tooltipCopiedText:n="Copied!",tooltipProps:a,tooltipText:H="Copy to clipboard",value:u}=B,w=h(B,["className","isDisabled","isLoading","label","onBlur","onCopy","size","testId","tooltipCopiedText","tooltipProps","tooltipText","value"]);let M=v({size:l}),[d,x]=m.useState(!1),k=m.useCallback(()=>T(this,null,function*(){try{yield window.navigator.clipboard.writeText(u);}catch(y){console.error(y);return}p==null||p(u),x(!0);}),[p,u]),z=y=>{d&&x(!1),i==null||i(y);};return m__default["default"].createElement(f36Tooltip.Tooltip,C(f({content:d?n:H},a),{isDisabled:o}),m__default["default"].createElement(f36Button.Button,C(f({"aria-label":d?"Value copied to clipboard":r!=null?r:"Copy to clipboard","aria-live":"assertive",className:emotion.cx(M.button,t),isDisabled:e||o,isLoading:e,onBlur:z,testId:s},w),{onClick:k,ref:I,startIcon:m__default["default"].createElement(f36Icons.CopyIcon,{variant:"muted",size:l==="small"?"tiny":"small"}),variant:"secondary"})))}E.displayName="CopyButton";var j=m__default["default"].forwardRef(E);
15
+ var S=Object.defineProperty,D=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var c=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var P=(t,o,e)=>o in t?S(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,f=(t,o)=>{for(var e in o||(o={}))b.call(o,e)&&P(t,e,o[e]);if(c)for(var e of c(o))v.call(o,e)&&P(t,e,o[e]);return t},C=(t,o)=>D(t,L(o));var g=(t,o)=>{var e={};for(var r in t)b.call(t,r)&&o.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&c)for(var r of c(t))o.indexOf(r)<0&&v.call(t,r)&&(e[r]=t[r]);return e};var h=(t,o,e)=>new Promise((r,i)=>{var p=n=>{try{s(e.next(n));}catch(a){i(a);}},l=n=>{try{s(e.throw(n));}catch(a){i(a);}},s=n=>n.done?r(n.value):Promise.resolve(n.value).then(p,l);s((e=e.apply(t,o)).next());});var T=({size:t})=>{let o=t==="small"?"32px":"40px";return {button:emotion.css({height:o,minHeight:"auto",minWidth:"auto",width:o})}};function E(q,k){var B=q,{className:t,isDisabled:o=!1,isLoading:e=!1,label:r,onBlur:i,onCopy:p,size:l="medium",testId:s="cf-ui-copy-button",tooltipCopiedText:n="Copied!",tooltipProps:a,tooltipText:H="Copy to clipboard",value:m}=B,w=g(B,["className","isDisabled","isLoading","label","onBlur","onCopy","size","testId","tooltipCopiedText","tooltipProps","tooltipText","value"]);let I=T({size:l}),[d,x]=u.useState(!1),M=u.useCallback(()=>h(this,null,function*(){try{yield window.navigator.clipboard.writeText(m);}catch(y){console.error(y);return}p==null||p(m),x(!0);}),[p,m]),z=y=>{d&&x(!1),i==null||i(y);};return u__default["default"].createElement(f36Tooltip.Tooltip,C(f({content:d?n:H},a),{isDisabled:o}),u__default["default"].createElement(f36Button.Button,C(f({"aria-label":d?"Value copied to clipboard":r!=null?r:"Copy to clipboard","aria-live":"assertive",className:emotion.cx(I.button,t),isDisabled:e||o,isLoading:e,onBlur:z,testId:s},w),{onClick:M,ref:k,startIcon:u__default["default"].createElement(f36Icons.CopyIcon,{variant:"muted",size:l==="small"?"tiny":"small"}),variant:"secondary"})))}E.displayName="CopyButton";var j=u__default["default"].forwardRef(E);
16
16
 
17
17
  exports.CopyButton = j;
18
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/CopyButton.tsx","../src/CopyButton.styles.ts"],"names":["React","useCallback","useState","CopyIcon","Tooltip","Button","css","getCopyButtonStyles","size","buttonSize","cx","_CopyButton","_a","ref","_b","className","isDisabled","isLoading","label","onBlur","onCopy","testId","tooltipCopiedText","tooltipProps","tooltipText","value","otherProps","__objRest","styles","copied","setCopied","handleClick","__async","error","handleBlur","event","__spreadProps","__spreadValues","CopyButton"],"mappings":"4xBAAA,OAAOA,GACL,eAAAC,EACA,YAAAC,MAGK,QACP,OAAS,YAAAC,MAAgB,wBAEzB,OAAS,WAAAC,MAAkC,0BAC3C,OAAS,UAAAC,MAAgC,yBCTzC,OAAS,OAAAC,MAAW,UAGb,IAAMC,EAAsB,CAAC,CAClC,KAAAC,CACF,IAAqC,CACnC,IAAMC,EAAaD,IAAS,QAAU,OAAS,OAE/C,MAAO,CACL,OAAQF,EAAI,CACV,OAAQG,EACR,UAAW,OACX,SAAU,OACV,MAAOA,CACT,CAAC,CACH,CACF,EDLA,OAAS,MAAAC,MAAU,UA6CnB,SAASC,EACPC,EAeAC,EACA,CAhBA,IAAAC,EAAAF,EACE,WAAAG,EACA,WAAAC,EAAa,GACb,UAAAC,EAAY,GACZ,MAAAC,EACA,OAAAC,EACA,OAAAC,EACA,KAAAZ,EAAO,SACP,OAAAa,EAAS,oBACT,kBAAAC,EAAoB,UACpB,aAAAC,EACA,YAAAC,EAAc,oBACd,MAAAC,CArEJ,EAyDEX,EAaKY,EAAAC,EAbLb,EAaK,CAZH,YACA,aACA,YACA,QACA,SACA,SACA,OACA,SACA,oBACA,eACA,cACA,UAKF,IAAMc,EAASrB,EAAoB,CAAE,KAAAC,CAAK,CAAC,EACrC,CAACqB,EAAQC,CAAS,EAAI5B,EAAS,EAAK,EAEpC6B,EAAc9B,EAElB,IAAY+B,EAAA,sBACZ,GAAI,CACF,MAAM,OAAO,UAAU,UAAU,UAAUP,CAAK,CAClD,OAASQ,EAAP,CACA,QAAQ,MAAMA,CAAK,EACnB,MACF,CAEAb,GAAA,MAAAA,EAASK,GACTK,EAAU,EAAI,CAChB,GAAG,CAACV,EAAQK,CAAK,CAAC,EAEZS,EAAoDC,GAAU,CAC9DN,GACFC,EAAU,EAAK,EAGjBX,GAAA,MAAAA,EAASgB,EACX,EAEA,OACEnC,EAAA,cAACI,EAAAgC,EAAAC,EAAA,CACC,QAASR,EAASP,EAAoBE,GAClCD,GAFL,CAGC,WAAYP,IAEZhB,EAAA,cAACK,EAAA+B,EAAAC,EAAA,CACC,aACER,EAAS,4BAA8BX,GAAA,KAAAA,EAAS,oBAElD,YAAU,YACV,UAAWR,EAAGkB,EAAO,OAAQb,CAAS,EACtC,WAAYE,GAAaD,EACzB,UAAWC,EACX,OAAQiB,EACR,OAAQb,GACJK,GAVL,CAWC,QAASK,EACT,IAAKlB,EACL,UACEb,EAAA,cAACG,EAAA,CACC,QAAQ,QACR,KAAMK,IAAS,QAAU,OAAS,QACpC,EAEF,QAAQ,aACV,CACF,CAEJ,CAEAG,EAAY,YAAc,aAEnB,IAAM2B,EAAatC,EAAM,WAAWW,CAAW","sourcesContent":["import React, {\n useCallback,\n useState,\n type MouseEventHandler,\n type FocusEventHandler,\n} from 'react';\nimport { CopyIcon } from '@contentful/f36-icons';\nimport type { ExpandProps } from '@contentful/f36-core';\nimport { Tooltip, type TooltipProps } from '@contentful/f36-tooltip';\nimport { Button, type ButtonProps } from '@contentful/f36-button';\nimport { getCopyButtonStyles } from './CopyButton.styles';\nimport { cx } from 'emotion';\n\nexport type CopyButtonProps = Omit<\n ButtonProps,\n 'children' | 'endIcon' | 'onCopy' | 'startIcon' | 'isDisabed' | 'size'\n> & {\n /**\n * Function that gets called when the button is clicked\n */\n onCopy?: (string) => void;\n /**\n * Text to be shown when the button is clicked\n * @default Copied!\n */\n tooltipCopiedText?: string;\n /**\n * Text to be shown when button is hovered or focused\n * @default Copy to clipboard\n */\n tooltipText?: string;\n /**\n * Props that are passed to the tooltip component\n */\n tooltipProps?: Omit<TooltipProps, 'content' | 'children'>;\n /**\n * Label to be used on aria-label for the button\n * @default Copy to clipboard\n */\n label?: string;\n /**\n * Allows to disable the copy button, when true the tooltip would not be shown\n * @default false\n */\n isDisabled?: boolean;\n /**\n * Allows setting size of the copy button to small\n * @default medium\n */\n size?: 'small' | 'medium';\n /**\n * Value that will be copied to clipboard when the button is clicked\n */\n value: string;\n};\n\nfunction _CopyButton(\n {\n className,\n isDisabled = false,\n isLoading = false,\n label,\n onBlur,\n onCopy,\n size = 'medium',\n testId = 'cf-ui-copy-button',\n tooltipCopiedText = 'Copied!',\n tooltipProps,\n tooltipText = 'Copy to clipboard',\n value,\n ...otherProps\n }: ExpandProps<CopyButtonProps>,\n ref: React.Ref<HTMLButtonElement>,\n) {\n const styles = getCopyButtonStyles({ size });\n const [copied, setCopied] = useState(false);\n\n const handleClick = useCallback<\n MouseEventHandler<HTMLButtonElement>\n >(async () => {\n try {\n await window.navigator.clipboard.writeText(value);\n } catch (error) {\n console.error(error);\n return;\n }\n\n onCopy?.(value);\n setCopied(true);\n }, [onCopy, value]);\n\n const handleBlur: FocusEventHandler<HTMLButtonElement> = (event) => {\n if (copied) {\n setCopied(false);\n }\n\n onBlur?.(event);\n };\n\n return (\n <Tooltip\n content={copied ? tooltipCopiedText : tooltipText}\n {...tooltipProps}\n isDisabled={isDisabled}\n >\n <Button\n aria-label={\n copied ? 'Value copied to clipboard' : label ?? `Copy to clipboard`\n }\n aria-live=\"assertive\"\n className={cx(styles.button, className)}\n isDisabled={isLoading || isDisabled}\n isLoading={isLoading}\n onBlur={handleBlur}\n testId={testId}\n {...otherProps}\n onClick={handleClick}\n ref={ref}\n startIcon={\n <CopyIcon\n variant=\"muted\"\n size={size === 'small' ? 'tiny' : 'small'}\n />\n }\n variant=\"secondary\"\n />\n </Tooltip>\n );\n}\n\n_CopyButton.displayName = 'CopyButton';\n\nexport const CopyButton = React.forwardRef(_CopyButton);\n","import { css } from 'emotion';\nimport { CopyButtonProps } from './CopyButton';\n\nexport const getCopyButtonStyles = ({\n size,\n}: Pick<CopyButtonProps, 'size'>) => {\n const buttonSize = size === 'small' ? '32px' : '40px';\n\n return {\n button: css({\n height: buttonSize,\n minHeight: 'auto',\n minWidth: 'auto',\n width: buttonSize,\n }),\n };\n};\n"]}
1
+ {"version":3,"sources":["../src/CopyButton.tsx","../src/CopyButton.styles.ts"],"names":["React","useCallback","useState","CopyIcon","Tooltip","Button","css","getCopyButtonStyles","size","buttonSize","cx","_CopyButton","_a","ref","_b","className","isDisabled","isLoading","label","onBlur","onCopy","testId","tooltipCopiedText","tooltipProps","tooltipText","value","otherProps","__objRest","styles","copied","setCopied","handleClick","__async","error","handleBlur","event","__spreadProps","__spreadValues","CopyButton"],"mappings":"4xBAAA,OAAOA,GACL,eAAAC,EACA,YAAAC,MAGK,QACP,OAAS,YAAAC,MAAgB,wBAEzB,OAAS,WAAAC,MAAkC,0BAC3C,OAAS,UAAAC,MAAgC,yBCTzC,OAAS,OAAAC,MAAW,UAGb,IAAMC,EAAsB,CAAC,CAClC,KAAAC,CACF,IAAqC,CACnC,IAAMC,EAAaD,IAAS,QAAU,OAAS,OAE/C,MAAO,CACL,OAAQF,EAAI,CACV,OAAQG,EACR,UAAW,OACX,SAAU,OACV,MAAOA,CACT,CAAC,CACH,CACF,EDLA,OAAS,MAAAC,MAAU,UAqDnB,SAASC,EACPC,EAeAC,EACA,CAhBA,IAAAC,EAAAF,EACE,WAAAG,EACA,WAAAC,EAAa,GACb,UAAAC,EAAY,GACZ,MAAAC,EACA,OAAAC,EACA,OAAAC,EACA,KAAAZ,EAAO,SACP,OAAAa,EAAS,oBACT,kBAAAC,EAAoB,UACpB,aAAAC,EACA,YAAAC,EAAc,oBACd,MAAAC,CA7EJ,EAiEEX,EAaKY,EAAAC,EAbLb,EAaK,CAZH,YACA,aACA,YACA,QACA,SACA,SACA,OACA,SACA,oBACA,eACA,cACA,UAKF,IAAMc,EAASrB,EAAoB,CAAE,KAAAC,CAAK,CAAC,EACrC,CAACqB,EAAQC,CAAS,EAAI5B,EAAS,EAAK,EAEpC6B,EAAc9B,EAElB,IAAY+B,EAAA,sBACZ,GAAI,CACF,MAAM,OAAO,UAAU,UAAU,UAAUP,CAAK,CAClD,OAASQ,EAAP,CACA,QAAQ,MAAMA,CAAK,EACnB,MACF,CAEAb,GAAA,MAAAA,EAASK,GACTK,EAAU,EAAI,CAChB,GAAG,CAACV,EAAQK,CAAK,CAAC,EAEZS,EAAoDC,GAAU,CAC9DN,GACFC,EAAU,EAAK,EAGjBX,GAAA,MAAAA,EAASgB,EACX,EAEA,OACEnC,EAAA,cAACI,EAAAgC,EAAAC,EAAA,CACC,QAASR,EAASP,EAAoBE,GAClCD,GAFL,CAGC,WAAYP,IAEZhB,EAAA,cAACK,EAAA+B,EAAAC,EAAA,CACC,aACER,EAAS,4BAA8BX,GAAA,KAAAA,EAAS,oBAElD,YAAU,YACV,UAAWR,EAAGkB,EAAO,OAAQb,CAAS,EACtC,WAAYE,GAAaD,EACzB,UAAWC,EACX,OAAQiB,EACR,OAAQb,GACJK,GAVL,CAWC,QAASK,EACT,IAAKlB,EACL,UACEb,EAAA,cAACG,EAAA,CACC,QAAQ,QACR,KAAMK,IAAS,QAAU,OAAS,QACpC,EAEF,QAAQ,aACV,CACF,CAEJ,CAEAG,EAAY,YAAc,aAEnB,IAAM2B,EAAatC,EAAM,WAAWW,CAAW","sourcesContent":["import React, {\n useCallback,\n useState,\n type MouseEventHandler,\n type FocusEventHandler,\n} from 'react';\nimport { CopyIcon } from '@contentful/f36-icons';\nimport type { ExpandProps } from '@contentful/f36-core';\nimport { Tooltip, type TooltipProps } from '@contentful/f36-tooltip';\nimport { Button, type ButtonProps } from '@contentful/f36-button';\nimport { getCopyButtonStyles } from './CopyButton.styles';\nimport { cx } from 'emotion';\n\nexport type CopyButtonProps = Omit<\n ButtonProps,\n | 'children'\n | 'endIcon'\n | 'onCopy'\n | 'onClick'\n | 'startIcon'\n | 'isDisabled'\n | 'size'\n | 'value'\n | 'variant'\n> & {\n /**\n * Function that gets called when the button is clicked\n */\n onCopy?: (string) => void;\n /**\n * Text to be shown when the button is clicked\n * @default Copied!\n */\n tooltipCopiedText?: string;\n /**\n * Text to be shown when button is hovered or focused\n * @default Copy to clipboard\n */\n tooltipText?: string;\n /**\n * Props that are passed to the tooltip component\n */\n tooltipProps?: Omit<TooltipProps, 'content' | 'children'>;\n /**\n * Label to be used on aria-label for the button\n * @default Copy to clipboard\n */\n label?: string;\n /**\n * Allows to disable the copy button, when true the tooltip would not be shown\n * @default false\n */\n isDisabled?: boolean;\n /**\n * Allows setting size of the copy button to small\n * @default medium\n */\n size?: 'small' | 'medium';\n /**\n * Value that will be copied to clipboard when the button is clicked\n */\n value: string;\n};\n\nfunction _CopyButton(\n {\n className,\n isDisabled = false,\n isLoading = false,\n label,\n onBlur,\n onCopy,\n size = 'medium',\n testId = 'cf-ui-copy-button',\n tooltipCopiedText = 'Copied!',\n tooltipProps,\n tooltipText = 'Copy to clipboard',\n value,\n ...otherProps\n }: ExpandProps<CopyButtonProps>,\n ref: React.Ref<HTMLButtonElement>,\n) {\n const styles = getCopyButtonStyles({ size });\n const [copied, setCopied] = useState(false);\n\n const handleClick = useCallback<\n MouseEventHandler<HTMLButtonElement>\n >(async () => {\n try {\n await window.navigator.clipboard.writeText(value);\n } catch (error) {\n console.error(error);\n return;\n }\n\n onCopy?.(value);\n setCopied(true);\n }, [onCopy, value]);\n\n const handleBlur: FocusEventHandler<HTMLButtonElement> = (event) => {\n if (copied) {\n setCopied(false);\n }\n\n onBlur?.(event);\n };\n\n return (\n <Tooltip\n content={copied ? tooltipCopiedText : tooltipText}\n {...tooltipProps}\n isDisabled={isDisabled}\n >\n <Button\n aria-label={\n copied ? 'Value copied to clipboard' : label ?? `Copy to clipboard`\n }\n aria-live=\"assertive\"\n className={cx(styles.button, className)}\n isDisabled={isLoading || isDisabled}\n isLoading={isLoading}\n onBlur={handleBlur}\n testId={testId}\n {...otherProps}\n onClick={handleClick}\n ref={ref}\n startIcon={\n <CopyIcon\n variant=\"muted\"\n size={size === 'small' ? 'tiny' : 'small'}\n />\n }\n variant=\"secondary\"\n />\n </Tooltip>\n );\n}\n\n_CopyButton.displayName = 'CopyButton';\n\nexport const CopyButton = React.forwardRef(_CopyButton);\n","import { css } from 'emotion';\nimport { CopyButtonProps } from './CopyButton';\n\nexport const getCopyButtonStyles = ({\n size,\n}: Pick<CopyButtonProps, 'size'>) => {\n const buttonSize = size === 'small' ? '32px' : '40px';\n\n return {\n button: css({\n height: buttonSize,\n minHeight: 'auto',\n minWidth: 'auto',\n width: buttonSize,\n }),\n };\n};\n"]}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@contentful/f36-copybutton",
3
- "version": "4.25.1",
3
+ "version": "4.25.2",
4
4
  "description": "Forma 36: CopyButton component",
5
5
  "scripts": {
6
6
  "build": "tsup"
7
7
  },
8
8
  "dependencies": {
9
- "@contentful/f36-button": "^4.25.1",
10
- "@contentful/f36-core": "^4.25.1",
9
+ "@contentful/f36-button": "^4.25.2",
10
+ "@contentful/f36-core": "^4.25.2",
11
11
  "@contentful/f36-icons": "^4.23.2",
12
12
  "@contentful/f36-tokens": "^4.0.1",
13
- "@contentful/f36-tooltip": "^4.25.1",
13
+ "@contentful/f36-tooltip": "^4.25.2",
14
14
  "emotion": "^10.0.17"
15
15
  },
16
16
  "peerDependencies": {