@mackin.com/styleguide 7.12.0 → 7.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +2 -0
  2. package/index.js +19 -17
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -29,6 +29,8 @@ interface AutocompleteProps {
29
29
  inputAriaAttributes?: React.AriaAttributes;
30
30
  /** Defaults to 0ms. */
31
31
  getOptionsDebounceMs?: number;
32
+ /** Will enable scrolling in the results list. */
33
+ allowScroll?: boolean;
32
34
  onChange: (value: string) => void;
33
35
  getOptions: (value: string) => Promise<AutocompleteValue[]>;
34
36
  onPick: (value: AutocompleteValue) => void;
package/index.js CHANGED
@@ -883,15 +883,19 @@ const getAutocompleteValueId = (v) => {
883
883
  };
884
884
  //TB: will need to use the new input
885
885
  const Autocomplete = (p) => {
886
- var _a;
886
+ var _a, _b;
887
887
  const element = React__namespace.useRef(null);
888
888
  const input = React__namespace.useRef(null);
889
889
  const list = React__namespace.useRef(null);
890
890
  const [values, setValues] = React__namespace.useState([]);
891
891
  const showValues = React__namespace.useMemo(() => values.length > 0, [values]);
892
+ const maxShowValues = (_a = p.maxShownValues) !== null && _a !== void 0 ? _a : DEFAULT_MAX_SHOWN_VALUES;
892
893
  const shownValues = React__namespace.useMemo(() => {
893
- var _a;
894
- return values.slice(0, (_a = p.maxShownValues) !== null && _a !== void 0 ? _a : DEFAULT_MAX_SHOWN_VALUES);
894
+ if (!p.allowScroll) {
895
+ //TB:normalize this value and use it below for list building
896
+ return values.slice(0, maxShowValues);
897
+ }
898
+ return values.slice();
895
899
  }, [values]);
896
900
  const onChangeForOptions = React__namespace.useRef(lodash.debounce((value) => {
897
901
  if (!p.minChars || value.length >= p.minChars) {
@@ -905,7 +909,7 @@ const Autocomplete = (p) => {
905
909
  else {
906
910
  setValues([]);
907
911
  }
908
- }, (_a = p.getOptionsDebounceMs) !== null && _a !== void 0 ? _a : 0, { leading: true, trailing: true }));
912
+ }, (_b = p.getOptionsDebounceMs) !== null && _b !== void 0 ? _b : 0, { leading: true, trailing: true }));
909
913
  const theme = useThemeSafely();
910
914
  const baseClass = css.css `
911
915
  label: Autocomplete;
@@ -923,6 +927,7 @@ const Autocomplete = (p) => {
923
927
  borderRadius: listBorderRadius,
924
928
  boxShadow: theme.controls.boxShadow,
925
929
  backgroundColor: theme.colors.bg,
930
+ color: theme.colors.font,
926
931
  marginTop: `-4px !important`,
927
932
  zIndex: theme.zIndexes.backdrop,
928
933
  'li:first-child button': {
@@ -932,7 +937,7 @@ const Autocomplete = (p) => {
932
937
  'li:last-child button': {
933
938
  borderBottomRightRadius: listBorderRadius,
934
939
  borderBottomLeftRadius: listBorderRadius,
935
- }
940
+ },
936
941
  });
937
942
  const inputClass = css.css `
938
943
  ${showValues && `
@@ -985,7 +990,10 @@ const Autocomplete = (p) => {
985
990
  }
986
991
  }
987
992
  }, onKeyPress: e => { var _a; return (_a = p.onKeyPress) === null || _a === void 0 ? void 0 : _a.call(p, e); } }),
988
- showValues && (React__namespace.createElement(List, { ref: list, className: listClass },
993
+ showValues && (React__namespace.createElement(List, { ref: list, className: css.cx(listClass, p.allowScroll && shownValues.length > maxShowValues && css.css({
994
+ overflowY: 'scroll',
995
+ maxHeight: `calc(${theme.controls.height} * ${maxShowValues})`
996
+ })) },
989
997
  shownValues.map((value, listItemIndex) => {
990
998
  return (React__namespace.createElement(ListItem, { key: getAutocompleteValueId(value), variant: "full" },
991
999
  React__namespace.createElement(Button, { onKeyDown: e => {
@@ -1012,7 +1020,7 @@ const Autocomplete = (p) => {
1012
1020
  } },
1013
1021
  React__namespace.createElement(Text, { tag: "div", ellipsis: true, align: "left" }, getAutocompleteValueText(value)))));
1014
1022
  }),
1015
- shownValues.length < values.length && (React__namespace.createElement(ListItem, null,
1023
+ !p.allowScroll && shownValues.length < values.length && (React__namespace.createElement(ListItem, null,
1016
1024
  React__namespace.createElement(Text, { tag: "div", italics: true, align: "center" },
1017
1025
  "Showing ",
1018
1026
  shownValues.length.toLocaleString(),
@@ -1049,9 +1057,6 @@ const BackdropContextProvider = (p) => {
1049
1057
  log('un-mounted');
1050
1058
  };
1051
1059
  }, []);
1052
- React.useEffect(() => {
1053
- log('re-rendered');
1054
- });
1055
1060
  React.useEffect(() => {
1056
1061
  log('showCount changed', showCount);
1057
1062
  }, [showCount]);
@@ -1105,9 +1110,6 @@ const BackdropOverlay = (p) => {
1105
1110
  log('unmounted');
1106
1111
  };
1107
1112
  }, []);
1108
- React.useEffect(() => {
1109
- log('re-rendered');
1110
- });
1111
1113
  React.useEffect(() => {
1112
1114
  log('context.showing changed', context.showing);
1113
1115
  }, [context.showing]);
@@ -1337,13 +1339,14 @@ const Modal = (p) => {
1337
1339
  const hasHeader = p.closeButton || p.heading;
1338
1340
  const contentRef = React__default['default'].useRef(null);
1339
1341
  const log = useLogger(`Modal ${(_a = p.id) !== null && _a !== void 0 ? _a : '?'}`, (_b = p.debug) !== null && _b !== void 0 ? _b : false);
1342
+ const showing = React.useRef(p.show);
1340
1343
  React.useEffect(() => {
1341
1344
  log('mounted');
1342
1345
  return () => {
1343
1346
  // handle the use of modals that are rendered only as show=true and then unmounted.
1344
1347
  backdrop.setShow(false);
1345
1348
  log('backdrop.setShow', false);
1346
- if (backdrop.showCount <= 1 && htmlBodyStyles) {
1349
+ if (showing.current && backdrop.showCount <= 1 && htmlBodyStyles) {
1347
1350
  log('backdrop.showCount', backdrop.showCount, 'removing htmlBodyStyles');
1348
1351
  document.body.classList.remove(htmlBodyStyles);
1349
1352
  }
@@ -1353,10 +1356,12 @@ const Modal = (p) => {
1353
1356
  React.useEffect(() => {
1354
1357
  log('show changed', p.show);
1355
1358
  backdrop.setShow(p.show);
1359
+ showing.current = p.show;
1356
1360
  log('backdrop.setShow', true);
1357
1361
  if (!htmlBodyStyles) {
1358
1362
  log('creating singleton htmlBodyStyles');
1359
1363
  htmlBodyStyles = css.css({
1364
+ label: 'ModalBodyOverrides',
1360
1365
  overflow: 'hidden',
1361
1366
  paddingRight: `${useScrollbarSize()}px`
1362
1367
  });
@@ -3787,9 +3792,6 @@ const WaitingIndicator = (p) => {
3787
3792
  log('unmounted');
3788
3793
  };
3789
3794
  }, []);
3790
- React.useEffect(() => {
3791
- log('re-rendered');
3792
- });
3793
3795
  }
3794
3796
  React.useEffect(() => {
3795
3797
  log('show changed', p.show);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "7.12.0",
3
+ "version": "7.13.1",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",