@mackin.com/styleguide 6.0.1-beta.1 → 6.2.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 +38 -13
  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
@@ -1591,7 +1591,7 @@ const Divider = (props) => {
1591
1591
 
1592
1592
  /** @jsx jsx */
1593
1593
  const ErrorModal = (props) => {
1594
- const { message } = props; __rest(props, ["message"]);
1594
+ const { message } = props;
1595
1595
  const theme = useThemeSafely();
1596
1596
  const modalStyles = react.css `
1597
1597
  .modalHeader {
@@ -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 `
@@ -3111,7 +3112,6 @@ const FileUploader = (p) => {
3111
3112
  message === 'failure' && (react.jsx(UploadInfoPanel, { variant: "error", message: fullFailureMessage, onClear: onClear }))));
3112
3113
  };
3113
3114
  const UploadInfoPanel = (p) => {
3114
- useThemeSafely();
3115
3115
  return (react.jsx(InfoPanel, { variant: p.variant },
3116
3116
  p.message,
3117
3117
  react.jsx(Button, { block: true, className: css.css({
@@ -3173,8 +3173,9 @@ const BoundStaticPager = (p) => {
3173
3173
  const Slider = (p) => {
3174
3174
  const theme = useThemeSafely();
3175
3175
  const currentValue = React.useRef(p.value);
3176
+ const sliderContainer = React.useRef(null);
3176
3177
  const height = p.showValue ? `calc(${theme.controls.height} + 1.5rem)` : theme.controls.height;
3177
- return (react.jsx("div", { css: {
3178
+ return (react.jsx("div", { ref: sliderContainer, css: {
3178
3179
  width: '100%',
3179
3180
  height,
3180
3181
  } },
@@ -3217,22 +3218,46 @@ const Slider = (p) => {
3217
3218
  '&:hover': {
3218
3219
  filter: theme.controls.hoverBrightness
3219
3220
  }
3220
- } }, props), p.showValue && react.jsx(HandleText, { value: currentValue.current, index: state.index, renderValue: p.renderValue })));
3221
+ } }, props), p.showValue && (react.jsx(HandleText, { index: state.index, parentElement: sliderContainer.current, value: Array.isArray(currentValue.current) ? currentValue.current[state.index] : currentValue.current, renderValue: p.renderValue, renderValueWidth: p.renderValueWidth }))));
3221
3222
  } })));
3222
3223
  };
3224
+ const rectsCollideX = (r1, r2) => {
3225
+ if (r1.left >= r2.left && r1.left <= r2.right) {
3226
+ return true;
3227
+ }
3228
+ if (r1.right >= r2.left && r1.right <= r2.right) {
3229
+ return true;
3230
+ }
3231
+ return false;
3232
+ };
3223
3233
  const HandleText = (p) => {
3224
3234
  var _a, _b, _c;
3225
3235
  const theme = useThemeSafely();
3226
- const value = Array.isArray(p.value) ? p.value[(_a = p.index) !== null && _a !== void 0 ? _a : 0] : p.value;
3227
- const displayValue = (_c = (_b = p.renderValue) === null || _b === void 0 ? void 0 : _b.call(p, value)) !== null && _c !== void 0 ? _c : value;
3228
- return (react.jsx(Text, { css: {
3229
- //width: theme.controls.height,
3230
- width: `calc(${theme.controls.height} * 2)`,
3231
- left: `calc(${theme.controls.height} / 2 * -1)`,
3232
- bottom: '-1.5rem',
3236
+ const displayValue = (_b = (_a = p.renderValue) === null || _a === void 0 ? void 0 : _a.call(p, p.value)) !== null && _b !== void 0 ? _b : p.value;
3237
+ const renderValueWidth = (_c = p.renderValueWidth) !== null && _c !== void 0 ? _c : theme.controls.height;
3238
+ const renderValueLeft = React.useMemo(() => {
3239
+ return `calc(${renderValueWidth} * 0.5 * -1 + (${theme.controls.height} * 0.5))`;
3240
+ }, [p.renderValueWidth]);
3241
+ const [flipText, setFlipText] = React.useState(false);
3242
+ React.useEffect(() => {
3243
+ // this needs to fire on every render due to the other handle also moving.
3244
+ var _a, _b;
3245
+ if (p.index === 1) {
3246
+ // only do this for the max/right-most handle
3247
+ const [r1, r2] = Array.from((_b = (_a = p.parentElement) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.slider-handle').values()) !== null && _b !== void 0 ? _b : []).map(e => e.getBoundingClientRect());
3248
+ if (r1 && r2) {
3249
+ setFlipText(rectsCollideX(r1, r2));
3250
+ }
3251
+ }
3252
+ });
3253
+ return (react.jsx(Text, { ellipsis: true, css: {
3254
+ width: renderValueWidth,
3255
+ left: renderValueLeft,
3256
+ top: flipText ? undefined : theme.controls.height,
3257
+ bottom: flipText ? theme.controls.height : undefined,
3233
3258
  position: 'absolute',
3234
- overflow: 'hidden'
3235
- }, tag: "div", align: "center" }, displayValue));
3259
+ overflow: 'hidden',
3260
+ }, className: "slider-handle", tag: "div", align: "center" }, displayValue));
3236
3261
  };
3237
3262
 
3238
3263
  /** @jsx jsx */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "6.0.1-beta.1",
3
+ "version": "6.2.0",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",