@mackin.com/styleguide 8.0.0-beta.13 → 8.0.0-beta.16

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 +11 -6
  2. package/index.js +63 -49
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -81,7 +81,7 @@ declare const Backdrop: (p: {
81
81
  children: React__default.ReactNode;
82
82
  /** Fade in time. Defaults to 250ms. */
83
83
  showTimeMs?: number;
84
- debug?: boolean;
84
+ __debug?: boolean;
85
85
  }) => JSX.Element;
86
86
 
87
87
  declare type ButtonVariant = 'label' | 'circle' | 'icon' | 'link' | 'inlineLink' | 'primary' | 'secondary' | 'omg' | 'primary2' | 'positive' | 'negative';
@@ -159,7 +159,7 @@ interface ConfirmModalProps {
159
159
  className?: string;
160
160
  variant?: 'omg';
161
161
  id?: string;
162
- debug?: boolean;
162
+ __debug?: boolean;
163
163
  }
164
164
  declare const ConfirmModal: (props: ConfirmModalProps) => JSX.Element;
165
165
 
@@ -176,7 +176,7 @@ declare const ErrorModal: (props: {
176
176
  message: string;
177
177
  show: boolean;
178
178
  id?: string;
179
- debug?: boolean;
179
+ __debug?: boolean;
180
180
  close: () => void;
181
181
  }) => JSX.Element;
182
182
 
@@ -290,7 +290,7 @@ interface InfoTipProps {
290
290
  /** Defaults to nav font color. */
291
291
  fontColor?: string;
292
292
  modalId?: string;
293
- modalDebug?: boolean;
293
+ __debug?: boolean;
294
294
  }
295
295
  declare const InfoTip: (props: InfoTipProps) => JSX.Element;
296
296
 
@@ -440,7 +440,7 @@ interface ModalProps {
440
440
  scrollable?: boolean;
441
441
  id?: string;
442
442
  className?: string;
443
- debug?: boolean;
443
+ __debug?: boolean;
444
444
  onClick?: () => void;
445
445
  }
446
446
  declare const Modal: (p: ModalProps) => React__default.ReactPortal | null;
@@ -448,6 +448,7 @@ declare const Modal: (p: ModalProps) => React__default.ReactPortal | null;
448
448
  declare const Nav: (props: {
449
449
  show: boolean;
450
450
  toggle: (show: boolean) => void;
451
+ id?: string | undefined;
451
452
  children?: React.ReactNode;
452
453
  responsive?: boolean | undefined;
453
454
  className?: string | undefined;
@@ -804,6 +805,10 @@ interface MackinTheme {
804
805
  desktop: string;
805
806
  tablet: string;
806
807
  };
808
+ mediaQueries: {
809
+ desktop: string;
810
+ tablet: string;
811
+ };
807
812
  }
808
813
  /** Call this on your theme after messing with the props. It will re-build things that depend on sizes and colors. */
809
814
  declare const calcDynamicThemeProps: <T extends MackinTheme>(theme: T) => void;
@@ -980,7 +985,7 @@ declare const WaitingIndicator: (p: {
980
985
  show: boolean;
981
986
  minShowTimeMs?: number;
982
987
  id?: string;
983
- debug?: boolean;
988
+ __debug?: boolean;
984
989
  }) => JSX.Element;
985
990
 
986
991
  export { Accordian, AccordianProps, Alignment, Autocomplete, AutocompleteProps, AutocompleteValue, Backdrop$1 as Backdrop, Backdrop as Backdrop2, BoundMemoryPager, BoundStaticPager, Button, ButtonProps, Calendar, CalendarProps, Checkbox, CheckboxProps, ConfirmModal, ConfirmModalProps, CopyButton, DateInput, DateInputProps, Divider, ErrorModal, FileUploader, Form, FormColumnRow, FormFlexRow, FormProps, GlobalStyles, Header, Highlight, ICONS, Icon, Image, InfoPanel, InfoTip, InfoTipProps, Input, InputProps, ItemPager, Label, LabelProps, List, ListItem, ListItemProps, ListProps, MackinTheme, Modal, Nav, NumberInput, NumberInputProps, OmniLink, OmniLinkProps, PagedResult, Pager, PagerProps, Picker, PickerProps, Popover, ProgressBar, ProgressBarProps, SearchBox, SearchBoxProps, Slider, TabHeader, TabHeaderProps, TabLocker, Table, Td, TdCurrency, TdNumber, Text, TextArea, TextAreaProps, TextInput, TextInputProps, TextProps, Th, ThSort, ThemeProvider, ToggleButton, ToggleButtonGroup, ToggleButtonGroupProps, ToggleButtonProps, TogglePasswordInput, Tr, WaitingIndicator, calcDynamicThemeProps, defaultTheme, getCurrencyDisplay, getFileSizeDisplay, useAccordianState, useMediaQuery, useThemeSafely };
package/index.js CHANGED
@@ -116,6 +116,8 @@ const calcDynamicThemeProps = (theme) => {
116
116
  theme.controls.focusOutlineRequiredShadow = `0px 0px 4px 2px ${theme.colors.focusOutlineRequired}`;
117
117
  theme.controls.dividerBorder = `2px solid ${theme.colors.divider}`;
118
118
  theme.controls.inputErrorMinHeight = `calc(${theme.fonts.sizeSmall} * 1.5 + 4px)`;
119
+ theme.mediaQueries.desktop = `@media(min-width:${theme.breakpoints.desktop})`;
120
+ theme.mediaQueries.tablet = `@media(min-width:${theme.breakpoints.tablet})`;
119
121
  };
120
122
  const defaultTheme = {
121
123
  colors: {
@@ -203,6 +205,10 @@ const defaultTheme = {
203
205
  breakpoints: {
204
206
  desktop: '800px',
205
207
  tablet: '768px'
208
+ },
209
+ mediaQueries: {
210
+ desktop: '',
211
+ tablet: ''
206
212
  }
207
213
  };
208
214
  calcDynamicThemeProps(defaultTheme);
@@ -435,12 +441,15 @@ const Accordian = (props) => {
435
441
  }
436
442
  }
437
443
  }, [open]);
438
- if (props.open !== undefined) {
439
- React__namespace.useEffect(() => {
440
- var _a;
441
- setOpen((_a = props.open) !== null && _a !== void 0 ? _a : false);
442
- }, [props.open]);
443
- }
444
+ React__namespace.useEffect(() => {
445
+ var _a;
446
+ if (props.open === undefined) {
447
+ // technically, we only need to use this effect if props.open was initialized with a boolean.
448
+ // you can't have conditional effects so here we go...
449
+ return;
450
+ }
451
+ setOpen((_a = props.open) !== null && _a !== void 0 ? _a : false);
452
+ }, [props.open]);
444
453
  return (React__namespace.createElement("div", { className: "accordian" },
445
454
  React__namespace.createElement(Button, { readOnly: props.disabled, block: (_d = props.block) !== null && _d !== void 0 ? _d : true, variant: props.variant, className: css.cx(css.css({
446
455
  display: 'flex',
@@ -1099,6 +1108,19 @@ const Backdrop$1 = (props) => {
1099
1108
  }, ref: backdrop, className: css.cx('backdrop', styles, props.className) }, props.children));
1100
1109
  };
1101
1110
 
1111
+ /** useEffect but ignores the first call on component mount. */
1112
+ const useIgnoreMount = (effect, deps) => {
1113
+ const mounted = React__default['default'].useRef(false);
1114
+ React__default['default'].useEffect(() => {
1115
+ if (!mounted.current) {
1116
+ mounted.current = true;
1117
+ }
1118
+ else {
1119
+ effect();
1120
+ }
1121
+ }, deps);
1122
+ };
1123
+
1102
1124
  const useLogger = (componentName, enabled) => {
1103
1125
  return (...messages) => {
1104
1126
  if (enabled) {
@@ -1108,19 +1130,20 @@ const useLogger = (componentName, enabled) => {
1108
1130
  };
1109
1131
  };
1110
1132
 
1133
+ const portalId = 'backdrop';
1111
1134
  const BackdropContext = React__default['default'].createContext({
1112
1135
  showing: false,
1113
1136
  showCount: 0,
1114
- portalId: 'backdrop',
1115
- setShow: s => {
1137
+ portalId: portalId,
1138
+ setShow: (s, f) => {
1116
1139
  /* empty */
1117
1140
  }
1118
1141
  });
1119
1142
  const BackdropContextProvider = (p) => {
1120
1143
  var _a;
1121
1144
  const [showCount, setShowCount] = React.useState(0);
1122
- const log = useLogger('BackdropContextProvider', (_a = p.debug) !== null && _a !== void 0 ? _a : false);
1123
- if (p.debug) {
1145
+ const log = useLogger('BackdropContextProvider', (_a = p.__debug) !== null && _a !== void 0 ? _a : false);
1146
+ if (p.__debug) {
1124
1147
  React.useEffect(() => {
1125
1148
  log('mounted');
1126
1149
  return () => {
@@ -1130,35 +1153,33 @@ const BackdropContextProvider = (p) => {
1130
1153
  React.useEffect(() => {
1131
1154
  log('re-rendered');
1132
1155
  });
1133
- React.useEffect(() => {
1156
+ useIgnoreMount(() => {
1134
1157
  log('showCount changed', showCount);
1135
1158
  }, [showCount]);
1136
1159
  }
1137
1160
  return (React__default['default'].createElement(BackdropContext.Provider, { value: {
1138
- portalId: 'backdrop',
1161
+ portalId: portalId,
1139
1162
  showing: showCount > 0,
1140
1163
  showCount: showCount,
1141
- setShow: (show) => {
1164
+ setShow: (show, from) => {
1142
1165
  if (show) {
1143
1166
  setShowCount(s => {
1144
1167
  const count = s + 1;
1145
- log('setShowCount', count);
1146
- log('showCount was', showCount);
1168
+ log(`setShow from ${from} ${s} -> ${count}`);
1147
1169
  return count;
1148
1170
  });
1149
1171
  }
1150
1172
  else {
1151
1173
  setShowCount(s => {
1152
1174
  const count = Math.max(0, s - 1);
1153
- log('setShowCount', count);
1154
- log('showCount was', showCount);
1175
+ log(`setShow from ${from} ${s} -> ${count}`);
1155
1176
  return count;
1156
1177
  });
1157
1178
  }
1158
1179
  }
1159
1180
  } },
1160
1181
  p.children,
1161
- p.debug && (React__default['default'].createElement("p", { className: css.css({
1182
+ p.__debug && (React__default['default'].createElement("p", { className: css.css({
1162
1183
  position: 'fixed',
1163
1184
  top: 0, right: 0,
1164
1185
  backgroundColor: '#ff00004f',
@@ -1175,8 +1196,8 @@ const BackdropOverlay = (p) => {
1175
1196
  const context = React.useContext(BackdropContext);
1176
1197
  const theme = useThemeSafely();
1177
1198
  const showTimeMs = (_a = p.showTimeMs) !== null && _a !== void 0 ? _a : 250;
1178
- const log = useLogger('BackdropOverlay', (_b = p.debug) !== null && _b !== void 0 ? _b : false);
1179
- if (p.debug) {
1199
+ const log = useLogger('BackdropOverlay', (_b = p.__debug) !== null && _b !== void 0 ? _b : false);
1200
+ if (p.__debug) {
1180
1201
  React.useEffect(() => {
1181
1202
  log('mounted');
1182
1203
  return () => {
@@ -1186,12 +1207,12 @@ const BackdropOverlay = (p) => {
1186
1207
  React.useEffect(() => {
1187
1208
  log('re-rendered');
1188
1209
  });
1189
- React.useEffect(() => {
1210
+ useIgnoreMount(() => {
1190
1211
  log('context.showing changed', context.showing);
1191
1212
  }, [context.showing]);
1192
1213
  }
1193
1214
  return (React__default['default'].createElement("div", { onClick: () => {
1194
- context === null || context === void 0 ? void 0 : context.setShow(false);
1215
+ context === null || context === void 0 ? void 0 : context.setShow(false, 'BackdropOverlay');
1195
1216
  log('onClick', 'setShow', false);
1196
1217
  }, id: context === null || context === void 0 ? void 0 : context.portalId, className: css.css({
1197
1218
  cursor: 'pointer',
@@ -1207,12 +1228,12 @@ const BackdropOverlay = (p) => {
1207
1228
  }) }));
1208
1229
  };
1209
1230
  const Backdrop = (p) => {
1210
- return (React__default['default'].createElement(BackdropContextProvider, { debug: p.debug },
1231
+ return (React__default['default'].createElement(BackdropContextProvider, { __debug: p.__debug },
1211
1232
  React__default['default'].createElement("div", { className: css.css({
1212
1233
  height: '100%'
1213
1234
  }) },
1214
1235
  p.children,
1215
- React__default['default'].createElement(BackdropOverlay, { showTimeMs: p.showTimeMs, debug: p.debug }))));
1236
+ React__default['default'].createElement(BackdropOverlay, { showTimeMs: p.showTimeMs, __debug: p.__debug }))));
1216
1237
  };
1217
1238
 
1218
1239
  const Calendar = (p) => {
@@ -1414,12 +1435,13 @@ const Modal = (p) => {
1414
1435
  const theme = useThemeSafely();
1415
1436
  const hasHeader = p.closeButton || p.heading;
1416
1437
  const contentRef = React__default['default'].useRef(null);
1417
- const log = useLogger(`Modal ${(_a = p.id) !== null && _a !== void 0 ? _a : '?'}`, (_b = p.debug) !== null && _b !== void 0 ? _b : false);
1438
+ const log = useLogger(`Modal ${(_a = p.id) !== null && _a !== void 0 ? _a : '?'}`, (_b = p.__debug) !== null && _b !== void 0 ? _b : false);
1418
1439
  React.useEffect(() => {
1419
1440
  log('mounted');
1420
1441
  return () => {
1442
+ var _a;
1421
1443
  // handle the use of modals that are rendered only as show=true and then unmounted.
1422
- backdrop.setShow(false);
1444
+ backdrop.setShow(false, (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal');
1423
1445
  log('backdrop.setShow', false);
1424
1446
  if (backdrop.showCount <= 1 && htmlBodyStyles) {
1425
1447
  log('backdrop.showCount', backdrop.showCount, 'removing htmlBodyStyles');
@@ -1428,10 +1450,11 @@ const Modal = (p) => {
1428
1450
  log('un-mounted');
1429
1451
  };
1430
1452
  }, []);
1431
- React.useEffect(() => {
1453
+ useIgnoreMount(() => {
1454
+ var _a;
1432
1455
  log('show changed', p.show);
1433
- backdrop.setShow(p.show);
1434
- log('backdrop.setShow', true);
1456
+ backdrop.setShow(p.show, (_a = p.id) !== null && _a !== void 0 ? _a : 'Modal');
1457
+ log('backdrop.setShow', p.show);
1435
1458
  if (!htmlBodyStyles) {
1436
1459
  log('creating singleton htmlBodyStyles');
1437
1460
  htmlBodyStyles = css.css({
@@ -1550,7 +1573,7 @@ const ConfirmModal = (props) => {
1550
1573
  }
1551
1574
  `}
1552
1575
  `;
1553
- return (React__namespace.createElement(Modal, { id: props.id, debug: props.debug, className: css.cx('confirmModal', modalStyle, props.className), heading: props.header, closeButton: true, show: props.show, onClick: props.onCancel },
1576
+ return (React__namespace.createElement(Modal, { id: props.id, __debug: props.__debug, className: css.cx('confirmModal', modalStyle, props.className), heading: props.header, closeButton: true, show: props.show, onClick: props.onCancel },
1554
1577
  React__namespace.createElement("div", { className: css.css({ padding: '1rem' }) },
1555
1578
  React__namespace.createElement(Text, { align: "center" }, props.text),
1556
1579
  React__namespace.createElement("div", { className: css.css({ textAlign: 'center' }) },
@@ -1600,7 +1623,7 @@ const ErrorModal = (props) => {
1600
1623
  color: ${theme.colors.omgFont};
1601
1624
  }
1602
1625
  `;
1603
- return (React__namespace.createElement(Modal, { id: props.id, debug: props.debug, className: css.cx('errorModal', modalStyles), heading: "Error", closeButton: true, show: props.show, onClick: props.close },
1626
+ return (React__namespace.createElement(Modal, { id: props.id, __debug: props.__debug, className: css.cx('errorModal', modalStyles), heading: "Error", closeButton: true, show: props.show, onClick: props.close },
1604
1627
  React__namespace.createElement("div", { className: css.css({ padding: '1rem' }) },
1605
1628
  React__namespace.createElement(Text, { align: "center" }, message))));
1606
1629
  };
@@ -2127,7 +2150,7 @@ const InfoTip = (props) => {
2127
2150
  if (props.variant === 'modal') {
2128
2151
  return (React__namespace.createElement(React__namespace.Fragment, null,
2129
2152
  button,
2130
- React__namespace.createElement(Modal, { id: props.modalId, debug: props.modalDebug, show: showTip, heading: props.modalHeader, onClick: closeTip, className: css.css({
2153
+ React__namespace.createElement(Modal, { id: props.modalId, __debug: props.__debug, show: showTip, heading: props.modalHeader, onClick: closeTip, className: css.css({
2131
2154
  whiteSpace: 'normal'
2132
2155
  }), closeButton: true },
2133
2156
  React__namespace.createElement("div", { className: css.css({ padding: '1rem' }) }, props.content))));
@@ -2266,19 +2289,6 @@ const tryClampDecimals = (value, step = 0) => {
2266
2289
  return parseFloat(value.toFixed(decimals));
2267
2290
  };
2268
2291
 
2269
- /** useEffect but ignores the first call on component mount. */
2270
- const useIgnoreMount = (effect, deps) => {
2271
- const mounted = React__default['default'].useRef(false);
2272
- React__default['default'].useEffect(() => {
2273
- if (!mounted.current) {
2274
- mounted.current = true;
2275
- }
2276
- else {
2277
- effect();
2278
- }
2279
- }, deps);
2280
- };
2281
-
2282
2292
  /** Common state handling for displaying validation messages with inputs. */
2283
2293
  const useInputValidationMessage = (ref, props) => {
2284
2294
  const [validationError, setValidationError] = React__default['default'].useState('');
@@ -2289,6 +2299,9 @@ const useInputValidationMessage = (ref, props) => {
2289
2299
  (_a = ref.current) === null || _a === void 0 ? void 0 : _a.setCustomValidity(customError);
2290
2300
  setValidationError(customError || getValidationMessage(ref.current, props.patternErrorMessage));
2291
2301
  };
2302
+ React.useEffect(() => {
2303
+ updateErrorMessage();
2304
+ }, [props.customError]);
2292
2305
  React__default['default'].useEffect(() => {
2293
2306
  updateErrorMessage();
2294
2307
  }, []);
@@ -2805,7 +2818,8 @@ const Nav = (props) => {
2805
2818
  }
2806
2819
  }, [backdrop.showing]);
2807
2820
  React__namespace.useEffect(() => {
2808
- backdrop.setShow(props.show);
2821
+ var _a;
2822
+ backdrop.setShow(props.show, (_a = props.id) !== null && _a !== void 0 ? _a : 'Nav');
2809
2823
  }, [props.show]);
2810
2824
  React__namespace.useLayoutEffect(() => {
2811
2825
  if (nav && nav.current) {
@@ -4104,8 +4118,8 @@ const WaitingIndicator = (p) => {
4104
4118
  const [show, setShow] = React.useState(p.show);
4105
4119
  const hideTimer = React.useRef(0);
4106
4120
  const lastShowStatus = React.useRef(false);
4107
- const log = useLogger(`WaitingIndicator ${(_a = p.id) !== null && _a !== void 0 ? _a : '?'}`, (_b = p.debug) !== null && _b !== void 0 ? _b : false);
4108
- if (p.debug) {
4121
+ const log = useLogger(`WaitingIndicator ${(_a = p.id) !== null && _a !== void 0 ? _a : '?'}`, (_b = p.__debug) !== null && _b !== void 0 ? _b : false);
4122
+ if (p.__debug) {
4109
4123
  React.useEffect(() => {
4110
4124
  log('mounted');
4111
4125
  return () => {
@@ -4155,7 +4169,7 @@ const WaitingIndicator = (p) => {
4155
4169
  }
4156
4170
  }
4157
4171
  }, [p.show]);
4158
- return (React__default['default'].createElement(Modal, { id: p.id, debug: p.debug, className: "waitingIndicator", show: show, noBackground: true },
4172
+ return (React__default['default'].createElement(Modal, { id: p.id, __debug: p.__debug, className: "waitingIndicator", show: show, noBackground: true },
4159
4173
  React__default['default'].createElement("div", { className: css.css({
4160
4174
  color: 'white',
4161
4175
  fontSize: '3rem'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "8.0.0-beta.13",
3
+ "version": "8.0.0-beta.16",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",