@mackin.com/styleguide 10.2.2 → 10.2.6

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/index.d.ts CHANGED
@@ -140,6 +140,7 @@ interface CheckboxProps extends Omit<React.DetailedHTMLProps<React.InputHTMLAttr
140
140
  checkedThemeColor?: 'primary' | 'primary2' | 'secondary';
141
141
  /** Background color when checked. Mutually exclusive with 'checkedThemeColor'. */
142
142
  checkedColor?: string;
143
+ tabIndex?: number | undefined;
143
144
  }
144
145
  declare const Checkbox: (props: CheckboxProps) => React.JSX.Element;
145
146
 
@@ -863,8 +864,9 @@ interface SliderProps<T extends SliderValue> {
863
864
  innerTrackClassName?: string;
864
865
  /** Styles applied to the floating handle text with using 'showValue'. */
865
866
  sliderTextClassName?: string;
866
- /** Styles applied to the floating handle text with using 'showValue'. */
867
+ /** Sets the aria-label value. */
867
868
  ariaLabel?: (T extends number ? string : readonly string[] | undefined) | undefined;
869
+ tabIndex?: number | undefined;
868
870
  }
869
871
  declare const Slider: <T extends SliderValue>(p: SliderProps<T>) => React__default.JSX.Element;
870
872
 
package/index.esm.js CHANGED
@@ -510,6 +510,7 @@ const Accordian = (props) => {
510
510
  const [open, setOpen] = React.useState(false);
511
511
  const theme = useThemeSafely();
512
512
  const content = React.useRef(null);
513
+ const [children, setChildren] = React.useState();
513
514
  const contentStyles = css({
514
515
  overflow: 'hidden',
515
516
  maxHeight: 0,
@@ -525,6 +526,7 @@ const Accordian = (props) => {
525
526
  const currentContent = content.current;
526
527
  if (currentContent) {
527
528
  if (open) {
529
+ setChildren(props.children);
528
530
  currentContent.classList.add(expandedContentStyles);
529
531
  window.setTimeout(() => {
530
532
  currentContent.classList.add(visibleStyle);
@@ -532,6 +534,11 @@ const Accordian = (props) => {
532
534
  }
533
535
  else {
534
536
  currentContent.classList.remove(visibleStyle, expandedContentStyles);
537
+ if (children !== undefined) {
538
+ window.setTimeout(() => {
539
+ setChildren(undefined);
540
+ }, accordianExpandTimeMs);
541
+ }
535
542
  }
536
543
  }
537
544
  }, [open]);
@@ -544,7 +551,7 @@ const Accordian = (props) => {
544
551
  }
545
552
  setOpen((_a = props.open) !== null && _a !== void 0 ? _a : false);
546
553
  }, [props.open]);
547
- return (React.createElement("div", { className: "accordian" },
554
+ return (React.createElement("div", { className: "accordian", "aria-expanded": open },
548
555
  React.createElement(Button, { readOnly: props.disabled, variant: props.variant, className: cx(css({
549
556
  display: 'flex',
550
557
  alignItems: 'center',
@@ -563,7 +570,7 @@ const Accordian = (props) => {
563
570
  }, rightIcon: !props.disabled ? React.createElement(Icon, { id: open ? 'collapse' : 'expand' }) : undefined },
564
571
  React.createElement("span", null, props.header)),
565
572
  React.createElement("div", { ref: content, className: cx('accordian__body', contentStyles) },
566
- React.createElement("div", { className: expandedContentWrapperStyles }, props.children))));
573
+ React.createElement("div", { className: expandedContentWrapperStyles }, children))));
567
574
  };
568
575
  const useAccordianState = (count, openIndex) => {
569
576
  const [panels, setShowPanel] = React.useState(new Array(count).fill(false).map((b, i) => {
@@ -969,13 +976,14 @@ const defaultMaxShownValues = 7;
969
976
  const buttonMarkerClass = 'ListItem__button';
970
977
  const defaultOnPickFocusMs = 100;
971
978
  const Autocomplete = (p) => {
972
- var _a;
979
+ var _a, _b;
973
980
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
974
981
  const inputProps = __rest(p, ["value", "className", "inputWrapperClassName", "inputClassName", "listClassName", "listItemClassName", "listItemButtonClassName", "maxShownValues", "allowScroll", "options", "onPick", "onPickFocusWaitMs"]);
975
982
  const theme = useThemeSafely();
976
983
  const element = React.useRef(null);
977
984
  const input = React.useRef(null);
978
985
  const list = React.useRef(null);
986
+ const [selectedResultIndex, setSelectedResultIndex] = React.useState();
979
987
  const maxShowValues = (_a = p.maxShownValues) !== null && _a !== void 0 ? _a : defaultMaxShownValues;
980
988
  const displayOptions = React.useMemo(() => {
981
989
  if (!p.allowScroll) {
@@ -994,10 +1002,12 @@ const Autocomplete = (p) => {
994
1002
  if (direction === -1) {
995
1003
  buttonIndex = displayOptions.length - 1;
996
1004
  }
1005
+ setSelectedResultIndex(buttonIndex);
997
1006
  return (_a = list.current) === null || _a === void 0 ? void 0 : _a.querySelector(`.${buttonMarkerClass}${buttonIndex}`);
998
1007
  }
999
1008
  else {
1000
1009
  const nextIndex = fromIndex + direction;
1010
+ setSelectedResultIndex(nextIndex);
1001
1011
  if (nextIndex >= displayOptions.length || nextIndex < 0) {
1002
1012
  return (_b = input.current) !== null && _b !== void 0 ? _b : undefined;
1003
1013
  }
@@ -1021,6 +1031,7 @@ const Autocomplete = (p) => {
1021
1031
  if (p.round || theme.controls.borderRadius) {
1022
1032
  listBorderRadius = theme.controls.borderRadius || '0.5rem';
1023
1033
  }
1034
+ const id = (_b = p.id) !== null && _b !== void 0 ? _b : `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1024
1035
  const onPickValue = (v) => {
1025
1036
  var _a;
1026
1037
  // the TextInput will not respond to outer value changes if it has focus.
@@ -1068,8 +1079,9 @@ const Autocomplete = (p) => {
1068
1079
  }
1069
1080
  }
1070
1081
  (_c = p.onKeyDown) === null || _c === void 0 ? void 0 : _c.call(p, e);
1071
- } })),
1072
- !!displayOptions.length && (React.createElement(List, { ref: list, className: cx(css({
1082
+ }, "aria-owns": id, "aria-expanded": !!displayOptions.length, "aria-autocomplete": "both", "aria-describedby": `${id}-aria-description` })),
1083
+ React.createElement("span", { id: `${id}-aria-description`, className: css({ display: "none" }) }, "When autocomplete results are available use up and down arrows to review and enter to select."),
1084
+ !!displayOptions.length && (React.createElement(List, { id: id, ref: list, role: "listbox", className: cx(css({
1073
1085
  position: 'absolute',
1074
1086
  width: '100%',
1075
1087
  border: theme.controls.border,
@@ -1092,7 +1104,7 @@ const Autocomplete = (p) => {
1092
1104
  }), p.listClassName) },
1093
1105
  displayOptions.map((v, listItemIndex) => {
1094
1106
  var _a;
1095
- return (React.createElement(ListItem, { key: v, variant: "full", className: p.listItemClassName },
1107
+ return (React.createElement(ListItem, { key: v, variant: "full", className: p.listItemClassName, role: "option", "aria-selected": selectedResultIndex === listItemIndex },
1096
1108
  React.createElement(Button, { title: ((_a = p.showOptionTextAsTitle) !== null && _a !== void 0 ? _a : true) ? v : undefined, onKeyDown: e => {
1097
1109
  var _a, _b;
1098
1110
  if (e.key === 'ArrowDown') {
@@ -1480,6 +1492,7 @@ const Calendar = (p) => {
1480
1492
  };
1481
1493
 
1482
1494
  const Checkbox = (props) => {
1495
+ var _a;
1483
1496
  const { onChange, label, checkedIcon, uncheckedIcon, checkedThemeColor, checkedColor, readOnly } = props, inputProps = __rest(props, ["onChange", "label", "checkedIcon", "uncheckedIcon", "checkedThemeColor", "checkedColor", "readOnly"]);
1484
1497
  const selected = checkedIcon || 'selected';
1485
1498
  const unselected = uncheckedIcon || 'unselected';
@@ -1544,7 +1557,7 @@ const Checkbox = (props) => {
1544
1557
  `;
1545
1558
  return (React.createElement("span", { className: cx('checkbox', checkboxStyles, props.className) },
1546
1559
  React.createElement("label", { className: labelStyles },
1547
- React.createElement("input", Object.assign({}, inputProps, { tabIndex: readOnly ? -1 : undefined, className: nativeCheckboxStyles, type: "checkbox", onChange: e => {
1560
+ React.createElement("input", Object.assign({}, inputProps, { tabIndex: readOnly ? -1 : (_a = props.tabIndex) !== null && _a !== void 0 ? _a : undefined, className: nativeCheckboxStyles, type: "checkbox", onChange: e => {
1548
1561
  if (readOnly) {
1549
1562
  e.preventDefault();
1550
1563
  return;
@@ -3939,7 +3952,7 @@ const Slider = (p) => {
3939
3952
  }), specificThumbStyles, p.handleClassName, css({
3940
3953
  width: sliderHandleSize,
3941
3954
  height: sliderHandleSize,
3942
- })) }, rest), p.showValue && (React__default.createElement(HandleText, { sliderHandleSize: sliderHandleSize, className: p.sliderTextClassName, index: state.index, parentElement: sliderContainer.current, value: Array.isArray(currentValue.current) ? currentValue.current[state.index] : currentValue.current, renderValue: p.renderValue, renderValueWidth: p.renderValueWidth }))));
3955
+ })) }, rest, { tabIndex: p.tabIndex }), p.showValue && (React__default.createElement(HandleText, { sliderHandleSize: sliderHandleSize, className: p.sliderTextClassName, index: state.index, parentElement: sliderContainer.current, value: Array.isArray(currentValue.current) ? currentValue.current[state.index] : currentValue.current, renderValue: p.renderValue, renderValueWidth: p.renderValueWidth }))));
3943
3956
  } })));
3944
3957
  };
3945
3958
  const rectsCollideX = (r1, r2) => {
@@ -4044,7 +4057,7 @@ const TabHeader = (p) => {
4044
4057
  buttonContent = tab.name;
4045
4058
  }
4046
4059
  return (React.createElement("li", { key: index, className: cx(tabStyles, p.tabClassName) },
4047
- React.createElement(Button, { disabled: tabsChanging, className: buttonStyles, variant: buttonVariant, title: title, readOnly: active, onClick: () => {
4060
+ React.createElement(Button, { "aria-role": "tab", "aria-selected": active, disabled: tabsChanging, className: buttonStyles, variant: buttonVariant, title: title, readOnly: active, onClick: () => {
4048
4061
  const onChange = () => {
4049
4062
  var _a;
4050
4063
  setTabIndex(index);
package/index.js CHANGED
@@ -528,6 +528,7 @@ const Accordian = (props) => {
528
528
  const [open, setOpen] = React__namespace.useState(false);
529
529
  const theme = useThemeSafely();
530
530
  const content = React__namespace.useRef(null);
531
+ const [children, setChildren] = React__namespace.useState();
531
532
  const contentStyles = css.css({
532
533
  overflow: 'hidden',
533
534
  maxHeight: 0,
@@ -543,6 +544,7 @@ const Accordian = (props) => {
543
544
  const currentContent = content.current;
544
545
  if (currentContent) {
545
546
  if (open) {
547
+ setChildren(props.children);
546
548
  currentContent.classList.add(expandedContentStyles);
547
549
  window.setTimeout(() => {
548
550
  currentContent.classList.add(visibleStyle);
@@ -550,6 +552,11 @@ const Accordian = (props) => {
550
552
  }
551
553
  else {
552
554
  currentContent.classList.remove(visibleStyle, expandedContentStyles);
555
+ if (children !== undefined) {
556
+ window.setTimeout(() => {
557
+ setChildren(undefined);
558
+ }, accordianExpandTimeMs);
559
+ }
553
560
  }
554
561
  }
555
562
  }, [open]);
@@ -562,7 +569,7 @@ const Accordian = (props) => {
562
569
  }
563
570
  setOpen((_a = props.open) !== null && _a !== void 0 ? _a : false);
564
571
  }, [props.open]);
565
- return (React__namespace.createElement("div", { className: "accordian" },
572
+ return (React__namespace.createElement("div", { className: "accordian", "aria-expanded": open },
566
573
  React__namespace.createElement(Button, { readOnly: props.disabled, variant: props.variant, className: css.cx(css.css({
567
574
  display: 'flex',
568
575
  alignItems: 'center',
@@ -581,7 +588,7 @@ const Accordian = (props) => {
581
588
  }, rightIcon: !props.disabled ? React__namespace.createElement(Icon, { id: open ? 'collapse' : 'expand' }) : undefined },
582
589
  React__namespace.createElement("span", null, props.header)),
583
590
  React__namespace.createElement("div", { ref: content, className: css.cx('accordian__body', contentStyles) },
584
- React__namespace.createElement("div", { className: expandedContentWrapperStyles }, props.children))));
591
+ React__namespace.createElement("div", { className: expandedContentWrapperStyles }, children))));
585
592
  };
586
593
  const useAccordianState = (count, openIndex) => {
587
594
  const [panels, setShowPanel] = React__namespace.useState(new Array(count).fill(false).map((b, i) => {
@@ -987,13 +994,14 @@ const defaultMaxShownValues = 7;
987
994
  const buttonMarkerClass = 'ListItem__button';
988
995
  const defaultOnPickFocusMs = 100;
989
996
  const Autocomplete = (p) => {
990
- var _a;
997
+ var _a, _b;
991
998
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
992
999
  const inputProps = __rest(p, ["value", "className", "inputWrapperClassName", "inputClassName", "listClassName", "listItemClassName", "listItemButtonClassName", "maxShownValues", "allowScroll", "options", "onPick", "onPickFocusWaitMs"]);
993
1000
  const theme = useThemeSafely();
994
1001
  const element = React__namespace.useRef(null);
995
1002
  const input = React__namespace.useRef(null);
996
1003
  const list = React__namespace.useRef(null);
1004
+ const [selectedResultIndex, setSelectedResultIndex] = React__namespace.useState();
997
1005
  const maxShowValues = (_a = p.maxShownValues) !== null && _a !== void 0 ? _a : defaultMaxShownValues;
998
1006
  const displayOptions = React__namespace.useMemo(() => {
999
1007
  if (!p.allowScroll) {
@@ -1012,10 +1020,12 @@ const Autocomplete = (p) => {
1012
1020
  if (direction === -1) {
1013
1021
  buttonIndex = displayOptions.length - 1;
1014
1022
  }
1023
+ setSelectedResultIndex(buttonIndex);
1015
1024
  return (_a = list.current) === null || _a === void 0 ? void 0 : _a.querySelector(`.${buttonMarkerClass}${buttonIndex}`);
1016
1025
  }
1017
1026
  else {
1018
1027
  const nextIndex = fromIndex + direction;
1028
+ setSelectedResultIndex(nextIndex);
1019
1029
  if (nextIndex >= displayOptions.length || nextIndex < 0) {
1020
1030
  return (_b = input.current) !== null && _b !== void 0 ? _b : undefined;
1021
1031
  }
@@ -1039,6 +1049,7 @@ const Autocomplete = (p) => {
1039
1049
  if (p.round || theme.controls.borderRadius) {
1040
1050
  listBorderRadius = theme.controls.borderRadius || '0.5rem';
1041
1051
  }
1052
+ const id = (_b = p.id) !== null && _b !== void 0 ? _b : `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1042
1053
  const onPickValue = (v) => {
1043
1054
  var _a;
1044
1055
  // the TextInput will not respond to outer value changes if it has focus.
@@ -1086,8 +1097,9 @@ const Autocomplete = (p) => {
1086
1097
  }
1087
1098
  }
1088
1099
  (_c = p.onKeyDown) === null || _c === void 0 ? void 0 : _c.call(p, e);
1089
- } })),
1090
- !!displayOptions.length && (React__namespace.createElement(List, { ref: list, className: css.cx(css.css({
1100
+ }, "aria-owns": id, "aria-expanded": !!displayOptions.length, "aria-autocomplete": "both", "aria-describedby": `${id}-aria-description` })),
1101
+ React__namespace.createElement("span", { id: `${id}-aria-description`, className: css.css({ display: "none" }) }, "When autocomplete results are available use up and down arrows to review and enter to select."),
1102
+ !!displayOptions.length && (React__namespace.createElement(List, { id: id, ref: list, role: "listbox", className: css.cx(css.css({
1091
1103
  position: 'absolute',
1092
1104
  width: '100%',
1093
1105
  border: theme.controls.border,
@@ -1110,7 +1122,7 @@ const Autocomplete = (p) => {
1110
1122
  }), p.listClassName) },
1111
1123
  displayOptions.map((v, listItemIndex) => {
1112
1124
  var _a;
1113
- return (React__namespace.createElement(ListItem, { key: v, variant: "full", className: p.listItemClassName },
1125
+ return (React__namespace.createElement(ListItem, { key: v, variant: "full", className: p.listItemClassName, role: "option", "aria-selected": selectedResultIndex === listItemIndex },
1114
1126
  React__namespace.createElement(Button, { title: ((_a = p.showOptionTextAsTitle) !== null && _a !== void 0 ? _a : true) ? v : undefined, onKeyDown: e => {
1115
1127
  var _a, _b;
1116
1128
  if (e.key === 'ArrowDown') {
@@ -1498,6 +1510,7 @@ const Calendar = (p) => {
1498
1510
  };
1499
1511
 
1500
1512
  const Checkbox = (props) => {
1513
+ var _a;
1501
1514
  const { onChange, label, checkedIcon, uncheckedIcon, checkedThemeColor, checkedColor, readOnly } = props, inputProps = __rest(props, ["onChange", "label", "checkedIcon", "uncheckedIcon", "checkedThemeColor", "checkedColor", "readOnly"]);
1502
1515
  const selected = checkedIcon || 'selected';
1503
1516
  const unselected = uncheckedIcon || 'unselected';
@@ -1562,7 +1575,7 @@ const Checkbox = (props) => {
1562
1575
  `;
1563
1576
  return (React__namespace.createElement("span", { className: css.cx('checkbox', checkboxStyles, props.className) },
1564
1577
  React__namespace.createElement("label", { className: labelStyles },
1565
- React__namespace.createElement("input", Object.assign({}, inputProps, { tabIndex: readOnly ? -1 : undefined, className: nativeCheckboxStyles, type: "checkbox", onChange: e => {
1578
+ React__namespace.createElement("input", Object.assign({}, inputProps, { tabIndex: readOnly ? -1 : (_a = props.tabIndex) !== null && _a !== void 0 ? _a : undefined, className: nativeCheckboxStyles, type: "checkbox", onChange: e => {
1566
1579
  if (readOnly) {
1567
1580
  e.preventDefault();
1568
1581
  return;
@@ -3957,7 +3970,7 @@ const Slider = (p) => {
3957
3970
  }), specificThumbStyles, p.handleClassName, css.css({
3958
3971
  width: sliderHandleSize,
3959
3972
  height: sliderHandleSize,
3960
- })) }, rest), p.showValue && (React.createElement(HandleText, { sliderHandleSize: sliderHandleSize, className: p.sliderTextClassName, index: state.index, parentElement: sliderContainer.current, value: Array.isArray(currentValue.current) ? currentValue.current[state.index] : currentValue.current, renderValue: p.renderValue, renderValueWidth: p.renderValueWidth }))));
3973
+ })) }, rest, { tabIndex: p.tabIndex }), p.showValue && (React.createElement(HandleText, { sliderHandleSize: sliderHandleSize, className: p.sliderTextClassName, index: state.index, parentElement: sliderContainer.current, value: Array.isArray(currentValue.current) ? currentValue.current[state.index] : currentValue.current, renderValue: p.renderValue, renderValueWidth: p.renderValueWidth }))));
3961
3974
  } })));
3962
3975
  };
3963
3976
  const rectsCollideX = (r1, r2) => {
@@ -4062,7 +4075,7 @@ const TabHeader = (p) => {
4062
4075
  buttonContent = tab.name;
4063
4076
  }
4064
4077
  return (React__namespace.createElement("li", { key: index, className: css.cx(tabStyles, p.tabClassName) },
4065
- React__namespace.createElement(Button, { disabled: tabsChanging, className: buttonStyles, variant: buttonVariant, title: title, readOnly: active, onClick: () => {
4078
+ React__namespace.createElement(Button, { "aria-role": "tab", "aria-selected": active, disabled: tabsChanging, className: buttonStyles, variant: buttonVariant, title: title, readOnly: active, onClick: () => {
4066
4079
  const onChange = () => {
4067
4080
  var _a;
4068
4081
  setTabIndex(index);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "10.2.2",
3
+ "version": "10.2.6",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "module": "./index.esm.js",