@wise/dynamic-flow-client 3.20.1 → 3.21.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.
package/build/main.mjs CHANGED
@@ -6123,12 +6123,6 @@ var decisionLayoutOptionSchema = z.object({
6123
6123
  icon: iconSchema.optional(),
6124
6124
  image: imageLayoutSchema.optional()
6125
6125
  });
6126
- var statusListLayoutItemSchema = z.object({
6127
- title: z.string(),
6128
- description: z.string().optional(),
6129
- icon: iconSchema,
6130
- status: statusListLayoutStatusSchema.optional()
6131
- });
6132
6126
  var instructionsLayoutSchema = z.object({
6133
6127
  type: z.literal("instructions"),
6134
6128
  title: z.string().optional(),
@@ -6136,6 +6130,10 @@ var instructionsLayoutSchema = z.object({
6136
6130
  control: z.string().optional(),
6137
6131
  margin: sizeSchema.optional()
6138
6132
  });
6133
+ var behaviorSchema = z.object({
6134
+ action: actionSchema.optional(),
6135
+ link: linkSchema.optional()
6136
+ });
6139
6137
  var buttonLayoutSchema = z.object({
6140
6138
  type: z.literal("button"),
6141
6139
  size: sizeSchema.optional(),
@@ -6152,10 +6150,6 @@ var reviewLayoutFieldSchema = z.object({
6152
6150
  value: z.string(),
6153
6151
  help: helpSchema.optional()
6154
6152
  });
6155
- var behaviorSchema = z.object({
6156
- action: actionSchema.optional(),
6157
- link: linkSchema.optional()
6158
- });
6159
6153
  var searchResultSearchSchema = z.object({
6160
6154
  type: z.literal("search"),
6161
6155
  title: z.string(),
@@ -6216,12 +6210,10 @@ var decisionLayoutSchema = z.object({
6216
6210
  control: z.string().optional(),
6217
6211
  margin: sizeSchema.optional()
6218
6212
  });
6219
- var statusListLayoutSchema = z.object({
6220
- type: z.literal("status-list"),
6221
- items: z.array(statusListLayoutItemSchema),
6222
- title: z.string().optional(),
6223
- control: z.string().optional(),
6224
- margin: sizeSchema.optional()
6213
+ var itemCallToActionSchema = z.object({
6214
+ title: z.string(),
6215
+ accessibilityDescription: z.string().optional(),
6216
+ behavior: behaviorSchema
6225
6217
  });
6226
6218
  var reviewLayoutSchema = z.object({
6227
6219
  type: z.literal("review"),
@@ -6255,6 +6247,13 @@ var alertLayoutSchema = z.object({
6255
6247
  margin: sizeSchema.optional(),
6256
6248
  callToAction: alertLayoutCallToActionSchema.optional()
6257
6249
  });
6250
+ var statusListLayoutItemSchema = z.object({
6251
+ title: z.string(),
6252
+ description: z.string().optional(),
6253
+ icon: iconSchema,
6254
+ status: statusListLayoutStatusSchema.optional(),
6255
+ callToAction: itemCallToActionSchema.optional()
6256
+ });
6258
6257
  var searchResponseBodySchema = z.object({
6259
6258
  results: z.array(searchResultSchema)
6260
6259
  });
@@ -6296,6 +6295,13 @@ var constSchemaSchema = z.object({
6296
6295
  analyticsId: z.string().optional(),
6297
6296
  disabled: z.boolean().optional()
6298
6297
  });
6298
+ var statusListLayoutSchema = z.object({
6299
+ type: z.literal("status-list"),
6300
+ items: z.array(statusListLayoutItemSchema),
6301
+ title: z.string().optional(),
6302
+ control: z.string().optional(),
6303
+ margin: sizeSchema.optional()
6304
+ });
6299
6305
  var layoutSchema = z.lazy(
6300
6306
  () => z.union([
6301
6307
  alertLayoutSchema,
@@ -14708,10 +14714,9 @@ var priorities = {
14708
14714
  positive: "primary",
14709
14715
  negative: "primary"
14710
14716
  };
14711
- var getButtonPriority = (component) => {
14712
- var _a;
14713
- const actionType = component.action.type;
14714
- return (_a = component.control) != null ? _a : actionType ? priorities[actionType] : "secondary";
14717
+ var getButtonPriority = (control, action) => {
14718
+ const actionType = action ? action.type : void 0;
14719
+ return control != null ? control : actionType ? priorities[actionType] : "secondary";
14715
14720
  };
14716
14721
  var contextToType = {
14717
14722
  positive: "positive",
@@ -14726,13 +14731,16 @@ var actionTypeToType = {
14726
14731
  positive: "positive",
14727
14732
  negative: "negative"
14728
14733
  };
14729
- var getButtonType = (component) => {
14730
- if (component.context) {
14731
- return contextToType[component.context];
14734
+ var getButtonType = (context, action) => {
14735
+ if (context) {
14736
+ return contextToType[context];
14732
14737
  }
14733
- const actionType = component.action.type;
14738
+ const actionType = action ? action.type : void 0;
14734
14739
  return actionType ? actionTypeToType[actionType] : "accent";
14735
14740
  };
14741
+ var getButtonTypeFromContext = (context) => {
14742
+ return context ? contextToType[context] : "accent";
14743
+ };
14736
14744
  var getButtonSize = (size) => {
14737
14745
  switch (size) {
14738
14746
  case "xs":
@@ -14750,13 +14758,55 @@ var getButtonSize = (size) => {
14750
14758
  // src/legacy/layout/button/DynamicButton.tsx
14751
14759
  import { jsx as jsx72 } from "react/jsx-runtime";
14752
14760
  function DynamicButton(props) {
14753
- var _a;
14761
+ return props.component.behavior ? /* @__PURE__ */ jsx72(DynamicButtonWithBehavior, __spreadValues({}, props)) : /* @__PURE__ */ jsx72(DynamicButtonWithoutBehavior, __spreadValues({}, props));
14762
+ }
14763
+ function DynamicButtonWithoutBehavior(props) {
14764
+ var _a, _b;
14754
14765
  const { component, onAction } = props;
14755
14766
  const componentAction = component.action;
14756
- const type = getButtonType(component);
14757
- const priority = getButtonPriority(component);
14767
+ const type = getButtonType(component.context, componentAction);
14768
+ const priority = getButtonPriority(component.control, componentAction);
14769
+ const { loading } = useDynamicFlow();
14770
+ const className = getMargin2(component.margin || "md");
14771
+ const disabled = loading || component.disabled || (componentAction == null ? void 0 : componentAction.disabled);
14772
+ const title = (_b = (_a = component.title) != null ? _a : componentAction == null ? void 0 : componentAction.title) != null ? _b : "";
14773
+ const onClick = () => {
14774
+ if (componentAction) {
14775
+ onAction(componentAction);
14776
+ }
14777
+ };
14778
+ return /* @__PURE__ */ jsx72(
14779
+ Button6,
14780
+ {
14781
+ size: getButtonSize(component.size),
14782
+ type: priority === "tertiary" ? void 0 : type,
14783
+ priority,
14784
+ block: true,
14785
+ className,
14786
+ disabled,
14787
+ onClick,
14788
+ children: title
14789
+ }
14790
+ );
14791
+ }
14792
+ function DynamicButtonWithBehavior(props) {
14793
+ var _a, _b;
14794
+ const { component } = props;
14795
+ const type = getButtonTypeFromContext(component.context);
14796
+ const priority = (_a = component.control) != null ? _a : "secondary";
14758
14797
  const { loading } = useDynamicFlow();
14759
14798
  const className = getMargin2(component.margin || "md");
14799
+ const disabled = loading || component.disabled;
14800
+ const title = (_b = component.title) != null ? _b : "";
14801
+ const onClick = () => {
14802
+ const { behavior } = component;
14803
+ if (behavior == null ? void 0 : behavior.action) {
14804
+ props.onAction(behavior.action);
14805
+ }
14806
+ if (behavior == null ? void 0 : behavior.link) {
14807
+ window.open(behavior.link.url, "_blank");
14808
+ }
14809
+ };
14760
14810
  return /* @__PURE__ */ jsx72(
14761
14811
  Button6,
14762
14812
  {
@@ -14765,9 +14815,9 @@ function DynamicButton(props) {
14765
14815
  priority,
14766
14816
  block: true,
14767
14817
  className,
14768
- disabled: loading || component.disabled || componentAction.disabled,
14769
- onClick: () => onAction(componentAction),
14770
- children: (_a = component.title) != null ? _a : componentAction.title
14818
+ disabled,
14819
+ onClick,
14820
+ children: title
14771
14821
  }
14772
14822
  );
14773
14823
  }
@@ -16311,7 +16361,7 @@ var _FormControl = class _FormControl extends PureComponent {
16311
16361
  UNSAFE_inputAttributes: {
16312
16362
  id,
16313
16363
  "aria-invalid": invalid,
16314
- "aria-labelledby": void 0,
16364
+ "aria-labelledby": labelledBy,
16315
16365
  "aria-describedby": describedBy
16316
16366
  },
16317
16367
  onChange: this.handleOnChange
@@ -16343,7 +16393,7 @@ var _FormControl = class _FormControl extends PureComponent {
16343
16393
  UNSAFE_triggerButtonProps: {
16344
16394
  id,
16345
16395
  "aria-invalid": invalid,
16346
- "aria-labelledby": void 0,
16396
+ "aria-labelledby": labelledBy,
16347
16397
  "aria-describedby": describedBy
16348
16398
  },
16349
16399
  items: items.map((value2) => ({
@@ -16864,11 +16914,12 @@ function OneOfSchema(props) {
16864
16914
  "has-error": !changed && props.errors && !isEmpty(props.errors) || (props.submitted || changed && blurred) && validations.length
16865
16915
  };
16866
16916
  const feedbackId = `${id}-feedback`;
16917
+ const labelId = `${id}-label`;
16867
16918
  return /* @__PURE__ */ jsxs32(Fragment15, { children: [
16868
16919
  (props.schema.oneOf.length > 1 || isConstSchema2(props.schema.oneOf[0])) && /* @__PURE__ */ jsxs32(Fragment15, { children: [
16869
16920
  props.schema.alert && /* @__PURE__ */ jsx91(DynamicAlert_default, { component: props.schema.alert }),
16870
16921
  /* @__PURE__ */ jsxs32("div", { className: (0, import_classnames11.default)(formGroupClasses), children: [
16871
- getTitleAndHelp(props.schema, id),
16922
+ getTitleAndHelp(props.schema, id, labelId),
16872
16923
  /* @__PURE__ */ jsx91(
16873
16924
  SchemaFormControl_default,
16874
16925
  {
@@ -16878,6 +16929,7 @@ function OneOfSchema(props) {
16878
16929
  disabled,
16879
16930
  invalid: !isEmpty(props.errors) || validations.length > 0,
16880
16931
  describedBy: feedbackId,
16932
+ labelledBy: labelId,
16881
16933
  required,
16882
16934
  onChange: onChooseNewSchema,
16883
16935
  onFocus,
@@ -16916,10 +16968,10 @@ function OneOfSchema(props) {
16916
16968
  )
16917
16969
  ] });
16918
16970
  }
16919
- function getTitleAndHelp(schema, forId) {
16971
+ function getTitleAndHelp(schema, forId, labelId) {
16920
16972
  var _a;
16921
16973
  const helpElement = schema.help ? /* @__PURE__ */ jsx91(Help_default2, { help: schema.help }) : null;
16922
- const titleElement = isConstSchema2(schema.oneOf[0]) ? /* @__PURE__ */ jsx91("div", { className: "m-b-1", children: /* @__PURE__ */ jsxs32("label", { className: "control-label d-inline", htmlFor: forId, children: [
16974
+ const titleElement = isConstSchema2(schema.oneOf[0]) ? /* @__PURE__ */ jsx91("div", { className: "m-b-1", children: /* @__PURE__ */ jsxs32("label", { className: "control-label d-inline", id: labelId, htmlFor: forId, children: [
16923
16975
  schema.title,
16924
16976
  " ",
16925
16977
  helpElement
@@ -1,7 +1,9 @@
1
- import type { ButtonLayout } from '@wise/dynamic-flow-types';
1
+ import type { Behavior, ButtonLayout } from '@wise/dynamic-flow-types';
2
2
  import type { CommonLayoutProps } from '../DynamicLayout';
3
3
  type Props = Omit<CommonLayoutProps, 'submitted' | 'onModelChange' | 'onPersistAsync'> & {
4
- component: ButtonLayout;
4
+ component: ButtonLayout & {
5
+ behavior?: Behavior;
6
+ };
5
7
  };
6
8
  declare function DynamicButton(props: Props): import("react/jsx-runtime").JSX.Element;
7
9
  export default DynamicButton;
@@ -1,4 +1,5 @@
1
- import type { ButtonLayout, Size } from '@wise/dynamic-flow-types';
2
- export declare const getButtonPriority: (component: ButtonLayout) => "primary" | "secondary" | "tertiary";
3
- export declare const getButtonType: (component: ButtonLayout) => "positive" | "negative" | "accent";
1
+ import type { Action, Size } from '@wise/dynamic-flow-types';
2
+ export declare const getButtonPriority: (control: "primary" | "secondary" | "tertiary" | undefined, action: Action | undefined) => "primary" | "secondary" | "tertiary";
3
+ export declare const getButtonType: (context: "positive" | "negative" | "neutral" | undefined, action: Action | undefined) => "positive" | "negative" | "accent";
4
+ export declare const getButtonTypeFromContext: (context: "positive" | "negative" | "neutral" | undefined) => "positive" | "negative" | "accent";
4
5
  export declare const getButtonSize: (size: Size | undefined) => "sm" | "md" | "lg";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/dynamic-flow-client",
3
- "version": "3.20.1",
3
+ "version": "3.21.0",
4
4
  "description": "Dynamic Flow web client",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./build/main.min.js",
@@ -103,7 +103,7 @@
103
103
  "nanoid": "5.0.7",
104
104
  "react-webcam": "^7.2.0",
105
105
  "screenfull": "^5.2.0",
106
- "@wise/dynamic-flow-types": "2.22.4"
106
+ "@wise/dynamic-flow-types": "2.23.1"
107
107
  },
108
108
  "scripts": {
109
109
  "dev": "pnpm build:visual-tests && storybook dev -p 3003",