@woosmap/ui 3.136.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 +1 -1
- package/src/components/CopyClipboardButton/CopyClipboardButton.js +23 -5
- package/src/components/CopyClipboardButton/CopyToClipboard.stories.js +1 -0
- package/src/components/CopyClipboardButton/CopyToClipboard.test.js +5 -0
- package/src/components/Dropdown/Dropdown.js +4 -29
- package/src/components/Dropdown/Dropdown.styl +0 -11
package/package.json
CHANGED
|
@@ -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 {
|
|
33
|
-
|
|
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={
|
|
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();
|
|
@@ -42,45 +42,21 @@ class DropdownMenu extends Component {
|
|
|
42
42
|
constructor(props) {
|
|
43
43
|
super(props);
|
|
44
44
|
this.childrenRefs = {};
|
|
45
|
-
this.menuRef = React.createRef();
|
|
46
|
-
this.state = {
|
|
47
|
-
directionInBounds: props.direction,
|
|
48
|
-
};
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
componentDidUpdate(_, prevState) {
|
|
52
|
-
if (this.menuRef.current) {
|
|
53
|
-
const { directionInBounds } = this.state;
|
|
54
|
-
const { directionInBounds: prevDirectionInBounds } = prevState;
|
|
55
|
-
const { top, bottom } = this.menuRef.current.getBoundingClientRect();
|
|
56
|
-
const { innerHeight } = window;
|
|
57
|
-
if (innerHeight > top && !prevDirectionInBounds.includes('s')) {
|
|
58
|
-
this.setDirectionInBounds(directionInBounds.replace('n', 's'));
|
|
59
|
-
}
|
|
60
|
-
if (innerHeight < bottom && !prevDirectionInBounds.includes('n')) {
|
|
61
|
-
this.setDirectionInBounds(directionInBounds.replace('s', 'n'));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
setDirectionInBounds = (direction) => {
|
|
67
|
-
this.setState({ directionInBounds: direction });
|
|
68
|
-
};
|
|
69
|
-
|
|
70
47
|
close = () => {
|
|
71
48
|
closeChildren(this.childrenRefs);
|
|
72
49
|
};
|
|
73
50
|
|
|
74
51
|
render() {
|
|
75
52
|
const { direction, children, closeCb, onMouseEnter, onMouseLeave, testId, isSection, ...rest } = this.props;
|
|
76
|
-
const { directionInBounds } = this.state;
|
|
77
53
|
const childrenWithProps = mapChildrenWithProps(children, this.childrenRefs, { closeCb });
|
|
78
54
|
if (isSection) {
|
|
79
55
|
return (
|
|
80
|
-
<div className="dropdown__container"
|
|
56
|
+
<div className="dropdown__container">
|
|
81
57
|
<div
|
|
82
58
|
role="menu"
|
|
83
|
-
className={cl('dropdown__menu',
|
|
59
|
+
className={cl('dropdown__menu', direction, 'dropdown__menu--section')}
|
|
84
60
|
data-testid={testId}
|
|
85
61
|
tabIndex="-1"
|
|
86
62
|
onMouseEnter={onMouseEnter}
|
|
@@ -95,12 +71,11 @@ class DropdownMenu extends Component {
|
|
|
95
71
|
return (
|
|
96
72
|
<ul
|
|
97
73
|
role="menu"
|
|
98
|
-
className={cl('dropdown__menu',
|
|
74
|
+
className={cl('dropdown__menu', direction)}
|
|
99
75
|
data-testid={testId}
|
|
100
76
|
{...rest}
|
|
101
77
|
onMouseEnter={onMouseEnter}
|
|
102
78
|
onMouseLeave={onMouseLeave}
|
|
103
|
-
ref={this.menuRef}
|
|
104
79
|
>
|
|
105
80
|
{childrenWithProps}
|
|
106
81
|
</ul>
|
|
@@ -124,7 +99,7 @@ DropdownMenu.propTypes = {
|
|
|
124
99
|
onMouseLeave: PropTypes.func,
|
|
125
100
|
testId: PropTypes.string,
|
|
126
101
|
isSection: PropTypes.bool,
|
|
127
|
-
direction: PropTypes.oneOf(['ne', 'e', 'se', 's', 'sw', 'w'
|
|
102
|
+
direction: PropTypes.oneOf(['ne', 'e', 'se', 's', 'sw', 'w']),
|
|
128
103
|
};
|
|
129
104
|
|
|
130
105
|
class DropdownMenuSection extends Component {
|
|
@@ -41,13 +41,6 @@
|
|
|
41
41
|
left 0
|
|
42
42
|
margin-bottom .3rem
|
|
43
43
|
|
|
44
|
-
&.nw
|
|
45
|
-
top auto
|
|
46
|
-
bottom 100%
|
|
47
|
-
right 0
|
|
48
|
-
left auto
|
|
49
|
-
margin-bottom .3rem
|
|
50
|
-
|
|
51
44
|
&.s
|
|
52
45
|
right 50%
|
|
53
46
|
left auto
|
|
@@ -57,10 +50,6 @@
|
|
|
57
50
|
right 0
|
|
58
51
|
left auto
|
|
59
52
|
|
|
60
|
-
&.se
|
|
61
|
-
right auto
|
|
62
|
-
left 0
|
|
63
|
-
|
|
64
53
|
|
|
65
54
|
&__item
|
|
66
55
|
flexMiddle()
|