@mackin.com/styleguide 11.0.12 → 11.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 (4) hide show
  1. package/index.d.ts +192 -162
  2. package/index.esm.js +1202 -1068
  3. package/index.js +1202 -1067
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -1260,6 +1260,128 @@ const styles = {
1260
1260
  }),
1261
1261
  };
1262
1262
 
1263
+ const defaultMinChars = 3;
1264
+ class AutocompleteController {
1265
+ constructor(getOptions, config) {
1266
+ var _a;
1267
+ this._value = undefined;
1268
+ this._options = [];
1269
+ this._minChars = (_a = config === null || config === void 0 ? void 0 : config.minChars) !== null && _a !== void 0 ? _a : defaultMinChars;
1270
+ if (config === null || config === void 0 ? void 0 : config.debounceMs) {
1271
+ this.getOptions = createDebouncedPromise(getOptions, config === null || config === void 0 ? void 0 : config.debounceMs);
1272
+ }
1273
+ else {
1274
+ this.getOptions = getOptions;
1275
+ }
1276
+ }
1277
+ get value() {
1278
+ return this._value;
1279
+ }
1280
+ get options() {
1281
+ return this._options;
1282
+ }
1283
+ async onChange(newValue) {
1284
+ // don't make getOptions calls if the value hasn't changed.
1285
+ if (newValue === this.value) {
1286
+ return;
1287
+ }
1288
+ // nullish should not make the getOptions call and instead clear everything.
1289
+ if (!newValue) {
1290
+ this._value = newValue;
1291
+ this._options = [];
1292
+ return;
1293
+ }
1294
+ // sub min chars should clear everything and not attempt the getOptions call.
1295
+ if (newValue.length < this._minChars) {
1296
+ this._value = newValue;
1297
+ this._options = [];
1298
+ return;
1299
+ }
1300
+ try {
1301
+ this._value = newValue;
1302
+ this._options = (await this.getOptions(newValue));
1303
+ }
1304
+ catch (err) {
1305
+ // this method will throw errors on debounce rejections. that is to be expected.
1306
+ // for actual getOptions exceptions, the owner of that function will need to handle errors.
1307
+ }
1308
+ }
1309
+ onPick(newValue) {
1310
+ this._value = newValue;
1311
+ this._options = [];
1312
+ }
1313
+ }
1314
+ const createDebouncedPromise = (originalFunction, trailingTimeoutMs) => {
1315
+ let timer;
1316
+ let onCancel;
1317
+ return (value) => {
1318
+ if (timer) {
1319
+ clearTimeout(timer);
1320
+ }
1321
+ if (onCancel) {
1322
+ onCancel('Promise cancelled due to in-progress debounce call.');
1323
+ onCancel = undefined;
1324
+ }
1325
+ return new Promise((res, rej) => {
1326
+ onCancel = rej;
1327
+ timer = setTimeout(() => {
1328
+ originalFunction(value)
1329
+ .then(values => {
1330
+ res(values);
1331
+ })
1332
+ .catch(err => {
1333
+ rej(err);
1334
+ })
1335
+ .finally(() => {
1336
+ clearTimeout(timer);
1337
+ });
1338
+ }, trailingTimeoutMs);
1339
+ });
1340
+ };
1341
+ };
1342
+
1343
+ /** Extracted logic around autocomplete functionality for Autocomplete.tsx that supports Entity (id/name) mapping. */
1344
+ class AutocompleteEntityController {
1345
+ constructor(getOptions, config) {
1346
+ this._options = [];
1347
+ const getStringOptions = async (value) => {
1348
+ this._options = await getOptions(value);
1349
+ return this._options.map(o => o.name);
1350
+ };
1351
+ this._ctrl = new AutocompleteController(getStringOptions, config);
1352
+ }
1353
+ get entity() {
1354
+ return this._pickedEntity;
1355
+ }
1356
+ get entities() {
1357
+ return this._options;
1358
+ }
1359
+ get value() {
1360
+ return this._ctrl.value;
1361
+ }
1362
+ get options() {
1363
+ return this._options.map(o => o.name);
1364
+ }
1365
+ async onChange(newValue) {
1366
+ const clearEntity = newValue !== this._ctrl.value;
1367
+ await this._ctrl.onChange(newValue);
1368
+ if (clearEntity) {
1369
+ this._pickedEntity = undefined;
1370
+ }
1371
+ this.trySyncCtrlOptions();
1372
+ }
1373
+ onPick(newValue) {
1374
+ this._ctrl.onPick(newValue);
1375
+ this._pickedEntity = this._options.find(o => o.name === this._ctrl.value);
1376
+ this.trySyncCtrlOptions();
1377
+ }
1378
+ trySyncCtrlOptions() {
1379
+ if (!this._ctrl.options.length) {
1380
+ this._options = [];
1381
+ }
1382
+ }
1383
+ }
1384
+
1263
1385
  /** Returns a UID. Use this instead of a direct call to a library. */
1264
1386
  function createUid() {
1265
1387
  return lodash.uniqueId();
@@ -2978,108 +3100,6 @@ const Label = (props) => {
2978
3100
  return (React__namespace.createElement("label", Object.assign({}, labelProps, { htmlFor: htmlFor, className: css.cx('label', labelStyles, outerClass) }), content));
2979
3101
  };
2980
3102
 
2981
- const Nav = (props) => {
2982
- var _a, _b, _c, _d;
2983
- const nav = React__namespace.useRef(null);
2984
- const theme = useThemeSafely();
2985
- const navWidth = (_a = props.navWidth) !== null && _a !== void 0 ? _a : theme.layout.navWidth;
2986
- const totalNavOffset = `calc(${navWidth} + 20px)`;
2987
- const backdrop = useBackdropContext();
2988
- const log = useLogger(`Nav ${(_b = props.id) !== null && _b !== void 0 ? _b : '?'}`, (_c = props.__debug) !== null && _c !== void 0 ? _c : false);
2989
- const slideMs = (_d = props.slideMs) !== null && _d !== void 0 ? _d : theme.timings.nav.slideMs;
2990
- const slideRight = css.keyframes `
2991
- 0% {
2992
- transform: translateX(0);
2993
- }
2994
-
2995
- 100% {
2996
- transform: translateX(${totalNavOffset});
2997
- }
2998
- `;
2999
- const slideLeft = css.keyframes `
3000
- 0% {
3001
- transform: translateX(${totalNavOffset});
3002
- }
3003
-
3004
- 100% {
3005
- transform: translateX(0px);
3006
- }
3007
- `;
3008
- const classNavShowing = css.css `
3009
- animation: ${slideRight} ${slideMs}ms cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
3010
- `;
3011
- const classNavNotShowing = css.css `
3012
- animation: ${slideLeft} ${slideMs}ms cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
3013
- `;
3014
- const zIndex = theme.zIndexes.nav;
3015
- // the padding-top here is to offset the navs' content from the header. the shadow creeps over it.
3016
- const navStyles = css.css `
3017
- label: Nav;
3018
- position: fixed;
3019
- top: 0;
3020
- left: calc(${totalNavOffset} * -1);
3021
- bottom: 0;
3022
- background-color: ${theme.colors.nav};
3023
- color: ${theme.colors.navFont};
3024
- width: ${navWidth};
3025
- min-width: ${navWidth};
3026
- box-shadow: 4px 2px 12px 6px rgba(0, 0, 0, 0.2);
3027
- z-index: ${zIndex};
3028
- overflow-y: auto;
3029
- .omniLink, .omniLink:active, .omniLink:focus, .omniLink:visited {
3030
- color: ${theme.colors.navFont};
3031
- }
3032
- padding-top:0;
3033
- `;
3034
- React__namespace.useEffect(() => {
3035
- if (!backdrop.showing) {
3036
- props.toggle(false);
3037
- }
3038
- }, [backdrop.showing]);
3039
- useBooleanChanged((current, previous) => {
3040
- var _a;
3041
- log('show changed', `${previous !== null && previous !== void 0 ? previous : 'undefined'} > ${current}`);
3042
- backdrop.setShow(current, { key: (_a = props.id) !== null && _a !== void 0 ? _a : 'Nav', zIndex });
3043
- if (!props.show && props.onCloseFocusId) {
3044
- const focusId = props.onCloseFocusId;
3045
- setTimeout(() => {
3046
- var _a;
3047
- (_a = document.getElementById(focusId)) === null || _a === void 0 ? void 0 : _a.focus();
3048
- }, 0);
3049
- }
3050
- }, props.show);
3051
- React__namespace.useLayoutEffect(() => {
3052
- if (nav && nav.current) {
3053
- if (props.show) {
3054
- if (!nav.current.classList.contains(classNavShowing)) {
3055
- nav.current.classList.add(classNavShowing);
3056
- setTimeout(() => {
3057
- var _a;
3058
- (_a = document.getElementById(props.focusContentId)) === null || _a === void 0 ? void 0 : _a.focus();
3059
- }, slideMs + 1);
3060
- }
3061
- }
3062
- else {
3063
- if (nav.current.classList.contains(classNavShowing)) {
3064
- nav.current.classList.remove(classNavShowing);
3065
- nav.current.classList.add(classNavNotShowing);
3066
- setTimeout(() => {
3067
- if (nav && nav.current) {
3068
- nav.current.classList.remove(classNavNotShowing);
3069
- }
3070
- }, slideMs);
3071
- }
3072
- }
3073
- }
3074
- });
3075
- return (React__namespace.createElement("nav", { role: "dialog", "aria-modal": "true", "aria-label": props.ariaLabel, ref: nav, className: css.cx('nav', navStyles, props.className), onKeyDown: e => {
3076
- if (e.code === 'Escape') {
3077
- props.toggle(false);
3078
- }
3079
- } },
3080
- React__namespace.createElement(TabLocker, { className: css.css({ height: '100%' }) }, props.children)));
3081
- };
3082
-
3083
3103
  const LinkContent = (props) => {
3084
3104
  return (React__namespace.createElement(React__namespace.Fragment, null,
3085
3105
  React__namespace.createElement("span", null,
@@ -3337,6 +3357,29 @@ const generateLinkStyles = (props, theme) => {
3337
3357
  return linkStyles;
3338
3358
  };
3339
3359
 
3360
+ const Link = (props) => {
3361
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3362
+ const { rightIcon, leftIcon, block, iconBlock, variant, round, small, colorOverride, children, disabled, ref, waiting } = props, linkProps = __rest(props, ["rightIcon", "leftIcon", "block", "iconBlock", "variant", "round", "small", "colorOverride", "children", "disabled", "ref", "waiting"]);
3363
+ const theme = useThemeSafely();
3364
+ const linkStyles = generateLinkStyles(props, theme);
3365
+ const mainClassName = css.cx('link', linkStyles, props.className);
3366
+ if (variant === 'text') {
3367
+ return React__namespace.createElement(Text, { className: mainClassName, tag: "div" }, props.children);
3368
+ }
3369
+ const isDisabled = props.disabled || props.waiting;
3370
+ return (React__namespace.createElement("a", Object.assign({}, linkProps, { tabIndex: disabled ? -1 : undefined, target: props.target, className: mainClassName, onClick: e => {
3371
+ var _a;
3372
+ if (isDisabled) {
3373
+ e.stopPropagation();
3374
+ e.preventDefault();
3375
+ }
3376
+ else {
3377
+ (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
3378
+ }
3379
+ } }),
3380
+ React__namespace.createElement(LinkContent, Object.assign({}, props))));
3381
+ };
3382
+
3340
3383
  const OmniLink = (props) => {
3341
3384
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
3342
3385
  const { noRouter, rightIcon, leftIcon, block, iconBlock, variant, round, small, colorOverride, children, ref, waiting } = props, linkProps = __rest(props, ["noRouter", "rightIcon", "leftIcon", "block", "iconBlock", "variant", "round", "small", "colorOverride", "children", "ref", "waiting"]);
@@ -3363,17 +3406,119 @@ const OmniLink = (props) => {
3363
3406
  } }), content));
3364
3407
  };
3365
3408
 
3366
- const roundPxPadding = '4px';
3367
- const Picker = (props) => {
3368
- const { value, options, onValueChange, readOnly, round, controlAlign, wrapperClassName, iconClassName, error } = props, selectProps = __rest(props
3369
- // if we put numbers in, we expect them out
3370
- , ["value", "options", "onValueChange", "readOnly", "round", "controlAlign", "wrapperClassName", "iconClassName", "error"]);
3371
- // if we put numbers in, we expect them out
3372
- let isNumber = false;
3373
- if (options && options.length) {
3374
- const testOption = options[0];
3375
- if (typeof testOption === 'object') {
3376
- isNumber = typeof testOption.id === 'number';
3409
+ const Nav = (props) => {
3410
+ var _a, _b, _c, _d;
3411
+ const nav = React__namespace.useRef(null);
3412
+ const theme = useThemeSafely();
3413
+ const navWidth = (_a = props.navWidth) !== null && _a !== void 0 ? _a : theme.layout.navWidth;
3414
+ const totalNavOffset = `calc(${navWidth} + 20px)`;
3415
+ const backdrop = useBackdropContext();
3416
+ const log = useLogger(`Nav ${(_b = props.id) !== null && _b !== void 0 ? _b : '?'}`, (_c = props.__debug) !== null && _c !== void 0 ? _c : false);
3417
+ const slideMs = (_d = props.slideMs) !== null && _d !== void 0 ? _d : theme.timings.nav.slideMs;
3418
+ const slideRight = css.keyframes `
3419
+ 0% {
3420
+ transform: translateX(0);
3421
+ }
3422
+
3423
+ 100% {
3424
+ transform: translateX(${totalNavOffset});
3425
+ }
3426
+ `;
3427
+ const slideLeft = css.keyframes `
3428
+ 0% {
3429
+ transform: translateX(${totalNavOffset});
3430
+ }
3431
+
3432
+ 100% {
3433
+ transform: translateX(0px);
3434
+ }
3435
+ `;
3436
+ const classNavShowing = css.css `
3437
+ animation: ${slideRight} ${slideMs}ms cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
3438
+ `;
3439
+ const classNavNotShowing = css.css `
3440
+ animation: ${slideLeft} ${slideMs}ms cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
3441
+ `;
3442
+ const zIndex = theme.zIndexes.nav;
3443
+ // the padding-top here is to offset the navs' content from the header. the shadow creeps over it.
3444
+ const navStyles = css.css `
3445
+ label: Nav;
3446
+ position: fixed;
3447
+ top: 0;
3448
+ left: calc(${totalNavOffset} * -1);
3449
+ bottom: 0;
3450
+ background-color: ${theme.colors.nav};
3451
+ color: ${theme.colors.navFont};
3452
+ width: ${navWidth};
3453
+ min-width: ${navWidth};
3454
+ box-shadow: 4px 2px 12px 6px rgba(0, 0, 0, 0.2);
3455
+ z-index: ${zIndex};
3456
+ overflow-y: auto;
3457
+ .omniLink, .omniLink:active, .omniLink:focus, .omniLink:visited {
3458
+ color: ${theme.colors.navFont};
3459
+ }
3460
+ padding-top:0;
3461
+ `;
3462
+ React__namespace.useEffect(() => {
3463
+ if (!backdrop.showing) {
3464
+ props.toggle(false);
3465
+ }
3466
+ }, [backdrop.showing]);
3467
+ useBooleanChanged((current, previous) => {
3468
+ var _a;
3469
+ log('show changed', `${previous !== null && previous !== void 0 ? previous : 'undefined'} > ${current}`);
3470
+ backdrop.setShow(current, { key: (_a = props.id) !== null && _a !== void 0 ? _a : 'Nav', zIndex });
3471
+ if (!props.show && props.onCloseFocusId) {
3472
+ const focusId = props.onCloseFocusId;
3473
+ setTimeout(() => {
3474
+ var _a;
3475
+ (_a = document.getElementById(focusId)) === null || _a === void 0 ? void 0 : _a.focus();
3476
+ }, 0);
3477
+ }
3478
+ }, props.show);
3479
+ React__namespace.useLayoutEffect(() => {
3480
+ if (nav && nav.current) {
3481
+ if (props.show) {
3482
+ if (!nav.current.classList.contains(classNavShowing)) {
3483
+ nav.current.classList.add(classNavShowing);
3484
+ setTimeout(() => {
3485
+ var _a;
3486
+ (_a = document.getElementById(props.focusContentId)) === null || _a === void 0 ? void 0 : _a.focus();
3487
+ }, slideMs + 1);
3488
+ }
3489
+ }
3490
+ else {
3491
+ if (nav.current.classList.contains(classNavShowing)) {
3492
+ nav.current.classList.remove(classNavShowing);
3493
+ nav.current.classList.add(classNavNotShowing);
3494
+ setTimeout(() => {
3495
+ if (nav && nav.current) {
3496
+ nav.current.classList.remove(classNavNotShowing);
3497
+ }
3498
+ }, slideMs);
3499
+ }
3500
+ }
3501
+ }
3502
+ });
3503
+ return (React__namespace.createElement("nav", { role: "dialog", "aria-modal": "true", "aria-label": props.ariaLabel, ref: nav, className: css.cx('nav', navStyles, props.className), onKeyDown: e => {
3504
+ if (e.code === 'Escape') {
3505
+ props.toggle(false);
3506
+ }
3507
+ } },
3508
+ React__namespace.createElement(TabLocker, { className: css.css({ height: '100%' }) }, props.children)));
3509
+ };
3510
+
3511
+ const roundPxPadding = '4px';
3512
+ const Picker = (props) => {
3513
+ const { value, options, onValueChange, readOnly, round, controlAlign, wrapperClassName, iconClassName, error, optionClassName } = props, selectProps = __rest(props
3514
+ // if we put numbers in, we expect them out
3515
+ , ["value", "options", "onValueChange", "readOnly", "round", "controlAlign", "wrapperClassName", "iconClassName", "error", "optionClassName"]);
3516
+ // if we put numbers in, we expect them out
3517
+ let isNumber = false;
3518
+ if (options && options.length) {
3519
+ const testOption = options[0];
3520
+ if (typeof testOption === 'object') {
3521
+ isNumber = typeof testOption.id === 'number';
3377
3522
  }
3378
3523
  else {
3379
3524
  isNumber = typeof testOption === 'number';
@@ -3381,6 +3526,7 @@ const Picker = (props) => {
3381
3526
  }
3382
3527
  const theme = useThemeSafely();
3383
3528
  const selectStyles = css.css({
3529
+ label: 'Picker',
3384
3530
  // fix the arrow so browser all look the same
3385
3531
  appearance: 'none',
3386
3532
  paddingLeft: theme.controls.padding,
@@ -3424,8 +3570,7 @@ const Picker = (props) => {
3424
3570
  const select = (React__namespace.createElement("select", Object.assign({}, selectProps, { tabIndex: readOnly ? -1 : selectProps.tabIndex, className: css.cx('picker', selectStyles, props.className), value: value, onKeyDown: e => {
3425
3571
  var _a;
3426
3572
  if (readOnly) {
3427
- if (e.keyCode === 9) {
3428
- //TAB
3573
+ if (e.code === 'Tab') {
3429
3574
  return;
3430
3575
  }
3431
3576
  e.preventDefault();
@@ -3466,7 +3611,7 @@ const Picker = (props) => {
3466
3611
  val = o;
3467
3612
  label = o;
3468
3613
  }
3469
- return React__namespace.createElement("option", { key: val, value: val }, label);
3614
+ return React__namespace.createElement("option", { key: val, value: val, className: optionClassName }, label);
3470
3615
  })));
3471
3616
  return (React__namespace.createElement("span", { className: css.cx(css.css({
3472
3617
  label: 'PickerWrapper',
@@ -3942,6 +4087,118 @@ class ItemPager {
3942
4087
  }
3943
4088
  }
3944
4089
 
4090
+ const MultiPicker = (props) => {
4091
+ const { value: values, options, onValueChange, readOnly, controlAlign, wrapperClassName, error, optionClassName } = props, selectProps = __rest(props
4092
+ // if we put numbers in, we expect them out
4093
+ , ["value", "options", "onValueChange", "readOnly", "controlAlign", "wrapperClassName", "error", "optionClassName"]);
4094
+ // if we put numbers in, we expect them out
4095
+ let isNumber = false;
4096
+ if (options && options.length) {
4097
+ const testOption = options[0];
4098
+ if (typeof testOption === 'object') {
4099
+ isNumber = typeof testOption.id === 'number';
4100
+ }
4101
+ else {
4102
+ isNumber = typeof testOption === 'number';
4103
+ }
4104
+ }
4105
+ const theme = useThemeSafely();
4106
+ const selectStyles = css.css({
4107
+ label: 'MultiPicker',
4108
+ padding: theme.controls.padding,
4109
+ minHeight: theme.controls.height,
4110
+ backgroundColor: theme.colors.bg,
4111
+ color: theme.colors.font,
4112
+ fontSize: theme.controls.fontSize,
4113
+ width: '100%',
4114
+ border: theme.controls.border,
4115
+ borderRadius: theme.controls.borderRadius || 0, /* safari fix */
4116
+ transition: theme.controls.transition,
4117
+ '&:disabled': {
4118
+ color: theme.colors.font,
4119
+ opacity: 1,
4120
+ backgroundColor: theme.colors.disabled,
4121
+ cursor: 'not-allowed'
4122
+ },
4123
+ '&:focus': {
4124
+ outline: 'none',
4125
+ boxShadow: theme.controls.focusOutlineShadow
4126
+ }
4127
+ }, error && {
4128
+ borderColor: theme.colors.required,
4129
+ ':focus': {
4130
+ boxShadow: theme.controls.focusOutlineRequiredShadow
4131
+ }
4132
+ }, readOnly && {
4133
+ backgroundColor: 'transparent !important',
4134
+ backgroundImage: 'unset',
4135
+ border: 'none',
4136
+ '&:focus': {
4137
+ outline: 'none',
4138
+ boxShadow: 'none'
4139
+ }
4140
+ });
4141
+ const select = (React__namespace.createElement("select", Object.assign({}, selectProps, { multiple: true, tabIndex: readOnly ? -1 : selectProps.tabIndex, className: css.cx(selectStyles, props.className), value: values.map(v => v.toString()), onKeyDown: e => {
4142
+ var _a;
4143
+ if (readOnly) {
4144
+ if (e.code === 'Tab') {
4145
+ return;
4146
+ }
4147
+ e.preventDefault();
4148
+ e.stopPropagation();
4149
+ }
4150
+ else {
4151
+ (_a = selectProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(selectProps, e);
4152
+ }
4153
+ }, onMouseDown: e => {
4154
+ var _a;
4155
+ if (readOnly) {
4156
+ e.preventDefault();
4157
+ e.stopPropagation();
4158
+ }
4159
+ else {
4160
+ (_a = selectProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(selectProps, e);
4161
+ }
4162
+ }, onChange: e => {
4163
+ var _a;
4164
+ const values = Array.from(e.target.selectedOptions).map(o => {
4165
+ let val = o.value;
4166
+ if (isNumber) {
4167
+ val = parseInt(val, 10);
4168
+ if (isNaN(val)) {
4169
+ val = '';
4170
+ }
4171
+ }
4172
+ return val;
4173
+ });
4174
+ onValueChange(values);
4175
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, e);
4176
+ } }), (options || []).map(o => {
4177
+ var _a;
4178
+ let val;
4179
+ let label;
4180
+ if (typeof o === 'object') {
4181
+ val = o.id;
4182
+ label = (_a = o.name) !== null && _a !== void 0 ? _a : o.id;
4183
+ }
4184
+ else {
4185
+ val = o;
4186
+ label = o;
4187
+ }
4188
+ return React__namespace.createElement("option", { key: val, value: val, className: optionClassName }, label);
4189
+ })));
4190
+ return (React__namespace.createElement("span", { className: css.cx(css.css({
4191
+ label: 'MultiPickerWrapper',
4192
+ position: 'relative',
4193
+ display: 'inline-block',
4194
+ width: '100%',
4195
+ }), wrapperClassName) },
4196
+ React__namespace.createElement("div", { className: css.css({
4197
+ position: 'relative'
4198
+ }) }, select),
4199
+ (error || controlAlign) && React__namespace.createElement(InputErrorDisplay, { error: error })));
4200
+ };
4201
+
3945
4202
  const ProgressBar = (props) => {
3946
4203
  var _a;
3947
4204
  const bar = React__namespace.useRef(null);
@@ -4020,9 +4277,9 @@ const useWaiting = (func) => {
4020
4277
  };
4021
4278
 
4022
4279
  const SearchBox = React__namespace.forwardRef((props, ref) => {
4023
- const { wrapperClassName, buttonClassName, inputWrapperClassName, inputClassName, onSubmit, noForm, noSubmitWhenEmpty, onClear } = props, inputProps = __rest(props, ["wrapperClassName", "buttonClassName", "inputWrapperClassName", "inputClassName", "onSubmit", "noForm", "noSubmitWhenEmpty", "onClear"]);
4280
+ const { wrapperClassName, buttonClassName, inputWrapperClassName, inputClassName, onSubmit, noForm, noSubmitWhenEmpty, onClear, searchButtonAriaLabel, clearButtonAriaLabel } = props, inputProps = __rest(props, ["wrapperClassName", "buttonClassName", "inputWrapperClassName", "inputClassName", "onSubmit", "noForm", "noSubmitWhenEmpty", "onClear", "searchButtonAriaLabel", "clearButtonAriaLabel"]);
4281
+ const searchBoxMarkerClass = 'searchBoxInput';
4024
4282
  const [waiting, handleSubmit] = useWaiting(async () => {
4025
- var _a, _b;
4026
4283
  if (noForm) {
4027
4284
  return;
4028
4285
  }
@@ -4032,12 +4289,17 @@ const SearchBox = React__namespace.forwardRef((props, ref) => {
4032
4289
  if ((noSubmitWhenEmpty !== null && noSubmitWhenEmpty !== void 0 ? noSubmitWhenEmpty : true) && !props.value) {
4033
4290
  return;
4034
4291
  }
4035
- // the active element will be the input. if the submit action changes props.value it will
4292
+ // the active element should be the input. if the submit action changes props.value it will
4036
4293
  // be ignored due to Inputs focused handling.
4037
- if (document.activeElement) {
4038
- (_b = (_a = document.activeElement).blur) === null || _b === void 0 ? void 0 : _b.call(_a);
4294
+ const focusElement = document.activeElement;
4295
+ if (focusElement && focusElement.classList.contains(searchBoxMarkerClass)) {
4296
+ focusElement.blur();
4039
4297
  }
4040
- return onSubmit();
4298
+ return onSubmit().then(() => {
4299
+ if (focusElement) {
4300
+ focusElement.focus();
4301
+ }
4302
+ });
4041
4303
  });
4042
4304
  const theme = useThemeSafely();
4043
4305
  const buttonStyles = css.cx(css.css({
@@ -4046,10 +4308,10 @@ const SearchBox = React__namespace.forwardRef((props, ref) => {
4046
4308
  }), buttonClassName);
4047
4309
  let clearButton;
4048
4310
  if (onClear && !!props.value) {
4049
- clearButton = (React__namespace.createElement(Button, { onClick: onClear, tabIndex: -1, disabled: waiting, className: buttonStyles, variant: "icon", small: true },
4311
+ clearButton = (React__namespace.createElement(Button, { "aria-label": clearButtonAriaLabel, onClick: onClear, tabIndex: -1, disabled: waiting, className: buttonStyles, variant: "icon", small: true },
4050
4312
  React__namespace.createElement(Icon, { id: "clear" })));
4051
4313
  }
4052
- const saveButton = (React__namespace.createElement(Button, { tabIndex: -1, disabled: waiting, readOnly: !props.onSubmit, type: "submit", className: buttonStyles, variant: "icon", small: true },
4314
+ const saveButton = (React__namespace.createElement(Button, { "aria-label": searchButtonAriaLabel, tabIndex: -1, disabled: waiting, readOnly: !props.onSubmit, type: "submit", className: buttonStyles, variant: "icon", small: true },
4053
4315
  React__namespace.createElement(Icon, { id: waiting ? 'waiting' : 'search', spin: waiting })));
4054
4316
  const rightControls = clearButton ? React__namespace.createElement(React__namespace.Fragment, null,
4055
4317
  clearButton,
@@ -4060,16 +4322,56 @@ const SearchBox = React__namespace.forwardRef((props, ref) => {
4060
4322
  paddingRight: `calc(${theme.controls.height} + ${theme.controls.heightSmall})`
4061
4323
  });
4062
4324
  }
4063
- const input = (React__namespace.createElement(TextInput, Object.assign({}, inputProps, { ref: ref, wrapperClassName: inputWrapperClassName, className: css.cx(clearButtonInputStyles, inputClassName), rightControl: rightControls })));
4325
+ const input = (React__namespace.createElement(TextInput, Object.assign({}, inputProps, { ref: ref, wrapperClassName: inputWrapperClassName, className: css.cx(searchBoxMarkerClass, clearButtonInputStyles, inputClassName), rightControl: rightControls })));
4064
4326
  const searchBoxWrapperStyles = css.cx(css.css({
4065
4327
  label: 'SearchBox'
4066
4328
  }), wrapperClassName);
4067
4329
  if (!noForm) {
4068
- return (React__namespace.createElement(Form, { role: "search", className: searchBoxWrapperStyles, onSubmit: handleSubmit }, input));
4330
+ return (React__namespace.createElement(Form, { role: "search", className: searchBoxWrapperStyles, onSubmit: handleSubmit, onKeyDown: e => {
4331
+ if (e.code === 'Escape' && onClear) {
4332
+ e.stopPropagation();
4333
+ e.preventDefault();
4334
+ // the active element should be the input. if the clear action changes props.value it will
4335
+ // be ignored due to Inputs focused handling.
4336
+ const focusElement = document.activeElement;
4337
+ if (focusElement && focusElement.classList.contains(searchBoxMarkerClass)) {
4338
+ focusElement.blur();
4339
+ }
4340
+ onClear();
4341
+ if (focusElement) {
4342
+ setTimeout(() => {
4343
+ focusElement.focus();
4344
+ }, 0);
4345
+ }
4346
+ }
4347
+ } }, input));
4069
4348
  }
4070
4349
  return (React__namespace.createElement("div", { className: searchBoxWrapperStyles }, input));
4071
4350
  });
4072
4351
 
4352
+ /** Converts an enum to an array of entities with id and name. The enum can be an integer or string enum.*/
4353
+ const enumToEntities = (enumObj) => {
4354
+ const entities = [];
4355
+ for (const key in enumObj) {
4356
+ if (isNaN(parseInt(key, 10))) {
4357
+ entities.push({
4358
+ id: enumObj[key],
4359
+ name: key
4360
+ });
4361
+ }
4362
+ }
4363
+ return entities;
4364
+ };
4365
+
4366
+ /** Displays the value in American dollars. */
4367
+ const getCurrencyDisplay = (value, isCents, denomination = '$') => {
4368
+ let actualValue = value || 0;
4369
+ if (isCents) {
4370
+ actualValue /= 100;
4371
+ }
4372
+ return `${denomination}${actualValue.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
4373
+ };
4374
+
4073
4375
  const GlobalStyles = () => {
4074
4376
  const theme = useThemeSafely();
4075
4377
  css.injectGlobal({
@@ -4098,699 +4400,37 @@ const GlobalStyles = () => {
4098
4400
  return null;
4099
4401
  };
4100
4402
 
4101
- /*
4102
- From https://fireship.io/snippets/use-media-query-hook/.
4103
- Tried using https://www.npmjs.com/package/react-media, but it cause Webpack build issues.
4104
- */
4105
- /** React wrapper around window resizing and window.matchMedia.
4106
- * https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
4107
- */
4108
- const useMediaQuery = (query) => {
4109
- const [matches, setMatches] = React.useState(window.matchMedia(query).matches);
4110
- React.useEffect(() => {
4111
- const media = window.matchMedia(query);
4112
- if (media.matches !== matches) {
4113
- setMatches(media.matches);
4114
- }
4115
- const listener = () => setMatches(media.matches);
4116
- window.addEventListener("resize", listener);
4117
- return () => window.removeEventListener("resize", listener);
4118
- }, [matches, query]);
4119
- return matches;
4120
- };
4403
+ var decimal=["decimal","décimale"];var place=["lugar","lieu"];var places=["lugares","lieux"];var file=["archivo","fichier"];var selected=["seleccionado","choisi"];var Upload=["Subir","Télécharger"];var Clear=["Cerrar","Fermer"];var Showing=["Mostrando","Affichage de"];var of=["de","sur"];var results=["resultados","résultats"];var Page=["Página","Page"];var Limit=["Límite","Limite"];var Sort=["Ordenar","Trier"];var January=["Enero","Janvier"];var February=["Febrero","Février"];var March=["Marzo","Mars"];var April=["Abril","Avril"];var May=["Mayo","Mai"];var June=["Junio","Juin"];var July=["Julio","Juillet"];var August=["Agosto","Août"];var September=["Septiembre","Septembre"];var October=["Octubre","Octobre"];var November=["Noviembre","Novembre"];var December=["Diciembre","Décembre"];var Sun=["Dom","Dim"];var Mon=["Lun","Lun"];var Tue=["Mar","Mar"];var Wed=["Mié","Mer"];var Thu=["Jue","Jeu"];var Fri=["Vie","Ven"];var Sat=["Sáb","Sam"];var OK=["Aceptar","Accepter"];var Cancel=["Cancelar","Annuler"];var strings = {"Required.":["Requerido.","Requis."],"Must be at least":["Debe ser al menos","Doit être au moins"],"characters in length.":["caracteres de longitud.","caractères de longueur."],"Must be an integer.":["Debe ser un número entero.","Doit être un entier."],"Limited to":["Limitado a","Limité à"],decimal:decimal,place:place,places:places,"Must be greater than or equal to":["Debe ser mayor o igual a","Doit être supérieur ou égal à"],"Must be less than or equal to":["Debe ser menor o igual a","Doit être inférieur ou égal à"],"Invalid email.":["Correo electrónico no válido.","Email invalide."],"Invalid URL.":["URL no válida.","URL non valide."],"Click or drag and drop files.":["Haga clic o arrastre y suelte archivos.","Cliquez ou faites glisser et déposez les fichiers."],file:file,selected:selected,"Upload failed.":["Error en la carga.","Le téléchargement a échoué."],Upload:Upload,"Upload successful.":["Carga exitosa","Téléchargement réussi."],"Invalid files":["Archivos no válidos","Fichiers invalides"],"Max file size exceeded":["Se ha excedido el tamaño máximo de archivo","La taille maximale du fichier a été dépassée"],"Error":["Error","Erreur"],Clear:Clear,Showing:Showing,of:of,results:results,"No Results":["No Hay Resultados","Aucun Résultat"],Page:Page,Limit:Limit,Sort:Sort,January:January,February:February,March:March,April:April,May:May,June:June,July:July,August:August,September:September,October:October,November:November,December:December,Sun:Sun,Mon:Mon,Tue:Tue,Wed:Wed,Thu:Thu,Fri:Fri,Sat:Sat,OK:OK,Cancel:Cancel,"Copied!":["¡Copiado!","Copié!"],"Copy to clipboard":["Copiar al portapapeles","Copier dans le presse-papier"]};
4121
4404
 
4122
- const Slider = (p) => {
4405
+ const LocalizationProvider = (p) => {
4123
4406
  var _a;
4124
- const theme = useThemeSafely();
4125
- const sliderContainer = React.useRef(null);
4126
- const sliderHandleSize = (_a = p.sliderHandleSize) !== null && _a !== void 0 ? _a : theme.controls.height;
4127
- const height = p.showValue ? `calc(${sliderHandleSize} + 1.5rem)` : sliderHandleSize;
4128
- // we're keeping this value in a ref vs. state so the constant updates don't cause re-render.
4129
- // we will have to respond to outside value changes after the fact however...
4130
- const currentValue = React.useRef(p.value);
4131
- const [, forceUpdate] = React.useState(Date.now());
4132
- React.useEffect(() => {
4133
- if (p.value !== currentValue.current) {
4134
- currentValue.current = p.value;
4135
- forceUpdate(Date.now());
4136
- }
4137
- }, [p.value]);
4138
- return (React.createElement("div", { ref: sliderContainer, className: css.cx(css.css({
4139
- label: 'Slider',
4140
- width: '100%',
4141
- height,
4142
- }), p.className) },
4143
- React.createElement(ReactSlider, { ariaLabel: p.ariaLabel, step: p.step, min: p.min, max: p.max, value: p.value, onAfterChange: (value) => {
4144
- p.onChange(value);
4145
- }, onChange: p.onUpdate || p.showValue ? (value) => {
4146
- var _a;
4147
- currentValue.current = value;
4148
- (_a = p.onUpdate) === null || _a === void 0 ? void 0 : _a.call(p, value);
4149
- } : undefined, renderTrack: (props) => {
4150
- const { className } = props, rest = __rest(props, ["className"]);
4151
- return (React.createElement("div", Object.assign({ className: css.cx(className, p.trackClassName, css.css({
4152
- display: 'flex',
4153
- alignItems: 'center',
4154
- height: sliderHandleSize
4155
- })) }, rest),
4156
- React.createElement("div", { className: css.css({
4157
- backgroundColor: theme.colors.secondary,
4158
- height: `calc(${sliderHandleSize} / 4)`,
4159
- borderRadius: theme.controls.roundRadius,
4160
- width: '100%'
4161
- }, p.innerTrackClassName && rest.key === 'track-1' && Array.isArray(p.value) ? p.innerTrackClassName : undefined) })));
4162
- }, renderThumb: (props, state) => {
4163
- var _a;
4164
- const { className } = props, rest = __rest(props, ["className"]);
4165
- let specificThumbStyles;
4166
- if (p.handle1ClassName && props.key === 'thumb-0') {
4167
- specificThumbStyles = p.handle1ClassName;
4407
+ const log = useLogger('LocalizationProvider', (_a = p.__debug) !== null && _a !== void 0 ? _a : false);
4408
+ const stringsDb = strings;
4409
+ return (React.createElement(LocalizationContext.Provider, { value: {
4410
+ language: p.language,
4411
+ getText: (text) => {
4412
+ if (!text) {
4413
+ return '';
4168
4414
  }
4169
- else if (p.handle2ClassName && props.key === 'thumb-1') {
4170
- specificThumbStyles = p.handle2ClassName;
4415
+ if (!isNaN(parseInt(text))) {
4416
+ return text;
4171
4417
  }
4172
- return (React.createElement("div", Object.assign({ className: css.cx(className, css.css({
4173
- borderRadius: theme.controls.roundRadius,
4174
- backgroundColor: 'white',
4175
- border: theme.controls.border,
4176
- cursor: 'grab',
4177
- boxShadow: theme.controls.buttonBoxShadow,
4178
- transition: theme.controls.transition,
4179
- '&:focus': {
4180
- outline: 'none',
4181
- boxShadow: theme.controls.focusOutlineShadow
4182
- },
4183
- '&:active': {
4184
- boxShadow: 'none',
4185
- cursor: 'grabbing'
4186
- },
4187
- '&:hover': {
4188
- filter: theme.controls.hoverBrightness
4189
- }
4190
- }), specificThumbStyles, p.handleClassName, css.css({
4191
- width: sliderHandleSize,
4192
- height: sliderHandleSize,
4193
- })) }, rest, { tabIndex: (_a = p.tabIndex) !== null && _a !== void 0 ? _a : 0 }), p.showValue && (React.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 }))));
4194
- } })));
4195
- };
4196
- const rectsCollideX = (r1, r2) => {
4197
- if (r1.left >= r2.left && r1.left <= r2.right) {
4198
- return true;
4199
- }
4200
- if (r1.right >= r2.left && r1.right <= r2.right) {
4201
- return true;
4202
- }
4203
- return false;
4204
- };
4205
- const HandleText = (p) => {
4206
- var _a, _b, _c;
4207
- const displayValue = (_b = (_a = p.renderValue) === null || _a === void 0 ? void 0 : _a.call(p, p.value)) !== null && _b !== void 0 ? _b : p.value;
4208
- const renderValueWidth = (_c = p.renderValueWidth) !== null && _c !== void 0 ? _c : p.sliderHandleSize;
4209
- const renderValueLeft = React.useMemo(() => {
4210
- return `calc(${renderValueWidth} * 0.5 * -1 + (${p.sliderHandleSize} * 0.5))`;
4211
- }, [p.renderValueWidth, p.sliderHandleSize]);
4212
- const [flipText, setFlipText] = React.useState(false);
4213
- const offset = '2px';
4214
- React.useEffect(() => {
4215
- // this needs to fire on every render due to the other handle also moving.
4216
- var _a, _b;
4217
- if (p.index === 1) {
4218
- // only do this for the max/right-most handle
4219
- 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());
4220
- if (r1 && r2) {
4221
- setFlipText(rectsCollideX(r1, r2));
4418
+ const wordArray = stringsDb[text];
4419
+ if (!wordArray) {
4420
+ log(`No localization data exists for "${text}".`);
4421
+ }
4422
+ if (p.language === exports.StyleGuideLanguage.English) {
4423
+ return text;
4424
+ }
4425
+ const languageIndex = p.language - 1;
4426
+ const translation = wordArray === null || wordArray === void 0 ? void 0 : wordArray[languageIndex];
4427
+ if (translation) {
4428
+ return translation;
4429
+ }
4430
+ log(`No ${exports.StyleGuideLanguage[p.language]} translations exist for "${text}".`);
4431
+ return text;
4222
4432
  }
4223
- }
4224
- });
4225
- return (React.createElement(Text, { ellipsis: true, className: css.cx('slider-handle', css.css({
4226
- width: renderValueWidth,
4227
- left: renderValueLeft,
4228
- top: flipText ? undefined : `calc(${p.sliderHandleSize} + ${offset})`,
4229
- bottom: flipText ? `calc(${p.sliderHandleSize} + ${offset})` : undefined,
4230
- position: 'absolute',
4231
- overflow: 'hidden',
4232
- }), p.className), tag: "div", align: "center" }, displayValue));
4233
- };
4234
-
4235
- const TabHeader = (p) => {
4236
- var _a, _b;
4237
- const [tabIndex, setTabIndex] = React__namespace.useState((_a = p.startingIndex) !== null && _a !== void 0 ? _a : 0);
4238
- const [tabsChanging, setTabsChanging] = React__namespace.useState(false);
4239
- const theme = useThemeSafely();
4240
- const variant = (_b = p.variant) !== null && _b !== void 0 ? _b : 'tab';
4241
- const menuStyles = css.css({
4242
- display: 'flex',
4243
- gap: theme.controls.gap,
4244
- listStyleType: 'none',
4245
- margin: 0,
4246
- padding: 0,
4247
- flexWrap: variant === 'button' ? 'wrap' : 'nowrap'
4248
- }, variant === 'button' && {
4249
- borderBottom: theme.controls.border,
4250
- paddingBottom: '1rem'
4251
- });
4252
- function onTabSelect(index, tabId, focusAfter) {
4253
- const onChange = () => {
4254
- var _a;
4255
- setTabIndex(index);
4256
- (_a = p.onTabChanged) === null || _a === void 0 ? void 0 : _a.call(p, index);
4257
- if (focusAfter) {
4258
- setTimeout(() => {
4259
- var _a;
4260
- (_a = document.getElementById(tabId)) === null || _a === void 0 ? void 0 : _a.focus();
4261
- }, 0);
4262
- }
4263
- };
4264
- if (p.onBeforeTabChanged) {
4265
- setTabsChanging(true);
4266
- p.onBeforeTabChanged(index)
4267
- .then(() => {
4268
- onChange();
4269
- })
4270
- .catch(() => {
4271
- /* do nothing */
4272
- })
4273
- .finally(() => {
4274
- setTabsChanging(false);
4275
- });
4276
- }
4277
- else {
4278
- onChange();
4279
- }
4280
- }
4281
- return (React__namespace.createElement("div", { className: "tabHeader" },
4282
- React__namespace.createElement("ul", { role: 'tablist', "aria-label": p.ariaLabel, className: css.cx(menuStyles, p.containerClassName) }, p.tabs.map((tab, index) => {
4283
- var _a, _b;
4284
- const active = index === tabIndex;
4285
- let tabStyles;
4286
- let buttonStyles;
4287
- let buttonVariant;
4288
- if (variant === 'tab') {
4289
- tabStyles = css.css({
4290
- paddingLeft: '1rem',
4291
- paddingRight: '1rem',
4292
- backgroundColor: theme.colors.bg,
4293
- zIndex: 1,
4294
- }, active && {
4295
- border: theme.controls.border,
4296
- borderRadius: theme.controls.borderRadius,
4297
- borderBottomLeftRadius: 0,
4298
- borderBottomRightRadius: 0,
4299
- borderBottom: 'none',
4300
- zIndex: 3,
4301
- });
4302
- buttonVariant = 'link';
4303
- buttonStyles = css.css({
4304
- maxWidth: (_a = p.maxTabWidth) !== null && _a !== void 0 ? _a : '10rem',
4305
- overflow: 'hidden'
4306
- });
4307
- }
4308
- else {
4309
- buttonVariant = active ? 'primary' : undefined;
4310
- buttonStyles = css.css({
4311
- paddingLeft: '1rem',
4312
- paddingRight: '1rem',
4313
- maxWidth: (_b = p.maxTabWidth) !== null && _b !== void 0 ? _b : '10rem',
4314
- overflow: 'hidden',
4315
- });
4316
- }
4317
- let title = tab.title;
4318
- let buttonContent;
4319
- if (typeof tab.name === 'string') {
4320
- title !== null && title !== void 0 ? title : (title = tab.name);
4321
- buttonContent = React__namespace.createElement(Text, { tag: "div", align: "center", ellipsis: true }, tab.name);
4322
- }
4323
- else {
4324
- buttonContent = tab.name;
4325
- }
4326
- const tabId = getTabHeaderTabId(p.id, index);
4327
- return (React__namespace.createElement("li", { key: index, className: css.cx(tabStyles, p.tabClassName) },
4328
- React__namespace.createElement(Button, { id: tabId, tabIndex: active ? 0 : -1, role: "tab", "aria-controls": p.ariaControlsId, "aria-selected": active, disabled: tabsChanging, className: buttonStyles, variant: buttonVariant, title: title, readOnly: active, onClick: () => {
4329
- onTabSelect(index, tabId, false);
4330
- }, onKeyDown: e => {
4331
- e.stopPropagation();
4332
- let newIndex = index;
4333
- if (e.code === 'ArrowLeft') {
4334
- if (index === 0) {
4335
- newIndex = p.tabs.length - 1;
4336
- }
4337
- else {
4338
- newIndex = index - 1;
4339
- }
4340
- }
4341
- else if (e.code === 'ArrowRight') {
4342
- if (index === p.tabs.length - 1) {
4343
- newIndex = 0;
4344
- }
4345
- else {
4346
- newIndex = index + 1;
4347
- }
4348
- }
4349
- if (newIndex !== index) {
4350
- onTabSelect(newIndex, getTabHeaderTabId(p.id, newIndex), true);
4351
- }
4352
- } }, buttonContent)));
4353
- })),
4354
- variant === 'tab' && (React__namespace.createElement("div", { className: css.cx(css.css({
4355
- label: 'TabHeaderDivider',
4356
- borderBottom: theme.controls.border,
4357
- marginTop: `calc(${theme.controls.borderWidth} * -1)`,
4358
- zIndex: 2,
4359
- position: 'relative'
4360
- }), p.tabHeaderDividerClassName) }))));
4361
- };
4362
- function getTabHeaderTabId(tabHeaderId, tabIndex) {
4363
- return `${tabHeaderId}_tab_${tabIndex}`;
4364
- }
4365
-
4366
- const Table = (props) => {
4367
- const theme = useThemeSafely();
4368
- const tableStyles = css.css `
4369
- label: Table;
4370
- width: 100%;
4371
- border-collapse: collapse;
4372
- ${props.noCellBorder && `
4373
- .table__td {
4374
- border-left: none;
4375
- border-right: none;
4376
- }
4377
- `}
4378
- ${props.altRows && `
4379
- .table__tr:nth-of-type(even) {
4380
- background-color: ${theme.colors.lightBg};
4381
- }
4382
- `}
4383
- `;
4384
- const wrapperStyles = css.css `
4385
- label: TableScrollWrapper;
4386
- width:100%;
4387
- overflow-y: auto;
4388
- padding:0 1px; //fixes always showing of the table scroller
4389
- `;
4390
- return (React__namespace.createElement("div", { className: css.cx(wrapperStyles, props.wrapperClassName) },
4391
- React__namespace.createElement("table", { className: css.cx(tableStyles, props.className) },
4392
- props.caption && React__namespace.createElement("caption", { className: css.css({
4393
- fontWeight: 'bold',
4394
- padding: theme.controls.padding
4395
- }) }, props.caption),
4396
- props.children)));
4397
- };
4398
- const Tr = (props) => {
4399
- return (React__namespace.createElement("tr", { className: css.cx('table__tr', props.className) }, props.children));
4400
- };
4401
- const Th = (props) => {
4402
- var _a;
4403
- let style = props.style;
4404
- if (props.width) {
4405
- if (style) {
4406
- style = Object.assign(Object.assign({}, style), { width: props.width, minWidth: props.width });
4407
- }
4408
- else {
4409
- style = { width: props.width, minWidth: props.width };
4410
- }
4411
- }
4412
- const theme = useThemeSafely();
4413
- const thStyles = css.css `
4414
- border-bottom: ${theme.controls.border};
4415
- padding: ${theme.controls.padding};
4416
- font-weight: bold;
4417
- text-align: ${(_a = props.align) !== null && _a !== void 0 ? _a : 'center'};
4418
- > .button {
4419
- font-weight: bold;
4420
- }
4421
- `;
4422
- return (React__namespace.createElement("th", { className: css.cx(thStyles, props.className), style: style }, props.children));
4423
- };
4424
- const Td = (props) => {
4425
- var _a;
4426
- const theme = useThemeSafely();
4427
- const tdStyles = css.css `
4428
- border: ${theme.controls.border};
4429
- padding: ${theme.controls.padding};
4430
- vertical-align: middle;
4431
- text-align: ${(_a = props.align) !== null && _a !== void 0 ? _a : 'center'};
4432
- `;
4433
- return (React__namespace.createElement("td", { colSpan: props.colSpan, style: props.style, className: css.cx('table__td', tdStyles, props.className) }, props.children));
4434
- };
4435
-
4436
- const TdCurrency = (props) => {
4437
- let actualValue = props.value || 0;
4438
- if (props.cents) {
4439
- actualValue = actualValue / 100;
4440
- }
4441
- const displayValue = actualValue.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
4442
- return (React__namespace.createElement(Td, { align: "right" },
4443
- "$",
4444
- displayValue));
4445
- };
4446
-
4447
- const TdNumber = (props) => {
4448
- return React__namespace.createElement(Td, { align: "right" }, props.value || props.value === 0 ? props.value.toLocaleString() : '');
4449
- };
4450
-
4451
- const ThSort = (props) => {
4452
- let iconId = '';
4453
- if (props.direction) {
4454
- if (props.direction === 'asc') {
4455
- iconId = 'sortAsc';
4456
- }
4457
- else {
4458
- iconId = 'sortDesc';
4459
- }
4460
- }
4461
- let rightContentSpecialJustify = 'center';
4462
- switch (props.align) {
4463
- case 'left':
4464
- rightContentSpecialJustify = 'flex-start';
4465
- break;
4466
- case 'right':
4467
- rightContentSpecialJustify = 'flex-end';
4468
- break;
4469
- }
4470
- return (React__namespace.createElement(Th, { align: props.align, style: props.style, width: props.width },
4471
- React__namespace.createElement("div", { className: props.rightContent && css.css({
4472
- display: 'flex',
4473
- alignItems: 'center',
4474
- justifyContent: rightContentSpecialJustify,
4475
- gap: '0.5rem'
4476
- }) },
4477
- React__namespace.createElement(Button, { onClick: props.onClick, variant: "link" },
4478
- props.text,
4479
- iconId && React__namespace.createElement(Icon, { className: css.css({
4480
- marginLeft: '0.5rem'
4481
- }), id: iconId })),
4482
- props.rightContent)));
4483
- };
4484
-
4485
- const defaultMaxLength = 200;
4486
- const defaultRows = 10;
4487
- const TextArea = React__namespace.forwardRef((props, ref) => {
4488
- var _a, _b;
4489
- const [localValue, setLocalValue] = React__namespace.useState(props.value);
4490
- const inputRef = (ref !== null && ref !== void 0 ? ref : React__namespace.useRef(null));
4491
- const [validationError, updateErrorMessage] = useInputValidationMessage(inputRef, props);
4492
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
4493
- const { onValueChange, customError, reportValueOnError, showErrorDisplay, allowUpdateOnFocus } = props, nativeProps = __rest(props, ["onValueChange", "customError", "reportValueOnError", "showErrorDisplay", "allowUpdateOnFocus"]);
4494
- const theme = useThemeSafely();
4495
- React__namespace.useEffect(() => {
4496
- updateErrorMessage();
4497
- }, []);
4498
- useIgnoreMount(() => {
4499
- var _a;
4500
- if ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.checkValidity()) {
4501
- onValueChange(localValue);
4502
- }
4503
- else {
4504
- if (reportValueOnError) {
4505
- onValueChange(localValue);
4506
- }
4507
- else {
4508
- onValueChange(undefined);
4509
- }
4510
- }
4511
- updateErrorMessage();
4512
- }, [localValue]);
4513
- useIgnoreMount(() => {
4514
- if (allowUpdateOnFocus || document.activeElement !== inputRef.current) {
4515
- setLocalValue(props.value);
4516
- }
4517
- updateErrorMessage();
4518
- }, [props.value]);
4519
- const styles = css.css({
4520
- backgroundColor: theme.colors.bg,
4521
- maxWidth: '100%',
4522
- minHeight: theme.controls.height,
4523
- fontFamily: theme.fonts.family,
4524
- fontSize: theme.fonts.size,
4525
- width: '100%',
4526
- border: theme.controls.border,
4527
- borderRadius: theme.controls.borderRadius,
4528
- color: theme.colors.font,
4529
- paddingTop: '0.75rem',
4530
- paddingLeft: theme.controls.padding,
4531
- paddingRight: theme.controls.padding,
4532
- height: 'auto',
4533
- transition: theme.controls.transition,
4534
- ':focus': {
4535
- outline: 'none',
4536
- boxShadow: theme.controls.focusOutlineShadow
4537
- },
4538
- ':disabled': {
4539
- backgroundColor: theme.colors.disabled,
4540
- cursor: 'not-allowed'
4541
- },
4542
- ':invalid': {
4543
- borderColor: theme.colors.required,
4544
- ':focus': {
4545
- boxShadow: theme.controls.focusOutlineRequiredShadow
4546
- }
4547
- },
4548
- }, props.readOnly && {
4549
- backgroundColor: 'transparent',
4550
- cursor: 'default',
4551
- border: 'none',
4552
- ':focus': {
4553
- outline: 'none',
4554
- boxShadow: 'none'
4555
- }
4556
- });
4557
- return (React__namespace.createElement("span", { className: css.css({
4558
- display: 'inline-block',
4559
- width: '100%'
4560
- }) },
4561
- React__namespace.createElement("textarea", Object.assign({}, nativeProps, { className: css.cx(styles, props.className), autoComplete: (_a = props.autoComplete) !== null && _a !== void 0 ? _a : 'off', tabIndex: props.readOnly ? -1 : props.tabIndex, maxLength: props.maxLength || defaultMaxLength, rows: (_b = props.rows) !== null && _b !== void 0 ? _b : defaultRows, ref: inputRef, value: localValue !== null && localValue !== void 0 ? localValue : '', onChange: e => {
4562
- var _a;
4563
- setLocalValue(e.target.value || undefined);
4564
- (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, e);
4565
- }, onBlur: e => {
4566
- var _a;
4567
- if (!props.noTrim) {
4568
- setLocalValue(currentValue => {
4569
- return currentValue === null || currentValue === void 0 ? void 0 : currentValue.trim();
4570
- });
4571
- }
4572
- (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, e);
4573
- } })),
4574
- (showErrorDisplay !== null && showErrorDisplay !== void 0 ? showErrorDisplay : true) && React__namespace.createElement(InputErrorDisplay, { error: validationError })));
4575
- });
4576
-
4577
- const ToggleButton = React__namespace.forwardRef((props, ref) => {
4578
- const { checked, checkedChildren, uncheckedChildren, checkedVariant, checkedClassName, checkedStyle, checkedIcon, uncheckedIcon } = props, buttonProps = __rest(props, ["checked", "checkedChildren", "uncheckedChildren", "checkedVariant", "checkedClassName", "checkedStyle", "checkedIcon", "uncheckedIcon"]);
4579
- let children;
4580
- if (checked) {
4581
- children = checkedChildren;
4582
- }
4583
- else {
4584
- children = uncheckedChildren;
4585
- }
4586
- return (React__namespace.createElement(Button, Object.assign({}, buttonProps, { ref: ref, className: css.cx('toggleButton', checked && 'toggleButton--checked', props.className, checked && checkedClassName), rightIcon: checked ? checkedIcon : uncheckedIcon, variant: checked ? checkedVariant : props.variant, style: checked ? checkedStyle : props.style }), children));
4587
- });
4588
-
4589
- const ToggleButtonGroup = (props) => {
4590
- const theme = useThemeSafely();
4591
- const groupStyles = css.css `
4592
- display: flex;
4593
- box-shadow: ${theme.controls.buttonBoxShadow};
4594
- border-radius: ${theme.controls.borderRadius};
4595
- ${props.round && `
4596
- border-radius: ${theme.controls.roundRadius};
4597
- `}
4598
- `;
4599
- const buttonStyles = css.css `
4600
- flex-grow:1;
4601
- box-shadow: none;
4602
- &:nth-of-type(1n+2){
4603
- margin-left: -1px;
4604
- }
4605
- border-radius: 0;
4606
- &:first-of-type{
4607
- border-top-left-radius: ${theme.controls.borderRadius};
4608
- border-bottom-left-radius: ${theme.controls.borderRadius};
4609
- }
4610
- &:last-child {
4611
- border-top-right-radius: ${theme.controls.borderRadius};
4612
- border-bottom-right-radius: ${theme.controls.borderRadius};
4613
- }
4614
- ${props.round && `
4615
- &:first-of-type{
4616
- border-top-left-radius: ${theme.controls.roundRadius};
4617
- border-bottom-left-radius: ${theme.controls.roundRadius};
4618
- padding-left: 1rem;
4619
- }
4620
- &:last-child {
4621
- border-top-right-radius: ${theme.controls.roundRadius};
4622
- border-bottom-right-radius: ${theme.controls.roundRadius};
4623
- padding-right: 1rem;
4624
- }
4625
- `}
4626
- `;
4627
- return (React__namespace.createElement("div", { className: css.cx('toggleButtonGroup', groupStyles, props.className) }, props.options.map(o => {
4628
- const active = o.id === props.value;
4629
- return React__namespace.createElement(Button, { style: props.width ? { width: props.width } : undefined, small: props.small, rightIcon: o.rightIcon, key: o.id, tabIndex: active ? -1 : 0, className: css.cx(css.css `
4630
- ${buttonStyles}
4631
- ${active && `
4632
- background-color: ${theme.colors.font};
4633
- color: ${theme.colors.bg};
4634
- cursor: default;
4635
- &:hover:not(:disabled) {
4636
- filter: none;
4637
- }
4638
- &:focus {
4639
- outline: none;
4640
- box-shadow: none;
4641
- }
4642
- `}
4643
- `, active ? o.activeClass : undefined), disabled: props.disabled, enforceMinWidth: props.enforceMinWidth, onClick: () => {
4644
- if (active) {
4645
- return;
4646
- }
4647
- props.onChange(o.id);
4648
- } }, o.name);
4649
- })));
4650
- };
4651
-
4652
- const TogglePasswordInput = React__namespace.forwardRef((props, ref) => {
4653
- const { onVisibilityChanged } = props, inputProps = __rest(props, ["onVisibilityChanged"]);
4654
- const [show, setShow] = React__namespace.useState(false);
4655
- useIgnoreMount(() => {
4656
- onVisibilityChanged === null || onVisibilityChanged === void 0 ? void 0 : onVisibilityChanged(show);
4657
- }, [show]);
4658
- return (React__namespace.createElement(TextInput, Object.assign({}, inputProps, { ref: ref, type: show ? 'text' : 'password', rightControl: (React__namespace.createElement(Button, { small: true, style: {
4659
- // small button is required here due to the icon pushing outside the boundries of the
4660
- // parent textbox. increasing the font size here to fill the small button.
4661
- fontSize: '1rem'
4662
- }, variant: "icon", onClick: () => {
4663
- setShow(previous => !previous);
4664
- } },
4665
- React__namespace.createElement(Icon, { id: show ? 'show' : 'hide' }))) })));
4666
- });
4667
-
4668
- let clearTimerId = undefined;
4669
- /** Allows for status notificaiton methods for screen readers.
4670
- * This hook does not have any dependencies, so it can be used in projects that don't important anything else from the style_guide. */
4671
- function useAriaLiveRegion() {
4672
- const id = 'MknAriaLiveRegion';
4673
- if (!document.getElementById(id)) {
4674
- const div = document.createElement('div');
4675
- div.id = id;
4676
- // different sources cannot decide if this is needed.
4677
- // "Can work for status messages, but aria-live="polite" + text is usually simpler and more reliable for loading."
4678
- div.role = 'status';
4679
- div.ariaLive = 'polite';
4680
- div.ariaAtomic = 'true';
4681
- div.style.position = 'absolute';
4682
- div.style.width = '1px';
4683
- div.style.height = '1px';
4684
- div.style.padding = '0px';
4685
- div.style.margin = '-1px';
4686
- div.style.overflow = 'hidden';
4687
- div.style.whiteSpace = 'nowrap';
4688
- document.body.prepend(div);
4689
- }
4690
- const clearNotification = () => {
4691
- if (clearTimerId) {
4692
- clearTimeout(clearTimerId);
4693
- }
4694
- const element = document.getElementById(id);
4695
- if (!element) {
4696
- return;
4697
- }
4698
- element.textContent = '';
4699
- };
4700
- return {
4701
- /**
4702
- * @param message - The text to be read by the screen reader.
4703
- * @param clearTimeoutMs - Milliseconds to wait before the message is cleared. Defaults to `2000`.
4704
- */
4705
- notify: (message, clearTimoutMs) => {
4706
- if (clearTimerId) {
4707
- clearTimeout(clearTimerId);
4708
- }
4709
- const element = document.getElementById(id);
4710
- if (!element) {
4711
- return;
4712
- }
4713
- element.textContent = message;
4714
- clearTimerId = setTimeout(() => {
4715
- // this is considered a good practice. if you leave text here, some screen readers will read it out randomly as you navigate around the page.
4716
- clearNotification();
4717
- }, clearTimoutMs !== null && clearTimoutMs !== void 0 ? clearTimoutMs : 2000);
4718
- },
4719
- clearNotification
4720
- };
4721
- }
4722
-
4723
- const WaitingIndicator = (p) => {
4724
- var _a, _b, _c;
4725
- const [show, setShow] = React.useState(p.show);
4726
- const hideTimer = React.useRef(0);
4727
- const lastShowStatus = React.useRef(false);
4728
- const log = useLogger(`WaitingIndicator ${(_a = p.id) !== null && _a !== void 0 ? _a : '?'}`, (_b = p.__debug) !== null && _b !== void 0 ? _b : false);
4729
- const { notify, clearNotification } = useAriaLiveRegion();
4730
- if (p.__debug) {
4731
- React.useEffect(() => {
4732
- log('mounted');
4733
- return () => {
4734
- log('unmounted');
4735
- };
4736
- }, []);
4737
- }
4738
- React.useEffect(() => {
4739
- log('show changed', p.show);
4740
- // we need to store the 'last props' since props.show will be captured locally and the incorrect
4741
- // value will display in the timeout below.
4742
- log('storing lastShowStatus', p.show);
4743
- lastShowStatus.current = p.show;
4744
- if (p.show) {
4745
- log('setShow', true);
4746
- setShow(true);
4747
- if (p.minShowTimeMs) {
4748
- log('staring hideTimer', 'timout in ms:', p.minShowTimeMs);
4749
- hideTimer.current = window.setTimeout(() => {
4750
- log('hideTimer complete', 'clearing hideTimer');
4751
- window.clearTimeout(hideTimer.current);
4752
- hideTimer.current = 0;
4753
- // this check is necessary since the show status may have updated again to true.
4754
- // if so, ignore this timeout since we're already past the min time and we're still
4755
- // showing the component.
4756
- if (!lastShowStatus.current) {
4757
- log('setShow', false);
4758
- setShow(false);
4759
- }
4760
- else {
4761
- log('ignoring hideTimer handler due to hideTimer ticking');
4762
- }
4763
- }, p.minShowTimeMs);
4764
- }
4765
- }
4766
- else {
4767
- // ignore hiding the component since the min timer is running.
4768
- if (!hideTimer.current) {
4769
- log('setShow', false);
4770
- setShow(false);
4771
- }
4772
- else {
4773
- log('ignoring show change due to hideTimer ticking');
4774
- }
4775
- }
4776
- if (p.show) {
4777
- // set to a very long time so the hiding of the waiting indicator clears it.
4778
- notify('Loading content.', 60000);
4779
- }
4780
- else {
4781
- clearNotification();
4782
- }
4783
- }, [p.show]);
4784
- const id = (_c = p.id) !== null && _c !== void 0 ? _c : 'MknWaitingIndicator';
4785
- return (React.createElement(Modal, { id: id, __debug: p.__debug, __asWaitingIndicator: true, heading: '', onClose: () => {
4786
- /* noop */
4787
- }, className: "waitingIndicator", show: show },
4788
- React.createElement("div", { className: css.css({
4789
- color: 'white',
4790
- fontSize: '3rem',
4791
- padding: '0.7rem'
4792
- }) },
4793
- React.createElement(Icon, { id: "waiting", spin: true }))));
4433
+ } }, p.children));
4794
4434
  };
4795
4435
 
4796
4436
  /*
@@ -5089,283 +4729,777 @@ summary {
5089
4729
  `;
5090
4730
  return null;
5091
4731
  };
5092
-
5093
- /** Displays the value in American dollars. */
5094
- const getCurrencyDisplay = (value, isCents, denomination = '$') => {
5095
- let actualValue = value || 0;
5096
- if (isCents) {
5097
- actualValue /= 100;
4732
+
4733
+ const Table = (props) => {
4734
+ const theme = useThemeSafely();
4735
+ const tableStyles = css.css `
4736
+ label: Table;
4737
+ width: 100%;
4738
+ border-collapse: collapse;
4739
+ ${props.noCellBorder && `
4740
+ .table__td {
4741
+ border-left: none;
4742
+ border-right: none;
4743
+ }
4744
+ `}
4745
+ ${props.altRows && `
4746
+ .table__tr:nth-of-type(even) {
4747
+ background-color: ${theme.colors.lightBg};
4748
+ }
4749
+ `}
4750
+ `;
4751
+ const wrapperStyles = css.css `
4752
+ label: TableScrollWrapper;
4753
+ width:100%;
4754
+ overflow-y: auto;
4755
+ padding:0 1px; //fixes always showing of the table scroller
4756
+ `;
4757
+ return (React__namespace.createElement("div", { className: css.cx(wrapperStyles, props.wrapperClassName) },
4758
+ React__namespace.createElement("table", { className: css.cx(tableStyles, props.className) },
4759
+ props.caption && React__namespace.createElement("caption", { className: css.css({
4760
+ fontWeight: 'bold',
4761
+ padding: theme.controls.padding
4762
+ }) }, props.caption),
4763
+ props.children)));
4764
+ };
4765
+ const Tr = (props) => {
4766
+ return (React__namespace.createElement("tr", { className: css.cx('table__tr', props.className) }, props.children));
4767
+ };
4768
+ const Th = (props) => {
4769
+ var _a;
4770
+ let style = props.style;
4771
+ if (props.width) {
4772
+ if (style) {
4773
+ style = Object.assign(Object.assign({}, style), { width: props.width, minWidth: props.width });
4774
+ }
4775
+ else {
4776
+ style = { width: props.width, minWidth: props.width };
4777
+ }
4778
+ }
4779
+ const theme = useThemeSafely();
4780
+ const thStyles = css.css `
4781
+ border-bottom: ${theme.controls.border};
4782
+ padding: ${theme.controls.padding};
4783
+ font-weight: bold;
4784
+ text-align: ${(_a = props.align) !== null && _a !== void 0 ? _a : 'center'};
4785
+ > .button {
4786
+ font-weight: bold;
4787
+ }
4788
+ `;
4789
+ return (React__namespace.createElement("th", { className: css.cx(thStyles, props.className), style: style }, props.children));
4790
+ };
4791
+ const Td = (props) => {
4792
+ var _a;
4793
+ const theme = useThemeSafely();
4794
+ const tdStyles = css.css `
4795
+ border: ${theme.controls.border};
4796
+ padding: ${theme.controls.padding};
4797
+ vertical-align: middle;
4798
+ text-align: ${(_a = props.align) !== null && _a !== void 0 ? _a : 'center'};
4799
+ `;
4800
+ return (React__namespace.createElement("td", { colSpan: props.colSpan, style: props.style, className: css.cx('table__td', tdStyles, props.className) }, props.children));
4801
+ };
4802
+
4803
+ /* eslint @typescript-eslint/no-explicit-any: 0 */
4804
+ const ThemeRenderer = (p) => {
4805
+ const { backgroundColor, color } = p, theme = __rest(p, ["backgroundColor", "color"]);
4806
+ const flatTheme = flatten(theme);
4807
+ const entries = lodash.orderBy(Object.entries(flatTheme), x => x[0]);
4808
+ return (React__namespace.createElement(Table, { caption: (React__namespace.createElement("div", null,
4809
+ React__namespace.createElement(Text, { tag: "h1", align: "center" }, "Theme"),
4810
+ React__namespace.createElement(Text, { tag: "p", align: "center", italics: true }, "Background color applied to show colors with alpha ('rgba(X, X, X, 0.X)')"))), className: css.css({
4811
+ backgroundColor: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : '#eee7ca',
4812
+ color: color !== null && color !== void 0 ? color : 'black'
4813
+ }) },
4814
+ React__namespace.createElement("thead", null,
4815
+ React__namespace.createElement(Tr, null,
4816
+ React__namespace.createElement(Th, { align: "left" }, "Property"),
4817
+ React__namespace.createElement(Th, { align: "left" }, "Value"))),
4818
+ React__namespace.createElement("tbody", null, entries.map(([key, value]) => {
4819
+ let colorBox;
4820
+ if (/color/i.test(key)) {
4821
+ colorBox = (React__namespace.createElement("span", { className: css.css({
4822
+ display: 'block',
4823
+ border: '1px solid black',
4824
+ width: '100%',
4825
+ height: 24,
4826
+ background: value
4827
+ }) }));
4828
+ }
4829
+ return (React__namespace.createElement(Tr, { key: key },
4830
+ React__namespace.createElement(Td, { align: "left" }, key),
4831
+ React__namespace.createElement(Td, { align: "left" },
4832
+ React__namespace.createElement("div", { className: css.css({
4833
+ display: 'flex',
4834
+ alignItems: 'center',
4835
+ gap: '1rem'
4836
+ }) },
4837
+ React__namespace.createElement("span", { className: css.css({ flexShrink: 1 }) }, value),
4838
+ " ",
4839
+ colorBox))));
4840
+ }))));
4841
+ };
4842
+ const flatten = (obj, parent, path = 'theme') => {
4843
+ const flatObj = parent !== null && parent !== void 0 ? parent : {};
4844
+ for (const prop in obj) {
4845
+ const value = obj[prop];
4846
+ const fullPath = `${path}.${prop}`;
4847
+ if (typeof value !== 'object') {
4848
+ flatObj[fullPath] = value;
4849
+ }
4850
+ else {
4851
+ flatten(value, flatObj, fullPath);
4852
+ }
4853
+ }
4854
+ return flatObj;
4855
+ };
4856
+
4857
+ let clearTimerId = undefined;
4858
+ /** Allows for status notificaiton methods for screen readers.
4859
+ * This hook does not have any dependencies, so it can be used in projects that don't important anything else from the style_guide. */
4860
+ function useAriaLiveRegion() {
4861
+ const id = 'MknAriaLiveRegion';
4862
+ if (!document.getElementById(id)) {
4863
+ const div = document.createElement('div');
4864
+ div.id = id;
4865
+ // different sources cannot decide if this is needed.
4866
+ // "Can work for status messages, but aria-live="polite" + text is usually simpler and more reliable for loading."
4867
+ div.role = 'status';
4868
+ div.ariaLive = 'polite';
4869
+ div.ariaAtomic = 'true';
4870
+ div.style.position = 'absolute';
4871
+ div.style.width = '1px';
4872
+ div.style.height = '1px';
4873
+ div.style.padding = '0px';
4874
+ div.style.margin = '-1px';
4875
+ div.style.overflow = 'hidden';
4876
+ div.style.whiteSpace = 'nowrap';
4877
+ document.body.prepend(div);
4878
+ }
4879
+ const clearNotification = () => {
4880
+ if (clearTimerId) {
4881
+ clearTimeout(clearTimerId);
4882
+ }
4883
+ const element = document.getElementById(id);
4884
+ if (!element) {
4885
+ return;
4886
+ }
4887
+ element.textContent = '';
4888
+ };
4889
+ return {
4890
+ /**
4891
+ * @param message - The text to be read by the screen reader.
4892
+ * @param clearTimeoutMs - Milliseconds to wait before the message is cleared. Defaults to `2000`.
4893
+ */
4894
+ notify: (message, clearTimoutMs) => {
4895
+ if (clearTimerId) {
4896
+ clearTimeout(clearTimerId);
4897
+ }
4898
+ const element = document.getElementById(id);
4899
+ if (!element) {
4900
+ return;
4901
+ }
4902
+ element.textContent = message;
4903
+ clearTimerId = setTimeout(() => {
4904
+ // this is considered a good practice. if you leave text here, some screen readers will read it out randomly as you navigate around the page.
4905
+ clearNotification();
4906
+ }, clearTimoutMs !== null && clearTimoutMs !== void 0 ? clearTimoutMs : 2000);
4907
+ },
4908
+ clearNotification
4909
+ };
4910
+ }
4911
+
4912
+ /*
4913
+ From https://fireship.io/snippets/use-media-query-hook/.
4914
+ Tried using https://www.npmjs.com/package/react-media, but it cause Webpack build issues.
4915
+ */
4916
+ /** React wrapper around window resizing and window.matchMedia.
4917
+ * https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
4918
+ */
4919
+ const useMediaQuery = (query) => {
4920
+ const [matches, setMatches] = React.useState(window.matchMedia(query).matches);
4921
+ React.useEffect(() => {
4922
+ const media = window.matchMedia(query);
4923
+ if (media.matches !== matches) {
4924
+ setMatches(media.matches);
4925
+ }
4926
+ const listener = () => setMatches(media.matches);
4927
+ window.addEventListener("resize", listener);
4928
+ return () => window.removeEventListener("resize", listener);
4929
+ }, [matches, query]);
4930
+ return matches;
4931
+ };
4932
+
4933
+ const Slider = (p) => {
4934
+ var _a;
4935
+ const theme = useThemeSafely();
4936
+ const sliderContainer = React.useRef(null);
4937
+ const sliderHandleSize = (_a = p.sliderHandleSize) !== null && _a !== void 0 ? _a : theme.controls.height;
4938
+ const height = p.showValue ? `calc(${sliderHandleSize} + 1.5rem)` : sliderHandleSize;
4939
+ // we're keeping this value in a ref vs. state so the constant updates don't cause re-render.
4940
+ // we will have to respond to outside value changes after the fact however...
4941
+ const currentValue = React.useRef(p.value);
4942
+ const [, forceUpdate] = React.useState(Date.now());
4943
+ React.useEffect(() => {
4944
+ if (p.value !== currentValue.current) {
4945
+ currentValue.current = p.value;
4946
+ forceUpdate(Date.now());
4947
+ }
4948
+ }, [p.value]);
4949
+ return (React.createElement("div", { ref: sliderContainer, className: css.cx(css.css({
4950
+ label: 'Slider',
4951
+ width: '100%',
4952
+ height,
4953
+ }), p.className) },
4954
+ React.createElement(ReactSlider, { ariaLabel: p.ariaLabel, step: p.step, min: p.min, max: p.max, value: p.value, onAfterChange: (value) => {
4955
+ p.onChange(value);
4956
+ }, onChange: p.onUpdate || p.showValue ? (value) => {
4957
+ var _a;
4958
+ currentValue.current = value;
4959
+ (_a = p.onUpdate) === null || _a === void 0 ? void 0 : _a.call(p, value);
4960
+ } : undefined, renderTrack: (props) => {
4961
+ const { className } = props, rest = __rest(props, ["className"]);
4962
+ return (React.createElement("div", Object.assign({ className: css.cx(className, p.trackClassName, css.css({
4963
+ display: 'flex',
4964
+ alignItems: 'center',
4965
+ height: sliderHandleSize
4966
+ })) }, rest),
4967
+ React.createElement("div", { className: css.css({
4968
+ backgroundColor: theme.colors.secondary,
4969
+ height: `calc(${sliderHandleSize} / 4)`,
4970
+ borderRadius: theme.controls.roundRadius,
4971
+ width: '100%'
4972
+ }, p.innerTrackClassName && rest.key === 'track-1' && Array.isArray(p.value) ? p.innerTrackClassName : undefined) })));
4973
+ }, renderThumb: (props, state) => {
4974
+ var _a;
4975
+ const { className } = props, rest = __rest(props, ["className"]);
4976
+ let specificThumbStyles;
4977
+ if (p.handle1ClassName && props.key === 'thumb-0') {
4978
+ specificThumbStyles = p.handle1ClassName;
4979
+ }
4980
+ else if (p.handle2ClassName && props.key === 'thumb-1') {
4981
+ specificThumbStyles = p.handle2ClassName;
4982
+ }
4983
+ return (React.createElement("div", Object.assign({ className: css.cx(className, css.css({
4984
+ borderRadius: theme.controls.roundRadius,
4985
+ backgroundColor: 'white',
4986
+ border: theme.controls.border,
4987
+ cursor: 'grab',
4988
+ boxShadow: theme.controls.buttonBoxShadow,
4989
+ transition: theme.controls.transition,
4990
+ '&:focus': {
4991
+ outline: 'none',
4992
+ boxShadow: theme.controls.focusOutlineShadow
4993
+ },
4994
+ '&:active': {
4995
+ boxShadow: 'none',
4996
+ cursor: 'grabbing'
4997
+ },
4998
+ '&:hover': {
4999
+ filter: theme.controls.hoverBrightness
5000
+ }
5001
+ }), specificThumbStyles, p.handleClassName, css.css({
5002
+ width: sliderHandleSize,
5003
+ height: sliderHandleSize,
5004
+ })) }, rest, { tabIndex: (_a = p.tabIndex) !== null && _a !== void 0 ? _a : 0 }), p.showValue && (React.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 }))));
5005
+ } })));
5006
+ };
5007
+ const rectsCollideX = (r1, r2) => {
5008
+ if (r1.left >= r2.left && r1.left <= r2.right) {
5009
+ return true;
5098
5010
  }
5099
- return `${denomination}${actualValue.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
5011
+ if (r1.right >= r2.left && r1.right <= r2.right) {
5012
+ return true;
5013
+ }
5014
+ return false;
5015
+ };
5016
+ const HandleText = (p) => {
5017
+ var _a, _b, _c;
5018
+ const displayValue = (_b = (_a = p.renderValue) === null || _a === void 0 ? void 0 : _a.call(p, p.value)) !== null && _b !== void 0 ? _b : p.value;
5019
+ const renderValueWidth = (_c = p.renderValueWidth) !== null && _c !== void 0 ? _c : p.sliderHandleSize;
5020
+ const renderValueLeft = React.useMemo(() => {
5021
+ return `calc(${renderValueWidth} * 0.5 * -1 + (${p.sliderHandleSize} * 0.5))`;
5022
+ }, [p.renderValueWidth, p.sliderHandleSize]);
5023
+ const [flipText, setFlipText] = React.useState(false);
5024
+ const offset = '2px';
5025
+ React.useEffect(() => {
5026
+ // this needs to fire on every render due to the other handle also moving.
5027
+ var _a, _b;
5028
+ if (p.index === 1) {
5029
+ // only do this for the max/right-most handle
5030
+ 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());
5031
+ if (r1 && r2) {
5032
+ setFlipText(rectsCollideX(r1, r2));
5033
+ }
5034
+ }
5035
+ });
5036
+ return (React.createElement(Text, { ellipsis: true, className: css.cx('slider-handle', css.css({
5037
+ width: renderValueWidth,
5038
+ left: renderValueLeft,
5039
+ top: flipText ? undefined : `calc(${p.sliderHandleSize} + ${offset})`,
5040
+ bottom: flipText ? `calc(${p.sliderHandleSize} + ${offset})` : undefined,
5041
+ position: 'absolute',
5042
+ overflow: 'hidden',
5043
+ }), p.className), tag: "div", align: "center" }, displayValue));
5100
5044
  };
5101
5045
 
5102
- /** Converts an enum to an array of entities with id and name. The enum can be an integer or string enum.*/
5103
- const enumToEntities = (enumObj) => {
5104
- const entities = [];
5105
- for (const key in enumObj) {
5106
- if (isNaN(parseInt(key, 10))) {
5107
- entities.push({
5108
- id: enumObj[key],
5109
- name: key
5046
+ const TabHeader = (p) => {
5047
+ var _a, _b;
5048
+ const [tabIndex, setTabIndex] = React__namespace.useState((_a = p.startingIndex) !== null && _a !== void 0 ? _a : 0);
5049
+ const [tabsChanging, setTabsChanging] = React__namespace.useState(false);
5050
+ const theme = useThemeSafely();
5051
+ const variant = (_b = p.variant) !== null && _b !== void 0 ? _b : 'tab';
5052
+ const menuStyles = css.css({
5053
+ display: 'flex',
5054
+ gap: theme.controls.gap,
5055
+ listStyleType: 'none',
5056
+ margin: 0,
5057
+ padding: 0,
5058
+ flexWrap: variant === 'button' ? 'wrap' : 'nowrap'
5059
+ }, variant === 'button' && {
5060
+ borderBottom: theme.controls.border,
5061
+ paddingBottom: '1rem'
5062
+ });
5063
+ function onTabSelect(index, tabId, focusAfter) {
5064
+ const onChange = () => {
5065
+ var _a;
5066
+ setTabIndex(index);
5067
+ (_a = p.onTabChanged) === null || _a === void 0 ? void 0 : _a.call(p, index);
5068
+ if (focusAfter) {
5069
+ setTimeout(() => {
5070
+ var _a;
5071
+ (_a = document.getElementById(tabId)) === null || _a === void 0 ? void 0 : _a.focus();
5072
+ }, 0);
5073
+ }
5074
+ };
5075
+ if (p.onBeforeTabChanged) {
5076
+ setTabsChanging(true);
5077
+ p.onBeforeTabChanged(index)
5078
+ .then(() => {
5079
+ onChange();
5080
+ })
5081
+ .catch(() => {
5082
+ /* do nothing */
5083
+ })
5084
+ .finally(() => {
5085
+ setTabsChanging(false);
5110
5086
  });
5111
5087
  }
5088
+ else {
5089
+ onChange();
5090
+ }
5091
+ }
5092
+ return (React__namespace.createElement("div", { className: "tabHeader" },
5093
+ React__namespace.createElement("ul", { role: 'tablist', "aria-label": p.ariaLabel, className: css.cx(menuStyles, p.containerClassName) }, p.tabs.map((tab, index) => {
5094
+ var _a, _b;
5095
+ const active = index === tabIndex;
5096
+ let tabStyles;
5097
+ let buttonStyles;
5098
+ let buttonVariant;
5099
+ if (variant === 'tab') {
5100
+ tabStyles = css.css({
5101
+ paddingLeft: '1rem',
5102
+ paddingRight: '1rem',
5103
+ backgroundColor: theme.colors.bg,
5104
+ zIndex: 1,
5105
+ }, active && {
5106
+ border: theme.controls.border,
5107
+ borderRadius: theme.controls.borderRadius,
5108
+ borderBottomLeftRadius: 0,
5109
+ borderBottomRightRadius: 0,
5110
+ borderBottom: 'none',
5111
+ zIndex: 3,
5112
+ });
5113
+ buttonVariant = 'link';
5114
+ buttonStyles = css.css({
5115
+ maxWidth: (_a = p.maxTabWidth) !== null && _a !== void 0 ? _a : '10rem',
5116
+ overflow: 'hidden'
5117
+ });
5118
+ }
5119
+ else {
5120
+ buttonVariant = active ? 'primary' : undefined;
5121
+ buttonStyles = css.css({
5122
+ paddingLeft: '1rem',
5123
+ paddingRight: '1rem',
5124
+ maxWidth: (_b = p.maxTabWidth) !== null && _b !== void 0 ? _b : '10rem',
5125
+ overflow: 'hidden',
5126
+ });
5127
+ }
5128
+ let title = tab.title;
5129
+ let buttonContent;
5130
+ if (typeof tab.name === 'string') {
5131
+ title !== null && title !== void 0 ? title : (title = tab.name);
5132
+ buttonContent = React__namespace.createElement(Text, { tag: "div", align: "center", ellipsis: true }, tab.name);
5133
+ }
5134
+ else {
5135
+ buttonContent = tab.name;
5136
+ }
5137
+ const tabId = getTabHeaderTabId(p.id, index);
5138
+ return (React__namespace.createElement("li", { key: index, className: css.cx(tabStyles, p.tabClassName) },
5139
+ React__namespace.createElement(Button, { id: tabId, tabIndex: active ? 0 : -1, role: "tab", "aria-controls": p.ariaControlsId, "aria-selected": active, disabled: tabsChanging, className: buttonStyles, variant: buttonVariant, title: title, readOnly: active, onClick: () => {
5140
+ onTabSelect(index, tabId, false);
5141
+ }, onKeyDown: e => {
5142
+ e.stopPropagation();
5143
+ let newIndex = index;
5144
+ if (e.code === 'ArrowLeft') {
5145
+ if (index === 0) {
5146
+ newIndex = p.tabs.length - 1;
5147
+ }
5148
+ else {
5149
+ newIndex = index - 1;
5150
+ }
5151
+ }
5152
+ else if (e.code === 'ArrowRight') {
5153
+ if (index === p.tabs.length - 1) {
5154
+ newIndex = 0;
5155
+ }
5156
+ else {
5157
+ newIndex = index + 1;
5158
+ }
5159
+ }
5160
+ if (newIndex !== index) {
5161
+ onTabSelect(newIndex, getTabHeaderTabId(p.id, newIndex), true);
5162
+ }
5163
+ } }, buttonContent)));
5164
+ })),
5165
+ variant === 'tab' && (React__namespace.createElement("div", { className: css.cx(css.css({
5166
+ label: 'TabHeaderDivider',
5167
+ borderBottom: theme.controls.border,
5168
+ marginTop: `calc(${theme.controls.borderWidth} * -1)`,
5169
+ zIndex: 2,
5170
+ position: 'relative'
5171
+ }), p.tabHeaderDividerClassName) }))));
5172
+ };
5173
+ function getTabHeaderTabId(tabHeaderId, tabIndex) {
5174
+ return `${tabHeaderId}_tab_${tabIndex}`;
5175
+ }
5176
+
5177
+ const TabContainer = (p) => {
5178
+ var _a;
5179
+ const [tabIndex, setTabIndex] = React__namespace.useState((_a = p.startingIndex) !== null && _a !== void 0 ? _a : 0);
5180
+ const theme = useThemeSafely();
5181
+ const tabPanelId = `${p.id}_tabpanel`;
5182
+ const tabHeaderId = `${p.id}_TabHeader`;
5183
+ return (React__namespace.createElement("div", { className: css.css({
5184
+ label: 'TabContainer'
5185
+ }) },
5186
+ React__namespace.createElement(TabHeader, { id: tabHeaderId, ariaControlsId: tabPanelId, ariaLabel: p.ariaLabel, tabs: p.tabs, maxTabWidth: p.maxTabWidth, variant: p.variant, containerClassName: p.tabHeaderClassName, tabClassName: p.tabClassName, tabHeaderDividerClassName: p.tabHeaderDividerClassName, startingIndex: tabIndex, onBeforeTabChanged: p.onBeforeTabChanged, onTabChanged: (newIndex) => {
5187
+ var _a;
5188
+ setTabIndex(newIndex);
5189
+ (_a = p.onTabChanged) === null || _a === void 0 ? void 0 : _a.call(p, newIndex);
5190
+ } }),
5191
+ React__namespace.createElement("div", { role: 'tabpanel', id: tabPanelId, "aria-labelledby": getTabHeaderTabId(tabHeaderId, tabIndex), className: css.cx(css.css({
5192
+ label: 'TabContainerContent',
5193
+ padding: '1rem',
5194
+ borderLeft: theme.controls.border,
5195
+ borderRight: theme.controls.border,
5196
+ borderBottom: theme.controls.border,
5197
+ }), p.contentClassName) }, p.tabs[tabIndex].getContent())));
5198
+ };
5199
+
5200
+ const TdCurrency = (props) => {
5201
+ let actualValue = props.value || 0;
5202
+ if (props.cents) {
5203
+ actualValue = actualValue / 100;
5204
+ }
5205
+ const displayValue = actualValue.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
5206
+ return (React__namespace.createElement(Td, { align: "right" },
5207
+ "$",
5208
+ displayValue));
5209
+ };
5210
+
5211
+ const TdNumber = (props) => {
5212
+ return React__namespace.createElement(Td, { align: "right" }, props.value || props.value === 0 ? props.value.toLocaleString() : '');
5213
+ };
5214
+
5215
+ const ThSort = (props) => {
5216
+ let iconId = '';
5217
+ if (props.direction) {
5218
+ if (props.direction === 'asc') {
5219
+ iconId = 'sortAsc';
5220
+ }
5221
+ else {
5222
+ iconId = 'sortDesc';
5223
+ }
5112
5224
  }
5113
- return entities;
5225
+ let rightContentSpecialJustify = 'center';
5226
+ switch (props.align) {
5227
+ case 'left':
5228
+ rightContentSpecialJustify = 'flex-start';
5229
+ break;
5230
+ case 'right':
5231
+ rightContentSpecialJustify = 'flex-end';
5232
+ break;
5233
+ }
5234
+ return (React__namespace.createElement(Th, { align: props.align, style: props.style, width: props.width },
5235
+ React__namespace.createElement("div", { className: props.rightContent && css.css({
5236
+ display: 'flex',
5237
+ alignItems: 'center',
5238
+ justifyContent: rightContentSpecialJustify,
5239
+ gap: '0.5rem'
5240
+ }) },
5241
+ React__namespace.createElement(Button, { onClick: props.onClick, variant: "link" },
5242
+ props.text,
5243
+ iconId && React__namespace.createElement(Icon, { className: css.css({
5244
+ marginLeft: '0.5rem'
5245
+ }), id: iconId })),
5246
+ props.rightContent)));
5114
5247
  };
5115
5248
 
5116
- const Link = (props) => {
5249
+ const defaultMaxLength = 200;
5250
+ const defaultRows = 10;
5251
+ const TextArea = React__namespace.forwardRef((props, ref) => {
5252
+ var _a, _b;
5253
+ const [localValue, setLocalValue] = React__namespace.useState(props.value);
5254
+ const inputRef = (ref !== null && ref !== void 0 ? ref : React__namespace.useRef(null));
5255
+ const [validationError, updateErrorMessage] = useInputValidationMessage(inputRef, props);
5117
5256
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
5118
- const { rightIcon, leftIcon, block, iconBlock, variant, round, small, colorOverride, children, disabled, ref, waiting } = props, linkProps = __rest(props, ["rightIcon", "leftIcon", "block", "iconBlock", "variant", "round", "small", "colorOverride", "children", "disabled", "ref", "waiting"]);
5257
+ const { onValueChange, customError, reportValueOnError, showErrorDisplay, allowUpdateOnFocus } = props, nativeProps = __rest(props, ["onValueChange", "customError", "reportValueOnError", "showErrorDisplay", "allowUpdateOnFocus"]);
5119
5258
  const theme = useThemeSafely();
5120
- const linkStyles = generateLinkStyles(props, theme);
5121
- const mainClassName = css.cx('link', linkStyles, props.className);
5122
- if (variant === 'text') {
5123
- return React__namespace.createElement(Text, { className: mainClassName, tag: "div" }, props.children);
5124
- }
5125
- const isDisabled = props.disabled || props.waiting;
5126
- return (React__namespace.createElement("a", Object.assign({}, linkProps, { tabIndex: disabled ? -1 : undefined, target: props.target, className: mainClassName, onClick: e => {
5127
- var _a;
5128
- if (isDisabled) {
5129
- e.stopPropagation();
5130
- e.preventDefault();
5259
+ React__namespace.useEffect(() => {
5260
+ updateErrorMessage();
5261
+ }, []);
5262
+ useIgnoreMount(() => {
5263
+ var _a;
5264
+ if ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.checkValidity()) {
5265
+ onValueChange(localValue);
5266
+ }
5267
+ else {
5268
+ if (reportValueOnError) {
5269
+ onValueChange(localValue);
5131
5270
  }
5132
5271
  else {
5133
- (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
5134
- }
5135
- } }),
5136
- React__namespace.createElement(LinkContent, Object.assign({}, props))));
5137
- };
5138
-
5139
- /* eslint @typescript-eslint/no-explicit-any: 0 */
5140
- const ThemeRenderer = (p) => {
5141
- const { backgroundColor, color } = p, theme = __rest(p, ["backgroundColor", "color"]);
5142
- const flatTheme = flatten(theme);
5143
- const entries = lodash.orderBy(Object.entries(flatTheme), x => x[0]);
5144
- return (React__namespace.createElement(Table, { caption: (React__namespace.createElement("div", null,
5145
- React__namespace.createElement(Text, { tag: "h1", align: "center" }, "Theme"),
5146
- React__namespace.createElement(Text, { tag: "p", align: "center", italics: true }, "Background color applied to show colors with alpha ('rgba(X, X, X, 0.X)')"))), className: css.css({
5147
- backgroundColor: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : '#eee7ca',
5148
- color: color !== null && color !== void 0 ? color : 'black'
5149
- }) },
5150
- React__namespace.createElement("thead", null,
5151
- React__namespace.createElement(Tr, null,
5152
- React__namespace.createElement(Th, { align: "left" }, "Property"),
5153
- React__namespace.createElement(Th, { align: "left" }, "Value"))),
5154
- React__namespace.createElement("tbody", null, entries.map(([key, value]) => {
5155
- let colorBox;
5156
- if (/color/i.test(key)) {
5157
- colorBox = (React__namespace.createElement("span", { className: css.css({
5158
- display: 'block',
5159
- border: '1px solid black',
5160
- width: '100%',
5161
- height: 24,
5162
- background: value
5163
- }) }));
5272
+ onValueChange(undefined);
5164
5273
  }
5165
- return (React__namespace.createElement(Tr, { key: key },
5166
- React__namespace.createElement(Td, { align: "left" }, key),
5167
- React__namespace.createElement(Td, { align: "left" },
5168
- React__namespace.createElement("div", { className: css.css({
5169
- display: 'flex',
5170
- alignItems: 'center',
5171
- gap: '1rem'
5172
- }) },
5173
- React__namespace.createElement("span", { className: css.css({ flexShrink: 1 }) }, value),
5174
- " ",
5175
- colorBox))));
5176
- }))));
5177
- };
5178
- const flatten = (obj, parent, path = 'theme') => {
5179
- const flatObj = parent !== null && parent !== void 0 ? parent : {};
5180
- for (const prop in obj) {
5181
- const value = obj[prop];
5182
- const fullPath = `${path}.${prop}`;
5183
- if (typeof value !== 'object') {
5184
- flatObj[fullPath] = value;
5185
5274
  }
5186
- else {
5187
- flatten(value, flatObj, fullPath);
5275
+ updateErrorMessage();
5276
+ }, [localValue]);
5277
+ useIgnoreMount(() => {
5278
+ if (allowUpdateOnFocus || document.activeElement !== inputRef.current) {
5279
+ setLocalValue(props.value);
5188
5280
  }
5281
+ updateErrorMessage();
5282
+ }, [props.value]);
5283
+ const styles = css.css({
5284
+ backgroundColor: theme.colors.bg,
5285
+ maxWidth: '100%',
5286
+ minHeight: theme.controls.height,
5287
+ fontFamily: theme.fonts.family,
5288
+ fontSize: theme.fonts.size,
5289
+ width: '100%',
5290
+ border: theme.controls.border,
5291
+ borderRadius: theme.controls.borderRadius,
5292
+ color: theme.colors.font,
5293
+ paddingTop: '0.75rem',
5294
+ paddingLeft: theme.controls.padding,
5295
+ paddingRight: theme.controls.padding,
5296
+ height: 'auto',
5297
+ transition: theme.controls.transition,
5298
+ ':focus': {
5299
+ outline: 'none',
5300
+ boxShadow: theme.controls.focusOutlineShadow
5301
+ },
5302
+ ':disabled': {
5303
+ backgroundColor: theme.colors.disabled,
5304
+ cursor: 'not-allowed'
5305
+ },
5306
+ ':invalid': {
5307
+ borderColor: theme.colors.required,
5308
+ ':focus': {
5309
+ boxShadow: theme.controls.focusOutlineRequiredShadow
5310
+ }
5311
+ },
5312
+ }, props.readOnly && {
5313
+ backgroundColor: 'transparent',
5314
+ cursor: 'default',
5315
+ border: 'none',
5316
+ ':focus': {
5317
+ outline: 'none',
5318
+ boxShadow: 'none'
5319
+ }
5320
+ });
5321
+ return (React__namespace.createElement("span", { className: css.css({
5322
+ display: 'inline-block',
5323
+ width: '100%'
5324
+ }) },
5325
+ React__namespace.createElement("textarea", Object.assign({}, nativeProps, { className: css.cx(styles, props.className), autoComplete: (_a = props.autoComplete) !== null && _a !== void 0 ? _a : 'off', tabIndex: props.readOnly ? -1 : props.tabIndex, maxLength: props.maxLength || defaultMaxLength, rows: (_b = props.rows) !== null && _b !== void 0 ? _b : defaultRows, ref: inputRef, value: localValue !== null && localValue !== void 0 ? localValue : '', onChange: e => {
5326
+ var _a;
5327
+ setLocalValue(e.target.value || undefined);
5328
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, e);
5329
+ }, onBlur: e => {
5330
+ var _a;
5331
+ if (!props.noTrim) {
5332
+ setLocalValue(currentValue => {
5333
+ return currentValue === null || currentValue === void 0 ? void 0 : currentValue.trim();
5334
+ });
5335
+ }
5336
+ (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, e);
5337
+ } })),
5338
+ (showErrorDisplay !== null && showErrorDisplay !== void 0 ? showErrorDisplay : true) && React__namespace.createElement(InputErrorDisplay, { error: validationError })));
5339
+ });
5340
+
5341
+ const ToggleButton = React__namespace.forwardRef((props, ref) => {
5342
+ const { checked, checkedChildren, uncheckedChildren, checkedVariant, checkedClassName, checkedStyle, checkedIcon, uncheckedIcon } = props, buttonProps = __rest(props, ["checked", "checkedChildren", "uncheckedChildren", "checkedVariant", "checkedClassName", "checkedStyle", "checkedIcon", "uncheckedIcon"]);
5343
+ let children;
5344
+ if (checked) {
5345
+ children = checkedChildren;
5189
5346
  }
5190
- return flatObj;
5347
+ else {
5348
+ children = uncheckedChildren;
5349
+ }
5350
+ return (React__namespace.createElement(Button, Object.assign({}, buttonProps, { ref: ref, className: css.cx('toggleButton', checked && 'toggleButton--checked', props.className, checked && checkedClassName), rightIcon: checked ? checkedIcon : uncheckedIcon, variant: checked ? checkedVariant : props.variant, style: checked ? checkedStyle : props.style }), children));
5351
+ });
5352
+
5353
+ const ToggleButtonGroup = (props) => {
5354
+ const theme = useThemeSafely();
5355
+ const groupStyles = css.css `
5356
+ display: flex;
5357
+ box-shadow: ${theme.controls.buttonBoxShadow};
5358
+ border-radius: ${theme.controls.borderRadius};
5359
+ ${props.round && `
5360
+ border-radius: ${theme.controls.roundRadius};
5361
+ `}
5362
+ `;
5363
+ const buttonStyles = css.css `
5364
+ flex-grow:1;
5365
+ box-shadow: none;
5366
+ &:nth-of-type(1n+2){
5367
+ margin-left: -1px;
5368
+ }
5369
+ border-radius: 0;
5370
+ &:first-of-type{
5371
+ border-top-left-radius: ${theme.controls.borderRadius};
5372
+ border-bottom-left-radius: ${theme.controls.borderRadius};
5373
+ }
5374
+ &:last-child {
5375
+ border-top-right-radius: ${theme.controls.borderRadius};
5376
+ border-bottom-right-radius: ${theme.controls.borderRadius};
5377
+ }
5378
+ ${props.round && `
5379
+ &:first-of-type{
5380
+ border-top-left-radius: ${theme.controls.roundRadius};
5381
+ border-bottom-left-radius: ${theme.controls.roundRadius};
5382
+ padding-left: 1rem;
5383
+ }
5384
+ &:last-child {
5385
+ border-top-right-radius: ${theme.controls.roundRadius};
5386
+ border-bottom-right-radius: ${theme.controls.roundRadius};
5387
+ padding-right: 1rem;
5388
+ }
5389
+ `}
5390
+ `;
5391
+ return (React__namespace.createElement("div", { className: css.cx('toggleButtonGroup', groupStyles, props.className) }, props.options.map(o => {
5392
+ const active = o.id === props.value;
5393
+ return React__namespace.createElement(Button, { style: props.width ? { width: props.width } : undefined, small: props.small, rightIcon: o.rightIcon, key: o.id, tabIndex: active ? -1 : 0, className: css.cx(css.css `
5394
+ ${buttonStyles}
5395
+ ${active && `
5396
+ background-color: ${theme.colors.font};
5397
+ color: ${theme.colors.bg};
5398
+ cursor: default;
5399
+ &:hover:not(:disabled) {
5400
+ filter: none;
5401
+ }
5402
+ &:focus {
5403
+ outline: none;
5404
+ box-shadow: none;
5405
+ }
5406
+ `}
5407
+ `, active ? o.activeClass : undefined), disabled: props.disabled, enforceMinWidth: props.enforceMinWidth, onClick: () => {
5408
+ if (active) {
5409
+ return;
5410
+ }
5411
+ props.onChange(o.id);
5412
+ } }, o.name);
5413
+ })));
5191
5414
  };
5192
5415
 
5193
- const TabContainer = (p) => {
5194
- var _a;
5195
- const [tabIndex, setTabIndex] = React__namespace.useState((_a = p.startingIndex) !== null && _a !== void 0 ? _a : 0);
5196
- const theme = useThemeSafely();
5197
- const tabPanelId = `${p.id}_tabpanel`;
5198
- const tabHeaderId = `${p.id}_TabHeader`;
5199
- return (React__namespace.createElement("div", { className: css.css({
5200
- label: 'TabContainer'
5201
- }) },
5202
- React__namespace.createElement(TabHeader, { id: tabHeaderId, ariaControlsId: tabPanelId, ariaLabel: p.ariaLabel, tabs: p.tabs, maxTabWidth: p.maxTabWidth, variant: p.variant, containerClassName: p.tabHeaderClassName, tabClassName: p.tabClassName, tabHeaderDividerClassName: p.tabHeaderDividerClassName, startingIndex: tabIndex, onBeforeTabChanged: p.onBeforeTabChanged, onTabChanged: (newIndex) => {
5203
- var _a;
5204
- setTabIndex(newIndex);
5205
- (_a = p.onTabChanged) === null || _a === void 0 ? void 0 : _a.call(p, newIndex);
5206
- } }),
5207
- React__namespace.createElement("div", { role: 'tabpanel', id: tabPanelId, "aria-labelledby": getTabHeaderTabId(tabHeaderId, tabIndex), className: css.cx(css.css({
5208
- label: 'TabContainerContent',
5209
- padding: '1rem',
5210
- borderLeft: theme.controls.border,
5211
- borderRight: theme.controls.border,
5212
- borderBottom: theme.controls.border,
5213
- }), p.contentClassName) }, p.tabs[tabIndex].getContent())));
5214
- };
5416
+ const TogglePasswordInput = React__namespace.forwardRef((props, ref) => {
5417
+ const { onVisibilityChanged } = props, inputProps = __rest(props, ["onVisibilityChanged"]);
5418
+ const [show, setShow] = React__namespace.useState(false);
5419
+ useIgnoreMount(() => {
5420
+ onVisibilityChanged === null || onVisibilityChanged === void 0 ? void 0 : onVisibilityChanged(show);
5421
+ }, [show]);
5422
+ return (React__namespace.createElement(TextInput, Object.assign({}, inputProps, { ref: ref, type: show ? 'text' : 'password', rightControl: (React__namespace.createElement(Button, { small: true, style: {
5423
+ // small button is required here due to the icon pushing outside the boundries of the
5424
+ // parent textbox. increasing the font size here to fill the small button.
5425
+ fontSize: '1rem'
5426
+ }, variant: "icon", onClick: () => {
5427
+ setShow(previous => !previous);
5428
+ } },
5429
+ React__namespace.createElement(Icon, { id: show ? 'show' : 'hide' }))) })));
5430
+ });
5215
5431
 
5216
- const defaultMinChars = 3;
5217
- class AutocompleteController {
5218
- constructor(getOptions, config) {
5219
- var _a;
5220
- this._value = undefined;
5221
- this._options = [];
5222
- this._minChars = (_a = config === null || config === void 0 ? void 0 : config.minChars) !== null && _a !== void 0 ? _a : defaultMinChars;
5223
- if (config === null || config === void 0 ? void 0 : config.debounceMs) {
5224
- this.getOptions = createDebouncedPromise(getOptions, config === null || config === void 0 ? void 0 : config.debounceMs);
5225
- }
5226
- else {
5227
- this.getOptions = getOptions;
5228
- }
5229
- }
5230
- get value() {
5231
- return this._value;
5232
- }
5233
- get options() {
5234
- return this._options;
5235
- }
5236
- async onChange(newValue) {
5237
- // don't make getOptions calls if the value hasn't changed.
5238
- if (newValue === this.value) {
5239
- return;
5240
- }
5241
- // nullish should not make the getOptions call and instead clear everything.
5242
- if (!newValue) {
5243
- this._value = newValue;
5244
- this._options = [];
5245
- return;
5246
- }
5247
- // sub min chars should clear everything and not attempt the getOptions call.
5248
- if (newValue.length < this._minChars) {
5249
- this._value = newValue;
5250
- this._options = [];
5251
- return;
5252
- }
5253
- try {
5254
- this._value = newValue;
5255
- this._options = (await this.getOptions(newValue));
5256
- }
5257
- catch (err) {
5258
- // this method will throw errors on debounce rejections. that is to be expected.
5259
- // for actual getOptions exceptions, the owner of that function will need to handle errors.
5260
- }
5261
- }
5262
- onPick(newValue) {
5263
- this._value = newValue;
5264
- this._options = [];
5432
+ const WaitingIndicator = (p) => {
5433
+ var _a, _b, _c;
5434
+ const [show, setShow] = React.useState(p.show);
5435
+ const hideTimer = React.useRef(0);
5436
+ const lastShowStatus = React.useRef(false);
5437
+ const log = useLogger(`WaitingIndicator ${(_a = p.id) !== null && _a !== void 0 ? _a : '?'}`, (_b = p.__debug) !== null && _b !== void 0 ? _b : false);
5438
+ const { notify, clearNotification } = useAriaLiveRegion();
5439
+ if (p.__debug) {
5440
+ React.useEffect(() => {
5441
+ log('mounted');
5442
+ return () => {
5443
+ log('unmounted');
5444
+ };
5445
+ }, []);
5265
5446
  }
5266
- }
5267
- const createDebouncedPromise = (originalFunction, trailingTimeoutMs) => {
5268
- let timer;
5269
- let onCancel;
5270
- return (value) => {
5271
- if (timer) {
5272
- clearTimeout(timer);
5447
+ React.useEffect(() => {
5448
+ log('show changed', p.show);
5449
+ // we need to store the 'last props' since props.show will be captured locally and the incorrect
5450
+ // value will display in the timeout below.
5451
+ log('storing lastShowStatus', p.show);
5452
+ lastShowStatus.current = p.show;
5453
+ if (p.show) {
5454
+ log('setShow', true);
5455
+ setShow(true);
5456
+ if (p.minShowTimeMs) {
5457
+ log('staring hideTimer', 'timout in ms:', p.minShowTimeMs);
5458
+ hideTimer.current = window.setTimeout(() => {
5459
+ log('hideTimer complete', 'clearing hideTimer');
5460
+ window.clearTimeout(hideTimer.current);
5461
+ hideTimer.current = 0;
5462
+ // this check is necessary since the show status may have updated again to true.
5463
+ // if so, ignore this timeout since we're already past the min time and we're still
5464
+ // showing the component.
5465
+ if (!lastShowStatus.current) {
5466
+ log('setShow', false);
5467
+ setShow(false);
5468
+ }
5469
+ else {
5470
+ log('ignoring hideTimer handler due to hideTimer ticking');
5471
+ }
5472
+ }, p.minShowTimeMs);
5473
+ }
5273
5474
  }
5274
- if (onCancel) {
5275
- onCancel('Promise cancelled due to in-progress debounce call.');
5276
- onCancel = undefined;
5475
+ else {
5476
+ // ignore hiding the component since the min timer is running.
5477
+ if (!hideTimer.current) {
5478
+ log('setShow', false);
5479
+ setShow(false);
5480
+ }
5481
+ else {
5482
+ log('ignoring show change due to hideTimer ticking');
5483
+ }
5277
5484
  }
5278
- return new Promise((res, rej) => {
5279
- onCancel = rej;
5280
- timer = setTimeout(() => {
5281
- originalFunction(value)
5282
- .then(values => {
5283
- res(values);
5284
- })
5285
- .catch(err => {
5286
- rej(err);
5287
- })
5288
- .finally(() => {
5289
- clearTimeout(timer);
5290
- });
5291
- }, trailingTimeoutMs);
5292
- });
5293
- };
5294
- };
5295
-
5296
- /** Extracted logic around autocomplete functionality for Autocomplete.tsx that supports Entity (id/name) mapping. */
5297
- class AutocompleteEntityController {
5298
- constructor(getOptions, config) {
5299
- this._options = [];
5300
- const getStringOptions = async (value) => {
5301
- this._options = await getOptions(value);
5302
- return this._options.map(o => o.name);
5303
- };
5304
- this._ctrl = new AutocompleteController(getStringOptions, config);
5305
- }
5306
- get entity() {
5307
- return this._pickedEntity;
5308
- }
5309
- get entities() {
5310
- return this._options;
5311
- }
5312
- get value() {
5313
- return this._ctrl.value;
5314
- }
5315
- get options() {
5316
- return this._options.map(o => o.name);
5317
- }
5318
- async onChange(newValue) {
5319
- const clearEntity = newValue !== this._ctrl.value;
5320
- await this._ctrl.onChange(newValue);
5321
- if (clearEntity) {
5322
- this._pickedEntity = undefined;
5485
+ if (p.show) {
5486
+ // set to a very long time so the hiding of the waiting indicator clears it.
5487
+ notify('Loading content.', 60000);
5323
5488
  }
5324
- this.trySyncCtrlOptions();
5325
- }
5326
- onPick(newValue) {
5327
- this._ctrl.onPick(newValue);
5328
- this._pickedEntity = this._options.find(o => o.name === this._ctrl.value);
5329
- this.trySyncCtrlOptions();
5330
- }
5331
- trySyncCtrlOptions() {
5332
- if (!this._ctrl.options.length) {
5333
- this._options = [];
5489
+ else {
5490
+ clearNotification();
5334
5491
  }
5335
- }
5336
- }
5337
-
5338
- var decimal=["decimal","décimale"];var place=["lugar","lieu"];var places=["lugares","lieux"];var file=["archivo","fichier"];var selected=["seleccionado","choisi"];var Upload=["Subir","Télécharger"];var Clear=["Cerrar","Fermer"];var Showing=["Mostrando","Affichage de"];var of=["de","sur"];var results=["resultados","résultats"];var Page=["Página","Page"];var Limit=["Límite","Limite"];var Sort=["Ordenar","Trier"];var January=["Enero","Janvier"];var February=["Febrero","Février"];var March=["Marzo","Mars"];var April=["Abril","Avril"];var May=["Mayo","Mai"];var June=["Junio","Juin"];var July=["Julio","Juillet"];var August=["Agosto","Août"];var September=["Septiembre","Septembre"];var October=["Octubre","Octobre"];var November=["Noviembre","Novembre"];var December=["Diciembre","Décembre"];var Sun=["Dom","Dim"];var Mon=["Lun","Lun"];var Tue=["Mar","Mar"];var Wed=["Mié","Mer"];var Thu=["Jue","Jeu"];var Fri=["Vie","Ven"];var Sat=["Sáb","Sam"];var OK=["Aceptar","Accepter"];var Cancel=["Cancelar","Annuler"];var strings = {"Required.":["Requerido.","Requis."],"Must be at least":["Debe ser al menos","Doit être au moins"],"characters in length.":["caracteres de longitud.","caractères de longueur."],"Must be an integer.":["Debe ser un número entero.","Doit être un entier."],"Limited to":["Limitado a","Limité à"],decimal:decimal,place:place,places:places,"Must be greater than or equal to":["Debe ser mayor o igual a","Doit être supérieur ou égal à"],"Must be less than or equal to":["Debe ser menor o igual a","Doit être inférieur ou égal à"],"Invalid email.":["Correo electrónico no válido.","Email invalide."],"Invalid URL.":["URL no válida.","URL non valide."],"Click or drag and drop files.":["Haga clic o arrastre y suelte archivos.","Cliquez ou faites glisser et déposez les fichiers."],file:file,selected:selected,"Upload failed.":["Error en la carga.","Le téléchargement a échoué."],Upload:Upload,"Upload successful.":["Carga exitosa","Téléchargement réussi."],"Invalid files":["Archivos no válidos","Fichiers invalides"],"Max file size exceeded":["Se ha excedido el tamaño máximo de archivo","La taille maximale du fichier a été dépassée"],"Error":["Error","Erreur"],Clear:Clear,Showing:Showing,of:of,results:results,"No Results":["No Hay Resultados","Aucun Résultat"],Page:Page,Limit:Limit,Sort:Sort,January:January,February:February,March:March,April:April,May:May,June:June,July:July,August:August,September:September,October:October,November:November,December:December,Sun:Sun,Mon:Mon,Tue:Tue,Wed:Wed,Thu:Thu,Fri:Fri,Sat:Sat,OK:OK,Cancel:Cancel,"Copied!":["¡Copiado!","Copié!"],"Copy to clipboard":["Copiar al portapapeles","Copier dans le presse-papier"]};
5339
-
5340
- const LocalizationProvider = (p) => {
5341
- var _a;
5342
- const log = useLogger('LocalizationProvider', (_a = p.__debug) !== null && _a !== void 0 ? _a : false);
5343
- const stringsDb = strings;
5344
- return (React.createElement(LocalizationContext.Provider, { value: {
5345
- language: p.language,
5346
- getText: (text) => {
5347
- if (!text) {
5348
- return '';
5349
- }
5350
- if (!isNaN(parseInt(text))) {
5351
- return text;
5352
- }
5353
- const wordArray = stringsDb[text];
5354
- if (!wordArray) {
5355
- log(`No localization data exists for "${text}".`);
5356
- }
5357
- if (p.language === exports.StyleGuideLanguage.English) {
5358
- return text;
5359
- }
5360
- const languageIndex = p.language - 1;
5361
- const translation = wordArray === null || wordArray === void 0 ? void 0 : wordArray[languageIndex];
5362
- if (translation) {
5363
- return translation;
5364
- }
5365
- log(`No ${exports.StyleGuideLanguage[p.language]} translations exist for "${text}".`);
5366
- return text;
5367
- }
5368
- } }, p.children));
5492
+ }, [p.show]);
5493
+ const id = (_c = p.id) !== null && _c !== void 0 ? _c : 'MknWaitingIndicator';
5494
+ return (React.createElement(Modal, { id: id, __debug: p.__debug, __asWaitingIndicator: true, heading: '', onClose: () => {
5495
+ /* noop */
5496
+ }, className: "waitingIndicator", show: show },
5497
+ React.createElement("div", { className: css.css({
5498
+ color: 'white',
5499
+ fontSize: '3rem',
5500
+ padding: '0.7rem'
5501
+ }) },
5502
+ React.createElement(Icon, { id: "waiting", spin: true }))));
5369
5503
  };
5370
5504
 
5371
5505
  exports.Accordion = Accordion;
@@ -5404,6 +5538,7 @@ exports.List = List;
5404
5538
  exports.ListItem = ListItem;
5405
5539
  exports.LocalizationProvider = LocalizationProvider;
5406
5540
  exports.Modal = Modal;
5541
+ exports.MultiPicker = MultiPicker;
5407
5542
  exports.Nav = Nav;
5408
5543
  exports.NormalizeCss = NormalizeCss;
5409
5544
  exports.NumberInput = NumberInput;