@mackin.com/styleguide 6.0.0 → 6.1.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 +2 -0
  2. package/index.js +29 -26
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -939,6 +939,8 @@ interface SliderProps<T extends SliderValue> {
939
939
  onUpdate?: (value: T) => void;
940
940
  /** Used with showValue. Will be called to render the display string. */
941
941
  renderValue?: (value: number) => string;
942
+ /** Used with renderValue for the custom element width. Defaults to theme.controls.height * 2. */
943
+ renderValueWidth?: string;
942
944
  }
943
945
  declare const Slider: <T extends SliderValue>(p: SliderProps<T>) => jsx.JSX.Element;
944
946
 
package/index.js CHANGED
@@ -1835,6 +1835,7 @@ const FormColumnRow = (props) => {
1835
1835
  };
1836
1836
 
1837
1837
  /** @jsx jsx */
1838
+ //TB: have a sticky variant
1838
1839
  const Header = (props) => {
1839
1840
  const theme = useThemeSafely();
1840
1841
  const bodyStyles = css.css `
@@ -2067,7 +2068,7 @@ const formatLocalValue = (value, type) => {
2067
2068
  return newValue;
2068
2069
  };
2069
2070
  const Input = (props) => {
2070
- var _a, _b;
2071
+ var _a, _b, _c;
2071
2072
  const [localValue, setLocalValue] = React__namespace.useState(formatLocalValue(props.value, props.type));
2072
2073
  const debounceMs = (_a = props.debounceMs) !== null && _a !== void 0 ? _a : DEFAULT_DEBOUNCE_MS;
2073
2074
  const autoComplete = (_b = props.autoComplete) !== null && _b !== void 0 ? _b : 'off';
@@ -2075,9 +2076,10 @@ const Input = (props) => {
2075
2076
  wrappedOnChange: (props.onChange && debounceMs) ? lodash.debounce((value) => {
2076
2077
  var _a;
2077
2078
  (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, value);
2078
- }, debounceMs) : props.onChange,
2079
+ }, debounceMs) : undefined,
2079
2080
  focused: false
2080
2081
  });
2082
+ const onChange = (_c = vars.current.wrappedOnChange) !== null && _c !== void 0 ? _c : props.onChange;
2081
2083
  const trySyncLocalValue = () => {
2082
2084
  if (vars.current.focused) {
2083
2085
  return;
@@ -2163,15 +2165,11 @@ const Input = (props) => {
2163
2165
  numValue = props.max;
2164
2166
  }
2165
2167
  setLocalValue(numValue);
2166
- if (vars.current.wrappedOnChange) {
2167
- vars.current.wrappedOnChange(numValue);
2168
- }
2168
+ onChange === null || onChange === void 0 ? void 0 : onChange(numValue);
2169
2169
  }
2170
2170
  else if (!value) {
2171
2171
  setLocalValue(value);
2172
- if (vars.current.wrappedOnChange) {
2173
- vars.current.wrappedOnChange(undefined);
2174
- }
2172
+ onChange === null || onChange === void 0 ? void 0 : onChange(undefined);
2175
2173
  }
2176
2174
  } });
2177
2175
  }
@@ -2179,10 +2177,10 @@ const Input = (props) => {
2179
2177
  inputElement = react.jsx("input", { style: props.style, autoComplete: autoComplete, tabIndex: props.readOnly ? -1 : undefined, readOnly: props.readOnly, maxLength: 10, required: props.required, disabled: props.disabled, id: props.id, css: inputStyles, className: props.inputClassName, placeholder: props.placeholder, type: "text", value: localValue, onFocus: onFocus, onBlur: onBlur, onChange: e => {
2180
2178
  const value = e.target.value;
2181
2179
  setLocalValue(value);
2182
- if (vars.current.wrappedOnChange) {
2180
+ if (onChange) {
2183
2181
  const dateParts = DATE_REGEX.exec(value);
2184
2182
  if (!dateParts) {
2185
- vars.current.wrappedOnChange(undefined);
2183
+ onChange(undefined);
2186
2184
  }
2187
2185
  else {
2188
2186
  const year = parseInt(dateParts[3], 10);
@@ -2196,10 +2194,10 @@ const Input = (props) => {
2196
2194
  if (props.max && ms > props.max) {
2197
2195
  ms = props.max;
2198
2196
  }
2199
- vars.current.wrappedOnChange(ms);
2197
+ onChange(ms);
2200
2198
  }
2201
2199
  else {
2202
- vars.current.wrappedOnChange(undefined);
2200
+ onChange(undefined);
2203
2201
  }
2204
2202
  }
2205
2203
  }
@@ -2215,9 +2213,7 @@ const Input = (props) => {
2215
2213
  `, className: props.inputClassName, placeholder: props.placeholder, value: localValue, onFocus: onFocus, onBlur: onBlur, onChange: e => {
2216
2214
  const value = e.target.value;
2217
2215
  setLocalValue(value);
2218
- if (vars.current.wrappedOnChange) {
2219
- vars.current.wrappedOnChange(value);
2220
- }
2216
+ onChange === null || onChange === void 0 ? void 0 : onChange(value);
2221
2217
  } });
2222
2218
  }
2223
2219
  else {
@@ -2225,9 +2221,7 @@ const Input = (props) => {
2225
2221
  inputElement = react.jsx("input", { style: props.style, autoComplete: autoComplete, tabIndex: props.readOnly ? -1 : undefined, readOnly: props.readOnly, maxLength: props.maxLength || DEFAULT_MAX_LENGTH, required: props.required, disabled: props.disabled, id: props.id, css: inputStyles, className: props.inputClassName, placeholder: props.placeholder, type: props.type, value: localValue, onFocus: onFocus, onBlur: onBlur, onChange: e => {
2226
2222
  const value = e.target.value;
2227
2223
  setLocalValue(value);
2228
- if (vars.current.wrappedOnChange) {
2229
- vars.current.wrappedOnChange(value);
2230
- }
2224
+ onChange === null || onChange === void 0 ? void 0 : onChange(value);
2231
2225
  } });
2232
2226
  }
2233
2227
  const inputWrapperStyles = react.css `
@@ -2667,7 +2661,15 @@ const useWaiting = (func) => {
2667
2661
 
2668
2662
  /** @jsx jsx */
2669
2663
  const SearchBox = (props) => {
2670
- const [waiting, onSubmit] = useWaiting(props.onSubmit || (() => Promise.resolve()));
2664
+ const [waiting, onSubmit] = useWaiting(async () => {
2665
+ var _a, _b, _c;
2666
+ // the active element will be the input. if the submit action changes props.value it will
2667
+ // be ignored due to Inputs focused handling.
2668
+ if (document.activeElement) {
2669
+ (_b = (_a = document.activeElement).blur) === null || _b === void 0 ? void 0 : _b.call(_a);
2670
+ }
2671
+ return (_c = props.onSubmit) === null || _c === void 0 ? void 0 : _c.call(props);
2672
+ });
2671
2673
  const theme = useThemeSafely();
2672
2674
  const submitButton = (react.jsx(Button, { disabled: waiting, readonly: !props.onSubmit, type: "submit", css: {
2673
2675
  color: `${theme.colors.font} !important;`,
@@ -3216,21 +3218,22 @@ const Slider = (p) => {
3216
3218
  '&:hover': {
3217
3219
  filter: theme.controls.hoverBrightness
3218
3220
  }
3219
- } }, props), p.showValue && react.jsx(HandleText, { value: currentValue.current, index: state.index, renderValue: p.renderValue })));
3221
+ } }, props), p.showValue && react.jsx(HandleText, { value: currentValue.current, index: state.index, renderValue: p.renderValue, renderValueWidth: p.renderValueWidth })));
3220
3222
  } })));
3221
3223
  };
3222
3224
  const HandleText = (p) => {
3223
- var _a, _b, _c;
3225
+ var _a, _b, _c, _d;
3224
3226
  const theme = useThemeSafely();
3225
3227
  const value = Array.isArray(p.value) ? p.value[(_a = p.index) !== null && _a !== void 0 ? _a : 0] : p.value;
3226
3228
  const displayValue = (_c = (_b = p.renderValue) === null || _b === void 0 ? void 0 : _b.call(p, value)) !== null && _c !== void 0 ? _c : value;
3227
- return (react.jsx(Text, { css: {
3228
- //width: theme.controls.height,
3229
- width: `calc(${theme.controls.height} * 2)`,
3230
- left: `calc(${theme.controls.height} / 2 * -1)`,
3229
+ const renderValueWidth = (_d = p.renderValueWidth) !== null && _d !== void 0 ? _d : theme.controls.height;
3230
+ const renderValueLeft = `calc(${renderValueWidth} * 0.5 * -1 + (${theme.controls.height} * 0.5))`;
3231
+ return (react.jsx(Text, { ellipsis: true, css: {
3232
+ width: renderValueWidth,
3233
+ left: renderValueLeft,
3231
3234
  bottom: '-1.5rem',
3232
3235
  position: 'absolute',
3233
- overflow: 'hidden'
3236
+ overflow: 'hidden',
3234
3237
  }, tag: "div", align: "center" }, displayValue));
3235
3238
  };
3236
3239
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",