carbon-react 95.1.0 → 96.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/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/tabs/__internal__/tab-title/tab-title.style.js +13 -7
- package/lib/components/tabs/__internal__/tabs-header/tabs-header.style.js +2 -3
- package/lib/components/tabs/tabs.component.js +9 -2
- package/package.json +9 -3
- package/scripts/check_carbon_version.js +30 -0
- package/scripts/check_rfcs.js +49 -0
|
@@ -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;
|
|
@@ -5,20 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.BaseShowEditPod = exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
12
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
13
|
-
|
|
14
12
|
var _reactTransitionGroup = require("react-transition-group");
|
|
15
13
|
|
|
16
14
|
var _propTypes2 = _interopRequireDefault(require("@styled-system/prop-types"));
|
|
17
15
|
|
|
18
16
|
var _utils = require("../../style/utils");
|
|
19
17
|
|
|
20
|
-
var _pod = _interopRequireDefault(require("../pod"));
|
|
21
|
-
|
|
22
18
|
var _form = _interopRequireDefault(require("../form"));
|
|
23
19
|
|
|
24
20
|
var _button = _interopRequireDefault(require("../button"));
|
|
@@ -27,8 +23,6 @@ var _deleteButton = _interopRequireDefault(require("./delete-button.style"));
|
|
|
27
23
|
|
|
28
24
|
var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
|
|
29
25
|
|
|
30
|
-
var _ether = require("../../__internal__/utils/ether");
|
|
31
|
-
|
|
32
26
|
var _tags = _interopRequireDefault(require("../../__internal__/utils/helpers/tags/tags"));
|
|
33
27
|
|
|
34
28
|
var _i18nContext = _interopRequireDefault(require("../../__internal__/i18n-context"));
|
|
@@ -37,230 +31,173 @@ var _showEditPod = _interopRequireDefault(require("./show-edit-pod.style"));
|
|
|
37
31
|
|
|
38
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
33
|
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
43
|
-
|
|
44
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
45
|
-
|
|
46
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
47
|
-
|
|
48
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
34
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
49
35
|
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
53
|
-
|
|
54
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
55
|
-
|
|
56
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
57
|
-
|
|
58
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
59
|
-
|
|
60
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
61
|
-
|
|
62
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
36
|
+
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; }
|
|
63
37
|
|
|
64
38
|
const marginPropTypes = (0, _utils.filterStyledSystemMarginProps)(_propTypes2.default.space);
|
|
65
39
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
_this.props.onCancel(ev);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_this.toggleEditingState(false);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
_defineProperty(_assertThisInitialized(_this), "toggleEditingState", newState => {
|
|
109
|
-
if (!_this.isControlled) {
|
|
110
|
-
_this.setState({
|
|
111
|
-
editing: newState
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
_defineProperty(_assertThisInitialized(_this), "onKeyDown", ev => {
|
|
117
|
-
if (_events.default.isEscKey(ev)) {
|
|
118
|
-
_this.onCancelEditForm(ev);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
_defineProperty(_assertThisInitialized(_this), "__focusOnPod", () => {
|
|
123
|
-
_reactDom.default.findDOMNode(_this.pod).focus(); // eslint-disable-line react/no-find-dom-node
|
|
124
|
-
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
return _this;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
_createClass(ShowEditPod, [{
|
|
131
|
-
key: "componentDidMount",
|
|
132
|
-
value: function componentDidMount() {
|
|
133
|
-
if (this.props.editing) {
|
|
134
|
-
this.__focusOnPod();
|
|
135
|
-
}
|
|
40
|
+
const ShowEditPod = ({
|
|
41
|
+
border = false,
|
|
42
|
+
className,
|
|
43
|
+
children,
|
|
44
|
+
saving = false,
|
|
45
|
+
editFields,
|
|
46
|
+
editing,
|
|
47
|
+
onEdit,
|
|
48
|
+
onSave,
|
|
49
|
+
onCancel,
|
|
50
|
+
onUndo,
|
|
51
|
+
cancel = true,
|
|
52
|
+
cancelText,
|
|
53
|
+
saveText,
|
|
54
|
+
onDelete,
|
|
55
|
+
deleteText,
|
|
56
|
+
softDelete,
|
|
57
|
+
buttonAlign = "right",
|
|
58
|
+
transitionName = "carbon-show-edit-pod__transition",
|
|
59
|
+
title,
|
|
60
|
+
hideDeleteButtonInViewMode = false,
|
|
61
|
+
variant = "transparent",
|
|
62
|
+
...rest
|
|
63
|
+
}) => {
|
|
64
|
+
const locale = (0, _react.useContext)(_i18nContext.default);
|
|
65
|
+
const ref = (0, _react.useRef)();
|
|
66
|
+
const [isEditing, setIsEditingState] = (0, _react.useState)(false);
|
|
67
|
+
const isControlled = editing !== undefined;
|
|
68
|
+
|
|
69
|
+
const focusPod = () => {
|
|
70
|
+
ref.current.focus();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
(0, _react.useEffect)(() => {
|
|
74
|
+
if (editing) {
|
|
75
|
+
focusPod();
|
|
136
76
|
}
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
key: "deleteButton",
|
|
144
|
-
value: function deleteButton() {
|
|
145
|
-
const label = this.props.deleteText || this.context.actions.delete();
|
|
146
|
-
return /*#__PURE__*/_react.default.createElement(_deleteButton.default, {
|
|
147
|
-
buttonType: "tertiary",
|
|
148
|
-
"data-element": "delete-button",
|
|
149
|
-
size: "small",
|
|
150
|
-
onClick: this.props.onDelete
|
|
151
|
-
}, label);
|
|
77
|
+
}, [editing]);
|
|
78
|
+
const isInEditMode = isControlled ? editing : isEditing;
|
|
79
|
+
|
|
80
|
+
const toggleEditingState = newState => {
|
|
81
|
+
if (!isControlled) {
|
|
82
|
+
setIsEditingState(newState);
|
|
152
83
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
size: "small"
|
|
171
|
-
}, this.props.saveText),
|
|
172
|
-
rightSideButtons: this.props.onDelete ? this.deleteButton() : null,
|
|
173
|
-
saving: this.props.saving
|
|
174
|
-
}, this.props.editFields);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const handleEdit = ev => {
|
|
87
|
+
onEdit(ev);
|
|
88
|
+
toggleEditingState(true);
|
|
89
|
+
focusPod();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const onSaveEditForm = ev => {
|
|
93
|
+
ev.preventDefault();
|
|
94
|
+
onSave(ev);
|
|
95
|
+
toggleEditingState(false);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const onCancelEditForm = ev => {
|
|
99
|
+
if (onCancel) {
|
|
100
|
+
onCancel(ev);
|
|
175
101
|
}
|
|
176
|
-
}, {
|
|
177
|
-
key: "content",
|
|
178
|
-
value: function content() {
|
|
179
|
-
if (this.isEditing()) {
|
|
180
|
-
return /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.CSSTransition, {
|
|
181
|
-
key: "1",
|
|
182
|
-
classNames: this.props.transitionName,
|
|
183
|
-
timeout: {
|
|
184
|
-
enter: 300,
|
|
185
|
-
exit: 50
|
|
186
|
-
}
|
|
187
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
188
|
-
key: "edit"
|
|
189
|
-
}, this.editContent()));
|
|
190
|
-
}
|
|
191
102
|
|
|
103
|
+
toggleEditingState(false);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const onKeyDown = ev => {
|
|
107
|
+
if (_events.default.isEscKey(ev)) {
|
|
108
|
+
onCancelEditForm(ev);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const deleteButton = () => {
|
|
113
|
+
const label = deleteText || locale.actions.delete();
|
|
114
|
+
return /*#__PURE__*/_react.default.createElement(_deleteButton.default, {
|
|
115
|
+
buttonType: "tertiary",
|
|
116
|
+
"data-element": "delete-button",
|
|
117
|
+
size: "small",
|
|
118
|
+
onClick: onDelete
|
|
119
|
+
}, label);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const editContent = () => /*#__PURE__*/_react.default.createElement(_form.default, {
|
|
123
|
+
onSubmit: onSaveEditForm,
|
|
124
|
+
buttonAlignment: buttonAlign,
|
|
125
|
+
"data-element": "edit-form",
|
|
126
|
+
leftSideButtons: cancel && /*#__PURE__*/_react.default.createElement(_button.default, {
|
|
127
|
+
"data-element": "cancel-button",
|
|
128
|
+
onClick: onCancelEditForm,
|
|
129
|
+
size: "small"
|
|
130
|
+
}, cancelText),
|
|
131
|
+
saveButton: /*#__PURE__*/_react.default.createElement(_button.default, {
|
|
132
|
+
disabled: saving,
|
|
133
|
+
"data-element": "submit-button",
|
|
134
|
+
buttonType: "primary",
|
|
135
|
+
type: "submit",
|
|
136
|
+
size: "small"
|
|
137
|
+
}, saveText),
|
|
138
|
+
rightSideButtons: onDelete ? deleteButton() : null,
|
|
139
|
+
saving: saving
|
|
140
|
+
}, editFields);
|
|
141
|
+
|
|
142
|
+
const content = () => {
|
|
143
|
+
if (isInEditMode) {
|
|
192
144
|
return /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.CSSTransition, {
|
|
193
|
-
key: "
|
|
194
|
-
classNames:
|
|
145
|
+
key: "1",
|
|
146
|
+
classNames: transitionName,
|
|
195
147
|
timeout: {
|
|
196
148
|
enter: 300,
|
|
197
149
|
exit: 50
|
|
198
150
|
}
|
|
199
151
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
200
|
-
key: "
|
|
201
|
-
},
|
|
152
|
+
key: "edit"
|
|
153
|
+
}, editContent()));
|
|
202
154
|
}
|
|
203
|
-
}, {
|
|
204
|
-
key: "universalProps",
|
|
205
|
-
value: function universalProps() {
|
|
206
|
-
const {
|
|
207
|
-
onEdit,
|
|
208
|
-
onDelete,
|
|
209
|
-
className,
|
|
210
|
-
...props
|
|
211
|
-
} = (0, _ether.validProps)(this, Object.keys(_pod.default.propTypes));
|
|
212
|
-
return props;
|
|
213
|
-
}
|
|
214
|
-
}, {
|
|
215
|
-
key: "contentProps",
|
|
216
|
-
value: function contentProps() {
|
|
217
|
-
const {
|
|
218
|
-
onEdit,
|
|
219
|
-
onDelete,
|
|
220
|
-
hideDeleteButtonInViewMode
|
|
221
|
-
} = this.props;
|
|
222
|
-
const props = this.universalProps();
|
|
223
|
-
|
|
224
|
-
if (onEdit) {
|
|
225
|
-
props.onEdit = this.onEdit;
|
|
226
|
-
}
|
|
227
155
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
156
|
+
return /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.CSSTransition, {
|
|
157
|
+
key: "2",
|
|
158
|
+
classNames: transitionName,
|
|
159
|
+
timeout: {
|
|
160
|
+
enter: 300,
|
|
161
|
+
exit: 50
|
|
162
|
+
}
|
|
163
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
164
|
+
key: "show"
|
|
165
|
+
}, children));
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const universalProps = () => ({
|
|
169
|
+
size: "small",
|
|
170
|
+
tabIndex: "-1",
|
|
171
|
+
title,
|
|
172
|
+
ref,
|
|
173
|
+
className,
|
|
174
|
+
border,
|
|
175
|
+
onUndo,
|
|
176
|
+
softDelete,
|
|
177
|
+
variant,
|
|
178
|
+
...rest,
|
|
179
|
+
...(0, _tags.default)("show-edit-pod", rest)
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const contentProps = () => ({ ...universalProps(),
|
|
183
|
+
...(!hideDeleteButtonInViewMode && {
|
|
184
|
+
onDelete
|
|
185
|
+
}),
|
|
186
|
+
...(onEdit && {
|
|
187
|
+
onEdit: handleEdit
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const editingProps = () => ({ ...universalProps(),
|
|
192
|
+
onKeyDown
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const podProps = () => isInEditMode ? editingProps() : contentProps();
|
|
196
|
+
|
|
197
|
+
return /*#__PURE__*/_react.default.createElement(_showEditPod.default, podProps(), /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.TransitionGroup, null, content()));
|
|
198
|
+
};
|
|
261
199
|
|
|
262
200
|
exports.BaseShowEditPod = ShowEditPod;
|
|
263
|
-
ShowEditPod.contextType = _i18nContext.default;
|
|
264
201
|
ShowEditPod.propTypes = { ...marginPropTypes,
|
|
265
202
|
|
|
266
203
|
/** Pod theme variant. */
|
|
@@ -322,16 +259,10 @@ ShowEditPod.propTypes = { ...marginPropTypes,
|
|
|
322
259
|
deleteText: _propTypes.default.string,
|
|
323
260
|
|
|
324
261
|
/** Can inform if the form is in a saving state (disables the save button) */
|
|
325
|
-
saving: _propTypes.default.bool
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
border: false,
|
|
330
|
-
buttonAlign: "right",
|
|
331
|
-
transitionName: "carbon-show-edit-pod__transition",
|
|
332
|
-
cancel: true,
|
|
333
|
-
saving: false,
|
|
334
|
-
hideDeleteButtonInViewMode: false
|
|
262
|
+
saving: _propTypes.default.bool,
|
|
263
|
+
|
|
264
|
+
/** Title to be displayed */
|
|
265
|
+
title: _propTypes.default.node
|
|
335
266
|
};
|
|
336
267
|
var _default = ShowEditPod;
|
|
337
268
|
exports.default = _default;
|
|
@@ -48,8 +48,10 @@ export interface ShowEditPodProps {
|
|
|
48
48
|
saveText?: string;
|
|
49
49
|
/** Can inform if the form is in a saving state (disables the save button) */
|
|
50
50
|
saving?: boolean;
|
|
51
|
+
/** Title to be displayed */
|
|
52
|
+
title?: React.ReactNode;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
declare
|
|
55
|
+
declare function ShowEditPod(props: ShowEditPodProps): JSX.Element;
|
|
54
56
|
|
|
55
57
|
export default ShowEditPod;
|
|
@@ -90,7 +90,7 @@ const StyledTitleContent = _styledComponents.default.div`
|
|
|
90
90
|
${size === "large" && position === "left" && (0, _styledComponents.css)`
|
|
91
91
|
font-size: 16px;
|
|
92
92
|
padding: 22px 24px;
|
|
93
|
-
${!isTabSelected && !alternateStyling &&
|
|
93
|
+
${!isTabSelected && !alternateStyling && error && `margin-right: -2px;`}
|
|
94
94
|
`}
|
|
95
95
|
|
|
96
96
|
${size === "default" && (0, _styledComponents.css)`
|
|
@@ -99,7 +99,7 @@ const StyledTitleContent = _styledComponents.default.div`
|
|
|
99
99
|
padding-bottom: 8px;
|
|
100
100
|
`}
|
|
101
101
|
|
|
102
|
-
${position === "left" && !isTabSelected && !alternateStyling &&
|
|
102
|
+
${position === "left" && !isTabSelected && !alternateStyling && error && `margin-right: -2px;`}
|
|
103
103
|
`}
|
|
104
104
|
`}
|
|
105
105
|
|
|
@@ -370,21 +370,23 @@ const StyledTabTitle = _styledComponents.default.li`
|
|
|
370
370
|
alternateStyling,
|
|
371
371
|
error,
|
|
372
372
|
warning,
|
|
373
|
-
info
|
|
373
|
+
info,
|
|
374
|
+
isInSidebar
|
|
374
375
|
}) => position === "left" && (0, _styledComponents.css)`
|
|
375
376
|
background-color: transparent;
|
|
376
377
|
border-bottom: 0px;
|
|
377
378
|
|
|
379
|
+
${!isInSidebar && (0, _styledComponents.css)`
|
|
380
|
+
border-right: ${alternateStyling ? "1px" : "2px"} solid
|
|
381
|
+
${theme.tab.background};
|
|
382
|
+
`}
|
|
383
|
+
|
|
378
384
|
${!borders && (0, _styledComponents.css)`
|
|
379
385
|
${StyledTitleContent} {
|
|
380
386
|
border-bottom: none;
|
|
381
387
|
}
|
|
382
388
|
`}
|
|
383
389
|
|
|
384
|
-
${!alternateStyling && (0, _styledComponents.css)`
|
|
385
|
-
border-right: 2px solid ${theme.tab.background};
|
|
386
|
-
`}
|
|
387
|
-
|
|
388
390
|
display: block;
|
|
389
391
|
height: auto;
|
|
390
392
|
margin-left: 0px;
|
|
@@ -397,6 +399,10 @@ const StyledTabTitle = _styledComponents.default.li`
|
|
|
397
399
|
${alternateStyling && `border-right-color: ${theme.tab.background};`}
|
|
398
400
|
}
|
|
399
401
|
|
|
402
|
+
${(warning || info) && (0, _styledComponents.css)`
|
|
403
|
+
border-right: none;
|
|
404
|
+
`}
|
|
405
|
+
|
|
400
406
|
${({
|
|
401
407
|
isTabSelected
|
|
402
408
|
}) => isTabSelected && (0, _styledComponents.css)`
|
|
@@ -75,11 +75,10 @@ const StyledTabsHeaderList = _styledComponents.default.ul`
|
|
|
75
75
|
|
|
76
76
|
${({
|
|
77
77
|
position,
|
|
78
|
-
noRightBorder
|
|
79
|
-
theme
|
|
78
|
+
noRightBorder
|
|
80
79
|
}) => position === "left" && (0, _styledComponents.css)`
|
|
81
80
|
flex-direction: column;
|
|
82
|
-
box-shadow:
|
|
81
|
+
box-shadow: none;
|
|
83
82
|
|
|
84
83
|
${noRightBorder && (0, _styledComponents.css)`
|
|
85
84
|
box-shadow: none;
|
|
@@ -282,8 +282,15 @@ const Tabs = ({
|
|
|
282
282
|
tab = child;
|
|
283
283
|
}
|
|
284
284
|
});
|
|
285
|
-
return tab ? /*#__PURE__*/(0, _react.cloneElement)(tab, {
|
|
286
|
-
|
|
285
|
+
return tab ? /*#__PURE__*/(0, _react.cloneElement)(tab, { ...tab.props,
|
|
286
|
+
role: "tabpanel",
|
|
287
|
+
position,
|
|
288
|
+
isTabSelected: isTabSelected(tab.props.tabId),
|
|
289
|
+
key: `${tab.props.tabId}-tab`,
|
|
290
|
+
ariaLabelledby: `${tab.props.tabId}-tab`,
|
|
291
|
+
updateErrors,
|
|
292
|
+
updateWarnings,
|
|
293
|
+
updateInfos
|
|
287
294
|
}) : null;
|
|
288
295
|
};
|
|
289
296
|
/** Builds all tabs where non selected tabs have class of hidden */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "96.0.0",
|
|
4
4
|
"description": "A library of reusable React components for easily building user interfaces.",
|
|
5
5
|
"engineStrict": true,
|
|
6
6
|
"engines": {
|
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
"node": ">=14.16.0"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
-
"lib"
|
|
11
|
+
"lib",
|
|
12
|
+
"scripts/check_carbon_version.js",
|
|
13
|
+
"scripts/check_rfcs.js"
|
|
12
14
|
],
|
|
13
15
|
"scripts": {
|
|
14
|
-
"start": "node ./
|
|
16
|
+
"start": "node ./scripts/check_node_version.js && start-storybook -p 9001 -s .assets -c .storybook",
|
|
15
17
|
"start:debug-theme": "cross-env STORYBOOK_DEBUG_THEME=true npm run start",
|
|
16
18
|
"test": "jest --config=./jest.conf.json",
|
|
17
19
|
"test-update": "jest --config=./jest.conf.json --updateSnapshot",
|
|
@@ -22,6 +24,7 @@
|
|
|
22
24
|
"lint": "eslint ./src",
|
|
23
25
|
"precompile": "npm run clean-lib && npm run copy-files && npm run babel",
|
|
24
26
|
"prepublishOnly": "npm run precompile",
|
|
27
|
+
"postinstall": "node ./scripts/check_carbon_version.js && node ./scripts/check_rfcs.js",
|
|
25
28
|
"watch": "npm run clean-lib && npm run copy-files -- --watch & npm run babel -- --watch",
|
|
26
29
|
"build-storybook": "build-storybook -c .storybook -s .assets",
|
|
27
30
|
"start:static": "npx http-server -p 9001 ./storybook-static",
|
|
@@ -132,16 +135,19 @@
|
|
|
132
135
|
"typescript": "^3.9.5"
|
|
133
136
|
},
|
|
134
137
|
"dependencies": {
|
|
138
|
+
"@octokit/rest": "^18.12.0",
|
|
135
139
|
"@popperjs/core": "^2.9.0",
|
|
136
140
|
"@sage/design-tokens": "^1.73.0",
|
|
137
141
|
"@styled-system/prop-types": "^5.1.5",
|
|
138
142
|
"@tippyjs/react": "^4.2.5",
|
|
139
143
|
"classnames": "~2.2.6",
|
|
140
144
|
"crypto-js": "~3.3.0",
|
|
145
|
+
"dotenv": "^10.0.0",
|
|
141
146
|
"immutable": "~3.8.2",
|
|
142
147
|
"invariant": "^2.2.4",
|
|
143
148
|
"lodash": "^4.17.20",
|
|
144
149
|
"moment": "~2.20.1",
|
|
150
|
+
"node-fetch": "^2.6.1",
|
|
145
151
|
"polished": "^4.0.5",
|
|
146
152
|
"prop-types": "^15.7.2",
|
|
147
153
|
"react-day-picker": "~6.1.1",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const fetch = require("node-fetch");
|
|
3
|
+
const dotenv = require("dotenv");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const { version } = require("../package.json");
|
|
6
|
+
|
|
7
|
+
dotenv.config();
|
|
8
|
+
const majorVersion = version.split(".")[0];
|
|
9
|
+
|
|
10
|
+
const checkCarbonVersion = () => {
|
|
11
|
+
fetch("https://registry.npmjs.com/carbon-react")
|
|
12
|
+
.then((res) => res.json())
|
|
13
|
+
.then((data) => {
|
|
14
|
+
const { latest } = data["dist-tags"];
|
|
15
|
+
const latestMajor = latest.split(".")[0];
|
|
16
|
+
|
|
17
|
+
const diff = Number(latestMajor) - Number(majorVersion);
|
|
18
|
+
|
|
19
|
+
if (diff > 1) {
|
|
20
|
+
console.log(
|
|
21
|
+
`carbon-react version installed is currently ${chalk.yellow(
|
|
22
|
+
diff
|
|
23
|
+
)} major versions behind the latest.`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
.catch((err) => console.log(err));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (!process.env.CARBON_INSTALL) checkCarbonVersion();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const { Octokit } = require("@octokit/rest");
|
|
3
|
+
const dotenv = require("dotenv");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
|
|
6
|
+
dotenv.config();
|
|
7
|
+
const octokit = new Octokit({
|
|
8
|
+
baseUrl: "https://api.github.com",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const method = "GET";
|
|
12
|
+
const owner = "sage";
|
|
13
|
+
const path = "pulls";
|
|
14
|
+
const repo = "carbon";
|
|
15
|
+
const url = "/repos/{owner}/{repo}/{path}";
|
|
16
|
+
|
|
17
|
+
const getOpenRfcs = async () => {
|
|
18
|
+
const { data } = await octokit.request({
|
|
19
|
+
owner,
|
|
20
|
+
repo,
|
|
21
|
+
url,
|
|
22
|
+
method,
|
|
23
|
+
path,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return data.filter((item) => {
|
|
27
|
+
const labels = item.labels.filter((label) => label.name === "RFC");
|
|
28
|
+
|
|
29
|
+
return labels.length > 0;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getRfcTitle = (rfc) => rfc.title.split(": ")[1];
|
|
34
|
+
|
|
35
|
+
const checkRfcs = async () => {
|
|
36
|
+
const openRfcs = await getOpenRfcs();
|
|
37
|
+
|
|
38
|
+
if (openRfcs.length > 0) {
|
|
39
|
+
console.log("\ncarbon-react currently has open RFCs:");
|
|
40
|
+
|
|
41
|
+
openRfcs.forEach((item) => {
|
|
42
|
+
const title = getRfcTitle(item);
|
|
43
|
+
console.log(`- ${title}: ${chalk.cyan(item.html_url)}`);
|
|
44
|
+
});
|
|
45
|
+
console.log("\n");
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (!process.env.CARBON_INSTALL) checkRfcs();
|