Skip to content

Commit

Permalink
new(Copy): Add invertTooltip prop (#380)
Browse files Browse the repository at this point in the history
* new(Copy): Add invertTooltip prop

* docs(Copy): update invertedTooltip story
  • Loading branch information
williaster authored Jun 4, 2020
1 parent c913d22 commit d2ea8da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/components/Copy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type CopyProps = {
children?: React.ReactElement;
/** Pass an HTML element attribute id to the Link. */
id?: string;
/** Invert the colors of the tooltip. */
invertTooltip?: boolean;
/** String of text to be copied to the clipboard. */
text: string;
/** Callback fired when text is copied. */
Expand All @@ -31,6 +33,7 @@ export default function Copy({
children,
text,
id,
invertTooltip,
trackingName,
underlined,
prompt,
Expand Down Expand Up @@ -64,6 +67,7 @@ export default function Copy({
return (
<Tooltip
remainOnMouseDown
inverted={invertTooltip}
content={
copied ? (
<T k="lunar.copy.copied" phrase="Copied!" />
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/components/Copy/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,16 @@ export function withACustomElementToTriggerTheCopy() {
withACustomElementToTriggerTheCopy.story = {
name: 'With a custom element to trigger the copy.',
};

export function withInvertedTooltip() {
return (
<Text>
Check out this inverted tooltip{' '}
<Copy invertTooltip text="Inverted tooltip." prompt="Yo copy me..." />.
</Text>
);
}

withInvertedTooltip.story = {
name: 'With an inverted tooltip.',
};
9 changes: 9 additions & 0 deletions packages/core/test/components/Copy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import copy from 'copy-to-clipboard';
import IconCopy from '@airbnb/lunar-icons/lib/interface/IconCopy';
import Copy from '../../src/components/Copy';
import IconButton from '../../src/components/IconButton';
import { Tooltip } from '../../src/components/Tooltip';

jest.mock('copy-to-clipboard', () => jest.fn(() => true));

Expand Down Expand Up @@ -50,4 +51,12 @@ describe('<Copy />', () => {
expect(spy).toHaveBeenCalledWith('foo', true);
expect(copy).toHaveBeenCalledWith('foo');
});

it('inverts the Tooltip if specified', () => {
const wrapper = shallow(<Copy invertTooltip={false} text="foo" />);

expect(wrapper.dive().find(Tooltip).prop('inverted')).toBe(false);
wrapper.setProps({ invertTooltip: true });
expect(wrapper.dive().find(Tooltip).prop('inverted')).toBe(true);
});
});

0 comments on commit d2ea8da

Please sign in to comment.