@contentful/f36-copybutton 4.16.0 → 4.19.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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.19.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @contentful/f36-icons@4.19.0
9
+ - @contentful/f36-tooltip@4.19.0
10
+ - @contentful/f36-core@4.19.0
11
+
12
+ ## 4.18.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies []:
17
+ - @contentful/f36-icons@4.18.0
18
+ - @contentful/f36-tooltip@4.18.0
19
+ - @contentful/f36-core@4.18.0
20
+
21
+ ## 4.17.0
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies []:
26
+ - @contentful/f36-icons@4.17.0
27
+ - @contentful/f36-tooltip@4.17.0
28
+ - @contentful/f36-core@4.17.0
29
+
3
30
  ## 4.16.0
4
31
 
5
32
  ### Patch Changes
@@ -1,7 +1,8 @@
1
- import React from "react";
2
- import { CommonProps } from "@contentful/f36-core";
3
- import { TooltipProps } from "@contentful/f36-tooltip";
4
- export interface CopyButtonProps extends CommonProps {
1
+ import React from 'react';
2
+ import { CommonProps } from '@contentful/f36-core';
3
+ import { TooltipProps } from '@contentful/f36-tooltip';
4
+
5
+ interface CopyButtonProps extends CommonProps {
5
6
  /**
6
7
  * Function that gets called when the button is clicked
7
8
  */
@@ -40,6 +41,6 @@ export interface CopyButtonProps extends CommonProps {
40
41
  */
41
42
  size?: 'small' | 'medium';
42
43
  }
43
- export const CopyButton: React.ForwardRefExoticComponent<CopyButtonProps & React.RefAttributes<HTMLDivElement>>;
44
+ declare const CopyButton: React.ForwardRefExoticComponent<CopyButtonProps & React.RefAttributes<HTMLDivElement>>;
44
45
 
45
- //# sourceMappingURL=types.d.ts.map
46
+ export { CopyButton, CopyButtonProps };
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var emotion = require('emotion');
6
+ var n = require('react');
7
+ var j = require('react-copy-to-clipboard');
8
+ var f36Icons = require('@contentful/f36-icons');
9
+ var f36Tooltip = require('@contentful/f36-tooltip');
10
+ var i = require('@contentful/f36-tokens');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var n__default = /*#__PURE__*/_interopDefaultLegacy(n);
15
+ var j__default = /*#__PURE__*/_interopDefaultLegacy(j);
16
+ var i__default = /*#__PURE__*/_interopDefaultLegacy(i);
17
+
18
+ var N=Object.defineProperty,$=Object.defineProperties;var I=Object.getOwnPropertyDescriptors;var s=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var b=(o,t,e)=>t in o?N(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,u=(o,t)=>{for(var e in t||(t={}))f.call(t,e)&&b(o,e,t[e]);if(s)for(var e of s(t))C.call(t,e)&&b(o,e,t[e]);return o},g=(o,t)=>$(o,I(t));var x=(o,t)=>{var e={};for(var r in o)f.call(o,r)&&t.indexOf(r)<0&&(e[r]=o[r]);if(o!=null&&s)for(var r of s(o))t.indexOf(r)<0&&C.call(o,r)&&(e[r]=o[r]);return e};var h=({size:o})=>{let t=o==="small"?"32px":"40px";return {wrapper:emotion.css({display:"inline-block",height:t,position:"relative",width:t}),copyButton:emotion.css({alignItems:"center",background:i__default["default"].colorWhite,border:`1px solid ${i__default["default"].gray300}`,display:"inline-flex",height:"100%",justifyContent:"center",outline:"none",padding:0,transition:`background ${i__default["default"].transitionDurationShort} ${i__default["default"].transitionEasingDefault}`,width:"100%","&:hover":{backgroundColor:i__default["default"].gray100,cursor:"pointer"},"&:active":{backgroundColor:i__default["default"].gray200,cursor:"pointer"},"&:focus":{boxShadow:i__default["default"].glowMuted},"&:focus:not(:focus-visible)":{boxShadow:"unset"},"&:focus-visible":{boxShadow:i__default["default"].glowMuted}}),copyButtonDisabled:emotion.css({cursor:"not-allowed",backgroundColor:i__default["default"].gray100,"&:hover":{cursor:"not-allowed",backgroundColor:i__default["default"].gray100},"&:focus":{borderColor:i__default["default"].gray300,boxShadow:"none"},"&:active, &:active:hover":{borderColor:i__default["default"].gray300,boxShadow:"none"}})}};function w(o,t){let y=o,{onCopy:e,value:r,className:B,testId:T="cf-ui-copy-button",tooltipText:P="Copy to clipboard",tooltipCopiedText:S="Copied!",tooltipProps:k,isDisabled:p=!1,size:c="medium"}=y,D=x(y,["onCopy","value","className","testId","tooltipText","tooltipCopiedText","tooltipProps","isDisabled","size"]),l=h({size:c}),[E,m]=n.useState(!1),a=n.useRef(null),z=n.useCallback(M=>{e&&e(M),m(!0),setTimeout(()=>{m(!1),a.current&&a.current.blur();},1e3);},[e]);return n__default["default"].createElement("div",u({ref:t,"data-test-id":T,className:emotion.cx(l.wrapper,B)},D),n__default["default"].createElement(j__default["default"],{text:r,onCopy:z},n__default["default"].createElement(f36Tooltip.Tooltip,g(u({content:E?S:P},k),{isDisabled:p}),n__default["default"].createElement("button",{type:"button",ref:a,className:emotion.cx(l.copyButton,{[l.copyButtonDisabled]:p}),"aria-label":`Copy ${r} to clipboard`,disabled:p,"aria-live":"assertive"},n__default["default"].createElement(f36Icons.CopyIcon,{variant:"muted",size:c==="small"?"tiny":"small"})))))}w.displayName="CopyButton";var q=n__default["default"].forwardRef(w);
19
+
20
+ exports.CopyButton = q;
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/CopyButton.tsx","../src/CopyButton.styles.ts"],"names":["cx","React","useState","useCallback","useRef","CopyToClipboard","CopyIcon","Tooltip","css","tokens","getStyles","size","buttonSize","_CopyButton","props","ref","_a","onCopy","value","className","testId","tooltipText","tooltipCopiedText","tooltipProps","isDisabled","otherProps","__objRest","styles","copied","setCopied","button","handleOnCopy","e","__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AAb,EAAO,QA7DX,EA+DMK,EADCS,EAAAC,EACDV,EADC,CATH,SACA,QACA,YACA,SACA,cACA,oBACA,eACA,aACA,SAGIW,EAASjB,EAAU,CAAE,KAAAC,CAAK,CAAC,EAE3B,CAACiB,EAAQC,CAAS,EAAI3B,EAAS,EAAK,EACpC4B,EAAS1B,EAAiC,IAAI,EAC9C2B,EAAe5B,EAClB6B,GAAc,CACTf,GACFA,EAAOe,CAAC,EAGVH,EAAU,EAAI,EAEd,WAAW,IAAM,CACfA,EAAU,EAAK,EACXC,EAAO,SACTA,EAAO,QAAQ,KAAK,CAExB,EAAG,GAAI,CACT,EACA,CAACb,CAAM,CACT,EAEA,OACEhB,EAAA,cAAC,MAAAgC,EAAA,CACC,IAAKlB,EACL,eAAcK,EACd,UAAWpB,EAAG2B,EAAO,QAASR,CAAS,GACnCM,GAEJxB,EAAA,cAACI,EAAA,CAAgB,KAAMa,EAAO,OAAQa,GACpC9B,EAAA,cAACM,EAAA2B,EAAAD,EAAA,CACC,QAASL,EAASN,EAAoBD,GAClCE,GAFL,CAGC,WAAYC,IAEZvB,EAAA,cAAC,UACC,KAAK,SACL,IAAK6B,EACL,UAAW9B,EAAG2B,EAAO,WAAY,CAC/B,CAACA,EAAO,oBAAqBH,CAC/B,CAAC,EACD,aAAY,QAAQN,iBACpB,SAAUM,EACV,YAAU,aAEVvB,EAAA,cAACK,EAAA,CACC,QAAQ,QACR,KAAMK,IAAS,QAAU,OAAS,QACpC,CACF,CACF,CACF,CACF,CAEJ,CAEAE,EAAY,YAAc,aAEnB,IAAMsB,EAAalC,EAAM,WAAWY,CAAW","sourcesContent":["import { cx } from 'emotion';\nimport React, { useState, useCallback, useRef } from 'react';\nimport CopyToClipboard from 'react-copy-to-clipboard';\nimport { CopyIcon } from '@contentful/f36-icons';\nimport type { CommonProps, ExpandProps } from '@contentful/f36-core';\nimport { Tooltip, type TooltipProps } from '@contentful/f36-tooltip';\nimport { getStyles } from './CopyButton.styles';\n\nexport interface CopyButtonProps extends CommonProps {\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 * Value that will be copied to clipboard when the button is clicked\n */\n value: string;\n /**\n * Label to be used on aria-label for the button\n * @default Copy {value} 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\nfunction _CopyButton(\n props: ExpandProps<CopyButtonProps>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n onCopy,\n value,\n className,\n testId = 'cf-ui-copy-button',\n tooltipText = 'Copy to clipboard',\n tooltipCopiedText = 'Copied!',\n tooltipProps,\n isDisabled = false,\n size = 'medium',\n ...otherProps\n } = props;\n const styles = getStyles({ size });\n\n const [copied, setCopied] = useState(false);\n const button = useRef<HTMLButtonElement | null>(null);\n const handleOnCopy = useCallback(\n (e: string) => {\n if (onCopy) {\n onCopy(e);\n }\n\n setCopied(true);\n\n setTimeout(() => {\n setCopied(false);\n if (button.current) {\n button.current.blur();\n }\n }, 1000);\n },\n [onCopy],\n );\n\n return (\n <div\n ref={ref}\n data-test-id={testId}\n className={cx(styles.wrapper, className)}\n {...otherProps}\n >\n <CopyToClipboard text={value} onCopy={handleOnCopy}>\n <Tooltip\n content={copied ? tooltipCopiedText : tooltipText}\n {...tooltipProps}\n isDisabled={isDisabled}\n >\n <button\n type=\"button\"\n ref={button}\n className={cx(styles.copyButton, {\n [styles.copyButtonDisabled]: isDisabled,\n })}\n aria-label={`Copy ${value} to clipboard`}\n disabled={isDisabled}\n aria-live=\"assertive\"\n >\n <CopyIcon\n variant=\"muted\"\n size={size === 'small' ? 'tiny' : 'small'}\n />\n </button>\n </Tooltip>\n </CopyToClipboard>\n </div>\n );\n}\n\n_CopyButton.displayName = 'CopyButton';\n\nexport const CopyButton = React.forwardRef(_CopyButton);\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getStyles = ({ size }) => {\n const buttonSize = size === 'small' ? '32px' : '40px';\n\n return {\n wrapper: css({\n display: 'inline-block',\n height: buttonSize,\n position: 'relative',\n width: buttonSize,\n }),\n copyButton: css({\n alignItems: 'center',\n background: tokens.colorWhite,\n border: `1px solid ${tokens.gray300}`,\n display: 'inline-flex',\n height: '100%',\n justifyContent: 'center',\n outline: 'none',\n padding: 0,\n transition: `background ${tokens.transitionDurationShort} ${tokens.transitionEasingDefault}`,\n width: '100%',\n '&:hover': {\n backgroundColor: tokens.gray100,\n cursor: 'pointer',\n },\n '&:active': {\n backgroundColor: tokens.gray200,\n cursor: 'pointer',\n },\n '&:focus': {\n boxShadow: tokens.glowMuted,\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: 'unset',\n },\n '&:focus-visible': {\n boxShadow: tokens.glowMuted,\n },\n }),\n copyButtonDisabled: css({\n cursor: 'not-allowed',\n backgroundColor: tokens.gray100,\n\n '&:hover': {\n cursor: 'not-allowed',\n backgroundColor: tokens.gray100,\n },\n\n '&:focus': {\n borderColor: tokens.gray300,\n boxShadow: 'none',\n },\n\n '&:active, &:active:hover': {\n borderColor: tokens.gray300,\n boxShadow: 'none',\n },\n }),\n };\n};\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,11 @@
1
+ import { cx, css } from 'emotion';
2
+ import n, { useState, useRef, useCallback } from 'react';
3
+ import j from 'react-copy-to-clipboard';
4
+ import { CopyIcon } from '@contentful/f36-icons';
5
+ import { Tooltip } from '@contentful/f36-tooltip';
6
+ import i from '@contentful/f36-tokens';
7
+
8
+ var N=Object.defineProperty,$=Object.defineProperties;var I=Object.getOwnPropertyDescriptors;var s=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var b=(o,t,e)=>t in o?N(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,u=(o,t)=>{for(var e in t||(t={}))f.call(t,e)&&b(o,e,t[e]);if(s)for(var e of s(t))C.call(t,e)&&b(o,e,t[e]);return o},g=(o,t)=>$(o,I(t));var x=(o,t)=>{var e={};for(var r in o)f.call(o,r)&&t.indexOf(r)<0&&(e[r]=o[r]);if(o!=null&&s)for(var r of s(o))t.indexOf(r)<0&&C.call(o,r)&&(e[r]=o[r]);return e};var h=({size:o})=>{let t=o==="small"?"32px":"40px";return {wrapper:css({display:"inline-block",height:t,position:"relative",width:t}),copyButton:css({alignItems:"center",background:i.colorWhite,border:`1px solid ${i.gray300}`,display:"inline-flex",height:"100%",justifyContent:"center",outline:"none",padding:0,transition:`background ${i.transitionDurationShort} ${i.transitionEasingDefault}`,width:"100%","&:hover":{backgroundColor:i.gray100,cursor:"pointer"},"&:active":{backgroundColor:i.gray200,cursor:"pointer"},"&:focus":{boxShadow:i.glowMuted},"&:focus:not(:focus-visible)":{boxShadow:"unset"},"&:focus-visible":{boxShadow:i.glowMuted}}),copyButtonDisabled:css({cursor:"not-allowed",backgroundColor:i.gray100,"&:hover":{cursor:"not-allowed",backgroundColor:i.gray100},"&:focus":{borderColor:i.gray300,boxShadow:"none"},"&:active, &:active:hover":{borderColor:i.gray300,boxShadow:"none"}})}};function w(o,t){let y=o,{onCopy:e,value:r,className:B,testId:T="cf-ui-copy-button",tooltipText:P="Copy to clipboard",tooltipCopiedText:S="Copied!",tooltipProps:k,isDisabled:p=!1,size:c="medium"}=y,D=x(y,["onCopy","value","className","testId","tooltipText","tooltipCopiedText","tooltipProps","isDisabled","size"]),l=h({size:c}),[E,m]=useState(!1),a=useRef(null),z=useCallback(M=>{e&&e(M),m(!0),setTimeout(()=>{m(!1),a.current&&a.current.blur();},1e3);},[e]);return n.createElement("div",u({ref:t,"data-test-id":T,className:cx(l.wrapper,B)},D),n.createElement(j,{text:r,onCopy:z},n.createElement(Tooltip,g(u({content:E?S:P},k),{isDisabled:p}),n.createElement("button",{type:"button",ref:a,className:cx(l.copyButton,{[l.copyButtonDisabled]:p}),"aria-label":`Copy ${r} to clipboard`,disabled:p,"aria-live":"assertive"},n.createElement(CopyIcon,{variant:"muted",size:c==="small"?"tiny":"small"})))))}w.displayName="CopyButton";var q=n.forwardRef(w);
9
+
10
+ export { q as CopyButton };
11
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/CopyButton.tsx","../src/CopyButton.styles.ts"],"names":["cx","React","useState","useCallback","useRef","CopyToClipboard","CopyIcon","Tooltip","css","tokens","getStyles","size","buttonSize","_CopyButton","props","ref","_a","onCopy","value","className","testId","tooltipText","tooltipCopiedText","tooltipProps","isDisabled","otherProps","__objRest","styles","copied","setCopied","button","handleOnCopy","e","__spreadValues","__spreadProps","CopyButton"],"mappings":"+kBAAA,OAAS,MAAAA,MAAU,UACnB,OAAOC,GAAS,YAAAC,EAAU,eAAAC,EAAa,UAAAC,MAAc,QACrD,OAAOC,MAAqB,0BAC5B,OAAS,YAAAC,MAAgB,wBAEzB,OAAS,WAAAC,MAAkC,0BCL3C,OAAS,OAAAC,MAAW,UACpB,OAAOC,MAAY,yBAEZ,IAAMC,EAAY,CAAC,CAAE,KAAAC,CAAK,IAAM,CACrC,IAAMC,EAAaD,IAAS,QAAU,OAAS,OAE/C,MAAO,CACL,QAASH,EAAI,CACX,QAAS,eACT,OAAQI,EACR,SAAU,WACV,MAAOA,CACT,CAAC,EACD,WAAYJ,EAAI,CACd,WAAY,SACZ,WAAYC,EAAO,WACnB,OAAQ,aAAaA,EAAO,UAC5B,QAAS,cACT,OAAQ,OACR,eAAgB,SAChB,QAAS,OACT,QAAS,EACT,WAAY,cAAcA,EAAO,2BAA2BA,EAAO,0BACnE,MAAO,OACP,UAAW,CACT,gBAAiBA,EAAO,QACxB,OAAQ,SAC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FL,CAGC,WAAYC,IAEZvB,EAAA,cAAC,UACC,KAAK,SACL,IAAK6B,EACL,UAAW9B,EAAG2B,EAAO,WAAY,CAC/B,CAACA,EAAO,oBAAqBH,CAC/B,CAAC,EACD,aAAY,QAAQN,iBACpB,SAAUM,EACV,YAAU,aAEVvB,EAAA,cAACK,EAAA,CACC,QAAQ,QACR,KAAMK,IAAS,QAAU,OAAS,QACpC,CACF,CACF,CACF,CACF,CAEJ,CAEAE,EAAY,YAAc,aAEnB,IAAMsB,EAAalC,EAAM,WAAWY,CAAW","sourcesContent":["import { cx } from 'emotion';\nimport React, { useState, useCallback, useRef } from 'react';\nimport CopyToClipboard from 'react-copy-to-clipboard';\nimport { CopyIcon } from '@contentful/f36-icons';\nimport type { CommonProps, ExpandProps } from '@contentful/f36-core';\nimport { Tooltip, type TooltipProps } from '@contentful/f36-tooltip';\nimport { getStyles } from './CopyButton.styles';\n\nexport interface CopyButtonProps extends CommonProps {\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 * Value that will be copied to clipboard when the button is clicked\n */\n value: string;\n /**\n * Label to be used on aria-label for the button\n * @default Copy {value} 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\nfunction _CopyButton(\n props: ExpandProps<CopyButtonProps>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n onCopy,\n value,\n className,\n testId = 'cf-ui-copy-button',\n tooltipText = 'Copy to clipboard',\n tooltipCopiedText = 'Copied!',\n tooltipProps,\n isDisabled = false,\n size = 'medium',\n ...otherProps\n } = props;\n const styles = getStyles({ size });\n\n const [copied, setCopied] = useState(false);\n const button = useRef<HTMLButtonElement | null>(null);\n const handleOnCopy = useCallback(\n (e: string) => {\n if (onCopy) {\n onCopy(e);\n }\n\n setCopied(true);\n\n setTimeout(() => {\n setCopied(false);\n if (button.current) {\n button.current.blur();\n }\n }, 1000);\n },\n [onCopy],\n );\n\n return (\n <div\n ref={ref}\n data-test-id={testId}\n className={cx(styles.wrapper, className)}\n {...otherProps}\n >\n <CopyToClipboard text={value} onCopy={handleOnCopy}>\n <Tooltip\n content={copied ? tooltipCopiedText : tooltipText}\n {...tooltipProps}\n isDisabled={isDisabled}\n >\n <button\n type=\"button\"\n ref={button}\n className={cx(styles.copyButton, {\n [styles.copyButtonDisabled]: isDisabled,\n })}\n aria-label={`Copy ${value} to clipboard`}\n disabled={isDisabled}\n aria-live=\"assertive\"\n >\n <CopyIcon\n variant=\"muted\"\n size={size === 'small' ? 'tiny' : 'small'}\n />\n </button>\n </Tooltip>\n </CopyToClipboard>\n </div>\n );\n}\n\n_CopyButton.displayName = 'CopyButton';\n\nexport const CopyButton = React.forwardRef(_CopyButton);\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getStyles = ({ size }) => {\n const buttonSize = size === 'small' ? '32px' : '40px';\n\n return {\n wrapper: css({\n display: 'inline-block',\n height: buttonSize,\n position: 'relative',\n width: buttonSize,\n }),\n copyButton: css({\n alignItems: 'center',\n background: tokens.colorWhite,\n border: `1px solid ${tokens.gray300}`,\n display: 'inline-flex',\n height: '100%',\n justifyContent: 'center',\n outline: 'none',\n padding: 0,\n transition: `background ${tokens.transitionDurationShort} ${tokens.transitionEasingDefault}`,\n width: '100%',\n '&:hover': {\n backgroundColor: tokens.gray100,\n cursor: 'pointer',\n },\n '&:active': {\n backgroundColor: tokens.gray200,\n cursor: 'pointer',\n },\n '&:focus': {\n boxShadow: tokens.glowMuted,\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: 'unset',\n },\n '&:focus-visible': {\n boxShadow: tokens.glowMuted,\n },\n }),\n copyButtonDisabled: css({\n cursor: 'not-allowed',\n backgroundColor: tokens.gray100,\n\n '&:hover': {\n cursor: 'not-allowed',\n backgroundColor: tokens.gray100,\n },\n\n '&:focus': {\n borderColor: tokens.gray300,\n boxShadow: 'none',\n },\n\n '&:active, &:active:hover': {\n borderColor: tokens.gray300,\n boxShadow: 'none',\n },\n }),\n };\n};\n"]}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@contentful/f36-copybutton",
3
- "version": "4.16.0",
3
+ "version": "4.19.0",
4
4
  "description": "Forma 36: CopyButton component",
5
5
  "scripts": {
6
- "build": "parcel build"
6
+ "build": "tsup"
7
7
  },
8
8
  "dependencies": {
9
9
  "@babel/runtime": "^7.6.2",
10
- "@contentful/f36-core": "^4.16.0",
11
- "@contentful/f36-icons": "^4.16.0",
10
+ "@contentful/f36-core": "^4.19.0",
11
+ "@contentful/f36-icons": "^4.19.0",
12
12
  "@contentful/f36-tokens": "^4.0.1",
13
- "@contentful/f36-tooltip": "^4.16.0",
13
+ "@contentful/f36-tooltip": "^4.19.0",
14
14
  "emotion": "^10.0.17",
15
15
  "react-copy-to-clipboard": "^5.1.0"
16
16
  },
@@ -21,9 +21,9 @@
21
21
  "files": [
22
22
  "dist"
23
23
  ],
24
- "main": "dist/main.js",
25
- "module": "dist/module.js",
26
- "types": "dist/types.d.ts",
24
+ "main": "dist/index.js",
25
+ "module": "dist/index.mjs",
26
+ "types": "dist/index.d.ts",
27
27
  "source": "src/index.ts",
28
28
  "sideEffects": false,
29
29
  "browserslist": "extends @contentful/browserslist-config",
package/dist/main.js DELETED
@@ -1,130 +0,0 @@
1
- var $2mOCL$emotion = require("emotion");
2
- var $2mOCL$react = require("react");
3
- var $2mOCL$reactcopytoclipboard = require("react-copy-to-clipboard");
4
- var $2mOCL$contentfulf36icons = require("@contentful/f36-icons");
5
- var $2mOCL$contentfulf36tooltip = require("@contentful/f36-tooltip");
6
- var $2mOCL$contentfulf36tokens = require("@contentful/f36-tokens");
7
-
8
- function $parcel$export(e, n, v, s) {
9
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
- }
11
- function $parcel$interopDefault(a) {
12
- return a && a.__esModule ? a.default : a;
13
- }
14
-
15
- $parcel$export(module.exports, "CopyButton", () => $7cfc52ec8d291deb$export$4f2558dd25106ae2);
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
- const $a21422a7510521de$export$ffd58b7f6f099a57 = ({ size: size })=>{
24
- const buttonSize = size === "small" ? "32px" : "40px";
25
- return {
26
- wrapper: /*#__PURE__*/ (0, $2mOCL$emotion.css)({
27
- display: "inline-block",
28
- height: buttonSize,
29
- position: "relative",
30
- width: buttonSize
31
- }),
32
- copyButton: /*#__PURE__*/ (0, $2mOCL$emotion.css)({
33
- alignItems: "center",
34
- background: (0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).colorWhite,
35
- border: `1px solid ${(0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).gray300}`,
36
- display: "inline-flex",
37
- height: "100%",
38
- justifyContent: "center",
39
- outline: "none",
40
- padding: 0,
41
- transition: `background ${(0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).transitionDurationShort} ${(0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).transitionEasingDefault}`,
42
- width: "100%",
43
- "&:hover": {
44
- backgroundColor: (0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).gray100,
45
- cursor: "pointer"
46
- },
47
- "&:active": {
48
- backgroundColor: (0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).gray200,
49
- cursor: "pointer"
50
- },
51
- "&:focus": {
52
- boxShadow: (0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).glowMuted
53
- },
54
- "&:focus:not(:focus-visible)": {
55
- boxShadow: "unset"
56
- },
57
- "&:focus-visible": {
58
- boxShadow: (0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).glowMuted
59
- }
60
- }),
61
- copyButtonDisabled: /*#__PURE__*/ (0, $2mOCL$emotion.css)({
62
- cursor: "not-allowed",
63
- backgroundColor: (0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).gray100,
64
- "&:hover": {
65
- cursor: "not-allowed",
66
- backgroundColor: (0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).gray100
67
- },
68
- "&:focus": {
69
- borderColor: (0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).gray300,
70
- boxShadow: "none"
71
- },
72
- "&:active, &:active:hover": {
73
- borderColor: (0, ($parcel$interopDefault($2mOCL$contentfulf36tokens))).gray300,
74
- boxShadow: "none"
75
- }
76
- })
77
- };
78
- };
79
-
80
-
81
- function $7cfc52ec8d291deb$var$_CopyButton(props, ref) {
82
- const { onCopy: onCopy , value: value , className: className , testId: testId = "cf-ui-copy-button" , tooltipText: tooltipText = "Copy to clipboard" , tooltipCopiedText: tooltipCopiedText = "Copied!" , tooltipProps: tooltipProps , isDisabled: isDisabled = false , size: size = "medium" , ...otherProps } = props;
83
- const styles = (0, $a21422a7510521de$export$ffd58b7f6f099a57)({
84
- size: size
85
- });
86
- const [copied, setCopied] = (0, $2mOCL$react.useState)(false);
87
- const button = (0, $2mOCL$react.useRef)(null);
88
- const handleOnCopy = (0, $2mOCL$react.useCallback)((e)=>{
89
- if (onCopy) onCopy(e);
90
- setCopied(true);
91
- setTimeout(()=>{
92
- setCopied(false);
93
- if (button.current) button.current.blur();
94
- }, 1000);
95
- }, [
96
- onCopy
97
- ]);
98
- return /*#__PURE__*/ (0, ($parcel$interopDefault($2mOCL$react))).createElement("div", {
99
- ref: ref,
100
- "data-test-id": testId,
101
- className: (0, $2mOCL$emotion.cx)(styles.wrapper, className),
102
- ...otherProps
103
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($2mOCL$react))).createElement((0, ($parcel$interopDefault($2mOCL$reactcopytoclipboard))), {
104
- text: value,
105
- onCopy: handleOnCopy
106
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($2mOCL$react))).createElement((0, $2mOCL$contentfulf36tooltip.Tooltip), {
107
- content: copied ? tooltipCopiedText : tooltipText,
108
- ...tooltipProps,
109
- isDisabled: isDisabled
110
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($2mOCL$react))).createElement("button", {
111
- type: "button",
112
- ref: button,
113
- className: (0, $2mOCL$emotion.cx)(styles.copyButton, {
114
- [styles.copyButtonDisabled]: isDisabled
115
- }),
116
- "aria-label": `Copy ${value} to clipboard`,
117
- disabled: isDisabled,
118
- "aria-live": "assertive"
119
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($2mOCL$react))).createElement((0, $2mOCL$contentfulf36icons.CopyIcon), {
120
- variant: "muted",
121
- size: size === "small" ? "tiny" : "small"
122
- })))));
123
- }
124
- $7cfc52ec8d291deb$var$_CopyButton.displayName = "CopyButton";
125
- const $7cfc52ec8d291deb$export$4f2558dd25106ae2 = /*#__PURE__*/ (0, ($parcel$interopDefault($2mOCL$react))).forwardRef($7cfc52ec8d291deb$var$_CopyButton);
126
-
127
-
128
-
129
-
130
- //# sourceMappingURL=main.js.map
package/dist/main.js.map DELETED
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;;;A;;;;;A;;AEGO,MAAMY,yCAAS,GAAG,CAAC,QAAEU,IAAAA,CAAAA,EAAH,GAAc;IACrC,MAAMyB,UAAU,GAAGzB,IAAI,KAAK,OAAT,GAAmB,MAAnB,GAA4B,MAA/C,AAAA;IAEA,OAAO;QACLmB,OAAO,EAAA,aAAE,CAAA,CAAA,GAAA,kBAAA,CAAA,CAAI;YACXO,OAAO,EAAE,cADE;YAEXC,MAAM,EAAEF,UAFG;YAGXG,QAAQ,EAAE,UAHC;YAIXC,KAAK,EAAEJ,UAAPI;SAJO,CADJ;QAOLT,UAAU,EAAA,aAAE,CAAA,CAAA,GAAA,kBAAA,CAAA,CAAI;YACdU,UAAU,EAAE,QADE;YAEdC,UAAU,EAAEP,CAAA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AAC,KAAD;QACE,GAAA,EAAKY,GAAD;QACJ,cAAA,EAAcI,MAAD;QACb,SAAA,EAAW,CAAA,GAAA,iBAAA,CAAA,CAAGE,MAAM,CAACU,OAAV,EAAmBb,SAAnB,CAAD;QACV,GAAIE,UAAJ;qBAEA,0DAAC,CAAA,GAAA,qDAAD,CAAA;QAAiB,IAAA,EAAMX,KAAD;QAAQ,MAAA,EAAQiB,YAAD;qBACnC,0DAAC,CAAA,GAAA,mCAAD,CAAA;QACE,OAAA,EAASJ,MAAM,GAAGjB,iBAAH,GAAuBC,WAA9B;QACR,GAAIC,YAAJ;QACA,UAAA,EAAYI,UAAD;qBAEX,0DAAC,QAAD;QACE,IAAA,EAAK,QADP;QAEE,GAAA,EAAKa,MAAD;QACJ,SAAA,EAAW,CAAA,GAAA,iBAAA,CAAA,CAAGH,MAAM,CAACW,UAAV,EAAsB;YAC/B,CAACX,MAAM,CAACY,kBAAR,CAAA,EAA6BtB,UAA7B;SADS,CAAD;QAGV,YAAA,EAAa,CAAA,KAAA,EAAOF,KAAM,CAAA,aAAA,CAAf;QACX,QAAA,EAAUE,UAAD;QACT,WAAA,EAAU,WARZ;qBAUE,0DAAC,CAAA,GAAA,kCAAD,CAAA;QACE,OAAA,EAAQ,OADV;QAEE,IAAA,EAAMC,IAAI,KAAK,OAAT,GAAmB,MAAnB,GAA4B,OAA7B;MAFnB,CAIA,CACA,CACA,CA7BE,CA8BF;CAEC;AAEDC,iCAAW,CAACqB,WAAZ,GAA0B,YAA1B,CAAArB;AAEO,MAAMvB,yCAAU,iBAAGE,CAAAA,GAAAA,sCAAK,CAAA,CAAC2C,UAAN,CAAiBtB,iCAAjB,CAAnB,AAAP;;AD1HA","sources":["packages/components/copybutton/src/index.ts","packages/components/copybutton/src/CopyButton.tsx","packages/components/copybutton/src/CopyButton.styles.ts"],"sourcesContent":["export { CopyButton } from './CopyButton';\nexport type { CopyButtonProps } from './CopyButton';\n","import { cx } from 'emotion';\nimport React, { useState, useCallback, useRef } from 'react';\nimport CopyToClipboard from 'react-copy-to-clipboard';\nimport { CopyIcon } from '@contentful/f36-icons';\nimport type { CommonProps, ExpandProps } from '@contentful/f36-core';\nimport { Tooltip, type TooltipProps } from '@contentful/f36-tooltip';\nimport { getStyles } from './CopyButton.styles';\n\nexport interface CopyButtonProps extends CommonProps {\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 * Value that will be copied to clipboard when the button is clicked\n */\n value: string;\n /**\n * Label to be used on aria-label for the button\n * @default Copy {value} 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\nfunction _CopyButton(\n props: ExpandProps<CopyButtonProps>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n onCopy,\n value,\n className,\n testId = 'cf-ui-copy-button',\n tooltipText = 'Copy to clipboard',\n tooltipCopiedText = 'Copied!',\n tooltipProps,\n isDisabled = false,\n size = 'medium',\n ...otherProps\n } = props;\n const styles = getStyles({ size });\n\n const [copied, setCopied] = useState(false);\n const button = useRef<HTMLButtonElement | null>(null);\n const handleOnCopy = useCallback(\n (e: string) => {\n if (onCopy) {\n onCopy(e);\n }\n\n setCopied(true);\n\n setTimeout(() => {\n setCopied(false);\n if (button.current) {\n button.current.blur();\n }\n }, 1000);\n },\n [onCopy],\n );\n\n return (\n <div\n ref={ref}\n data-test-id={testId}\n className={cx(styles.wrapper, className)}\n {...otherProps}\n >\n <CopyToClipboard text={value} onCopy={handleOnCopy}>\n <Tooltip\n content={copied ? tooltipCopiedText : tooltipText}\n {...tooltipProps}\n isDisabled={isDisabled}\n >\n <button\n type=\"button\"\n ref={button}\n className={cx(styles.copyButton, {\n [styles.copyButtonDisabled]: isDisabled,\n })}\n aria-label={`Copy ${value} to clipboard`}\n disabled={isDisabled}\n aria-live=\"assertive\"\n >\n <CopyIcon\n variant=\"muted\"\n size={size === 'small' ? 'tiny' : 'small'}\n />\n </button>\n </Tooltip>\n </CopyToClipboard>\n </div>\n );\n}\n\n_CopyButton.displayName = 'CopyButton';\n\nexport const CopyButton = React.forwardRef(_CopyButton);\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getStyles = ({ size }) => {\n const buttonSize = size === 'small' ? '32px' : '40px';\n\n return {\n wrapper: css({\n display: 'inline-block',\n height: buttonSize,\n position: 'relative',\n width: buttonSize,\n }),\n copyButton: css({\n alignItems: 'center',\n background: tokens.colorWhite,\n border: `1px solid ${tokens.gray300}`,\n display: 'inline-flex',\n height: '100%',\n justifyContent: 'center',\n outline: 'none',\n padding: 0,\n transition: `background ${tokens.transitionDurationShort} ${tokens.transitionEasingDefault}`,\n width: '100%',\n '&:hover': {\n backgroundColor: tokens.gray100,\n cursor: 'pointer',\n },\n '&:active': {\n backgroundColor: tokens.gray200,\n cursor: 'pointer',\n },\n '&:focus': {\n boxShadow: tokens.glowMuted,\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: 'unset',\n },\n '&:focus-visible': {\n boxShadow: tokens.glowMuted,\n },\n }),\n copyButtonDisabled: css({\n cursor: 'not-allowed',\n backgroundColor: tokens.gray100,\n\n '&:hover': {\n cursor: 'not-allowed',\n backgroundColor: tokens.gray100,\n },\n\n '&:focus': {\n borderColor: tokens.gray300,\n boxShadow: 'none',\n },\n\n '&:active, &:active:hover': {\n borderColor: tokens.gray300,\n boxShadow: 'none',\n },\n }),\n };\n};\n"],"names":["CopyButton","CopyButtonProps","React","useState","useCallback","useRef","CopyToClipboard","CopyIcon","CommonProps","ExpandProps","Tooltip","TooltipProps","getStyles","onCopy","string","tooltipCopiedText","tooltipText","tooltipProps","Omit","value","label","isDisabled","size","_CopyButton","props","ref","Ref","HTMLDivElement","className","testId","otherProps","styles","copied","setCopied","button","HTMLButtonElement","handleOnCopy","e","setTimeout","current","blur","wrapper","copyButton","copyButtonDisabled","displayName","forwardRef","tokens","buttonSize","display","height","position","width","alignItems","background","colorWhite","border","gray300","justifyContent","outline","padding","transition","transitionDurationShort","transitionEasingDefault","backgroundColor","gray100","cursor","gray200","boxShadow","glowMuted","borderColor"],"version":3,"file":"main.js.map"}
package/dist/module.js DELETED
@@ -1,123 +0,0 @@
1
- import {cx as $dnnsg$cx, css as $dnnsg$css} from "emotion";
2
- import $dnnsg$react, {useState as $dnnsg$useState, useRef as $dnnsg$useRef, useCallback as $dnnsg$useCallback} from "react";
3
- import $dnnsg$reactcopytoclipboard from "react-copy-to-clipboard";
4
- import {CopyIcon as $dnnsg$CopyIcon} from "@contentful/f36-icons";
5
- import {Tooltip as $dnnsg$Tooltip} from "@contentful/f36-tooltip";
6
- import $dnnsg$contentfulf36tokens from "@contentful/f36-tokens";
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
- const $c5d0896db030b9aa$export$ffd58b7f6f099a57 = ({ size: size })=>{
16
- const buttonSize = size === "small" ? "32px" : "40px";
17
- return {
18
- wrapper: /*#__PURE__*/ (0, $dnnsg$css)({
19
- display: "inline-block",
20
- height: buttonSize,
21
- position: "relative",
22
- width: buttonSize
23
- }),
24
- copyButton: /*#__PURE__*/ (0, $dnnsg$css)({
25
- alignItems: "center",
26
- background: (0, $dnnsg$contentfulf36tokens).colorWhite,
27
- border: `1px solid ${(0, $dnnsg$contentfulf36tokens).gray300}`,
28
- display: "inline-flex",
29
- height: "100%",
30
- justifyContent: "center",
31
- outline: "none",
32
- padding: 0,
33
- transition: `background ${(0, $dnnsg$contentfulf36tokens).transitionDurationShort} ${(0, $dnnsg$contentfulf36tokens).transitionEasingDefault}`,
34
- width: "100%",
35
- "&:hover": {
36
- backgroundColor: (0, $dnnsg$contentfulf36tokens).gray100,
37
- cursor: "pointer"
38
- },
39
- "&:active": {
40
- backgroundColor: (0, $dnnsg$contentfulf36tokens).gray200,
41
- cursor: "pointer"
42
- },
43
- "&:focus": {
44
- boxShadow: (0, $dnnsg$contentfulf36tokens).glowMuted
45
- },
46
- "&:focus:not(:focus-visible)": {
47
- boxShadow: "unset"
48
- },
49
- "&:focus-visible": {
50
- boxShadow: (0, $dnnsg$contentfulf36tokens).glowMuted
51
- }
52
- }),
53
- copyButtonDisabled: /*#__PURE__*/ (0, $dnnsg$css)({
54
- cursor: "not-allowed",
55
- backgroundColor: (0, $dnnsg$contentfulf36tokens).gray100,
56
- "&:hover": {
57
- cursor: "not-allowed",
58
- backgroundColor: (0, $dnnsg$contentfulf36tokens).gray100
59
- },
60
- "&:focus": {
61
- borderColor: (0, $dnnsg$contentfulf36tokens).gray300,
62
- boxShadow: "none"
63
- },
64
- "&:active, &:active:hover": {
65
- borderColor: (0, $dnnsg$contentfulf36tokens).gray300,
66
- boxShadow: "none"
67
- }
68
- })
69
- };
70
- };
71
-
72
-
73
- function $b6698237aa721326$var$_CopyButton(props, ref) {
74
- const { onCopy: onCopy , value: value , className: className , testId: testId = "cf-ui-copy-button" , tooltipText: tooltipText = "Copy to clipboard" , tooltipCopiedText: tooltipCopiedText = "Copied!" , tooltipProps: tooltipProps , isDisabled: isDisabled = false , size: size = "medium" , ...otherProps } = props;
75
- const styles = (0, $c5d0896db030b9aa$export$ffd58b7f6f099a57)({
76
- size: size
77
- });
78
- const [copied, setCopied] = (0, $dnnsg$useState)(false);
79
- const button = (0, $dnnsg$useRef)(null);
80
- const handleOnCopy = (0, $dnnsg$useCallback)((e)=>{
81
- if (onCopy) onCopy(e);
82
- setCopied(true);
83
- setTimeout(()=>{
84
- setCopied(false);
85
- if (button.current) button.current.blur();
86
- }, 1000);
87
- }, [
88
- onCopy
89
- ]);
90
- return /*#__PURE__*/ (0, $dnnsg$react).createElement("div", {
91
- ref: ref,
92
- "data-test-id": testId,
93
- className: (0, $dnnsg$cx)(styles.wrapper, className),
94
- ...otherProps
95
- }, /*#__PURE__*/ (0, $dnnsg$react).createElement((0, $dnnsg$reactcopytoclipboard), {
96
- text: value,
97
- onCopy: handleOnCopy
98
- }, /*#__PURE__*/ (0, $dnnsg$react).createElement((0, $dnnsg$Tooltip), {
99
- content: copied ? tooltipCopiedText : tooltipText,
100
- ...tooltipProps,
101
- isDisabled: isDisabled
102
- }, /*#__PURE__*/ (0, $dnnsg$react).createElement("button", {
103
- type: "button",
104
- ref: button,
105
- className: (0, $dnnsg$cx)(styles.copyButton, {
106
- [styles.copyButtonDisabled]: isDisabled
107
- }),
108
- "aria-label": `Copy ${value} to clipboard`,
109
- disabled: isDisabled,
110
- "aria-live": "assertive"
111
- }, /*#__PURE__*/ (0, $dnnsg$react).createElement((0, $dnnsg$CopyIcon), {
112
- variant: "muted",
113
- size: size === "small" ? "tiny" : "small"
114
- })))));
115
- }
116
- $b6698237aa721326$var$_CopyButton.displayName = "CopyButton";
117
- const $b6698237aa721326$export$4f2558dd25106ae2 = /*#__PURE__*/ (0, $dnnsg$react).forwardRef($b6698237aa721326$var$_CopyButton);
118
-
119
-
120
-
121
-
122
- export {$b6698237aa721326$export$4f2558dd25106ae2 as CopyButton};
123
- //# sourceMappingURL=module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;A;;;;;A;;AEGO,MAAMY,yCAAS,GAAG,CAAC,QAAEU,IAAAA,CAAAA,EAAH,GAAc;IACrC,MAAMyB,UAAU,GAAGzB,IAAI,KAAK,OAAT,GAAmB,MAAnB,GAA4B,MAA/C,AAAA;IAEA,OAAO;QACLmB,OAAO,EAAA,aAAE,CAAA,CAAA,GAAA,UAAA,CAAA,CAAI;YACXO,OAAO,EAAE,cADE;YAEXC,MAAM,EAAEF,UAFG;YAGXG,QAAQ,EAAE,UAHC;YAIXC,KAAK,EAAEJ,UAAPI;SAJO,CADJ;QAOLT,UAAU,EAAA,aAAE,CAAA,CA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AV,CAKC;KAb2B,EAe9B;QAACrB,MAAD;KAf8B,CAAhC,AAcG;IAIH,qBACE,gCAAC,KAAD;QACE,GAAA,EAAKY,GAAD;QACJ,cAAA,EAAcI,MAAD;QACb,SAAA,EAAW,CAAA,GAAA,SAAA,CAAA,CAAGE,MAAM,CAACU,OAAV,EAAmBb,SAAnB,CAAD;QACV,GAAIE,UAAJ;qBAEA,gCAAC,CAAA,GAAA,2BAAD,CAAA;QAAiB,IAAA,EAAMX,KAAD;QAAQ,MAAA,EAAQiB,YAAD;qBACnC,gCAAC,CAAA,GAAA,cAAD,CAAA;QACE,OAAA,EAASJ,MAAM,GAAGjB,iBAAH,GAAuBC,WAA9B;QACR,GAAIC,YAAJ;QACA,UAAA,EAAYI,UAAD;qBAEX,gCAAC,QAAD;QACE,IAAA,EAAK,QADP;QAEE,GAAA,EAAKa,MAAD;QACJ,SAAA,EAAW,CAAA,GAAA,SAAA,CAAA,CAAGH,MAAM,CAACW,UAAV,EAAsB;YAC/B,CAACX,MAAM,CAACY,kBAAR,CAAA,EAA6BtB,UAA7B;SADS,CAAD;QAGV,YAAA,EAAa,CAAA,KAAA,EAAOF,KAAM,CAAA,aAAA,CAAf;QACX,QAAA,EAAUE,UAAD;QACT,WAAA,EAAU,WARZ;qBAUE,gCAAC,CAAA,GAAA,eAAD,CAAA;QACE,OAAA,EAAQ,OADV;QAEE,IAAA,EAAMC,IAAI,KAAK,OAAT,GAAmB,MAAnB,GAA4B,OAA7B;MAFnB,CAIA,CACA,CACA,CA7BE,CA8BF;CAEC;AAEDC,iCAAW,CAACqB,WAAZ,GAA0B,YAA1B,CAAArB;AAEO,MAAMvB,yCAAU,iBAAGE,CAAAA,GAAAA,YAAK,CAAA,CAAC2C,UAAN,CAAiBtB,iCAAjB,CAAnB,AAAP;;AD1HA","sources":["packages/components/copybutton/src/index.ts","packages/components/copybutton/src/CopyButton.tsx","packages/components/copybutton/src/CopyButton.styles.ts"],"sourcesContent":["export { CopyButton } from './CopyButton';\nexport type { CopyButtonProps } from './CopyButton';\n","import { cx } from 'emotion';\nimport React, { useState, useCallback, useRef } from 'react';\nimport CopyToClipboard from 'react-copy-to-clipboard';\nimport { CopyIcon } from '@contentful/f36-icons';\nimport type { CommonProps, ExpandProps } from '@contentful/f36-core';\nimport { Tooltip, type TooltipProps } from '@contentful/f36-tooltip';\nimport { getStyles } from './CopyButton.styles';\n\nexport interface CopyButtonProps extends CommonProps {\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 * Value that will be copied to clipboard when the button is clicked\n */\n value: string;\n /**\n * Label to be used on aria-label for the button\n * @default Copy {value} 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\nfunction _CopyButton(\n props: ExpandProps<CopyButtonProps>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n onCopy,\n value,\n className,\n testId = 'cf-ui-copy-button',\n tooltipText = 'Copy to clipboard',\n tooltipCopiedText = 'Copied!',\n tooltipProps,\n isDisabled = false,\n size = 'medium',\n ...otherProps\n } = props;\n const styles = getStyles({ size });\n\n const [copied, setCopied] = useState(false);\n const button = useRef<HTMLButtonElement | null>(null);\n const handleOnCopy = useCallback(\n (e: string) => {\n if (onCopy) {\n onCopy(e);\n }\n\n setCopied(true);\n\n setTimeout(() => {\n setCopied(false);\n if (button.current) {\n button.current.blur();\n }\n }, 1000);\n },\n [onCopy],\n );\n\n return (\n <div\n ref={ref}\n data-test-id={testId}\n className={cx(styles.wrapper, className)}\n {...otherProps}\n >\n <CopyToClipboard text={value} onCopy={handleOnCopy}>\n <Tooltip\n content={copied ? tooltipCopiedText : tooltipText}\n {...tooltipProps}\n isDisabled={isDisabled}\n >\n <button\n type=\"button\"\n ref={button}\n className={cx(styles.copyButton, {\n [styles.copyButtonDisabled]: isDisabled,\n })}\n aria-label={`Copy ${value} to clipboard`}\n disabled={isDisabled}\n aria-live=\"assertive\"\n >\n <CopyIcon\n variant=\"muted\"\n size={size === 'small' ? 'tiny' : 'small'}\n />\n </button>\n </Tooltip>\n </CopyToClipboard>\n </div>\n );\n}\n\n_CopyButton.displayName = 'CopyButton';\n\nexport const CopyButton = React.forwardRef(_CopyButton);\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getStyles = ({ size }) => {\n const buttonSize = size === 'small' ? '32px' : '40px';\n\n return {\n wrapper: css({\n display: 'inline-block',\n height: buttonSize,\n position: 'relative',\n width: buttonSize,\n }),\n copyButton: css({\n alignItems: 'center',\n background: tokens.colorWhite,\n border: `1px solid ${tokens.gray300}`,\n display: 'inline-flex',\n height: '100%',\n justifyContent: 'center',\n outline: 'none',\n padding: 0,\n transition: `background ${tokens.transitionDurationShort} ${tokens.transitionEasingDefault}`,\n width: '100%',\n '&:hover': {\n backgroundColor: tokens.gray100,\n cursor: 'pointer',\n },\n '&:active': {\n backgroundColor: tokens.gray200,\n cursor: 'pointer',\n },\n '&:focus': {\n boxShadow: tokens.glowMuted,\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: 'unset',\n },\n '&:focus-visible': {\n boxShadow: tokens.glowMuted,\n },\n }),\n copyButtonDisabled: css({\n cursor: 'not-allowed',\n backgroundColor: tokens.gray100,\n\n '&:hover': {\n cursor: 'not-allowed',\n backgroundColor: tokens.gray100,\n },\n\n '&:focus': {\n borderColor: tokens.gray300,\n boxShadow: 'none',\n },\n\n '&:active, &:active:hover': {\n borderColor: tokens.gray300,\n boxShadow: 'none',\n },\n }),\n };\n};\n"],"names":["CopyButton","CopyButtonProps","React","useState","useCallback","useRef","CopyToClipboard","CopyIcon","CommonProps","ExpandProps","Tooltip","TooltipProps","getStyles","onCopy","string","tooltipCopiedText","tooltipText","tooltipProps","Omit","value","label","isDisabled","size","_CopyButton","props","ref","Ref","HTMLDivElement","className","testId","otherProps","styles","copied","setCopied","button","HTMLButtonElement","handleOnCopy","e","setTimeout","current","blur","wrapper","copyButton","copyButtonDisabled","displayName","forwardRef","tokens","buttonSize","display","height","position","width","alignItems","background","colorWhite","border","gray300","justifyContent","outline","padding","transition","transitionDurationShort","transitionEasingDefault","backgroundColor","gray100","cursor","gray200","boxShadow","glowMuted","borderColor"],"version":3,"file":"module.js.map"}
@@ -1 +0,0 @@
1
- {"mappings":";;;ACQA,gCAAiC,SAAQ,WAAW;IAClD;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,YAAY,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,UAAU,CAAC,CAAC;IAC1D;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC3B;AA4ED,OAAO,MAAM,kGAA0C,CAAC","sources":["packages/components/copybutton/src/src/CopyButton.styles.ts","packages/components/copybutton/src/src/CopyButton.tsx","packages/components/copybutton/src/src/index.ts","packages/components/copybutton/src/index.ts"],"sourcesContent":[null,null,null,"export { CopyButton } from './CopyButton';\nexport type { CopyButtonProps } from './CopyButton';\n"],"names":[],"version":3,"file":"types.d.ts.map"}