@dxc-technology/halstack-react 0.0.0-301f60b → 0.0.0-335f028
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/HalstackContext.d.ts +10 -0
- package/{ThemeContext.js → HalstackContext.js} +6 -6
- package/accordion/Accordion.d.ts +1 -1
- package/accordion/Accordion.js +7 -28
- package/accordion/Accordion.stories.tsx +11 -11
- package/accordion/Accordion.test.js +19 -4
- package/accordion/types.d.ts +4 -0
- package/accordion-group/AccordionGroup.d.ts +1 -1
- package/accordion-group/AccordionGroup.js +13 -15
- package/accordion-group/AccordionGroup.stories.tsx +1 -1
- package/accordion-group/AccordionGroup.test.js +24 -6
- package/accordion-group/types.d.ts +4 -0
- package/bleed/types.d.ts +24 -0
- package/button/Button.js +14 -11
- package/card/Card.js +27 -28
- package/checkbox/Checkbox.d.ts +1 -1
- package/checkbox/Checkbox.js +40 -39
- package/checkbox/Checkbox.stories.tsx +124 -128
- package/checkbox/Checkbox.test.js +13 -0
- package/checkbox/types.d.ts +7 -3
- package/common/variables.js +6 -7
- package/date-input/DateInput.js +50 -39
- package/date-input/DateInput.stories.tsx +7 -7
- package/date-input/DateInput.test.js +69 -59
- package/date-input/types.d.ts +16 -9
- package/dialog/Dialog.js +4 -32
- package/dropdown/Dropdown.js +13 -17
- package/footer/Footer.js +10 -85
- package/header/Header.js +20 -44
- package/header/Header.stories.tsx +46 -36
- package/header/Header.test.js +18 -2
- package/inset/types.d.ts +24 -0
- package/layout/ApplicationLayout.js +5 -18
- package/link/Link.d.ts +3 -2
- package/link/Link.js +65 -56
- package/link/Link.stories.tsx +87 -52
- package/link/Link.test.js +7 -15
- package/link/types.d.ts +8 -23
- package/main.d.ts +3 -2
- package/main.js +13 -5
- package/number-input/NumberInput.js +11 -18
- package/number-input/NumberInput.stories.tsx +5 -5
- package/number-input/NumberInput.test.js +2 -4
- package/number-input/types.d.ts +16 -9
- package/package.json +6 -5
- package/password-input/PasswordInput.test.js +2 -4
- package/password-input/types.d.ts +13 -10
- package/quick-nav/QuickNav.d.ts +4 -0
- package/quick-nav/QuickNav.js +64 -0
- package/quick-nav/QuickNav.stories.tsx +237 -0
- package/quick-nav/types.d.ts +21 -0
- package/quick-nav/types.js +5 -0
- package/radio/Radio.js +10 -11
- package/row/types.d.ts +18 -0
- package/select/Listbox.d.ts +4 -0
- package/select/Listbox.js +148 -0
- package/select/Option.js +1 -1
- package/select/Select.js +71 -156
- package/select/Select.stories.tsx +19 -19
- package/select/Select.test.js +405 -248
- package/select/types.d.ts +42 -12
- package/slider/Slider.d.ts +1 -1
- package/slider/Slider.js +2 -1
- package/slider/Slider.stories.tsx +8 -8
- package/slider/Slider.test.js +31 -10
- package/slider/types.d.ts +4 -0
- package/stack/types.d.ts +15 -0
- package/switch/Switch.d.ts +1 -1
- package/switch/Switch.js +32 -19
- package/switch/Switch.stories.tsx +14 -14
- package/switch/Switch.test.js +25 -0
- package/switch/types.d.ts +6 -2
- package/tabs/Tabs.d.ts +1 -1
- package/tabs/Tabs.js +9 -11
- package/tabs/Tabs.stories.tsx +0 -8
- package/tabs/Tabs.test.js +26 -9
- package/tabs/types.d.ts +4 -0
- package/tag/Tag.js +14 -19
- package/tag/Tag.stories.tsx +12 -8
- package/text-input/TextInput.js +2 -4
- package/text-input/TextInput.test.js +21 -34
- package/text-input/types.d.ts +13 -10
- package/textarea/Textarea.js +2 -4
- package/textarea/Textarea.test.js +10 -20
- package/textarea/types.d.ts +13 -10
- package/toggle-group/ToggleGroup.d.ts +1 -1
- package/toggle-group/ToggleGroup.js +5 -4
- package/toggle-group/ToggleGroup.stories.tsx +4 -4
- package/toggle-group/ToggleGroup.test.js +35 -4
- package/toggle-group/types.d.ts +8 -0
- package/useTheme.js +2 -2
- package/wizard/Wizard.d.ts +1 -1
- package/wizard/Wizard.js +28 -19
- package/wizard/Wizard.stories.tsx +13 -23
- package/wizard/Wizard.test.js +36 -23
- package/wizard/types.d.ts +6 -2
- package/ThemeContext.d.ts +0 -10
package/select/types.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ declare type CommonProps = {
|
|
|
53
53
|
/**
|
|
54
54
|
* An array of objects representing the selectable options.
|
|
55
55
|
*/
|
|
56
|
-
options
|
|
56
|
+
options: Option[] | OptionGroup[];
|
|
57
57
|
/**
|
|
58
58
|
* Helper text to be placed above the select.
|
|
59
59
|
*/
|
|
@@ -79,9 +79,12 @@ declare type CommonProps = {
|
|
|
79
79
|
*/
|
|
80
80
|
searchable?: boolean;
|
|
81
81
|
/**
|
|
82
|
-
* If it is defined
|
|
83
|
-
* the error below the select component.
|
|
84
|
-
*
|
|
82
|
+
* If it is a defined value and also a truthy string, the component will
|
|
83
|
+
* change its appearance, showing the error below the select component.
|
|
84
|
+
* If the defined value is an empty string, it will reserve a space below
|
|
85
|
+
* the component for a future error, but it would not change its look. In
|
|
86
|
+
* case of being undefined or null, both the appearance and the space for
|
|
87
|
+
* the error message would not be modified.
|
|
85
88
|
*/
|
|
86
89
|
error?: string;
|
|
87
90
|
/**
|
|
@@ -105,6 +108,10 @@ declare type SingleSelect = CommonProps & {
|
|
|
105
108
|
* option value.
|
|
106
109
|
*/
|
|
107
110
|
multiple?: false;
|
|
111
|
+
/**
|
|
112
|
+
* Initial value of the select, only when it is uncontrolled.
|
|
113
|
+
*/
|
|
114
|
+
defaultValue?: string;
|
|
108
115
|
/**
|
|
109
116
|
* Value of the select. If undefined, the component will be uncontrolled
|
|
110
117
|
* and the value will be managed internally by the component.
|
|
@@ -113,21 +120,21 @@ declare type SingleSelect = CommonProps & {
|
|
|
113
120
|
/**
|
|
114
121
|
* This function will be called when the user selects an option.
|
|
115
122
|
* An object including the current value and the error (if the value entered is not valid)
|
|
116
|
-
* will be passed to this function. If there is no error, error will be
|
|
123
|
+
* will be passed to this function. If there is no error, error will not be defined.
|
|
117
124
|
*/
|
|
118
125
|
onChange?: (val: {
|
|
119
126
|
value: string;
|
|
120
|
-
error
|
|
127
|
+
error?: string;
|
|
121
128
|
}) => void;
|
|
122
129
|
/**
|
|
123
130
|
* This function will be called when the select loses the focus. An
|
|
124
131
|
* object including the value and the error (if the value
|
|
125
132
|
* selected is not valid) will be passed to this function. If there is no error,
|
|
126
|
-
* error will be
|
|
133
|
+
* error will not be defined.
|
|
127
134
|
*/
|
|
128
135
|
onBlur?: (val: {
|
|
129
136
|
value: string;
|
|
130
|
-
error
|
|
137
|
+
error?: string;
|
|
131
138
|
}) => void;
|
|
132
139
|
};
|
|
133
140
|
declare type MultipleSelect = CommonProps & {
|
|
@@ -137,6 +144,10 @@ declare type MultipleSelect = CommonProps & {
|
|
|
137
144
|
* option value.
|
|
138
145
|
*/
|
|
139
146
|
multiple: true;
|
|
147
|
+
/**
|
|
148
|
+
* Initial value of the select, only when it is uncontrolled.
|
|
149
|
+
*/
|
|
150
|
+
defaultValue?: string[];
|
|
140
151
|
/**
|
|
141
152
|
* Value of the select. If undefined, the component will be uncontrolled
|
|
142
153
|
* and the value will be managed internally by the component.
|
|
@@ -149,7 +160,7 @@ declare type MultipleSelect = CommonProps & {
|
|
|
149
160
|
*/
|
|
150
161
|
onChange?: (val: {
|
|
151
162
|
value: string[];
|
|
152
|
-
error
|
|
163
|
+
error?: string;
|
|
153
164
|
}) => void;
|
|
154
165
|
/**
|
|
155
166
|
* This function will be called when the select loses the focus. An
|
|
@@ -159,7 +170,7 @@ declare type MultipleSelect = CommonProps & {
|
|
|
159
170
|
*/
|
|
160
171
|
onBlur?: (val: {
|
|
161
172
|
value: string[];
|
|
162
|
-
error
|
|
173
|
+
error?: string;
|
|
163
174
|
}) => void;
|
|
164
175
|
};
|
|
165
176
|
declare type Props = SingleSelect | MultipleSelect;
|
|
@@ -172,12 +183,31 @@ export declare type OptionProps = {
|
|
|
172
183
|
onClick: (option: Option) => void;
|
|
173
184
|
multiple: boolean;
|
|
174
185
|
visualFocused: boolean;
|
|
175
|
-
isGroupedOption
|
|
186
|
+
isGroupedOption?: boolean;
|
|
176
187
|
isLastOption: boolean;
|
|
177
188
|
isSelected: boolean;
|
|
178
189
|
};
|
|
179
190
|
/**
|
|
180
|
-
*
|
|
191
|
+
* Listbox from the select component.
|
|
192
|
+
*/
|
|
193
|
+
export declare type ListboxProps = {
|
|
194
|
+
id: string;
|
|
195
|
+
currentValue: string | string[];
|
|
196
|
+
options: Option[] | OptionGroup[];
|
|
197
|
+
visualFocusIndex: number;
|
|
198
|
+
lastOptionIndex: number;
|
|
199
|
+
multiple: boolean;
|
|
200
|
+
optional: boolean;
|
|
201
|
+
optionalItem: Option;
|
|
202
|
+
searchable: boolean;
|
|
203
|
+
handleOptionOnClick: (option: Option) => void;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Reference to the listbox component.
|
|
207
|
+
*/
|
|
208
|
+
export declare type ListboxRefType = HTMLUListElement;
|
|
209
|
+
/**
|
|
210
|
+
* Reference to the select component.
|
|
181
211
|
*/
|
|
182
212
|
export declare type RefType = HTMLDivElement;
|
|
183
213
|
export default Props;
|
package/slider/Slider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import SliderPropsType from "./types";
|
|
3
|
-
declare const DxcSlider: ({ label, name, value, helperText, minValue, maxValue, step, showLimitsValues, showInput, disabled, marks, onChange, onDragEnd, labelFormatCallback, margin, size, }: SliderPropsType) => JSX.Element;
|
|
3
|
+
declare const DxcSlider: ({ label, name, defaultValue, value, helperText, minValue, maxValue, step, showLimitsValues, showInput, disabled, marks, onChange, onDragEnd, labelFormatCallback, margin, size, }: SliderPropsType) => JSX.Element;
|
|
4
4
|
export default DxcSlider;
|
package/slider/Slider.js
CHANGED
|
@@ -44,6 +44,7 @@ var DxcSlider = function DxcSlider(_ref) {
|
|
|
44
44
|
label = _ref$label === void 0 ? "" : _ref$label,
|
|
45
45
|
_ref$name = _ref.name,
|
|
46
46
|
name = _ref$name === void 0 ? "" : _ref$name,
|
|
47
|
+
defaultValue = _ref.defaultValue,
|
|
47
48
|
value = _ref.value,
|
|
48
49
|
_ref$helperText = _ref.helperText,
|
|
49
50
|
helperText = _ref$helperText === void 0 ? "" : _ref$helperText,
|
|
@@ -68,7 +69,7 @@ var DxcSlider = function DxcSlider(_ref) {
|
|
|
68
69
|
_ref$size = _ref.size,
|
|
69
70
|
size = _ref$size === void 0 ? "fillParent" : _ref$size;
|
|
70
71
|
|
|
71
|
-
var _useState = (0, _react.useState)(0),
|
|
72
|
+
var _useState = (0, _react.useState)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : 0),
|
|
72
73
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
73
74
|
innerValue = _useState2[0],
|
|
74
75
|
setInnerValue = _useState2[1];
|
|
@@ -37,7 +37,7 @@ export const Chromatic = () => (
|
|
|
37
37
|
label="Slider"
|
|
38
38
|
helperText="Help message"
|
|
39
39
|
disabled
|
|
40
|
-
|
|
40
|
+
defaultValue={40}
|
|
41
41
|
minValue={0}
|
|
42
42
|
maxValue={50}
|
|
43
43
|
showLimitsValues
|
|
@@ -49,16 +49,16 @@ export const Chromatic = () => (
|
|
|
49
49
|
<Title title="Variants" theme="light" level={2} />
|
|
50
50
|
<ExampleContainer>
|
|
51
51
|
<Title title="Continuous slider" theme="light" level={4} />
|
|
52
|
-
<DxcSlider
|
|
52
|
+
<DxcSlider defaultValue={65} label="Slider" helperText="Help message" showLimitsValues />
|
|
53
53
|
</ExampleContainer>
|
|
54
54
|
<ExampleContainer>
|
|
55
55
|
<Title title="Discrete slider" theme="light" level={4} />
|
|
56
|
-
<DxcSlider
|
|
56
|
+
<DxcSlider defaultValue={20} label="Slider" helperText="Help message" showLimitsValues marks step={5} />
|
|
57
57
|
</ExampleContainer>
|
|
58
58
|
<ExampleContainer>
|
|
59
59
|
<Title title="Discrete slider with input" theme="light" level={4} />
|
|
60
60
|
<DxcSlider
|
|
61
|
-
|
|
61
|
+
defaultValue={20}
|
|
62
62
|
minValue={0}
|
|
63
63
|
maxValue={50}
|
|
64
64
|
label="Slider"
|
|
@@ -94,7 +94,7 @@ export const Chromatic = () => (
|
|
|
94
94
|
label="Slider"
|
|
95
95
|
helperText="Help message"
|
|
96
96
|
disabled
|
|
97
|
-
|
|
97
|
+
defaultValue={40}
|
|
98
98
|
minValue={0}
|
|
99
99
|
maxValue={50}
|
|
100
100
|
showLimitsValues
|
|
@@ -105,16 +105,16 @@ export const Chromatic = () => (
|
|
|
105
105
|
</ExampleContainer>
|
|
106
106
|
<ExampleContainer>
|
|
107
107
|
<Title title="Continuous slider" theme="dark" level={4} />
|
|
108
|
-
<DxcSlider
|
|
108
|
+
<DxcSlider defaultValue={65} label="Slider" helperText="Help message" showLimitsValues />
|
|
109
109
|
</ExampleContainer>
|
|
110
110
|
<ExampleContainer>
|
|
111
111
|
<Title title="Discrete slider" theme="dark" level={4} />
|
|
112
|
-
<DxcSlider
|
|
112
|
+
<DxcSlider defaultValue={20} label="Slider" helperText="Help message" showLimitsValues marks step={5} />
|
|
113
113
|
</ExampleContainer>
|
|
114
114
|
<ExampleContainer>
|
|
115
115
|
<Title title="Discrete slider with input" theme="dark" level={4} />
|
|
116
116
|
<DxcSlider
|
|
117
|
-
|
|
117
|
+
defaultValue={20}
|
|
118
118
|
minValue={0}
|
|
119
119
|
maxValue={50}
|
|
120
120
|
label="Slider"
|
package/slider/Slider.test.js
CHANGED
|
@@ -20,10 +20,25 @@ describe("Slider component tests", function () {
|
|
|
20
20
|
expect(getByText("0")).toBeTruthy();
|
|
21
21
|
expect(getByText("100")).toBeTruthy();
|
|
22
22
|
});
|
|
23
|
+
test("Slider renders with correct initial value when it is uncontrolled", function () {
|
|
24
|
+
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
25
|
+
defaultValue: 30,
|
|
26
|
+
minValue: 0,
|
|
27
|
+
maxValue: 100,
|
|
28
|
+
showLimitsValues: true,
|
|
29
|
+
showInput: true
|
|
30
|
+
})),
|
|
31
|
+
getByRole = _render2.getByRole;
|
|
32
|
+
|
|
33
|
+
var slider = getByRole("slider");
|
|
34
|
+
var input = getByRole("textbox");
|
|
35
|
+
expect(slider.getAttribute("aria-valuenow")).toBe("30");
|
|
36
|
+
expect(input.value).toBe("30");
|
|
37
|
+
});
|
|
23
38
|
test("Calls correct function onChange in controlled slider", function () {
|
|
24
39
|
var onChange = jest.fn();
|
|
25
40
|
|
|
26
|
-
var
|
|
41
|
+
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
27
42
|
minValue: 0,
|
|
28
43
|
maxValue: 100,
|
|
29
44
|
onChange: onChange,
|
|
@@ -31,8 +46,10 @@ describe("Slider component tests", function () {
|
|
|
31
46
|
value: 13,
|
|
32
47
|
showInput: true
|
|
33
48
|
})),
|
|
34
|
-
getByRole =
|
|
49
|
+
getByRole = _render3.getByRole;
|
|
35
50
|
|
|
51
|
+
expect(getByRole("slider").getAttribute("aria-valuenow")).toBe("13");
|
|
52
|
+
expect(getByRole("textbox").value).toBe("13");
|
|
36
53
|
(0, _react2.act)(function () {
|
|
37
54
|
_react2.fireEvent.change(getByRole("textbox"), {
|
|
38
55
|
target: {
|
|
@@ -41,18 +58,20 @@ describe("Slider component tests", function () {
|
|
|
41
58
|
});
|
|
42
59
|
});
|
|
43
60
|
expect(onChange).toHaveBeenCalledWith(25);
|
|
61
|
+
expect(getByRole("slider").getAttribute("aria-valuenow")).toBe("13");
|
|
62
|
+
expect(getByRole("textbox").value).toBe("13");
|
|
44
63
|
});
|
|
45
64
|
test("Calls correct function onChange in uncontrolled slider", function () {
|
|
46
65
|
var onChange = jest.fn();
|
|
47
66
|
|
|
48
|
-
var
|
|
67
|
+
var _render4 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
49
68
|
minValue: 0,
|
|
50
69
|
maxValue: 100,
|
|
51
70
|
onChange: onChange,
|
|
52
71
|
showLimitsValues: true,
|
|
53
72
|
showInput: true
|
|
54
73
|
})),
|
|
55
|
-
getByRole =
|
|
74
|
+
getByRole = _render4.getByRole;
|
|
56
75
|
|
|
57
76
|
(0, _react2.act)(function () {
|
|
58
77
|
_react2.fireEvent.change(getByRole("textbox"), {
|
|
@@ -62,11 +81,13 @@ describe("Slider component tests", function () {
|
|
|
62
81
|
});
|
|
63
82
|
});
|
|
64
83
|
expect(onChange).toHaveBeenCalledWith(25);
|
|
84
|
+
expect(getByRole("slider").getAttribute("aria-valuenow")).toBe("25");
|
|
85
|
+
expect(getByRole("textbox").value).toBe("25");
|
|
65
86
|
});
|
|
66
87
|
test("Disabled slider have disabled input", function () {
|
|
67
88
|
var onChange = jest.fn();
|
|
68
89
|
|
|
69
|
-
var
|
|
90
|
+
var _render5 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
70
91
|
minValue: 0,
|
|
71
92
|
maxValue: 100,
|
|
72
93
|
onChange: onChange,
|
|
@@ -75,7 +96,7 @@ describe("Slider component tests", function () {
|
|
|
75
96
|
showInput: true,
|
|
76
97
|
value: 13
|
|
77
98
|
})),
|
|
78
|
-
getByRole =
|
|
99
|
+
getByRole = _render5.getByRole;
|
|
79
100
|
|
|
80
101
|
(0, _react2.act)(function () {
|
|
81
102
|
_react2.fireEvent.change(getByRole("textbox"), {
|
|
@@ -90,7 +111,7 @@ describe("Slider component tests", function () {
|
|
|
90
111
|
test("Calls correct function onDragEnd", function () {
|
|
91
112
|
var onDragEnd = jest.fn();
|
|
92
113
|
|
|
93
|
-
var
|
|
114
|
+
var _render6 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
94
115
|
minValue: 0,
|
|
95
116
|
maxValue: 100,
|
|
96
117
|
showLimitsValues: true,
|
|
@@ -98,7 +119,7 @@ describe("Slider component tests", function () {
|
|
|
98
119
|
onDragEnd: onDragEnd,
|
|
99
120
|
value: 25
|
|
100
121
|
})),
|
|
101
|
-
getByRole =
|
|
122
|
+
getByRole = _render6.getByRole;
|
|
102
123
|
|
|
103
124
|
(0, _react2.act)(function () {
|
|
104
125
|
_react2.fireEvent.mouseDown(getByRole("slider"));
|
|
@@ -112,7 +133,7 @@ describe("Slider component tests", function () {
|
|
|
112
133
|
return "".concat(x, "$");
|
|
113
134
|
});
|
|
114
135
|
|
|
115
|
-
var
|
|
136
|
+
var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Slider["default"], {
|
|
116
137
|
minValue: 0,
|
|
117
138
|
maxValue: 100,
|
|
118
139
|
showLimitsValues: true,
|
|
@@ -120,7 +141,7 @@ describe("Slider component tests", function () {
|
|
|
120
141
|
value: 25,
|
|
121
142
|
labelFormatCallback: labelFormatCallback
|
|
122
143
|
})),
|
|
123
|
-
getByText =
|
|
144
|
+
getByText = _render7.getByText;
|
|
124
145
|
|
|
125
146
|
expect(getByText("0$")).toBeTruthy();
|
|
126
147
|
expect(getByText("100$")).toBeTruthy();
|
package/slider/types.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ declare type Props = {
|
|
|
14
14
|
* Name attribute of the input element.
|
|
15
15
|
*/
|
|
16
16
|
name?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Initial value of the slider, only when it is uncontrolled.
|
|
19
|
+
*/
|
|
20
|
+
defaultValue?: number;
|
|
17
21
|
/**
|
|
18
22
|
* The selected value. If undefined, the component will be uncontrolled and the value will be managed internally by the component.
|
|
19
23
|
*/
|
package/stack/types.d.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
declare type Props = {
|
|
3
|
+
/**
|
|
4
|
+
* Space applied between each child.
|
|
5
|
+
*/
|
|
3
6
|
gutter?: "none" | "xxxsmall" | "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge" | "xxxlarge";
|
|
7
|
+
/**
|
|
8
|
+
* If true, a divider is shown between children.
|
|
9
|
+
*/
|
|
4
10
|
divider?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Alignment applied to children.
|
|
13
|
+
*/
|
|
5
14
|
align?: "start" | "center" | "end" | "baseline" | "stretch";
|
|
15
|
+
/**
|
|
16
|
+
* Specifies the HTML tag or component that is rendered as the wrapper element.
|
|
17
|
+
*/
|
|
6
18
|
as?: React.ElementType;
|
|
19
|
+
/**
|
|
20
|
+
* Custom content inside the stack.
|
|
21
|
+
*/
|
|
7
22
|
children: React.ReactNode;
|
|
8
23
|
};
|
|
9
24
|
export default Props;
|
package/switch/Switch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import SwitchPropsType from "./types";
|
|
3
|
-
declare const DxcSwitch: ({ checked, value, label, labelPosition, name, disabled,
|
|
3
|
+
declare const DxcSwitch: ({ defaultChecked, checked, value, label, labelPosition, name, disabled, optional, onChange, margin, size, tabIndex, }: SwitchPropsType) => JSX.Element;
|
|
4
4
|
export default DxcSwitch;
|
package/switch/Switch.js
CHANGED
|
@@ -21,7 +21,7 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
|
21
21
|
|
|
22
22
|
var _core = require("@material-ui/core");
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _uuid = require("uuid");
|
|
25
25
|
|
|
26
26
|
var _variables = require("../common/variables.js");
|
|
27
27
|
|
|
@@ -38,7 +38,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
38
38
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
39
39
|
|
|
40
40
|
var DxcSwitch = function DxcSwitch(_ref) {
|
|
41
|
-
var
|
|
41
|
+
var defaultChecked = _ref.defaultChecked,
|
|
42
|
+
checked = _ref.checked,
|
|
42
43
|
value = _ref.value,
|
|
43
44
|
_ref$label = _ref.label,
|
|
44
45
|
label = _ref$label === void 0 ? "" : _ref$label,
|
|
@@ -48,19 +49,25 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
48
49
|
name = _ref$name === void 0 ? "" : _ref$name,
|
|
49
50
|
_ref$disabled = _ref.disabled,
|
|
50
51
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
52
|
+
_ref$optional = _ref.optional,
|
|
53
|
+
optional = _ref$optional === void 0 ? false : _ref$optional,
|
|
51
54
|
onChange = _ref.onChange,
|
|
52
|
-
_ref$required = _ref.required,
|
|
53
|
-
required = _ref$required === void 0 ? false : _ref$required,
|
|
54
55
|
margin = _ref.margin,
|
|
55
56
|
_ref$size = _ref.size,
|
|
56
57
|
size = _ref$size === void 0 ? "fitContent" : _ref$size,
|
|
57
58
|
_ref$tabIndex = _ref.tabIndex,
|
|
58
59
|
tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
|
|
59
60
|
|
|
60
|
-
var _useState = (0, _react.useState)(
|
|
61
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState,
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
var _useState = (0, _react.useState)("switch-".concat((0, _uuid.v4)())),
|
|
62
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 1),
|
|
63
|
+
switchId = _useState2[0];
|
|
64
|
+
|
|
65
|
+
var labelId = "label-".concat(switchId);
|
|
66
|
+
|
|
67
|
+
var _useState3 = (0, _react.useState)(defaultChecked !== null && defaultChecked !== void 0 ? defaultChecked : false),
|
|
68
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
69
|
+
innerChecked = _useState4[0],
|
|
70
|
+
setInnerChecked = _useState4[1];
|
|
64
71
|
|
|
65
72
|
var colorsTheme = (0, _useTheme["default"])();
|
|
66
73
|
var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
|
|
@@ -75,6 +82,14 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
75
82
|
} else onChange === null || onChange === void 0 ? void 0 : onChange(!checked);
|
|
76
83
|
};
|
|
77
84
|
|
|
85
|
+
var labelComponent = /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
86
|
+
id: labelId,
|
|
87
|
+
labelPosition: labelPosition,
|
|
88
|
+
onClick: !disabled && handlerSwitchChange,
|
|
89
|
+
disabled: disabled,
|
|
90
|
+
backgroundType: backgroundType
|
|
91
|
+
}, labelPosition === "before" ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, label, " ", optional && /*#__PURE__*/_react["default"].createElement("span", null, "(Optional)")) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, optional && /*#__PURE__*/_react["default"].createElement("span", null, "(Optional)"), " ", label));
|
|
92
|
+
|
|
78
93
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
79
94
|
theme: colorsTheme["switch"]
|
|
80
95
|
}, /*#__PURE__*/_react["default"].createElement(SwitchContainer, {
|
|
@@ -83,22 +98,20 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
83
98
|
labelPosition: labelPosition,
|
|
84
99
|
size: size,
|
|
85
100
|
backgroundType: backgroundType
|
|
86
|
-
}, /*#__PURE__*/_react["default"].createElement(_core.Switch, {
|
|
101
|
+
}, labelPosition === "before" && labelComponent, /*#__PURE__*/_react["default"].createElement(_core.Switch, {
|
|
87
102
|
checked: checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
88
103
|
inputProps: {
|
|
89
104
|
name: name,
|
|
105
|
+
"aria-labelledby": labelId,
|
|
106
|
+
role: "switch",
|
|
107
|
+
"aria-checked": checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
90
108
|
tabIndex: tabIndex
|
|
91
109
|
},
|
|
92
110
|
onChange: handlerSwitchChange,
|
|
93
111
|
value: value,
|
|
94
112
|
disabled: disabled,
|
|
95
113
|
disableRipple: true
|
|
96
|
-
}),
|
|
97
|
-
labelPosition: labelPosition,
|
|
98
|
-
onClick: !disabled && handlerSwitchChange,
|
|
99
|
-
disabled: disabled,
|
|
100
|
-
backgroundType: backgroundType
|
|
101
|
-
}, required && /*#__PURE__*/_react["default"].createElement(_RequiredComponent["default"], null), label)));
|
|
114
|
+
}), labelPosition === "after" && labelComponent));
|
|
102
115
|
};
|
|
103
116
|
|
|
104
117
|
var sizes = {
|
|
@@ -113,10 +126,8 @@ var calculateWidth = function calculateWidth(margin, size) {
|
|
|
113
126
|
return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
|
|
114
127
|
};
|
|
115
128
|
|
|
116
|
-
var SwitchContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n width: ", ";\n display: inline-flex;\n align-items: center;\n
|
|
129
|
+
var SwitchContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n width: ", ";\n display: inline-flex;\n align-items: center;\n\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n cursor: ", ";\n\n .MuiSwitch-root {\n align-items: center;\n width: ", ";\n height: 45px;\n margin: 3px;\n\n .Mui-focusVisible {\n outline: ", ";\n outline-offset: -3px;\n }\n\n .MuiSwitch-track {\n /*Enabled and unchecked bar*/\n background-color: ", ";\n height: ", ";\n }\n\n .MuiSwitch-switchBase + .MuiSwitch-track {\n opacity: 1;\n }\n\n .MuiIconButton-root {\n /*Enabled and unchecked*/\n top: unset;\n .MuiSwitch-thumb {\n /*Only for thumb in all states*/\n width: ", ";\n height: ", ";\n }\n color: ", ";\n &:hover {\n background-color: transparent;\n }\n &.Mui-disabled {\n /*Disabled and unchecked*/\n color: ", ";\n + .MuiSwitch-track {\n /*Disabled and unchecked bar*/\n background-color: ", ";\n }\n }\n &.Mui-disabled.Mui-checked {\n /*Disabled and checked*/\n color: ", ";\n + .MuiSwitch-track {\n /*Disabled and checked bar*/\n background-color: ", ";\n }\n }\n &.Mui-checked {\n /*Enabled and checked*/\n color: ", ";\n transform: translateX(", ");\n &:hover {\n background-color: transparent;\n }\n + .MuiSwitch-track {\n /*Enabled and checked bar*/\n background-color: ", ";\n }\n }\n }\n }\n"])), function (props) {
|
|
117
130
|
return calculateWidth(props.margin, props.size);
|
|
118
|
-
}, function (props) {
|
|
119
|
-
return props.labelPosition === "after" ? "row" : "row-reverse";
|
|
120
131
|
}, function (props) {
|
|
121
132
|
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
122
133
|
}, function (props) {
|
|
@@ -159,7 +170,7 @@ var SwitchContainer = _styledComponents["default"].div(_templateObject || (_temp
|
|
|
159
170
|
return props.backgroundType === "dark" ? props.theme.checkedTrackBackgroundColorOnDark : props.theme.checkedTrackBackgroundColor;
|
|
160
171
|
});
|
|
161
172
|
|
|
162
|
-
var LabelContainer = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: ", ";\n opacity: 1;\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n cursor: ", ";\n ", "\n"])), function (props) {
|
|
173
|
+
var LabelContainer = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: ", ";\n opacity: 1;\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n cursor: ", ";\n ", "\n\n ", "\n"])), function (props) {
|
|
163
174
|
return props.disabled ? props.backgroundType === "dark" ? props.theme.disabledLabelFontColorOnDark : props.theme.disabledLabelFontColor : props.backgroundType === "dark" ? props.theme.labelFontColorOnDark : props.theme.labelFontColor;
|
|
164
175
|
}, function (props) {
|
|
165
176
|
return props.theme.labelFontFamily;
|
|
@@ -173,6 +184,8 @@ var LabelContainer = _styledComponents["default"].span(_templateObject2 || (_tem
|
|
|
173
184
|
return props.disabled === true ? "not-allowed" : "pointer";
|
|
174
185
|
}, function (props) {
|
|
175
186
|
return props.labelPosition === "after" ? "margin-left: ".concat(props.theme.spaceBetweenLabelSwitch, ";") : "margin-right: ".concat(props.theme.spaceBetweenLabelSwitch, ";");
|
|
187
|
+
}, function (props) {
|
|
188
|
+
return props.labelPosition === "before" && "order: -1";
|
|
176
189
|
});
|
|
177
190
|
|
|
178
191
|
var _default = DxcSwitch;
|
|
@@ -23,23 +23,23 @@ export const Chromatic = () => (
|
|
|
23
23
|
</ExampleContainer>
|
|
24
24
|
<ExampleContainer>
|
|
25
25
|
<Title title="Checked" theme="light" level={4} />
|
|
26
|
-
<DxcSwitch label="Switch"
|
|
26
|
+
<DxcSwitch label="Switch" defaultChecked />
|
|
27
27
|
</ExampleContainer>
|
|
28
28
|
<ExampleContainer>
|
|
29
|
-
<Title title="
|
|
30
|
-
<DxcSwitch label="Switch"
|
|
29
|
+
<Title title="Optional" theme="light" level={4} />
|
|
30
|
+
<DxcSwitch label="Switch" optional />
|
|
31
31
|
</ExampleContainer>
|
|
32
32
|
<ExampleContainer>
|
|
33
33
|
<Title title="Disabled" theme="light" level={4} />
|
|
34
34
|
<DxcSwitch label="Switch" disabled />
|
|
35
35
|
</ExampleContainer>
|
|
36
36
|
<ExampleContainer>
|
|
37
|
-
<Title title="Disabled
|
|
38
|
-
<DxcSwitch label="Switch" disabled
|
|
37
|
+
<Title title="Disabled optional" theme="light" level={4} />
|
|
38
|
+
<DxcSwitch label="Switch" disabled optional labelPosition="after" />
|
|
39
39
|
</ExampleContainer>
|
|
40
40
|
<ExampleContainer>
|
|
41
41
|
<Title title="Disabled checked" theme="light" level={4} />
|
|
42
|
-
<DxcSwitch label="Switch" disabled
|
|
42
|
+
<DxcSwitch label="Switch" disabled defaultChecked labelPosition="after" />
|
|
43
43
|
</ExampleContainer>
|
|
44
44
|
<BackgroundColorProvider color="#333333">
|
|
45
45
|
<DarkContainer>
|
|
@@ -49,23 +49,23 @@ export const Chromatic = () => (
|
|
|
49
49
|
</ExampleContainer>
|
|
50
50
|
<ExampleContainer>
|
|
51
51
|
<Title title="Checked" theme="dark" level={4} />
|
|
52
|
-
<DxcSwitch label="Switch"
|
|
52
|
+
<DxcSwitch label="Switch" defaultChecked />
|
|
53
53
|
</ExampleContainer>
|
|
54
54
|
<ExampleContainer>
|
|
55
|
-
<Title title="
|
|
56
|
-
<DxcSwitch label="Switch"
|
|
55
|
+
<Title title="Optional" theme="dark" level={4} />
|
|
56
|
+
<DxcSwitch label="Switch" optional />
|
|
57
57
|
</ExampleContainer>
|
|
58
58
|
<ExampleContainer>
|
|
59
59
|
<Title title="Disabled" theme="dark" level={4} />
|
|
60
60
|
<DxcSwitch label="Switch" disabled />
|
|
61
61
|
</ExampleContainer>
|
|
62
62
|
<ExampleContainer>
|
|
63
|
-
<Title title="Disabled
|
|
64
|
-
<DxcSwitch label="Switch" disabled
|
|
63
|
+
<Title title="Disabled optional" theme="dark" level={4} />
|
|
64
|
+
<DxcSwitch label="Switch" disabled optional labelPosition="after" />
|
|
65
65
|
</ExampleContainer>
|
|
66
66
|
<ExampleContainer>
|
|
67
67
|
<Title title="Disabled checked" theme="dark" level={4} />
|
|
68
|
-
<DxcSwitch label="Switch" disabled
|
|
68
|
+
<DxcSwitch label="Switch" disabled defaultChecked labelPosition="after" />
|
|
69
69
|
</ExampleContainer>
|
|
70
70
|
</DarkContainer>
|
|
71
71
|
</BackgroundColorProvider>
|
|
@@ -139,7 +139,7 @@ const Switch = () => (
|
|
|
139
139
|
export const FocusedSwitch = Switch.bind({});
|
|
140
140
|
FocusedSwitch.play = async ({ canvasElement }) => {
|
|
141
141
|
const canvas = within(canvasElement);
|
|
142
|
-
canvas.getByRole("
|
|
142
|
+
canvas.getByRole("switch").focus();
|
|
143
143
|
};
|
|
144
144
|
|
|
145
145
|
const DarkSwitch = () => (
|
|
@@ -156,5 +156,5 @@ const DarkSwitch = () => (
|
|
|
156
156
|
export const FocusedSwitchOnDark = DarkSwitch.bind({});
|
|
157
157
|
FocusedSwitchOnDark.play = async ({ canvasElement }) => {
|
|
158
158
|
const canvas = within(canvasElement);
|
|
159
|
-
canvas.getByRole("
|
|
159
|
+
canvas.getByRole("switch").focus();
|
|
160
160
|
};
|
package/switch/Switch.test.js
CHANGED
|
@@ -70,4 +70,29 @@ describe("Switch component tests", function () {
|
|
|
70
70
|
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
71
71
|
expect(onChange.mock.calls[1][0]).toBe(false);
|
|
72
72
|
});
|
|
73
|
+
test("Renders with correct initial value and initial state when it is uncontrolled", function () {
|
|
74
|
+
var _render5 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
75
|
+
label: "Default label",
|
|
76
|
+
defaultChecked: true,
|
|
77
|
+
value: "test-defaultChecked"
|
|
78
|
+
})),
|
|
79
|
+
getByRole = _render5.getByRole;
|
|
80
|
+
|
|
81
|
+
var inputEl = getByRole("switch");
|
|
82
|
+
expect(inputEl.checked).toBe(true);
|
|
83
|
+
expect(inputEl.value).toBe("test-defaultChecked");
|
|
84
|
+
expect(inputEl.getAttribute("aria-checked")).toBe("true");
|
|
85
|
+
});
|
|
86
|
+
test("Renders with correct aria attributes", function () {
|
|
87
|
+
var _render6 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
88
|
+
label: "Default label"
|
|
89
|
+
})),
|
|
90
|
+
getByRole = _render6.getByRole,
|
|
91
|
+
getByText = _render6.getByText;
|
|
92
|
+
|
|
93
|
+
var inputEl = getByRole("switch");
|
|
94
|
+
var label = getByText("Default label");
|
|
95
|
+
expect(inputEl.getAttribute("aria-labelledby")).toBe(label.id);
|
|
96
|
+
expect(inputEl.getAttribute("aria-checked")).toBe("false");
|
|
97
|
+
});
|
|
73
98
|
});
|
package/switch/types.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ declare type Margin = {
|
|
|
6
6
|
right?: Space;
|
|
7
7
|
};
|
|
8
8
|
declare type Props = {
|
|
9
|
+
/**
|
|
10
|
+
* Initial state of the switch, only when it is uncontrolled.
|
|
11
|
+
*/
|
|
12
|
+
defaultChecked?: boolean;
|
|
9
13
|
/**
|
|
10
14
|
* If true, the component is checked. If undefined, the component will be uncontrolled
|
|
11
15
|
* and the checked attribute will be managed internally by the component.
|
|
@@ -38,9 +42,9 @@ declare type Props = {
|
|
|
38
42
|
*/
|
|
39
43
|
onChange?: (checked: boolean) => void;
|
|
40
44
|
/**
|
|
41
|
-
* If true, the
|
|
45
|
+
* If true, the component will display '(Optional)' next to the label.
|
|
42
46
|
*/
|
|
43
|
-
|
|
47
|
+
optional?: boolean;
|
|
44
48
|
/**
|
|
45
49
|
* Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
|
|
46
50
|
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
|
package/tabs/Tabs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import TabsPropsType from "./types";
|
|
3
|
-
declare const DxcTabs: ({ activeTabIndex, tabs, onTabClick, onTabHover, margin, iconPosition, tabIndex, }: TabsPropsType) => JSX.Element;
|
|
3
|
+
declare const DxcTabs: ({ defaultActiveTabIndex, activeTabIndex, tabs, onTabClick, onTabHover, margin, iconPosition, tabIndex, }: TabsPropsType) => JSX.Element;
|
|
4
4
|
export default DxcTabs;
|