@dhis2-ui/button 10.6.0 → 10.7.1
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/build/cjs/split-button/split-button.js +82 -32
- package/build/cjs/split-button/split-button.prod.stories.js +48 -1
- package/build/es/split-button/split-button.js +67 -17
- package/build/es/split-button/split-button.prod.stories.js +46 -0
- package/package.json +6 -6
- package/types/index.d.ts +15 -1
@@ -5,12 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.SplitButton = void 0;
|
7
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
8
|
+
var _propTypes = require("@dhis2/prop-types");
|
8
9
|
var _uiConstants = require("@dhis2/ui-constants");
|
9
10
|
var _uiIcons = require("@dhis2/ui-icons");
|
10
11
|
var _layer = require("@dhis2-ui/layer");
|
11
12
|
var _popper = require("@dhis2-ui/popper");
|
12
13
|
var _classnames = _interopRequireDefault(require("classnames"));
|
13
|
-
var
|
14
|
+
var _propTypes2 = _interopRequireDefault(require("prop-types"));
|
14
15
|
var _react = _interopRequireWildcard(require("react"));
|
15
16
|
var _index = require("../button/index.js");
|
16
17
|
var _index2 = _interopRequireDefault(require("../locales/index.js"));
|
@@ -33,29 +34,66 @@ class SplitButton extends _react.Component {
|
|
33
34
|
open: false
|
34
35
|
});
|
35
36
|
_defineProperty(this, "anchorRef", /*#__PURE__*/_react.default.createRef());
|
37
|
+
_defineProperty(this, "isControlled", () => typeof this.props.open === 'boolean');
|
36
38
|
_defineProperty(this, "handleKeyDown", event => {
|
37
|
-
|
39
|
+
const open = this.isControlled() ? this.props.open : this.state.open;
|
40
|
+
if (event.key === 'Escape' && open) {
|
38
41
|
event.preventDefault();
|
39
42
|
event.stopPropagation();
|
40
|
-
this.
|
41
|
-
|
42
|
-
|
43
|
+
if (this.isControlled()) {
|
44
|
+
if (this.props.onToggle) {
|
45
|
+
this.props.onToggle({
|
46
|
+
name: this.props.name,
|
47
|
+
value: this.props.value,
|
48
|
+
open: false
|
49
|
+
}, event);
|
50
|
+
}
|
51
|
+
} else {
|
52
|
+
this.setState({
|
53
|
+
open: false
|
54
|
+
});
|
55
|
+
}
|
43
56
|
this.anchorRef.current && this.anchorRef.current.focus();
|
44
57
|
}
|
45
58
|
});
|
46
|
-
_defineProperty(this, "
|
59
|
+
_defineProperty(this, "handlePrimaryAction", (payload, event) => {
|
47
60
|
if (this.props.onClick) {
|
48
61
|
this.props.onClick({
|
49
62
|
name: payload.name,
|
50
63
|
value: payload.value,
|
51
|
-
open: this.state.open
|
64
|
+
open: this.isControlled() ? this.props.open : this.state.open
|
52
65
|
}, event);
|
53
66
|
}
|
54
67
|
});
|
55
|
-
_defineProperty(this, "
|
56
|
-
this.
|
57
|
-
|
58
|
-
|
68
|
+
_defineProperty(this, "handleToggle", (payload, event) => {
|
69
|
+
if (this.isControlled()) {
|
70
|
+
if (this.props.onToggle) {
|
71
|
+
this.props.onToggle({
|
72
|
+
name: payload.name,
|
73
|
+
value: payload.value,
|
74
|
+
open: !this.props.open
|
75
|
+
}, event);
|
76
|
+
}
|
77
|
+
} else {
|
78
|
+
this.setState(prevState => ({
|
79
|
+
open: !prevState.open
|
80
|
+
}));
|
81
|
+
}
|
82
|
+
});
|
83
|
+
_defineProperty(this, "handleBackdropClick", event => {
|
84
|
+
if (this.isControlled()) {
|
85
|
+
if (this.props.onToggle) {
|
86
|
+
this.props.onToggle({
|
87
|
+
name: this.props.name,
|
88
|
+
value: this.props.value,
|
89
|
+
open: false
|
90
|
+
}, event);
|
91
|
+
}
|
92
|
+
} else {
|
93
|
+
this.setState({
|
94
|
+
open: false
|
95
|
+
});
|
96
|
+
}
|
59
97
|
});
|
60
98
|
}
|
61
99
|
componentDidMount() {
|
@@ -65,9 +103,7 @@ class SplitButton extends _react.Component {
|
|
65
103
|
document.removeEventListener('keydown', this.handleKeyDown);
|
66
104
|
}
|
67
105
|
render() {
|
68
|
-
const
|
69
|
-
open
|
70
|
-
} = this.state;
|
106
|
+
const open = this.isControlled() ? this.props.open : this.state.open;
|
71
107
|
const {
|
72
108
|
component,
|
73
109
|
children,
|
@@ -101,7 +137,7 @@ class SplitButton extends _react.Component {
|
|
101
137
|
secondary: secondary,
|
102
138
|
destructive: destructive,
|
103
139
|
disabled: disabled,
|
104
|
-
onClick: this.
|
140
|
+
onClick: this.handlePrimaryAction,
|
105
141
|
type: type,
|
106
142
|
tabIndex: tabIndex,
|
107
143
|
className: (0, _classnames.default)(className),
|
@@ -116,7 +152,7 @@ class SplitButton extends _react.Component {
|
|
116
152
|
secondary: secondary,
|
117
153
|
destructive: destructive,
|
118
154
|
disabled: disabled,
|
119
|
-
onClick: this.
|
155
|
+
onClick: this.handleToggle,
|
120
156
|
type: type,
|
121
157
|
tabIndex: tabIndex,
|
122
158
|
className: (0, _classnames.default)(className, rightButton.className),
|
@@ -124,7 +160,7 @@ class SplitButton extends _react.Component {
|
|
124
160
|
title: _index2.default.t('Toggle dropdown'),
|
125
161
|
"aria-label": _index2.default.t('Toggle dropdown')
|
126
162
|
}, arrow), open && /*#__PURE__*/_react.default.createElement(_layer.Layer, {
|
127
|
-
onBackdropClick: this.
|
163
|
+
onBackdropClick: this.handleBackdropClick,
|
128
164
|
transparent: true
|
129
165
|
}, /*#__PURE__*/_react.default.createElement(_popper.Popper, {
|
130
166
|
dataTest: `${dataTest}-menu`,
|
@@ -140,38 +176,52 @@ _defineProperty(SplitButton, "defaultProps", {
|
|
140
176
|
dataTest: 'dhis2-uicore-splitbutton'
|
141
177
|
});
|
142
178
|
SplitButton.propTypes = {
|
143
|
-
children:
|
144
|
-
className:
|
179
|
+
children: _propTypes2.default.string,
|
180
|
+
className: _propTypes2.default.string,
|
145
181
|
/** Component to render when the dropdown is opened */
|
146
|
-
component:
|
147
|
-
dataTest:
|
182
|
+
component: _propTypes2.default.element,
|
183
|
+
dataTest: _propTypes2.default.string,
|
148
184
|
/**
|
149
185
|
* Applies 'destructive' button appearance, implying a dangerous action.
|
150
186
|
*/
|
151
|
-
destructive:
|
187
|
+
destructive: _propTypes2.default.bool,
|
152
188
|
/** Disables the button and makes it uninteractive */
|
153
|
-
disabled:
|
189
|
+
disabled: _propTypes2.default.bool,
|
154
190
|
/** An icon to add inside the button */
|
155
|
-
icon:
|
191
|
+
icon: _propTypes2.default.element,
|
156
192
|
/** Grants the button the initial focus */
|
157
|
-
initialFocus:
|
193
|
+
initialFocus: _propTypes2.default.bool,
|
158
194
|
/** Changes button size. Mutually exclusive with `small` prop */
|
159
195
|
large: _uiConstants.sharedPropTypes.sizePropType,
|
160
|
-
name:
|
196
|
+
name: _propTypes2.default.string,
|
197
|
+
/**
|
198
|
+
* Controls popper visibility. When implementing this prop the component becomes a controlled component
|
199
|
+
*/
|
200
|
+
open: _propTypes2.default.bool,
|
161
201
|
/**
|
162
202
|
* Applies 'primary' button appearance, implying the most important action.
|
163
203
|
*/
|
164
|
-
primary:
|
204
|
+
primary: _propTypes2.default.bool,
|
165
205
|
/**
|
166
206
|
* Applies 'secondary' button appearance.
|
167
207
|
*/
|
168
|
-
secondary:
|
208
|
+
secondary: _propTypes2.default.bool,
|
169
209
|
/** Changes button size. Mutually exclusive with `large` prop */
|
170
210
|
small: _uiConstants.sharedPropTypes.sizePropType,
|
171
|
-
tabIndex:
|
211
|
+
tabIndex: _propTypes2.default.string,
|
172
212
|
/** Type of button. Applied to html `button` element */
|
173
|
-
type:
|
213
|
+
type: _propTypes2.default.oneOf(['submit', 'reset', 'button']),
|
174
214
|
/** Value associated with the button. Passed in object to onClick handler */
|
175
|
-
value:
|
176
|
-
|
215
|
+
value: _propTypes2.default.string,
|
216
|
+
/**
|
217
|
+
* Callback triggered when the main button is clicked.
|
218
|
+
* Called with signature `({ name: string, value: string, open: bool }, event)`
|
219
|
+
*/
|
220
|
+
onClick: _propTypes2.default.func,
|
221
|
+
/**
|
222
|
+
* Callback triggered when the dropdown is toggled (by clicking the chevron, pressing Escape, or clicking the backdrop).
|
223
|
+
* Called with signature `({ name: string, value: string, open: bool }, event)`.
|
224
|
+
* Required if `open` prop is used (controlled component).
|
225
|
+
*/
|
226
|
+
onToggle: (0, _propTypes.requiredIf)(props => typeof props.open === 'boolean', _propTypes2.default.func)
|
177
227
|
};
|
@@ -3,11 +3,16 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.default = exports.WithIcon = exports.Small = exports.Secondary = exports.RTL = exports.Primary = exports.Large = exports.InitialFocus = exports.Disabled = exports.Destructive = exports.Default = void 0;
|
6
|
+
exports.default = exports.WithIcon = exports.Small = exports.Secondary = exports.RTL = exports.Primary = exports.Large = exports.InitialFocus = exports.Disabled = exports.Destructive = exports.Default = exports.ControlledOpen = void 0;
|
7
7
|
var _uiConstants = require("@dhis2/ui-constants");
|
8
|
+
var _menu = require("@dhis2-ui/menu");
|
9
|
+
var _modal = require("@dhis2-ui/modal");
|
8
10
|
var _react = _interopRequireDefault(require("react"));
|
11
|
+
var _button = require("../button/button.js");
|
12
|
+
var _buttonStrip = require("../button-strip/button-strip.js");
|
9
13
|
var _splitButton = require("./split-button.js");
|
10
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
15
|
+
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); }
|
11
16
|
const description = `
|
12
17
|
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".
|
13
18
|
|
@@ -113,4 +118,46 @@ const RTL = args => /*#__PURE__*/_react.default.createElement("div", {
|
|
113
118
|
exports.RTL = RTL;
|
114
119
|
RTL.args = {
|
115
120
|
children: 'RTL text'
|
121
|
+
};
|
122
|
+
const ControlledOpen = args => {
|
123
|
+
const [openFlyout, setOpenFlyout] = _react.default.useState(false);
|
124
|
+
const [openModal, setOpenModal] = _react.default.useState(false);
|
125
|
+
const handleClick = () => {
|
126
|
+
console.log('Main button clicked. This will not open the flyout menu.');
|
127
|
+
};
|
128
|
+
const handleToggle = () => {
|
129
|
+
setOpenFlyout(prevState => !prevState);
|
130
|
+
};
|
131
|
+
const component = /*#__PURE__*/_react.default.createElement(_menu.FlyoutMenu, null, /*#__PURE__*/_react.default.createElement(_menu.MenuItem, {
|
132
|
+
onClick: () => {
|
133
|
+
console.log('Console log and close flyout');
|
134
|
+
setOpenFlyout(false);
|
135
|
+
},
|
136
|
+
label: "Action 1"
|
137
|
+
}), /*#__PURE__*/_react.default.createElement(_menu.MenuItem, {
|
138
|
+
onClick: () => {
|
139
|
+
console.log('Open modal and close flyout');
|
140
|
+
setOpenFlyout(false);
|
141
|
+
setOpenModal(true);
|
142
|
+
},
|
143
|
+
label: "Open modal"
|
144
|
+
}));
|
145
|
+
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_splitButton.SplitButton, _extends({}, args, {
|
146
|
+
open: openFlyout,
|
147
|
+
onClick: handleClick,
|
148
|
+
onToggle: handleToggle,
|
149
|
+
component: component
|
150
|
+
})), openModal && /*#__PURE__*/_react.default.createElement(_modal.Modal, {
|
151
|
+
onClose: () => setOpenModal(false)
|
152
|
+
}, /*#__PURE__*/_react.default.createElement(_modal.ModalTitle, null, "Modal"), /*#__PURE__*/_react.default.createElement(_modal.ModalContent, null, /*#__PURE__*/_react.default.createElement("p", null, "Modal content")), /*#__PURE__*/_react.default.createElement(_modal.ModalActions, null, /*#__PURE__*/_react.default.createElement(_buttonStrip.ButtonStrip, null, /*#__PURE__*/_react.default.createElement(_button.Button, {
|
153
|
+
onClick: () => setOpenModal(false)
|
154
|
+
}, "Close")))));
|
155
|
+
};
|
156
|
+
exports.ControlledOpen = ControlledOpen;
|
157
|
+
ControlledOpen.parameters = {
|
158
|
+
docs: {
|
159
|
+
description: {
|
160
|
+
story: 'This story demonstrates how the `SplitButton` can be controlled from the outside using the `open` prop and an `onToggle` handler that updates the external state.'
|
161
|
+
}
|
162
|
+
}
|
116
163
|
};
|
@@ -2,6 +2,7 @@ import _JSXStyle from "styled-jsx/style";
|
|
2
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
3
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
4
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); }
|
5
|
+
import { requiredIf } from '@dhis2/prop-types';
|
5
6
|
import { spacers, sharedPropTypes } from '@dhis2/ui-constants';
|
6
7
|
import { IconChevronUp16, IconChevronDown16 } from '@dhis2/ui-icons';
|
7
8
|
import { Layer } from '@dhis2-ui/layer';
|
@@ -24,29 +25,66 @@ class SplitButton extends Component {
|
|
24
25
|
open: false
|
25
26
|
});
|
26
27
|
_defineProperty(this, "anchorRef", /*#__PURE__*/React.createRef());
|
28
|
+
_defineProperty(this, "isControlled", () => typeof this.props.open === 'boolean');
|
27
29
|
_defineProperty(this, "handleKeyDown", event => {
|
28
|
-
|
30
|
+
const open = this.isControlled() ? this.props.open : this.state.open;
|
31
|
+
if (event.key === 'Escape' && open) {
|
29
32
|
event.preventDefault();
|
30
33
|
event.stopPropagation();
|
31
|
-
this.
|
32
|
-
|
33
|
-
|
34
|
+
if (this.isControlled()) {
|
35
|
+
if (this.props.onToggle) {
|
36
|
+
this.props.onToggle({
|
37
|
+
name: this.props.name,
|
38
|
+
value: this.props.value,
|
39
|
+
open: false
|
40
|
+
}, event);
|
41
|
+
}
|
42
|
+
} else {
|
43
|
+
this.setState({
|
44
|
+
open: false
|
45
|
+
});
|
46
|
+
}
|
34
47
|
this.anchorRef.current && this.anchorRef.current.focus();
|
35
48
|
}
|
36
49
|
});
|
37
|
-
_defineProperty(this, "
|
50
|
+
_defineProperty(this, "handlePrimaryAction", (payload, event) => {
|
38
51
|
if (this.props.onClick) {
|
39
52
|
this.props.onClick({
|
40
53
|
name: payload.name,
|
41
54
|
value: payload.value,
|
42
|
-
open: this.state.open
|
55
|
+
open: this.isControlled() ? this.props.open : this.state.open
|
43
56
|
}, event);
|
44
57
|
}
|
45
58
|
});
|
46
|
-
_defineProperty(this, "
|
47
|
-
this.
|
48
|
-
|
49
|
-
|
59
|
+
_defineProperty(this, "handleToggle", (payload, event) => {
|
60
|
+
if (this.isControlled()) {
|
61
|
+
if (this.props.onToggle) {
|
62
|
+
this.props.onToggle({
|
63
|
+
name: payload.name,
|
64
|
+
value: payload.value,
|
65
|
+
open: !this.props.open
|
66
|
+
}, event);
|
67
|
+
}
|
68
|
+
} else {
|
69
|
+
this.setState(prevState => ({
|
70
|
+
open: !prevState.open
|
71
|
+
}));
|
72
|
+
}
|
73
|
+
});
|
74
|
+
_defineProperty(this, "handleBackdropClick", event => {
|
75
|
+
if (this.isControlled()) {
|
76
|
+
if (this.props.onToggle) {
|
77
|
+
this.props.onToggle({
|
78
|
+
name: this.props.name,
|
79
|
+
value: this.props.value,
|
80
|
+
open: false
|
81
|
+
}, event);
|
82
|
+
}
|
83
|
+
} else {
|
84
|
+
this.setState({
|
85
|
+
open: false
|
86
|
+
});
|
87
|
+
}
|
50
88
|
});
|
51
89
|
}
|
52
90
|
componentDidMount() {
|
@@ -56,9 +94,7 @@ class SplitButton extends Component {
|
|
56
94
|
document.removeEventListener('keydown', this.handleKeyDown);
|
57
95
|
}
|
58
96
|
render() {
|
59
|
-
const
|
60
|
-
open
|
61
|
-
} = this.state;
|
97
|
+
const open = this.isControlled() ? this.props.open : this.state.open;
|
62
98
|
const {
|
63
99
|
component,
|
64
100
|
children,
|
@@ -92,7 +128,7 @@ class SplitButton extends Component {
|
|
92
128
|
secondary: secondary,
|
93
129
|
destructive: destructive,
|
94
130
|
disabled: disabled,
|
95
|
-
onClick: this.
|
131
|
+
onClick: this.handlePrimaryAction,
|
96
132
|
type: type,
|
97
133
|
tabIndex: tabIndex,
|
98
134
|
className: cx(className),
|
@@ -107,7 +143,7 @@ class SplitButton extends Component {
|
|
107
143
|
secondary: secondary,
|
108
144
|
destructive: destructive,
|
109
145
|
disabled: disabled,
|
110
|
-
onClick: this.
|
146
|
+
onClick: this.handleToggle,
|
111
147
|
type: type,
|
112
148
|
tabIndex: tabIndex,
|
113
149
|
className: cx(className, rightButton.className),
|
@@ -115,7 +151,7 @@ class SplitButton extends Component {
|
|
115
151
|
title: i18n.t('Toggle dropdown'),
|
116
152
|
"aria-label": i18n.t('Toggle dropdown')
|
117
153
|
}, arrow), open && /*#__PURE__*/React.createElement(Layer, {
|
118
|
-
onBackdropClick: this.
|
154
|
+
onBackdropClick: this.handleBackdropClick,
|
119
155
|
transparent: true
|
120
156
|
}, /*#__PURE__*/React.createElement(Popper, {
|
121
157
|
dataTest: `${dataTest}-menu`,
|
@@ -148,6 +184,10 @@ SplitButton.propTypes = {
|
|
148
184
|
/** Changes button size. Mutually exclusive with `small` prop */
|
149
185
|
large: sharedPropTypes.sizePropType,
|
150
186
|
name: PropTypes.string,
|
187
|
+
/**
|
188
|
+
* Controls popper visibility. When implementing this prop the component becomes a controlled component
|
189
|
+
*/
|
190
|
+
open: PropTypes.bool,
|
151
191
|
/**
|
152
192
|
* Applies 'primary' button appearance, implying the most important action.
|
153
193
|
*/
|
@@ -163,6 +203,16 @@ SplitButton.propTypes = {
|
|
163
203
|
type: PropTypes.oneOf(['submit', 'reset', 'button']),
|
164
204
|
/** Value associated with the button. Passed in object to onClick handler */
|
165
205
|
value: PropTypes.string,
|
166
|
-
|
206
|
+
/**
|
207
|
+
* Callback triggered when the main button is clicked.
|
208
|
+
* Called with signature `({ name: string, value: string, open: bool }, event)`
|
209
|
+
*/
|
210
|
+
onClick: PropTypes.func,
|
211
|
+
/**
|
212
|
+
* Callback triggered when the dropdown is toggled (by clicking the chevron, pressing Escape, or clicking the backdrop).
|
213
|
+
* Called with signature `({ name: string, value: string, open: bool }, event)`.
|
214
|
+
* Required if `open` prop is used (controlled component).
|
215
|
+
*/
|
216
|
+
onToggle: requiredIf(props => typeof props.open === 'boolean', PropTypes.func)
|
167
217
|
};
|
168
218
|
export { SplitButton };
|
@@ -1,5 +1,10 @@
|
|
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); }
|
1
2
|
import { sharedPropTypes } from '@dhis2/ui-constants';
|
3
|
+
import { FlyoutMenu, MenuItem } from '@dhis2-ui/menu';
|
4
|
+
import { Modal, ModalContent, ModalTitle, ModalActions } from '@dhis2-ui/modal';
|
2
5
|
import React from 'react';
|
6
|
+
import { Button } from '../button/button.js';
|
7
|
+
import { ButtonStrip } from '../button-strip/button-strip.js';
|
3
8
|
import { SplitButton } from './split-button.js';
|
4
9
|
const description = `
|
5
10
|
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".
|
@@ -105,4 +110,45 @@ export const RTL = args => /*#__PURE__*/React.createElement("div", {
|
|
105
110
|
}, /*#__PURE__*/React.createElement(SplitButton, args));
|
106
111
|
RTL.args = {
|
107
112
|
children: 'RTL text'
|
113
|
+
};
|
114
|
+
export const ControlledOpen = args => {
|
115
|
+
const [openFlyout, setOpenFlyout] = React.useState(false);
|
116
|
+
const [openModal, setOpenModal] = React.useState(false);
|
117
|
+
const handleClick = () => {
|
118
|
+
console.log('Main button clicked. This will not open the flyout menu.');
|
119
|
+
};
|
120
|
+
const handleToggle = () => {
|
121
|
+
setOpenFlyout(prevState => !prevState);
|
122
|
+
};
|
123
|
+
const component = /*#__PURE__*/React.createElement(FlyoutMenu, null, /*#__PURE__*/React.createElement(MenuItem, {
|
124
|
+
onClick: () => {
|
125
|
+
console.log('Console log and close flyout');
|
126
|
+
setOpenFlyout(false);
|
127
|
+
},
|
128
|
+
label: "Action 1"
|
129
|
+
}), /*#__PURE__*/React.createElement(MenuItem, {
|
130
|
+
onClick: () => {
|
131
|
+
console.log('Open modal and close flyout');
|
132
|
+
setOpenFlyout(false);
|
133
|
+
setOpenModal(true);
|
134
|
+
},
|
135
|
+
label: "Open modal"
|
136
|
+
}));
|
137
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(SplitButton, _extends({}, args, {
|
138
|
+
open: openFlyout,
|
139
|
+
onClick: handleClick,
|
140
|
+
onToggle: handleToggle,
|
141
|
+
component: component
|
142
|
+
})), openModal && /*#__PURE__*/React.createElement(Modal, {
|
143
|
+
onClose: () => setOpenModal(false)
|
144
|
+
}, /*#__PURE__*/React.createElement(ModalTitle, null, "Modal"), /*#__PURE__*/React.createElement(ModalContent, null, /*#__PURE__*/React.createElement("p", null, "Modal content")), /*#__PURE__*/React.createElement(ModalActions, null, /*#__PURE__*/React.createElement(ButtonStrip, null, /*#__PURE__*/React.createElement(Button, {
|
145
|
+
onClick: () => setOpenModal(false)
|
146
|
+
}, "Close")))));
|
147
|
+
};
|
148
|
+
ControlledOpen.parameters = {
|
149
|
+
docs: {
|
150
|
+
description: {
|
151
|
+
story: 'This story demonstrates how the `SplitButton` can be controlled from the outside using the `open` prop and an `onToggle` handler that updates the external state.'
|
152
|
+
}
|
153
|
+
}
|
108
154
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dhis2-ui/button",
|
3
|
-
"version": "10.
|
3
|
+
"version": "10.7.1",
|
4
4
|
"description": "UI Button",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -33,11 +33,11 @@
|
|
33
33
|
},
|
34
34
|
"dependencies": {
|
35
35
|
"@dhis2/prop-types": "^3.1.2",
|
36
|
-
"@dhis2-ui/layer": "10.
|
37
|
-
"@dhis2-ui/loader": "10.
|
38
|
-
"@dhis2-ui/popper": "10.
|
39
|
-
"@dhis2/ui-constants": "10.
|
40
|
-
"@dhis2/ui-icons": "10.
|
36
|
+
"@dhis2-ui/layer": "10.7.1",
|
37
|
+
"@dhis2-ui/loader": "10.7.1",
|
38
|
+
"@dhis2-ui/popper": "10.7.1",
|
39
|
+
"@dhis2/ui-constants": "10.7.1",
|
40
|
+
"@dhis2/ui-icons": "10.7.1",
|
41
41
|
"classnames": "^2.3.1",
|
42
42
|
"prop-types": "^15.7.2"
|
43
43
|
},
|
package/types/index.d.ts
CHANGED
@@ -212,6 +212,10 @@ export interface SplitButtonProps {
|
|
212
212
|
*/
|
213
213
|
large?: boolean
|
214
214
|
name?: string
|
215
|
+
/**
|
216
|
+
* Controls popper visibility. When implementing this prop the component becomes a controlled component
|
217
|
+
*/
|
218
|
+
open?: boolean
|
215
219
|
/** Applies 'primary' button appearance, implying the most important action */
|
216
220
|
primary?: boolean
|
217
221
|
/** Applies 'secondary' button appearance */
|
@@ -229,7 +233,17 @@ export interface SplitButtonProps {
|
|
229
233
|
* Value associated with the button. Passed in object to onClick handler
|
230
234
|
*/
|
231
235
|
value?: string
|
232
|
-
|
236
|
+
/**
|
237
|
+
* Callback triggered when the main button is clicked.
|
238
|
+
* Called with signature `({ name: string, value: string, open: bool }, event)`
|
239
|
+
*/
|
240
|
+
onClick?: ButtonEventHandler<React.MouseEvent<HTMLButtonElement>>
|
241
|
+
/**
|
242
|
+
* Callback triggered when the dropdown is toggled (by clicking the chevron, pressing Escape, or clicking the backdrop).
|
243
|
+
* Called with signature `({ name: string, value: string, open: bool }, event)`.
|
244
|
+
* Required if `open` prop is used (controlled component).
|
245
|
+
*/
|
246
|
+
onToggle?: ButtonOpenEventHandler
|
233
247
|
}
|
234
248
|
|
235
249
|
export class SplitButton extends React.Component<SplitButtonProps, any> {
|