@homebound/beam 2.175.2 → 2.177.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,6 +54,12 @@ const ourReset = (0, react_1.css) `
54
54
  transform: rotate(360deg);
55
55
  }
56
56
  }
57
+
58
+ @keyframes pulse {
59
+ 50% {
60
+ opacity: 0.6;
61
+ }
62
+ }
57
63
  `;
58
64
  // Copy/pasted from TW which uses this as their base reset.
59
65
  const modernNormalizeReset = (0, react_1.css) `
@@ -0,0 +1,10 @@
1
+ declare type Sizes = "sm" | "md" | "lg";
2
+ export declare type LoadingSkeletonProps = {
3
+ rows?: number;
4
+ columns?: number;
5
+ size?: Sizes;
6
+ randomizeWidths?: boolean;
7
+ contrast?: boolean;
8
+ };
9
+ export declare function LoadingSkeleton({ rows, columns, size, randomizeWidths, contrast, }: LoadingSkeletonProps): import("@emotion/react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoadingSkeleton = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const Css_1 = require("../Css");
6
+ function LoadingSkeleton({ rows = 1, columns = 1, size = "md", randomizeWidths = false, contrast = false, }) {
7
+ const cellArray = [...Array(columns)];
8
+ const rowArray = [...Array(rows)];
9
+ const rowHeight = sizeToPixels[size];
10
+ const rowCells = (rowNumber) => {
11
+ const flexGrowForCell = randomizeWidths ? getRandomizedFlexBasisByRowIndex(rowNumber) : 1;
12
+ return cellArray.map((_, i) => ((0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.br4
13
+ .add("animation", "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite")
14
+ .add("flexGrow", flexGrowForCell)
15
+ .bgGray300.if(contrast).bgGray700.$ }, `row-${rowNumber}-cell-${i}`)));
16
+ };
17
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({ "aria-label": "Loading" }, { children: rowArray.map((_, i) => ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.df.childGap1.mb1.hPx(rowHeight).$ }, { children: rowCells(i) }), `row-${i}`))) }), void 0));
18
+ }
19
+ exports.LoadingSkeleton = LoadingSkeleton;
20
+ /** Create the illusion of random widths by cycling through a list of widths that look nice in order */
21
+ function getRandomizedFlexBasisByRowIndex(rowIndex) {
22
+ const randomizedFlexBasisValues = [0.65, 0.8, 0.75, 0.9, 0.8, 0.85, 0.8, 0.95];
23
+ const valueIndex = rowIndex % randomizedFlexBasisValues.length;
24
+ return randomizedFlexBasisValues[valueIndex];
25
+ }
26
+ const sizeToPixels = {
27
+ sm: 16,
28
+ md: 24,
29
+ lg: 32,
30
+ };
@@ -17,6 +17,7 @@ export * from "./Icon";
17
17
  export * from "./IconButton";
18
18
  export * from "./Layout";
19
19
  export * from "./Loader";
20
+ export * from "./LoadingSkeleton";
20
21
  export * from "./Modal";
21
22
  export * from "./Modal/useModal";
22
23
  export { NavLink } from "./NavLink";
@@ -31,6 +31,7 @@ __exportStar(require("./Icon"), exports);
31
31
  __exportStar(require("./IconButton"), exports);
32
32
  __exportStar(require("./Layout"), exports);
33
33
  __exportStar(require("./Loader"), exports);
34
+ __exportStar(require("./LoadingSkeleton"), exports);
34
35
  __exportStar(require("./Modal"), exports);
35
36
  __exportStar(require("./Modal/useModal"), exports);
36
37
  var NavLink_1 = require("./NavLink");
@@ -8,38 +8,38 @@ const defaultTestId_1 = require("../utils/defaultTestId");
8
8
  function MultiSelectField(props) {
9
9
  const { getOptionValue = (o) => o.id, // if unset, assume O implements HasId
10
10
  getOptionLabel = (o) => o.name, // if unset, assume O implements HasName
11
- values, options, onSelect, readOnly = false, errorMsg, onFocus, onBlur, disabled, label, } = props;
11
+ values, options, onSelect, readOnly = false, errorMsg, onFocus, onBlur, disabled, label, disabledOptions = [], helperText, } = props;
12
12
  const tid = (0, utils_1.useTestIds)(props, (0, defaultTestId_1.defaultTestId)(label));
13
- return ((0, jsx_runtime_1.jsxs)("select", Object.assign({}, tid, {
14
- // We're cheating and assume the values are strings...what we should really do is either:
15
- // a) use beam's valueToKey mapping to string-encode any Value, or
16
- // b) instead of using `values` directly, use the index of each value's `option` in `options`
17
- value: values, onChange: (e) => {
18
- var _a, _b, _c;
19
- const { target } = e;
20
- const selectedValues = [...values];
21
- for (let i = 0; i < target.selectedOptions.length; i++) {
22
- if (selectedValues.includes((_a = target.selectedOptions.item(i)) === null || _a === void 0 ? void 0 : _a.value)) {
23
- // deSelect if already selected
24
- selectedValues.splice(selectedValues.indexOf((_b = target.selectedOptions.item(i)) === null || _b === void 0 ? void 0 : _b.value), 1);
25
- }
26
- else {
27
- // add value
28
- selectedValues.push((_c = target.selectedOptions.item(i)) === null || _c === void 0 ? void 0 : _c.value);
29
- }
30
- }
31
- const selectedOptions = options.filter((o) => selectedValues.includes(getOptionValue(o)));
32
- onSelect(selectedOptions.map((o) => getOptionValue(o)), selectedOptions);
33
- }, multiple: true, onFocus: () => {
34
- if (!readOnly && onFocus)
35
- onFocus();
36
- }, onBlur: () => {
37
- if (!readOnly && onBlur)
38
- onBlur();
39
- },
40
- // Read Only does not apply to `select` fields, instead we'll add in disabled for tests to verify.
41
- disabled: !!(readOnly || disabled), "data-error": !!errorMsg, "data-errormsg": errorMsg, "data-readonly": readOnly }, { children: [(0, jsx_runtime_1.jsx)("option", { disabled: true, value: "" }, void 0), options.map((option, i) => {
42
- return ((0, jsx_runtime_1.jsx)("option", Object.assign({ value: getOptionValue(option) }, { children: getOptionLabel(option) }), i));
43
- })] }), void 0));
13
+ return ((0, jsx_runtime_1.jsxs)("label", Object.assign({}, tid.label, { children: [label, (0, jsx_runtime_1.jsxs)("select", Object.assign({}, tid, {
14
+ // We're cheating and assume the values are strings...what we should really do is either:
15
+ // a) use beam's valueToKey mapping to string-encode any Value, or
16
+ // b) instead of using `values` directly, use the index of each value's `option` in `options`
17
+ value: values, onChange: (e) => {
18
+ var _a, _b, _c;
19
+ const { target } = e;
20
+ const selectedValues = [...values];
21
+ for (let i = 0; i < target.selectedOptions.length; i++) {
22
+ if (selectedValues.includes((_a = target.selectedOptions.item(i)) === null || _a === void 0 ? void 0 : _a.value)) {
23
+ // deSelect if already selected
24
+ selectedValues.splice(selectedValues.indexOf((_b = target.selectedOptions.item(i)) === null || _b === void 0 ? void 0 : _b.value), 1);
25
+ }
26
+ else {
27
+ // add value
28
+ selectedValues.push((_c = target.selectedOptions.item(i)) === null || _c === void 0 ? void 0 : _c.value);
29
+ }
30
+ }
31
+ const selectedOptions = options.filter((o) => selectedValues.includes(getOptionValue(o)));
32
+ onSelect(selectedOptions.map((o) => getOptionValue(o)), selectedOptions);
33
+ }, multiple: true, onFocus: () => {
34
+ if (!readOnly && onFocus)
35
+ onFocus();
36
+ }, onBlur: () => {
37
+ if (!readOnly && onBlur)
38
+ onBlur();
39
+ },
40
+ // Read Only does not apply to `select` fields, instead we'll add in disabled for tests to verify.
41
+ disabled: !!(readOnly || disabled), "data-error": !!errorMsg, "data-errormsg": errorMsg, "data-readonly": readOnly }, { children: [(0, jsx_runtime_1.jsx)("option", { disabled: true, value: "" }, void 0), options.map((option, i) => {
42
+ return ((0, jsx_runtime_1.jsx)("option", Object.assign({ value: getOptionValue(option), disabled: disabledOptions.includes(getOptionValue(option)) }, { children: getOptionLabel(option) }), i));
43
+ })] }), void 0), helperText && (0, jsx_runtime_1.jsx)("div", Object.assign({}, tid.helperText, { children: helperText }), void 0)] }), void 0));
44
44
  }
45
45
  exports.MultiSelectField = MultiSelectField;
@@ -9,7 +9,7 @@ const defaultTestId_1 = require("../utils/defaultTestId");
9
9
  function SelectField(props) {
10
10
  const { getOptionValue = (o) => o.id, // if unset, assume O implements HasId
11
11
  getOptionLabel = (o) => o.name, // if unset, assume O implements HasName
12
- value, options: maybeOptions, onSelect, readOnly = false, errorMsg, onBlur, onFocus, disabled, disabledOptions = [], label, } = props;
12
+ value, options: maybeOptions, onSelect, readOnly = false, errorMsg, onBlur, onFocus, disabled, disabledOptions = [], label, helperText, } = props;
13
13
  const tid = (0, utils_1.useTestIds)(props, (0, defaultTestId_1.defaultTestId)(label));
14
14
  const [options, setOptions] = (0, react_1.useState)(Array.isArray(maybeOptions) ? maybeOptions : maybeOptions.initial);
15
15
  const currentOption = options.find((o) => getOptionValue(o) === value) || options[0];
@@ -18,25 +18,25 @@ function SelectField(props) {
18
18
  setOptions(maybeOptions);
19
19
  }
20
20
  }, [maybeOptions]);
21
- return ((0, jsx_runtime_1.jsxs)("select", Object.assign({}, tid, { value:
22
- // @ts-ignore - allow `value` to be seen as a string
23
- value !== undefined && value !== "" && currentOption ? getOptionValue(currentOption) : "", onChange: (e) => {
24
- const option = options.find((o) => `${getOptionValue(o)}` === e.target.value) || options[0];
25
- onSelect(getOptionValue(option), option);
26
- }, onFocus: async () => {
27
- if (!Array.isArray(maybeOptions)) {
28
- const result = await maybeOptions.load();
29
- setOptions(result.options);
30
- }
31
- if (!readOnly && onFocus)
32
- onFocus();
33
- }, onBlur: () => {
34
- if (!readOnly && onBlur)
35
- onBlur();
36
- },
37
- // Read Only does not apply to `select` fields, instead we'll add in disabled for tests to verify.
38
- disabled: !!(disabled || readOnly), "data-error": !!errorMsg, "data-errormsg": errorMsg, "data-readonly": readOnly }, { children: [(0, jsx_runtime_1.jsx)("option", { disabled: true, value: "" }, void 0), options.map((option, i) => {
39
- return ((0, jsx_runtime_1.jsx)("option", Object.assign({ value: `${getOptionValue(option)}`, disabled: disabledOptions.includes(getOptionValue(option)) }, { children: getOptionLabel(option) }), i));
40
- })] }), void 0));
21
+ return ((0, jsx_runtime_1.jsxs)("label", Object.assign({}, tid.label, { children: [label, (0, jsx_runtime_1.jsxs)("select", Object.assign({}, tid, { value:
22
+ // @ts-ignore - allow `value` to be seen as a string
23
+ value !== undefined && value !== "" && currentOption ? getOptionValue(currentOption) : "", onChange: (e) => {
24
+ const option = options.find((o) => `${getOptionValue(o)}` === e.target.value) || options[0];
25
+ onSelect(getOptionValue(option), option);
26
+ }, onFocus: async () => {
27
+ if (!Array.isArray(maybeOptions)) {
28
+ const result = await maybeOptions.load();
29
+ setOptions(result.options);
30
+ }
31
+ if (!readOnly && onFocus)
32
+ onFocus();
33
+ }, onBlur: () => {
34
+ if (!readOnly && onBlur)
35
+ onBlur();
36
+ },
37
+ // Read Only does not apply to `select` fields, instead we'll add in disabled for tests to verify.
38
+ disabled: !!(disabled || readOnly), "data-error": !!errorMsg, "data-errormsg": errorMsg, "data-readonly": readOnly }, { children: [(0, jsx_runtime_1.jsx)("option", { disabled: true, value: "" }, void 0), options.map((option, i) => {
39
+ return ((0, jsx_runtime_1.jsx)("option", Object.assign({ value: `${getOptionValue(option)}`, disabled: disabledOptions.includes(getOptionValue(option)) }, { children: getOptionLabel(option) }), i));
40
+ })] }), void 0), helperText && (0, jsx_runtime_1.jsx)("div", Object.assign({}, tid.helperText, { children: helperText }), void 0)] }), void 0));
41
41
  }
42
42
  exports.SelectField = SelectField;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.175.2",
3
+ "version": "2.177.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",