@dhis2-ui/button 9.10.3 → 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
@@ -4,29 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
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;
|
7
|
-
|
8
7
|
var _uiConstants = require("@dhis2/ui-constants");
|
9
|
-
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
11
|
-
|
12
9
|
var _splitButton = require("./split-button.js");
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
11
|
+
const description = `
|
12
|
+
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
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
\`\`\`js
|
15
|
+
import { SplitButton } from '@dhis2/ui'
|
16
|
+
\`\`\`
|
17
|
+
`;
|
18
18
|
window.onClick = (payload, event) => {
|
19
19
|
console.log('onClick payload', payload);
|
20
20
|
console.log('onClick event', event);
|
21
21
|
};
|
22
|
-
|
23
22
|
const onClick = function () {
|
24
23
|
return window.onClick(...arguments);
|
25
24
|
};
|
26
|
-
|
27
25
|
const DropdownComponent = /*#__PURE__*/_react.default.createElement("span", null, "Dropdown component");
|
28
|
-
|
29
|
-
var _default = {
|
26
|
+
var _default = exports.default = {
|
30
27
|
title: 'Split Button',
|
31
28
|
component: _splitButton.SplitButton,
|
32
29
|
parameters: {
|
@@ -44,84 +41,75 @@ var _default = {
|
|
44
41
|
children: 'Label me!'
|
45
42
|
},
|
46
43
|
argTypes: {
|
47
|
-
small: {
|
44
|
+
small: {
|
45
|
+
..._uiConstants.sharedPropTypes.sizeArgType
|
48
46
|
},
|
49
|
-
large: {
|
47
|
+
large: {
|
48
|
+
..._uiConstants.sharedPropTypes.sizeArgType
|
50
49
|
},
|
51
|
-
primary: {
|
50
|
+
primary: {
|
51
|
+
..._uiConstants.sharedPropTypes.buttonVariantArgType
|
52
52
|
},
|
53
|
-
secondary: {
|
53
|
+
secondary: {
|
54
|
+
..._uiConstants.sharedPropTypes.buttonVariantArgType
|
54
55
|
},
|
55
|
-
destructive: {
|
56
|
+
destructive: {
|
57
|
+
..._uiConstants.sharedPropTypes.buttonVariantArgType
|
56
58
|
}
|
57
59
|
}
|
58
60
|
};
|
59
|
-
exports.default = _default;
|
60
|
-
|
61
61
|
const Template = args => /*#__PURE__*/_react.default.createElement(_splitButton.SplitButton, args);
|
62
|
-
|
63
|
-
const
|
64
|
-
exports.Default = Default;
|
65
|
-
const Primary = Template.bind({});
|
66
|
-
exports.Primary = Primary;
|
62
|
+
const Default = exports.Default = Template.bind({});
|
63
|
+
const Primary = exports.Primary = Template.bind({});
|
67
64
|
Primary.args = {
|
68
65
|
primary: true
|
69
66
|
};
|
70
67
|
Primary.parameters = {
|
71
68
|
docs: {
|
72
69
|
description: {
|
73
|
-
story:
|
70
|
+
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._`
|
74
71
|
}
|
75
72
|
}
|
76
73
|
};
|
77
|
-
const Secondary = Template.bind({});
|
78
|
-
exports.Secondary = Secondary;
|
74
|
+
const Secondary = exports.Secondary = Template.bind({});
|
79
75
|
Secondary.args = {
|
80
76
|
secondary: true
|
81
77
|
};
|
82
|
-
const Destructive = Template.bind({});
|
83
|
-
exports.Destructive = Destructive;
|
78
|
+
const Destructive = exports.Destructive = Template.bind({});
|
84
79
|
Destructive.props = {
|
85
80
|
destructive: true
|
86
81
|
};
|
87
|
-
const Disabled = Template.bind({});
|
88
|
-
exports.Disabled = Disabled;
|
82
|
+
const Disabled = exports.Disabled = Template.bind({});
|
89
83
|
Disabled.args = {
|
90
84
|
disabled: true
|
91
85
|
};
|
92
|
-
const Small = Template.bind({});
|
93
|
-
exports.Small = Small;
|
86
|
+
const Small = exports.Small = Template.bind({});
|
94
87
|
Small.args = {
|
95
88
|
small: true
|
96
89
|
};
|
97
|
-
const Large = Template.bind({});
|
98
|
-
exports.Large = Large;
|
90
|
+
const Large = exports.Large = Template.bind({});
|
99
91
|
Large.args = {
|
100
92
|
large: true
|
101
93
|
};
|
102
|
-
const InitialFocus = Template.bind({});
|
103
|
-
exports.InitialFocus = InitialFocus;
|
94
|
+
const InitialFocus = exports.InitialFocus = Template.bind({});
|
104
95
|
InitialFocus.args = {
|
105
96
|
initialFocus: true
|
106
|
-
};
|
107
|
-
|
97
|
+
};
|
98
|
+
// Disable this on docs page because grabbing focus repeatedly is annoying
|
108
99
|
InitialFocus.parameters = {
|
109
100
|
docs: {
|
110
101
|
disable: true
|
111
102
|
}
|
112
103
|
};
|
113
|
-
const WithIcon = Template.bind({});
|
114
|
-
exports.WithIcon = WithIcon;
|
104
|
+
const WithIcon = exports.WithIcon = Template.bind({});
|
115
105
|
WithIcon.args = {
|
116
106
|
children: 'Children',
|
117
107
|
component: /*#__PURE__*/_react.default.createElement("div", null, "Component"),
|
118
108
|
icon: /*#__PURE__*/_react.default.createElement("div", null, "Icon")
|
119
109
|
};
|
120
|
-
|
121
110
|
const RTL = args => /*#__PURE__*/_react.default.createElement("div", {
|
122
111
|
dir: "rtl"
|
123
112
|
}, /*#__PURE__*/_react.default.createElement(_splitButton.SplitButton, args));
|
124
|
-
|
125
113
|
exports.RTL = RTL;
|
126
114
|
RTL.args = {
|
127
115
|
children: 'RTL text'
|
@@ -1,15 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _react = require("@testing-library/react");
|
4
|
-
|
5
4
|
var _react2 = _interopRequireDefault(require("react"));
|
6
|
-
|
7
5
|
require("@testing-library/jest-dom/extend-expect");
|
8
|
-
|
9
6
|
var _splitButton = require("./split-button.js");
|
10
|
-
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12
|
-
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
13
8
|
describe('SplitButton', () => {
|
14
9
|
afterEach(_react.cleanup);
|
15
10
|
it('renders button with children', () => {
|
@@ -24,13 +19,9 @@ describe('SplitButton', () => {
|
|
24
19
|
queryByTestId
|
25
20
|
} = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_splitButton.SplitButton, null));
|
26
21
|
const toggleButton = getByTestId('dhis2-uicore-splitbutton-toggle');
|
27
|
-
|
28
22
|
_react.fireEvent.click(toggleButton);
|
29
|
-
|
30
23
|
expect(queryByTestId('dhis2-uicore-splitbutton-menu')).toBeInTheDocument();
|
31
|
-
|
32
24
|
_react.fireEvent.click(toggleButton);
|
33
|
-
|
34
25
|
expect(queryByTestId('dhis2-uicore-splitbutton-menu')).not.toBeInTheDocument();
|
35
26
|
});
|
36
27
|
it('renders dropdown content when open is true', () => {
|
@@ -40,9 +31,7 @@ describe('SplitButton', () => {
|
|
40
31
|
component: /*#__PURE__*/_react2.default.createElement("div", null, "Dropdown Content")
|
41
32
|
}));
|
42
33
|
const toggleButton = getByTestId('dhis2-uicore-splitbutton-toggle');
|
43
|
-
|
44
34
|
_react.fireEvent.click(toggleButton);
|
45
|
-
|
46
35
|
expect(getByTestId('dhis2-uicore-splitbutton-menu')).toBeInTheDocument();
|
47
36
|
});
|
48
37
|
it("does not close dropdown 'Enter' key is pressed", async () => {
|
@@ -52,16 +41,13 @@ describe('SplitButton', () => {
|
|
52
41
|
component: /*#__PURE__*/_react2.default.createElement("div", null, "Dropdown Content")
|
53
42
|
}));
|
54
43
|
const toggleButton = getByTestId('dhis2-uicore-splitbutton-toggle');
|
55
|
-
|
56
44
|
_react.fireEvent.click(toggleButton);
|
57
|
-
|
58
45
|
expect(getByTestId('dhis2-uicore-splitbutton-menu')).toBeInTheDocument();
|
59
|
-
|
60
46
|
_react.fireEvent.keyDown(document, {
|
61
47
|
key: 'Enter'
|
62
|
-
});
|
63
|
-
|
48
|
+
});
|
64
49
|
|
50
|
+
// Use waitFor to wait for the DOM to update
|
65
51
|
await (0, _react.waitFor)(() => {
|
66
52
|
expect(getByTestId('dhis2-uicore-splitbutton-menu')).toBeInTheDocument();
|
67
53
|
});
|
@@ -74,16 +60,13 @@ describe('SplitButton', () => {
|
|
74
60
|
component: /*#__PURE__*/_react2.default.createElement("div", null, "Dropdown Content")
|
75
61
|
}));
|
76
62
|
const toggleButton = getByTestId('dhis2-uicore-splitbutton-toggle');
|
77
|
-
|
78
63
|
_react.fireEvent.click(toggleButton);
|
79
|
-
|
80
64
|
expect(getByTestId('dhis2-uicore-splitbutton-menu')).toBeInTheDocument();
|
81
|
-
|
82
65
|
_react.fireEvent.keyDown(document, {
|
83
66
|
key: 'Escape'
|
84
|
-
});
|
85
|
-
|
67
|
+
});
|
86
68
|
|
69
|
+
// Use waitFor to wait for the DOM to update
|
87
70
|
await (0, _react.waitFor)(() => {
|
88
71
|
expect(queryByTestId('dhis2-uicore-splitbutton-menu')).not.toBeInTheDocument();
|
89
72
|
});
|
@@ -1,20 +1,24 @@
|
|
1
|
-
import { storiesOf } from '@storybook/react';
|
2
1
|
import React from 'react';
|
3
2
|
import { Button } from './button.js';
|
4
3
|
window.onClick = window.Cypress && window.Cypress.cy.stub();
|
5
4
|
window.onBlur = window.Cypress && window.Cypress.cy.stub();
|
6
5
|
window.onFocus = window.Cypress && window.Cypress.cy.stub();
|
7
|
-
|
6
|
+
export default {
|
7
|
+
title: 'Button'
|
8
|
+
};
|
9
|
+
export const WithOnClick = () => /*#__PURE__*/React.createElement(Button, {
|
8
10
|
name: "Button",
|
9
11
|
value: "default",
|
10
12
|
onClick: window.onClick
|
11
|
-
}, "Label me!")
|
13
|
+
}, "Label me!");
|
14
|
+
export const WithInitialFocusAndOnBlur = () => /*#__PURE__*/React.createElement(Button, {
|
12
15
|
name: "Button",
|
13
16
|
value: "default",
|
14
17
|
initialFocus: true,
|
15
18
|
onBlur: window.onBlur
|
16
|
-
}, "Label me!")
|
19
|
+
}, "Label me!");
|
20
|
+
export const WithOnFocus = () => /*#__PURE__*/React.createElement(Button, {
|
17
21
|
name: "Button",
|
18
22
|
value: "default",
|
19
23
|
onFocus: window.onFocus
|
20
|
-
}, "Label me!")
|
24
|
+
}, "Label me!");
|
@@ -1,9 +1,7 @@
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
2
|
-
|
3
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
4
|
-
|
5
|
-
import { CircularLoader } from '@dhis2-ui/loader';
|
2
|
+
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); }
|
6
3
|
import { sharedPropTypes } from '@dhis2/ui-constants';
|
4
|
+
import { CircularLoader } from '@dhis2-ui/loader';
|
7
5
|
import cx from 'classnames';
|
8
6
|
import PropTypes from 'prop-types';
|
9
7
|
import React, { useEffect, useRef } from 'react';
|
@@ -43,31 +41,25 @@ export const Button = _ref => {
|
|
43
41
|
'aria-label': ariaLabel,
|
44
42
|
title
|
45
43
|
} = otherProps;
|
46
|
-
|
47
44
|
if (!children && !title && !ariaLabel) {
|
48
45
|
console.debug('Button component has no children but is missing title and ariaLabel attribute.');
|
49
46
|
}
|
50
|
-
|
51
47
|
const handleClick = event => onClick && onClick({
|
52
48
|
value,
|
53
49
|
name
|
54
50
|
}, event);
|
55
|
-
|
56
51
|
const handleBlur = event => onBlur && onBlur({
|
57
52
|
value,
|
58
53
|
name
|
59
54
|
}, event);
|
60
|
-
|
61
55
|
const handleFocus = event => onFocus && onFocus({
|
62
56
|
value,
|
63
57
|
name
|
64
58
|
}, event);
|
65
|
-
|
66
59
|
const handleKeyDown = event => onKeyDown && onKeyDown({
|
67
60
|
value,
|
68
61
|
name
|
69
62
|
}, event);
|
70
|
-
|
71
63
|
const iconOnly = icon && !children;
|
72
64
|
const buttonClassName = cx(className, {
|
73
65
|
primary,
|
@@ -91,16 +83,16 @@ export const Button = _ref => {
|
|
91
83
|
onFocus: handleFocus,
|
92
84
|
onKeyDown: handleKeyDown
|
93
85
|
}, otherProps, {
|
94
|
-
className:
|
86
|
+
className: `jsx-${styles.__hash}` + " " + (otherProps && otherProps.className != null && otherProps.className || buttonClassName || "")
|
95
87
|
}), loading && /*#__PURE__*/React.createElement("span", {
|
96
|
-
className:
|
88
|
+
className: `jsx-${styles.__hash}` + " " + "loader"
|
97
89
|
}, destructive || primary ? /*#__PURE__*/React.createElement(CircularLoader, {
|
98
90
|
extrasmall: true,
|
99
91
|
invert: true
|
100
92
|
}) : /*#__PURE__*/React.createElement(CircularLoader, {
|
101
93
|
extrasmall: true
|
102
94
|
})), icon && /*#__PURE__*/React.createElement("span", {
|
103
|
-
className:
|
95
|
+
className: `jsx-${styles.__hash}` + " " + "button-icon"
|
104
96
|
}, icon), children, /*#__PURE__*/React.createElement(_JSXStyle, {
|
105
97
|
id: styles.__hash
|
106
98
|
}, styles));
|
@@ -112,85 +104,65 @@ Button.defaultProps = {
|
|
112
104
|
Button.propTypes = {
|
113
105
|
/** Component to render inside the button */
|
114
106
|
children: PropTypes.node,
|
115
|
-
|
116
107
|
/** A className that will be passed to the `<button>` element */
|
117
108
|
className: PropTypes.string,
|
118
|
-
|
119
109
|
/**
|
120
110
|
* A string that will be applied as a `data-test` attribute on the button element
|
121
111
|
* for identification during testing
|
122
112
|
*/
|
123
113
|
dataTest: PropTypes.string,
|
124
|
-
|
125
114
|
/**
|
126
115
|
* Applies 'destructive' button appearance, implying a dangerous action.
|
127
116
|
*/
|
128
117
|
destructive: PropTypes.bool,
|
129
|
-
|
130
118
|
/** Applies a greyed-out appearance and makes the button non-interactive */
|
131
119
|
disabled: PropTypes.bool,
|
132
|
-
|
133
120
|
/** An icon element to display inside the button */
|
134
121
|
icon: PropTypes.element,
|
135
|
-
|
136
122
|
/** Use this variant to capture the initial focus on the page. */
|
137
123
|
initialFocus: PropTypes.bool,
|
138
|
-
|
139
124
|
/** Makes the button large. Mutually exclusive with `small` */
|
140
125
|
large: sharedPropTypes.sizePropType,
|
141
|
-
|
142
126
|
/** Sets the button into a loading state */
|
143
127
|
loading: PropTypes.bool,
|
144
|
-
|
145
128
|
/**
|
146
129
|
* Sets `name` attribute on button element.
|
147
130
|
* Gets passed as part of the first argument to callbacks (see `onClick`).
|
148
131
|
*/
|
149
132
|
name: PropTypes.string,
|
150
|
-
|
151
133
|
/**
|
152
134
|
* Applies 'primary' button appearance, implying the most important action.
|
153
135
|
*/
|
154
136
|
primary: PropTypes.bool,
|
155
|
-
|
156
137
|
/**
|
157
138
|
* Applies 'secondary' button appearance.
|
158
139
|
*/
|
159
140
|
secondary: PropTypes.bool,
|
160
|
-
|
161
141
|
/** Makes the button small. Mutually exclusive with `large` prop */
|
162
142
|
small: sharedPropTypes.sizePropType,
|
163
|
-
|
164
143
|
/** Tab index for focusing the button with a keyboard */
|
165
144
|
tabIndex: PropTypes.string,
|
166
|
-
|
167
145
|
/** Changes appearance of button to an on/off state */
|
168
146
|
toggled: PropTypes.bool,
|
169
|
-
|
170
147
|
/** Sets `type` attribute on `<button>` element */
|
171
148
|
type: PropTypes.oneOf(['submit', 'reset', 'button']),
|
172
|
-
|
173
149
|
/**
|
174
150
|
* Value associated with the button.
|
175
151
|
* Gets passed as part of the first argument to callbacks (see `onClick`).
|
176
152
|
*/
|
177
153
|
value: PropTypes.string,
|
178
|
-
|
179
154
|
/**
|
180
155
|
* Callback to trigger on de-focus (blur).
|
181
156
|
* Called with same args as `onClick`
|
182
157
|
* */
|
183
158
|
onBlur: PropTypes.func,
|
184
|
-
|
185
159
|
/**
|
186
160
|
* Callback to trigger on click.
|
187
161
|
* Called with args `({ value, name }, event)`
|
188
162
|
* */
|
189
163
|
onClick: PropTypes.func,
|
190
|
-
|
191
164
|
/** Callback to trigger on focus. Called with same args as `onClick` */
|
192
165
|
onFocus: PropTypes.func,
|
193
|
-
|
194
166
|
/** Callback to trigger on key-down. Called with same args as `onClick` */
|
195
167
|
onKeyDown: PropTypes.func
|
196
168
|
};
|
@@ -1,23 +1,27 @@
|
|
1
|
-
function _extends() { _extends = Object.assign
|
2
|
-
|
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); }
|
3
2
|
import { sharedPropTypes } from '@dhis2/ui-constants';
|
4
3
|
import React from 'react';
|
5
|
-
import { Button } from './button.js';
|
4
|
+
import { Button } from './button.js';
|
5
|
+
|
6
|
+
// Note: make sure 'fenced code blocks' are not indentend in this template string
|
7
|
+
const description = `Buttons are used for triggering actions.
|
8
|
+
There are different types of buttons in the design system which are intended
|
9
|
+
for different types of actions.
|
6
10
|
|
7
|
-
|
11
|
+
\`\`\`js
|
12
|
+
import { Button } from '@dhis2/ui'
|
13
|
+
\`\`\``;
|
8
14
|
const {
|
9
15
|
buttonVariantArgType,
|
10
16
|
sizeArgType
|
11
17
|
} = sharedPropTypes;
|
12
|
-
|
13
18
|
const logger = _ref => {
|
14
19
|
let {
|
15
20
|
name,
|
16
21
|
value
|
17
22
|
} = _ref;
|
18
|
-
return console.log(
|
23
|
+
return console.log(`${name}: ${value}`);
|
19
24
|
};
|
20
|
-
|
21
25
|
export default {
|
22
26
|
title: 'Button',
|
23
27
|
component: Button,
|
@@ -37,15 +41,20 @@ export default {
|
|
37
41
|
ariaLabel: 'Button'
|
38
42
|
},
|
39
43
|
argTypes: {
|
40
|
-
primary: {
|
44
|
+
primary: {
|
45
|
+
...buttonVariantArgType
|
41
46
|
},
|
42
|
-
secondary: {
|
47
|
+
secondary: {
|
48
|
+
...buttonVariantArgType
|
43
49
|
},
|
44
|
-
destructive: {
|
50
|
+
destructive: {
|
51
|
+
...buttonVariantArgType
|
45
52
|
},
|
46
|
-
small: {
|
53
|
+
small: {
|
54
|
+
...sizeArgType
|
47
55
|
},
|
48
|
-
large: {
|
56
|
+
large: {
|
57
|
+
...sizeArgType
|
49
58
|
}
|
50
59
|
}
|
51
60
|
};
|
@@ -67,9 +76,7 @@ const DemoIcon16 = /*#__PURE__*/React.createElement("svg", {
|
|
67
76
|
d: "m6.85355339 9.14644661c.17356635.17356635.1928515.44299075.05785545.63785889l-.05785545.06924789-4.14755339 4.14644661h2.794c.24545989 0 .44960837.1768752.49194433.4101244l.00805567.0898756c0 .2454599-.17687516.4496084-.41012437.4919443l-.08987563.0080557h-4c-.24545989 0-.44960837-.1768752-.49194433-.4101244l-.00805567-.0898756v-4c0-.2761424.22385763-.5.5-.5.24545989 0 .44960837.1768752.49194433.4101244l.00805567.0898756v2.792l4.14644661-4.14555339c.19526215-.19526215.51184463-.19526215.70710678 0zm6.14644661-2.14644661v6h-6v-1h5v-5zm-4-4v1h-5v5h-1v-6zm5.5-2c.2454599 0 .4496084.17687516.4919443.41012437l.0080557.08987563v4c0 .27614237-.2238576.5-.5.5-.2454599 0-.4496084-.17687516-.4919443-.41012437l-.0080557-.08987563v-2.794l-4.14644661 4.14755339c-.19526215.19526215-.51184463.19526215-.70710678 0-.17356635-.17356635-.1928515-.44299075-.05785545-.63785889l.05785545-.06924789 4.14655339-4.14744661-2.793.001c-.2454599 0-.4496084-.17687516-.4919443-.41012437l-.0080557-.08987563c0-.24545989.1768752-.44960837.4101244-.49194433l.0898756-.00805567z",
|
68
77
|
fill: "inherit"
|
69
78
|
}));
|
70
|
-
|
71
79
|
const Template = args => /*#__PURE__*/React.createElement(Button, args);
|
72
|
-
|
73
80
|
export const Basic = Template.bind({});
|
74
81
|
Basic.args = {
|
75
82
|
name: 'Basic button'
|
@@ -182,9 +189,9 @@ export const InitialFocus = Template.bind({});
|
|
182
189
|
InitialFocus.args = {
|
183
190
|
initialFocus: true,
|
184
191
|
name: 'Focused button'
|
185
|
-
};
|
192
|
+
};
|
193
|
+
// When enabled, this story grabs focus every time a control is changed
|
186
194
|
// in the docs page. Disabled for better UX
|
187
|
-
|
188
195
|
InitialFocus.parameters = {
|
189
196
|
docs: {
|
190
197
|
disable: true
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { colors, theme, spacers } from '@dhis2/ui-constants';
|
2
|
-
const _defaultExport = [
|
2
|
+
const _defaultExport = [`button.jsx-1796590446{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;position:relative;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;border-radius:4px;font-weight:400;-webkit-letter-spacing:0.5px;-moz-letter-spacing:0.5px;-ms-letter-spacing:0.5px;letter-spacing:0.5px;-webkit-text-decoration:none;text-decoration:none;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:${colors.grey900};height:36px;padding:0 ${spacers.dp12};font-size:14px;line-height:16px;border:1px solid ${colors.grey500};background-color:#f9fafb;}`, "button.jsx-1796590446:disabled{cursor:not-allowed;}", `button.jsx-1796590446:focus{outline:3px solid ${theme.focus};outline-offset:-3px;-webkit-text-decoration:underline;text-decoration:underline;}`, "button.jsx-1796590446:focus.jsx-1796590446:not(:focus-visible){outline:none;-webkit-text-decoration:none;text-decoration:none;}", "button.jsx-1796590446:active.jsx-1796590446:focus,button.jsx-1796590446:disabled.jsx-1796590446:focus{outline:none;-webkit-text-decoration:none;text-decoration:none;}", `button.jsx-1796590446:hover{border-color:${colors.grey500};background-color:${colors.grey200};}`, `button.jsx-1796590446:active,button.jsx-1796590446:active.jsx-1796590446:focus{border-color:${colors.grey500};background-color:${colors.grey200};box-shadow:0 0 0 1px rgb(0,0,0,0.1) inset;}`, "button.jsx-1796590446:focus{background-color:#f9fafb;}", `button.jsx-1796590446:disabled{border-color:${colors.grey400};background-color:#f9fafb;box-shadow:none;color:${theme.disabled};fill:${theme.disabled};}`, ".small.jsx-1796590446{height:28px;padding:0 6px;font-size:14px;line-height:16px;}", `.large.jsx-1796590446{height:43px;padding:0 ${spacers.dp24};font-size:16px;-webkit-letter-spacing:0.57px;-moz-letter-spacing:0.57px;-ms-letter-spacing:0.57px;letter-spacing:0.57px;line-height:19px;}`, `.primary.jsx-1796590446{border-color:${theme.primary800};background:linear-gradient(180deg,#1565c0 0%,#0650a3 100%);background-color:#2b61b3;color:${colors.white};fill:${colors.white};font-weight:500;}`, `.primary.jsx-1796590446:hover{border-color:${theme.primary800};background:linear-gradient(180deg,#054fa3 0%,#034793 100%);background-color:#21539f;}`, ".primary.jsx-1796590446:active,.primary.jsx-1796590446:active.jsx-1796590446:focus{background:linear-gradient(180deg,#054fa3 0%,#034793 100%);background-color:#1c4a90;box-shadow:0 0 0 1px rgba(0,0,0,0.18) inset;}", `.primary.jsx-1796590446:focus{background:${colors.blue800};border-color:${colors.blue900};outline-offset:-5px;}`, `.primary.jsx-1796590446:disabled{border-color:#93a6bd;background:#b3c6de;box-shadow:none;color:${colors.white};fill:${colors.white};}`, ".secondary.jsx-1796590446{border-color:rgba(74,87,104,0.25);background-color:transparent;}", ".secondary.jsx-1796590446:hover{border-color:rgba(74,87,104,0.5);background-color:rgba(160,173,186,0.05);}", ".secondary.jsx-1796590446:active,.secondary.jsx-1796590446:active.jsx-1796590446:focus{background-color:rgba(160,173,186,0.2);box-shadow:none;}", ".secondary.jsx-1796590446:focus{background-color:transparent;}", `.secondary.jsx-1796590446:disabled{border-color:rgba(74,87,104,0.25);background-color:transparent;box-shadow:none;color:${theme.disabled};fill:${theme.disabled};}`, `.destructive.jsx-1796590446{border-color:#a10b0b;background:linear-gradient(180deg,#d32f2f 0%,#b71c1c 100%);background-color:#b9242b;color:${colors.white};fill:${colors.white};font-weight:500;}`, ".destructive.jsx-1796590446:hover{border-color:#a10b0b;background:linear-gradient(180deg,#b81c1c 0%,#b80c0b 100%);background-color:#ac0f1a;}", ".destructive.jsx-1796590446:active,.destructive.jsx-1796590446:active.jsx-1796590446:focus{background:linear-gradient(180deg,#b81c1c 0%,#b80c0b 100%);background-color:#ac101b;box-shadow:0 0 0 1px rgba(0,0,0,0.18) inset;}", ".destructive.jsx-1796590446:focus{background:linear-gradient(180deg,#d32f2f 0%,#b71c1c 100%);background-color:#b72229;}", `.destructive.jsx-1796590446:disabled{border-color:#c59898;background:#d6a8a8;box-shadow:none;color:${colors.white};fill:${colors.white};}`, `.destructive.secondary.jsx-1796590446{border-color:rgba(74,87,104,0.25);background:transparent;color:${colors.red700};fill:${colors.red700};font-weight:400;}`, `.destructive.secondary.jsx-1796590446:hover{border-color:${colors.red600};background:${colors.red050};color:${colors.red800};fill:${colors.red800};}`, `.destructive.secondary.jsx-1796590446:active,.destructive.secondary.jsx-1796590446:active.jsx-1796590446:focus{background:${colors.red100};border-color:${colors.red700};box-shadow:none;}`, ".destructive.secondary.jsx-1796590446:disabled{background:transparent;border-color:rgba(74,87,104,0.25);color:rgba(183,28,28,0.6);fill:rgba(183,28,28,0.6);}", ".icon-only.jsx-1796590446{padding:0 0 0 5px;}", ".button-icon.jsx-1796590446{margin-inline-end:6px;color:inherit;fill:inherit;font-size:26px;vertical-align:middle;pointer-events:none;}", ".icon-only.jsx-1796590446 .button-icon.jsx-1796590446{margin-inline-end:5px;}", ".small.icon-only.jsx-1796590446{padding-block:0;padding-inline-start:5px;padding-inline-end:4px;}", ".small.jsx-1796590446 .button-icon.jsx-1796590446{margin-inline-end:2px;}", ".small.icon-only.jsx-1796590446 .button-icon.jsx-1796590446{margin-inline-end:1px;}", `.toggled.jsx-1796590446{background:${colors.grey700};border:1px solid ${colors.grey900};color:${colors.grey050};fill:${colors.grey050};}`, `.toggled.jsx-1796590446:focus{background:${colors.grey800};}`, `.toggled.jsx-1796590446:hover{background:${colors.grey800};border-color:${colors.grey900};}`, `.toggled.jsx-1796590446:active,.toggled.jsx-1796590446:active.jsx-1796590446:focus{background:${colors.grey900};border-color:${colors.grey900};}`, `.toggled.jsx-1796590446:disabled{background:${colors.grey500};border-color:${colors.grey600};color:${colors.grey050};fill:${colors.grey050};}`, ".loader.jsx-1796590446{width:16px;height:16px;margin-inline-end:8px;}", ".loader.jsx-1796590446+.button-icon.jsx-1796590446{display:none;}", ".icon-only.jsx-1796590446 .loader.jsx-1796590446{margin:0 8px 0 4px;margin-inline-start:4px;margin-inline-end:8px;}", ".small.icon-only.jsx-1796590446 .loader.jsx-1796590446{margin:0 4px;}"];
|
3
3
|
_defaultExport.__hash = "1796590446";
|
4
4
|
export default _defaultExport;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
|
2
2
|
Given('an Button with initialFocus and onBlur handler is rendered', () => {
|
3
|
-
cy.visitStory('Button', 'With
|
3
|
+
cy.visitStory('Button', 'With initial focus and on blur');
|
4
4
|
cy.focused().should('exist');
|
5
5
|
});
|
6
6
|
When('the Button is blurred', () => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
|
2
2
|
Given('a Button with onClick handler is rendered', () => {
|
3
|
-
cy.visitStory('Button', 'With
|
3
|
+
cy.visitStory('Button', 'With on click');
|
4
4
|
});
|
5
5
|
When('the Button is clicked', () => {
|
6
6
|
cy.get('[data-test="dhis2-uicore-button"]').click();
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
|
2
2
|
Given('a Button with onFocus handler is rendered', () => {
|
3
|
-
cy.visitStory('Button', 'With
|
3
|
+
cy.visitStory('Button', 'With on focus');
|
4
4
|
});
|
5
5
|
When('the Button is focused', () => {
|
6
6
|
cy.get('[data-test="dhis2-uicore-button"]').focus();
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { Button } from '../index.js';
|
3
|
+
import { ButtonStrip } from './index.js';
|
4
|
+
export default {
|
5
|
+
title: 'ButtonStrip'
|
6
|
+
};
|
7
|
+
export const WithChildren = () => /*#__PURE__*/React.createElement(ButtonStrip, null, /*#__PURE__*/React.createElement(Button, null, "I am a child"), /*#__PURE__*/React.createElement(Button, null, "I am a child"), /*#__PURE__*/React.createElement(Button, null, "I am a child"));
|
@@ -4,7 +4,6 @@ import { spacers } from '@dhis2/ui-constants';
|
|
4
4
|
import cx from 'classnames';
|
5
5
|
import PropTypes from 'prop-types';
|
6
6
|
import React, { Children } from 'react';
|
7
|
-
|
8
7
|
const ButtonStrip = _ref => {
|
9
8
|
let {
|
10
9
|
className,
|
@@ -25,9 +24,8 @@ const ButtonStrip = _ref => {
|
|
25
24
|
}, child)), /*#__PURE__*/React.createElement(_JSXStyle, {
|
26
25
|
id: "3148822533",
|
27
26
|
dynamic: [spacers.dp8]
|
28
|
-
}, ["div.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", "div.middle.__jsx-style-dynamic-selector{-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}", "div.end.__jsx-style-dynamic-selector{-webkit-box-pack:end;-webkit-justify-content:flex-end;-ms-flex-pack:end;justify-content:flex-end;}",
|
27
|
+
}, ["div.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", "div.middle.__jsx-style-dynamic-selector{-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}", "div.end.__jsx-style-dynamic-selector{-webkit-box-pack:end;-webkit-justify-content:flex-end;-ms-flex-pack:end;justify-content:flex-end;}", `.box.__jsx-style-dynamic-selector{margin-inline-start:${spacers.dp8};}`, ".box.__jsx-style-dynamic-selector:first-child{margin-inline-start:0;}"]));
|
29
28
|
};
|
30
|
-
|
31
29
|
const alignmentPropType = mutuallyExclusive(['middle', 'end'], PropTypes.bool);
|
32
30
|
ButtonStrip.defaultProps = {
|
33
31
|
dataTest: 'dhis2-uicore-buttonstrip'
|
@@ -36,10 +34,8 @@ ButtonStrip.propTypes = {
|
|
36
34
|
children: PropTypes.node,
|
37
35
|
className: PropTypes.string,
|
38
36
|
dataTest: PropTypes.string,
|
39
|
-
|
40
37
|
/** Horizontal alignment for buttons. Mutually exclusive with `middle` prop */
|
41
38
|
end: alignmentPropType,
|
42
|
-
|
43
39
|
/** Horizontal alignment. Mutually exclusive with `end` prop */
|
44
40
|
middle: alignmentPropType
|
45
41
|
};
|
@@ -1,8 +1,13 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { Button, SplitButton } from '../index.js';
|
3
3
|
import { ButtonStrip } from './index.js';
|
4
|
-
const description =
|
4
|
+
const description = `
|
5
|
+
A wrapper for buttons to add spacing and alignment.
|
5
6
|
|
7
|
+
\`\`\`js
|
8
|
+
import { ButtonStrip } from '@dhis2/ui'
|
9
|
+
\`\`\`
|
10
|
+
`;
|
6
11
|
const Wrapper = fn => /*#__PURE__*/React.createElement("div", {
|
7
12
|
style: {
|
8
13
|
width: '100%',
|
@@ -10,7 +15,6 @@ const Wrapper = fn => /*#__PURE__*/React.createElement("div", {
|
|
10
15
|
padding: 8
|
11
16
|
}
|
12
17
|
}, fn());
|
13
|
-
|
14
18
|
const alignmentArgType = {
|
15
19
|
table: {
|
16
20
|
type: {
|
@@ -34,9 +38,11 @@ export default {
|
|
34
38
|
}
|
35
39
|
},
|
36
40
|
argTypes: {
|
37
|
-
middle: {
|
41
|
+
middle: {
|
42
|
+
...alignmentArgType
|
38
43
|
},
|
39
|
-
end: {
|
44
|
+
end: {
|
45
|
+
...alignmentArgType
|
40
46
|
}
|
41
47
|
}
|
42
48
|
};
|