@primer/components 0.0.0-2021116163027 → 0.0.0-2021116181214

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.
Files changed (59) hide show
  1. package/dist/browser.esm.js +2 -2
  2. package/dist/browser.esm.js.map +1 -1
  3. package/dist/browser.umd.js +2 -2
  4. package/dist/browser.umd.js.map +1 -1
  5. package/lib/CheckboxInputField.d.ts +3 -2
  6. package/lib/ChoiceFieldset/ChoiceFieldCaption.d.ts +3 -0
  7. package/lib/ChoiceFieldset/ChoiceFieldCaption.js +35 -0
  8. package/lib/ChoiceFieldset/ChoiceFieldLabel.d.ts +3 -0
  9. package/lib/ChoiceFieldset/ChoiceFieldLabel.js +35 -0
  10. package/lib/ChoiceFieldset/ChoiceFieldset.d.ts +65 -0
  11. package/lib/ChoiceFieldset/ChoiceFieldset.js +95 -0
  12. package/lib/ChoiceFieldset/ChoiceFieldsetDescription.d.ts +3 -0
  13. package/lib/ChoiceFieldset/ChoiceFieldsetDescription.js +29 -0
  14. package/lib/ChoiceFieldset/ChoiceFieldsetLegend.d.ts +9 -0
  15. package/lib/ChoiceFieldset/ChoiceFieldsetLegend.js +44 -0
  16. package/lib/ChoiceFieldset/ChoiceFieldsetList.d.ts +9 -0
  17. package/lib/ChoiceFieldset/ChoiceFieldsetList.js +69 -0
  18. package/lib/ChoiceFieldset/ChoiceFieldsetListContext.d.ts +19 -0
  19. package/lib/ChoiceFieldset/ChoiceFieldsetListContext.js +15 -0
  20. package/lib/ChoiceFieldset/ChoiceFieldsetListItem.d.ts +25 -0
  21. package/lib/ChoiceFieldset/ChoiceFieldsetListItem.js +75 -0
  22. package/lib/ChoiceFieldset/ChoiceFieldsetValidation.d.ts +6 -0
  23. package/lib/ChoiceFieldset/ChoiceFieldsetValidation.js +17 -0
  24. package/lib/ChoiceFieldset/index.d.ts +3 -0
  25. package/lib/ChoiceFieldset/index.js +23 -0
  26. package/lib/RadioInputField.d.ts +4 -2
  27. package/lib/RadioInputField.js +3 -11
  28. package/lib/_InputCaption.js +1 -0
  29. package/lib/_InputField/ToggleInputField.d.ts +2 -2
  30. package/lib/index.d.ts +1 -0
  31. package/lib/index.js +14 -0
  32. package/lib-esm/CheckboxInputField.d.ts +3 -2
  33. package/lib-esm/ChoiceFieldset/ChoiceFieldCaption.d.ts +3 -0
  34. package/lib-esm/ChoiceFieldset/ChoiceFieldCaption.js +20 -0
  35. package/lib-esm/ChoiceFieldset/ChoiceFieldLabel.d.ts +3 -0
  36. package/lib-esm/ChoiceFieldset/ChoiceFieldLabel.js +20 -0
  37. package/lib-esm/ChoiceFieldset/ChoiceFieldset.d.ts +65 -0
  38. package/lib-esm/ChoiceFieldset/ChoiceFieldset.js +72 -0
  39. package/lib-esm/ChoiceFieldset/ChoiceFieldsetDescription.d.ts +3 -0
  40. package/lib-esm/ChoiceFieldset/ChoiceFieldsetDescription.js +17 -0
  41. package/lib-esm/ChoiceFieldset/ChoiceFieldsetLegend.d.ts +9 -0
  42. package/lib-esm/ChoiceFieldset/ChoiceFieldsetLegend.js +31 -0
  43. package/lib-esm/ChoiceFieldset/ChoiceFieldsetList.d.ts +9 -0
  44. package/lib-esm/ChoiceFieldset/ChoiceFieldsetList.js +52 -0
  45. package/lib-esm/ChoiceFieldset/ChoiceFieldsetListContext.d.ts +19 -0
  46. package/lib-esm/ChoiceFieldset/ChoiceFieldsetListContext.js +5 -0
  47. package/lib-esm/ChoiceFieldset/ChoiceFieldsetListItem.d.ts +25 -0
  48. package/lib-esm/ChoiceFieldset/ChoiceFieldsetListItem.js +51 -0
  49. package/lib-esm/ChoiceFieldset/ChoiceFieldsetValidation.d.ts +6 -0
  50. package/lib-esm/ChoiceFieldset/ChoiceFieldsetValidation.js +7 -0
  51. package/lib-esm/ChoiceFieldset/index.d.ts +3 -0
  52. package/lib-esm/ChoiceFieldset/index.js +2 -0
  53. package/lib-esm/RadioInputField.d.ts +4 -2
  54. package/lib-esm/RadioInputField.js +3 -12
  55. package/lib-esm/_InputCaption.js +1 -0
  56. package/lib-esm/_InputField/ToggleInputField.d.ts +2 -2
  57. package/lib-esm/index.d.ts +1 -0
  58. package/lib-esm/index.js +1 -0
  59. package/package.json +1 -1
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
+ var _ = require(".");
11
+
10
12
  var _InputField = _interopRequireDefault(require("./_InputField/InputField"));
11
13
 
12
14
  var _slots = require("./_InputField/slots");
@@ -19,16 +21,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
21
 
20
22
  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); }
21
23
 
22
- // TODO: use Primer's checkbox input once it's available
23
- // https://github.com/github/primer/issues/489
24
- const RadioInput = props => {
25
- return /*#__PURE__*/_react.default.createElement("input", _extends({
26
- type: "radio"
27
- }, props));
28
- };
29
-
30
- RadioInput.displayName = "RadioInput";
31
-
32
24
  // pulling out `id`, `disabled`, and `required` because those should come from the parent TextInputField component
33
25
  const Input = ({
34
26
  id: idProp,
@@ -58,7 +50,7 @@ const Input = ({
58
50
  id,
59
51
  required,
60
52
  captionId
61
- }) => /*#__PURE__*/_react.default.createElement(RadioInput, _extends({
53
+ }) => /*#__PURE__*/_react.default.createElement(_.Radio, _extends({
62
54
  "aria-describedby": captionId,
63
55
  id: id,
64
56
  required: required,
@@ -17,6 +17,7 @@ const InputCaption = ({
17
17
  id
18
18
  }) => /*#__PURE__*/_react.default.createElement(_.Text, {
19
19
  color: disabled ? 'fg.subtle' : 'fg.muted',
20
+ display: "block",
20
21
  fontSize: 0,
21
22
  id: id
22
23
  }, children);
@@ -1,13 +1,13 @@
1
1
  import React from 'react';
2
2
  import { Props as InputFieldProps } from './InputField';
3
3
  import { FormValidationStatus } from '../utils/types/FormValidationStatus';
4
- export interface Props extends Pick<InputFieldProps, 'disabled' | 'id'> {
4
+ export interface ToggleInputFieldProps extends Pick<InputFieldProps, 'disabled' | 'id'> {
5
5
  /**
6
6
  * Styles the field to visually communicate the result of form validation
7
7
  */
8
8
  validationStatus?: FormValidationStatus;
9
9
  }
10
- declare const _default: React.FC<Props> & {
10
+ declare const _default: React.FC<ToggleInputFieldProps> & {
11
11
  LeadingVisual: React.FC<{}>;
12
12
  };
13
13
  export default _default;
package/lib/index.d.ts CHANGED
@@ -49,6 +49,7 @@ export type { CircleBadgeProps, CircleBadgeIconProps } from './CircleBadge';
49
49
  export { default as CircleOcticon } from './CircleOcticon';
50
50
  export type { CircleOcticonProps } from './CircleOcticon';
51
51
  export { default as CheckboxInputField } from './CheckboxInputField';
52
+ export { default as ChoiceFieldset, Item } from './ChoiceFieldset';
52
53
  export { default as CounterLabel } from './CounterLabel';
53
54
  export type { CounterLabelProps } from './CounterLabel';
54
55
  export { default as Details } from './Details';
package/lib/index.js CHANGED
@@ -279,6 +279,18 @@ Object.defineProperty(exports, "CheckboxInputField", {
279
279
  return _CheckboxInputField.default;
280
280
  }
281
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
+ });
282
294
  Object.defineProperty(exports, "CounterLabel", {
283
295
  enumerable: true,
284
296
  get: function () {
@@ -600,6 +612,8 @@ var _CircleOcticon = _interopRequireDefault(require("./CircleOcticon"));
600
612
 
601
613
  var _CheckboxInputField = _interopRequireDefault(require("./CheckboxInputField"));
602
614
 
615
+ var _ChoiceFieldset = _interopRequireWildcard(require("./ChoiceFieldset"));
616
+
603
617
  var _CounterLabel = _interopRequireDefault(require("./CounterLabel"));
604
618
 
605
619
  var _Details = _interopRequireDefault(require("./Details"));
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- declare const _default: React.FC<import("./_InputField/ToggleInputField").Props> & {
3
- Input: React.FC<Omit<React.HTMLProps<HTMLInputElement>, "ref"> & {
2
+ import { ToggleInputFieldProps } from './_InputField/ToggleInputField';
3
+ declare const _default: React.FC<ToggleInputFieldProps> & {
4
+ Input: React.FC<React.HTMLProps<HTMLInputElement> & {
4
5
  ref?: React.Ref<HTMLInputElement> | undefined;
5
6
  }>;
6
7
  Caption: React.FC<{}>;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const ChoiceFieldCaption: React.FC;
3
+ export default ChoiceFieldCaption;
@@ -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,3 @@
1
+ import React from 'react';
2
+ declare const ChoiceFieldLabel: React.FC;
3
+ export default ChoiceFieldLabel;
@@ -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,72 @@
1
+ import React from 'react';
2
+ import { Box } from '..';
3
+ import createSlots from '../utils/create-slots';
4
+ import { uniqueId } from '../utils/uniqueId';
5
+ import ValidationAnimationContainer from '../_InputField/ValidationAnimationContainer';
6
+ import InputValidation from '../_InputValidation';
7
+ import ChoiceFieldsetListItem from './ChoiceFieldsetListItem';
8
+ import ChoiceFieldsetDescription from './ChoiceFieldsetDescription';
9
+ import ChoiceFieldsetLegend from './ChoiceFieldsetLegend';
10
+ import ChoiceFieldsetList from './ChoiceFieldsetList';
11
+ import ChoiceFieldsetValidation from './ChoiceFieldsetValidation';
12
+ const {
13
+ Slots,
14
+ Slot
15
+ } = createSlots(['Description', 'ChoiceList', 'Legend', 'Validation']);
16
+ export { Slot };
17
+
18
+ const ChoiceFieldset = ({
19
+ children,
20
+ disabled,
21
+ id,
22
+ name,
23
+ onSelect,
24
+ required,
25
+ selected,
26
+ validationMap,
27
+ validationResult
28
+ }) => {
29
+ var _React$Children$map;
30
+
31
+ const fieldsetId = id || uniqueId();
32
+ 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);
33
+ const validationChildToRender = validationChildren === null || validationChildren === void 0 ? void 0 : validationChildren.find(child => child.props.validationKey === validationResult);
34
+ const validationMessageId = validationChildToRender ? `${fieldsetId}-validationMsg` : undefined;
35
+ return /*#__PURE__*/React.createElement(Slots, {
36
+ context: {
37
+ disabled,
38
+ name,
39
+ onSelect,
40
+ required,
41
+ selected,
42
+ validationMessageId
43
+ }
44
+ }, slots => {
45
+ const isLegendVisible = /*#__PURE__*/React.isValidElement(slots.Legend) && slots.Legend.props.isVisible;
46
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Box, {
47
+ as: "fieldset",
48
+ border: "none",
49
+ margin: 0,
50
+ padding: 0,
51
+ "aria-describedby": [validationMessageId].filter(Boolean).join(' ')
52
+ }, React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child) && child.type !== ChoiceFieldsetValidation), /*#__PURE__*/React.createElement(Box, {
53
+ mb: isLegendVisible ? 3 : undefined
54
+ }, slots.Legend, slots.Description), slots.ChoiceList), validationChildToRender && /*#__PURE__*/React.createElement(Box, {
55
+ mt: 3
56
+ }, validationMap && validationResult && validationMessageId && /*#__PURE__*/React.createElement(ValidationAnimationContainer, {
57
+ show: true
58
+ }, /*#__PURE__*/React.createElement(InputValidation, {
59
+ validationStatus: validationMap[validationResult],
60
+ id: validationMessageId
61
+ }, validationChildToRender))));
62
+ });
63
+ };
64
+
65
+ ChoiceFieldset.displayName = "ChoiceFieldset";
66
+ export default Object.assign(ChoiceFieldset, {
67
+ Description: ChoiceFieldsetDescription,
68
+ Item: ChoiceFieldsetListItem,
69
+ Legend: ChoiceFieldsetLegend,
70
+ List: ChoiceFieldsetList,
71
+ Validation: ChoiceFieldsetValidation
72
+ });
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const ChoiceFieldsetDescription: React.FC;
3
+ export default ChoiceFieldsetDescription;
@@ -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,52 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { CheckboxInputField, RadioInputField } from '..';
4
+ import { get } from '../constants';
5
+ import { uniqueId } from '../utils/uniqueId';
6
+ import { Slot } from './ChoiceFieldset';
7
+ import ChoiceFieldsetListContext from './ChoiceFieldsetListContext';
8
+ const List = styled.ul.withConfig({
9
+ displayName: "ChoiceFieldsetList__List",
10
+ componentId: "sc-16da7ba-0"
11
+ })(["display:flex;flex-direction:column;list-style:none;margin:0;padding:0;> li + li{margin-top:", ";}"], get('space.2'));
12
+
13
+ const ChoiceFieldsetList = ({
14
+ selectionVariant,
15
+ children
16
+ }) => /*#__PURE__*/React.createElement(Slot, {
17
+ name: "ChoiceList"
18
+ }, ({
19
+ name,
20
+ onSelect,
21
+ disabled,
22
+ selected = []
23
+ }) => {
24
+ const getSelectedCheckboxes = (value, checked) => {
25
+ if (checked) {
26
+ return selectionVariant === 'multiple' ? [...selected, value] : [value];
27
+ }
28
+
29
+ return selected.filter(selectedValue => selectedValue !== value);
30
+ };
31
+
32
+ return /*#__PURE__*/React.createElement(ChoiceFieldsetListContext.Provider, {
33
+ value: {
34
+ disabled,
35
+ selected,
36
+ name: name || uniqueId(),
37
+ fieldComponent: selectionVariant === 'multiple' ? CheckboxInputField : RadioInputField,
38
+ onChange: e => {
39
+ onSelect && onSelect(getSelectedCheckboxes(e.currentTarget.value, e.currentTarget.checked));
40
+ },
41
+ selectionVariant
42
+ }
43
+ }, /*#__PURE__*/React.createElement(List, null, React.Children.map(children, (child, i) => /*#__PURE__*/React.createElement("li", {
44
+ key: i
45
+ }, child))));
46
+ });
47
+
48
+ ChoiceFieldsetList.displayName = "ChoiceFieldsetList";
49
+ ChoiceFieldsetList.defaultProps = {
50
+ selectionVariant: 'single'
51
+ };
52
+ export default ChoiceFieldsetList;
@@ -0,0 +1,19 @@
1
+ import { ChangeEventHandler } from 'react';
2
+ import { CheckboxInputField, RadioInputField } from '..';
3
+ import { ComponentProps } from '../utils/types';
4
+ import InputField from '../_InputField';
5
+ import ToggleInputField, { ToggleInputFieldProps } from '../_InputField/ToggleInputField';
6
+ declare const ChoiceFieldsetListContext: import("react").Context<{
7
+ disabled?: boolean | undefined;
8
+ name: string;
9
+ onChange: ChangeEventHandler<HTMLInputElement>;
10
+ fieldComponent: React.FC<ToggleInputFieldProps> & {
11
+ Input: React.FC<ComponentProps<typeof RadioInputField.Input>> | React.FC<ComponentProps<typeof CheckboxInputField.Input>>;
12
+ Caption: React.FC<ComponentProps<typeof InputField.Caption>>;
13
+ Label: React.FC<ComponentProps<typeof InputField.Label>>;
14
+ LeadingVisual: React.FC<ComponentProps<typeof ToggleInputField.LeadingVisual>>;
15
+ };
16
+ selected?: string[] | undefined;
17
+ selectionVariant?: "single" | "multiple" | undefined;
18
+ } | null>;
19
+ export default ChoiceFieldsetListContext;
@@ -0,0 +1,5 @@
1
+ import { createContext } from 'react';
2
+ import { CheckboxInputField } from '..';
3
+ const ChoiceFieldsetListContext = /*#__PURE__*/createContext(null);
4
+ CheckboxInputField.Input;
5
+ export default ChoiceFieldsetListContext;
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { ComponentProps } from '../utils/types';
3
+ export interface ChoiceFieldProps {
4
+ /**
5
+ * Whether the field is ready for user input
6
+ */
7
+ disabled?: boolean;
8
+ /**
9
+ * The unique identifier for this field. Used to associate the label, validation text, and caption text.
10
+ * If an ID is not provided, one will be automatically generated.
11
+ */
12
+ id?: string;
13
+ /**
14
+ * The value that is being selected
15
+ */
16
+ value: string;
17
+ }
18
+ declare const ChoiceFieldsetListItem: React.FC<ChoiceFieldProps>;
19
+ export declare type ChoiceFieldComponentProps = ComponentProps<typeof ChoiceFieldsetListItem>;
20
+ declare const _default: React.FC<ChoiceFieldProps> & {
21
+ Caption: React.FC<{}>;
22
+ Label: React.FC<{}>;
23
+ LeadingVisual: React.FC<{}>;
24
+ };
25
+ export default _default;
@@ -0,0 +1,51 @@
1
+ import React, { useContext } from 'react';
2
+ import { uniqueId } from '../utils/uniqueId';
3
+ import ToggleInputLeadingVisual from '../_InputField/ToggleInputLeadingVisual';
4
+ import ChoiceFieldCaption from './ChoiceFieldCaption';
5
+ import ChoiceFieldLabel from './ChoiceFieldLabel';
6
+ import ChoiceFieldsetListContext from './ChoiceFieldsetListContext';
7
+
8
+ const ChoiceFieldsetListItem = ({
9
+ children,
10
+ id,
11
+ disabled: disabledProp,
12
+ value
13
+ }) => {
14
+ const choiceFieldsetListContext = useContext(ChoiceFieldsetListContext);
15
+
16
+ if (choiceFieldsetListContext === null) {
17
+ throw new Error('ChoiceFieldsetListContext returned null');
18
+ }
19
+
20
+ const {
21
+ name,
22
+ onChange,
23
+ fieldComponent: FieldComponent,
24
+ selected,
25
+ disabled,
26
+ selectionVariant
27
+ } = choiceFieldsetListContext;
28
+ const fieldId = id || uniqueId();
29
+ const labelChild = React.Children.toArray(children).find(child => /*#__PURE__*/React.isValidElement(child) && child.type === ChoiceFieldLabel);
30
+ const otherValidChildren = React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child) && (child.type === ChoiceFieldCaption || child.type === ToggleInputLeadingVisual));
31
+ return /*#__PURE__*/React.createElement(FieldComponent, {
32
+ id: fieldId,
33
+ disabled: disabledProp || disabled
34
+ }, /*#__PURE__*/React.createElement(FieldComponent.Input, {
35
+ checked: selected === null || selected === void 0 ? void 0 : selected.includes(value),
36
+ value: value,
37
+ name: selectionVariant === 'multiple' ? value : name,
38
+ onChange: onChange
39
+ }), labelChild ? // if <Item.Label> was passed, we can just render the children as-is
40
+ children :
41
+ /*#__PURE__*/
42
+ // if <Item.Label> was NOT passed, treat all the children except <Item.Caption> and <Item.LeadingVisual> as the label
43
+ React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FieldComponent.Label, null, children), otherValidChildren));
44
+ };
45
+
46
+ ChoiceFieldsetListItem.displayName = "ChoiceFieldsetListItem";
47
+ export default Object.assign(ChoiceFieldsetListItem, {
48
+ Caption: ChoiceFieldCaption,
49
+ Label: ChoiceFieldLabel,
50
+ LeadingVisual: ToggleInputLeadingVisual
51
+ });
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export interface ChoiceFieldsetValidationProps {
3
+ validationKey: string;
4
+ }
5
+ declare const ChoiceFieldsetValidation: React.FC<ChoiceFieldsetValidationProps>;
6
+ export default ChoiceFieldsetValidation;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+
3
+ const ChoiceFieldsetValidation = ({
4
+ children
5
+ }) => /*#__PURE__*/React.createElement(React.Fragment, null, children);
6
+
7
+ export default ChoiceFieldsetValidation;
@@ -0,0 +1,3 @@
1
+ export { default } from './ChoiceFieldset';
2
+ export { default as Item } from './ChoiceFieldsetListItem';
3
+ export type { ChoiceFieldsetProps } from './ChoiceFieldset';
@@ -0,0 +1,2 @@
1
+ export { default } from './ChoiceFieldset';
2
+ export { default as Item } from './ChoiceFieldsetListItem';
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
- declare const _default: React.FC<import("./_InputField/ToggleInputField").Props> & {
3
- Input: React.FC<React.HTMLProps<HTMLInputElement>>;
2
+ import { RadioProps } from '.';
3
+ import { ToggleInputFieldProps } from './_InputField/ToggleInputField';
4
+ declare const _default: React.FC<ToggleInputFieldProps> & {
5
+ Input: React.FC<RadioProps>;
4
6
  Caption: React.FC<{}>;
5
7
  Label: React.FC<import("./_InputField/InputFieldLabel").Props>;
6
8
  LeadingVisual: React.FC<{}>;
@@ -1,21 +1,12 @@
1
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
2
 
3
3
  import React from 'react';
4
+ import { Radio } from '.';
4
5
  import InputField from './_InputField/InputField';
5
6
  import { Slot } from './_InputField/slots';
6
7
  import ToggleInputField from './_InputField/ToggleInputField';
7
- import ToggleInputLeadingVisual from './_InputField/ToggleInputLeadingVisual'; // TODO: use Primer's checkbox input once it's available
8
- // https://github.com/github/primer/issues/489
8
+ import ToggleInputLeadingVisual from './_InputField/ToggleInputLeadingVisual'; // pulling out `id`, `disabled`, and `required` because those should come from the parent TextInputField component
9
9
 
10
- const RadioInput = props => {
11
- return /*#__PURE__*/React.createElement("input", _extends({
12
- type: "radio"
13
- }, props));
14
- };
15
-
16
- RadioInput.displayName = "RadioInput";
17
-
18
- // pulling out `id`, `disabled`, and `required` because those should come from the parent TextInputField component
19
10
  const Input = ({
20
11
  id: idProp,
21
12
  required: requiredProp,
@@ -44,7 +35,7 @@ const Input = ({
44
35
  id,
45
36
  required,
46
37
  captionId
47
- }) => /*#__PURE__*/React.createElement(RadioInput, _extends({
38
+ }) => /*#__PURE__*/React.createElement(Radio, _extends({
48
39
  "aria-describedby": captionId,
49
40
  id: id,
50
41
  required: required,
@@ -7,6 +7,7 @@ const InputCaption = ({
7
7
  id
8
8
  }) => /*#__PURE__*/React.createElement(Text, {
9
9
  color: disabled ? 'fg.subtle' : 'fg.muted',
10
+ display: "block",
10
11
  fontSize: 0,
11
12
  id: id
12
13
  }, children);
@@ -1,13 +1,13 @@
1
1
  import React from 'react';
2
2
  import { Props as InputFieldProps } from './InputField';
3
3
  import { FormValidationStatus } from '../utils/types/FormValidationStatus';
4
- export interface Props extends Pick<InputFieldProps, 'disabled' | 'id'> {
4
+ export interface ToggleInputFieldProps extends Pick<InputFieldProps, 'disabled' | 'id'> {
5
5
  /**
6
6
  * Styles the field to visually communicate the result of form validation
7
7
  */
8
8
  validationStatus?: FormValidationStatus;
9
9
  }
10
- declare const _default: React.FC<Props> & {
10
+ declare const _default: React.FC<ToggleInputFieldProps> & {
11
11
  LeadingVisual: React.FC<{}>;
12
12
  };
13
13
  export default _default;
@@ -49,6 +49,7 @@ export type { CircleBadgeProps, CircleBadgeIconProps } from './CircleBadge';
49
49
  export { default as CircleOcticon } from './CircleOcticon';
50
50
  export type { CircleOcticonProps } from './CircleOcticon';
51
51
  export { default as CheckboxInputField } from './CheckboxInputField';
52
+ export { default as ChoiceFieldset, Item } from './ChoiceFieldset';
52
53
  export { default as CounterLabel } from './CounterLabel';
53
54
  export type { CounterLabelProps } from './CounterLabel';
54
55
  export { default as Details } from './Details';
package/lib-esm/index.js CHANGED
@@ -32,6 +32,7 @@ export { default as Caret } from './Caret';
32
32
  export { default as CircleBadge } from './CircleBadge';
33
33
  export { default as CircleOcticon } from './CircleOcticon';
34
34
  export { default as CheckboxInputField } from './CheckboxInputField';
35
+ export { default as ChoiceFieldset, Item } from './ChoiceFieldset';
35
36
  export { default as CounterLabel } from './CounterLabel';
36
37
  export { default as Details } from './Details';
37
38
  export { default as Dialog } from './Dialog';