@dhis2-ui/switch 9.11.0 → 9.11.1-beta.2
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/index.js +0 -2
- package/build/cjs/switch/__tests__/switch.test.js +1 -7
- package/build/cjs/switch/features/accepts_initial_focus/index.js +1 -2
- package/build/cjs/switch/features/accepts_label/index.js +0 -1
- package/build/cjs/switch/features/can_be_blurred/index.js +1 -2
- package/build/cjs/switch/features/can_be_changed/index.js +1 -2
- package/build/cjs/switch/features/can_be_disabled/index.js +0 -1
- package/build/cjs/switch/features/can_be_focused/index.js +1 -2
- package/build/cjs/switch/index.js +0 -1
- package/build/cjs/switch/switch-icons.js +21 -22
- package/build/cjs/switch/switch.e2e.stories.js +57 -0
- package/build/cjs/switch/switch.js +7 -40
- package/build/cjs/switch/{switch.stories.js → switch.prod.stories.js} +53 -73
- package/build/cjs/switch-field/__tests__/switch-field.test.js +1 -7
- package/build/cjs/switch-field/features/can_be_required/index.js +0 -1
- package/build/cjs/switch-field/index.js +0 -1
- package/build/cjs/switch-field/switch-field.e2e.stories.js +19 -0
- package/build/cjs/switch-field/switch-field.js +4 -30
- package/build/cjs/switch-field/{switch-field.stories.js → switch-field.prod.stories.js} +59 -72
- package/build/es/switch/features/accepts_initial_focus/index.js +1 -1
- package/build/es/switch/features/can_be_blurred/index.js +1 -1
- package/build/es/switch/features/can_be_changed/index.js +1 -1
- package/build/es/switch/features/can_be_focused/index.js +1 -1
- package/build/es/switch/switch-icons.js +20 -13
- package/build/es/switch/{switch.stories.e2e.js → switch.e2e.stories.js} +15 -8
- package/build/es/switch/switch.js +4 -29
- package/build/es/switch/{switch.stories.js → switch.prod.stories.js} +33 -25
- package/build/es/switch-field/switch-field.e2e.stories.js +11 -0
- package/build/es/switch-field/switch-field.js +3 -22
- package/build/es/switch-field/{switch-field.stories.js → switch-field.prod.stories.js} +38 -23
- package/package.json +7 -7
- package/build/cjs/switch/switch.stories.e2e.js +0 -44
- package/build/cjs/switch-field/switch-field.stories.e2e.js +0 -16
- package/build/es/switch-field/switch-field.stories.e2e.js +0 -9
|
@@ -4,29 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.WarningDense = exports.Warning = exports.ValidDense = exports.Valid = exports.RequiredDense = exports.Required = exports.ImageLabelDense = exports.ImageLabel = exports.HelpText = exports.FocusedUncheckedDense = exports.FocusedUnchecked = exports.FocusedCheckedDense = exports.FocusedChecked = exports.ErrorDense = exports.Error = exports.DisabledDense = exports.Disabled = exports.DefaultDense = exports.Default = exports.CheckedDense = exports.Checked = void 0;
|
|
7
|
-
|
|
8
7
|
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _index = require("./index.js");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
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); }
|
|
12
|
+
const description = `
|
|
13
|
+
A \`SwitchField\` is a Switch component wrapped with extra form utilities, including the ability to add a label, help text, and validation text. Validation styles like 'error' apply to all of these subcomponents.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
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); }
|
|
17
|
-
|
|
18
|
-
const description = "\nA `SwitchField` is a Switch component wrapped with extra form utilities, including the ability to add a label, help text, and validation text. Validation styles like 'error' apply to all of these subcomponents.\n\nSee the basic Switch for usage and design system guidelines.\n\n```js\nimport { SwitchField } from '@dhis2/ui'\n```\n";
|
|
15
|
+
See the basic Switch for usage and design system guidelines.
|
|
19
16
|
|
|
17
|
+
\`\`\`js
|
|
18
|
+
import { SwitchField } from '@dhis2/ui'
|
|
19
|
+
\`\`\`
|
|
20
|
+
`;
|
|
20
21
|
const logger = _ref => {
|
|
21
22
|
let {
|
|
22
23
|
name,
|
|
23
24
|
value,
|
|
24
25
|
checked
|
|
25
26
|
} = _ref;
|
|
26
|
-
return console.log(
|
|
27
|
+
return console.log(`name: ${name}, value: ${value}, checked: ${checked}`);
|
|
27
28
|
};
|
|
28
|
-
|
|
29
|
-
var _default = {
|
|
29
|
+
var _default = exports.default = {
|
|
30
30
|
title: 'Switch Field',
|
|
31
31
|
component: _index.SwitchField,
|
|
32
32
|
parameters: {
|
|
@@ -44,38 +44,35 @@ var _default = {
|
|
|
44
44
|
onChange: logger
|
|
45
45
|
},
|
|
46
46
|
argTypes: {
|
|
47
|
-
valid: {
|
|
47
|
+
valid: {
|
|
48
|
+
..._uiConstants.sharedPropTypes.statusArgType
|
|
48
49
|
},
|
|
49
|
-
warning: {
|
|
50
|
+
warning: {
|
|
51
|
+
..._uiConstants.sharedPropTypes.statusArgType
|
|
50
52
|
},
|
|
51
|
-
error: {
|
|
53
|
+
error: {
|
|
54
|
+
..._uiConstants.sharedPropTypes.statusArgType
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
};
|
|
55
|
-
exports.default = _default;
|
|
56
|
-
|
|
57
58
|
const Template = args => /*#__PURE__*/_react.default.createElement(_index.SwitchField, args);
|
|
58
|
-
|
|
59
59
|
const CheckedUncheckedTemplate = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_index.SwitchField, args), /*#__PURE__*/_react.default.createElement(_index.SwitchField, _extends({}, args, {
|
|
60
60
|
checked: true
|
|
61
61
|
})));
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
exports.Default = Default;
|
|
65
|
-
const FocusedUnchecked = Template.bind({});
|
|
66
|
-
exports.FocusedUnchecked = FocusedUnchecked;
|
|
62
|
+
const Default = exports.Default = Template.bind({});
|
|
63
|
+
const FocusedUnchecked = exports.FocusedUnchecked = Template.bind({});
|
|
67
64
|
FocusedUnchecked.args = {
|
|
68
65
|
initialFocus: true
|
|
69
|
-
};
|
|
70
|
-
|
|
66
|
+
};
|
|
67
|
+
// Disable stories on docs page that grab focus
|
|
71
68
|
FocusedUnchecked.parameters = {
|
|
72
69
|
docs: {
|
|
73
70
|
disable: true
|
|
74
71
|
}
|
|
75
72
|
};
|
|
76
|
-
const FocusedChecked = Template.bind({});
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
const FocusedChecked = exports.FocusedChecked = Template.bind({});
|
|
74
|
+
FocusedChecked.args = {
|
|
75
|
+
...FocusedUnchecked.args,
|
|
79
76
|
checked: true
|
|
80
77
|
};
|
|
81
78
|
FocusedChecked.parameters = {
|
|
@@ -83,69 +80,59 @@ FocusedChecked.parameters = {
|
|
|
83
80
|
disable: true
|
|
84
81
|
}
|
|
85
82
|
};
|
|
86
|
-
const Checked = Template.bind({});
|
|
87
|
-
exports.Checked = Checked;
|
|
83
|
+
const Checked = exports.Checked = Template.bind({});
|
|
88
84
|
Checked.args = {
|
|
89
85
|
checked: true,
|
|
90
86
|
value: 'checkedValue'
|
|
91
87
|
};
|
|
92
|
-
const Required = Template.bind({});
|
|
93
|
-
exports.Required = Required;
|
|
88
|
+
const Required = exports.Required = Template.bind({});
|
|
94
89
|
Required.args = {
|
|
95
90
|
required: true
|
|
96
91
|
};
|
|
97
|
-
const Disabled = CheckedUncheckedTemplate.bind({});
|
|
98
|
-
exports.Disabled = Disabled;
|
|
92
|
+
const Disabled = exports.Disabled = CheckedUncheckedTemplate.bind({});
|
|
99
93
|
Disabled.args = {
|
|
100
94
|
disabled: true
|
|
101
95
|
};
|
|
102
|
-
|
|
103
96
|
const HelpText = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_index.SwitchField, args), /*#__PURE__*/_react.default.createElement(_index.SwitchField, _extends({}, args, {
|
|
104
97
|
error: true,
|
|
105
98
|
validationText: "Validation text (error state)"
|
|
106
99
|
})));
|
|
107
|
-
|
|
108
100
|
exports.HelpText = HelpText;
|
|
109
101
|
HelpText.args = {
|
|
110
102
|
helpText: 'Help text'
|
|
111
103
|
};
|
|
112
|
-
const Valid = CheckedUncheckedTemplate.bind({});
|
|
113
|
-
exports.Valid = Valid;
|
|
104
|
+
const Valid = exports.Valid = CheckedUncheckedTemplate.bind({});
|
|
114
105
|
Valid.args = {
|
|
115
106
|
valid: true,
|
|
116
107
|
validationText: 'I am validation text',
|
|
117
108
|
value: 'validValue'
|
|
118
109
|
};
|
|
119
|
-
const Warning = CheckedUncheckedTemplate.bind({});
|
|
120
|
-
exports.Warning = Warning;
|
|
110
|
+
const Warning = exports.Warning = CheckedUncheckedTemplate.bind({});
|
|
121
111
|
Warning.args = {
|
|
122
112
|
warning: true,
|
|
123
113
|
value: 'warningValue',
|
|
124
114
|
validationText: 'I am validation text'
|
|
125
115
|
};
|
|
126
|
-
const Error = CheckedUncheckedTemplate.bind({});
|
|
127
|
-
exports.Error = Error;
|
|
116
|
+
const Error = exports.Error = CheckedUncheckedTemplate.bind({});
|
|
128
117
|
Error.args = {
|
|
129
118
|
error: true,
|
|
130
119
|
value: 'errorValue',
|
|
131
120
|
validationText: 'I am validation text'
|
|
132
121
|
};
|
|
133
|
-
const ImageLabel = Template.bind({});
|
|
134
|
-
exports.ImageLabel = ImageLabel;
|
|
122
|
+
const ImageLabel = exports.ImageLabel = Template.bind({});
|
|
135
123
|
ImageLabel.args = {
|
|
136
124
|
label: /*#__PURE__*/_react.default.createElement("img", {
|
|
137
125
|
src: "https://picsum.photos/id/82/200/100"
|
|
138
126
|
})
|
|
139
127
|
};
|
|
140
|
-
const DefaultDense = Template.bind({});
|
|
141
|
-
exports.DefaultDense = DefaultDense;
|
|
128
|
+
const DefaultDense = exports.DefaultDense = Template.bind({});
|
|
142
129
|
DefaultDense.storyName = 'Default - Dense';
|
|
143
130
|
DefaultDense.args = {
|
|
144
131
|
dense: true
|
|
145
132
|
};
|
|
146
|
-
const FocusedUncheckedDense = Template.bind({});
|
|
147
|
-
|
|
148
|
-
|
|
133
|
+
const FocusedUncheckedDense = exports.FocusedUncheckedDense = Template.bind({});
|
|
134
|
+
FocusedUncheckedDense.args = {
|
|
135
|
+
...DefaultDense.args,
|
|
149
136
|
...FocusedUnchecked.args
|
|
150
137
|
};
|
|
151
138
|
FocusedUncheckedDense.parameters = {
|
|
@@ -154,9 +141,9 @@ FocusedUncheckedDense.parameters = {
|
|
|
154
141
|
}
|
|
155
142
|
};
|
|
156
143
|
FocusedUncheckedDense.storyName = 'Focused unchecked - Dense';
|
|
157
|
-
const FocusedCheckedDense = Template.bind({});
|
|
158
|
-
|
|
159
|
-
|
|
144
|
+
const FocusedCheckedDense = exports.FocusedCheckedDense = Template.bind({});
|
|
145
|
+
FocusedCheckedDense.args = {
|
|
146
|
+
...DefaultDense.args,
|
|
160
147
|
...FocusedChecked.args
|
|
161
148
|
};
|
|
162
149
|
FocusedCheckedDense.parameters = {
|
|
@@ -165,45 +152,45 @@ FocusedCheckedDense.parameters = {
|
|
|
165
152
|
}
|
|
166
153
|
};
|
|
167
154
|
FocusedCheckedDense.storyName = 'Focused checked - Dense';
|
|
168
|
-
const CheckedDense = Template.bind({});
|
|
169
|
-
|
|
170
|
-
|
|
155
|
+
const CheckedDense = exports.CheckedDense = Template.bind({});
|
|
156
|
+
CheckedDense.args = {
|
|
157
|
+
...DefaultDense.args,
|
|
171
158
|
...Checked.args
|
|
172
159
|
};
|
|
173
160
|
CheckedDense.storyName = 'Checked - Dense';
|
|
174
|
-
const RequiredDense = Template.bind({});
|
|
175
|
-
|
|
176
|
-
|
|
161
|
+
const RequiredDense = exports.RequiredDense = Template.bind({});
|
|
162
|
+
RequiredDense.args = {
|
|
163
|
+
...DefaultDense.args,
|
|
177
164
|
...Required.args
|
|
178
165
|
};
|
|
179
166
|
RequiredDense.storyName = 'Required - Dense';
|
|
180
|
-
const DisabledDense = CheckedUncheckedTemplate.bind({});
|
|
181
|
-
|
|
182
|
-
|
|
167
|
+
const DisabledDense = exports.DisabledDense = CheckedUncheckedTemplate.bind({});
|
|
168
|
+
DisabledDense.args = {
|
|
169
|
+
...DefaultDense.args,
|
|
183
170
|
...Disabled.args
|
|
184
171
|
};
|
|
185
172
|
DisabledDense.storyName = 'Disabled - Dense';
|
|
186
|
-
const ValidDense = CheckedUncheckedTemplate.bind({});
|
|
187
|
-
|
|
188
|
-
|
|
173
|
+
const ValidDense = exports.ValidDense = CheckedUncheckedTemplate.bind({});
|
|
174
|
+
ValidDense.args = {
|
|
175
|
+
...DefaultDense.args,
|
|
189
176
|
...Valid.args
|
|
190
177
|
};
|
|
191
178
|
ValidDense.storyName = 'Valid - Dense';
|
|
192
|
-
const WarningDense = CheckedUncheckedTemplate.bind({});
|
|
193
|
-
|
|
194
|
-
|
|
179
|
+
const WarningDense = exports.WarningDense = CheckedUncheckedTemplate.bind({});
|
|
180
|
+
WarningDense.args = {
|
|
181
|
+
...DefaultDense.args,
|
|
195
182
|
...Warning.args
|
|
196
183
|
};
|
|
197
184
|
WarningDense.storyName = 'Warning - Dense';
|
|
198
|
-
const ErrorDense = CheckedUncheckedTemplate.bind({});
|
|
199
|
-
|
|
200
|
-
|
|
185
|
+
const ErrorDense = exports.ErrorDense = CheckedUncheckedTemplate.bind({});
|
|
186
|
+
ErrorDense.args = {
|
|
187
|
+
...DefaultDense.args,
|
|
201
188
|
...Error.args
|
|
202
189
|
};
|
|
203
190
|
ErrorDense.storyName = 'Error - Dense';
|
|
204
|
-
const ImageLabelDense = Template.bind({});
|
|
205
|
-
|
|
206
|
-
|
|
191
|
+
const ImageLabelDense = exports.ImageLabelDense = Template.bind({});
|
|
192
|
+
ImageLabelDense.args = {
|
|
193
|
+
...DefaultDense.args,
|
|
207
194
|
...ImageLabel.args
|
|
208
195
|
};
|
|
209
196
|
ImageLabelDense.storyName = 'Image label - Dense';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor';
|
|
2
2
|
Given('a Switch with initialFocus is rendered', () => {
|
|
3
|
-
cy.visitStory('Switch', 'With
|
|
3
|
+
cy.visitStory('Switch', 'With initial focus');
|
|
4
4
|
});
|
|
5
5
|
Then('the Switch is focused', () => {
|
|
6
6
|
cy.focused().parent('[data-test="dhis2-uicore-switch"]').should('exist');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
|
|
2
2
|
Given('a Switch with initialFocus and onBlur handler is rendered', () => {
|
|
3
|
-
cy.visitStory('Switch', 'With
|
|
3
|
+
cy.visitStory('Switch', 'With initial focus and on blur');
|
|
4
4
|
});
|
|
5
5
|
When('the Switch is blurred', () => {
|
|
6
6
|
cy.get('[data-test="dhis2-uicore-switch"] input').blur();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
|
|
2
2
|
Given('a Switch with onChange handler is rendered', () => {
|
|
3
|
-
cy.visitStory('Switch', 'With
|
|
3
|
+
cy.visitStory('Switch', 'With on change');
|
|
4
4
|
});
|
|
5
5
|
When('the Switch is clicked', () => {
|
|
6
6
|
cy.get('[data-test="dhis2-uicore-switch"]').click();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor';
|
|
2
2
|
Given('a Switch with onFocus handler is rendered', () => {
|
|
3
|
-
cy.visitStory('Switch', 'With
|
|
3
|
+
cy.visitStory('Switch', 'With on focus');
|
|
4
4
|
});
|
|
5
5
|
When('the Switch is focused', () => {
|
|
6
6
|
cy.get('[data-test="dhis2-uicore-switch"] input').focus();
|
|
@@ -2,11 +2,10 @@ import _JSXStyle from "styled-jsx/style";
|
|
|
2
2
|
import { colors } from '@dhis2/ui-constants';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
const styles = ["svg.jsx-4217794981{display:block;pointer-events:none;height:18px;width:35px;}", "svg.jsx-4217794981:dir(rtl){-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1);}", "svg[dir='rtl'].jsx-4217794981{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1);}", "svg.dense.jsx-4217794981{height:14px;width:27px;}",
|
|
5
|
+
const styles = ["svg.jsx-4217794981{display:block;pointer-events:none;height:18px;width:35px;}", "svg.jsx-4217794981:dir(rtl){-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1);}", "svg[dir='rtl'].jsx-4217794981{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1);}", "svg.dense.jsx-4217794981{height:14px;width:27px;}", `svg.jsx-4217794981 .background.jsx-4217794981,svg.jsx-4217794981 .border.jsx-4217794981{fill:${colors.grey600};}`, `svg.jsx-4217794981 .checkmark.jsx-4217794981,svg.jsx-4217794981 .cross.jsx-4217794981,svg.jsx-4217794981 .handle.jsx-4217794981{fill:${colors.white};}`, "svg.jsx-4217794981 .checkmark.jsx-4217794981:dir(rtl){display:none;}", "svg[dir='rtl'].jsx-4217794981 .checkmark.jsx-4217794981{display:none;}", "svg.checked.jsx-4217794981 .handle-unchecked.jsx-4217794981,svg.jsx-4217794981:not(.checked) .handle-checked.jsx-4217794981{fill:none;}", `svg.checked.jsx-4217794981 .background.jsx-4217794981{fill:${colors.teal400};}`, `svg.valid.jsx-4217794981 .background.jsx-4217794981{fill:${colors.blue600};}`, `svg.warning.jsx-4217794981 .background.jsx-4217794981{fill:${colors.yellow700};}`, `svg.error.jsx-4217794981 .background.jsx-4217794981{fill:${colors.red500};}`, `svg.checked.jsx-4217794981 .border.jsx-4217794981{fill:${colors.teal700};}`, `svg.disabled.jsx-4217794981 .background.jsx-4217794981{fill:${colors.grey300};}`, `svg.disabled.jsx-4217794981 .border.jsx-4217794981{fill:${colors.grey400};}`, `svg.valid.jsx-4217794981 .border.jsx-4217794981{fill:${colors.blue600};}`, `svg.valid.checked.jsx-4217794981 .border.jsx-4217794981,svg.valid.indeterminate.jsx-4217794981 .border.jsx-4217794981{fill:${colors.blue700};}`, `svg.warning.jsx-4217794981 .border.jsx-4217794981{fill:${colors.yellow700};}`, `svg.warning.checked.jsx-4217794981 .border.jsx-4217794981{fill:${colors.yellow800};}`, `svg.error.jsx-4217794981 .border.jsx-4217794981{fill:${colors.red500};}`, `svg.error.checked.jsx-4217794981 .border.jsx-4217794981{fill:${colors.red700};}`];
|
|
6
6
|
styles.__hash = "4217794981";
|
|
7
7
|
export function SwitchRegular(_ref) {
|
|
8
8
|
var _document$documentEle, _document$documentEle2;
|
|
9
|
-
|
|
10
9
|
let {
|
|
11
10
|
className
|
|
12
11
|
} = _ref;
|
|
@@ -14,33 +13,41 @@ export function SwitchRegular(_ref) {
|
|
|
14
13
|
viewBox: "0 0 42 22",
|
|
15
14
|
xmlns: "http://www.w3.org/2000/svg",
|
|
16
15
|
dir: (_document$documentEle = (_document$documentEle2 = document.documentElement) === null || _document$documentEle2 === void 0 ? void 0 : _document$documentEle2.dir) !== null && _document$documentEle !== void 0 ? _document$documentEle : 'ltr',
|
|
17
|
-
className:
|
|
16
|
+
className: `jsx-${styles.__hash}` + " " + (className || "")
|
|
18
17
|
}, /*#__PURE__*/React.createElement("path", {
|
|
19
18
|
d: "M0,11 L0,11 C0,4.92486775 4.92076837,0 11.0075657,0 L30.9924343,0 C37.071745,0 42,4.923532 42,11 L42,11 C42,17.0751322 37.0792316,22 30.9924343,22 L11.0075657,22 C4.92825504,22 0,17.0791222 0,11 L0,11 Z",
|
|
20
19
|
fill: "red",
|
|
21
|
-
className:
|
|
20
|
+
className: `jsx-${styles.__hash}` + " " + "background"
|
|
22
21
|
}), /*#__PURE__*/React.createElement("path", {
|
|
23
|
-
d: "M30.9924343,0 C36.975248,0 41.8432574,4.76846989 41.99629,10.7115309 L42,11 C42,17.0751322 37.0792316,22 30.9924343,22 L11.0075657,22 C5.02475203,22 0.156742552,17.2341007 0.00370995454,11.2885915 L0,11 C0,4.92486775 4.92076837,0 11.0075657,0 L30.9924343,0 Z M30.9924343,1 L11.0075657,1 C5.47559009,1 0.99991738,5.47461611 0.99991738,10.9871457 L1.00337887,11.2628608 C1.14271146,16.6761076 5.5768313,21 11.0075657,21 L30.9924343,21 C36.5244099,21 41.0000827,16.5253839 41.0000827,11.0128598 L40.9966214,10.7372722 C40.8572703,5.32553352 36.4222391,1 30.9924343,1 Z"
|
|
22
|
+
d: "M30.9924343,0 C36.975248,0 41.8432574,4.76846989 41.99629,10.7115309 L42,11 C42,17.0751322 37.0792316,22 30.9924343,22 L11.0075657,22 C5.02475203,22 0.156742552,17.2341007 0.00370995454,11.2885915 L0,11 C0,4.92486775 4.92076837,0 11.0075657,0 L30.9924343,0 Z M30.9924343,1 L11.0075657,1 C5.47559009,1 0.99991738,5.47461611 0.99991738,10.9871457 L1.00337887,11.2628608 C1.14271146,16.6761076 5.5768313,21 11.0075657,21 L30.9924343,21 C36.5244099,21 41.0000827,16.5253839 41.0000827,11.0128598 L40.9966214,10.7372722 C40.8572703,5.32553352 36.4222391,1 30.9924343,1 Z"
|
|
23
|
+
|
|
24
|
+
// fill="#00695C"
|
|
24
25
|
// fillRule="nonzero"
|
|
25
26
|
,
|
|
26
|
-
className:
|
|
27
|
+
className: `jsx-${styles.__hash}` + " " + "border"
|
|
27
28
|
}), /*#__PURE__*/React.createElement("path", {
|
|
28
29
|
d: "M27.7071068,7.29289322 L30,9.585 L32.2928932,7.29289322 C32.6533772,6.93240926 33.2206082,6.90467972 33.6128994,7.20970461 L33.7071068,7.29289322 C34.0976311,7.68341751 34.0976311,8.31658249 33.7071068,8.70710678 L33.7071068,8.70710678 L31.415,11 L33.7071068,13.2928932 C34.0976311,13.6834175 34.0976311,14.3165825 33.7071068,14.7071068 C33.3165825,15.0976311 32.6834175,15.0976311 32.2928932,14.7071068 L30,12.415 L27.7071068,14.7071068 C27.3466228,15.0675907 26.7793918,15.0953203 26.3871006,14.7902954 L26.2928932,14.7071068 C25.9023689,14.3165825 25.9023689,13.6834175 26.2928932,13.2928932 L26.2928932,13.2928932 L28.585,11 L26.2928932,8.70710678 C25.9023689,8.31658249 25.9023689,7.68341751 26.2928932,7.29289322 C26.6834175,6.90236893 27.3165825,6.90236893 27.7071068,7.29289322 Z",
|
|
29
30
|
fill: "#FFFFFF",
|
|
30
|
-
className:
|
|
31
|
+
className: `jsx-${styles.__hash}` + " " + "cross"
|
|
31
32
|
}), /*#__PURE__*/React.createElement("path", {
|
|
32
|
-
d: "M7.74451387,10.0285252 C7.39595738,10.1198564 7.12375034,10.3923519 7.03251575,10.7412777 C6.94128115,11.0902035 7.04521722,11.4612586 7.30437605,11.7118278 L10.2982384,14.7078028 C10.6875399,15.0973991 11.3185977,15.0973991 11.7078992,14.7078028 L16.695624,8.71585285 C16.9547828,8.46528367 17.0587189,8.09422851 16.9674843,7.74530271 C16.8762497,7.39637691 16.6040426,7.12388146 16.2554861,7.0325502 C15.9069296,6.94121893 15.5362672,7.04526513 15.2859632,7.30469855 L11.0030688,12.5910713 L8.71403676,10.3006735 C8.46373279,10.0412401 8.09307036,9.9371939 7.74451387,10.0285252 Z"
|
|
33
|
+
d: "M7.74451387,10.0285252 C7.39595738,10.1198564 7.12375034,10.3923519 7.03251575,10.7412777 C6.94128115,11.0902035 7.04521722,11.4612586 7.30437605,11.7118278 L10.2982384,14.7078028 C10.6875399,15.0973991 11.3185977,15.0973991 11.7078992,14.7078028 L16.695624,8.71585285 C16.9547828,8.46528367 17.0587189,8.09422851 16.9674843,7.74530271 C16.8762497,7.39637691 16.6040426,7.12388146 16.2554861,7.0325502 C15.9069296,6.94121893 15.5362672,7.04526513 15.2859632,7.30469855 L11.0030688,12.5910713 L8.71403676,10.3006735 C8.46373279,10.0412401 8.09307036,9.9371939 7.74451387,10.0285252 Z"
|
|
34
|
+
|
|
35
|
+
// fill="#FFFFFF"
|
|
33
36
|
// fillRule="nonzero"
|
|
34
37
|
,
|
|
35
|
-
className:
|
|
38
|
+
className: `jsx-${styles.__hash}` + " " + "checkmark"
|
|
36
39
|
}), /*#__PURE__*/React.createElement("path", {
|
|
37
|
-
d: "M11,20 C15.9705627,20 20,15.9705627 20,11 C20,6.02943725 15.9705627,2 11,2 C6.02943725,2 2,6.02943725 2,11 C2,15.9705627 6.02943725,20 11,20 Z"
|
|
40
|
+
d: "M11,20 C15.9705627,20 20,15.9705627 20,11 C20,6.02943725 15.9705627,2 11,2 C6.02943725,2 2,6.02943725 2,11 C2,15.9705627 6.02943725,20 11,20 Z"
|
|
41
|
+
|
|
42
|
+
// fill="#FFFFFF"
|
|
38
43
|
,
|
|
39
|
-
className:
|
|
44
|
+
className: `jsx-${styles.__hash}` + " " + "handle handle-unchecked"
|
|
40
45
|
}), /*#__PURE__*/React.createElement("path", {
|
|
41
|
-
d: "M31,20 C35.9705627,20 40,15.9705627 40,11 C40,6.02943725 35.9705627,2 31,2 C26.0294373,2 22,6.02943725 22,11 C22,15.9705627 26.0294373,20 31,20 Z"
|
|
46
|
+
d: "M31,20 C35.9705627,20 40,15.9705627 40,11 C40,6.02943725 35.9705627,2 31,2 C26.0294373,2 22,6.02943725 22,11 C22,15.9705627 26.0294373,20 31,20 Z"
|
|
47
|
+
|
|
48
|
+
// fill="#FFFFFF"
|
|
42
49
|
,
|
|
43
|
-
className:
|
|
50
|
+
className: `jsx-${styles.__hash}` + " " + "handle handle-checked"
|
|
44
51
|
}), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
45
52
|
id: styles.__hash
|
|
46
53
|
}, styles));
|
|
@@ -1,37 +1,44 @@
|
|
|
1
|
-
import { storiesOf } from '@storybook/react';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { Switch } from './index.js';
|
|
4
3
|
window.onChange = 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: 'Switch'
|
|
8
|
+
};
|
|
9
|
+
export const WithOnChange = () => /*#__PURE__*/React.createElement(Switch, {
|
|
8
10
|
name: "Ex",
|
|
9
11
|
label: "Switch",
|
|
10
12
|
value: "default",
|
|
11
13
|
onChange: window.onChange
|
|
12
|
-
})
|
|
14
|
+
});
|
|
15
|
+
export const WithInitialFocusAndOnBlur = () => /*#__PURE__*/React.createElement(Switch, {
|
|
13
16
|
initialFocus: true,
|
|
14
17
|
name: "Ex",
|
|
15
18
|
label: "Switch",
|
|
16
19
|
value: "default",
|
|
17
20
|
onBlur: window.onBlur
|
|
18
|
-
})
|
|
21
|
+
});
|
|
22
|
+
export const WithOnFocus = () => /*#__PURE__*/React.createElement(Switch, {
|
|
19
23
|
name: "Ex",
|
|
20
24
|
label: "Switch",
|
|
21
25
|
value: "default",
|
|
22
26
|
onFocus: window.onFocus
|
|
23
|
-
})
|
|
27
|
+
});
|
|
28
|
+
export const WithDisabled = () => /*#__PURE__*/React.createElement(Switch, {
|
|
24
29
|
name: "Ex",
|
|
25
30
|
label: "Switch",
|
|
26
31
|
value: "default",
|
|
27
32
|
disabled: true
|
|
28
|
-
})
|
|
33
|
+
});
|
|
34
|
+
export const WithLabel = () => /*#__PURE__*/React.createElement(Switch, {
|
|
29
35
|
name: "Ex",
|
|
30
36
|
label: "The label",
|
|
31
37
|
value: "default"
|
|
32
|
-
})
|
|
38
|
+
});
|
|
39
|
+
export const WithInitialFocus = () => /*#__PURE__*/React.createElement(Switch, {
|
|
33
40
|
name: "Ex",
|
|
34
41
|
label: "The label",
|
|
35
42
|
value: "default",
|
|
36
43
|
initialFocus: true
|
|
37
|
-
})
|
|
44
|
+
});
|
|
@@ -1,50 +1,42 @@
|
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
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); }
|
|
5
5
|
import { colors, theme, sharedPropTypes } from '@dhis2/ui-constants';
|
|
6
6
|
import cx from 'classnames';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import React, { Component, createRef } from 'react';
|
|
9
9
|
import { SwitchRegular } from './switch-icons.js';
|
|
10
|
-
|
|
11
10
|
class Switch extends Component {
|
|
12
11
|
constructor() {
|
|
13
12
|
super(...arguments);
|
|
14
|
-
|
|
15
13
|
_defineProperty(this, "ref", /*#__PURE__*/createRef());
|
|
16
|
-
|
|
17
14
|
_defineProperty(this, "handleChange", e => {
|
|
18
15
|
if (this.props.onChange) {
|
|
19
16
|
this.props.onChange(this.createHandlerPayload(), e);
|
|
20
17
|
}
|
|
21
18
|
});
|
|
22
|
-
|
|
23
19
|
_defineProperty(this, "handleBlur", e => {
|
|
24
20
|
if (this.props.onBlur) {
|
|
25
21
|
this.props.onBlur(this.createHandlerPayload(), e);
|
|
26
22
|
}
|
|
27
23
|
});
|
|
28
|
-
|
|
29
24
|
_defineProperty(this, "handleFocus", e => {
|
|
30
25
|
if (this.props.onFocus) {
|
|
31
26
|
this.props.onFocus(this.createHandlerPayload(), e);
|
|
32
27
|
}
|
|
33
28
|
});
|
|
34
|
-
|
|
35
29
|
_defineProperty(this, "handleKeyDown", e => {
|
|
36
30
|
if (this.props.onKeyDown) {
|
|
37
31
|
this.props.onKeyDown(this.createHandlerPayload(), e);
|
|
38
32
|
}
|
|
39
33
|
});
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
componentDidMount() {
|
|
43
36
|
if (this.props.initialFocus) {
|
|
44
37
|
this.ref.current.focus();
|
|
45
38
|
}
|
|
46
39
|
}
|
|
47
|
-
|
|
48
40
|
createHandlerPayload() {
|
|
49
41
|
return {
|
|
50
42
|
value: this.props.value,
|
|
@@ -52,7 +44,6 @@ class Switch extends Component {
|
|
|
52
44
|
checked: !this.props.checked
|
|
53
45
|
};
|
|
54
46
|
}
|
|
55
|
-
|
|
56
47
|
render() {
|
|
57
48
|
const {
|
|
58
49
|
'aria-label': ariaLabel,
|
|
@@ -108,11 +99,9 @@ class Switch extends Component {
|
|
|
108
99
|
})), label, /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
109
100
|
id: "3097670863",
|
|
110
101
|
dynamic: [colors.grey900, theme.disabled, theme.focus]
|
|
111
|
-
}, [
|
|
102
|
+
}, [`label.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:start;-webkit-justify-content:flex-start;-ms-flex-pack:start;justify-content:flex-start;color:${colors.grey900};font-size:14px;line-height:19px;}`, "label.dense.__jsx-style-dynamic-selector{font-size:14px;line-height:16px;}", `label.disabled.__jsx-style-dynamic-selector{cursor:not-allowed;color:${theme.disabled};}`, "input.__jsx-style-dynamic-selector{opacity:0;position:absolute;height:18px;width:35px;margin-left:3px;}", "label.dense.__jsx-style-dynamic-selector input.__jsx-style-dynamic-selector{height:14px;width:27px;}", ".icon.__jsx-style-dynamic-selector{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;margin-right:5px;border:2px solid transparent;padding:1px;border-radius:14px;}", "label.dense.__jsx-style-dynamic-selector .icon.__jsx-style-dynamic-selector{margin-right:3px;border-radius:12px;}", `input.__jsx-style-dynamic-selector:focus+.icon.__jsx-style-dynamic-selector{outline:3px solid ${theme.focus};outline-offset:-3px;}`]));
|
|
112
103
|
}
|
|
113
|
-
|
|
114
104
|
}
|
|
115
|
-
|
|
116
105
|
Switch.defaultProps = {
|
|
117
106
|
checked: false,
|
|
118
107
|
dataTest: 'dhis2-uicore-switch',
|
|
@@ -124,47 +113,33 @@ Switch.propTypes = {
|
|
|
124
113
|
checked: PropTypes.bool,
|
|
125
114
|
className: PropTypes.string,
|
|
126
115
|
dataTest: PropTypes.string,
|
|
127
|
-
|
|
128
116
|
/** Makes the switch smaller for information-dense layouts */
|
|
129
117
|
dense: PropTypes.bool,
|
|
130
|
-
|
|
131
118
|
/** Disables the switch */
|
|
132
119
|
disabled: PropTypes.bool,
|
|
133
|
-
|
|
134
120
|
/** Applies 'error' styles for validation feedback. Mutually exclusive with `valid` and `warning` prop types */
|
|
135
121
|
error: sharedPropTypes.statusPropType,
|
|
136
|
-
|
|
137
122
|
/** Grab initial focus on the page */
|
|
138
123
|
initialFocus: PropTypes.bool,
|
|
139
|
-
|
|
140
124
|
/** Label for the switch. Can be a string or an element, for example an image */
|
|
141
125
|
label: PropTypes.node,
|
|
142
|
-
|
|
143
126
|
/** Name associated with the switch. Passed to event handlers in object */
|
|
144
127
|
name: PropTypes.string,
|
|
145
|
-
|
|
146
128
|
/** Sets a role attribute on the input */
|
|
147
129
|
role: PropTypes.string,
|
|
148
130
|
tabIndex: PropTypes.string,
|
|
149
|
-
|
|
150
131
|
/** Applies 'valid' styles for validation feedback. Mutually exclusive with `error` and `warning` prop types */
|
|
151
132
|
valid: sharedPropTypes.statusPropType,
|
|
152
|
-
|
|
153
133
|
/** Value associated with the switch. Passed to event handlers in object */
|
|
154
134
|
value: PropTypes.string,
|
|
155
|
-
|
|
156
135
|
/** Applies 'warning' styles for validation feedback. Mutually exclusive with `valid` and `error` prop types */
|
|
157
136
|
warning: sharedPropTypes.statusPropType,
|
|
158
|
-
|
|
159
137
|
/** Called with signature `({ name: string, value: string, checked: bool }, event)` */
|
|
160
138
|
onBlur: PropTypes.func,
|
|
161
|
-
|
|
162
139
|
/** Called with signature `({ name: string, value: string, checked: bool }, event)` */
|
|
163
140
|
onChange: PropTypes.func,
|
|
164
|
-
|
|
165
141
|
/** Called with signature `({ name: string, value: string, checked: bool }, event)` */
|
|
166
142
|
onFocus: PropTypes.func,
|
|
167
|
-
|
|
168
143
|
/** Called with signature `({ name: string, value: string, checked: bool }, event)` */
|
|
169
144
|
onKeyDown: PropTypes.func
|
|
170
145
|
};
|