@pingux/astro 1.33.0 → 1.33.1-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.
@@ -6,19 +6,23 @@ import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-sta
6
6
  import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
7
7
  import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
8
8
  import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
9
+ import _everyInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/every";
10
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
9
11
  import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
12
+ import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
10
13
  import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
11
14
 
12
15
  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; }
13
16
 
14
17
  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
18
 
16
- import React from 'react';
19
+ import React, { useEffect, useState } from 'react';
17
20
  import { ariaAttributeBaseArgTypes } from '../../utils/devUtils/props/ariaAttributes';
18
21
  import CheckboxField from './CheckboxField';
19
22
  import Link from '../Link';
20
23
  import Text from '../Text';
21
24
  import statuses from '../../utils/devUtils/constants/statuses';
25
+ import Box from '../Box';
22
26
  import { jsx as ___EmotionJSX } from "@emotion/react";
23
27
  export default {
24
28
  title: 'Form/CheckboxField',
@@ -43,7 +47,7 @@ export default {
43
47
  status: {
44
48
  control: {
45
49
  type: 'select',
46
- options: statuses
50
+ options: _Object$values(statuses)
47
51
  },
48
52
  defaultValue: statuses.DEFAULT
49
53
  },
@@ -114,4 +118,97 @@ export var HelperText = function HelperText() {
114
118
  helperText: "Here is some helpful text...",
115
119
  label: "Click me"
116
120
  });
121
+ };
122
+ export var Indeterminate = function Indeterminate() {
123
+ // Whether the parent checkbox is indeterminate (default is true for our example)
124
+ var _useState = useState(true),
125
+ _useState2 = _slicedToArray(_useState, 2),
126
+ isIndeterminate = _useState2[0],
127
+ setIsIndeterminate = _useState2[1]; // Whether the parent checkbox should be checked, this is set independently from indeterminism
128
+
129
+
130
+ var _useState3 = useState(false),
131
+ _useState4 = _slicedToArray(_useState3, 2),
132
+ isCompleted = _useState4[0],
133
+ setIsCompleted = _useState4[1]; // The state of the sub-checkboxes
134
+
135
+
136
+ var _useState5 = useState([{
137
+ label: 'Apple Chunks',
138
+ isSelected: true
139
+ }, {
140
+ label: 'Blueberries',
141
+ isSelected: false
142
+ }, {
143
+ label: 'Grapes',
144
+ isSelected: false
145
+ }, {
146
+ label: 'Strawberry Slices',
147
+ isSelected: true
148
+ }]),
149
+ _useState6 = _slicedToArray(_useState5, 2),
150
+ subCheckboxes = _useState6[0],
151
+ setSubCheckboxes = _useState6[1]; // Determine which checkbox needs its state updated
152
+
153
+
154
+ var handleSubCheckboxChange = function handleSubCheckboxChange(isSelected, changedIndex) {
155
+ var changeAll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
156
+
157
+ var newSubCheckboxes = _mapInstanceProperty(subCheckboxes).call(subCheckboxes, function (checkbox, index) {
158
+ if (changeAll || index === changedIndex) return _objectSpread(_objectSpread({}, checkbox), {}, {
159
+ isSelected: isSelected
160
+ });
161
+ return checkbox;
162
+ });
163
+
164
+ setSubCheckboxes(newSubCheckboxes);
165
+ }; // Update all sub-checkbox states when the parent checkbox is pressed
166
+
167
+
168
+ var handleParentCheckboxChange = function handleParentCheckboxChange(isSelected) {
169
+ handleSubCheckboxChange(isSelected, null, true);
170
+ };
171
+
172
+ useEffect(function () {
173
+ // Determine if all sub-checkboxes are selected / unselected or if there is a mix
174
+ // and update the parent checkbox
175
+ if (_everyInstanceProperty(subCheckboxes).call(subCheckboxes, function (item) {
176
+ return item.isSelected;
177
+ })) {
178
+ setIsIndeterminate(false);
179
+ setIsCompleted(true);
180
+ } else if (_everyInstanceProperty(subCheckboxes).call(subCheckboxes, function (item) {
181
+ return !item.isSelected;
182
+ })) {
183
+ setIsIndeterminate(false);
184
+ setIsCompleted(false);
185
+ } else {
186
+ setIsIndeterminate(true);
187
+ setIsCompleted(false);
188
+ }
189
+ }, [isIndeterminate, subCheckboxes]);
190
+ return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(CheckboxField, {
191
+ label: "Fruit Salad Recipe",
192
+ isIndeterminate: isIndeterminate,
193
+ isSelected: isCompleted,
194
+ onChange: handleParentCheckboxChange
195
+ }), ___EmotionJSX(Box, {
196
+ ml: "lg"
197
+ }, _mapInstanceProperty(subCheckboxes).call(subCheckboxes, function (checkbox, index) {
198
+ return ___EmotionJSX(CheckboxField, {
199
+ key: checkbox.label,
200
+ label: checkbox.label,
201
+ isSelected: checkbox.isSelected,
202
+ onChange: function onChange(isSelected) {
203
+ return handleSubCheckboxChange(isSelected, index);
204
+ }
205
+ });
206
+ })));
207
+ };
208
+ Indeterminate.parameters = {
209
+ docs: {
210
+ description: {
211
+ story: 'When a `CheckboxField` is indeterminate, it\'s necessary to control the state in order to determine how it should function when pressed. Here is an example of how to do that.'
212
+ }
213
+ }
117
214
  };
@@ -12,7 +12,12 @@ var defaultProps = {
12
12
 
13
13
  var getComponent = function getComponent() {
14
14
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
15
- return render(___EmotionJSX(CheckboxField, _extends({}, defaultProps, props)));
15
+
16
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
17
+ _ref$renderFn = _ref.renderFn,
18
+ renderFn = _ref$renderFn === void 0 ? render : _ref$renderFn;
19
+
20
+ return renderFn(___EmotionJSX(CheckboxField, _extends({}, defaultProps, props)));
16
21
  }; // Need to be added to each test file to test accessibility using axe.
17
22
 
18
23
 
@@ -81,4 +86,33 @@ test('read only checkbox', function () {
81
86
  });
82
87
  var input = screen.getByRole('checkbox');
83
88
  expect(input).toHaveAttribute('readonly');
89
+ });
90
+ test('indeterminate checkbox', function () {
91
+ var _getComponent = getComponent({
92
+ isIndeterminate: true
93
+ }),
94
+ rerender = _getComponent.rerender;
95
+
96
+ var input = screen.getByRole('checkbox');
97
+ var label = screen.getByText(testLabel);
98
+ /* eslint-disable jest-dom/prefer-checked */
99
+
100
+ expect(input).toHaveAttribute('aria-checked', 'mixed');
101
+ expect(label).toHaveClass('is-indeterminate'); // Ensure it cannot be changed via user interaction
102
+
103
+ userEvent.click(input);
104
+ expect(input).toHaveAttribute('aria-checked', 'mixed'); // An indeterminite checkbox can still have the checked attribute
105
+
106
+ expect(input).toBeChecked(); // Ensure it works normally when toggled off again
107
+
108
+ getComponent({}, {
109
+ renderFn: rerender
110
+ }); // Reset the variable since the DOM has changed
111
+
112
+ input = screen.getByRole('checkbox');
113
+ expect(input).not.toHaveAttribute('aria-checked', 'mixed');
114
+ expect(label).not.toHaveClass('is-indeterminate'); // Ensure it can be changed via user interaction, should be unchecked now
115
+
116
+ userEvent.click(input);
117
+ expect(input).not.toBeChecked();
84
118
  });
@@ -86,7 +86,12 @@ var Modal = /*#__PURE__*/forwardRef(function (props, ref) {
86
86
 
87
87
  var _useDialog = useDialog(contentProps, modalRef),
88
88
  dialogProps = _useDialog.dialogProps,
89
- titleProps = _useDialog.titleProps;
89
+ titleProps = _useDialog.titleProps; // Prevents extra dialog focus from being called.
90
+
91
+
92
+ dialogProps.onMouseDown = function (e) {
93
+ return e.preventDefault();
94
+ };
90
95
 
91
96
  var _useStatusClasses = useStatusClasses(className, {
92
97
  isDarkMode: others.variant === 'modal.dark'
@@ -2,13 +2,20 @@ import React from 'react';
2
2
  import userEvent from '@testing-library/user-event';
3
3
  import axeTest from '../../../utils/testUtils/testAxe';
4
4
  import { render, screen, queryByAttribute } from '../../../utils/testUtils/testWrapper';
5
- import { OverlayProvider, Modal } from '../../../index'; // For testing the modal alone
5
+ import { CheckboxField, OverlayProvider, Modal } from '../../../index'; // For testing the modal alone
6
6
 
7
7
  import { jsx as ___EmotionJSX } from "@emotion/react";
8
8
 
9
9
  var getComponent = function getComponent() {
10
10
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
11
  return render(___EmotionJSX(OverlayProvider, null, ___EmotionJSX(Modal, props)));
12
+ };
13
+
14
+ var getComponentWithCheckbox = function getComponentWithCheckbox() {
15
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16
+ return render(___EmotionJSX(OverlayProvider, null, ___EmotionJSX(Modal, props, ___EmotionJSX(CheckboxField, {
17
+ "aria-label": "checkbox"
18
+ }))));
12
19
  }; // **********
13
20
  // Unit tests
14
21
  // **********
@@ -185,4 +192,16 @@ test('should auto focus the first tabbable element if "hasAutoFocus" is true', f
185
192
  });
186
193
  var button = screen.queryByRole('button');
187
194
  expect(button).toHaveFocus();
195
+ });
196
+ test('checkbox should not have focus outline on click', function () {
197
+ getComponentWithCheckbox({
198
+ isOpen: true
199
+ });
200
+ var checkbox = screen.getByRole('checkbox');
201
+ userEvent.click(checkbox);
202
+ expect(checkbox).toBeChecked();
203
+ expect(checkbox).not.toHaveClass('is-focused');
204
+ userEvent.click(checkbox);
205
+ expect(checkbox).not.toBeChecked();
206
+ expect(checkbox).not.toHaveClass('is-focused');
188
207
  });
@@ -9,7 +9,7 @@ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
9
9
  import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
10
10
  import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
11
11
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
12
- var _excluded = ["autocomplete", "autoComplete", "autoCorrect", "children", "className", "containerProps", "controlProps", "defaultText", "defaultValue", "direction", "disabledKeys", "hasAutoFocus", "hasNoStatusIndicator", "helperText", "hintText", "id", "isDefaultSelected", "isDisabled", "isReadOnly", "isRequired", "isSelected", "label", "labelMode", "labelProps", "maxLength", "name", "onBlur", "onChange", "onClear", "onFocus", "onFocusChange", "onLoadMore", "onOpenChange", "onSelectionChange", "placeholder", "role", "selectedKey", "spellCheck", "status", "statusClasses", "type", "value"];
12
+ var _excluded = ["autocomplete", "autoComplete", "autoCorrect", "children", "className", "containerProps", "controlProps", "defaultText", "defaultValue", "direction", "disabledKeys", "hasAutoFocus", "hasNoStatusIndicator", "helperText", "hintText", "id", "isDefaultSelected", "isDisabled", "isIndeterminate", "isReadOnly", "isRequired", "isSelected", "label", "labelMode", "labelProps", "maxLength", "name", "onBlur", "onChange", "onClear", "onFocus", "onFocusChange", "onLoadMore", "onOpenChange", "onSelectionChange", "placeholder", "role", "selectedKey", "spellCheck", "status", "statusClasses", "type", "value"];
13
13
 
14
14
  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; }
15
15
 
@@ -55,6 +55,7 @@ var useField = function useField() {
55
55
  id = props.id,
56
56
  isDefaultSelected = props.isDefaultSelected,
57
57
  isDisabled = props.isDisabled,
58
+ isIndeterminate = props.isIndeterminate,
58
59
  isReadOnly = props.isReadOnly,
59
60
  isRequired = props.isRequired,
60
61
  isSelected = props.isSelected,
@@ -181,6 +182,7 @@ var useField = function useField() {
181
182
  disabled: isDisabled,
182
183
  id: id,
183
184
  isFocused: hasFocusWithin,
185
+ isIndeterminate: isIndeterminate,
184
186
  maxLength: maxLength,
185
187
  name: name,
186
188
  onChange: fieldOnChange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingux/astro",
3
- "version": "1.33.0",
3
+ "version": "1.33.1-alpha.1",
4
4
  "description": "PingUX themeable React component library",
5
5
  "repository": {
6
6
  "type": "git",