@mackin.com/styleguide 8.9.5 → 8.11.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 +9 -3
  2. package/index.js +32 -24
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -54,6 +54,8 @@ interface AutocompleteProps<T extends AutocompleteValue> {
54
54
  /** Defaults to 0ms. */
55
55
  getOptionsDebounceMs?: number;
56
56
  autoFocus?: boolean;
57
+ /** Will enable scrolling in the results list. */
58
+ allowScroll?: boolean;
57
59
  onChange: (value: string) => void;
58
60
  getOptions: (value: string) => Promise<T[]>;
59
61
  onPick: (value: T) => void;
@@ -882,18 +884,22 @@ interface SliderProps<T extends SliderValue> {
882
884
  renderValue?: (value: number) => string;
883
885
  /** Used with renderValue for the custom element width. Defaults to theme.controls.height * 2. */
884
886
  renderValueWidth?: string;
887
+ /** The with and height of the handles. Defaults to theme.controls.height. Do not use css to change the handle sizes. */
888
+ sliderHandleSize?: string;
885
889
  /** Styles of the overall slider. */
886
890
  className?: string;
887
- /** Styles for the slider handles. */
891
+ /** Styles for the slider handles. Do not use css to change the handle sizes. Use 'sliderHandleSize'. */
888
892
  handleClassName?: string;
889
- /** Styles for the first handle. */
893
+ /** Styles for the first handle. Do not use css to change the handle sizes. Use 'sliderHandleSize'. */
890
894
  handle1ClassName?: string;
891
- /** Styles for the second handle. Ignored if the value is not an array. */
895
+ /** Styles for the second handle. Ignored if the value is not an array. Do not use css to change the handle sizes. Use 'sliderHandleSize'. */
892
896
  handle2ClassName?: string;
893
897
  /** Styles of the track. */
894
898
  trackClassName?: string;
895
899
  /** Styles applied to the track between two handlers. Ignored if the value is not an array. */
896
900
  innerTrackClassName?: string;
901
+ /** Styles applied to the floating handle text with using 'showValue'. */
902
+ sliderTextClassName?: string;
897
903
  }
898
904
  declare const Slider: <T extends SliderValue>(p: SliderProps<T>) => JSX.Element;
899
905
 
package/index.js CHANGED
@@ -891,16 +891,19 @@ const TabLocker = (props) => {
891
891
  const defaultMaxShownValues = 7;
892
892
  const buttonMarkerClass = 'ListItem__button';
893
893
  const Autocomplete = (p) => {
894
- var _a;
894
+ var _a, _b;
895
895
  const theme = useThemeSafely();
896
896
  const element = React__namespace.useRef(null);
897
897
  const input = React__namespace.useRef(null);
898
898
  const list = React__namespace.useRef(null);
899
899
  const [values, setValues] = React__namespace.useState([]);
900
900
  const showValues = React__namespace.useMemo(() => values.length > 0, [values]);
901
+ const maxShowValues = (_a = p.maxShownValues) !== null && _a !== void 0 ? _a : defaultMaxShownValues;
901
902
  const shownValues = React__namespace.useMemo(() => {
902
- var _a;
903
- return values.slice(0, (_a = p.maxShownValues) !== null && _a !== void 0 ? _a : defaultMaxShownValues);
903
+ if (!p.allowScroll) {
904
+ return values.slice(0, maxShowValues);
905
+ }
906
+ return values.slice();
904
907
  }, [values]);
905
908
  const onChangeForOptions = React__namespace.useRef(lodash.debounce((value) => {
906
909
  if (!p.minChars || value.length >= p.minChars) {
@@ -914,7 +917,7 @@ const Autocomplete = (p) => {
914
917
  else {
915
918
  setValues([]);
916
919
  }
917
- }, (_a = p.getOptionsDebounceMs) !== null && _a !== void 0 ? _a : 0, { leading: false, trailing: true }));
920
+ }, (_b = p.getOptionsDebounceMs) !== null && _b !== void 0 ? _b : 0, { leading: false, trailing: true }));
918
921
  const getNextTabElement = (fromIndex, direction) => {
919
922
  var _a, _b, _c;
920
923
  if (fromIndex === -1) {
@@ -983,7 +986,7 @@ const Autocomplete = (p) => {
983
986
  }
984
987
  (_c = p.onKeyDown) === null || _c === void 0 ? void 0 : _c.call(p, e);
985
988
  }, onKeyPress: e => { var _a; return (_a = p.onKeyPress) === null || _a === void 0 ? void 0 : _a.call(p, e); } }),
986
- showValues && (React__namespace.createElement(List, { ref: list, className: css.css({
989
+ showValues && (React__namespace.createElement(List, { ref: list, className: css.cx(css.css({
987
990
  position: 'absolute',
988
991
  width: '100%',
989
992
  border: theme.controls.border,
@@ -1000,7 +1003,10 @@ const Autocomplete = (p) => {
1000
1003
  borderBottomRightRadius: listBorderRadius,
1001
1004
  borderBottomLeftRadius: listBorderRadius,
1002
1005
  }
1003
- }) },
1006
+ }), p.allowScroll && shownValues.length > maxShowValues && css.css({
1007
+ overflowY: 'scroll',
1008
+ maxHeight: `calc(${theme.controls.height} * ${maxShowValues})`
1009
+ })) },
1004
1010
  shownValues.map((value, listItemIndex) => {
1005
1011
  return (React__namespace.createElement(ListItem, { key: getAutocompleteValueId(value), variant: "full" },
1006
1012
  React__namespace.createElement(Button, { onKeyDown: e => {
@@ -1029,7 +1035,7 @@ const Autocomplete = (p) => {
1029
1035
  } },
1030
1036
  React__namespace.createElement(Text, { tag: "div", ellipsis: true, align: "left" }, getAutocompleteValueText(value)))));
1031
1037
  }),
1032
- shownValues.length < values.length && (React__namespace.createElement(ListItem, null,
1038
+ !p.allowScroll && shownValues.length < values.length && (React__namespace.createElement(ListItem, null,
1033
1039
  React__namespace.createElement(Text, { tag: "div", italics: true, align: "center" },
1034
1040
  "Showing ",
1035
1041
  shownValues.length.toLocaleString(),
@@ -3215,8 +3221,6 @@ const OmniLink = (props) => {
3215
3221
  };
3216
3222
 
3217
3223
  const roundPxPadding = '4px';
3218
- //TB: needs to be 2rem padding for right caret
3219
- //TB: the generated border is bad (border: 1pxsolidrgba(0, 0, 0, 0.125);)
3220
3224
  const Picker = (props) => {
3221
3225
  const selectProps = __rest(props
3222
3226
  // if we put numbers in, we expect them out
@@ -3846,6 +3850,7 @@ const SearchBox = (props) => {
3846
3850
  }), props.buttonClassName), variant: "icon", small: true },
3847
3851
  React__namespace.createElement(Icon, { id: waiting ? 'waiting' : 'search', spin: waiting })));
3848
3852
  //TB: FUTURE replace with new inputs
3853
+ //TB: change the search icon to x when value is present
3849
3854
  const input = (React__namespace.createElement(Input, { inputClassName: props.inputClassName, autoFocus: props.autoFocus, id: props.id, debounceMs: props.debounceMs, disabled: waiting, type: "text", value: props.value, placeholder: props.placeholder, round: props.round, onChange: props.onChange, rightControl: submitButton }));
3850
3855
  const wrapperClassName = css.cx('searchBox', props.className);
3851
3856
  if (!props.noForm) {
@@ -3883,10 +3888,12 @@ const GlobalStyles = (p) => {
3883
3888
  };
3884
3889
 
3885
3890
  const Slider = (p) => {
3891
+ var _a;
3886
3892
  const theme = useThemeSafely();
3887
3893
  const currentValue = React.useRef(p.value);
3888
3894
  const sliderContainer = React.useRef(null);
3889
- const height = p.showValue ? `calc(${theme.controls.height} + 1.5rem)` : theme.controls.height;
3895
+ const sliderHandleSize = (_a = p.sliderHandleSize) !== null && _a !== void 0 ? _a : theme.controls.height;
3896
+ const height = p.showValue ? `calc(${sliderHandleSize} + 1.5rem)` : sliderHandleSize;
3890
3897
  return (React__default['default'].createElement("div", { ref: sliderContainer, className: css.cx(css.css({
3891
3898
  label: 'Slider',
3892
3899
  width: '100%',
@@ -3900,17 +3907,17 @@ const Slider = (p) => {
3900
3907
  (_a = p.onUpdate) === null || _a === void 0 ? void 0 : _a.call(p, value);
3901
3908
  } : undefined, renderTrack: (props, state) => {
3902
3909
  const { className } = props, rest = __rest(props, ["className"]);
3903
- return React__default['default'].createElement("div", Object.assign({ className: css.cx(className, css.css({
3910
+ return (React__default['default'].createElement("div", Object.assign({ className: css.cx(className, p.trackClassName, css.css({
3904
3911
  display: 'flex',
3905
3912
  alignItems: 'center',
3906
- height: theme.controls.height
3907
- }), p.trackClassName) }, rest),
3913
+ height: sliderHandleSize
3914
+ })) }, rest),
3908
3915
  React__default['default'].createElement("div", { className: css.css({
3909
3916
  backgroundColor: theme.colors.secondary,
3910
- height: `calc(${theme.controls.height} / 4)`,
3917
+ height: `calc(${sliderHandleSize} / 4)`,
3911
3918
  borderRadius: theme.controls.roundRadius,
3912
3919
  width: '100%'
3913
- }, p.innerTrackClassName && rest.key === 'track-1' && Array.isArray(p.value) ? p.innerTrackClassName : undefined) }));
3920
+ }, p.innerTrackClassName && rest.key === 'track-1' && Array.isArray(p.value) ? p.innerTrackClassName : undefined) })));
3914
3921
  }, renderThumb: (props, state) => {
3915
3922
  const { className } = props, rest = __rest(props, ["className"]);
3916
3923
  let specificThumbStyles;
@@ -3921,8 +3928,6 @@ const Slider = (p) => {
3921
3928
  specificThumbStyles = p.handle2ClassName;
3922
3929
  }
3923
3930
  return (React__default['default'].createElement("div", Object.assign({ className: css.cx(className, css.css({
3924
- width: theme.controls.height,
3925
- height: theme.controls.height,
3926
3931
  borderRadius: theme.controls.roundRadius,
3927
3932
  backgroundColor: 'white',
3928
3933
  border: theme.controls.border,
@@ -3940,7 +3945,10 @@ const Slider = (p) => {
3940
3945
  '&:hover': {
3941
3946
  filter: theme.controls.hoverBrightness
3942
3947
  }
3943
- }), specificThumbStyles, p.handleClassName) }, rest), p.showValue && (React__default['default'].createElement(HandleText, { index: state.index, parentElement: sliderContainer.current, value: Array.isArray(currentValue.current) ? currentValue.current[state.index] : currentValue.current, renderValue: p.renderValue, renderValueWidth: p.renderValueWidth }))));
3948
+ }), specificThumbStyles, p.handleClassName, css.css({
3949
+ width: sliderHandleSize,
3950
+ height: sliderHandleSize,
3951
+ })) }, rest), p.showValue && (React__default['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 }))));
3944
3952
  } })));
3945
3953
  };
3946
3954
  const rectsCollideX = (r1, r2) => {
@@ -3954,13 +3962,13 @@ const rectsCollideX = (r1, r2) => {
3954
3962
  };
3955
3963
  const HandleText = (p) => {
3956
3964
  var _a, _b, _c;
3957
- const theme = useThemeSafely();
3958
3965
  const displayValue = (_b = (_a = p.renderValue) === null || _a === void 0 ? void 0 : _a.call(p, p.value)) !== null && _b !== void 0 ? _b : p.value;
3959
- const renderValueWidth = (_c = p.renderValueWidth) !== null && _c !== void 0 ? _c : theme.controls.height;
3966
+ const renderValueWidth = (_c = p.renderValueWidth) !== null && _c !== void 0 ? _c : p.sliderHandleSize;
3960
3967
  const renderValueLeft = React.useMemo(() => {
3961
- return `calc(${renderValueWidth} * 0.5 * -1 + (${theme.controls.height} * 0.5))`;
3968
+ return `calc(${renderValueWidth} * 0.5 * -1 + (${p.sliderHandleSize} * 0.5))`;
3962
3969
  }, [p.renderValueWidth]);
3963
3970
  const [flipText, setFlipText] = React.useState(false);
3971
+ const offset = '2px';
3964
3972
  React.useEffect(() => {
3965
3973
  // this needs to fire on every render due to the other handle also moving.
3966
3974
  var _a, _b;
@@ -3975,11 +3983,11 @@ const HandleText = (p) => {
3975
3983
  return (React__default['default'].createElement(Text, { ellipsis: true, className: css.cx('slider-handle', css.css({
3976
3984
  width: renderValueWidth,
3977
3985
  left: renderValueLeft,
3978
- top: flipText ? undefined : theme.controls.height,
3979
- bottom: flipText ? theme.controls.height : undefined,
3986
+ top: flipText ? undefined : `calc(${p.sliderHandleSize} + ${offset})`,
3987
+ bottom: flipText ? `calc(${p.sliderHandleSize} + ${offset})` : undefined,
3980
3988
  position: 'absolute',
3981
3989
  overflow: 'hidden',
3982
- })), tag: "div", align: "center" }, displayValue));
3990
+ }), p.className), tag: "div", align: "center" }, displayValue));
3983
3991
  };
3984
3992
 
3985
3993
  const TabHeader = (p) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "8.9.5",
3
+ "version": "8.11.1",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",