@woosmap/ui 3.137.0 → 3.138.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": "3.137.0",
3
+ "version": "3.138.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/WebGeoServices/ui.git"
@@ -16,10 +16,12 @@ export default class CopyClipboardButton extends Component {
16
16
  }
17
17
  }
18
18
 
19
- copy = () => {
20
- const { text, getText, copyCallback } = this.props;
19
+ copy = (e) => {
20
+ const { text, getText, copyCallback, stopPropagation } = this.props;
21
21
  const { copied } = this.state;
22
22
 
23
+ if (stopPropagation) e.stopPropagation();
24
+
23
25
  const textToCopy = text || (getText ? getText() : null);
24
26
 
25
27
  if (textToCopy !== null && copy(textToCopy) && !copied) {
@@ -29,13 +31,27 @@ export default class CopyClipboardButton extends Component {
29
31
  };
30
32
 
31
33
  render() {
32
- const { type, noLabel, label, copiedLabel, copiedIcon, icon, getText, testId, copyCallback, ...rest } =
33
- this.props;
34
+ const {
35
+ type,
36
+ noLabel,
37
+ label: propsLabel,
38
+ copiedLabel,
39
+ copiedIcon,
40
+ icon,
41
+ getText,
42
+ testId,
43
+ copyCallback,
44
+ stopPropagation,
45
+ ...rest
46
+ } = this.props;
34
47
  const { copied } = this.state;
48
+ let label;
49
+ if (noLabel) label = '';
50
+ else label = copied && copiedLabel ? copiedLabel : propsLabel;
35
51
  return (
36
52
  <Button
37
53
  type={type}
38
- label={copied && copiedLabel ? copiedLabel : label}
54
+ label={label}
39
55
  icon={copied && copiedIcon ? copiedIcon : icon}
40
56
  onClick={this.copy}
41
57
  {...rest}
@@ -56,6 +72,7 @@ CopyClipboardButton.defaultProps = {
56
72
  getText: null,
57
73
  testId: 'copy-clipboard-button',
58
74
  copyCallback: () => {},
75
+ stopPropagation: false,
59
76
  };
60
77
 
61
78
  CopyClipboardButton.propTypes = {
@@ -69,4 +86,5 @@ CopyClipboardButton.propTypes = {
69
86
  copiedIcon: PropTypes.string,
70
87
  icon: PropTypes.string,
71
88
  copyCallback: PropTypes.func,
89
+ stopPropagation: PropTypes.bool,
72
90
  };
@@ -10,6 +10,7 @@ export default Story;
10
10
  const Template = () => (
11
11
  <div className="flex-column mbib">
12
12
  <CopyClipboardButton type="primary" text="Text to be copied" />
13
+ <CopyClipboardButton type="primary" text="Text to be copied" noLabel />
13
14
  <CopyClipboardButton
14
15
  label="withCallback"
15
16
  copiedLabel={null}
@@ -10,6 +10,11 @@ it('renders a CopyClipboardButton component ', () => {
10
10
  expect(getByTestId('copy-clipboard-button')).toHaveClass('btn');
11
11
  });
12
12
 
13
+ it('renders a CopyClipboardButton component without label', () => {
14
+ const { getByTestId } = render(<CopyClipboardButton text="Text" noLabel />);
15
+ expect(getByTestId('copy-clipboard-button')).toHaveClass('btn--no-label');
16
+ });
17
+
13
18
  it('copies the content', () => {
14
19
  const { container } = render(<CopyClipboardButton text="Text to be copied" />);
15
20
  document.execCommand = jest.fn();