@contentful/f36-copybutton 4.18.0 → 4.19.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/CHANGELOG.md +29 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/index.mjs +0 -11
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 4.19.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @contentful/f36-icons@4.19.2
|
|
9
|
+
- @contentful/f36-tooltip@4.19.2
|
|
10
|
+
- @contentful/f36-core@4.19.2
|
|
11
|
+
|
|
12
|
+
## 4.19.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#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
|
|
17
|
+
fix(notification): use type imports
|
|
18
|
+
- Updated dependencies [[`42f0c321`](https://github.com/contentful/forma-36/commit/42f0c3218965137191842f492fe5dbf4bd10784c)]:
|
|
19
|
+
- @contentful/f36-icons@4.19.1
|
|
20
|
+
- @contentful/f36-tooltip@4.19.1
|
|
21
|
+
- @contentful/f36-core@4.19.1
|
|
22
|
+
|
|
23
|
+
## 4.19.0
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies []:
|
|
28
|
+
- @contentful/f36-icons@4.19.0
|
|
29
|
+
- @contentful/f36-tooltip@4.19.0
|
|
30
|
+
- @contentful/f36-core@4.19.0
|
|
31
|
+
|
|
3
32
|
## 4.18.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,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,SACV,EACA,WAAY,CACV,gBAAiBA,EAAO,QACxB,OAAQ,SACV,EACA,UAAW,CACT,UAAWA,EAAO,SACpB,EACA,8BAA+B,CAC7B,UAAW,OAC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,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/dist/index.js
CHANGED
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var emotion = require('emotion');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var t = require('react');
|
|
7
|
+
var k = require('react-copy-to-clipboard');
|
|
8
8
|
var f36Icons = require('@contentful/f36-icons');
|
|
9
9
|
var f36Tooltip = require('@contentful/f36-tooltip');
|
|
10
|
-
var
|
|
10
|
+
var o = require('@contentful/f36-tokens');
|
|
11
11
|
|
|
12
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
13
|
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
14
|
+
var t__default = /*#__PURE__*/_interopDefaultLegacy(t);
|
|
15
|
+
var k__default = /*#__PURE__*/_interopDefaultLegacy(k);
|
|
16
|
+
var o__default = /*#__PURE__*/_interopDefaultLegacy(o);
|
|
17
17
|
|
|
18
|
-
var
|
|
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
19
|
|
|
20
|
-
exports.CopyButton =
|
|
20
|
+
exports.CopyButton = z;
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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","
|
|
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","handleO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CACL,EAAIV,EACEW,EAASf,EAAU,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"]}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/f36-copybutton",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.2",
|
|
4
4
|
"description": "Forma 36: CopyButton component",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@babel/runtime": "^7.6.2",
|
|
10
|
-
"@contentful/f36-core": "^4.
|
|
11
|
-
"@contentful/f36-icons": "^4.
|
|
10
|
+
"@contentful/f36-core": "^4.19.2",
|
|
11
|
+
"@contentful/f36-icons": "^4.19.2",
|
|
12
12
|
"@contentful/f36-tokens": "^4.0.1",
|
|
13
|
-
"@contentful/f36-tooltip": "^4.
|
|
13
|
+
"@contentful/f36-tooltip": "^4.19.2",
|
|
14
14
|
"emotion": "^10.0.17",
|
|
15
15
|
"react-copy-to-clipboard": "^5.1.0"
|
|
16
16
|
},
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"main": "dist/index.js",
|
|
25
|
-
"module": "dist/index.
|
|
25
|
+
"module": "dist/esm/index.js",
|
|
26
26
|
"types": "dist/index.d.ts",
|
|
27
27
|
"source": "src/index.ts",
|
|
28
28
|
"sideEffects": false,
|
package/dist/index.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,SACV,EACA,WAAY,CACV,gBAAiBA,EAAO,QACxB,OAAQ,SACV,EACA,UAAW,CACT,UAAWA,EAAO,SACpB,EACA,8BAA+B,CAC7B,UAAW,OACb,EACA,kBAAmB,CACjB,UAAWA,EAAO,SACpB,CACF,CAAC,EACD,mBAAoBD,EAAI,CACtB,OAAQ,cACR,gBAAiBC,EAAO,QAExB,UAAW,CACT,OAAQ,cACR,gBAAiBA,EAAO,OAC1B,EAEA,UAAW,CACT,YAAaA,EAAO,QACpB,UAAW,MACb,EAEA,2BAA4B,CAC1B,YAAaA,EAAO,QACpB,UAAW,MACb,CACF,CAAC,CACH,CACF,EDdA,SAASI,EACPC,EACAC,EACA,CACA,IAWIC,EAAAF,EAVF,QAAAG,EACA,MAAAC,EACA,UAAAC,EACA,OAAAC,EAAS,oBACT,YAAAC,EAAc,oBACd,kBAAAC,EAAoB,UACpB,aAAAC,EACA,WAAAC,EAAa,GACb,KAAAb,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"]}
|