@homebound/beam 2.322.0 → 2.324.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.
@@ -0,0 +1,12 @@
1
+ import { FieldState } from "@homebound/form-state";
2
+ import { IconCardProps } from "../inputs";
3
+ import { IconProps } from "../components";
4
+ export type BoundIconCardFieldProps = Omit<IconCardProps, "label" | "selected" | "onChange"> & {
5
+ field: FieldState<boolean | null | undefined>;
6
+ icon: IconProps["icon"];
7
+ /** Make optional so that callers can override if they want to. */
8
+ onChange?: (values: boolean) => void;
9
+ label?: string;
10
+ };
11
+ /** Wraps `IconCard` and binds it to a form field. */
12
+ export declare function BoundIconCardField(props: BoundIconCardFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BoundIconCardField = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const inputs_1 = require("../inputs");
6
+ const defaultLabel_1 = require("../utils/defaultLabel");
7
+ const utils_1 = require("../utils");
8
+ const mobx_react_1 = require("mobx-react");
9
+ /** Wraps `IconCard` and binds it to a form field. */
10
+ function BoundIconCardField(props) {
11
+ const { icon, field, onChange = (value) => field.set(value), label = (0, defaultLabel_1.defaultLabel)(field.key), ...others } = props;
12
+ const testId = (0, utils_1.useTestIds)(props, field.key);
13
+ return ((0, jsx_runtime_1.jsx)(mobx_react_1.Observer, { children: () => {
14
+ var _a;
15
+ return ((0, jsx_runtime_1.jsx)(inputs_1.IconCard, { icon: icon, label: label, selected: (_a = field.value) !== null && _a !== void 0 ? _a : false, onChange: (selected) => {
16
+ // We are triggering blur manually for checkbox fields due to its transactional nature
17
+ onChange(selected);
18
+ field.maybeAutoSave();
19
+ }, disabled: field.readOnly, ...testId, ...others }));
20
+ } }));
21
+ }
22
+ exports.BoundIconCardField = BoundIconCardField;
@@ -0,0 +1,10 @@
1
+ import { FieldState } from "@homebound/form-state";
2
+ import { IconCardGroupProps } from "../inputs/IconCardGroup";
3
+ export type BoundIconCardGroupFieldProps = Omit<IconCardGroupProps, "label" | "values" | "onChange"> & {
4
+ field: FieldState<string[] | null | undefined>;
5
+ /** Make optional so that callers can override if they want to. */
6
+ onChange?: (values: string[]) => void;
7
+ label?: string;
8
+ };
9
+ /** Wraps `IconCardGroup` and binds it to a form field. */
10
+ export declare function BoundIconCardGroupField(props: BoundIconCardGroupFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BoundIconCardGroupField = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const mobx_react_1 = require("mobx-react");
6
+ const IconCardGroup_1 = require("../inputs/IconCardGroup");
7
+ const utils_1 = require("../utils");
8
+ const defaultLabel_1 = require("../utils/defaultLabel");
9
+ /** Wraps `IconCardGroup` and binds it to a form field. */
10
+ function BoundIconCardGroupField(props) {
11
+ const { field, onChange = (value) => field.set(value), label = (0, defaultLabel_1.defaultLabel)(field.key), ...others } = props;
12
+ const testId = (0, utils_1.useTestIds)(props, field.key);
13
+ return ((0, jsx_runtime_1.jsx)(mobx_react_1.Observer, { children: () => ((0, jsx_runtime_1.jsx)(IconCardGroup_1.IconCardGroup, { label: label, values: field.value || [], onChange: (values) => {
14
+ // We are triggering blur manually for checkbox fields due to its transactional nature
15
+ onChange(values);
16
+ field.maybeAutoSave();
17
+ }, disabled: field.readOnly, ...testId, ...others })) }));
18
+ }
19
+ exports.BoundIconCardGroupField = BoundIconCardGroupField;
@@ -15,6 +15,8 @@ export * from "./BoundTextAreaField";
15
15
  export * from "./BoundTextField";
16
16
  export * from "./BoundToggleChipGroupField";
17
17
  export * from "./BoundTreeSelectField";
18
+ export * from "./BoundIconCardField";
19
+ export * from "./BoundIconCardGroupField";
18
20
  export * from "./FormHeading";
19
21
  export * from "./FormLines";
20
22
  export * from "./StaticField";
@@ -31,6 +31,8 @@ __exportStar(require("./BoundTextAreaField"), exports);
31
31
  __exportStar(require("./BoundTextField"), exports);
32
32
  __exportStar(require("./BoundToggleChipGroupField"), exports);
33
33
  __exportStar(require("./BoundTreeSelectField"), exports);
34
+ __exportStar(require("./BoundIconCardField"), exports);
35
+ __exportStar(require("./BoundIconCardGroupField"), exports);
34
36
  __exportStar(require("./FormHeading"), exports);
35
37
  __exportStar(require("./FormLines"), exports);
36
38
  __exportStar(require("./StaticField"), exports);
@@ -0,0 +1,24 @@
1
+ import { RefObject } from "react";
2
+ import { IconProps } from "../components";
3
+ export interface IconCardProps {
4
+ /** The icon to use within the card. */
5
+ icon: IconProps["icon"];
6
+ label: string;
7
+ selected?: boolean;
8
+ /** Handler that is called when the element's selection state changes. */
9
+ onChange?: (selected: boolean) => void;
10
+ cardRef?: RefObject<HTMLInputElement>;
11
+ disabled?: boolean;
12
+ tooltip?: string;
13
+ }
14
+ export declare function IconCard(props: IconCardProps): import("@emotion/react/jsx-runtime").JSX.Element;
15
+ export declare const selectedStyles: {
16
+ borderWidth: import("csstype").Property.BorderWidth<string | 0> | undefined;
17
+ } & {
18
+ borderColor: import("csstype").Property.BorderColor | undefined;
19
+ } & {
20
+ backgroundColor: import("csstype").Property.BackgroundColor | undefined;
21
+ };
22
+ export declare const iconCardStylesHover: {
23
+ backgroundColor: import("csstype").Property.BackgroundColor | undefined;
24
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.iconCardStylesHover = exports.selectedStyles = exports.IconCard = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_aria_1 = require("react-aria");
7
+ const react_stately_1 = require("react-stately");
8
+ const components_1 = require("../components");
9
+ const Css_1 = require("../Css");
10
+ const useGetRef_1 = require("../hooks/useGetRef");
11
+ const utils_1 = require("../utils");
12
+ const defaultTestId_1 = require("../utils/defaultTestId");
13
+ function IconCard(props) {
14
+ const { selected: isSelected = false, disabled: isDisabled = false, icon, cardRef, label, tooltip, ...otherProps } = props;
15
+ const ref = (0, useGetRef_1.useGetRef)(cardRef);
16
+ const ariaProps = { isSelected, isDisabled, ...otherProps };
17
+ const checkboxProps = { ...ariaProps, "aria-label": label };
18
+ const { hoverProps, isHovered } = (0, react_aria_1.useHover)({ isDisabled });
19
+ const toggleState = (0, react_stately_1.useToggleState)(ariaProps);
20
+ const { inputProps } = (0, react_aria_1.useCheckbox)(checkboxProps, toggleState, ref);
21
+ const styles = (0, react_1.useMemo)(() => ({
22
+ ...baseStyles,
23
+ ...(isHovered && exports.iconCardStylesHover),
24
+ ...(isSelected && exports.selectedStyles),
25
+ ...(isDisabled && disabledStyles),
26
+ }), [isDisabled, isHovered, isSelected]);
27
+ const tid = (0, utils_1.useTestIds)(props, (0, defaultTestId_1.defaultTestId)(label));
28
+ return (0, components_1.maybeTooltip)({
29
+ title: (0, components_1.resolveTooltip)(isDisabled, tooltip),
30
+ placement: "top",
31
+ children: ((0, jsx_runtime_1.jsxs)("button", { css: styles, ...hoverProps, onClick: toggleState.toggle, disabled: isDisabled, ...tid, children: [(0, jsx_runtime_1.jsx)(react_aria_1.VisuallyHidden, { children: (0, jsx_runtime_1.jsx)("input", { ref: ref, ...inputProps, ...tid.value }) }), (0, jsx_runtime_1.jsx)(components_1.Icon, { icon: icon, inc: 4, color: isDisabled ? Css_1.Palette.Gray300 : Css_1.Palette.Gray900 }), (0, jsx_runtime_1.jsx)("span", { css: Css_1.Css.xsMd.if(isDisabled).gray300.$, children: label })] })),
32
+ });
33
+ }
34
+ exports.IconCard = IconCard;
35
+ const baseStyles = Css_1.Css.df.fdc.aic.jcc.wPx(130).hPx(114).ba.br8.bGray300.bgWhite.gap("12px").p2.tc.$;
36
+ exports.selectedStyles = Css_1.Css.bw2.bBlue500.bgBlue50.$;
37
+ const disabledStyles = Css_1.Css.bGray200.bgGray50.$;
38
+ exports.iconCardStylesHover = Css_1.Css.bgGray100.$;
@@ -0,0 +1,23 @@
1
+ import { ReactNode } from "react";
2
+ import { IconProps } from "../components/Icon";
3
+ import { PresentationFieldProps } from "../components/PresentationContext";
4
+ export interface IconCardGroupItemOption {
5
+ icon: IconProps["icon"];
6
+ label: string;
7
+ disabled?: boolean;
8
+ /** The value of the IconCardGroup item, stored in value array in state. */
9
+ value: string;
10
+ }
11
+ export interface IconCardGroupProps extends Pick<PresentationFieldProps, "labelStyle"> {
12
+ label: string;
13
+ /** Called when a card is selected */
14
+ onChange: (values: string[]) => void;
15
+ /** Options for the cards contained within the IconCardGroup. */
16
+ options: IconCardGroupItemOption[];
17
+ /** The values currently selected. */
18
+ values: string[];
19
+ errorMsg?: string;
20
+ helperText?: string | ReactNode;
21
+ disabled?: boolean;
22
+ }
23
+ export declare function IconCardGroup(props: IconCardGroupProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IconCardGroup = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const react_aria_1 = require("react-aria");
6
+ const react_stately_1 = require("react-stately");
7
+ const Css_1 = require("../Css");
8
+ const Label_1 = require("../components/Label");
9
+ const PresentationContext_1 = require("../components/PresentationContext");
10
+ const utils_1 = require("../utils");
11
+ const IconCard_1 = require("./IconCard");
12
+ const HelperText_1 = require("../components/HelperText");
13
+ const ErrorMessage_1 = require("./ErrorMessage");
14
+ function IconCardGroup(props) {
15
+ var _a;
16
+ const { fieldProps } = (0, PresentationContext_1.usePresentationContext)();
17
+ const { options, label, labelStyle = (_a = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.labelStyle) !== null && _a !== void 0 ? _a : "above", values, errorMsg, helperText, disabled: isDisabled = false, } = props;
18
+ const state = (0, react_stately_1.useCheckboxGroupState)({ ...props, isDisabled, value: values });
19
+ const { groupProps, labelProps } = (0, react_aria_1.useCheckboxGroup)(props, state);
20
+ const tid = (0, utils_1.useTestIds)(props);
21
+ return ((0, jsx_runtime_1.jsxs)("div", { ...groupProps, ...tid, children: [labelStyle !== "hidden" && ((0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.if(labelStyle === "left").w50.$, children: (0, jsx_runtime_1.jsx)(Label_1.Label, { label: label, ...labelProps, ...tid.label }) })), (0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.df.gap2.add({ flexWrap: "wrap" }).$, children: options.map((option) => {
22
+ const { icon, label, disabled } = option;
23
+ const isSelected = state.isSelected(option.value);
24
+ const isDisabled = disabled || state.isDisabled;
25
+ return ((0, jsx_runtime_1.jsx)(IconCard_1.IconCard, { icon: icon, label: label, selected: isSelected, disabled: isDisabled, onChange: () => state.toggleValue(option.value), ...tid[option.value] }, option.value));
26
+ }) }), errorMsg && (0, jsx_runtime_1.jsx)(ErrorMessage_1.ErrorMessage, { errorMsg: errorMsg, ...tid.errorMsg }), helperText && (0, jsx_runtime_1.jsx)(HelperText_1.HelperText, { helperText: helperText, ...tid.helperText })] }));
27
+ }
28
+ exports.IconCardGroup = IconCardGroup;
@@ -20,6 +20,8 @@ export interface RichTextFieldProps {
20
20
  onFocus?: () => void;
21
21
  /** For rendering formatted text */
22
22
  readOnly?: boolean;
23
+ /** Will set width to: 100% */
24
+ fullWidth?: boolean;
23
25
  }
24
26
  /**
25
27
  * Provides a simple rich text editor based on trix.
@@ -23,7 +23,7 @@ require("trix/dist/trix.css");
23
23
  * We also integrate [tributejs]{@link https://github.com/zurb/tribute} for @ mentions.
24
24
  */
25
25
  function RichTextField(props) {
26
- const { mergeTags, label, value = "", onChange, onBlur = utils_1.noop, onFocus = utils_1.noop, readOnly } = props;
26
+ const { mergeTags, label, value = "", onChange, onBlur = utils_1.noop, onFocus = utils_1.noop, readOnly, fullWidth } = props;
27
27
  // We get a reference to the Editor instance after trix-init fires
28
28
  const [editor, setEditor] = (0, react_2.useState)();
29
29
  const editorElement = (0, react_2.useRef)();
@@ -98,7 +98,7 @@ function RichTextField(props) {
98
98
  }, [value, readOnly, editor]);
99
99
  const { placeholder, autoFocus } = props;
100
100
  if (!readOnly) {
101
- return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.w100.maxw("550px").$, children: [label && (0, jsx_runtime_1.jsx)(Label_1.Label, { labelProps: {}, label: label }), (0, jsx_runtime_1.jsxs)("div", { css: { ...Css_1.Css.br4.bgWhite.$, ...trixCssOverrides }, children: [(0, jsx_runtime_1.jsx)("input", { type: "hidden", id: `input-${id}`, value: value }), (0, react_2.createElement)("trix-editor", {
101
+ return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.w100.if(!fullWidth).maxw("550px").$, children: [label && (0, jsx_runtime_1.jsx)(Label_1.Label, { labelProps: {}, label: label }), (0, jsx_runtime_1.jsxs)("div", { css: { ...Css_1.Css.br4.bgWhite.$, ...trixCssOverrides }, children: [(0, jsx_runtime_1.jsx)("input", { type: "hidden", id: `input-${id}`, value: value }), (0, react_2.createElement)("trix-editor", {
102
102
  id: id,
103
103
  input: `input-${id}`,
104
104
  // Autofocus attribute is case sensitive since this is standard HTML
@@ -107,7 +107,7 @@ function RichTextField(props) {
107
107
  })] }), (0, jsx_runtime_1.jsx)(react_1.Global, { styles: [tributeOverrides] })] }));
108
108
  }
109
109
  else {
110
- return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.w100.maxw("550px").$, children: [label && (0, jsx_runtime_1.jsx)(Label_1.Label, { label: label }), (0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.mh("120px").bgWhite.sm.gray900.bn.p1.br4.bGray300.ba.$, dangerouslySetInnerHTML: { __html: dompurify_1.default.sanitize(value) || placeholder || "" }, "data-readonly": "true" })] }));
110
+ return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.w100.if(!fullWidth).maxw("550px").$, children: [label && (0, jsx_runtime_1.jsx)(Label_1.Label, { label: label }), (0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.mh("120px").bgWhite.sm.gray900.bn.p1.br4.bGray300.ba.$, dangerouslySetInnerHTML: { __html: dompurify_1.default.sanitize(value) || placeholder || "" }, "data-readonly": "true" })] }));
111
111
  }
112
112
  }
113
113
  exports.RichTextField = RichTextField;
@@ -18,4 +18,5 @@ export type { TextFieldApi } from "./TextField";
18
18
  export * from "./ToggleButton";
19
19
  export * from "./ToggleChipGroup";
20
20
  export * from "./TreeSelectField";
21
+ export * from "./IconCard";
21
22
  export type { Value } from "./Value";
@@ -33,3 +33,4 @@ __exportStar(require("./TextField"), exports);
33
33
  __exportStar(require("./ToggleButton"), exports);
34
34
  __exportStar(require("./ToggleChipGroup"), exports);
35
35
  __exportStar(require("./TreeSelectField"), exports);
36
+ __exportStar(require("./IconCard"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.322.0",
3
+ "version": "2.324.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",