@homebound/beam 2.80.0 → 2.80.4

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.
@@ -1,5 +1,6 @@
1
- import { MutableRefObject, ReactNode } from "react";
1
+ import { MutableRefObject, PropsWithChildren } from "react";
2
2
  import { ModalProps } from "./Modal/Modal";
3
+ import { PresentationContextProps } from "./PresentationContext";
3
4
  import { ContentStack } from "./SuperDrawer/useSuperDrawer";
4
5
  import { CanCloseCheck, CheckFn } from "../types";
5
6
  /** The internal state of our Beam context; see useModal and useSuperDrawer for the public APIs. */
@@ -25,7 +26,8 @@ export interface BeamContextState {
25
26
  }
26
27
  /** This is only exported internally, for useModal and useSuperDrawer, it's not a public API. */
27
28
  export declare const BeamContext: import("react").Context<BeamContextState>;
28
- export declare function BeamProvider({ children }: {
29
- children: ReactNode;
30
- }): import("@emotion/react/jsx-runtime").JSX.Element;
29
+ interface BeamProviderProps extends PropsWithChildren<PresentationContextProps> {
30
+ }
31
+ export declare function BeamProvider({ children, ...presentationProps }: BeamProviderProps): import("@emotion/react/jsx-runtime").JSX.Element;
31
32
  export declare function useBeamContext(): BeamContextState;
33
+ export {};
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const react_aria_1 = require("react-aria");
7
7
  const Modal_1 = require("./Modal/Modal");
8
+ const PresentationContext_1 = require("./PresentationContext");
8
9
  const SuperDrawer_1 = require("./SuperDrawer/SuperDrawer");
9
10
  const index_1 = require("../utils/index");
10
11
  /** This is only exported internally, for useModal and useSuperDrawer, it's not a public API. */
@@ -20,7 +21,7 @@ exports.BeamContext = (0, react_1.createContext)({
20
21
  tabActionsRef: new index_1.EmptyRef(),
21
22
  tabActionsDiv: undefined,
22
23
  });
23
- function BeamProvider({ children }) {
24
+ function BeamProvider({ children, ...presentationProps }) {
24
25
  // We want the identity of these to be stable, b/c they end up being used as dependencies
25
26
  // in both useModal's and useSuperDrawer's return values, which means the end-application's
26
27
  // dependencies as well, i.e. things like GridTable rowStyles will memoize on openInDrawer.
@@ -54,7 +55,7 @@ function BeamProvider({ children }) {
54
55
  tabActionsDiv,
55
56
  };
56
57
  }, [modalBodyDiv, modalFooterDiv]);
57
- return ((0, jsx_runtime_1.jsxs)(exports.BeamContext.Provider, Object.assign({ value: { ...context } }, { children: [(0, jsx_runtime_1.jsxs)(react_aria_1.OverlayProvider, { children: [children, modalRef.current && drawerContentStackRef.current.length === 0 && (0, jsx_runtime_1.jsx)(Modal_1.Modal, Object.assign({}, modalRef.current), void 0)] }, void 0), (0, jsx_runtime_1.jsx)(SuperDrawer_1.SuperDrawer, {}, void 0)] }), void 0));
58
+ return ((0, jsx_runtime_1.jsx)(exports.BeamContext.Provider, Object.assign({ value: { ...context } }, { children: (0, jsx_runtime_1.jsxs)(PresentationContext_1.PresentationProvider, Object.assign({}, presentationProps, { children: [(0, jsx_runtime_1.jsxs)(react_aria_1.OverlayProvider, { children: [children, modalRef.current && drawerContentStackRef.current.length === 0 && (0, jsx_runtime_1.jsx)(Modal_1.Modal, Object.assign({}, modalRef.current), void 0)] }, void 0), (0, jsx_runtime_1.jsx)(SuperDrawer_1.SuperDrawer, {}, void 0)] }), void 0) }), void 0));
58
59
  }
59
60
  exports.BeamProvider = BeamProvider;
60
61
  /** Looks like a ref, but invokes a re-render on set (w/o changing the setter identity). */
@@ -1,5 +1,5 @@
1
1
  import { AriaButtonProps } from "@react-types/button";
2
- import { ReactNode, RefObject } from "react";
2
+ import { ButtonHTMLAttributes, ReactNode, RefObject } from "react";
3
3
  import { IconProps } from "./";
4
4
  import { BeamButtonProps, BeamFocusableProps } from "../interfaces";
5
5
  export interface ButtonProps extends BeamButtonProps, BeamFocusableProps {
@@ -12,6 +12,8 @@ export interface ButtonProps extends BeamButtonProps, BeamFocusableProps {
12
12
  /** HTML attributes to apply to the button element when it is being used to trigger a menu. */
13
13
  menuTriggerProps?: AriaButtonProps;
14
14
  buttonRef?: RefObject<HTMLElement>;
15
+ /** Allow for setting "submit" | "button" | "reset" on button element */
16
+ type?: ButtonHTMLAttributes<HTMLButtonElement>["type"];
15
17
  }
16
18
  export declare function Button(props: ButtonProps): import("@emotion/react/jsx-runtime").JSX.Element;
17
19
  declare type ButtonSize = "sm" | "md" | "lg";
@@ -0,0 +1,25 @@
1
+ import { PropsWithChildren } from "react";
2
+ import { GridStyle } from "./Table";
3
+ export declare type PresentationContextProps = {
4
+ fieldProps?: {
5
+ numberAlignment?: "left" | "right";
6
+ hideLabel?: boolean;
7
+ labelSuffix?: LabelSuffixStyle;
8
+ };
9
+ gridTableStyle?: GridStyle;
10
+ };
11
+ export declare const PresentationContext: import("react").Context<PresentationContextProps>;
12
+ export declare function PresentationProvider(props: PropsWithChildren<PresentationContextProps>): import("@emotion/react/jsx-runtime").JSX.Element;
13
+ export declare function usePresentationContext(): PresentationContextProps;
14
+ /**
15
+ * Label settings for required/optional fields.
16
+ *
17
+ * We may want to just hard-code this behavior, so that it's very consistent,
18
+ * but for now making it configurable.
19
+ */
20
+ export declare type LabelSuffixStyle = {
21
+ /** The suffix to use for required fields. */
22
+ required?: string;
23
+ /** The suffix to use for explicitly optional (i.e. `required=false`) fields. */
24
+ optional?: string;
25
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePresentationContext = exports.PresentationProvider = exports.PresentationContext = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ exports.PresentationContext = (0, react_1.createContext)({});
7
+ function PresentationProvider(props) {
8
+ const { children, ...presentationProps } = props;
9
+ // Check to see if we are nested within another PresentationContext. If so, make sure values already above us are passed through if not overwritten (except baseContext)
10
+ const existingContext = usePresentationContext();
11
+ const context = (0, react_1.useMemo)(() => {
12
+ const fieldProps = { ...existingContext.fieldProps, ...presentationProps.fieldProps };
13
+ return { ...existingContext, ...presentationProps, fieldProps };
14
+ }, [presentationProps, existingContext]);
15
+ return (0, jsx_runtime_1.jsx)(exports.PresentationContext.Provider, Object.assign({ value: context }, { children: children }), void 0);
16
+ }
17
+ exports.PresentationProvider = PresentationProvider;
18
+ function usePresentationContext() {
19
+ return (0, react_1.useContext)(exports.PresentationContext);
20
+ }
21
+ exports.usePresentationContext = usePresentationContext;
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfirmCloseModal = void 0;
4
4
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
- const src_1 = require("../..");
5
+ const components_1 = require("..");
6
+ const Css_1 = require("../../Css");
6
7
  const BeamContext_1 = require("../BeamContext");
7
8
  /** Modal content to appear when a close checks fails */
8
9
  function ConfirmCloseModal(props) {
@@ -14,7 +15,7 @@ function ConfirmCloseModal(props) {
14
15
  // after a close and could/will cause other close attempts to fail.
15
16
  modalState.current = undefined;
16
17
  }
17
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(src_1.ModalHeader, { children: "Confirm" }, void 0), (0, jsx_runtime_1.jsx)(src_1.ModalBody, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: src_1.Css.tc.wPx(400).$ }, { children: [(0, jsx_runtime_1.jsx)("p", Object.assign({ css: src_1.Css.lgEm.gray900.mb2.$ }, { children: "Are you sure you want to cancel?" }), void 0), (0, jsx_runtime_1.jsx)("p", Object.assign({ css: src_1.Css.base.gray700.$ }, { children: "Any data you've entered so far will be lost." }), void 0)] }), void 0) }, void 0), (0, jsx_runtime_1.jsx)(src_1.ModalFooter, Object.assign({ xss: src_1.Css.jcc.$ }, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: src_1.Css.df.fdc.childGap1.aic.$ }, { children: [(0, jsx_runtime_1.jsx)(src_1.Button, { label: continueText, onClick: closeModal }, void 0), (0, jsx_runtime_1.jsx)(src_1.Button, { variant: "tertiary", label: discardText, onClick: () => {
18
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(components_1.ModalHeader, { children: "Confirm" }, void 0), (0, jsx_runtime_1.jsx)(components_1.ModalBody, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.tc.wPx(400).$ }, { children: [(0, jsx_runtime_1.jsx)("p", Object.assign({ css: Css_1.Css.lgEm.gray900.mb2.$ }, { children: "Are you sure you want to cancel?" }), void 0), (0, jsx_runtime_1.jsx)("p", Object.assign({ css: Css_1.Css.base.gray700.$ }, { children: "Any data you've entered so far will be lost." }), void 0)] }), void 0) }, void 0), (0, jsx_runtime_1.jsx)(components_1.ModalFooter, Object.assign({ xss: Css_1.Css.jcc.$ }, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.df.fdc.childGap1.aic.$ }, { children: [(0, jsx_runtime_1.jsx)(components_1.Button, { label: continueText, onClick: closeModal }, void 0), (0, jsx_runtime_1.jsx)(components_1.Button, { variant: "tertiary", label: discardText, onClick: () => {
18
19
  // The order of these calls doesn't really matter; close this modal and tell the call to do their close
19
20
  onClose();
20
21
  closeModal();
@@ -169,7 +169,7 @@ export interface GridTableProps<R extends Kinded, S, X> {
169
169
  * row `kind` along with the data rows. (Admittedly, out of pragmatism, we do apply some
170
170
  * special styling to the row that uses `kind: "header"`.)
171
171
  */
172
- export declare function GridTable<R extends Kinded, S = {}, X extends Only<GridTableXss, X> = {}>(props: GridTableProps<R, S, X>): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
172
+ export declare function GridTable<R extends Kinded, S = {}, X extends Only<GridTableXss, X> = {}>(props: GridTableProps<R, S, X>): import("@emotion/react/jsx-runtime").JSX.Element;
173
173
  /**
174
174
  * Creates a `grid-template-column` specific to our virtual output.
175
175
  *
@@ -30,6 +30,7 @@ const react_1 = __importStar(require("react"));
30
30
  const react_router_dom_1 = require("react-router-dom");
31
31
  const react_virtuoso_1 = require("react-virtuoso");
32
32
  const CssReset_1 = require("../CssReset");
33
+ const PresentationContext_1 = require("../PresentationContext");
33
34
  const GridRowLookup_1 = require("./GridRowLookup");
34
35
  const GridSortContext_1 = require("./GridSortContext");
35
36
  const nestedCards_1 = require("./nestedCards");
@@ -202,7 +203,7 @@ function GridTable(props) {
202
203
  // just trust the GridTable impl that, at runtime, `as=virtual` will (other than being virtualized)
203
204
  // behave semantically the same as `as=div` did for its tests.
204
205
  const _as = as === "virtual" && runningInJest ? "div" : as;
205
- return renders[_as](style, id, columns, headerRows, filteredRows, firstRowMessage, stickyHeader, (_a = style.nestedCards) === null || _a === void 0 ? void 0 : _a.firstLastColumnWidth, xss, virtuosoRef);
206
+ return ((0, jsx_runtime_1.jsx)(PresentationContext_1.PresentationProvider, Object.assign({ fieldProps: { hideLabel: true, numberAlignment: "right" } }, { children: renders[_as](style, id, columns, headerRows, filteredRows, firstRowMessage, stickyHeader, (_a = style.nestedCards) === null || _a === void 0 ? void 0 : _a.firstLastColumnWidth, xss, virtuosoRef) }), void 0));
206
207
  }
207
208
  exports.GridTable = GridTable;
208
209
  // Determine which HTML element to use to build the GridTable
@@ -1,40 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cardStyle = exports.condensedStyle = exports.defaultStyle = void 0;
4
- const src_1 = require("../..");
4
+ const Css_1 = require("../../Css");
5
5
  /** Our original table look & feel/style. */
6
6
  exports.defaultStyle = {
7
- rootCss: src_1.Css.gray700.$,
8
- betweenRowsCss: src_1.Css.bt.bGray400.$,
9
- firstNonHeaderRowCss: src_1.Css.add({ borderTopStyle: "none" }).$,
10
- cellCss: src_1.Css.py2.px3.$,
11
- firstCellCss: src_1.Css.pl1.$,
12
- lastCellCss: src_1.Css.$,
13
- indentOneCss: src_1.Css.pl4.$,
14
- indentTwoCss: src_1.Css.pl7.$,
7
+ rootCss: Css_1.Css.gray700.$,
8
+ betweenRowsCss: Css_1.Css.bt.bGray400.$,
9
+ firstNonHeaderRowCss: Css_1.Css.add({ borderTopStyle: "none" }).$,
10
+ cellCss: Css_1.Css.py2.px3.$,
11
+ firstCellCss: Css_1.Css.pl1.$,
12
+ lastCellCss: Css_1.Css.$,
13
+ indentOneCss: Css_1.Css.pl4.$,
14
+ indentTwoCss: Css_1.Css.pl7.$,
15
15
  // Use h100 so that all cells are the same height when scrolled; set bgWhite for when we're laid over other rows.
16
- headerCellCss: src_1.Css.asfe.nowrap.py1.bgGray100.h100.aife.$,
17
- firstRowMessageCss: src_1.Css.px1.py2.$,
18
- rowHoverColor: src_1.Palette.Gray200,
16
+ headerCellCss: Css_1.Css.asfe.nowrap.py1.bgGray100.h100.aife.$,
17
+ firstRowMessageCss: Css_1.Css.px1.py2.$,
18
+ rowHoverColor: Css_1.Palette.Gray200,
19
19
  };
20
20
  /** Tightens up the padding of rows, great for rows that have form elements in them. */
21
21
  exports.condensedStyle = {
22
22
  ...exports.defaultStyle,
23
- headerCellCss: src_1.Css.bgGray100.tinyEm.$,
24
- cellCss: src_1.Css.aic.sm.py1.px2.$,
25
- rootCss: src_1.Css.dg.gray700.xs.$,
23
+ headerCellCss: Css_1.Css.bgGray100.tinyEm.$,
24
+ cellCss: Css_1.Css.aic.sm.py1.px2.$,
25
+ rootCss: Css_1.Css.dg.gray700.xs.$,
26
26
  };
27
27
  /** Renders each row as a card. */
28
28
  exports.cardStyle = {
29
29
  ...exports.defaultStyle,
30
- firstNonHeaderRowCss: src_1.Css.mt2.$,
31
- cellCss: src_1.Css.p2.my1.bt.bb.bGray400.$,
32
- firstCellCss: src_1.Css.bl.add({ borderTopLeftRadius: "4px", borderBottomLeftRadius: "4px" }).$,
33
- lastCellCss: src_1.Css.br.add({ borderTopRightRadius: "4px", borderBottomRightRadius: "4px" }).$,
30
+ firstNonHeaderRowCss: Css_1.Css.mt2.$,
31
+ cellCss: Css_1.Css.p2.my1.bt.bb.bGray400.$,
32
+ firstCellCss: Css_1.Css.bl.add({ borderTopLeftRadius: "4px", borderBottomLeftRadius: "4px" }).$,
33
+ lastCellCss: Css_1.Css.br.add({ borderTopRightRadius: "4px", borderBottomRightRadius: "4px" }).$,
34
34
  // Undo the card look & feel for the header
35
35
  headerCellCss: {
36
36
  ...exports.defaultStyle.headerCellCss,
37
- ...src_1.Css.add({
37
+ ...Css_1.Css.add({
38
38
  border: "none",
39
39
  borderRadius: "unset",
40
40
  }).p1.m0.xsEm.gray700.$,
@@ -18,6 +18,7 @@ export * from "./Modal/useModal";
18
18
  export { NavLink } from "./NavLink";
19
19
  export * from "./Pill";
20
20
  export * from "./Pills";
21
+ export { PresentationProvider } from "./PresentationContext";
21
22
  export * from "./Stepper";
22
23
  export * from "./SuperDrawer";
23
24
  export * from "./Table";
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.TabsWithContent = exports.Tabs = exports.TabContent = exports.NavLink = exports.BeamProvider = exports.maybeAddCardPadding = exports.makeSpacer = exports.makeOpenOrCloseCard = void 0;
13
+ exports.TabsWithContent = exports.Tabs = exports.TabContent = exports.PresentationProvider = exports.NavLink = exports.BeamProvider = exports.maybeAddCardPadding = exports.makeSpacer = exports.makeOpenOrCloseCard = void 0;
14
14
  __exportStar(require("./Table/GridTable"), exports);
15
15
  var nestedCards_1 = require("./Table/nestedCards");
16
16
  Object.defineProperty(exports, "makeOpenOrCloseCard", { enumerable: true, get: function () { return nestedCards_1.makeOpenOrCloseCard; } });
@@ -36,6 +36,8 @@ var NavLink_1 = require("./NavLink");
36
36
  Object.defineProperty(exports, "NavLink", { enumerable: true, get: function () { return NavLink_1.NavLink; } });
37
37
  __exportStar(require("./Pill"), exports);
38
38
  __exportStar(require("./Pills"), exports);
39
+ var PresentationContext_1 = require("./PresentationContext");
40
+ Object.defineProperty(exports, "PresentationProvider", { enumerable: true, get: function () { return PresentationContext_1.PresentationProvider; } });
39
41
  __exportStar(require("./Stepper"), exports);
40
42
  __exportStar(require("./SuperDrawer"), exports);
41
43
  __exportStar(require("./Table"), exports);
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from "react";
2
- import { LabelSuffixStyle } from "./FormContext";
2
+ import { LabelSuffixStyle } from "../components/PresentationContext";
3
3
  export declare type FormWidth =
4
4
  /** 320px. */
5
5
  "sm"
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FieldGroup = exports.FormDivider = exports.FormLines = void 0;
4
4
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
5
  const react_1 = require("react");
6
+ const PresentationContext_1 = require("../components/PresentationContext");
6
7
  const Css_1 = require("../Css");
7
- const FormContext_1 = require("./FormContext");
8
8
  /**
9
9
  * Applies standard Form layout/size/spacing between lines.
10
10
  *
@@ -12,10 +12,12 @@ const FormContext_1 = require("./FormContext");
12
12
  * (see the `FieldGroup` component), where they will be laid out side-by-side.
13
13
  */
14
14
  function FormLines(props) {
15
- const settings = (0, react_1.useContext)(FormContext_1.FormContext);
16
- const { children, width = "full", labelSuffix = settings.labelSuffix } = props;
15
+ const { fieldProps } = (0, PresentationContext_1.usePresentationContext)();
16
+ const { children, width = "full", labelSuffix = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.labelSuffix } = props;
17
17
  let firstFormHeading = true;
18
- return ((0, jsx_runtime_1.jsx)(FormContext_1.FormContext.Provider, Object.assign({ value: { labelSuffix } }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ css: {
18
+ return (
19
+ // Only overwrite label suffix if the property was defined in `props`. Ensures we only set to `undefined` if explicitly set.
20
+ (0, jsx_runtime_1.jsx)(PresentationContext_1.PresentationProvider, Object.assign({ fieldProps: "labelSuffix" in props ? { labelSuffix } : {} }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ css: {
19
21
  // Note that we're purposefully not using display:flex so that our children's margins will collapse.
20
22
  ...Css_1.Css.w(sizes[width]).$,
21
23
  // Purposefully use this instead of childGap3 to put margin-bottom on the last line
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLabelSuffix = void 0;
4
- const react_1 = require("react");
5
- const FormContext_1 = require("./FormContext");
4
+ const PresentationContext_1 = require("../components/PresentationContext");
6
5
  function getLabelSuffix(required) {
6
+ var _a, _b;
7
7
  // We promise to always call `getLabelSuffix` deterministically
8
8
  // eslint-disable-next-line react-hooks/rules-of-hooks
9
- const settings = (0, react_1.useContext)(FormContext_1.FormContext);
9
+ const { fieldProps } = (0, PresentationContext_1.usePresentationContext)();
10
10
  if (required === true) {
11
- return settings.labelSuffix.required;
11
+ return (_a = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.labelSuffix) === null || _a === void 0 ? void 0 : _a.required;
12
12
  }
13
13
  else if (required === false) {
14
- return settings.labelSuffix.optional;
14
+ return (_b = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.labelSuffix) === null || _b === void 0 ? void 0 : _b.optional;
15
15
  }
16
16
  else {
17
17
  return undefined;
@@ -8,12 +8,13 @@ const HelperText_1 = require("../components/HelperText");
8
8
  const Css_1 = require("../Css");
9
9
  const ErrorMessage_1 = require("./ErrorMessage");
10
10
  const utils_1 = require("../utils");
11
+ const defaultTestId_1 = require("../utils/defaultTestId");
11
12
  function CheckboxBase(props) {
12
13
  const { ariaProps, description, isDisabled = false, isIndeterminate = false, isSelected, inputProps, label, errorMsg, helperText, } = props;
13
14
  const ref = (0, react_1.useRef)(null);
14
15
  const { isFocusVisible, focusProps } = (0, react_aria_1.useFocusRing)(ariaProps);
15
16
  const { hoverProps, isHovered } = (0, react_aria_1.useHover)({ isDisabled });
16
- const tid = (0, utils_1.useTestIds)(props);
17
+ const tid = (0, utils_1.useTestIds)(props, (0, defaultTestId_1.defaultTestId)(label));
17
18
  const markIcon = isIndeterminate ? dashSmall : isSelected ? checkmarkSmall : "";
18
19
  return ((0, jsx_runtime_1.jsxs)("label", Object.assign({ css: Css_1.Css.df.cursorPointer.relative
19
20
  // Prevents accidental checkbox clicks due to label width being longer
@@ -22,7 +23,7 @@ function CheckboxBase(props) {
22
23
  .maxw((0, Css_1.px)(320))
23
24
  .if(description !== undefined)
24
25
  .maxw((0, Css_1.px)(344))
25
- .if(isDisabled).cursorNotAllowed.$ }, { children: [(0, jsx_runtime_1.jsx)(react_aria_1.VisuallyHidden, { children: (0, jsx_runtime_1.jsx)("input", Object.assign({ ref: ref }, inputProps, focusProps), void 0) }, void 0), (0, jsx_runtime_1.jsx)("span", Object.assign({}, hoverProps, { css: {
26
+ .if(isDisabled).cursorNotAllowed.$ }, { children: [(0, jsx_runtime_1.jsx)(react_aria_1.VisuallyHidden, { children: (0, jsx_runtime_1.jsx)("input", Object.assign({ ref: ref }, inputProps, focusProps, tid), void 0) }, void 0), (0, jsx_runtime_1.jsx)("span", Object.assign({}, hoverProps, { css: {
26
27
  ...baseStyles,
27
28
  ...((isSelected || isIndeterminate) && filledBoxStyles),
28
29
  ...((isSelected || isIndeterminate) && isHovered && filledBoxHoverStyles),
@@ -17,7 +17,7 @@ export interface NumberFieldProps {
17
17
  onFocus?: () => void;
18
18
  readOnly?: boolean;
19
19
  /** Styles overrides */
20
- xss?: Xss<"textAlign">;
20
+ xss?: Xss<"textAlign" | "justifyContent">;
21
21
  }
22
22
  export declare function NumberField(props: NumberFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
23
23
  export declare function parseRawInput(rawInputValue: string | undefined, factor: number, type?: NumberFieldType): number | undefined;
@@ -5,11 +5,15 @@ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const react_aria_1 = require("react-aria");
7
7
  const react_stately_1 = require("react-stately");
8
+ const PresentationContext_1 = require("../components/PresentationContext");
8
9
  const Css_1 = require("../Css");
9
10
  const labelUtils_1 = require("../forms/labelUtils");
10
11
  const TextFieldBase_1 = require("./TextFieldBase");
11
12
  function NumberField(props) {
12
- const { disabled = false, required, readOnly = false, type, label, onBlur, onFocus, errorMsg, helperText, compact = false, value, onChange, xss, ...otherProps } = props;
13
+ // Determine default alignment based on presentation context
14
+ const { fieldProps } = (0, PresentationContext_1.usePresentationContext)();
15
+ const alignment = (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.numberAlignment) === "right" ? Css_1.Css.tr.jcfe.$ : Css_1.Css.tl.jcfs.$;
16
+ const { disabled = false, required, readOnly = false, type, label, hideLabel = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.hideLabel, onBlur, onFocus, errorMsg, helperText, compact = false, value, onChange, xss, ...otherProps } = props;
13
17
  const factor = type === "percent" || type === "cents" ? 100 : type === "basisPoints" ? 10000 : 1;
14
18
  const labelSuffix = (0, labelUtils_1.getLabelSuffix)(required);
15
19
  // If formatOptions isn't memo'd, a useEffect in useNumberStateField will cause jank,
@@ -56,7 +60,7 @@ function NumberField(props) {
56
60
  if (readOnly && !inputRef.current) {
57
61
  inputRef.current = document.createElement("input");
58
62
  }
59
- return ((0, jsx_runtime_1.jsx)(TextFieldBase_1.TextFieldBase, Object.assign({ xss: { ...Css_1.Css.tr.jcfe.$, ...xss }, groupProps: groupProps, labelProps: labelProps, label: label, required: required, inputProps: inputProps,
63
+ return ((0, jsx_runtime_1.jsx)(TextFieldBase_1.TextFieldBase, Object.assign({ xss: { ...alignment, ...xss }, groupProps: groupProps, labelProps: labelProps, label: label, hideLabel: hideLabel, required: required, inputProps: inputProps,
60
64
  // This is called on each DOM change, to push the latest value into the field
61
65
  onChange: (rawInputValue) => {
62
66
  const changeValue = parseRawInput(rawInputValue, factor, type);
@@ -12,7 +12,7 @@ interface TextFieldBaseProps extends Pick<BeamTextFieldProps, "label" | "require
12
12
  /** TextField specific */
13
13
  compact?: boolean;
14
14
  /** Styles overrides */
15
- xss?: Xss<"textAlign" | "fontWeight">;
15
+ xss?: Xss<"textAlign" | "fontWeight" | "justifyContent">;
16
16
  endAdornment?: ReactNode;
17
17
  startAdornment?: ReactNode;
18
18
  inlineLabel?: boolean;
@@ -1,6 +1,17 @@
1
- import { RenderResult, Wrapper } from "@homebound/rtl-utils";
2
- export * from "@homebound/rtl-react-router-utils";
3
- export * from "@homebound/rtl-utils";
1
+ import { newLocation as _newLocation, withRouter as _withRouter } from "@homebound/rtl-react-router-utils";
2
+ import { change as _change, click as _click, getOptions as _getOptions, input as _input, RenderResult, select as _select, type as _type, typeAndWait as _typeAndWait, wait as _wait, Wrapper } from "@homebound/rtl-utils";
3
+ import { ReactElement } from "react";
4
+ export { _change as change, _click as click, _getOptions as getOptions, _input as input, _select as select, _type as type, _typeAndWait as typeAndWait, _wait as wait, };
5
+ export { _newLocation as newLocation, _withRouter as withRouter };
6
+ interface RenderOpts {
7
+ at?: {
8
+ url: string;
9
+ route?: string;
10
+ };
11
+ omitBeamContext?: boolean;
12
+ }
13
+ export declare function render(component: ReactElement, withoutBeamProvider: RenderOpts, ...otherWrappers: Wrapper[]): Promise<RenderResult & Record<string, HTMLElement & Function>>;
14
+ export declare function render(component: ReactElement, ...otherWrappers: Wrapper[]): Promise<RenderResult & Record<string, HTMLElement & Function>>;
4
15
  export declare function cell(r: RenderResult, row: number, column: number): HTMLElement;
5
16
  export declare function cellOf(r: RenderResult, testId: string, row: number, column: number): HTMLElement;
6
17
  export declare function cellAnd(r: RenderResult, row: number, column: number, testId: string): HTMLElement;
package/dist/utils/rtl.js CHANGED
@@ -1,21 +1,38 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
2
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.withBeamRTL = exports.rowAnd = exports.row = exports.cellAnd = exports.cellOf = exports.cell = void 0;
3
+ exports.withBeamRTL = exports.rowAnd = exports.row = exports.cellAnd = exports.cellOf = exports.cell = exports.render = exports.withRouter = exports.newLocation = exports.wait = exports.typeAndWait = exports.type = exports.select = exports.input = exports.getOptions = exports.click = exports.change = void 0;
14
4
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const rtl_react_router_utils_1 = require("@homebound/rtl-react-router-utils");
6
+ Object.defineProperty(exports, "newLocation", { enumerable: true, get: function () { return rtl_react_router_utils_1.newLocation; } });
7
+ Object.defineProperty(exports, "withRouter", { enumerable: true, get: function () { return rtl_react_router_utils_1.withRouter; } });
8
+ const rtl_utils_1 = require("@homebound/rtl-utils");
9
+ Object.defineProperty(exports, "change", { enumerable: true, get: function () { return rtl_utils_1.change; } });
10
+ Object.defineProperty(exports, "click", { enumerable: true, get: function () { return rtl_utils_1.click; } });
11
+ Object.defineProperty(exports, "getOptions", { enumerable: true, get: function () { return rtl_utils_1.getOptions; } });
12
+ Object.defineProperty(exports, "input", { enumerable: true, get: function () { return rtl_utils_1.input; } });
13
+ Object.defineProperty(exports, "select", { enumerable: true, get: function () { return rtl_utils_1.select; } });
14
+ Object.defineProperty(exports, "type", { enumerable: true, get: function () { return rtl_utils_1.type; } });
15
+ Object.defineProperty(exports, "typeAndWait", { enumerable: true, get: function () { return rtl_utils_1.typeAndWait; } });
16
+ Object.defineProperty(exports, "wait", { enumerable: true, get: function () { return rtl_utils_1.wait; } });
15
17
  const react_1 = require("@testing-library/react");
16
18
  const components_1 = require("../components");
17
- __exportStar(require("@homebound/rtl-react-router-utils"), exports);
18
- __exportStar(require("@homebound/rtl-utils"), exports);
19
+ function render(component, wrapperOrOpts, ...otherWrappers) {
20
+ if (wrapperOrOpts && "wrap" in wrapperOrOpts) {
21
+ // They passed at least single wrapper + maybe more.
22
+ // We put `withBeamRTL` first so that any `withApollo`s wrap outside of beam, so in-drawer/in-modal content has apollo
23
+ return (0, rtl_utils_1.render)(component, ...[exports.withBeamRTL, wrapperOrOpts, ...otherWrappers]);
24
+ }
25
+ else if (wrapperOrOpts) {
26
+ const { omitBeamContext, at } = wrapperOrOpts;
27
+ return (0, rtl_utils_1.render)(component, ...[
28
+ ...otherWrappers,
29
+ ...(!omitBeamContext ? [exports.withBeamRTL] : []),
30
+ ...(at ? [(0, rtl_react_router_utils_1.withRouter)(at.url, at.route)] : [(0, rtl_react_router_utils_1.withRouter)()]),
31
+ ]);
32
+ }
33
+ return (0, rtl_utils_1.render)(component, exports.withBeamRTL);
34
+ }
35
+ exports.render = render;
19
36
  function cell(r, row, column) {
20
37
  return r.getByTestId("grid-table").childNodes[row].childNodes[column];
21
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.80.0",
3
+ "version": "2.80.4",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -1,26 +0,0 @@
1
- /// <reference types="react" />
2
- export interface FormSettings {
3
- labelSuffix: LabelSuffixStyle;
4
- }
5
- /**
6
- * Label settings for required/optional fields.
7
- *
8
- * We may want to just hard-code this behavior, so that it's very consistent,
9
- * but for now making it configurable.
10
- */
11
- export declare type LabelSuffixStyle = {
12
- /** The suffix to use for required fields. */
13
- required?: string;
14
- /** The suffix to use for explicitly optional (i.e. `required=false`) fields. */
15
- optional?: string;
16
- };
17
- /**
18
- * An internal context for holding form-wide state/preferences.
19
- *
20
- * Currently this can only be set via the `FormLines.labelSuffix` prop,
21
- * otherwise we just use a hard-coded default.
22
- *
23
- * Eventually we should probably expose a way to set this via the `BeamContext`
24
- * as well, and also override on individual fields as needed.
25
- */
26
- export declare const FormContext: import("react").Context<FormSettings>;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormContext = void 0;
4
- const react_1 = require("react");
5
- /**
6
- * An internal context for holding form-wide state/preferences.
7
- *
8
- * Currently this can only be set via the `FormLines.labelSuffix` prop,
9
- * otherwise we just use a hard-coded default.
10
- *
11
- * Eventually we should probably expose a way to set this via the `BeamContext`
12
- * as well, and also override on individual fields as needed.
13
- */
14
- exports.FormContext = (0, react_1.createContext)({
15
- labelSuffix: { required: undefined, optional: undefined },
16
- });