carbon-react 95.1.1 → 96.1.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.
@@ -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;
@@ -48,6 +48,8 @@ export interface PodProps {
48
48
  height?: string | number;
49
49
  }
50
50
 
51
- declare class Pod extends React.Component<PodProps> {}
51
+ declare function Pod(
52
+ props: PodProps & React.RefAttributes<HTMLElement>
53
+ ): JSX.Element;
52
54
 
53
55
  export default Pod;
@@ -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
- setSelectedValue(prevValue => {
196
- if (value && isControlled.current && prevValue !== newValue) {
197
- setMatchingText(newValue);
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
- return newValue;
201
- });
202
- setHighlightedValue(newValue); // prevent value update on filter change
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
- }, [value, defaultValue, onChange, children]);
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
- setMatchingText(value || defaultValue); // update text value only when children are changing
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 === 0) {
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 === 0) {
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: title
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 onChageMissingMessage = "onChange prop required when using a controlled input element";
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, onChageMissingMessage);
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
- return newValue;
227
- });
228
- }, [value, defaultValue, onChange]); // removes placeholder when a value is present
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 && value.length > 0;
232
- const hasSelectedValue = selectedValue && selectedValue.length > 0;
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
- setSelectedValue(newValue);
185
- }, [value, defaultValue, onChange]);
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 = "";
@@ -55,7 +55,7 @@ export interface SimpleSelectProps
55
55
  | "left-start"
56
56
  | "left-end";
57
57
  /** Use the opposite list placement if the set placement does not fit */
58
- flipEnabled?: bool;
58
+ flipEnabled?: boolean;
59
59
  }
60
60
 
61
61
  declare function SimpleSelect(
@@ -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 = _interopRequireDefault(require("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 _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); }
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 _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
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
- let ShowEditPod = /*#__PURE__*/function (_React$Component) {
67
- _inherits(ShowEditPod, _React$Component);
68
-
69
- var _super = _createSuper(ShowEditPod);
70
-
71
- function ShowEditPod(...args) {
72
- var _this;
73
-
74
- _classCallCheck(this, ShowEditPod);
75
-
76
- _this = _super.call(this, ...args);
77
-
78
- _defineProperty(_assertThisInitialized(_this), "state", {
79
- editing: false
80
- });
81
-
82
- _defineProperty(_assertThisInitialized(_this), "isControlled", _this.props.editing !== undefined);
83
-
84
- _defineProperty(_assertThisInitialized(_this), "onEdit", ev => {
85
- _this.props.onEdit(ev);
86
-
87
- _this.toggleEditingState(true);
88
-
89
- _this.__focusOnPod();
90
- });
91
-
92
- _defineProperty(_assertThisInitialized(_this), "onSaveEditForm", ev => {
93
- ev.preventDefault();
94
-
95
- _this.props.onSave(ev);
96
-
97
- _this.toggleEditingState(false);
98
- });
99
-
100
- _defineProperty(_assertThisInitialized(_this), "onCancelEditForm", ev => {
101
- if (_this.props.onCancel) {
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
- key: "isEditing",
139
- value: function isEditing() {
140
- return this.isControlled ? this.props.editing : this.state.editing;
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
- key: "editContent",
155
- value: function editContent() {
156
- return /*#__PURE__*/_react.default.createElement(_form.default, {
157
- onSubmit: this.onSaveEditForm,
158
- buttonAlignment: this.props.buttonAlign,
159
- "data-element": "edit-form",
160
- leftSideButtons: this.props.cancel && /*#__PURE__*/_react.default.createElement(_button.default, {
161
- "data-element": "cancel-button",
162
- onClick: this.onCancelEditForm,
163
- size: "small"
164
- }, this.props.cancelText),
165
- saveButton: /*#__PURE__*/_react.default.createElement(_button.default, {
166
- disabled: this.props.saving,
167
- "data-element": "submit-button",
168
- buttonType: "primary",
169
- type: "submit",
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: "2",
194
- classNames: this.props.transitionName,
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: "show"
201
- }, this.props.children));
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
- return { ...props,
229
- onDelete: !hideDeleteButtonInViewMode && onDelete
230
- };
231
- }
232
- }, {
233
- key: "editingProps",
234
- value: function editingProps() {
235
- const props = this.universalProps();
236
- props.onKeyDown = this.onKeyDown;
237
- return props;
238
- }
239
- }, {
240
- key: "podProps",
241
- value: function podProps() {
242
- return this.isEditing() ? this.editingProps() : this.contentProps();
243
- }
244
- }, {
245
- key: "render",
246
- value: function render() {
247
- return /*#__PURE__*/_react.default.createElement(_showEditPod.default, _extends({
248
- className: this.props.className,
249
- size: "small"
250
- }, this.podProps(), {
251
- ref: node => {
252
- this.pod = node;
253
- },
254
- tabIndex: "-1"
255
- }, (0, _tags.default)("show-edit-pod", this.props)), /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.TransitionGroup, null, this.content()));
256
- }
257
- }]);
258
-
259
- return ShowEditPod;
260
- }(_react.default.Component);
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
- ShowEditPod.defaultProps = {
328
- variant: "transparent",
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 class ShowEditPod extends React.Component<ShowEditPodProps> {}
55
+ declare function ShowEditPod(props: ShowEditPodProps): JSX.Element;
54
56
 
55
57
  export default ShowEditPod;
@@ -282,8 +282,15 @@ const Tabs = ({
282
282
  tab = child;
283
283
  }
284
284
  });
285
- return tab ? /*#__PURE__*/(0, _react.cloneElement)(tab, {
286
- isTabSelected: isTabSelected(tab.props.tabId)
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": "95.1.1",
3
+ "version": "96.1.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 ./check_version.js && start-storybook -p 9001 -s .assets -c .storybook",
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,14 +24,14 @@
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",
28
31
  "babel": "cross-env NODE_ENV=production babel ./src --config-file ./babel.config.js --out-dir ./lib --ignore '**/*/__spec__.js','**/*.spec.js','**/__definition__.js' --quiet",
29
32
  "clean-lib": "rimraf ./lib",
30
33
  "copy-files": "cpy \"**/\" \"!**/(*.js|*.md|*.mdx|*.stories.*|*.snap)\" ../lib/ --cwd=src --parents",
31
- "commit": "git-cz",
32
- "chromatic": "chromatic"
34
+ "commit": "git-cz"
33
35
  },
34
36
  "repository": {
35
37
  "type": "git",
@@ -86,6 +88,7 @@
86
88
  "babel-jest": "^26.6.3",
87
89
  "browserslist": "^4.16.6",
88
90
  "chalk": "^4.1.1",
91
+ "chromatic": "^6.0.5",
89
92
  "commitizen": "^4.2.4",
90
93
  "conventional-changelog-conventionalcommits": "^4.5.0",
91
94
  "core-js": "^3.1.4",
@@ -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();