@woosmap/ui 2.54.0 → 2.55.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woosmap/ui",
3
- "version": "2.54.0",
3
+ "version": "2.55.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/WebGeoServices/ui.git"
@@ -17,25 +17,26 @@ export default class CopyClipboardButton extends Component {
17
17
  }
18
18
 
19
19
  copy = () => {
20
- const { text, getText } = this.props;
20
+ const { text, getText, copyCallback } = this.props;
21
21
  const { copied } = this.state;
22
22
 
23
23
  const textToCopy = text || (getText ? getText() : null);
24
24
 
25
25
  if (textToCopy !== null && copy(textToCopy) && !copied) {
26
- this.setState({ copied: true });
26
+ this.setState({ copied: true }, copyCallback);
27
27
  this.copyTimeout = setTimeout(() => this.setState({ copied: false }), 1000);
28
28
  }
29
29
  };
30
30
 
31
31
  render() {
32
- const { type, noLabel, label, copiedLabel, copiedIcon, icon, getText, testId, ...rest } = this.props;
32
+ const { type, noLabel, label, copiedLabel, copiedIcon, icon, getText, testId, copyCallback, ...rest } =
33
+ this.props;
33
34
  const { copied } = this.state;
34
35
  return (
35
36
  <Button
36
37
  type={type}
37
- label={copied && label ? copiedLabel : label}
38
- icon={copied ? copiedIcon : icon}
38
+ label={copied && copiedLabel ? copiedLabel : label}
39
+ icon={copied && copiedIcon ? copiedIcon : icon}
39
40
  onClick={this.copy}
40
41
  {...rest}
41
42
  testId={testId}
@@ -54,6 +55,7 @@ CopyClipboardButton.defaultProps = {
54
55
  text: null,
55
56
  getText: null,
56
57
  testId: 'copy-clipboard-button',
58
+ copyCallback: () => {},
57
59
  };
58
60
 
59
61
  CopyClipboardButton.propTypes = {
@@ -66,4 +68,5 @@ CopyClipboardButton.propTypes = {
66
68
  copiedLabel: PropTypes.string,
67
69
  copiedIcon: PropTypes.string,
68
70
  icon: PropTypes.string,
71
+ copyCallback: PropTypes.func,
69
72
  };
@@ -7,6 +7,17 @@ const Story = {
7
7
  };
8
8
 
9
9
  export default Story;
10
- const Template = () => <CopyClipboardButton type="primary" text="Text to be copied" />;
10
+ const Template = () => (
11
+ <div className="flex-column mbib">
12
+ <CopyClipboardButton type="primary" text="Text to be copied" />
13
+ <CopyClipboardButton
14
+ label="withCallback"
15
+ copiedLabel={null}
16
+ copiedIcon={null}
17
+ text="Text to be copied"
18
+ copyCallback={() => console.log('copy callback')}
19
+ />
20
+ </div>
21
+ );
11
22
  export const Default = Template.bind({});
12
23
  Default.args = {};
@@ -23,3 +23,10 @@ it('copies the content from callback', () => {
23
23
  userEvent.click(container.firstChild);
24
24
  expect(document.execCommand).toHaveBeenCalledWith('copy');
25
25
  });
26
+
27
+ it('copies the content and send a call back', () => {
28
+ const cb = jest.fn();
29
+ const { container } = render(<CopyClipboardButton text="text" copyCallback={cb} />);
30
+ userEvent.click(container.firstChild);
31
+ expect(cb).toHaveBeenCalledWith();
32
+ });