@homebound/beam 2.144.0 → 2.146.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.
@@ -1,6 +1,10 @@
1
1
  import { SnackbarNoticeProps } from "./SnackbarNotice";
2
2
  interface SnackbarProps {
3
3
  notices: SnackbarNoticeProps[];
4
+ offset: Offset;
4
5
  }
5
- export declare function Snackbar({ notices }: SnackbarProps): import("@emotion/react/jsx-runtime").JSX.Element;
6
+ export declare function Snackbar({ notices, offset }: SnackbarProps): import("@emotion/react/jsx-runtime").JSX.Element;
7
+ export declare type Offset = {
8
+ bottom?: number;
9
+ };
6
10
  export {};
@@ -4,7 +4,13 @@ exports.Snackbar = void 0;
4
4
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
5
  const SnackbarNotice_1 = require("./SnackbarNotice");
6
6
  const Css_1 = require("../../Css");
7
- function Snackbar({ notices }) {
8
- return ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.fixed.bottom3.left3.df.fdc.aifs.gapPx(12).$ }, { children: notices.map((data) => ((0, jsx_runtime_1.jsx)(SnackbarNotice_1.SnackbarNotice, Object.assign({}, data), data.id))) }), void 0));
7
+ const utils_1 = require("../../utils");
8
+ function Snackbar({ notices, offset }) {
9
+ var _a;
10
+ const tid = (0, utils_1.useTestIds)({});
11
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, tid.snackbarWrapper, { css: Css_1.Css.fixed.z999.bottomPx((_a = offset.bottom) !== null && _a !== void 0 ? _a : defaultOffset.bottom).left3.df.fdc.aifs.gapPx(12).$ }, { children: notices.map((data) => ((0, jsx_runtime_1.jsx)(SnackbarNotice_1.SnackbarNotice, Object.assign({}, data), data.id))) }), void 0));
9
12
  }
10
13
  exports.Snackbar = Snackbar;
14
+ const defaultOffset = {
15
+ bottom: 24,
16
+ };
@@ -1,7 +1,9 @@
1
1
  import React, { PropsWithChildren } from "react";
2
2
  import { SnackbarNoticeProps } from "./SnackbarNotice";
3
+ import { Offset } from "./Snackbar";
3
4
  export declare type SnackbarContextProps = {
4
5
  setNotices: React.Dispatch<React.SetStateAction<SnackbarNoticeProps[]>>;
6
+ setOffset: React.Dispatch<React.SetStateAction<Offset>>;
5
7
  };
6
8
  export declare const SnackbarContext: React.Context<SnackbarContextProps>;
7
9
  export declare function SnackbarProvider(props: PropsWithChildren<{}>): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -4,11 +4,12 @@ exports.useSnackbarContext = exports.SnackbarProvider = exports.SnackbarContext
4
4
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const Snackbar_1 = require("./Snackbar");
7
- exports.SnackbarContext = (0, react_1.createContext)({ setNotices: () => { } });
7
+ exports.SnackbarContext = (0, react_1.createContext)({ setNotices: () => { }, setOffset: () => { } });
8
8
  function SnackbarProvider(props) {
9
9
  const [notices, setNotices] = (0, react_1.useState)([]);
10
- const contextValue = (0, react_1.useMemo)(() => ({ setNotices }), []);
11
- return ((0, jsx_runtime_1.jsxs)(exports.SnackbarContext.Provider, Object.assign({ value: contextValue }, { children: [props.children, (0, jsx_runtime_1.jsx)(Snackbar_1.Snackbar, { notices: notices }, void 0)] }), void 0));
10
+ const [offset, setOffset] = (0, react_1.useState)({});
11
+ const contextValue = (0, react_1.useMemo)(() => ({ setNotices, setOffset }), []);
12
+ return ((0, jsx_runtime_1.jsxs)(exports.SnackbarContext.Provider, Object.assign({ value: contextValue }, { children: [props.children, (0, jsx_runtime_1.jsx)(Snackbar_1.Snackbar, { notices: notices, offset: offset }, void 0)] }), void 0));
12
13
  }
13
14
  exports.SnackbarProvider = SnackbarProvider;
14
15
  function useSnackbarContext() {
@@ -1,9 +1,18 @@
1
1
  import { SnackbarNoticeProps } from "./SnackbarNotice";
2
+ import { Offset } from "./Snackbar";
2
3
  export interface UseSnackbarHook {
3
4
  triggerNotice: (props: TriggerNoticeProps) => {
4
5
  close: () => void;
5
6
  };
6
7
  closeNotice: (id: string) => void;
8
+ /**
9
+ * A custom hook that components may call to notify snackbar it should offset,
10
+ * such as a bottom-mounted Stepper component that ought not be covered by
11
+ * notifications. Behaves like a useEffect, and will clean up on dismount.
12
+ * (Known issue: If multiple components call this, last-to-render takes
13
+ * precedence and first-to-dismount unsets everything)
14
+ */
15
+ useSnackbarOffset: (offset: Offset) => void;
7
16
  }
8
17
  export declare function useSnackbar(): UseSnackbarHook;
9
18
  export interface TriggerNoticeProps extends Omit<SnackbarNoticeProps, "id" | "onClose"> {
@@ -5,7 +5,7 @@ const react_1 = require("react");
5
5
  const SnackbarContext_1 = require("./SnackbarContext");
6
6
  const utils_1 = require("../../utils");
7
7
  function useSnackbar() {
8
- const { setNotices } = (0, SnackbarContext_1.useSnackbarContext)();
8
+ const { setNotices, setOffset } = (0, SnackbarContext_1.useSnackbarContext)();
9
9
  const onClose = (0, react_1.useCallback)((noticeId) => {
10
10
  setNotices((prev) => {
11
11
  let returnValue = prev;
@@ -50,7 +50,11 @@ function useSnackbar() {
50
50
  };
51
51
  }, [onClose, setNotices]);
52
52
  const closeNotice = (0, react_1.useCallback)((id) => onClose(id), [onClose]);
53
- return { triggerNotice, closeNotice };
53
+ const useSnackbarOffset = ({ bottom }) => (0, react_1.useEffect)(() => {
54
+ setOffset({ bottom });
55
+ return () => setOffset({});
56
+ }, [bottom]);
57
+ return { triggerNotice, closeNotice, useSnackbarOffset };
54
58
  }
55
59
  exports.useSnackbar = useSnackbar;
56
60
  let snackbarId = 1;
@@ -12,10 +12,16 @@ function Stepper({ steps, currentStep, onChange }) {
12
12
  }
13
13
  // calc progress based on last completed step - return -1 when no steps completed
14
14
  const lastCompletedStep = steps.map((step) => step.state).lastIndexOf("complete");
15
- return ((0, jsx_runtime_1.jsxs)("nav", Object.assign({ "aria-label": "steps", css: Css_1.Css.df.fdc.$ }, { children: [(0, jsx_runtime_1.jsx)("ol", Object.assign({ css: Css_1.Css.listReset.df.$ }, { children: steps.map((step) => {
15
+ const maxStepWidth = 200;
16
+ const minStepWidth = 100;
17
+ const gap = 8;
18
+ return ((0, jsx_runtime_1.jsxs)("nav", Object.assign({ "aria-label": "steps", css: Css_1.Css.df.fdc.w100.$ }, { children: [(0, jsx_runtime_1.jsx)("ol", Object.assign({ css: Css_1.Css.listReset.df.gapPx(gap).$ }, { children: steps.map((step) => {
16
19
  const isCurrent = currentStep === step.value;
17
- return ((0, jsx_runtime_1.jsx)("li", Object.assign({ css: Css_1.Css.df.fdc.wPx(200).$, "aria-current": isCurrent }, { children: (0, jsx_runtime_1.jsx)(StepButton, Object.assign({}, step, { onClick: () => onChange(step.value), isCurrent: isCurrent }), void 0) }), step.label));
18
- }) }), void 0), (0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.mt1.bgGray300.hPx(4).w(`${steps.length * 200}px`).$ }, { children: (0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.bgLightBlue600
20
+ return ((0, jsx_runtime_1.jsx)("li", Object.assign({ css: Css_1.Css.df.fg1.fdc.maxwPx(maxStepWidth).mwPx(minStepWidth).$, "aria-current": isCurrent }, { children: (0, jsx_runtime_1.jsx)(StepButton, Object.assign({}, step, { onClick: () => onChange(step.value), isCurrent: isCurrent }), void 0) }), step.label));
21
+ }) }), void 0), (0, jsx_runtime_1.jsx)("div", Object.assign({ css: Css_1.Css.mt1.bgGray300
22
+ .hPx(4)
23
+ .maxwPx(steps.length * maxStepWidth + (steps.length - 1) * gap)
24
+ .mwPx(steps.length * minStepWidth + (steps.length - 1) * gap).w100.$ }, { children: (0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.bgLightBlue600
19
25
  .add("transition", "width 200ms")
20
26
  .h100.w(`${((lastCompletedStep + 1) / steps.length) * 100}%`).$ }, void 0) }), void 0)] }), void 0));
21
27
  }
@@ -1,8 +1,8 @@
1
1
  import { FieldState } from "@homebound/form-state";
2
2
  import { SelectFieldProps, Value } from "../inputs";
3
3
  import { HasIdAndName, Optional } from "../types";
4
- export declare type BoundSelectFieldProps<T, V extends Value> = Omit<SelectFieldProps<T, V>, "value" | "onSelect" | "label"> & {
5
- onSelect?: (option: V | undefined) => void;
4
+ export declare type BoundSelectFieldProps<O, V extends Value> = Omit<SelectFieldProps<O, V>, "value" | "onSelect" | "label"> & {
5
+ onSelect?: (value: V | undefined, opt: O | undefined) => void;
6
6
  field: FieldState<any, V | null | undefined>;
7
7
  label?: string;
8
8
  };
@@ -14,8 +14,8 @@ function BoundSelectField(props) {
14
14
  const testId = (0, useTestIds_1.useTestIds)(props, field.key);
15
15
  return ((0, jsx_runtime_1.jsx)(mobx_react_1.Observer, { children: () => {
16
16
  var _a;
17
- return ((0, jsx_runtime_1.jsx)(inputs_1.SelectField, Object.assign({ label: label, value: (_a = field.value) !== null && _a !== void 0 ? _a : undefined, onSelect: (value) => {
18
- onSelect(value);
17
+ return ((0, jsx_runtime_1.jsx)(inputs_1.SelectField, Object.assign({ label: label, value: (_a = field.value) !== null && _a !== void 0 ? _a : undefined, onSelect: (value, opt) => {
18
+ onSelect(value, opt);
19
19
  field.maybeAutoSave();
20
20
  }, options: options, readOnly: readOnly !== null && readOnly !== void 0 ? readOnly : field.readOnly, errorMsg: field.touched ? field.errors.join(" ") : undefined, required: field.required, getOptionLabel: getOptionLabel, getOptionValue: getOptionValue, onBlur: () => {
21
21
  field.blur();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.144.0",
3
+ "version": "2.146.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",