@openedx/paragon 21.9.1 → 21.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const _excluded = ["type", "value", "checked", "children", "isIndeterminate", "isInvalid", "onClick", "onFocus", "inputHidden", "className"];
1
+ const _excluded = ["type", "value", "checked", "children", "isIndeterminate", "isInvalid", "onClick", "onFocus", "inputHidden", "className", "showActiveBoxState"];
2
2
  function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
3
3
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
4
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -26,7 +26,8 @@ const SelectableBox = /*#__PURE__*/React.forwardRef((_ref, ref) => {
26
26
  onClick,
27
27
  onFocus,
28
28
  inputHidden,
29
- className
29
+ className,
30
+ showActiveBoxState
30
31
  } = _ref,
31
32
  props = _objectWithoutProperties(_ref, _excluded);
32
33
  const inputType = getInputType('SelectableBox', type);
@@ -68,7 +69,7 @@ const SelectableBox = /*#__PURE__*/React.forwardRef((_ref, ref) => {
68
69
  onClick: () => inputRef.current.click(),
69
70
  onFocus: onFocus,
70
71
  className: classNames('pgn__selectable_box', className, {
71
- 'pgn__selectable_box-active': isChecked() || checked,
72
+ 'pgn__selectable_box-active': !inputHidden && !showActiveBoxState ? false : isChecked() || checked,
72
73
  'pgn__selectable_box-invalid': isInvalid
73
74
  }),
74
75
  tabIndex: 0,
@@ -95,7 +96,9 @@ SelectableBox.propTypes = {
95
96
  /** Adds errors styles to the `SelectableBox`. */
96
97
  isInvalid: PropTypes.bool,
97
98
  /** A class that is appended to the base element. */
98
- className: PropTypes.string
99
+ className: PropTypes.string,
100
+ /** Controls the visibility of the active state for the `SelectableBox`. */
101
+ showActiveBoxState: PropTypes.bool
99
102
  };
100
103
  SelectableBox.defaultProps = {
101
104
  value: undefined,
@@ -106,7 +109,8 @@ SelectableBox.defaultProps = {
106
109
  inputHidden: true,
107
110
  isIndeterminate: false,
108
111
  isInvalid: false,
109
- className: undefined
112
+ className: undefined,
113
+ showActiveBoxState: true
110
114
  };
111
115
  SelectableBox.Set = SelectableBoxSet;
112
116
  export default SelectableBox;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["React","useRef","useEffect","PropTypes","classNames","SelectableBoxSet","useCheckboxSetContext","useRadioSetContext","getInputType","INPUT_TYPES","SelectableBox","forwardRef","_ref","ref","type","value","checked","children","isIndeterminate","isInvalid","onClick","onFocus","inputHidden","className","props","_objectWithoutProperties","_excluded","inputType","radioValue","checkboxValues","isChecked","includes","inputRef","input","createElement","_objectSpread","hidden","tabIndex","onChange","current","onclick","_extends","role","onKeyPress","click","propTypes","node","isRequired","oneOfType","string","number","bool","oneOf","func","defaultProps","undefined","Set"],"sources":["../../src/SelectableBox/index.jsx"],"sourcesContent":["import React, { useRef, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\nimport SelectableBoxSet from './SelectableBoxSet';\nimport { useCheckboxSetContext } from '../Form/FormCheckboxSetContext';\nimport { useRadioSetContext } from '../Form/FormRadioSetContext';\nimport { getInputType } from './utils';\n\nconst INPUT_TYPES = [\n 'radio',\n 'checkbox',\n];\n\nconst SelectableBox = React.forwardRef(({\n type,\n value,\n checked,\n children,\n isIndeterminate,\n isInvalid,\n onClick,\n onFocus,\n inputHidden,\n className,\n ...props\n}, ref) => {\n const inputType = getInputType('SelectableBox', type);\n const { value: radioValue } = useRadioSetContext();\n const { value: checkboxValues = [] } = useCheckboxSetContext();\n\n const isChecked = () => {\n switch (type) {\n case 'radio':\n return radioValue === value;\n case 'checkbox':\n return checkboxValues.includes(value);\n default:\n return radioValue === value;\n }\n };\n\n const inputRef = useRef(null);\n const input = React.createElement(inputType, {\n value,\n checked,\n hidden: inputHidden,\n ref: inputRef,\n tabIndex: -1,\n onChange: () => {},\n ...(type === 'checkbox' ? { ...props, isIndeterminate } : { ...props }),\n }, null);\n\n useEffect(() => {\n if (onClick && inputRef.current) {\n inputRef.current.onclick = () => onClick(inputRef.current);\n }\n }, [onClick]);\n\n return (\n <div\n role=\"button\"\n onKeyPress={() => inputRef.current.click()}\n onClick={() => inputRef.current.click()}\n onFocus={onFocus}\n className={classNames('pgn__selectable_box', className, {\n 'pgn__selectable_box-active': isChecked() || checked,\n 'pgn__selectable_box-invalid': isInvalid,\n })}\n tabIndex={0}\n ref={ref}\n {...props}\n >\n {input}\n {children}\n </div>\n );\n});\n\nSelectableBox.propTypes = {\n /** Content of the `SelectableBox`. */\n children: PropTypes.node.isRequired,\n /** A value that is passed to the input tag. */\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n /** Controls whether `SelectableBox` is checked. */\n checked: PropTypes.bool,\n /** Indicates the input type: checkbox or radio. */\n type: PropTypes.oneOf(INPUT_TYPES),\n /** Function that is called when the `SelectableBox` is clicked. */\n onClick: PropTypes.func,\n /** Function that is called when the `SelectableBox` is focused. */\n onFocus: PropTypes.func,\n /** Controls display of the input (checkbox or radio button) on the `SelectableBox`. */\n inputHidden: PropTypes.bool,\n /** Indicates a state for the 'checkbox' `type` when `SelectableBox` is neither checked nor unchecked. */\n isIndeterminate: PropTypes.bool,\n /** Adds errors styles to the `SelectableBox`. */\n isInvalid: PropTypes.bool,\n /** A class that is appended to the base element. */\n className: PropTypes.string,\n};\n\nSelectableBox.defaultProps = {\n value: undefined,\n checked: false,\n type: 'radio',\n onClick: () => {},\n onFocus: () => {},\n inputHidden: true,\n isIndeterminate: false,\n isInvalid: false,\n className: undefined,\n};\n\nSelectableBox.Set = SelectableBoxSet;\nexport default SelectableBox;\n"],"mappings":";;;;;;;;;AAAA,OAAOA,KAAK,IAAIC,MAAM,EAAEC,SAAS,QAAQ,OAAO;AAChD,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,gBAAgB,MAAM,oBAAoB;AACjD,SAASC,qBAAqB,QAAQ,gCAAgC;AACtE,SAASC,kBAAkB,QAAQ,6BAA6B;AAChE,SAASC,YAAY,QAAQ,SAAS;AAEtC,MAAMC,WAAW,GAAG,CAClB,OAAO,EACP,UAAU,CACX;AAED,MAAMC,aAAa,gBAAGV,KAAK,CAACW,UAAU,CAAC,CAAAC,IAAA,EAYpCC,GAAG,KAAK;EAAA,IAZ6B;MACtCC,IAAI;MACJC,KAAK;MACLC,OAAO;MACPC,QAAQ;MACRC,eAAe;MACfC,SAAS;MACTC,OAAO;MACPC,OAAO;MACPC,WAAW;MACXC;IAEF,CAAC,GAAAX,IAAA;IADIY,KAAK,GAAAC,wBAAA,CAAAb,IAAA,EAAAc,SAAA;EAER,MAAMC,SAAS,GAAGnB,YAAY,CAAC,eAAe,EAAEM,IAAI,CAAC;EACrD,MAAM;IAAEC,KAAK,EAAEa;EAAW,CAAC,GAAGrB,kBAAkB,CAAC,CAAC;EAClD,MAAM;IAAEQ,KAAK,EAAEc,cAAc,GAAG;EAAG,CAAC,GAAGvB,qBAAqB,CAAC,CAAC;EAE9D,MAAMwB,SAAS,GAAGA,CAAA,KAAM;IACtB,QAAQhB,IAAI;MACV,KAAK,OAAO;QACV,OAAOc,UAAU,KAAKb,KAAK;MAC7B,KAAK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KAAK,EACLhB,QACE,CAAC;AAEV,CAAC,CAAC;AAEFP,aAAa,CAACmC,SAAS,GAAG;EACxB;EACA5B,QAAQ,EAAEd,SAAS,CAAC2C,IAAI,CAACC,UAAU;EACnC;EACAhC,KAAK,EAAEZ,SAAS,CAAC6C,SAAS,CAAC,CAAC7C,SAAS,CAAC8C,MAAM,EAAE9C,SAAS,CAAC+C,MAAM,CAAC,CAAC;EAChE;EACAlC,OAAO,EAAEb,SAAS,CAACgD,IAAI;EACvB;EACArC,IAAI,EAAEX,SAAS,CAACiD,KAAK,CAAC3C,WAAW,CAAC;EAClC;EACAW,OAAO,EAAEjB,SAAS,CAACkD,IAAI;EACvB;EACAhC,OAAO,EAAElB,SAAS,CAACkD,IAAI;EACvB;EACA/B,WAAW,EAAEnB,SAAS,CAACgD,IAAI;EAC3B;EACAjC,eAAe,EAAEf,SAAS,CAACgD,IAAI;EAC/B;EACAhC,SAAS,EAAEhB,SAAS,CAACgD,IAAI;EACzB;EACA5B,SAAS,EAAEpB,SAAS,CAAC8C;AACvB,CAAC;AAEDvC,aAAa,CAAC4C,YAAY,GAAG;EAC3BvC,KAAK,EAAEwC,SAAS;EAChBvC,OAAO,EAAE,KAAK;EACdF,IAAI,EAAE,OAAO;EACbM,OAAO,EAAEA,CAAA,KAAM,CAAC,CAAC;EACjBC,OAAO,EAAEA,CAAA,KAAM,CAAC,CAAC;EACjBC,WAAW,EAAE,IAAI;EACjBJ,eAAe,EAAE,KAAK;EACtBC,SAAS,EAAE,KAAK;EAChBI,SAAS,EAAEgC;AACb,CAAC;AAED7C,aAAa,CAAC8C,GAAG,GAAGnD,gBAAgB;AACpC,eAAeK,aAAa"}
1
+ {"version":3,"file":"index.js","names":["React","useRef","useEffect","PropTypes","classNames","SelectableBoxSet","useCheckboxSetContext","useRadioSetContext","getInputType","INPUT_TYPES","SelectableBox","forwardRef","_ref","ref","type","value","checked","children","isIndeterminate","isInvalid","onClick","onFocus","inputHidden","className","showActiveBoxState","props","_objectWithoutProperties","_excluded","inputType","radioValue","checkboxValues","isChecked","includes","inputRef","input","createElement","_objectSpread","hidden","tabIndex","onChange","current","onclick","_extends","role","onKeyPress","click","propTypes","node","isRequired","oneOfType","string","number","bool","oneOf","func","defaultProps","undefined","Set"],"sources":["../../src/SelectableBox/index.jsx"],"sourcesContent":["import React, { useRef, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\nimport SelectableBoxSet from './SelectableBoxSet';\nimport { useCheckboxSetContext } from '../Form/FormCheckboxSetContext';\nimport { useRadioSetContext } from '../Form/FormRadioSetContext';\nimport { getInputType } from './utils';\n\nconst INPUT_TYPES = [\n 'radio',\n 'checkbox',\n];\n\nconst SelectableBox = React.forwardRef(({\n type,\n value,\n checked,\n children,\n isIndeterminate,\n isInvalid,\n onClick,\n onFocus,\n inputHidden,\n className,\n showActiveBoxState,\n ...props\n}, ref) => {\n const inputType = getInputType('SelectableBox', type);\n const { value: radioValue } = useRadioSetContext();\n const { value: checkboxValues = [] } = useCheckboxSetContext();\n\n const isChecked = () => {\n switch (type) {\n case 'radio':\n return radioValue === value;\n case 'checkbox':\n return checkboxValues.includes(value);\n default:\n return radioValue === value;\n }\n };\n\n const inputRef = useRef(null);\n const input = React.createElement(inputType, {\n value,\n checked,\n hidden: inputHidden,\n ref: inputRef,\n tabIndex: -1,\n onChange: () => {},\n ...(type === 'checkbox' ? { ...props, isIndeterminate } : { ...props }),\n }, null);\n\n useEffect(() => {\n if (onClick && inputRef.current) {\n inputRef.current.onclick = () => onClick(inputRef.current);\n }\n }, [onClick]);\n\n return (\n <div\n role=\"button\"\n onKeyPress={() => inputRef.current.click()}\n onClick={() => inputRef.current.click()}\n onFocus={onFocus}\n className={classNames('pgn__selectable_box', className, {\n 'pgn__selectable_box-active': (!inputHidden && !showActiveBoxState) ? false : isChecked() || checked,\n 'pgn__selectable_box-invalid': isInvalid,\n })}\n tabIndex={0}\n ref={ref}\n {...props}\n >\n {input}\n {children}\n </div>\n );\n});\n\nSelectableBox.propTypes = {\n /** Content of the `SelectableBox`. */\n children: PropTypes.node.isRequired,\n /** A value that is passed to the input tag. */\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n /** Controls whether `SelectableBox` is checked. */\n checked: PropTypes.bool,\n /** Indicates the input type: checkbox or radio. */\n type: PropTypes.oneOf(INPUT_TYPES),\n /** Function that is called when the `SelectableBox` is clicked. */\n onClick: PropTypes.func,\n /** Function that is called when the `SelectableBox` is focused. */\n onFocus: PropTypes.func,\n /** Controls display of the input (checkbox or radio button) on the `SelectableBox`. */\n inputHidden: PropTypes.bool,\n /** Indicates a state for the 'checkbox' `type` when `SelectableBox` is neither checked nor unchecked. */\n isIndeterminate: PropTypes.bool,\n /** Adds errors styles to the `SelectableBox`. */\n isInvalid: PropTypes.bool,\n /** A class that is appended to the base element. */\n className: PropTypes.string,\n /** Controls the visibility of the active state for the `SelectableBox`. */\n showActiveBoxState: PropTypes.bool,\n};\n\nSelectableBox.defaultProps = {\n value: undefined,\n checked: false,\n type: 'radio',\n onClick: () => {},\n onFocus: () => {},\n inputHidden: true,\n isIndeterminate: false,\n isInvalid: false,\n className: undefined,\n showActiveBoxState: true,\n};\n\nSelectableBox.Set = SelectableBoxSet;\nexport default SelectableBox;\n"],"mappings":";;;;;;;;;AAAA,OAAOA,KAAK,IAAIC,MAAM,EAAEC,SAAS,QAAQ,OAAO;AAChD,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,gBAAgB,MAAM,oBAAoB;AACjD,SAASC,qBAAqB,QAAQ,gCAAgC;AACtE,SAASC,kBAAkB,QAAQ,6BAA6B;AAChE,SAASC,YAAY,QAAQ,SAAS;AAEtC,MAAMC,WAAW,GAAG,CAClB,OAAO,EACP,UAAU,CACX;AAED,MAAMC,aAAa,gBAAGV,KAAK,CAACW,UAAU,CAAC,CAAAC,IAAA,EAapCC,GAAG,KAAK;EAAA,IAb6B;MACtCC,IAAI;MACJC,K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AM;EAC3B;EACA1B,kBAAkB,EAAErB,SAAS,CAACiD;AAChC,CAAC;AAED1C,aAAa,CAAC6C,YAAY,GAAG;EAC3BxC,KAAK,EAAEyC,SAAS;EAChBxC,OAAO,EAAE,KAAK;EACdF,IAAI,EAAE,OAAO;EACbM,OAAO,EAAEA,CAAA,KAAM,CAAC,CAAC;EACjBC,OAAO,EAAEA,CAAA,KAAM,CAAC,CAAC;EACjBC,WAAW,EAAE,IAAI;EACjBJ,eAAe,EAAE,KAAK;EACtBC,SAAS,EAAE,KAAK;EAChBI,SAAS,EAAEiC,SAAS;EACpBhC,kBAAkB,EAAE;AACtB,CAAC;AAEDd,aAAa,CAAC+C,GAAG,GAAGpD,gBAAgB;AACpC,eAAeK,aAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openedx/paragon",
3
- "version": "21.9.1",
3
+ "version": "21.10.0",
4
4
  "description": "Accessible, responsive UI component library based on Bootstrap.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -200,30 +200,11 @@ For link to be `disabled`, it must have href defined with some value.
200
200
  )}
201
201
  ```
202
202
 
203
- ### With a Spinner
204
-
205
- ```jsx live
206
- <>
207
- <Button variant="primary" className="mb-2 mr-2 mb-sm-0" aria-label="Loading some stuff">
208
- <Spinner animation="border" />
209
- </Button>
210
- <Button variant="brand" className="mb-2 mr-2 mb-sm-0" aria-label="Loading some stuff">
211
- <Spinner animation="border" />
212
- </Button>
213
- <Button variant="outline-primary" className="mb-2 mr-2 mb-sm-0" aria-label="Loading some stuff">
214
- <Spinner animation="border" />
215
- </Button>
216
- <Button variant="outline-brand" className="mb-2 mr-2 mb-sm-0" aria-label="Loading some stuff">
217
- <Spinner animation="border" />
218
- </Button>
219
- <Button variant="inverse-primary" className="mb-2 mr-2 mb-sm-0" aria-label="Loading some stuff">
220
- <Spinner animation="border" />
221
- </Button>
222
- <Button variant="inverse-brand" className="mb-2 mr-2 mb-sm-0" aria-label="Loading some stuff">
223
- <Spinner animation="border" />
224
- </Button>
225
- </>
226
- ```
203
+ ## Stateful buttons
204
+ To implement loading state using a `Button` component, the [StatefulButton](https://paragon-openedx.netlify.app/components/statefulbutton/) component
205
+ is available for use. <br/>
206
+ This specialized component is designed to seamlessly manage and display boot states, providing a more efficient and
207
+ user-friendly experience.
227
208
 
228
209
  ***
229
210
 
@@ -436,7 +436,7 @@ See ``dataViewToggleOptions`` props documentation for all supported props.
436
436
  }}
437
437
  isSortable
438
438
  defaultColumnValues={{ Filter: TextFilter }}
439
- itemCount={7}
439
+ itemCount={3}
440
440
  data={[
441
441
  {
442
442
  name: 'Lil Bub',
@@ -6,9 +6,9 @@ components:
6
6
  - SelectableBoxSet
7
7
  categories:
8
8
  - Forms
9
- status: 'New'
9
+ status: 'Stable'
10
10
  designStatus: 'Done'
11
- devStatus: 'In progress'
11
+ devStatus: 'Done'
12
12
  notes: |
13
13
  ---
14
14
 
@@ -26,7 +26,7 @@ As ``Checkbox``
26
26
  const allCheeseOptions = ['swiss', 'cheddar', 'pepperjack'];
27
27
  const [checkedCheeses, { add, remove, set, clear }] = useCheckboxSetValues(['swiss']);
28
28
 
29
- const handleChange = e => {
29
+ const handleChange = (e) => {
30
30
  e.target.checked ? add(e.target.value) : remove(e.target.value);
31
31
  };
32
32
 
@@ -34,35 +34,32 @@ As ``Checkbox``
34
34
  const isExtraSmall = useMediaQuery({ maxWidth: breakpoints.extraSmall.maxWidth });
35
35
 
36
36
  return (
37
- <div className="bg-light-200 p-3">
38
- <SelectableBox.Set
39
- value={checkedCheeses}
37
+ <SelectableBox.Set
38
+ className="bg-light-200 p-3"
39
+ value={checkedCheeses}
40
+ type={type}
41
+ onChange={handleChange}
42
+ name="cheeses"
43
+ columns={isExtraSmall ? 1 : 2}
44
+ ariaLabel="cheese selection"
45
+ >
46
+ <SelectableBox value="swiss" type={type} aria-label="swiss checkbox">
47
+ <h3>It is my first SelectableBox</h3>
48
+ <p>Swiss</p>
49
+ </SelectableBox>
50
+ <SelectableBox value="cheddar" inputHidden={false} type={type} aria-label="cheddar checkbox">
51
+ <h3>Cheddar</h3>
52
+ </SelectableBox>
53
+ <SelectableBox
54
+ value="pepperjack"
55
+ inputHidden={false}
40
56
  type={type}
41
- onChange={handleChange}
42
- name="cheeses"
43
- columns={isExtraSmall ? 1 : 2}
44
- ariaLabel="cheese selection"
57
+ isInvalid={isInvalid()}
58
+ aria-label="pepperjack checkbox"
45
59
  >
46
- <SelectableBox value="swiss" type={type} aria-label="swiss checkbox">
47
- <div>
48
- <h3>It is my first SelectableBox</h3>
49
- <p>Swiss</p>
50
- </div>
51
- </SelectableBox>
52
- <SelectableBox value="cheddar" inputHidden={false} type={type} aria-label="cheddar checkbox">
53
- Cheddar
54
- </SelectableBox>
55
- <SelectableBox
56
- value="pepperjack"
57
- inputHidden={false}
58
- type={type}
59
- isInvalid={isInvalid()}
60
- aria-label="pepperjack checkbox"
61
- >
62
- <h3>Pepperjack</h3>
63
- </SelectableBox>
64
- </SelectableBox.Set>
65
- </div>
60
+ <h3>Pepperjack</h3>
61
+ </SelectableBox>
62
+ </SelectableBox.Set>
66
63
  );
67
64
  }
68
65
  ```
@@ -71,31 +68,27 @@ As ``Checkbox``
71
68
 
72
69
  ```jsx live
73
70
  () => {
74
- const type = 'radio';
75
71
  const [value, setValue] = useState('green');
76
- const handleChange = e => setValue(e.target.value);
72
+ const handleChange = (e) => setValue(e.target.value);
77
73
  const isExtraSmall = useMediaQuery({ maxWidth: breakpoints.extraSmall.maxWidth });
78
74
 
79
75
  return (
80
76
  <SelectableBox.Set
81
- type={type}
82
77
  value={value}
83
78
  onChange={handleChange}
84
79
  name="colors"
85
80
  columns={isExtraSmall ? 1 : 3}
86
81
  ariaLabel="color selection"
87
82
  >
88
- <SelectableBox value="red" type={type} aria-label="red checkbox">
89
- <div>
90
- <h3>It is Red color</h3>
91
- <p>Select me</p>
92
- </div>
83
+ <SelectableBox value="red" aria-label="red checkbox">
84
+ <h3>It is Red color</h3>
85
+ <p>Select me</p>
93
86
  </SelectableBox>
94
- <SelectableBox value="green" inputHidden={false} type={type} aria-label="green-checkbox">
87
+ <SelectableBox value="green" inputHidden={false} aria-label="green radio-button">
95
88
  <h3>Green</h3>
96
89
  <p>Leaves and grass</p>
97
90
  </SelectableBox>
98
- <SelectableBox value="blue" inputHidden={false} type={type} aria-label="blue checkbox">
91
+ <SelectableBox value="blue" inputHidden={false} aria-label="blue radio-button">
99
92
  <h3>Blue</h3>
100
93
  <p>The sky</p>
101
94
  </SelectableBox>
@@ -103,6 +96,7 @@ As ``Checkbox``
103
96
  );
104
97
  }
105
98
  ```
99
+
106
100
  ## As Checkbox
107
101
  As ``Checkbox`` with ``isIndeterminate``
108
102
 
@@ -117,7 +111,7 @@ As ``Checkbox`` with ``isIndeterminate``
117
111
  const isIndeterminate = someChecked && !allChecked;
118
112
  const isExtraSmall = useMediaQuery({ maxWidth: breakpoints.small.maxWidth });
119
113
 
120
- const handleChange = e => {
114
+ const handleChange = (e) => {
121
115
  e.target.checked ? add(e.target.value) : remove(e.target.value);
122
116
  };
123
117
 
@@ -127,18 +121,17 @@ As ``Checkbox`` with ``isIndeterminate``
127
121
 
128
122
  return (
129
123
  <>
130
- <div className="mb-3">
131
- <SelectableBox
132
- checked={allChecked}
133
- isIndeterminate={isIndeterminate}
134
- onClick={handleCheckAllChange}
135
- inputHidden={false}
136
- type={type}
137
- aria-label="all options checkbox"
138
- >
139
- All the cheese
140
- </SelectableBox>
141
- </div>
124
+ <SelectableBox
125
+ className="mb-3"
126
+ checked={allChecked}
127
+ isIndeterminate={isIndeterminate}
128
+ onClick={handleCheckAllChange}
129
+ inputHidden={false}
130
+ type={type}
131
+ aria-label="all options checkbox"
132
+ >
133
+ All the cheese
134
+ </SelectableBox>
142
135
  <SelectableBox.Set
143
136
  value={checkedCheeses}
144
137
  type={type}
@@ -148,13 +141,11 @@ As ``Checkbox`` with ``isIndeterminate``
148
141
  ariaLabel="cheese selection"
149
142
  >
150
143
  <SelectableBox value="swiss" type={type} aria-label="swiss checkbox">
151
- <div>
152
- <h3>It is my first SelectableBox</h3>
153
- <p>Swiss</p>
154
- </div>
144
+ <h3>It is my first SelectableBox</h3>
145
+ <p>Swiss</p>
155
146
  </SelectableBox>
156
147
  <SelectableBox value="cheddar" inputHidden={false} type={type} aria-label="cheddar checkbox">
157
- Cheddar
148
+ <h3>Cheddar</h3>
158
149
  </SelectableBox>
159
150
  <SelectableBox value="pepperjack" inputHidden={false} type={type} aria-label="pepperjack checkbox">
160
151
  <h3>Pepperjack</h3>
@@ -173,16 +164,16 @@ As ``Checkbox`` with ``ariaLabelledby``
173
164
  const allCheeseOptions = ['swiss', 'cheddar', 'pepperjack'];
174
165
  const [checkedCheeses, { add, remove, set, clear }] = useCheckboxSetValues(['swiss']);
175
166
 
176
- const handleChange = e => {
167
+ const handleChange = (e) => {
177
168
  e.target.checked ? add(e.target.value) : remove(e.target.value);
178
169
  };
179
170
 
180
171
  const isExtraSmall = useMediaQuery({ maxWidth: breakpoints.extraSmall.maxWidth });
181
172
 
182
173
  return (
183
- <div className="bg-light-200 p-3">
174
+ <Stack className="bg-light-200 p-3">
184
175
  <h3 id="cheese selection" className="mb-4">
185
- Select your favorite cheese
176
+ Select your favorite cheese:
186
177
  </h3>
187
178
  <SelectableBox.Set
188
179
  value={checkedCheeses}
@@ -193,22 +184,63 @@ As ``Checkbox`` with ``ariaLabelledby``
193
184
  ariaLabelledby="cheese selection"
194
185
  >
195
186
  <SelectableBox value="swiss" inputHidden={false} type={type} aria-label="swiss checkbox">
196
- <h3>
197
- Swiss
198
- </h3>
187
+ <h3>Swiss</h3>
199
188
  </SelectableBox>
200
189
  <SelectableBox value="cheddar" inputHidden={false} type={type} aria-label="cheddar checkbox">
201
- <h3>
202
- Cheddar
203
- </h3>
190
+ <h3>Cheddar</h3>
204
191
  </SelectableBox>
205
192
  <SelectableBox value="pepperjack" inputHidden={false} type={type} aria-label="pepperjack checkbox">
206
- <h3>
207
- Pepperjack
208
- </h3>
193
+ <h3>Pepperjack</h3>
209
194
  </SelectableBox>
210
195
  </SelectableBox.Set>
211
- </div>
196
+ </Stack>
197
+ );
198
+ }
199
+ ```
200
+
201
+ ## Without active outline
202
+ The `showActiveBoxState` property only affects `SelectableBox` that have `inputHidden` set to `false`.
203
+ If a component has no input, the border is always rendered in an active state.
204
+
205
+ ```jsx live
206
+ () => {
207
+ const [value, setValue] = useState('apples');
208
+ const handleChange = (e) => setValue(e.target.value);
209
+ const isExtraSmall = useMediaQuery({ maxWidth: breakpoints.extraSmall.maxWidth });
210
+
211
+ return (
212
+ <SelectableBox.Set
213
+ value={value}
214
+ onChange={handleChange}
215
+ name="fruits"
216
+ columns={isExtraSmall ? 1 : 3}
217
+ ariaLabel="fruits selection"
218
+ >
219
+ <SelectableBox
220
+ value="apples"
221
+ inputHidden={false}
222
+ showActiveBoxState={false}
223
+ aria-label="apple radio-button"
224
+ >
225
+ <h3>Apples</h3>
226
+ </SelectableBox>
227
+ <SelectableBox
228
+ value="oranges"
229
+ inputHidden={false}
230
+ showActiveBoxState={false}
231
+ aria-label="orange radio-button"
232
+ >
233
+ <h3>Oranges</h3>
234
+ </SelectableBox>
235
+ <SelectableBox
236
+ value="bananas"
237
+ inputHidden={false}
238
+ showActiveBoxState={false}
239
+ aria-label="banana radio-button"
240
+ >
241
+ <h3>Bananas</h3>
242
+ </SelectableBox>
243
+ </SelectableBox.Set>
212
244
  );
213
245
  }
214
246
  ```
@@ -22,6 +22,7 @@ const SelectableBox = React.forwardRef(({
22
22
  onFocus,
23
23
  inputHidden,
24
24
  className,
25
+ showActiveBoxState,
25
26
  ...props
26
27
  }, ref) => {
27
28
  const inputType = getInputType('SelectableBox', type);
@@ -63,7 +64,7 @@ const SelectableBox = React.forwardRef(({
63
64
  onClick={() => inputRef.current.click()}
64
65
  onFocus={onFocus}
65
66
  className={classNames('pgn__selectable_box', className, {
66
- 'pgn__selectable_box-active': isChecked() || checked,
67
+ 'pgn__selectable_box-active': (!inputHidden && !showActiveBoxState) ? false : isChecked() || checked,
67
68
  'pgn__selectable_box-invalid': isInvalid,
68
69
  })}
69
70
  tabIndex={0}
@@ -97,6 +98,8 @@ SelectableBox.propTypes = {
97
98
  isInvalid: PropTypes.bool,
98
99
  /** A class that is appended to the base element. */
99
100
  className: PropTypes.string,
101
+ /** Controls the visibility of the active state for the `SelectableBox`. */
102
+ showActiveBoxState: PropTypes.bool,
100
103
  };
101
104
 
102
105
  SelectableBox.defaultProps = {
@@ -109,6 +112,7 @@ SelectableBox.defaultProps = {
109
112
  isIndeterminate: false,
110
113
  isInvalid: false,
111
114
  className: undefined,
115
+ showActiveBoxState: true,
112
116
  };
113
117
 
114
118
  SelectableBox.Set = SelectableBoxSet;
@@ -100,6 +100,13 @@ describe('<SelectableBox />', () => {
100
100
  rerender(<SelectableCheckbox inputHidden={false} />);
101
101
  expect(inputElement.getAttribute('hidden')).toBeNull();
102
102
  });
103
+ it('renders with active state and updates to inactive when showActiveBoxState is false', async () => {
104
+ const { rerender } = render(<SelectableCheckbox inputHidden={false} checked />);
105
+ const selectableBox = screen.getByRole('button');
106
+ expect(selectableBox.classList.contains('pgn__selectable_box-active')).toEqual(true);
107
+ rerender(<SelectableCheckbox inputHidden={false} showActiveBoxState={false} checked />);
108
+ expect(selectableBox.classList.contains('pgn__selectable_box-active')).toEqual(false);
109
+ });
103
110
  });
104
111
  describe('correct interactions', () => {
105
112
  it('correct checkbox state change when checked is changed', () => {
@@ -226,6 +226,60 @@ notes: |
226
226
  </Tabs>
227
227
  ```
228
228
 
229
+ ## Conditional rendering
230
+
231
+ ```jsx live
232
+ () => {
233
+ const librariesEnabled = true;
234
+ const visibleTabs = useMemo(() => {
235
+ const tabs = [];
236
+
237
+ tabs.push(
238
+ <Tab
239
+ key="courses"
240
+ eventKey="courses"
241
+ title="Courses"
242
+ >
243
+ Hello I am the courses panel.
244
+ </Tab>
245
+ );
246
+
247
+ tabs.push(
248
+ <Tab
249
+ key="programs"
250
+ eventKey="programs"
251
+ title="Programs"
252
+ >
253
+ Hello I am the programs panel.
254
+ </Tab>
255
+ );
256
+
257
+ if (librariesEnabled) {
258
+ tabs.push(
259
+ <Tab
260
+ key="libraries"
261
+ eventKey="libraries"
262
+ title="Libraries"
263
+ >
264
+ Hello I am the libraries panel.
265
+ </Tab>
266
+ );
267
+ }
268
+
269
+ return tabs;
270
+ }, [librariesEnabled]);
271
+
272
+ return (
273
+ <Tabs
274
+ id="tabs"
275
+ defaultActiveKey="courses"
276
+ >
277
+ {visibleTabs}
278
+ </Tabs>
279
+ );
280
+ }
281
+ ```
282
+
229
283
  ***
230
284
 
231
285
  ## Tabs.Deprecated