@contentful/f36-copybutton 4.17.0 → 4.19.1

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,34 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.19.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2209](https://github.com/contentful/forma-36/pull/2209) [`42f0c321`](https://github.com/contentful/forma-36/commit/42f0c3218965137191842f492fe5dbf4bd10784c) Thanks [@denkristoffer](https://github.com/denkristoffer)! - build: build ESM to JS file - legacy output
8
+ fix(notification): use type imports
9
+ - Updated dependencies [[`42f0c321`](https://github.com/contentful/forma-36/commit/42f0c3218965137191842f492fe5dbf4bd10784c)]:
10
+ - @contentful/f36-icons@4.19.1
11
+ - @contentful/f36-tooltip@4.19.1
12
+ - @contentful/f36-core@4.19.1
13
+
14
+ ## 4.19.0
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies []:
19
+ - @contentful/f36-icons@4.19.0
20
+ - @contentful/f36-tooltip@4.19.0
21
+ - @contentful/f36-core@4.19.0
22
+
23
+ ## 4.18.0
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies []:
28
+ - @contentful/f36-icons@4.18.0
29
+ - @contentful/f36-tooltip@4.18.0
30
+ - @contentful/f36-core@4.18.0
31
+
3
32
  ## 4.17.0
4
33
 
5
34
  ### Patch Changes
@@ -0,0 +1,11 @@
1
+ import { cx, css } from 'emotion';
2
+ import t, { useState, useRef, useCallback } from 'react';
3
+ import k from 'react-copy-to-clipboard';
4
+ import { CopyIcon } from '@contentful/f36-icons';
5
+ import { Tooltip } from '@contentful/f36-tooltip';
6
+ import o from '@contentful/f36-tokens';
7
+
8
+ var c=({size:r})=>{let e=r==="small"?"32px":"40px";return {wrapper:css({display:"inline-block",height:e,position:"relative",width:e}),copyButton:css({alignItems:"center",background:o.colorWhite,border:`1px solid ${o.gray300}`,display:"inline-flex",height:"100%",justifyContent:"center",outline:"none",padding:0,transition:`background ${o.transitionDurationShort} ${o.transitionEasingDefault}`,width:"100%","&:hover":{backgroundColor:o.gray100,cursor:"pointer"},"&:active":{backgroundColor:o.gray200,cursor:"pointer"},"&:focus":{boxShadow:o.glowMuted},"&:focus:not(:focus-visible)":{boxShadow:"unset"},"&:focus-visible":{boxShadow:o.glowMuted}}),copyButtonDisabled:css({cursor:"not-allowed",backgroundColor:o.gray100,"&:hover":{cursor:"not-allowed",backgroundColor:o.gray100},"&:focus":{borderColor:o.gray300,boxShadow:"none"},"&:active, &:active:hover":{borderColor:o.gray300,boxShadow:"none"}})}};function y(r,e){let{onCopy:i,value:a,className:b,testId:f="cf-ui-copy-button",tooltipText:C="Copy to clipboard",tooltipCopiedText:g="Copied!",tooltipProps:x,isDisabled:n=!1,size:u="medium",...h}=r,s=c({size:u}),[v,d]=useState(!1),p=useRef(null),w=useCallback(B=>{i&&i(B),d(!0),setTimeout(()=>{d(!1),p.current&&p.current.blur();},1e3);},[i]);return t.createElement("div",{ref:e,"data-test-id":f,className:cx(s.wrapper,b),...h},t.createElement(k,{text:a,onCopy:w},t.createElement(Tooltip,{content:v?g:C,...x,isDisabled:n},t.createElement("button",{type:"button",ref:p,className:cx(s.copyButton,{[s.copyButtonDisabled]:n}),"aria-label":`Copy ${a} to clipboard`,disabled:n,"aria-live":"assertive"},t.createElement(CopyIcon,{variant:"muted",size:u==="small"?"tiny":"small"})))))}y.displayName="CopyButton";var z=t.forwardRef(y);
9
+
10
+ export { z as CopyButton };
11
+ //# 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","onCopy","value","className","testId","tooltipText","tooltipCopiedText","tooltipProps","isDisabled","otherProps","styles","copied","setCopied","button","handleOnCopy","e","CopyButton"],"mappings":"AAAA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,CAAE,KAAAC,CAAK,CAAC,EAE3B,CAACe,EAAQC,CAAS,EAAIzB,EAAS,EAAK,EACpC0B,EAASxB,EAAiC,IAAI,EAC9CyB,EAAe1B,EAClB2B,GAAc,CACTd,GACFA,EAAOc,CAAC,EAGVH,EAAU,EAAI,EAEd,WAAW,IAAM,CACfA,EAAU,EAAK,EACXC,EAAO,SACTA,EAAO,QAAQ,KAAK,CAExB,EAAG,GAAI,CACT,EACA,CAACZ,CAAM,CACT,EAEA,OACEf,EAAA,cAAC,OACC,IAAKc,EACL,eAAcI,EACd,UAAWnB,EAAGyB,EAAO,QAASP,CAAS,EACtC,GAAGM,GAEJvB,EAAA,cAACI,EAAA,CAAgB,KAAMY,EAAO,OAAQY,GACpC5B,EAAA,cAACM,EAAA,CACC,QAASmB,EAASL,EAAoBD,EACrC,GAAGE,EACJ,WAAYC,GAEZtB,EAAA,cAAC,UACC,KAAK,SACL,IAAK2B,EACL,UAAW5B,EAAGyB,EAAO,WAAY,CAC/B,CAACA,EAAO,oBAAqBF,CAC/B,CAAC,EACD,aAAY,QAAQN,iBACpB,SAAUM,EACV,YAAU,aAEVtB,EAAA,cAACK,EAAA,CACC,QAAQ,QACR,KAAMK,IAAS,QAAU,OAAS,QACpC,CACF,CACF,CACF,CACF,CAEJ,CAEAE,EAAY,YAAc,aAEnB,IAAMkB,EAAa9B,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"]}
@@ -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 t = require('react');
7
+ var k = require('react-copy-to-clipboard');
8
+ var f36Icons = require('@contentful/f36-icons');
9
+ var f36Tooltip = require('@contentful/f36-tooltip');
10
+ var o = require('@contentful/f36-tokens');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var t__default = /*#__PURE__*/_interopDefaultLegacy(t);
15
+ var k__default = /*#__PURE__*/_interopDefaultLegacy(k);
16
+ var o__default = /*#__PURE__*/_interopDefaultLegacy(o);
17
+
18
+ var c=({size:r})=>{let e=r==="small"?"32px":"40px";return {wrapper:emotion.css({display:"inline-block",height:e,position:"relative",width:e}),copyButton:emotion.css({alignItems:"center",background:o__default["default"].colorWhite,border:`1px solid ${o__default["default"].gray300}`,display:"inline-flex",height:"100%",justifyContent:"center",outline:"none",padding:0,transition:`background ${o__default["default"].transitionDurationShort} ${o__default["default"].transitionEasingDefault}`,width:"100%","&:hover":{backgroundColor:o__default["default"].gray100,cursor:"pointer"},"&:active":{backgroundColor:o__default["default"].gray200,cursor:"pointer"},"&:focus":{boxShadow:o__default["default"].glowMuted},"&:focus:not(:focus-visible)":{boxShadow:"unset"},"&:focus-visible":{boxShadow:o__default["default"].glowMuted}}),copyButtonDisabled:emotion.css({cursor:"not-allowed",backgroundColor:o__default["default"].gray100,"&:hover":{cursor:"not-allowed",backgroundColor:o__default["default"].gray100},"&:focus":{borderColor:o__default["default"].gray300,boxShadow:"none"},"&:active, &:active:hover":{borderColor:o__default["default"].gray300,boxShadow:"none"}})}};function y(r,e){let{onCopy:i,value:a,className:b,testId:f="cf-ui-copy-button",tooltipText:C="Copy to clipboard",tooltipCopiedText:g="Copied!",tooltipProps:x,isDisabled:n=!1,size:u="medium",...h}=r,s=c({size:u}),[v,d]=t.useState(!1),p=t.useRef(null),w=t.useCallback(B=>{i&&i(B),d(!0),setTimeout(()=>{d(!1),p.current&&p.current.blur();},1e3);},[i]);return t__default["default"].createElement("div",{ref:e,"data-test-id":f,className:emotion.cx(s.wrapper,b),...h},t__default["default"].createElement(k__default["default"],{text:a,onCopy:w},t__default["default"].createElement(f36Tooltip.Tooltip,{content:v?g:C,...x,isDisabled:n},t__default["default"].createElement("button",{type:"button",ref:p,className:emotion.cx(s.copyButton,{[s.copyButtonDisabled]:n}),"aria-label":`Copy ${a} to clipboard`,disabled:n,"aria-live":"assertive"},t__default["default"].createElement(f36Icons.CopyIcon,{variant:"muted",size:u==="small"?"tiny":"small"})))))}y.displayName="CopyButton";var z=t__default["default"].forwardRef(y);
19
+
20
+ exports.CopyButton = z;
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","onCopy","value","className","testId","tooltipText","tooltipCopiedText","tooltipProps","isDisabled","otherProps","styles","copied","setCopied","button","handleOnCopy","e","CopyButton"],"mappings":"AAAA,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,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d,UAAWnB,EAAGyB,EAAO,QAASP,CAAS,EACtC,GAAGM,GAEJvB,EAAA,cAACI,EAAA,CAAgB,KAAMY,EAAO,OAAQY,GACpC5B,EAAA,cAACM,EAAA,CACC,QAASmB,EAASL,EAAoBD,EACrC,GAAGE,EACJ,WAAYC,GAEZtB,EAAA,cAAC,UACC,KAAK,SACL,IAAK2B,EACL,UAAW5B,EAAGyB,EAAO,WAAY,CAC/B,CAACA,EAAO,oBAAqBF,CAC/B,CAAC,EACD,aAAY,QAAQN,iBACpB,SAAUM,EACV,YAAU,aAEVtB,EAAA,cAACK,EAAA,CACC,QAAQ,QACR,KAAMK,IAAS,QAAU,OAAS,QACpC,CACF,CACF,CACF,CACF,CAEJ,CAEAE,EAAY,YAAc,aAEnB,IAAMkB,EAAa9B,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.17.0",
3
+ "version": "4.19.1",
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.17.0",
11
- "@contentful/f36-icons": "^4.17.0",
10
+ "@contentful/f36-core": "^4.19.1",
11
+ "@contentful/f36-icons": "^4.19.1",
12
12
  "@contentful/f36-tokens": "^4.0.1",
13
- "@contentful/f36-tooltip": "^4.17.0",
13
+ "@contentful/f36-tooltip": "^4.19.1",
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/esm/index.js",
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,Q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/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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A,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"}