@dhis2-ui/button 9.11.0 → 9.11.1-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/build/cjs/button/__tests__/Button.test.js +1 -8
- package/build/cjs/button/button.e2e.stories.js +34 -0
- package/build/cjs/button/button.js +8 -47
- package/build/cjs/button/{button.stories.js → button.prod.stories.js} +36 -59
- package/build/cjs/button/button.styles.js +2 -5
- package/build/cjs/button/features/can_be_blurred/index.js +1 -2
- package/build/cjs/button/features/can_be_clicked/index.js +1 -2
- package/build/cjs/button/features/can_be_focused/index.js +1 -2
- package/build/cjs/button/index.js +0 -1
- package/build/cjs/button-strip/button-strip.e2e.stories.js +15 -0
- package/build/cjs/button-strip/button-strip.js +4 -17
- package/build/cjs/button-strip/{button-strip.stories.js → button-strip.prod.stories.js} +13 -21
- package/build/cjs/button-strip/features/accepts_children/index.js +0 -1
- package/build/cjs/button-strip/index.js +0 -1
- package/build/cjs/dropdown-button/__tests__/dropdown-button.test.js +1 -23
- package/build/cjs/dropdown-button/dropdown-button.e2e.stories.js +60 -0
- package/build/cjs/dropdown-button/dropdown-button.js +11 -48
- package/build/cjs/dropdown-button/{dropdown-button.stories.js → dropdown-button.prod.stories.js} +36 -60
- package/build/cjs/dropdown-button/features/accepts_children/index.js +0 -1
- package/build/cjs/dropdown-button/features/accepts_component/index.js +0 -1
- package/build/cjs/dropdown-button/features/accepts_icon/index.js +0 -1
- package/build/cjs/dropdown-button/features/accepts_initial_focus/index.js +1 -2
- package/build/cjs/dropdown-button/features/button_is_clickable/index.js +1 -2
- package/build/cjs/dropdown-button/features/can_be_disabled/index.js +1 -2
- package/build/cjs/dropdown-button/features/common/index.js +0 -1
- package/build/cjs/dropdown-button/features/opens_a_dropdown/index.js +0 -1
- package/build/cjs/dropdown-button/index.js +0 -1
- package/build/cjs/index.js +0 -4
- package/build/cjs/locales/index.js +3 -9
- package/build/cjs/split-button/features/accepts_children/index.js +0 -1
- package/build/cjs/split-button/features/accepts_icon/index.js +0 -1
- package/build/cjs/split-button/features/accepts_initial_focus/index.js +1 -2
- package/build/cjs/split-button/features/arrow_opens_menu/index.js +0 -1
- package/build/cjs/split-button/features/button_is_clickable/index.js +1 -2
- package/build/cjs/split-button/features/can_be_disabled/index.js +0 -1
- package/build/cjs/split-button/features/common/index.js +0 -1
- package/build/cjs/split-button/index.js +0 -1
- package/build/cjs/split-button/split-button.e2e.stories.js +53 -0
- package/build/cjs/split-button/split-button.js +13 -48
- package/build/cjs/split-button/{split-button.stories.js → split-button.prod.stories.js} +30 -42
- package/build/cjs/split-button/split-button.test.js +5 -22
- package/build/es/button/{button.stories.e2e.js → button.e2e.stories.js} +9 -5
- package/build/es/button/button.js +5 -33
- package/build/es/button/{button.stories.js → button.prod.stories.js} +23 -16
- package/build/es/button/button.styles.js +1 -1
- package/build/es/button/features/can_be_blurred/index.js +1 -1
- package/build/es/button/features/can_be_clicked/index.js +1 -1
- package/build/es/button/features/can_be_focused/index.js +1 -1
- package/build/es/button-strip/button-strip.e2e.stories.js +7 -0
- package/build/es/button-strip/button-strip.js +1 -5
- package/build/es/button-strip/{button-strip.stories.js → button-strip.prod.stories.js} +10 -4
- package/build/es/dropdown-button/{dropdown-button.stories.e2e.js → dropdown-button.e2e.stories.js} +17 -9
- package/build/es/dropdown-button/dropdown-button.js +8 -35
- package/build/es/dropdown-button/{dropdown-button.stories.js → dropdown-button.prod.stories.js} +21 -20
- package/build/es/dropdown-button/features/accepts_initial_focus/index.js +1 -1
- package/build/es/dropdown-button/features/button_is_clickable/index.js +1 -1
- package/build/es/dropdown-button/features/can_be_disabled/index.js +1 -1
- package/build/es/split-button/features/accepts_initial_focus/index.js +1 -1
- package/build/es/split-button/features/button_is_clickable/index.js +1 -1
- package/build/es/split-button/{split-button.stories.e2e.js → split-button.e2e.stories.js} +15 -8
- package/build/es/split-button/split-button.js +10 -32
- package/build/es/split-button/{split-button.stories.js → split-button.prod.stories.js} +19 -13
- package/build/es/split-button/split-button.test.js +4 -2
- package/package.json +9 -9
- package/build/cjs/button/button.stories.e2e.js +0 -27
- package/build/cjs/button-strip/button-strip.stories.e2e.js +0 -13
- package/build/cjs/dropdown-button/dropdown-button.stories.e2e.js +0 -45
- package/build/cjs/split-button/split-button.stories.e2e.js +0 -40
- package/build/es/button-strip/button-strip.stories.e2e.js +0 -5
package/build/es/dropdown-button/{dropdown-button.stories.e2e.js → dropdown-button.e2e.stories.js}
RENAMED
@@ -1,38 +1,46 @@
|
|
1
|
-
import { storiesOf } from '@storybook/react';
|
2
1
|
import React from 'react';
|
3
2
|
import { DropdownButton } from './index.js';
|
4
3
|
window.onClick = window.Cypress && window.Cypress.cy.stub();
|
5
|
-
|
4
|
+
export default {
|
5
|
+
title: 'DropdownButton'
|
6
|
+
};
|
7
|
+
export const Default = () => /*#__PURE__*/React.createElement(DropdownButton, {
|
6
8
|
name: "Button",
|
7
9
|
value: "default",
|
8
10
|
component: /*#__PURE__*/React.createElement("div", null, "Content")
|
9
|
-
}, "Button")
|
11
|
+
}, "Button");
|
12
|
+
export const WithOnClick = () => /*#__PURE__*/React.createElement(DropdownButton, {
|
10
13
|
name: "Button",
|
11
14
|
value: "default",
|
12
15
|
onClick: window.onClick,
|
13
16
|
component: /*#__PURE__*/React.createElement("div", null, "Content")
|
14
|
-
}, "Button")
|
17
|
+
}, "Button");
|
18
|
+
export const WithChildren = () => /*#__PURE__*/React.createElement(DropdownButton, {
|
15
19
|
name: "Button",
|
16
20
|
value: "default",
|
17
21
|
component: /*#__PURE__*/React.createElement("div", null, "Component")
|
18
|
-
}, "I am a child")
|
22
|
+
}, "I am a child");
|
23
|
+
export const WithComponent = () => /*#__PURE__*/React.createElement(DropdownButton, {
|
19
24
|
name: "Button",
|
20
25
|
value: "default",
|
21
26
|
component: /*#__PURE__*/React.createElement("div", null, "I am a component")
|
22
|
-
})
|
27
|
+
});
|
28
|
+
export const WithIcon = () => /*#__PURE__*/React.createElement(DropdownButton, {
|
23
29
|
name: "Button",
|
24
30
|
value: "default",
|
25
31
|
component: /*#__PURE__*/React.createElement("div", null, "I am a component"),
|
26
32
|
icon: 'Icon'
|
27
|
-
})
|
33
|
+
});
|
34
|
+
export const WithInitialFocus = () => /*#__PURE__*/React.createElement(DropdownButton, {
|
28
35
|
name: "Button",
|
29
36
|
value: "default",
|
30
37
|
component: /*#__PURE__*/React.createElement("div", null, "Content"),
|
31
38
|
initialFocus: true
|
32
|
-
})
|
39
|
+
});
|
40
|
+
export const DisabledWithOnClick = () => /*#__PURE__*/React.createElement(DropdownButton, {
|
33
41
|
name: "Button",
|
34
42
|
value: "default",
|
35
43
|
component: /*#__PURE__*/React.createElement("div", null, "Content"),
|
36
44
|
onClick: window.onClick,
|
37
45
|
disabled: true
|
38
|
-
})
|
46
|
+
});
|
@@ -1,15 +1,14 @@
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
2
|
-
|
3
|
-
function
|
4
|
-
|
5
|
-
import { Layer } from '@dhis2-ui/layer';
|
6
|
-
import { Popper } from '@dhis2-ui/popper';
|
2
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
3
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
4
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
7
5
|
import { requiredIf } from '@dhis2/prop-types';
|
8
6
|
import { spacers, sharedPropTypes } from '@dhis2/ui-constants';
|
7
|
+
import { Layer } from '@dhis2-ui/layer';
|
8
|
+
import { Popper } from '@dhis2-ui/popper';
|
9
9
|
import PropTypes from 'prop-types';
|
10
10
|
import React, { Component } from 'react';
|
11
|
-
import { Button } from '../index.js';
|
12
|
-
|
11
|
+
import { Button } from '../button/index.js';
|
13
12
|
function ArrowDown(_ref) {
|
14
13
|
let {
|
15
14
|
className
|
@@ -25,11 +24,9 @@ function ArrowDown(_ref) {
|
|
25
24
|
id: "2347926856"
|
26
25
|
}, ["svg.jsx-2347926856{fill:inherit;height:12px;width:12px;vertical-align:middle;pointer-events:none;}"]));
|
27
26
|
}
|
28
|
-
|
29
27
|
ArrowDown.propTypes = {
|
30
28
|
className: PropTypes.string
|
31
29
|
};
|
32
|
-
|
33
30
|
function ArrowUp(_ref2) {
|
34
31
|
let {
|
35
32
|
className
|
@@ -46,27 +43,22 @@ function ArrowUp(_ref2) {
|
|
46
43
|
id: "2347926856"
|
47
44
|
}, ["svg.jsx-2347926856{fill:inherit;height:12px;width:12px;vertical-align:middle;pointer-events:none;}"]));
|
48
45
|
}
|
49
|
-
|
50
46
|
ArrowUp.propTypes = {
|
51
47
|
className: PropTypes.string
|
52
48
|
};
|
53
49
|
const arrow = {
|
54
50
|
styles: /*#__PURE__*/React.createElement(_JSXStyle, {
|
55
51
|
id: "1035250400"
|
56
|
-
}, [
|
52
|
+
}, [`.jsx-1035250400{margin-inline-start:${spacers.dp12};}`]),
|
57
53
|
className: "jsx-1035250400"
|
58
54
|
};
|
59
|
-
|
60
55
|
class DropdownButton extends Component {
|
61
56
|
constructor() {
|
62
57
|
super(...arguments);
|
63
|
-
|
64
58
|
_defineProperty(this, "state", {
|
65
59
|
open: false
|
66
60
|
});
|
67
|
-
|
68
61
|
_defineProperty(this, "anchorRef", /*#__PURE__*/React.createRef());
|
69
|
-
|
70
62
|
_defineProperty(this, "handleKeyDown", event => {
|
71
63
|
if (event.key === 'Escape' && this.state.open) {
|
72
64
|
event.preventDefault();
|
@@ -76,13 +68,11 @@ class DropdownButton extends Component {
|
|
76
68
|
});
|
77
69
|
}
|
78
70
|
});
|
79
|
-
|
80
71
|
_defineProperty(this, "onClickHandler", (_ref3, event) => {
|
81
72
|
let {
|
82
73
|
name,
|
83
74
|
value
|
84
75
|
} = _ref3;
|
85
|
-
|
86
76
|
const handleClick = open => {
|
87
77
|
if (this.props.onClick) {
|
88
78
|
this.props.onClick({
|
@@ -92,7 +82,6 @@ class DropdownButton extends Component {
|
|
92
82
|
}, event);
|
93
83
|
}
|
94
84
|
};
|
95
|
-
|
96
85
|
if (typeof this.props.open === 'boolean') {
|
97
86
|
handleClick(!this.props.open);
|
98
87
|
} else {
|
@@ -104,15 +93,12 @@ class DropdownButton extends Component {
|
|
104
93
|
}
|
105
94
|
});
|
106
95
|
}
|
107
|
-
|
108
96
|
componentDidMount() {
|
109
97
|
document.addEventListener('keydown', this.handleKeyDown);
|
110
98
|
}
|
111
|
-
|
112
99
|
componentWillUnmount() {
|
113
100
|
document.removeEventListener('keydown', this.handleKeyDown);
|
114
101
|
}
|
115
|
-
|
116
102
|
render() {
|
117
103
|
const {
|
118
104
|
component,
|
@@ -160,16 +146,14 @@ class DropdownButton extends Component {
|
|
160
146
|
onBackdropClick: this.onClickHandler,
|
161
147
|
transparent: true
|
162
148
|
}, /*#__PURE__*/React.createElement(Popper, {
|
163
|
-
dataTest:
|
149
|
+
dataTest: `${dataTest}-popper`,
|
164
150
|
placement: "bottom-start",
|
165
151
|
reference: this.anchorRef
|
166
152
|
}, component)), arrow.styles, /*#__PURE__*/React.createElement(_JSXStyle, {
|
167
153
|
id: "3163060161"
|
168
154
|
}, ["div.jsx-3163060161{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;position:relative;color:inherit;white-space:nowrap;}"]));
|
169
155
|
}
|
170
|
-
|
171
156
|
}
|
172
|
-
|
173
157
|
DropdownButton.defaultProps = {
|
174
158
|
dataTest: 'dhis2-uicore-dropdownbutton'
|
175
159
|
};
|
@@ -177,48 +161,37 @@ DropdownButton.propTypes = {
|
|
177
161
|
/** Children to render inside the buton */
|
178
162
|
children: PropTypes.node,
|
179
163
|
className: PropTypes.string,
|
180
|
-
|
181
164
|
/** Component to show/hide when button is clicked */
|
182
165
|
component: PropTypes.element,
|
183
166
|
dataTest: PropTypes.string,
|
184
|
-
|
185
167
|
/**
|
186
168
|
* Applies 'destructive' button appearance, implying a dangerous action.
|
187
169
|
*/
|
188
170
|
destructive: PropTypes.bool,
|
189
|
-
|
190
171
|
/** Make the button non-interactive */
|
191
172
|
disabled: PropTypes.bool,
|
192
173
|
icon: PropTypes.element,
|
193
|
-
|
194
174
|
/** Grants button initial focus on the page */
|
195
175
|
initialFocus: PropTypes.bool,
|
196
|
-
|
197
176
|
/** Button size. Mutually exclusive with `small` prop */
|
198
177
|
large: sharedPropTypes.sizePropType,
|
199
178
|
name: PropTypes.string,
|
200
|
-
|
201
179
|
/** Controls popper visibility. When implementing this prop the component becomes a controlled component */
|
202
180
|
open: PropTypes.bool,
|
203
|
-
|
204
181
|
/**
|
205
182
|
* Applies 'primary' button appearance, implying the most important action.
|
206
183
|
*/
|
207
184
|
primary: PropTypes.bool,
|
208
|
-
|
209
185
|
/**
|
210
186
|
* Applies 'secondary' button appearance.
|
211
187
|
*/
|
212
188
|
secondary: PropTypes.bool,
|
213
|
-
|
214
189
|
/** Button size. Mutually exclusive with `large` prop */
|
215
190
|
small: sharedPropTypes.sizePropType,
|
216
191
|
tabIndex: PropTypes.string,
|
217
|
-
|
218
192
|
/** Type of button. Can take advantage of different default behavior */
|
219
193
|
type: PropTypes.oneOf(['submit', 'reset', 'button']),
|
220
194
|
value: PropTypes.string,
|
221
|
-
|
222
195
|
/**
|
223
196
|
* Callback triggered on click.
|
224
197
|
* Called with signature `({ name: string, value: string, open: bool }, event)`
|
package/build/es/dropdown-button/{dropdown-button.stories.js → dropdown-button.prod.stories.js}
RENAMED
@@ -1,10 +1,15 @@
|
|
1
|
-
function _extends() { _extends = Object.assign
|
2
|
-
|
3
|
-
import { FlyoutMenu, MenuItem } from '@dhis2-ui/menu';
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
4
2
|
import { sharedPropTypes } from '@dhis2/ui-constants';
|
3
|
+
import { FlyoutMenu, MenuItem } from '@dhis2-ui/menu';
|
5
4
|
import React, { useState } from 'react';
|
6
5
|
import { DropdownButton } from './index.js';
|
7
|
-
const description =
|
6
|
+
const description = `
|
7
|
+
Presents several actions to a user in a small space. Can replace single, individual buttons. Should only be used for actions that are related to one another. Ensure the button has a useful level that communicates that actions are contained within. Dropdown buttons do not have an explicit action, only expanding the list of contained actions.
|
8
|
+
|
9
|
+
\`\`\`js
|
10
|
+
import { DropdownButton } from '@dhis2/ui'
|
11
|
+
\`\`\`
|
12
|
+
`;
|
8
13
|
const Simple = /*#__PURE__*/React.createElement("span", null, "Simplest thing");
|
9
14
|
const {
|
10
15
|
sizeArgType,
|
@@ -21,15 +26,20 @@ export default {
|
|
21
26
|
}
|
22
27
|
},
|
23
28
|
argTypes: {
|
24
|
-
primary: {
|
29
|
+
primary: {
|
30
|
+
...buttonVariantArgType
|
25
31
|
},
|
26
|
-
secondary: {
|
32
|
+
secondary: {
|
33
|
+
...buttonVariantArgType
|
27
34
|
},
|
28
|
-
destructive: {
|
35
|
+
destructive: {
|
36
|
+
...buttonVariantArgType
|
29
37
|
},
|
30
|
-
small: {
|
38
|
+
small: {
|
39
|
+
...sizeArgType
|
31
40
|
},
|
32
|
-
large: {
|
41
|
+
large: {
|
42
|
+
...sizeArgType
|
33
43
|
}
|
34
44
|
},
|
35
45
|
// Default args for all stories (can be overridden)
|
@@ -40,9 +50,7 @@ export default {
|
|
40
50
|
children: 'Label me!'
|
41
51
|
}
|
42
52
|
};
|
43
|
-
|
44
53
|
const Template = args => /*#__PURE__*/React.createElement(DropdownButton, args);
|
45
|
-
|
46
54
|
export const Default = Template.bind({});
|
47
55
|
export const WithClick = Template.bind({});
|
48
56
|
WithClick.args = {
|
@@ -86,9 +94,9 @@ WithMenu.args = {
|
|
86
94
|
}), /*#__PURE__*/React.createElement(MenuItem, {
|
87
95
|
label: "Item 3"
|
88
96
|
}))
|
89
|
-
};
|
97
|
+
};
|
98
|
+
// FlyoutMenu needs iframe
|
90
99
|
// But docs page down too much with iframe, so disabled
|
91
|
-
|
92
100
|
WithMenu.parameters = {
|
93
101
|
docs: {
|
94
102
|
disable: true
|
@@ -103,29 +111,23 @@ InitialFocus.args = {
|
|
103
111
|
* a control is changed, therefore it is omitted from the docs page (but
|
104
112
|
* not the normal 'canvas' story viewer)
|
105
113
|
*/
|
106
|
-
|
107
114
|
InitialFocus.parameters = {
|
108
115
|
docs: {
|
109
116
|
disable: true
|
110
117
|
}
|
111
118
|
};
|
112
|
-
|
113
119
|
const OpenTemplate = args => {
|
114
120
|
return /*#__PURE__*/React.createElement(DropdownButton, args);
|
115
121
|
};
|
116
|
-
|
117
122
|
export const Open = OpenTemplate.bind({});
|
118
123
|
Open.args = {
|
119
124
|
open: true,
|
120
125
|
component: Simple,
|
121
126
|
onClick: () => {}
|
122
127
|
};
|
123
|
-
|
124
128
|
const ManualControlTemplate = args => {
|
125
129
|
const [isOpen, setIsOpen] = useState(true);
|
126
|
-
|
127
130
|
const handleOpen = () => setIsOpen(false);
|
128
|
-
|
129
131
|
const Menu = /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", null, "First option does nothing"), /*#__PURE__*/React.createElement("li", {
|
130
132
|
onClick: handleOpen
|
131
133
|
}, "Close the dropdown"));
|
@@ -135,7 +137,6 @@ const ManualControlTemplate = args => {
|
|
135
137
|
component: Menu
|
136
138
|
}));
|
137
139
|
};
|
138
|
-
|
139
140
|
export const ManualControl = ManualControlTemplate.bind({});
|
140
141
|
ManualControl.args = {};
|
141
142
|
export const RTL = args => /*#__PURE__*/React.createElement("div", {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor';
|
2
2
|
Given('a DropdownButton with initialFocus is rendered', () => {
|
3
|
-
cy.visitStory('DropdownButton', 'With
|
3
|
+
cy.visitStory('DropdownButton', 'With initial focus');
|
4
4
|
});
|
5
5
|
Then('the DropdownButton is focused', () => {
|
6
6
|
cy.focused().parent('[data-test="dhis2-uicore-dropdownbutton"]').should('exist');
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor';
|
2
2
|
Given('a DropdownButton with onClick handler is rendered', () => {
|
3
|
-
cy.visitStory('DropdownButton', 'With
|
3
|
+
cy.visitStory('DropdownButton', 'With on click');
|
4
4
|
});
|
5
5
|
Then('the onClick handler is called', () => {
|
6
6
|
cy.window().should(win => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor';
|
2
2
|
Given('a disabled DropdownButton with onClick handler is rendered', () => {
|
3
|
-
cy.visitStory('DropdownButton', 'Disabled with
|
3
|
+
cy.visitStory('DropdownButton', 'Disabled with on click');
|
4
4
|
});
|
5
5
|
Then('the onClick handler is not called', () => {
|
6
6
|
cy.window().should(win => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor';
|
2
2
|
Given('a SplitButton with initialFocus is rendered', () => {
|
3
|
-
cy.visitStory('SplitButton', 'With
|
3
|
+
cy.visitStory('SplitButton', 'With initial focus');
|
4
4
|
});
|
5
5
|
Then('the SplitButton button is focused', () => {
|
6
6
|
cy.focused().should('have.attr', 'data-test', 'dhis2-uicore-splitbutton-button');
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor';
|
2
2
|
Given('a SplitButton with onClick hander is rendered', () => {
|
3
|
-
cy.visitStory('SplitButton', 'With
|
3
|
+
cy.visitStory('SplitButton', 'With on click');
|
4
4
|
});
|
5
5
|
Then('the onClick handler is called', () => {
|
6
6
|
cy.window().its('onClick').should('be.calledWith', {
|
@@ -1,33 +1,40 @@
|
|
1
|
-
import { storiesOf } from '@storybook/react';
|
2
1
|
import React from 'react';
|
3
2
|
import { SplitButton } from './split-button.js';
|
4
3
|
window.onClick = window.Cypress && window.Cypress.cy.stub();
|
5
|
-
|
4
|
+
export default {
|
5
|
+
title: 'SplitButton'
|
6
|
+
};
|
7
|
+
export const Default = () => /*#__PURE__*/React.createElement(SplitButton, {
|
6
8
|
name: "Button",
|
7
9
|
value: "default",
|
8
10
|
component: /*#__PURE__*/React.createElement("div", null, "Component")
|
9
|
-
}, "Label me!")
|
11
|
+
}, "Label me!");
|
12
|
+
export const WithOnClick = () => /*#__PURE__*/React.createElement(SplitButton, {
|
10
13
|
name: "Button",
|
11
14
|
value: "default",
|
12
15
|
component: /*#__PURE__*/React.createElement("div", null, "Component"),
|
13
16
|
onClick: window.onClick
|
14
|
-
}, "Label me!")
|
17
|
+
}, "Label me!");
|
18
|
+
export const WithChildren = () => /*#__PURE__*/React.createElement(SplitButton, {
|
15
19
|
name: "Button",
|
16
20
|
value: "default",
|
17
21
|
component: /*#__PURE__*/React.createElement("div", null, "Component")
|
18
|
-
}, "I am a child")
|
22
|
+
}, "I am a child");
|
23
|
+
export const WithIcon = () => /*#__PURE__*/React.createElement(SplitButton, {
|
19
24
|
name: "Button",
|
20
25
|
value: "default",
|
21
26
|
component: /*#__PURE__*/React.createElement("div", null, "Component"),
|
22
27
|
icon: /*#__PURE__*/React.createElement("div", null, "Icon")
|
23
|
-
}, "Children")
|
28
|
+
}, "Children");
|
29
|
+
export const WithInitialFocus = () => /*#__PURE__*/React.createElement(SplitButton, {
|
24
30
|
name: "Button",
|
25
31
|
value: "default",
|
26
32
|
component: /*#__PURE__*/React.createElement("div", null, "Component"),
|
27
33
|
initialFocus: true
|
28
|
-
}, "Children")
|
34
|
+
}, "Children");
|
35
|
+
export const WithDisabled = () => /*#__PURE__*/React.createElement(SplitButton, {
|
29
36
|
name: "Button",
|
30
37
|
value: "default",
|
31
38
|
component: /*#__PURE__*/React.createElement("div", null, "Component"),
|
32
39
|
disabled: true
|
33
|
-
}, "Children")
|
40
|
+
}, "Children");
|
@@ -1,33 +1,29 @@
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
2
|
-
|
3
|
-
function
|
4
|
-
|
5
|
-
import { Layer } from '@dhis2-ui/layer';
|
6
|
-
import { Popper } from '@dhis2-ui/popper';
|
2
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
3
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
4
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
7
5
|
import { spacers, sharedPropTypes } from '@dhis2/ui-constants';
|
8
6
|
import { IconChevronUp16, IconChevronDown16 } from '@dhis2/ui-icons';
|
7
|
+
import { Layer } from '@dhis2-ui/layer';
|
8
|
+
import { Popper } from '@dhis2-ui/popper';
|
9
9
|
import cx from 'classnames';
|
10
10
|
import PropTypes from 'prop-types';
|
11
11
|
import React, { Component } from 'react';
|
12
|
-
import { Button } from '../index.js';
|
12
|
+
import { Button } from '../button/index.js';
|
13
13
|
import i18n from '../locales/index.js';
|
14
14
|
const rightButton = {
|
15
15
|
styles: /*#__PURE__*/React.createElement(_JSXStyle, {
|
16
16
|
id: "2502148942"
|
17
|
-
}, [
|
17
|
+
}, [`button.jsx-2502148942{padding:0 ${spacers.dp12};}`]),
|
18
18
|
className: "jsx-2502148942"
|
19
19
|
};
|
20
|
-
|
21
20
|
class SplitButton extends Component {
|
22
21
|
constructor() {
|
23
22
|
super(...arguments);
|
24
|
-
|
25
23
|
_defineProperty(this, "state", {
|
26
24
|
open: false
|
27
25
|
});
|
28
|
-
|
29
26
|
_defineProperty(this, "anchorRef", /*#__PURE__*/React.createRef());
|
30
|
-
|
31
27
|
_defineProperty(this, "handleKeyDown", event => {
|
32
28
|
if (event.key === 'Escape' && this.state.open) {
|
33
29
|
event.preventDefault();
|
@@ -38,7 +34,6 @@ class SplitButton extends Component {
|
|
38
34
|
this.anchorRef.current && this.anchorRef.current.focus();
|
39
35
|
}
|
40
36
|
});
|
41
|
-
|
42
37
|
_defineProperty(this, "onClick", (payload, event) => {
|
43
38
|
if (this.props.onClick) {
|
44
39
|
this.props.onClick({
|
@@ -48,22 +43,18 @@ class SplitButton extends Component {
|
|
48
43
|
}, event);
|
49
44
|
}
|
50
45
|
});
|
51
|
-
|
52
46
|
_defineProperty(this, "onToggle", () => {
|
53
47
|
this.setState(prevState => ({
|
54
48
|
open: !prevState.open
|
55
49
|
}));
|
56
50
|
});
|
57
51
|
}
|
58
|
-
|
59
52
|
componentDidMount() {
|
60
53
|
document.addEventListener('keydown', this.handleKeyDown);
|
61
54
|
}
|
62
|
-
|
63
55
|
componentWillUnmount() {
|
64
56
|
document.removeEventListener('keydown', this.handleKeyDown);
|
65
57
|
}
|
66
|
-
|
67
58
|
render() {
|
68
59
|
const {
|
69
60
|
open
|
@@ -106,7 +97,7 @@ class SplitButton extends Component {
|
|
106
97
|
tabIndex: tabIndex,
|
107
98
|
className: cx(className),
|
108
99
|
initialFocus: initialFocus,
|
109
|
-
dataTest:
|
100
|
+
dataTest: `${dataTest}-button`
|
110
101
|
}, children), /*#__PURE__*/React.createElement(Button, {
|
111
102
|
name: name,
|
112
103
|
value: value,
|
@@ -120,69 +111,56 @@ class SplitButton extends Component {
|
|
120
111
|
type: type,
|
121
112
|
tabIndex: tabIndex,
|
122
113
|
className: cx(className, rightButton.className),
|
123
|
-
dataTest:
|
114
|
+
dataTest: `${dataTest}-toggle`,
|
124
115
|
title: i18n.t('Toggle dropdown'),
|
125
116
|
"aria-label": i18n.t('Toggle dropdown')
|
126
117
|
}, arrow), open && /*#__PURE__*/React.createElement(Layer, {
|
127
118
|
onBackdropClick: this.onToggle,
|
128
119
|
transparent: true
|
129
120
|
}, /*#__PURE__*/React.createElement(Popper, {
|
130
|
-
dataTest:
|
121
|
+
dataTest: `${dataTest}-menu`,
|
131
122
|
placement: "bottom-end",
|
132
123
|
reference: this.anchorRef
|
133
124
|
}, component)), rightButton.styles, /*#__PURE__*/React.createElement(_JSXStyle, {
|
134
125
|
id: "2116647326"
|
135
126
|
}, ["div.jsx-2116647326{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;color:inherit;white-space:nowrap;position:relative;z-index:0;}", "div.jsx-2116647326>button:first-child{border-start-end-radius:0;border-end-end-radius:0;border-inline-end:0;}", "div.jsx-2116647326>button:last-child{border-start-start-radius:0;border-end-start-radius:0;}"]));
|
136
127
|
}
|
137
|
-
|
138
128
|
}
|
139
|
-
|
140
129
|
SplitButton.defaultProps = {
|
141
130
|
dataTest: 'dhis2-uicore-splitbutton'
|
142
131
|
};
|
143
132
|
SplitButton.propTypes = {
|
144
133
|
children: PropTypes.string,
|
145
134
|
className: PropTypes.string,
|
146
|
-
|
147
135
|
/** Component to render when the dropdown is opened */
|
148
136
|
component: PropTypes.element,
|
149
137
|
dataTest: PropTypes.string,
|
150
|
-
|
151
138
|
/**
|
152
139
|
* Applies 'destructive' button appearance, implying a dangerous action.
|
153
140
|
*/
|
154
141
|
destructive: PropTypes.bool,
|
155
|
-
|
156
142
|
/** Disables the button and makes it uninteractive */
|
157
143
|
disabled: PropTypes.bool,
|
158
|
-
|
159
144
|
/** An icon to add inside the button */
|
160
145
|
icon: PropTypes.element,
|
161
|
-
|
162
146
|
/** Grants the button the initial focus */
|
163
147
|
initialFocus: PropTypes.bool,
|
164
|
-
|
165
148
|
/** Changes button size. Mutually exclusive with `small` prop */
|
166
149
|
large: sharedPropTypes.sizePropType,
|
167
150
|
name: PropTypes.string,
|
168
|
-
|
169
151
|
/**
|
170
152
|
* Applies 'primary' button appearance, implying the most important action.
|
171
153
|
*/
|
172
154
|
primary: PropTypes.bool,
|
173
|
-
|
174
155
|
/**
|
175
156
|
* Applies 'secondary' button appearance.
|
176
157
|
*/
|
177
158
|
secondary: PropTypes.bool,
|
178
|
-
|
179
159
|
/** Changes button size. Mutually exclusive with `large` prop */
|
180
160
|
small: sharedPropTypes.sizePropType,
|
181
161
|
tabIndex: PropTypes.string,
|
182
|
-
|
183
162
|
/** Type of button. Applied to html `button` element */
|
184
163
|
type: PropTypes.oneOf(['submit', 'reset', 'button']),
|
185
|
-
|
186
164
|
/** Value associated with the button. Passed in object to onClick handler */
|
187
165
|
value: PropTypes.string,
|
188
166
|
onClick: PropTypes.func
|
@@ -1,17 +1,20 @@
|
|
1
1
|
import { sharedPropTypes } from '@dhis2/ui-constants';
|
2
2
|
import React from 'react';
|
3
3
|
import { SplitButton } from './split-button.js';
|
4
|
-
const description =
|
4
|
+
const description = `
|
5
|
+
Similar to the dropdown button, but can be triggered independently of opening the contained action list. The main action may be 'Save' and the contained actions may be "Save and add another" and "Save and open".
|
5
6
|
|
7
|
+
\`\`\`js
|
8
|
+
import { SplitButton } from '@dhis2/ui'
|
9
|
+
\`\`\`
|
10
|
+
`;
|
6
11
|
window.onClick = (payload, event) => {
|
7
12
|
console.log('onClick payload', payload);
|
8
13
|
console.log('onClick event', event);
|
9
14
|
};
|
10
|
-
|
11
15
|
const onClick = function () {
|
12
16
|
return window.onClick(...arguments);
|
13
17
|
};
|
14
|
-
|
15
18
|
const DropdownComponent = /*#__PURE__*/React.createElement("span", null, "Dropdown component");
|
16
19
|
export default {
|
17
20
|
title: 'Split Button',
|
@@ -31,21 +34,24 @@ export default {
|
|
31
34
|
children: 'Label me!'
|
32
35
|
},
|
33
36
|
argTypes: {
|
34
|
-
small: {
|
37
|
+
small: {
|
38
|
+
...sharedPropTypes.sizeArgType
|
35
39
|
},
|
36
|
-
large: {
|
40
|
+
large: {
|
41
|
+
...sharedPropTypes.sizeArgType
|
37
42
|
},
|
38
|
-
primary: {
|
43
|
+
primary: {
|
44
|
+
...sharedPropTypes.buttonVariantArgType
|
39
45
|
},
|
40
|
-
secondary: {
|
46
|
+
secondary: {
|
47
|
+
...sharedPropTypes.buttonVariantArgType
|
41
48
|
},
|
42
|
-
destructive: {
|
49
|
+
destructive: {
|
50
|
+
...sharedPropTypes.buttonVariantArgType
|
43
51
|
}
|
44
52
|
}
|
45
53
|
};
|
46
|
-
|
47
54
|
const Template = args => /*#__PURE__*/React.createElement(SplitButton, args);
|
48
|
-
|
49
55
|
export const Default = Template.bind({});
|
50
56
|
export const Primary = Template.bind({});
|
51
57
|
Primary.args = {
|
@@ -54,7 +60,7 @@ Primary.args = {
|
|
54
60
|
Primary.parameters = {
|
55
61
|
docs: {
|
56
62
|
description: {
|
57
|
-
story:
|
63
|
+
story: `_**Note**: The dropdown components in the following examples do not appear in the right place on this page. View the following examples in the 'Canvas' tab for the correct placement._`
|
58
64
|
}
|
59
65
|
}
|
60
66
|
};
|
@@ -81,8 +87,8 @@ Large.args = {
|
|
81
87
|
export const InitialFocus = Template.bind({});
|
82
88
|
InitialFocus.args = {
|
83
89
|
initialFocus: true
|
84
|
-
};
|
85
|
-
|
90
|
+
};
|
91
|
+
// Disable this on docs page because grabbing focus repeatedly is annoying
|
86
92
|
InitialFocus.parameters = {
|
87
93
|
docs: {
|
88
94
|
disable: true
|