carbon-react 95.1.2 → 97.0.0
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/lib/components/multi-action-button/multi-action-button.component.js +2 -2
- package/lib/components/multi-action-button/multi-action-button.config.js +1 -1
- package/lib/components/multi-action-button/multi-action-button.d.ts +4 -1
- package/lib/components/pod/pod.d.ts +3 -1
- package/lib/components/select/filterable-select/filterable-select.component.js +25 -10
- package/lib/components/select/multi-select/multi-select.component.js +13 -16
- package/lib/components/select/simple-select/simple-select.component.js +6 -4
- package/lib/components/select/simple-select/simple-select.d.ts +1 -1
- package/lib/components/select/utils/is-expected-option.js +8 -0
- package/lib/components/show-edit-pod/show-edit-pod-test.stories.js +165 -0
- package/lib/components/show-edit-pod/show-edit-pod.component.js +154 -223
- package/lib/components/show-edit-pod/show-edit-pod.d.ts +3 -1
- package/lib/components/textarea/textarea-test.stories.js +153 -0
- package/lib/components/textarea/textarea.component.js +144 -215
- package/lib/components/textarea/textarea.d.ts +1 -1
- package/package.json +11 -5
- package/scripts/check_carbon_version.js +30 -0
- package/scripts/check_rfcs.js +49 -0
|
@@ -212,8 +212,8 @@ const MultiActionButton = ({
|
|
|
212
212
|
|
|
213
213
|
MultiActionButton.propTypes = { ...marginPropTypes,
|
|
214
214
|
|
|
215
|
-
/** Button type: "primary" | "secondary"
|
|
216
|
-
buttonType: _propTypes.default.oneOf(["primary", "secondary"]),
|
|
215
|
+
/** Button type: "primary" | "secondary" | "tertiary" */
|
|
216
|
+
buttonType: _propTypes.default.oneOf(["primary", "secondary", "tertiary"]),
|
|
217
217
|
|
|
218
218
|
/** The additional button to display. */
|
|
219
219
|
children: _propTypes.default.node.isRequired,
|
|
@@ -8,5 +8,5 @@ const MULTI_ACTION_BUTTON_ALIGNMENTS = ["left", "right"];
|
|
|
8
8
|
exports.MULTI_ACTION_BUTTON_ALIGNMENTS = MULTI_ACTION_BUTTON_ALIGNMENTS;
|
|
9
9
|
const MULTI_ACTION_BUTTON_SIZES = ["small", "medium", "large"];
|
|
10
10
|
exports.MULTI_ACTION_BUTTON_SIZES = MULTI_ACTION_BUTTON_SIZES;
|
|
11
|
-
const MULTI_ACTION_BUTTON_THEMES = ["primary", "secondary"];
|
|
11
|
+
const MULTI_ACTION_BUTTON_THEMES = ["primary", "secondary", "tertiary"];
|
|
12
12
|
exports.MULTI_ACTION_BUTTON_THEMES = MULTI_ACTION_BUTTON_THEMES;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import SplitButton from "../split-button";
|
|
2
2
|
|
|
3
|
-
declare class MultiActionButton extends SplitButton {
|
|
3
|
+
declare class MultiActionButton extends SplitButton {
|
|
4
|
+
/** Button type: "primary" | "secondary" | "tertiary" */
|
|
5
|
+
buttonType?: "primary" | "secondary" | "tertiary";
|
|
6
|
+
}
|
|
4
7
|
|
|
5
8
|
export default MultiActionButton;
|
|
@@ -78,7 +78,7 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
78
78
|
const [textboxRef, setTextboxRef] = (0, _react.useState)();
|
|
79
79
|
const [isOpen, setOpen] = (0, _react.useState)(false);
|
|
80
80
|
const [textValue, setTextValue] = (0, _react.useState)("");
|
|
81
|
-
const [selectedValue, setSelectedValue] = (0, _react.useState)("");
|
|
81
|
+
const [selectedValue, setSelectedValue] = (0, _react.useState)(value || defaultValue || "");
|
|
82
82
|
const [highlightedValue, setHighlightedValue] = (0, _react.useState)("");
|
|
83
83
|
const [filterText, setFilterText] = (0, _react.useState)("");
|
|
84
84
|
const createCustomEvent = (0, _react.useCallback)(newValue => {
|
|
@@ -187,21 +187,33 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
187
187
|
}
|
|
188
188
|
}, [setMatchingText, selectedValue]);
|
|
189
189
|
(0, _react.useEffect)(() => {
|
|
190
|
-
const newValue = value || defaultValue;
|
|
191
190
|
const modeSwitchedMessage = "Input elements should not switch from uncontrolled to controlled (or vice versa). " + "Decide between using a controlled or uncontrolled input element for the lifetime of the component";
|
|
192
191
|
const onChangeMissingMessage = "onChange prop required when using a controlled input element";
|
|
193
192
|
(0, _invariant.default)(isControlled.current === (value !== undefined), modeSwitchedMessage);
|
|
194
193
|
(0, _invariant.default)(!isControlled.current || isControlled.current && onChange, onChangeMissingMessage);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
|
|
195
|
+
if (isControlled.current) {
|
|
196
|
+
setSelectedValue(prevValue => {
|
|
197
|
+
if (value && prevValue !== value) {
|
|
198
|
+
setMatchingText(value);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return value;
|
|
202
|
+
});
|
|
203
|
+
setHighlightedValue(value);
|
|
204
|
+
} else {
|
|
205
|
+
if (textValue !== selectedValue) {
|
|
206
|
+
setMatchingText(selectedValue);
|
|
198
207
|
}
|
|
199
208
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
209
|
+
if (highlightedValue !== selectedValue) {
|
|
210
|
+
setHighlightedValue(selectedValue);
|
|
211
|
+
}
|
|
212
|
+
} // prevent value update on filter change
|
|
213
|
+
// selectedValue and highlightedValue omitted from deps, only want uncontrolled change if onChange/children update
|
|
203
214
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
204
|
-
|
|
215
|
+
|
|
216
|
+
}, [value, onChange, children]);
|
|
205
217
|
(0, _react.useEffect)(() => {
|
|
206
218
|
if (!isOpen) {
|
|
207
219
|
setFilterText("");
|
|
@@ -215,8 +227,11 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
215
227
|
(0, _invariant.default)(!hasListActionButton || hasListActionButton && onListAction, onListActionMissingMessage);
|
|
216
228
|
}, [listActionButton, onListAction]);
|
|
217
229
|
(0, _react.useEffect)(() => {
|
|
218
|
-
|
|
230
|
+
if (isControlled.current) {
|
|
231
|
+
setMatchingText(value);
|
|
232
|
+
} // update text value only when children are changing
|
|
219
233
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
234
|
+
|
|
220
235
|
}, [value, children]);
|
|
221
236
|
(0, _react.useEffect)(() => {
|
|
222
237
|
if (onFilterChange) {
|
|
@@ -82,7 +82,7 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
82
82
|
const [textboxRef, setTextboxRef] = (0, _react.useState)();
|
|
83
83
|
const [isOpen, setOpenState] = (0, _react.useState)(false);
|
|
84
84
|
const [textValue, setTextValue] = (0, _react.useState)("");
|
|
85
|
-
const [selectedValue, setSelectedValue] = (0, _react.useState)([]);
|
|
85
|
+
const [selectedValue, setSelectedValue] = (0, _react.useState)(value || defaultValue || []);
|
|
86
86
|
const [highlightedValue, setHighlightedValue] = (0, _react.useState)("");
|
|
87
87
|
const [filterText, setFilterText] = (0, _react.useState)("");
|
|
88
88
|
const [placeholderOverride, setPlaceholderOverride] = (0, _react.useState)();
|
|
@@ -124,7 +124,7 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
124
124
|
setSelectedValue(previousValue => {
|
|
125
125
|
isClickTriggeredBySelect.current = true;
|
|
126
126
|
|
|
127
|
-
if (previousValue.length
|
|
127
|
+
if (!previousValue.length) {
|
|
128
128
|
return previousValue;
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -185,7 +185,7 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
185
185
|
const mapValuesToPills = (0, _react.useCallback)(() => {
|
|
186
186
|
const canDelete = !disabled && !readOnly;
|
|
187
187
|
|
|
188
|
-
if (selectedValue.length
|
|
188
|
+
if (!selectedValue.length) {
|
|
189
189
|
return "";
|
|
190
190
|
}
|
|
191
191
|
|
|
@@ -205,31 +205,28 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
205
205
|
const {
|
|
206
206
|
title
|
|
207
207
|
} = pillProps;
|
|
208
|
+
const key = title + ((matchingOption === null || matchingOption === void 0 ? void 0 : matchingOption.props.value) || index);
|
|
208
209
|
return /*#__PURE__*/_react.default.createElement(_multiSelect.StyledSelectPillContainer, {
|
|
209
|
-
key:
|
|
210
|
+
key: key
|
|
210
211
|
}, /*#__PURE__*/_react.default.createElement(_pill.default, _extends({
|
|
211
212
|
onDelete: canDelete ? () => removeSelectedValue(index) : undefined
|
|
212
213
|
}, pillProps), title));
|
|
213
214
|
}); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
214
215
|
}, [children, disabled, readOnly, selectedValue]);
|
|
215
216
|
(0, _react.useEffect)(() => {
|
|
216
|
-
const newValue = value || defaultValue;
|
|
217
217
|
const modeSwitchedMessage = "Input elements should not switch from uncontrolled to controlled (or vice versa). " + "Decide between using a controlled or uncontrolled input element for the lifetime of the component";
|
|
218
|
-
const
|
|
218
|
+
const onChangeMissingMessage = "onChange prop required when using a controlled input element";
|
|
219
219
|
(0, _invariant.default)(isControlled.current === (value !== undefined), modeSwitchedMessage);
|
|
220
|
-
(0, _invariant.default)(!isControlled.current || isControlled.current && onChange,
|
|
221
|
-
setSelectedValue(previousValue => {
|
|
222
|
-
if (!newValue && previousValue.length === 0) {
|
|
223
|
-
return previousValue;
|
|
224
|
-
}
|
|
220
|
+
(0, _invariant.default)(!isControlled.current || isControlled.current && onChange, onChangeMissingMessage);
|
|
225
221
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
222
|
+
if (isControlled.current) {
|
|
223
|
+
setSelectedValue(value);
|
|
224
|
+
}
|
|
225
|
+
}, [value, onChange]); // removes placeholder when a value is present
|
|
229
226
|
|
|
230
227
|
(0, _react.useEffect)(() => {
|
|
231
|
-
const hasValue = value
|
|
232
|
-
const hasSelectedValue = selectedValue
|
|
228
|
+
const hasValue = value === null || value === void 0 ? void 0 : value.length;
|
|
229
|
+
const hasSelectedValue = selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.length;
|
|
233
230
|
|
|
234
231
|
if (hasValue || hasSelectedValue) {
|
|
235
232
|
setPlaceholderOverride(" ");
|
|
@@ -77,7 +77,7 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
77
77
|
const [textboxRef, setTextboxRef] = (0, _react.useState)();
|
|
78
78
|
const [isOpen, setOpenState] = (0, _react.useState)(false);
|
|
79
79
|
const [textValue, setTextValue] = (0, _react.useState)("");
|
|
80
|
-
const [selectedValue, setSelectedValue] = (0, _react.useState)("");
|
|
80
|
+
const [selectedValue, setSelectedValue] = (0, _react.useState)(value || defaultValue || "");
|
|
81
81
|
const childOptions = (0, _react.useMemo)(() => _react.default.Children.toArray(children), [children]);
|
|
82
82
|
const createCustomEvent = (0, _react.useCallback)(newValue => {
|
|
83
83
|
const customEvent = {
|
|
@@ -176,13 +176,15 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
176
176
|
isClickTriggeredBySelect.current = false;
|
|
177
177
|
}, []);
|
|
178
178
|
(0, _react.useEffect)(() => {
|
|
179
|
-
const newValue = value || defaultValue;
|
|
180
179
|
const modeSwitchedMessage = "Input elements should not switch from uncontrolled to controlled (or vice versa). " + "Decide between using a controlled or uncontrolled input element for the lifetime of the component";
|
|
181
180
|
const onChangeMissingMessage = "onChange prop required when using a controlled input element";
|
|
182
181
|
(0, _invariant.default)(isControlled.current === (value !== undefined), modeSwitchedMessage);
|
|
183
182
|
(0, _invariant.default)(!isControlled.current || isControlled.current && onChange, onChangeMissingMessage);
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
|
|
184
|
+
if (isControlled.current) {
|
|
185
|
+
setSelectedValue(value);
|
|
186
|
+
}
|
|
187
|
+
}, [value, onChange]);
|
|
186
188
|
(0, _react.useEffect)(() => {
|
|
187
189
|
const matchingOption = childOptions.find(child => (0, _isExpectedOption.default)(child, selectedValue));
|
|
188
190
|
let newText = "";
|
|
@@ -22,5 +22,13 @@ function isExpectedOption(element, expectedValue) {
|
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
const {
|
|
26
|
+
length
|
|
27
|
+
} = typeof expectedValue === "string" ? expectedValue : Object.keys(expectedValue);
|
|
28
|
+
|
|
29
|
+
if (!length) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
return (0, _isExpectedValue.default)(element.props.value, expectedValue);
|
|
26
34
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Default = exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _addonActions = require("@storybook/addon-actions");
|
|
11
|
+
|
|
12
|
+
var _showEditPod = _interopRequireDefault(require("./show-edit-pod.component"));
|
|
13
|
+
|
|
14
|
+
var _content = _interopRequireDefault(require("../content"));
|
|
15
|
+
|
|
16
|
+
var _specialCharacters = _interopRequireDefault(require("../../../.storybook/utils/argTypes/specialCharacters"));
|
|
17
|
+
|
|
18
|
+
var _textbox = _interopRequireDefault(require("../textbox"));
|
|
19
|
+
|
|
20
|
+
var _fieldset = _interopRequireDefault(require("../fieldset"));
|
|
21
|
+
|
|
22
|
+
var _showEditPod2 = require("./show-edit-pod.config");
|
|
23
|
+
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
+
|
|
26
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
27
|
+
|
|
28
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
29
|
+
|
|
30
|
+
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); }
|
|
31
|
+
|
|
32
|
+
var _default = {
|
|
33
|
+
component: _showEditPod.default,
|
|
34
|
+
title: "ShowEditPod/Test",
|
|
35
|
+
parameters: {
|
|
36
|
+
info: {
|
|
37
|
+
disable: true
|
|
38
|
+
},
|
|
39
|
+
chromatic: {
|
|
40
|
+
disable: true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
argTypes: {
|
|
44
|
+
buttonAlign: {
|
|
45
|
+
options: _showEditPod2.SHOW_EDIT_POD_ALIGNMENTS,
|
|
46
|
+
control: {
|
|
47
|
+
type: "select"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
variant: {
|
|
51
|
+
options: _showEditPod2.SHOW_EDIT_POD_THEMES,
|
|
52
|
+
control: {
|
|
53
|
+
type: "select"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
cancelTextSpecialCharacters: _specialCharacters.default,
|
|
57
|
+
deleteTextSpecialCharacters: _specialCharacters.default,
|
|
58
|
+
saveTextSpecialCharacters: _specialCharacters.default,
|
|
59
|
+
titleSpecialCharacters: _specialCharacters.default
|
|
60
|
+
},
|
|
61
|
+
args: {
|
|
62
|
+
border: false,
|
|
63
|
+
buttonAlign: "right",
|
|
64
|
+
cancel: true,
|
|
65
|
+
cancelText: "Cancel",
|
|
66
|
+
cancelTextSpecialCharacters: undefined,
|
|
67
|
+
deleteText: "Delete",
|
|
68
|
+
deleteTextSpecialCharacters: undefined,
|
|
69
|
+
saveText: "Save",
|
|
70
|
+
saveTextSpecialCharacters: undefined,
|
|
71
|
+
saving: false,
|
|
72
|
+
title: "Person",
|
|
73
|
+
titleSpecialCharacters: undefined,
|
|
74
|
+
transitionName: "carbon-show-edit-pod__transition",
|
|
75
|
+
variant: "transparent"
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
exports.default = _default;
|
|
79
|
+
|
|
80
|
+
const ShowEditPodStory = ({
|
|
81
|
+
cancelTextSpecialCharacters,
|
|
82
|
+
cancelText,
|
|
83
|
+
deleteTextSpecialCharacters,
|
|
84
|
+
deleteText,
|
|
85
|
+
saveTextSpecialCharacters,
|
|
86
|
+
saveText,
|
|
87
|
+
titleSpecialCharacters,
|
|
88
|
+
title,
|
|
89
|
+
...args
|
|
90
|
+
}) => {
|
|
91
|
+
const [isEditing, setIsEditing] = (0, _react.useState)(false);
|
|
92
|
+
const [state, setState] = (0, _react.useState)({
|
|
93
|
+
edit_first_name: "Alan",
|
|
94
|
+
edit_second_name: "Smith",
|
|
95
|
+
edit_telephone: "000 000 0000"
|
|
96
|
+
});
|
|
97
|
+
const fieldProps = [{
|
|
98
|
+
key: "edit_first_name",
|
|
99
|
+
label: "First Name"
|
|
100
|
+
}, {
|
|
101
|
+
key: "edit_second_name",
|
|
102
|
+
label: "Second Name"
|
|
103
|
+
}, {
|
|
104
|
+
key: "edit_telephone",
|
|
105
|
+
label: "Telephone"
|
|
106
|
+
}];
|
|
107
|
+
|
|
108
|
+
const onEdit = () => {
|
|
109
|
+
setIsEditing(true);
|
|
110
|
+
(0, _addonActions.action)("edit")();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const onCancel = () => {
|
|
114
|
+
setIsEditing(false);
|
|
115
|
+
(0, _addonActions.action)("cancel")();
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const onDelete = () => {
|
|
119
|
+
setIsEditing(false);
|
|
120
|
+
(0, _addonActions.action)("delete")();
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const onSave = () => {
|
|
124
|
+
setIsEditing(false);
|
|
125
|
+
(0, _addonActions.action)("onSave")();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const setField = fieldName => e => {
|
|
129
|
+
setState({ ...state,
|
|
130
|
+
[fieldName]: e.target.value
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return /*#__PURE__*/_react.default.createElement(_showEditPod.default, _extends({}, args, {
|
|
135
|
+
editing: isEditing,
|
|
136
|
+
onDelete: onDelete,
|
|
137
|
+
onCancel: onCancel,
|
|
138
|
+
onEdit: onEdit,
|
|
139
|
+
editFields: /*#__PURE__*/_react.default.createElement(_fieldset.default, null, fieldProps.map(({
|
|
140
|
+
key,
|
|
141
|
+
label
|
|
142
|
+
}) => /*#__PURE__*/_react.default.createElement(_textbox.default, {
|
|
143
|
+
label: label,
|
|
144
|
+
key: key,
|
|
145
|
+
onChange: setField(key),
|
|
146
|
+
value: state[key],
|
|
147
|
+
labelInline: true,
|
|
148
|
+
labelAlign: "right"
|
|
149
|
+
}))),
|
|
150
|
+
onSave: onSave,
|
|
151
|
+
cancelText: cancelTextSpecialCharacters || cancelText,
|
|
152
|
+
deleteText: deleteTextSpecialCharacters || deleteText,
|
|
153
|
+
saveText: saveTextSpecialCharacters || saveText,
|
|
154
|
+
title: titleSpecialCharacters || title
|
|
155
|
+
}), fieldProps.map(({
|
|
156
|
+
key,
|
|
157
|
+
label
|
|
158
|
+
}) => /*#__PURE__*/_react.default.createElement(_content.default, {
|
|
159
|
+
key: key,
|
|
160
|
+
title: label
|
|
161
|
+
}, state[key])));
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const Default = ShowEditPodStory.bind({});
|
|
165
|
+
exports.Default = Default;
|