@mackin.com/styleguide 7.12.1 → 7.14.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.
Files changed (3) hide show
  1. package/index.d.ts +7 -0
  2. package/index.js +15 -7
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -29,6 +29,13 @@ interface AutocompleteProps {
29
29
  inputAriaAttributes?: React.AriaAttributes;
30
30
  /** Defaults to 0ms. */
31
31
  getOptionsDebounceMs?: number;
32
+ /** Options passed to the lodash debounce function. */
33
+ debounceOptions?: {
34
+ leading: boolean;
35
+ trailing: boolean;
36
+ };
37
+ /** Will enable scrolling in the results list. */
38
+ allowScroll?: boolean;
32
39
  onChange: (value: string) => void;
33
40
  getOptions: (value: string) => Promise<AutocompleteValue[]>;
34
41
  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, _c;
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, (_c = p.debounceOptions) !== null && _c !== void 0 ? _c : { 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(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "7.12.1",
3
+ "version": "7.14.0",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",