UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 1.5 kB
{"version":3,"file":"CopyButton.cjs","names":["useProps"],"sources":["../../../src/components/CopyButton/CopyButton.tsx"],"sourcesContent":["import { useClipboard } from '@mantine/hooks';\nimport { useProps } from '../../core';\n\nexport interface CopyButtonProps {\n /** Children callback, provides current status and copy function as an argument */\n children: (payload: { copied: boolean; copy: () => void }) => React.ReactNode;\n\n /** Value that is copied to the clipboard when the button is clicked */\n value: string;\n\n /** Copied status timeout in ms @default 1000 */\n timeout?: number;\n}\n\nconst defaultProps = {\n timeout: 1000,\n} satisfies Partial<CopyButtonProps>;\n\nexport function CopyButton(props: CopyButtonProps) {\n const { children, timeout, value, ...others } = useProps('CopyButton', defaultProps, props);\n const clipboard = useClipboard({ timeout });\n const copy = () => clipboard.copy(value);\n return <>{children({ copy, copied: clipboard.copied, ...others })}</>;\n}\n\nCopyButton.displayName = '@mantine/core/CopyButton';\n\nexport namespace CopyButton {\n export type Props = CopyButtonProps;\n}\n"],"mappings":";;;;;;AAcA,MAAM,eAAe,EACnB,SAAS,IACX;AAEA,SAAgB,WAAW,OAAwB;CACjD,MAAM,EAAE,UAAU,SAAS,OAAO,GAAG,WAAWA,kBAAAA,SAAS,cAAc,cAAc,KAAK;CAC1F,MAAM,aAAA,GAAA,eAAA,cAAyB,EAAE,QAAQ,CAAC;CAC1C,MAAM,aAAa,UAAU,KAAK,KAAK;CACvC,OAAO,iBAAA,GAAA,kBAAA,KAAA,kBAAA,UAAA,EAAA,UAAG,SAAS;EAAE;EAAM,QAAQ,UAAU;EAAQ,GAAG;CAAO,CAAC,EAAI,CAAA;AACtE;AAEA,WAAW,cAAc"}