diff --git a/src/components/code-snippet/__snapshots__/code-snippet.test.tsx.snap b/src/components/code-snippet/__snapshots__/code-snippet.test.tsx.snap index 456a846d..a91e4dec 100644 --- a/src/components/code-snippet/__snapshots__/code-snippet.test.tsx.snap +++ b/src/components/code-snippet/__snapshots__/code-snippet.test.tsx.snap @@ -339,6 +339,7 @@ exports[`CodeSnippet copy ranges renders as expected 1`] = ` aria-controls="radix-4" aria-expanded="false" aria-haspopup="dialog" + class="inline-block" data-state="closed" type="button" > @@ -392,6 +393,7 @@ exports[`CodeSnippet copy ranges renders as expected 1`] = ` aria-controls="radix-5" aria-expanded="false" aria-haspopup="dialog" + class="inline-block" data-state="closed" type="button" > @@ -628,6 +630,7 @@ exports[`CodeSnippet highlighted, no ranges, with onCopy callback renders as exp aria-controls="radix-0" aria-expanded="false" aria-haspopup="dialog" + class="inline-block" data-state="closed" type="button" > diff --git a/src/components/copy-button/__snapshots__/copy-button.test.tsx.snap b/src/components/copy-button/__snapshots__/copy-button.test.tsx.snap index 761676be..fc738707 100644 --- a/src/components/copy-button/__snapshots__/copy-button.test.tsx.snap +++ b/src/components/copy-button/__snapshots__/copy-button.test.tsx.snap @@ -16,33 +16,15 @@ exports[`CopyButton all props renders as expected 1`] = ` aria-controls="radix-4" aria-expanded="false" aria-haspopup="dialog" + class="inline-block" data-state="closed" type="button" > - + A custom child in place of the visual button + @@ -66,6 +48,7 @@ exports[`CopyButton basic renders as expected 1`] = ` aria-controls="radix-0" aria-expanded="false" aria-haspopup="dialog" + class="inline-block" data-state="closed" type="button" > diff --git a/src/components/copy-button/copy-button.test.tsx b/src/components/copy-button/copy-button.test.tsx index 97796fa0..b60d375d 100644 --- a/src/components/copy-button/copy-button.test.tsx +++ b/src/components/copy-button/copy-button.test.tsx @@ -38,6 +38,10 @@ describe('CopyButton', () => { className: 'px6 py6 btn btn--purple btn--stroke', focusTrapPaused: true, block: true, + tooltipTheme: 'dark', + children: ( + A custom child in place of the visual button + ), passthroughProps: { 'data-testid': 'foo' } diff --git a/src/components/copy-button/copy-button.tsx b/src/components/copy-button/copy-button.tsx index 56d5e680..bb6e37b1 100644 --- a/src/components/copy-button/copy-button.tsx +++ b/src/components/copy-button/copy-button.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement, useState, useEffect, useCallback, HTMLAttributes} from 'react'; +import React, { ReactElement, useState, useEffect, useCallback, HTMLAttributes, ReactNode} from 'react'; import classnames from 'classnames'; import PropTypes from 'prop-types'; import Clipboard from 'clipboard/dist/clipboard.min.js'; @@ -14,6 +14,8 @@ interface Props { block?: boolean; focusTrapPaused?: boolean; className?: string; + themeTooltip?: 'light' | 'dark'; + children?: ReactNode; passthroughProps?: HTMLAttributes; } @@ -31,6 +33,8 @@ export default function CopyButton({ block = false, focusTrapPaused, className = 'btn btn--xs py3 px3 round', + children, + themeTooltip = 'light', passthroughProps }: Props): ReactElement { const [clipboard, setClipboard] = useState(null); @@ -98,6 +102,14 @@ export default function CopyButton({ block }); + const body = children ? children : + // data-clipboard-text and the container ref are used by clipboard.js // to copy text. Note that this wont have as nice a failure mode. return ( @@ -112,23 +124,19 @@ export default function CopyButton({ Copied!} active={showingFeedback} + coloring={themeTooltip} placement="top" alignment="center" hideWhenAnchorIsOffscreen={true} padding="small" > -
+
- + {body}
@@ -169,7 +177,13 @@ CopyButton.propTypes = { /** * An object of props that you want to pass through to the ` + + ); +}