@pingux/astro 2.52.0-alpha.0 → 2.52.0-alpha.1
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.
@@ -14,12 +14,14 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
14
14
|
_Object$defineProperty(exports, "__esModule", {
|
15
15
|
value: true
|
16
16
|
});
|
17
|
-
exports["default"] = exports.Required = exports.Indeterminate = exports.HelperText = exports.DefaultSelected = exports.Default = exports.Controlled = void 0;
|
17
|
+
exports["default"] = exports.Required = exports.Indeterminate = exports.HelperText = exports.ExpandableAndToggleableIndeterminate = exports.DefaultSelected = exports.Default = exports.Controlled = void 0;
|
18
18
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
19
19
|
var _every = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/every"));
|
20
20
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
21
21
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
22
22
|
var _react = _interopRequireWildcard(require("react"));
|
23
|
+
var _MenuDownIcon = _interopRequireDefault(require("@pingux/mdi-react/MenuDownIcon"));
|
24
|
+
var _MenuRightIcon = _interopRequireDefault(require("@pingux/mdi-react/MenuRightIcon"));
|
23
25
|
var _storybookDocsLayout = _interopRequireDefault(require("../../../.storybook/storybookDocsLayout"));
|
24
26
|
var _index = require("../../index");
|
25
27
|
var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
|
@@ -121,19 +123,139 @@ var HelperText = function HelperText() {
|
|
121
123
|
});
|
122
124
|
};
|
123
125
|
exports.HelperText = HelperText;
|
126
|
+
var ExpandableAndToggleableIndeterminate = function ExpandableAndToggleableIndeterminate() {
|
127
|
+
var _useState = (0, _react.useState)(false),
|
128
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
129
|
+
isReadOnly = _useState2[0],
|
130
|
+
setIsReadOnly = _useState2[1];
|
131
|
+
var _useState3 = (0, _react.useState)(true),
|
132
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
133
|
+
isExpanded = _useState4[0],
|
134
|
+
setIsExpanded = _useState4[1];
|
135
|
+
// Whether the parent checkbox is indeterminate (default is true for our example)
|
136
|
+
var _useState5 = (0, _react.useState)(true),
|
137
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
138
|
+
isIndeterminate = _useState6[0],
|
139
|
+
setIsIndeterminate = _useState6[1];
|
140
|
+
// Whether the parent checkbox should be checked, this is set independently from indeterminism
|
141
|
+
var _useState7 = (0, _react.useState)(false),
|
142
|
+
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
143
|
+
isCompleted = _useState8[0],
|
144
|
+
setIsCompleted = _useState8[1];
|
145
|
+
// The state of the sub-checkboxes
|
146
|
+
var _useState9 = (0, _react.useState)([{
|
147
|
+
label: 'Apple Chunks',
|
148
|
+
isSelected: true
|
149
|
+
}, {
|
150
|
+
label: 'Blueberries',
|
151
|
+
isSelected: false
|
152
|
+
}, {
|
153
|
+
label: 'Grapes',
|
154
|
+
isSelected: false
|
155
|
+
}, {
|
156
|
+
label: 'Strawberry Slices',
|
157
|
+
isSelected: true
|
158
|
+
}]),
|
159
|
+
_useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
|
160
|
+
subCheckboxes = _useState10[0],
|
161
|
+
setSubCheckboxes = _useState10[1];
|
162
|
+
|
163
|
+
// Determine which checkbox needs its state updated
|
164
|
+
var handleSubCheckboxChange = function handleSubCheckboxChange(isSelected, changedIndex) {
|
165
|
+
var changeAll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
166
|
+
var newSubCheckboxes = (0, _map["default"])(subCheckboxes).call(subCheckboxes, function (checkbox, index) {
|
167
|
+
if (changeAll || index === changedIndex) return _objectSpread(_objectSpread({}, checkbox), {}, {
|
168
|
+
isSelected: isSelected
|
169
|
+
});
|
170
|
+
return checkbox;
|
171
|
+
});
|
172
|
+
setSubCheckboxes(newSubCheckboxes);
|
173
|
+
};
|
174
|
+
|
175
|
+
// Update all sub-checkbox states when the parent checkbox is pressed
|
176
|
+
var handleParentCheckboxChange = function handleParentCheckboxChange(isSelected) {
|
177
|
+
handleSubCheckboxChange(isSelected, null, true);
|
178
|
+
};
|
179
|
+
(0, _react.useEffect)(function () {
|
180
|
+
// Determine if all sub-checkboxes are selected / unselected or if there is a mix
|
181
|
+
// and update the parent checkbox
|
182
|
+
if ((0, _every["default"])(subCheckboxes).call(subCheckboxes, function (item) {
|
183
|
+
return item.isSelected;
|
184
|
+
})) {
|
185
|
+
setIsIndeterminate(false);
|
186
|
+
setIsCompleted(true);
|
187
|
+
} else if ((0, _every["default"])(subCheckboxes).call(subCheckboxes, function (item) {
|
188
|
+
return !item.isSelected;
|
189
|
+
})) {
|
190
|
+
setIsIndeterminate(false);
|
191
|
+
setIsCompleted(false);
|
192
|
+
} else {
|
193
|
+
setIsIndeterminate(true);
|
194
|
+
setIsCompleted(false);
|
195
|
+
}
|
196
|
+
}, [isIndeterminate, subCheckboxes]);
|
197
|
+
return (0, _react2.jsx)(_react["default"].Fragment, null, (0, _react2.jsx)(_index.SwitchField, {
|
198
|
+
isSelected: isReadOnly,
|
199
|
+
label: "Is Read Only",
|
200
|
+
onChange: setIsReadOnly,
|
201
|
+
value: "my-switch"
|
202
|
+
}), (0, _react2.jsx)("br", null), (0, _react2.jsx)(_index.Box, {
|
203
|
+
isRow: true,
|
204
|
+
alignItems: "center"
|
205
|
+
}, (0, _react2.jsx)(_index.IconButtonToggle, {
|
206
|
+
toggledIcon: _MenuDownIcon["default"],
|
207
|
+
defaultIcon: _MenuRightIcon["default"],
|
208
|
+
onToggle: setIsExpanded,
|
209
|
+
isToggled: isExpanded,
|
210
|
+
buttonProps: {
|
211
|
+
'aria-label': isExpanded ? 'menu down' : 'menu up',
|
212
|
+
'aria-controls': 'expanded-checkboxes',
|
213
|
+
'aria-expanded': isExpanded
|
214
|
+
},
|
215
|
+
iconProps: {
|
216
|
+
size: 'sm'
|
217
|
+
}
|
218
|
+
}), isReadOnly ? (0, _react2.jsx)(_index.Text, null, "Fruit Salad Recipe") : (0, _react2.jsx)(_index.CheckboxField, {
|
219
|
+
label: "Fruit Salad Recipe",
|
220
|
+
isIndeterminate: isIndeterminate,
|
221
|
+
isSelected: isCompleted,
|
222
|
+
onChange: handleParentCheckboxChange
|
223
|
+
}), (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(_index.Badge, {
|
224
|
+
ml: "sm",
|
225
|
+
label: subCheckboxes.length,
|
226
|
+
variant: "countNeutral"
|
227
|
+
}))), (0, _react2.jsx)(_index.Box, {
|
228
|
+
ml: "50px",
|
229
|
+
id: "expanded-checkboxes"
|
230
|
+
}, isExpanded && (0, _map["default"])(subCheckboxes).call(subCheckboxes, function (checkbox, index) {
|
231
|
+
return (0, _react2.jsx)(_index.Box, {
|
232
|
+
isRow: true,
|
233
|
+
alignItems: "center",
|
234
|
+
height: "24px"
|
235
|
+
}, isReadOnly ? (0, _react2.jsx)(_index.Text, null, checkbox.label) : (0, _react2.jsx)(_index.CheckboxField, {
|
236
|
+
key: checkbox.label,
|
237
|
+
label: checkbox.label,
|
238
|
+
isSelected: checkbox.isSelected,
|
239
|
+
onChange: function onChange(isSelected) {
|
240
|
+
return handleSubCheckboxChange(isSelected, index);
|
241
|
+
}
|
242
|
+
}));
|
243
|
+
})));
|
244
|
+
};
|
245
|
+
exports.ExpandableAndToggleableIndeterminate = ExpandableAndToggleableIndeterminate;
|
124
246
|
var Indeterminate = function Indeterminate() {
|
125
247
|
// Whether the parent checkbox is indeterminate (default is true for our example)
|
126
|
-
var
|
127
|
-
|
128
|
-
isIndeterminate =
|
129
|
-
setIsIndeterminate =
|
248
|
+
var _useState11 = (0, _react.useState)(true),
|
249
|
+
_useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
|
250
|
+
isIndeterminate = _useState12[0],
|
251
|
+
setIsIndeterminate = _useState12[1];
|
130
252
|
// Whether the parent checkbox should be checked, this is set independently from indeterminism
|
131
|
-
var
|
132
|
-
|
133
|
-
isCompleted =
|
134
|
-
setIsCompleted =
|
253
|
+
var _useState13 = (0, _react.useState)(false),
|
254
|
+
_useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
|
255
|
+
isCompleted = _useState14[0],
|
256
|
+
setIsCompleted = _useState14[1];
|
135
257
|
// The state of the sub-checkboxes
|
136
|
-
var
|
258
|
+
var _useState15 = (0, _react.useState)([{
|
137
259
|
label: 'Apple Chunks',
|
138
260
|
isSelected: true
|
139
261
|
}, {
|
@@ -146,9 +268,9 @@ var Indeterminate = function Indeterminate() {
|
|
146
268
|
label: 'Strawberry Slices',
|
147
269
|
isSelected: true
|
148
270
|
}]),
|
149
|
-
|
150
|
-
subCheckboxes =
|
151
|
-
setSubCheckboxes =
|
271
|
+
_useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
|
272
|
+
subCheckboxes = _useState16[0],
|
273
|
+
setSubCheckboxes = _useState16[1];
|
152
274
|
|
153
275
|
// Determine which checkbox needs its state updated
|
154
276
|
var handleSubCheckboxChange = function handleSubCheckboxChange(isSelected, changedIndex) {
|
@@ -13,8 +13,10 @@ import _everyInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instan
|
|
13
13
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
15
|
import React, { useEffect, useState } from 'react';
|
16
|
+
import MenuDown from '@pingux/mdi-react/MenuDownIcon';
|
17
|
+
import MenuRight from '@pingux/mdi-react/MenuRightIcon';
|
16
18
|
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
17
|
-
import { Box, CheckboxField, Link, Text } from '../../index';
|
19
|
+
import { Badge, Box, CheckboxField, IconButtonToggle, Link, SwitchField, Text } from '../../index';
|
18
20
|
import { ariaAttributeBaseArgTypes } from '../../utils/docUtils/ariaAttributes';
|
19
21
|
import { inputFieldAttributeBaseArgTypes } from '../../utils/docUtils/fieldAttributes';
|
20
22
|
import { statusArgTypes } from '../../utils/docUtils/statusProp';
|
@@ -104,19 +106,138 @@ export var HelperText = function HelperText() {
|
|
104
106
|
label: "Click me"
|
105
107
|
});
|
106
108
|
};
|
109
|
+
export var ExpandableAndToggleableIndeterminate = function ExpandableAndToggleableIndeterminate() {
|
110
|
+
var _useState = useState(false),
|
111
|
+
_useState2 = _slicedToArray(_useState, 2),
|
112
|
+
isReadOnly = _useState2[0],
|
113
|
+
setIsReadOnly = _useState2[1];
|
114
|
+
var _useState3 = useState(true),
|
115
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
116
|
+
isExpanded = _useState4[0],
|
117
|
+
setIsExpanded = _useState4[1];
|
118
|
+
// Whether the parent checkbox is indeterminate (default is true for our example)
|
119
|
+
var _useState5 = useState(true),
|
120
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
121
|
+
isIndeterminate = _useState6[0],
|
122
|
+
setIsIndeterminate = _useState6[1];
|
123
|
+
// Whether the parent checkbox should be checked, this is set independently from indeterminism
|
124
|
+
var _useState7 = useState(false),
|
125
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
126
|
+
isCompleted = _useState8[0],
|
127
|
+
setIsCompleted = _useState8[1];
|
128
|
+
// The state of the sub-checkboxes
|
129
|
+
var _useState9 = useState([{
|
130
|
+
label: 'Apple Chunks',
|
131
|
+
isSelected: true
|
132
|
+
}, {
|
133
|
+
label: 'Blueberries',
|
134
|
+
isSelected: false
|
135
|
+
}, {
|
136
|
+
label: 'Grapes',
|
137
|
+
isSelected: false
|
138
|
+
}, {
|
139
|
+
label: 'Strawberry Slices',
|
140
|
+
isSelected: true
|
141
|
+
}]),
|
142
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
143
|
+
subCheckboxes = _useState10[0],
|
144
|
+
setSubCheckboxes = _useState10[1];
|
145
|
+
|
146
|
+
// Determine which checkbox needs its state updated
|
147
|
+
var handleSubCheckboxChange = function handleSubCheckboxChange(isSelected, changedIndex) {
|
148
|
+
var changeAll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
149
|
+
var newSubCheckboxes = _mapInstanceProperty(subCheckboxes).call(subCheckboxes, function (checkbox, index) {
|
150
|
+
if (changeAll || index === changedIndex) return _objectSpread(_objectSpread({}, checkbox), {}, {
|
151
|
+
isSelected: isSelected
|
152
|
+
});
|
153
|
+
return checkbox;
|
154
|
+
});
|
155
|
+
setSubCheckboxes(newSubCheckboxes);
|
156
|
+
};
|
157
|
+
|
158
|
+
// Update all sub-checkbox states when the parent checkbox is pressed
|
159
|
+
var handleParentCheckboxChange = function handleParentCheckboxChange(isSelected) {
|
160
|
+
handleSubCheckboxChange(isSelected, null, true);
|
161
|
+
};
|
162
|
+
useEffect(function () {
|
163
|
+
// Determine if all sub-checkboxes are selected / unselected or if there is a mix
|
164
|
+
// and update the parent checkbox
|
165
|
+
if (_everyInstanceProperty(subCheckboxes).call(subCheckboxes, function (item) {
|
166
|
+
return item.isSelected;
|
167
|
+
})) {
|
168
|
+
setIsIndeterminate(false);
|
169
|
+
setIsCompleted(true);
|
170
|
+
} else if (_everyInstanceProperty(subCheckboxes).call(subCheckboxes, function (item) {
|
171
|
+
return !item.isSelected;
|
172
|
+
})) {
|
173
|
+
setIsIndeterminate(false);
|
174
|
+
setIsCompleted(false);
|
175
|
+
} else {
|
176
|
+
setIsIndeterminate(true);
|
177
|
+
setIsCompleted(false);
|
178
|
+
}
|
179
|
+
}, [isIndeterminate, subCheckboxes]);
|
180
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(SwitchField, {
|
181
|
+
isSelected: isReadOnly,
|
182
|
+
label: "Is Read Only",
|
183
|
+
onChange: setIsReadOnly,
|
184
|
+
value: "my-switch"
|
185
|
+
}), ___EmotionJSX("br", null), ___EmotionJSX(Box, {
|
186
|
+
isRow: true,
|
187
|
+
alignItems: "center"
|
188
|
+
}, ___EmotionJSX(IconButtonToggle, {
|
189
|
+
toggledIcon: MenuDown,
|
190
|
+
defaultIcon: MenuRight,
|
191
|
+
onToggle: setIsExpanded,
|
192
|
+
isToggled: isExpanded,
|
193
|
+
buttonProps: {
|
194
|
+
'aria-label': isExpanded ? 'menu down' : 'menu up',
|
195
|
+
'aria-controls': 'expanded-checkboxes',
|
196
|
+
'aria-expanded': isExpanded
|
197
|
+
},
|
198
|
+
iconProps: {
|
199
|
+
size: 'sm'
|
200
|
+
}
|
201
|
+
}), isReadOnly ? ___EmotionJSX(Text, null, "Fruit Salad Recipe") : ___EmotionJSX(CheckboxField, {
|
202
|
+
label: "Fruit Salad Recipe",
|
203
|
+
isIndeterminate: isIndeterminate,
|
204
|
+
isSelected: isCompleted,
|
205
|
+
onChange: handleParentCheckboxChange
|
206
|
+
}), ___EmotionJSX(Box, null, ___EmotionJSX(Badge, {
|
207
|
+
ml: "sm",
|
208
|
+
label: subCheckboxes.length,
|
209
|
+
variant: "countNeutral"
|
210
|
+
}))), ___EmotionJSX(Box, {
|
211
|
+
ml: "50px",
|
212
|
+
id: "expanded-checkboxes"
|
213
|
+
}, isExpanded && _mapInstanceProperty(subCheckboxes).call(subCheckboxes, function (checkbox, index) {
|
214
|
+
return ___EmotionJSX(Box, {
|
215
|
+
isRow: true,
|
216
|
+
alignItems: "center",
|
217
|
+
height: "24px"
|
218
|
+
}, isReadOnly ? ___EmotionJSX(Text, null, checkbox.label) : ___EmotionJSX(CheckboxField, {
|
219
|
+
key: checkbox.label,
|
220
|
+
label: checkbox.label,
|
221
|
+
isSelected: checkbox.isSelected,
|
222
|
+
onChange: function onChange(isSelected) {
|
223
|
+
return handleSubCheckboxChange(isSelected, index);
|
224
|
+
}
|
225
|
+
}));
|
226
|
+
})));
|
227
|
+
};
|
107
228
|
export var Indeterminate = function Indeterminate() {
|
108
229
|
// Whether the parent checkbox is indeterminate (default is true for our example)
|
109
|
-
var
|
110
|
-
|
111
|
-
isIndeterminate =
|
112
|
-
setIsIndeterminate =
|
230
|
+
var _useState11 = useState(true),
|
231
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
232
|
+
isIndeterminate = _useState12[0],
|
233
|
+
setIsIndeterminate = _useState12[1];
|
113
234
|
// Whether the parent checkbox should be checked, this is set independently from indeterminism
|
114
|
-
var
|
115
|
-
|
116
|
-
isCompleted =
|
117
|
-
setIsCompleted =
|
235
|
+
var _useState13 = useState(false),
|
236
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
237
|
+
isCompleted = _useState14[0],
|
238
|
+
setIsCompleted = _useState14[1];
|
118
239
|
// The state of the sub-checkboxes
|
119
|
-
var
|
240
|
+
var _useState15 = useState([{
|
120
241
|
label: 'Apple Chunks',
|
121
242
|
isSelected: true
|
122
243
|
}, {
|
@@ -129,9 +250,9 @@ export var Indeterminate = function Indeterminate() {
|
|
129
250
|
label: 'Strawberry Slices',
|
130
251
|
isSelected: true
|
131
252
|
}]),
|
132
|
-
|
133
|
-
subCheckboxes =
|
134
|
-
setSubCheckboxes =
|
253
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
254
|
+
subCheckboxes = _useState16[0],
|
255
|
+
setSubCheckboxes = _useState16[1];
|
135
256
|
|
136
257
|
// Determine which checkbox needs its state updated
|
137
258
|
var handleSubCheckboxChange = function handleSubCheckboxChange(isSelected, changedIndex) {
|