@primer/components 0.0.0-2021118165314 → 0.0.0-20211181903
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/dist/browser.esm.js +2 -2
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +2 -2
- package/dist/browser.umd.js.map +1 -1
- package/lib/Autocomplete/AutocompleteMenu.js +11 -17
- package/lib/CheckboxInputField.d.ts +11 -0
- package/lib/CheckboxInputField.js +73 -0
- package/lib/ChoiceFieldset/ChoiceFieldCaption.d.ts +3 -0
- package/lib/ChoiceFieldset/ChoiceFieldCaption.js +35 -0
- package/lib/ChoiceFieldset/ChoiceFieldLabel.d.ts +3 -0
- package/lib/ChoiceFieldset/ChoiceFieldLabel.js +35 -0
- package/lib/ChoiceFieldset/ChoiceFieldset.d.ts +65 -0
- package/lib/ChoiceFieldset/ChoiceFieldset.js +93 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetDescription.d.ts +3 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetDescription.js +29 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetLegend.d.ts +9 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetLegend.js +44 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetList.d.ts +9 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetList.js +71 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetListContext.d.ts +19 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetListContext.js +15 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetListItem.d.ts +25 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetListItem.js +75 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetValidation.d.ts +6 -0
- package/lib/ChoiceFieldset/ChoiceFieldsetValidation.js +17 -0
- package/lib/ChoiceFieldset/index.d.ts +3 -0
- package/lib/ChoiceFieldset/index.js +23 -0
- package/lib/RadioInputField.d.ts +10 -0
- package/lib/RadioInputField.js +74 -0
- package/lib/TextInputField.d.ts +583 -0
- package/lib/TextInputField.js +66 -0
- package/lib/_InputCaption.d.ts +13 -0
- package/lib/_InputCaption.js +27 -0
- package/lib/_InputField/InputField.d.ts +39 -0
- package/lib/_InputField/InputField.js +88 -0
- package/lib/_InputField/InputFieldCaption.d.ts +3 -0
- package/lib/_InputField/InputFieldCaption.js +30 -0
- package/lib/_InputField/InputFieldLabel.d.ts +9 -0
- package/lib/_InputField/InputFieldLabel.js +34 -0
- package/lib/_InputField/InputFieldValidation.d.ts +6 -0
- package/lib/_InputField/InputFieldValidation.js +17 -0
- package/lib/_InputField/ToggleInputField.d.ts +13 -0
- package/lib/_InputField/ToggleInputField.js +75 -0
- package/lib/_InputField/ToggleInputLeadingVisual.d.ts +3 -0
- package/lib/_InputField/ToggleInputLeadingVisual.js +22 -0
- package/lib/_InputField/ValidationAnimationContainer.d.ts +6 -0
- package/lib/_InputField/ValidationAnimationContainer.js +48 -0
- package/lib/_InputField/index.d.ts +1 -0
- package/lib/_InputField/index.js +15 -0
- package/lib/_InputField/slots.d.ts +13 -0
- package/lib/_InputField/slots.js +17 -0
- package/lib/_InputLabel.d.ts +8 -0
- package/lib/_InputLabel.js +45 -0
- package/lib/_InputValidation.d.ts +8 -0
- package/lib/_InputValidation.js +59 -0
- package/lib/_VisuallyHidden.d.ts +6 -0
- package/lib/_VisuallyHidden.js +39 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +38 -0
- package/lib/utils/types/FormValidationStatus.d.ts +1 -0
- package/lib/utils/types/FormValidationStatus.js +1 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.js +7 -16
- package/lib-esm/CheckboxInputField.d.ts +11 -0
- package/lib-esm/CheckboxInputField.js +56 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldCaption.d.ts +3 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldCaption.js +20 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldLabel.d.ts +3 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldLabel.js +20 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldset.d.ts +65 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldset.js +71 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetDescription.d.ts +3 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetDescription.js +17 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetLegend.d.ts +9 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetLegend.js +31 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetList.d.ts +9 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetList.js +55 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetListContext.d.ts +19 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetListContext.js +5 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetListItem.d.ts +25 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetListItem.js +51 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetValidation.d.ts +6 -0
- package/lib-esm/ChoiceFieldset/ChoiceFieldsetValidation.js +7 -0
- package/lib-esm/ChoiceFieldset/index.d.ts +3 -0
- package/lib-esm/ChoiceFieldset/index.js +2 -0
- package/lib-esm/RadioInputField.d.ts +10 -0
- package/lib-esm/RadioInputField.js +56 -0
- package/lib-esm/TextInputField.d.ts +583 -0
- package/lib-esm/TextInputField.js +50 -0
- package/lib-esm/_InputCaption.d.ts +13 -0
- package/lib-esm/_InputCaption.js +16 -0
- package/lib-esm/_InputField/InputField.d.ts +39 -0
- package/lib-esm/_InputField/InputField.js +69 -0
- package/lib-esm/_InputField/InputFieldCaption.d.ts +3 -0
- package/lib-esm/_InputField/InputFieldCaption.js +18 -0
- package/lib-esm/_InputField/InputFieldLabel.d.ts +9 -0
- package/lib-esm/_InputField/InputFieldLabel.js +22 -0
- package/lib-esm/_InputField/InputFieldValidation.d.ts +6 -0
- package/lib-esm/_InputField/InputFieldValidation.js +7 -0
- package/lib-esm/_InputField/ToggleInputField.d.ts +13 -0
- package/lib-esm/_InputField/ToggleInputField.js +58 -0
- package/lib-esm/_InputField/ToggleInputLeadingVisual.d.ts +3 -0
- package/lib-esm/_InputField/ToggleInputLeadingVisual.js +11 -0
- package/lib-esm/_InputField/ValidationAnimationContainer.d.ts +6 -0
- package/lib-esm/_InputField/ValidationAnimationContainer.js +33 -0
- package/lib-esm/_InputField/index.d.ts +1 -0
- package/lib-esm/_InputField/index.js +1 -0
- package/lib-esm/_InputField/slots.d.ts +13 -0
- package/lib-esm/_InputField/slots.js +5 -0
- package/lib-esm/_InputLabel.d.ts +8 -0
- package/lib-esm/_InputLabel.js +33 -0
- package/lib-esm/_InputValidation.d.ts +8 -0
- package/lib-esm/_InputValidation.js +46 -0
- package/lib-esm/_VisuallyHidden.d.ts +6 -0
- package/lib-esm/_VisuallyHidden.js +26 -0
- package/lib-esm/index.d.ts +4 -0
- package/lib-esm/index.js +4 -0
- package/lib-esm/utils/types/FormValidationStatus.d.ts +1 -0
- package/lib-esm/utils/types/FormValidationStatus.js +1 -0
- package/package.json +2 -2
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _octiconsReact = require("@primer/octicons-react");
|
9
|
+
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
11
|
+
|
12
|
+
var _ = require(".");
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
const validationIconMap = {
|
17
|
+
success: _octiconsReact.CheckCircleFillIcon,
|
18
|
+
error: _octiconsReact.AlertFillIcon
|
19
|
+
};
|
20
|
+
const validationColorMap = {
|
21
|
+
success: 'success.fg',
|
22
|
+
error: 'danger.fg'
|
23
|
+
};
|
24
|
+
|
25
|
+
const InputValidation = ({
|
26
|
+
children,
|
27
|
+
id,
|
28
|
+
validationStatus
|
29
|
+
}) => {
|
30
|
+
const IconComponent = validationStatus ? validationIconMap[validationStatus] : undefined;
|
31
|
+
const fgColor = validationStatus ? validationColorMap[validationStatus] : undefined;
|
32
|
+
return /*#__PURE__*/_react.default.createElement(_.Text, {
|
33
|
+
fontSize: 0,
|
34
|
+
sx: {
|
35
|
+
alignItems: 'center',
|
36
|
+
color: fgColor,
|
37
|
+
display: 'flex',
|
38
|
+
a: {
|
39
|
+
color: 'currentColor',
|
40
|
+
textDecoration: 'underline'
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}, IconComponent && /*#__PURE__*/_react.default.createElement(_.Box, {
|
44
|
+
as: "span",
|
45
|
+
mr: 1,
|
46
|
+
sx: {
|
47
|
+
display: 'flex'
|
48
|
+
}
|
49
|
+
}, /*#__PURE__*/_react.default.createElement(IconComponent, {
|
50
|
+
size: 12,
|
51
|
+
fill: "currentColor"
|
52
|
+
})), /*#__PURE__*/_react.default.createElement("span", {
|
53
|
+
id: id
|
54
|
+
}, children));
|
55
|
+
};
|
56
|
+
|
57
|
+
InputValidation.displayName = "InputValidation";
|
58
|
+
var _default = InputValidation;
|
59
|
+
exports.default = _default;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
9
|
+
|
10
|
+
var _sx = _interopRequireDefault(require("./sx"));
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
const VisuallyHidden = _styledComponents.default.span.withConfig({
|
15
|
+
displayName: "_VisuallyHidden__VisuallyHidden",
|
16
|
+
componentId: "sc-1k15c4h-0"
|
17
|
+
})(["", ""], props => {
|
18
|
+
if (props.isVisible) {
|
19
|
+
return _sx.default;
|
20
|
+
}
|
21
|
+
|
22
|
+
return `
|
23
|
+
position: absolute;
|
24
|
+
width: 1px;
|
25
|
+
height: 1px;
|
26
|
+
padding: 0;
|
27
|
+
margin: -1px;
|
28
|
+
overflow: hidden;
|
29
|
+
clip: rect(0, 0, 0, 0);
|
30
|
+
white-space: nowrap;
|
31
|
+
border-width: 0;
|
32
|
+
`;
|
33
|
+
});
|
34
|
+
|
35
|
+
VisuallyHidden.defaultProps = {
|
36
|
+
isVisible: true
|
37
|
+
};
|
38
|
+
var _default = VisuallyHidden;
|
39
|
+
exports.default = _default;
|
package/lib/index.d.ts
CHANGED
@@ -48,6 +48,8 @@ export { default as CircleBadge } from './CircleBadge';
|
|
48
48
|
export type { CircleBadgeProps, CircleBadgeIconProps } from './CircleBadge';
|
49
49
|
export { default as CircleOcticon } from './CircleOcticon';
|
50
50
|
export type { CircleOcticonProps } from './CircleOcticon';
|
51
|
+
export { default as CheckboxInputField } from './CheckboxInputField';
|
52
|
+
export { default as ChoiceFieldset, Item } from './ChoiceFieldset';
|
51
53
|
export { default as CounterLabel } from './CounterLabel';
|
52
54
|
export type { CounterLabelProps } from './CounterLabel';
|
53
55
|
export { default as Details } from './Details';
|
@@ -88,6 +90,7 @@ export { default as Popover } from './Popover';
|
|
88
90
|
export type { PopoverProps, PopoverContentProps } from './Popover';
|
89
91
|
export { default as ProgressBar } from './ProgressBar';
|
90
92
|
export type { ProgressBarProps } from './ProgressBar';
|
93
|
+
export { default as RadioInputField } from './RadioInputField';
|
91
94
|
export { default as SelectMenu } from './SelectMenu';
|
92
95
|
export type { SelectMenuProps, SelectMenuDividerProps, SelectMenuFilterProps, SelectMenuFooterProps, SelectMenuItemProps, SelectMenuListProps, SelectMenuModalProps, SelectMenuTabsProps, SelectMenuHeaderProps, SelectMenuTabProps, SelectMenuTabPanelProps, SelectMenuLoadingAnimationProps } from './SelectMenu';
|
93
96
|
export { default as SideNav } from './SideNav';
|
@@ -104,6 +107,7 @@ export { default as TabNav } from './TabNav';
|
|
104
107
|
export type { TabNavProps, TabNavLinkProps } from './TabNav';
|
105
108
|
export { default as TextInput } from './TextInput';
|
106
109
|
export type { TextInputProps } from './TextInput';
|
110
|
+
export { default as TextInputField } from './TextInputField';
|
107
111
|
export { default as TextInputWithTokens } from './TextInputWithTokens';
|
108
112
|
export type { TextInputWithTokensProps } from './TextInputWithTokens';
|
109
113
|
export { default as Text } from './Text';
|
package/lib/index.js
CHANGED
@@ -273,6 +273,24 @@ Object.defineProperty(exports, "CircleOcticon", {
|
|
273
273
|
return _CircleOcticon.default;
|
274
274
|
}
|
275
275
|
});
|
276
|
+
Object.defineProperty(exports, "CheckboxInputField", {
|
277
|
+
enumerable: true,
|
278
|
+
get: function () {
|
279
|
+
return _CheckboxInputField.default;
|
280
|
+
}
|
281
|
+
});
|
282
|
+
Object.defineProperty(exports, "ChoiceFieldset", {
|
283
|
+
enumerable: true,
|
284
|
+
get: function () {
|
285
|
+
return _ChoiceFieldset.default;
|
286
|
+
}
|
287
|
+
});
|
288
|
+
Object.defineProperty(exports, "Item", {
|
289
|
+
enumerable: true,
|
290
|
+
get: function () {
|
291
|
+
return _ChoiceFieldset.Item;
|
292
|
+
}
|
293
|
+
});
|
276
294
|
Object.defineProperty(exports, "CounterLabel", {
|
277
295
|
enumerable: true,
|
278
296
|
get: function () {
|
@@ -399,6 +417,12 @@ Object.defineProperty(exports, "ProgressBar", {
|
|
399
417
|
return _ProgressBar.default;
|
400
418
|
}
|
401
419
|
});
|
420
|
+
Object.defineProperty(exports, "RadioInputField", {
|
421
|
+
enumerable: true,
|
422
|
+
get: function () {
|
423
|
+
return _RadioInputField.default;
|
424
|
+
}
|
425
|
+
});
|
402
426
|
Object.defineProperty(exports, "SelectMenu", {
|
403
427
|
enumerable: true,
|
404
428
|
get: function () {
|
@@ -447,6 +471,12 @@ Object.defineProperty(exports, "TextInput", {
|
|
447
471
|
return _TextInput.default;
|
448
472
|
}
|
449
473
|
});
|
474
|
+
Object.defineProperty(exports, "TextInputField", {
|
475
|
+
enumerable: true,
|
476
|
+
get: function () {
|
477
|
+
return _TextInputField.default;
|
478
|
+
}
|
479
|
+
});
|
450
480
|
Object.defineProperty(exports, "TextInputWithTokens", {
|
451
481
|
enumerable: true,
|
452
482
|
get: function () {
|
@@ -580,6 +610,10 @@ var _CircleBadge = _interopRequireDefault(require("./CircleBadge"));
|
|
580
610
|
|
581
611
|
var _CircleOcticon = _interopRequireDefault(require("./CircleOcticon"));
|
582
612
|
|
613
|
+
var _CheckboxInputField = _interopRequireDefault(require("./CheckboxInputField"));
|
614
|
+
|
615
|
+
var _ChoiceFieldset = _interopRequireWildcard(require("./ChoiceFieldset"));
|
616
|
+
|
583
617
|
var _CounterLabel = _interopRequireDefault(require("./CounterLabel"));
|
584
618
|
|
585
619
|
var _Details = _interopRequireDefault(require("./Details"));
|
@@ -620,6 +654,8 @@ var _Popover = _interopRequireDefault(require("./Popover"));
|
|
620
654
|
|
621
655
|
var _ProgressBar = _interopRequireDefault(require("./ProgressBar"));
|
622
656
|
|
657
|
+
var _RadioInputField = _interopRequireDefault(require("./RadioInputField"));
|
658
|
+
|
623
659
|
var _SelectMenu = _interopRequireDefault(require("./SelectMenu"));
|
624
660
|
|
625
661
|
var _SideNav = _interopRequireDefault(require("./SideNav"));
|
@@ -636,6 +672,8 @@ var _TabNav = _interopRequireDefault(require("./TabNav"));
|
|
636
672
|
|
637
673
|
var _TextInput = _interopRequireDefault(require("./TextInput"));
|
638
674
|
|
675
|
+
var _TextInputField = _interopRequireDefault(require("./TextInputField"));
|
676
|
+
|
639
677
|
var _TextInputWithTokens = _interopRequireDefault(require("./TextInputWithTokens"));
|
640
678
|
|
641
679
|
var _Text = _interopRequireDefault(require("./Text"));
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare type FormValidationStatus = 'error' | 'success';
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
@@ -4,8 +4,9 @@ import { useFocusZone } from '../hooks/useFocusZone';
|
|
4
4
|
import { Box, Spinner } from '../';
|
5
5
|
import { AutocompleteContext } from './AutocompleteContext';
|
6
6
|
import { PlusIcon } from '@primer/octicons-react';
|
7
|
-
import { uniqueId } from '../utils/uniqueId';
|
8
7
|
import { scrollIntoViewingArea } from '../behaviors/scrollIntoViewingArea';
|
8
|
+
import VisuallyHidden from '../_VisuallyHidden';
|
9
|
+
import { useSSRSafeId } from '@react-aria/ssr';
|
9
10
|
|
10
11
|
const getDefaultSortFn = isItemSelectedFn => (itemIdA, itemIdB) => isItemSelectedFn(itemIdA) === isItemSelectedFn(itemIdB) ? 0 : isItemSelectedFn(itemIdA) ? -1 : 1;
|
11
12
|
|
@@ -72,6 +73,7 @@ function AutocompleteMenu(props) {
|
|
72
73
|
const [sortedItemIds, setSortedItemIds] = useState(items.map(({
|
73
74
|
id: itemId
|
74
75
|
}) => itemId));
|
76
|
+
const generatedUniqueId = useSSRSafeId(id);
|
75
77
|
const selectableItems = useMemo(() => items.map(selectableItem => {
|
76
78
|
return { ...selectableItem,
|
77
79
|
role: 'option',
|
@@ -107,7 +109,7 @@ function AutocompleteMenu(props) {
|
|
107
109
|
onAction: item => {
|
108
110
|
// TODO: make it possible to pass a leadingVisual when using `addNewItem`
|
109
111
|
addNewItem.handleAddItem({ ...item,
|
110
|
-
id: item.id ||
|
112
|
+
id: item.id || generatedUniqueId,
|
111
113
|
leadingVisual: undefined
|
112
114
|
});
|
113
115
|
|
@@ -116,7 +118,7 @@ function AutocompleteMenu(props) {
|
|
116
118
|
setAutocompleteSuggestion('');
|
117
119
|
}
|
118
120
|
}
|
119
|
-
}] : [])], [sortedAndFilteredItemsToRender, addNewItem, setAutocompleteSuggestion, selectionVariant, setInputValue]);
|
121
|
+
}] : [])], [sortedAndFilteredItemsToRender, addNewItem, setAutocompleteSuggestion, selectionVariant, setInputValue, generatedUniqueId]);
|
120
122
|
useFocusZone({
|
121
123
|
containerRef: listContainerRef,
|
122
124
|
focusOutBehavior: 'wrap',
|
@@ -164,19 +166,8 @@ function AutocompleteMenu(props) {
|
|
164
166
|
setSelectedItemLength(selectedItemIds.length);
|
165
167
|
}
|
166
168
|
}, [selectedItemIds, setSelectedItemLength]);
|
167
|
-
return /*#__PURE__*/React.createElement(
|
168
|
-
|
169
|
-
// visually hides this label for sighted users
|
170
|
-
position: 'absolute',
|
171
|
-
width: '1px',
|
172
|
-
height: '1px',
|
173
|
-
padding: '0',
|
174
|
-
margin: '-1px',
|
175
|
-
overflow: 'hidden',
|
176
|
-
clip: 'rect(0, 0, 0, 0)',
|
177
|
-
whiteSpace: 'nowrap',
|
178
|
-
borderWidth: '0'
|
179
|
-
} : {}
|
169
|
+
return /*#__PURE__*/React.createElement(VisuallyHidden, {
|
170
|
+
isVisible: showMenu
|
180
171
|
}, loading ? /*#__PURE__*/React.createElement(Box, {
|
181
172
|
p: 3,
|
182
173
|
display: "flex",
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { ToggleInputFieldProps } from './_InputField/ToggleInputField';
|
3
|
+
declare const _default: React.FC<ToggleInputFieldProps> & {
|
4
|
+
Input: React.FC<React.HTMLProps<HTMLInputElement> & {
|
5
|
+
ref?: React.Ref<HTMLInputElement> | undefined;
|
6
|
+
}>;
|
7
|
+
Caption: React.FC<{}>;
|
8
|
+
Label: React.FC<import("./_InputField/InputFieldLabel").Props>;
|
9
|
+
LeadingVisual: React.FC<{}>;
|
10
|
+
};
|
11
|
+
export default _default;
|
@@ -0,0 +1,56 @@
|
|
1
|
+
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); }
|
2
|
+
|
3
|
+
import React from 'react';
|
4
|
+
import { Checkbox } from '.';
|
5
|
+
import InputField from './_InputField/InputField';
|
6
|
+
import { Slot } from './_InputField/slots';
|
7
|
+
import ToggleInputField from './_InputField/ToggleInputField';
|
8
|
+
import ToggleInputLeadingVisual from './_InputField/ToggleInputLeadingVisual';
|
9
|
+
|
10
|
+
const Input = ({
|
11
|
+
id: idProp,
|
12
|
+
required: requiredProp,
|
13
|
+
disabled: disabledProp,
|
14
|
+
...rest
|
15
|
+
}) => {
|
16
|
+
if (idProp) {
|
17
|
+
// eslint-disable-next-line no-console
|
18
|
+
console.warn("instead of passing the 'id' prop directly to <TextInputField.Input>, it should be passed to the parent component, <TextInputField>");
|
19
|
+
}
|
20
|
+
|
21
|
+
if (disabledProp) {
|
22
|
+
// eslint-disable-next-line no-console
|
23
|
+
console.warn("instead of passing the 'disabled' prop directly to <TextInputField.Input>, it should be passed to the parent component, <TextInputField>");
|
24
|
+
}
|
25
|
+
|
26
|
+
if (requiredProp) {
|
27
|
+
// eslint-disable-next-line no-console
|
28
|
+
console.warn("instead of passing the 'required' prop directly to <TextInputField.Input>, it should be passed to the parent component, <TextInputField>");
|
29
|
+
}
|
30
|
+
|
31
|
+
return /*#__PURE__*/React.createElement(Slot, {
|
32
|
+
name: "Input"
|
33
|
+
}, ({
|
34
|
+
disabled,
|
35
|
+
id,
|
36
|
+
required,
|
37
|
+
captionId
|
38
|
+
}) => /*#__PURE__*/React.createElement(Checkbox, _extends({
|
39
|
+
"aria-describedby": captionId,
|
40
|
+
id: id,
|
41
|
+
required: required,
|
42
|
+
disabled: disabled
|
43
|
+
}, rest)));
|
44
|
+
};
|
45
|
+
|
46
|
+
Input.displayName = "Input";
|
47
|
+
|
48
|
+
const CheckboxInputField = props => /*#__PURE__*/React.createElement(ToggleInputField, props);
|
49
|
+
|
50
|
+
CheckboxInputField.displayName = "CheckboxInputField";
|
51
|
+
export default Object.assign(CheckboxInputField, {
|
52
|
+
Input,
|
53
|
+
Caption: InputField.Caption,
|
54
|
+
Label: InputField.Label,
|
55
|
+
LeadingVisual: ToggleInputLeadingVisual
|
56
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import React, { useContext } from 'react';
|
2
|
+
import ChoiceFieldsetListContext from './ChoiceFieldsetListContext';
|
3
|
+
|
4
|
+
const ChoiceFieldCaption = ({
|
5
|
+
children
|
6
|
+
}) => {
|
7
|
+
const choiceFieldsetListContext = useContext(ChoiceFieldsetListContext);
|
8
|
+
|
9
|
+
if (choiceFieldsetListContext === null) {
|
10
|
+
throw new Error('ChoiceFieldsetListContext returned null');
|
11
|
+
}
|
12
|
+
|
13
|
+
const {
|
14
|
+
fieldComponent: FieldComponent
|
15
|
+
} = choiceFieldsetListContext;
|
16
|
+
return /*#__PURE__*/React.createElement(FieldComponent.Caption, null, children);
|
17
|
+
};
|
18
|
+
|
19
|
+
ChoiceFieldCaption.displayName = "ChoiceFieldCaption";
|
20
|
+
export default ChoiceFieldCaption;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import React, { useContext } from 'react';
|
2
|
+
import ChoiceFieldsetListContext from './ChoiceFieldsetListContext';
|
3
|
+
|
4
|
+
const ChoiceFieldLabel = ({
|
5
|
+
children
|
6
|
+
}) => {
|
7
|
+
const choiceFieldsetListContext = useContext(ChoiceFieldsetListContext);
|
8
|
+
|
9
|
+
if (choiceFieldsetListContext === null) {
|
10
|
+
throw new Error('ChoiceFieldsetListContext returned null');
|
11
|
+
}
|
12
|
+
|
13
|
+
const {
|
14
|
+
fieldComponent: FieldComponent
|
15
|
+
} = choiceFieldsetListContext;
|
16
|
+
return /*#__PURE__*/React.createElement(FieldComponent.Label, null, children);
|
17
|
+
};
|
18
|
+
|
19
|
+
ChoiceFieldLabel.displayName = "ChoiceFieldLabel";
|
20
|
+
export default ChoiceFieldLabel;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
2
|
+
import { FormValidationStatus } from '../utils/types/FormValidationStatus';
|
3
|
+
export interface ChoiceFieldsetProps<T = Record<string, FormValidationStatus>> {
|
4
|
+
children?: React.ReactNode;
|
5
|
+
/**
|
6
|
+
* Whether the fieldset is NOT ready for user input
|
7
|
+
*/
|
8
|
+
disabled?: boolean;
|
9
|
+
/**
|
10
|
+
* The unique identifier for this fieldset. Used to associate the validation text with the fieldset
|
11
|
+
* If an ID is not passed, one will be automatically generated
|
12
|
+
*/
|
13
|
+
id?: string;
|
14
|
+
/**
|
15
|
+
* The unique identifier used to associate radio inputs with eachother
|
16
|
+
* If a name is not passed and the fieldset renders radio inputs, a name will be automatically generated
|
17
|
+
*/
|
18
|
+
name?: string;
|
19
|
+
/**
|
20
|
+
* The callback that is called when a user toggles a choice on or off
|
21
|
+
*/
|
22
|
+
onSelect?: (selectedValues: string[]) => void;
|
23
|
+
/**
|
24
|
+
* Whether this field must have a value for the user to complete their task
|
25
|
+
*/
|
26
|
+
required?: boolean;
|
27
|
+
/**
|
28
|
+
* The selected values
|
29
|
+
*/
|
30
|
+
selected?: string[];
|
31
|
+
/**
|
32
|
+
* A map of validation statuses and their associated validation keys. When one of the validation keys is passed to the `validationResult` prop,
|
33
|
+
* the associated validation message will be rendered in the correct style
|
34
|
+
*/
|
35
|
+
validationMap?: T;
|
36
|
+
/**
|
37
|
+
* The key of the validation message to show
|
38
|
+
*/
|
39
|
+
validationResult?: keyof T;
|
40
|
+
}
|
41
|
+
export interface ChoiceFieldsetContext extends ChoiceFieldsetProps {
|
42
|
+
validationMessageId: string;
|
43
|
+
}
|
44
|
+
declare const Slot: React.FC<{
|
45
|
+
name: "Description" | "ChoiceList" | "Legend" | "Validation";
|
46
|
+
children: React.ReactNode;
|
47
|
+
}>;
|
48
|
+
export { Slot };
|
49
|
+
declare const ChoiceFieldset: <T extends Record<string, FormValidationStatus>>({ children, disabled, id, name, onSelect, required, selected, validationMap, validationResult }: ChoiceFieldsetProps<T>) => JSX.Element;
|
50
|
+
export declare type InputFieldComponentProps = ComponentProps<typeof ChoiceFieldset>;
|
51
|
+
export type { ChoiceFieldsetListProps } from './ChoiceFieldsetList';
|
52
|
+
export type { ChoiceFieldsetLegendProps } from './ChoiceFieldsetLegend';
|
53
|
+
export type { ChoiceFieldProps } from './ChoiceFieldsetListItem';
|
54
|
+
declare const _default: (<T extends Record<string, FormValidationStatus>>({ children, disabled, id, name, onSelect, required, selected, validationMap, validationResult }: ChoiceFieldsetProps<T>) => JSX.Element) & {
|
55
|
+
Description: React.FC<{}>;
|
56
|
+
Item: React.FC<import("./ChoiceFieldsetListItem").ChoiceFieldProps> & {
|
57
|
+
Caption: React.FC<{}>;
|
58
|
+
Label: React.FC<{}>;
|
59
|
+
LeadingVisual: React.FC<{}>;
|
60
|
+
};
|
61
|
+
Legend: React.FC<import("./ChoiceFieldsetLegend").ChoiceFieldsetLegendProps>;
|
62
|
+
List: React.FC<import("./ChoiceFieldsetList").ChoiceFieldsetListProps>;
|
63
|
+
Validation: React.FC<import("./ChoiceFieldsetValidation").ChoiceFieldsetValidationProps>;
|
64
|
+
};
|
65
|
+
export default _default;
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { Box, useSSRSafeId } from '..';
|
3
|
+
import createSlots from '../utils/create-slots';
|
4
|
+
import ValidationAnimationContainer from '../_InputField/ValidationAnimationContainer';
|
5
|
+
import InputValidation from '../_InputValidation';
|
6
|
+
import ChoiceFieldsetListItem from './ChoiceFieldsetListItem';
|
7
|
+
import ChoiceFieldsetDescription from './ChoiceFieldsetDescription';
|
8
|
+
import ChoiceFieldsetLegend from './ChoiceFieldsetLegend';
|
9
|
+
import ChoiceFieldsetList from './ChoiceFieldsetList';
|
10
|
+
import ChoiceFieldsetValidation from './ChoiceFieldsetValidation';
|
11
|
+
const {
|
12
|
+
Slots,
|
13
|
+
Slot
|
14
|
+
} = createSlots(['Description', 'ChoiceList', 'Legend', 'Validation']);
|
15
|
+
export { Slot };
|
16
|
+
|
17
|
+
const ChoiceFieldset = ({
|
18
|
+
children,
|
19
|
+
disabled,
|
20
|
+
id,
|
21
|
+
name,
|
22
|
+
onSelect,
|
23
|
+
required,
|
24
|
+
selected,
|
25
|
+
validationMap,
|
26
|
+
validationResult
|
27
|
+
}) => {
|
28
|
+
var _React$Children$map;
|
29
|
+
|
30
|
+
const fieldsetId = useSSRSafeId(id);
|
31
|
+
const validationChildren = (_React$Children$map = React.Children.map(children, child => /*#__PURE__*/React.isValidElement(child) && child.type === ChoiceFieldsetValidation ? child : null)) === null || _React$Children$map === void 0 ? void 0 : _React$Children$map.filter(Boolean);
|
32
|
+
const validationChildToRender = validationChildren === null || validationChildren === void 0 ? void 0 : validationChildren.find(child => child.props.validationKey === validationResult);
|
33
|
+
const validationMessageId = validationChildToRender ? `${fieldsetId}-validationMsg` : undefined;
|
34
|
+
return /*#__PURE__*/React.createElement(Slots, {
|
35
|
+
context: {
|
36
|
+
disabled,
|
37
|
+
name,
|
38
|
+
onSelect,
|
39
|
+
required,
|
40
|
+
selected,
|
41
|
+
validationMessageId
|
42
|
+
}
|
43
|
+
}, slots => {
|
44
|
+
const isLegendVisible = /*#__PURE__*/React.isValidElement(slots.Legend) && slots.Legend.props.isVisible;
|
45
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Box, {
|
46
|
+
as: "fieldset",
|
47
|
+
border: "none",
|
48
|
+
margin: 0,
|
49
|
+
padding: 0,
|
50
|
+
"aria-describedby": [validationMessageId].filter(Boolean).join(' ')
|
51
|
+
}, React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child) && child.type !== ChoiceFieldsetValidation), /*#__PURE__*/React.createElement(Box, {
|
52
|
+
mb: isLegendVisible ? 3 : undefined
|
53
|
+
}, slots.Legend, slots.Description), slots.ChoiceList), validationChildToRender && /*#__PURE__*/React.createElement(Box, {
|
54
|
+
mt: 3
|
55
|
+
}, validationMap && validationResult && validationMessageId && /*#__PURE__*/React.createElement(ValidationAnimationContainer, {
|
56
|
+
show: true
|
57
|
+
}, /*#__PURE__*/React.createElement(InputValidation, {
|
58
|
+
validationStatus: validationMap[validationResult],
|
59
|
+
id: validationMessageId
|
60
|
+
}, validationChildToRender))));
|
61
|
+
});
|
62
|
+
};
|
63
|
+
|
64
|
+
ChoiceFieldset.displayName = "ChoiceFieldset";
|
65
|
+
export default Object.assign(ChoiceFieldset, {
|
66
|
+
Description: ChoiceFieldsetDescription,
|
67
|
+
Item: ChoiceFieldsetListItem,
|
68
|
+
Legend: ChoiceFieldsetLegend,
|
69
|
+
List: ChoiceFieldsetList,
|
70
|
+
Validation: ChoiceFieldsetValidation
|
71
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { Text } from '..';
|
3
|
+
import { Slot } from './ChoiceFieldset';
|
4
|
+
|
5
|
+
const ChoiceFieldsetDescription = ({
|
6
|
+
children
|
7
|
+
}) => /*#__PURE__*/React.createElement(Slot, {
|
8
|
+
name: "Description"
|
9
|
+
}, ({
|
10
|
+
disabled
|
11
|
+
}) => /*#__PURE__*/React.createElement(Text, {
|
12
|
+
color: disabled ? 'fg.muted' : 'fg.default',
|
13
|
+
fontSize: 1
|
14
|
+
}, children));
|
15
|
+
|
16
|
+
ChoiceFieldsetDescription.displayName = "ChoiceFieldsetDescription";
|
17
|
+
export default ChoiceFieldsetDescription;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export interface ChoiceFieldsetLegendProps {
|
3
|
+
/**
|
4
|
+
* Whether to visually hide the fieldset legend
|
5
|
+
*/
|
6
|
+
visuallyHidden?: boolean;
|
7
|
+
}
|
8
|
+
declare const ChoiceFieldsetLegend: React.FC<ChoiceFieldsetLegendProps>;
|
9
|
+
export default ChoiceFieldsetLegend;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { Box } from '..';
|
3
|
+
import VisuallyHidden from '../_VisuallyHidden';
|
4
|
+
import { Slot } from './ChoiceFieldset';
|
5
|
+
|
6
|
+
const ChoiceFieldsetLegend = ({
|
7
|
+
children,
|
8
|
+
visuallyHidden
|
9
|
+
}) => /*#__PURE__*/React.createElement(Slot, {
|
10
|
+
name: "Legend"
|
11
|
+
}, ({
|
12
|
+
required,
|
13
|
+
disabled
|
14
|
+
}) => /*#__PURE__*/React.createElement(VisuallyHidden, {
|
15
|
+
as: "legend",
|
16
|
+
isVisible: !visuallyHidden,
|
17
|
+
title: required ? 'required field' : undefined,
|
18
|
+
sx: {
|
19
|
+
color: disabled ? 'fg.muted' : undefined,
|
20
|
+
fontSize: 2,
|
21
|
+
padding: 0
|
22
|
+
}
|
23
|
+
}, required ? /*#__PURE__*/React.createElement(Box, {
|
24
|
+
display: "flex",
|
25
|
+
as: "span"
|
26
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
27
|
+
mr: 1
|
28
|
+
}, children), /*#__PURE__*/React.createElement("span", null, "*")) : children));
|
29
|
+
|
30
|
+
ChoiceFieldsetLegend.displayName = "ChoiceFieldsetLegend";
|
31
|
+
export default ChoiceFieldsetLegend;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export interface ChoiceFieldsetListProps {
|
3
|
+
/**
|
4
|
+
* Whether multiple items or a single item can be selected
|
5
|
+
*/
|
6
|
+
selectionVariant?: 'single' | 'multiple';
|
7
|
+
}
|
8
|
+
declare const ChoiceFieldsetList: React.FC<ChoiceFieldsetListProps>;
|
9
|
+
export default ChoiceFieldsetList;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import styled from 'styled-components';
|
3
|
+
import { CheckboxInputField, RadioInputField, useSSRSafeId } from '..';
|
4
|
+
import { get } from '../constants';
|
5
|
+
import { Slot } from './ChoiceFieldset';
|
6
|
+
import ChoiceFieldsetListContext from './ChoiceFieldsetListContext';
|
7
|
+
const List = styled.ul.withConfig({
|
8
|
+
displayName: "ChoiceFieldsetList__List",
|
9
|
+
componentId: "sc-16da7ba-0"
|
10
|
+
})(["display:flex;flex-direction:column;list-style:none;margin:0;padding:0;> li + li{margin-top:", ";}"], get('space.2'));
|
11
|
+
|
12
|
+
const getSelectedCheckboxes = (value, checked, selectedValues, selectionVariant) => {
|
13
|
+
if (checked) {
|
14
|
+
return selectionVariant === 'multiple' ? [...selectedValues, value] : [value];
|
15
|
+
}
|
16
|
+
|
17
|
+
return selectedValues.filter(selectedValue => selectedValue !== value);
|
18
|
+
};
|
19
|
+
|
20
|
+
const ChoiceFieldsetList = ({
|
21
|
+
selectionVariant,
|
22
|
+
children
|
23
|
+
}) => {
|
24
|
+
const ssrSafeUniqueName = useSSRSafeId();
|
25
|
+
return /*#__PURE__*/React.createElement(Slot, {
|
26
|
+
name: "ChoiceList"
|
27
|
+
}, ({
|
28
|
+
name,
|
29
|
+
onSelect,
|
30
|
+
disabled,
|
31
|
+
selected = []
|
32
|
+
}) => {
|
33
|
+
return /*#__PURE__*/React.createElement(ChoiceFieldsetListContext.Provider, {
|
34
|
+
value: {
|
35
|
+
disabled,
|
36
|
+
selected,
|
37
|
+
name: name || ssrSafeUniqueName,
|
38
|
+
fieldComponent: selectionVariant === 'multiple' ? CheckboxInputField : RadioInputField,
|
39
|
+
onChange: e => {
|
40
|
+
const updatedSelections = getSelectedCheckboxes(e.currentTarget.value, e.currentTarget.checked, selected, selectionVariant);
|
41
|
+
onSelect && onSelect(updatedSelections);
|
42
|
+
},
|
43
|
+
selectionVariant
|
44
|
+
}
|
45
|
+
}, /*#__PURE__*/React.createElement(List, null, React.Children.map(children, (child, i) => /*#__PURE__*/React.createElement("li", {
|
46
|
+
key: i
|
47
|
+
}, child))));
|
48
|
+
});
|
49
|
+
};
|
50
|
+
|
51
|
+
ChoiceFieldsetList.displayName = "ChoiceFieldsetList";
|
52
|
+
ChoiceFieldsetList.defaultProps = {
|
53
|
+
selectionVariant: 'single'
|
54
|
+
};
|
55
|
+
export default ChoiceFieldsetList;
|