policyengine-household-wizard 0.1.0 → 0.2.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.
Files changed (53) hide show
  1. package/README.md +37 -2
  2. package/dist/WizardReviewList-DhLx8Bla.cjs +1 -0
  3. package/dist/WizardReviewList-oY1HqmLw.js +354 -0
  4. package/dist/index-B_OXaS4a.cjs +1 -0
  5. package/dist/index-DWM0giHt.js +220 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.js +34 -28
  8. package/dist/primitives/WizardReviewList.d.ts +3 -2
  9. package/dist/primitives/WizardReviewList.d.ts.map +1 -1
  10. package/dist/primitives/index.d.ts +3 -1
  11. package/dist/primitives/index.d.ts.map +1 -1
  12. package/dist/primitives/types.d.ts +18 -0
  13. package/dist/primitives/types.d.ts.map +1 -1
  14. package/dist/primitives/useWizardStepFocus.d.ts +13 -0
  15. package/dist/primitives/useWizardStepFocus.d.ts.map +1 -0
  16. package/dist/primitives/useWizardSteps.d.ts +1 -1
  17. package/dist/primitives/useWizardSteps.d.ts.map +1 -1
  18. package/dist/primitives.cjs +1 -1
  19. package/dist/primitives.js +5 -4
  20. package/dist/us-household/adapters/v1Payload.d.ts +119 -3
  21. package/dist/us-household/adapters/v1Payload.d.ts.map +1 -1
  22. package/dist/us-household/amount.d.ts +8 -0
  23. package/dist/us-household/amount.d.ts.map +1 -0
  24. package/dist/us-household/index.d.ts +2 -1
  25. package/dist/us-household/index.d.ts.map +1 -1
  26. package/dist/us-household/normalize.d.ts.map +1 -1
  27. package/dist/us-household/serialize.d.ts.map +1 -1
  28. package/dist/us-household/tippedOccupations.d.ts +40 -0
  29. package/dist/us-household/tippedOccupations.d.ts.map +1 -0
  30. package/dist/us-household/types.d.ts +137 -4
  31. package/dist/us-household/types.d.ts.map +1 -1
  32. package/dist/us-household/validate.d.ts.map +1 -1
  33. package/dist/us-household-adapters.cjs +1 -1
  34. package/dist/us-household-adapters.js +3 -90
  35. package/dist/us-household.cjs +1 -1
  36. package/dist/us-household.js +346 -246
  37. package/package.json +4 -1
  38. package/src/primitives/WizardReviewList.tsx +35 -18
  39. package/src/primitives/index.ts +3 -0
  40. package/src/primitives/types.ts +20 -0
  41. package/src/primitives/useWizardStepFocus.ts +42 -0
  42. package/src/primitives/useWizardSteps.ts +181 -84
  43. package/src/styles.css +9 -0
  44. package/src/us-household/adapters/v1Payload.ts +211 -18
  45. package/src/us-household/amount.ts +10 -0
  46. package/src/us-household/index.ts +11 -0
  47. package/src/us-household/normalize.ts +79 -4
  48. package/src/us-household/serialize.ts +5 -1
  49. package/src/us-household/tippedOccupations.ts +145 -0
  50. package/src/us-household/types.ts +143 -4
  51. package/src/us-household/validate.ts +101 -4
  52. package/dist/WizardReviewList-De9RTK_4.js +0 -245
  53. package/dist/WizardReviewList-tfP9LcqU.cjs +0 -1
@@ -1,29 +1,127 @@
1
1
  export type USMaritalStatus = 'single' | 'married';
2
2
 
3
+ /**
4
+ * `'dependent'` means claimed as a tax dependent by someone in the household;
5
+ * `'adult'` means not claimed. Choose it from the user's answer, not from age.
6
+ * The V1 adapter sends it for every person as `is_tax_unit_dependent`. It puts
7
+ * everyone in one tax unit, where PolicyEngine US makes the two oldest adults
8
+ * head and spouse. Any other adult is then neither head, spouse nor
9
+ * dependent, and their income counts in the unit's gross income.
10
+ */
3
11
  export type USPersonKind = 'adult' | 'dependent';
4
12
 
5
13
  /**
6
14
  * Person-level fields that the wizard surfaces uniformly across apps. Apps that
7
- * do not collect a flag should leave it `undefined`; the adapters treat
8
- * `undefined` differently from `false` (omitted vs. explicitly set).
15
+ * do not collect a flag should leave it `undefined`. The V1 adapter sends only
16
+ * `true` and `false`; for these flags `false` and `undefined` give the same
17
+ * model results, and the difference matters to review screens and links.
9
18
  */
10
19
  export interface USPersonFlags {
11
20
  isDisabled?: boolean;
12
21
  isBlind?: boolean;
22
+ /**
23
+ * Full-time student at any level. PolicyEngine US counts everyone aged 5 to
24
+ * 17 as a K-12 student by age, so the V1 adapter sends this only from age 18,
25
+ * as full-time college enrollment ("is_full_time_college_student"). Rules
26
+ * for college students (for example SNAP's student rule and New Jersey's
27
+ * exemption for dependents attending college) then count that person.
28
+ */
13
29
  isFullTimeStudent?: boolean;
14
30
  isPregnant?: boolean;
15
31
  needsCare?: boolean;
16
32
  }
17
33
 
34
+ /**
35
+ * Annual amounts in dollars. Fields are additive, so an amount belongs in
36
+ * exactly one field. Each field sets its own PolicyEngine US variable, except
37
+ * that `pensionIncome` and `privatePensionIncome` share one and are summed,
38
+ * and `tipIncome` is also added to wages.
39
+ */
18
40
  export interface USPersonIncomes {
19
- /** Wages and salaries; "employment_income" in PolicyEngine US. */
41
+ /**
42
+ * Wages and salaries, not counting tips entered in `tipIncome`;
43
+ * "employment_income" in PolicyEngine US.
44
+ */
20
45
  employmentIncome?: number;
46
+ /**
47
+ * Tips received as an employee; "tip_income" in PolicyEngine US.
48
+ * PolicyEngine US counts tips as part of wages (`employment_income` is
49
+ * wages "including tips and commissions"), and income and payroll taxes
50
+ * read `employment_income`. A few rules read `tip_income` on its own, such
51
+ * as the federal deduction for qualified tips (2025-2028) and Georgia's cash
52
+ * tip exclusion. So the V1 adapter sends these tips both as `tip_income` and
53
+ * added to `employment_income`. Tips can count for the deduction only with a
54
+ * listed `tippedOccupationCode`. A self-employed worker's tips belong in
55
+ * `selfEmploymentIncome`, which the adapter does not send as `tip_income`.
56
+ */
57
+ tipIncome?: number;
58
+ /** "self_employment_income" in PolicyEngine US. */
21
59
  selfEmploymentIncome?: number;
60
+ /**
61
+ * Social Security retirement benefits; "social_security_retirement" in
62
+ * PolicyEngine US. Put SSDI in `ssdiAmount`, not here: the model adds the two
63
+ * to get total Social Security. Survivors or dependents benefits entered here
64
+ * count as retirement benefits.
65
+ */
22
66
  socialSecurityIncome?: number;
67
+ /**
68
+ * Reported Supplemental Security Income; "ssi" in PolicyEngine US. It
69
+ * replaces the model's own SSI calculation, and that works for a whole
70
+ * household only: an `ssi` input for one person would stop the model from
71
+ * computing everyone else's. So the V1 adapter sends amounts only when every
72
+ * person has one, and `validate()` asks for the missing ones. Enter 0 for a
73
+ * person who receives none; a 0 is always sent, as
74
+ * "takes_up_ssi_if_eligible" false. Leave it blank to let the model compute
75
+ * a person's SSI.
76
+ */
23
77
  ssiAmount?: number;
78
+ /** Social Security Disability Insurance; "social_security_disability" in PolicyEngine US. */
24
79
  ssdiAmount?: number;
80
+ /**
81
+ * Taxable pension income whose source the user did not give. The V1 adapter
82
+ * adds it to `privatePensionIncome`. Some states' rules in PolicyEngine US
83
+ * apply only to government pensions (for example, Arizona's public pension
84
+ * exclusion and Minnesota's public pension subtraction), so ask for
85
+ * `publicPensionIncome` when the app can. The adapter never sets the
86
+ * `taxable_pension_income` total: that would leave both components at zero,
87
+ * so rules that read either component would see nothing.
88
+ */
25
89
  pensionIncome?: number;
90
+ /**
91
+ * Taxable pension income from a government employer;
92
+ * "taxable_public_pension_income" in PolicyEngine US. PolicyEngine US also
93
+ * has a separate `taxable_federal_pension_income` input, read by West
94
+ * Virginia's public pension subtraction and (from 2.6.14) Indiana's civil
95
+ * service annuity deduction; the adapter does not set it.
96
+ */
97
+ publicPensionIncome?: number;
98
+ /**
99
+ * Taxable pension income from a non-government employer;
100
+ * "taxable_private_pension_income" in PolicyEngine US.
101
+ */
102
+ privatePensionIncome?: number;
103
+ /** Qualified dividends; "qualified_dividend_income" in PolicyEngine US. */
26
104
  dividendIncome?: number;
105
+ /**
106
+ * Ordinary dividends that are not qualified;
107
+ * "non_qualified_dividend_income" in PolicyEngine US. Form 1099-DIV's
108
+ * ordinary dividends (box 1a) are the sum of this and `dividendIncome`
109
+ * (box 1b).
110
+ */
111
+ nonQualifiedDividendIncome?: number;
112
+ /**
113
+ * Net gains on assets held one year or less, negative for a net loss;
114
+ * "short_term_capital_gains" in PolicyEngine US.
115
+ */
116
+ shortTermCapitalGains?: number;
117
+ /**
118
+ * Net gains on assets held more than one year, negative for a net loss;
119
+ * "long_term_capital_gains" in PolicyEngine US. That variable is computed as
120
+ * gains before behavioral responses plus the response, and PolicyEngine US's
121
+ * Simulation moves an input on it onto
122
+ * `long_term_capital_gains_before_response`, as it does for wages.
123
+ */
124
+ longTermCapitalGains?: number;
27
125
  taxableInterestIncome?: number;
28
126
  rentalIncome?: number;
29
127
  unemploymentCompensation?: number;
@@ -31,7 +129,48 @@ export interface USPersonIncomes {
31
129
  miscellaneousIncome?: number;
32
130
  }
33
131
 
34
- export interface USPersonDraft extends USPersonFlags, USPersonIncomes {
132
+ /**
133
+ * Annual amounts paid, in dollars, that PolicyEngine US deducts or credits.
134
+ * Each field sets one PolicyEngine US input variable. Federal deductions sum
135
+ * the tax unit's amounts, so an app that asks about a shared expense once can
136
+ * put it on one adult, ideally the one who pays it or owns the home. Some
137
+ * state rules read a person's own amount: Montana caps real estate taxes per
138
+ * person, and homestead or elderly property tax reductions in Kentucky, Ohio,
139
+ * South Carolina, Mississippi and Tennessee read the owner's (Kentucky) or the
140
+ * head's or spouse's real estate taxes.
141
+ */
142
+ export interface USPersonExpenses {
143
+ /** Gifts of cash to charity; "charitable_cash_donations" in PolicyEngine US. */
144
+ charitableCashDonations?: number;
145
+ /**
146
+ * Interest paid on a home mortgage; "home_mortgage_interest" in PolicyEngine
147
+ * US. Not "mortgage_interest": that is a computed total of deductible and
148
+ * non-deductible interest, and the federal interest deduction ignores an
149
+ * input on it.
150
+ */
151
+ mortgageInterest?: number;
152
+ /** Real estate (property) taxes paid; "real_estate_taxes" in PolicyEngine US. */
153
+ realEstateTaxes?: number;
154
+ }
155
+
156
+ /** Work details that rules read alongside income. */
157
+ export interface USPersonOccupation {
158
+ /**
159
+ * Treasury Tipped Occupation Code for the occupation in which the person
160
+ * received `tipIncome` (see `TIPPED_OCCUPATIONS`), or 0 if it is not a
161
+ * listed occupation; "treasury_tipped_occupation_code" in PolicyEngine US.
162
+ * Only tips from a listed occupation qualify for the federal deduction for
163
+ * qualified tips. Leave it unset if the user was not asked: PolicyEngine US
164
+ * then reads 0, so tips get no deduction.
165
+ */
166
+ tippedOccupationCode?: number;
167
+ }
168
+
169
+ export interface USPersonDraft
170
+ extends USPersonFlags,
171
+ USPersonIncomes,
172
+ USPersonExpenses,
173
+ USPersonOccupation {
35
174
  /** Stable identifier — used as the person key in the API payload. */
36
175
  id: string;
37
176
  kind: USPersonKind;
@@ -1,6 +1,34 @@
1
+ import { toAmount } from './amount';
1
2
  import { isUSStateCode } from './states';
2
3
  import { isCountyCode } from './counties';
3
- import type { USHouseholdDraft, ValidationIssue, ValidationResult } from './types';
4
+ import { toTippedOccupationCode } from './tippedOccupations';
5
+ import type {
6
+ USHouseholdDraft,
7
+ USPersonDraft,
8
+ USPersonExpenses,
9
+ ValidationIssue,
10
+ ValidationResult,
11
+ } from './types';
12
+
13
+ const EXPENSE_LABELS: Readonly<Record<keyof USPersonExpenses, string>> = {
14
+ charitableCashDonations: 'Charitable cash donations',
15
+ mortgageInterest: 'Mortgage interest',
16
+ realEstateTaxes: 'Real estate taxes',
17
+ };
18
+
19
+ /**
20
+ * "adult 2" or "dependent 1": people are numbered within their kind, in draft
21
+ * order, matching the labels apps show.
22
+ */
23
+ function personLabel(people: USPersonDraft[], index: number): string {
24
+ const { kind } = people[index];
25
+ const ordinal = people.slice(0, index + 1).filter((person) => person.kind === kind).length;
26
+ return `${kind} ${ordinal}`;
27
+ }
28
+
29
+ function capitalize(text: string): string {
30
+ return text.charAt(0).toUpperCase() + text.slice(1);
31
+ }
4
32
 
5
33
  export interface ValidateOptions {
6
34
  /**
@@ -72,12 +100,81 @@ export function validate(
72
100
  });
73
101
  }
74
102
 
103
+ // An `ssi` amount sent for one person stops PolicyEngine US from computing
104
+ // SSI for everyone else. So the V1 adapter sends entered amounts only when
105
+ // everyone has one (0 included), and the missing ones are asked for here.
106
+ const someoneReceivesSsi = draft.people.some((person) => {
107
+ const amount = toAmount(person.ssiAmount);
108
+ return amount !== undefined && amount !== 0;
109
+ });
110
+
75
111
  draft.people.forEach((person, index) => {
112
+ const label = personLabel(draft.people, index);
76
113
  if (requireAges && (person.age === null || person.age === undefined)) {
77
114
  issues.push({
78
115
  code: 'person.age.required',
79
116
  path: `people[${index}].age`,
80
- message: `Age is required for ${person.kind === 'adult' ? `adult ${index + 1}` : `dependent ${index + 1}`}.`,
117
+ message: `Age is required for ${label}.`,
118
+ });
119
+ }
120
+
121
+ for (const [field, fieldLabel] of Object.entries(EXPENSE_LABELS)) {
122
+ const amount = toAmount(person[field as keyof USPersonExpenses]);
123
+ if (amount !== undefined && amount < 0) {
124
+ issues.push({
125
+ code: `person.${field}.negative`,
126
+ path: `people[${index}].${field}`,
127
+ message: `${fieldLabel} for ${label} cannot be negative.`,
128
+ });
129
+ }
130
+ }
131
+
132
+ const wages = toAmount(person.employmentIncome);
133
+ if (wages !== undefined && wages < 0) {
134
+ issues.push({
135
+ code: 'person.employmentIncome.negative',
136
+ path: `people[${index}].employmentIncome`,
137
+ message: `Wages for ${label} cannot be negative.`,
138
+ });
139
+ }
140
+
141
+ const tips = toAmount(person.tipIncome);
142
+ if (tips !== undefined && tips < 0) {
143
+ issues.push({
144
+ code: 'person.tipIncome.negative',
145
+ path: `people[${index}].tipIncome`,
146
+ message: `Tips for ${label} cannot be negative.`,
147
+ });
148
+ }
149
+
150
+ // The V1 adapter sends only listed codes and 0, so any other answer would
151
+ // be dropped silently. Without an answer, the model reads 0 and tips get
152
+ // no deduction; apps that do not ask about the deduction can treat
153
+ // `person.tippedOccupationCode.requiredWithTips` as a warning.
154
+ const occupationCode = person.tippedOccupationCode as unknown;
155
+ const answeredOccupation =
156
+ occupationCode !== undefined &&
157
+ occupationCode !== null &&
158
+ !(typeof occupationCode === 'string' && occupationCode.trim() === '');
159
+ if (answeredOccupation && toTippedOccupationCode(occupationCode) === undefined) {
160
+ issues.push({
161
+ code: 'person.tippedOccupationCode.invalid',
162
+ path: `people[${index}].tippedOccupationCode`,
163
+ message: `Tipped occupation code ${String(occupationCode)} for ${label} is not on the Treasury list.`,
164
+ });
165
+ } else if (!answeredOccupation && tips !== undefined && tips > 0) {
166
+ issues.push({
167
+ code: 'person.tippedOccupationCode.requiredWithTips',
168
+ path: `people[${index}].tippedOccupationCode`,
169
+ message: `Tipped occupation is required for ${label} because they receive tips. Enter 0 if it is not on the Treasury list.`,
170
+ });
171
+ }
172
+
173
+ if (someoneReceivesSsi && toAmount(person.ssiAmount) === undefined) {
174
+ issues.push({
175
+ code: 'person.ssiAmount.requiredWhenAnyReceives',
176
+ path: `people[${index}].ssiAmount`,
177
+ message: `SSI is required for ${label} because someone in the household receives SSI. Enter 0 if they receive none.`,
81
178
  });
82
179
  }
83
180
 
@@ -97,14 +194,14 @@ export function validate(
97
194
  issues.push({
98
195
  code: 'person.age.dependentTooOld',
99
196
  path: `people[${index}].age`,
100
- message: `Dependent ${index + 1} is older than 23; confirm they qualify.`,
197
+ message: `${capitalize(label)} is older than 23; confirm they qualify.`,
101
198
  });
102
199
  }
103
200
  if (person.kind === 'adult' && person.age < 14) {
104
201
  issues.push({
105
202
  code: 'person.age.adultTooYoung',
106
203
  path: `people[${index}].age`,
107
- message: `Adult ${index + 1} is younger than 14.`,
204
+ message: `${capitalize(label)} is younger than 14.`,
108
205
  });
109
206
  }
110
207
  }
@@ -1,245 +0,0 @@
1
- import { useMemo as N, useState as P, useEffect as W, useRef as R, useCallback as b } from "react";
2
- import { jsxs as m, jsx as l, Fragment as V } from "react/jsx-runtime";
3
- function C(r, s) {
4
- return r.filter((a) => a.isVisible ? a.isVisible(s) : !0);
5
- }
6
- function S(r) {
7
- return { id: r.id, label: r.label };
8
- }
9
- function B(r, s) {
10
- return r.length === 0 ? null : s && r.some((a) => a.id === s) ? s : r[0].id;
11
- }
12
- function D(r) {
13
- const { steps: s, state: a, initialStepId: i, onStepChange: t } = r, e = N(
14
- () => C(s, a),
15
- [s, a]
16
- ), o = N(
17
- () => e.map(S),
18
- [e]
19
- ), u = N(
20
- () => B(e, i),
21
- // Only recompute when explicit initialStepId or the set of step ids changes.
22
- // eslint-disable-next-line react-hooks/exhaustive-deps
23
- [i]
24
- ), [c, d] = P(u);
25
- W(() => {
26
- if (e.length === 0) {
27
- c !== null && d(null);
28
- return;
29
- }
30
- e.some((w) => w.id === c) || d(e[0].id);
31
- }, [e, c]);
32
- const f = R(t);
33
- W(() => {
34
- f.current = t;
35
- }, [t]);
36
- const v = b((p) => {
37
- d((w) => {
38
- var k;
39
- return w === p ? w : ((k = f.current) == null || k.call(f, p), p);
40
- });
41
- }, []), n = N(
42
- () => e.findIndex((p) => p.id === c),
43
- [e, c]
44
- ), h = n >= 0 ? e[n] : null, x = h ? S(h) : null, z = e.length, g = n <= 0, y = z === 0 ? !0 : n === z - 1, j = h != null && h.isComplete ? h.isComplete(a) : !0, M = b(() => {
45
- n < 0 || n >= e.length - 1 || v(e[n + 1].id);
46
- }, [n, e, v]), $ = b(() => {
47
- n <= 0 || v(e[n - 1].id);
48
- }, [n, e, v]), E = b(
49
- (p) => {
50
- e.some((w) => w.id === p) && v(p);
51
- },
52
- [e, v]
53
- ), I = b(() => {
54
- const p = B(e, i);
55
- p && v(p);
56
- }, [e, i, v]);
57
- return {
58
- visibleSteps: o,
59
- currentStep: x,
60
- currentStepIndex: n,
61
- totalSteps: z,
62
- isFirstStep: g,
63
- isLastStep: y,
64
- canAdvance: j,
65
- goNext: M,
66
- goBack: $,
67
- goToStep: E,
68
- reset: I
69
- };
70
- }
71
- function O({
72
- totalSteps: r,
73
- currentStepIndex: s,
74
- currentStepLabel: a,
75
- className: i,
76
- ...t
77
- }) {
78
- const e = Math.max(r, 0), o = Math.max(0, Math.min(s, e - 1)), u = e > 0 ? (o + 1) / e * 100 : 0, c = e > 0 ? o + 1 : 0, d = { width: `${u}%` };
79
- return /* @__PURE__ */ m(
80
- "div",
81
- {
82
- role: "group",
83
- "aria-label": t["aria-label"] ?? "Wizard progress",
84
- className: ["pe-wizard-progress", i].filter(Boolean).join(" "),
85
- ...t,
86
- children: [
87
- /* @__PURE__ */ m("div", { className: "pe-wizard-progress-topline", children: [
88
- /* @__PURE__ */ m("span", { "data-testid": "pe-wizard-progress-step", children: [
89
- "Step ",
90
- c,
91
- " of ",
92
- e
93
- ] }),
94
- a ? /* @__PURE__ */ l("span", { "data-testid": "pe-wizard-progress-label", children: a }) : null
95
- ] }),
96
- /* @__PURE__ */ l(
97
- "div",
98
- {
99
- className: "pe-wizard-progress-track",
100
- role: "progressbar",
101
- "aria-valuemin": 0,
102
- "aria-valuemax": e,
103
- "aria-valuenow": c,
104
- "aria-valuetext": a,
105
- children: /* @__PURE__ */ l("div", { className: "pe-wizard-progress-bar", style: d })
106
- }
107
- )
108
- ]
109
- }
110
- );
111
- }
112
- function q({
113
- selected: r = !1,
114
- title: s,
115
- description: a,
116
- onSelect: i,
117
- onClick: t,
118
- className: e,
119
- type: o,
120
- disabled: u,
121
- ...c
122
- }) {
123
- const d = ["pe-wizard-option-card"];
124
- return r && d.push("pe-wizard-option-card--selected"), e && d.push(e), /* @__PURE__ */ m(
125
- "button",
126
- {
127
- type: o ?? "button",
128
- role: "radio",
129
- "aria-checked": r,
130
- "aria-disabled": u ? !0 : void 0,
131
- disabled: u,
132
- className: d.join(" "),
133
- onClick: (f) => {
134
- u || (t == null || t(f), f.defaultPrevented || i == null || i());
135
- },
136
- ...c,
137
- children: [
138
- /* @__PURE__ */ l("span", { className: "pe-wizard-option-card-title", children: s }),
139
- a ? /* @__PURE__ */ l("span", { className: "pe-wizard-option-card-description", children: a }) : null
140
- ]
141
- }
142
- );
143
- }
144
- function A({
145
- canAdvance: r,
146
- isFirstStep: s,
147
- isLastStep: a,
148
- backLabel: i = "Back",
149
- continueLabel: t = "Continue",
150
- submitLabel: e = "Submit",
151
- busyLabel: o,
152
- busy: u = !1,
153
- onBack: c,
154
- onContinue: d,
155
- onSubmit: f,
156
- leadingActions: v,
157
- trailingActions: n,
158
- hideBack: h = !1,
159
- className: x,
160
- ...z
161
- }) {
162
- const g = u || !r, y = u && o ? o : a ? e : t, j = () => {
163
- g || (a ? f == null || f() : d == null || d());
164
- };
165
- return /* @__PURE__ */ m(
166
- "div",
167
- {
168
- className: ["pe-wizard-nav", x].filter(Boolean).join(" "),
169
- ...z,
170
- children: [
171
- v ? /* @__PURE__ */ l("div", { className: "pe-wizard-nav-leading", children: v }) : null,
172
- h ? null : /* @__PURE__ */ l(
173
- "button",
174
- {
175
- type: "button",
176
- className: "pe-wizard-nav-back",
177
- onClick: c,
178
- disabled: s || u,
179
- "aria-label": typeof i == "string" ? i : void 0,
180
- children: i
181
- }
182
- ),
183
- /* @__PURE__ */ l(
184
- "button",
185
- {
186
- type: "button",
187
- className: "pe-wizard-nav-primary",
188
- onClick: j,
189
- disabled: g,
190
- "aria-disabled": g,
191
- children: y
192
- }
193
- ),
194
- n ? /* @__PURE__ */ l("div", { className: "pe-wizard-nav-trailing", children: n }) : null
195
- ]
196
- }
197
- );
198
- }
199
- function G({ items: r, className: s, ...a }) {
200
- return /* @__PURE__ */ l(
201
- "div",
202
- {
203
- className: ["pe-wizard-review-list", s].filter(Boolean).join(" "),
204
- role: "list",
205
- ...a,
206
- children: r.map((i) => {
207
- const t = ["pe-wizard-review-item"];
208
- i.missing && t.push("pe-wizard-review-item--missing");
209
- const e = typeof i.onEdit == "function", o = /* @__PURE__ */ m(V, { children: [
210
- /* @__PURE__ */ l("span", { className: "pe-wizard-review-item-label", children: i.label }),
211
- /* @__PURE__ */ l("span", { className: "pe-wizard-review-item-value", children: i.missing && (i.value === null || i.value === void 0 || i.value === "") ? "Missing" : i.value })
212
- ] });
213
- return e ? /* @__PURE__ */ l(
214
- "button",
215
- {
216
- type: "button",
217
- role: "listitem",
218
- className: t.join(" "),
219
- "data-testid": `pe-wizard-review-${i.id}`,
220
- onClick: i.onEdit,
221
- "aria-label": typeof i.label == "string" ? `${i.editLabel ?? "Edit"} ${i.label}` : void 0,
222
- children: o
223
- },
224
- i.id
225
- ) : /* @__PURE__ */ l(
226
- "div",
227
- {
228
- role: "listitem",
229
- className: t.join(" "),
230
- "data-testid": `pe-wizard-review-${i.id}`,
231
- children: o
232
- },
233
- i.id
234
- );
235
- })
236
- }
237
- );
238
- }
239
- export {
240
- A as W,
241
- q as a,
242
- O as b,
243
- G as c,
244
- D as u
245
- };
@@ -1 +0,0 @@
1
- "use strict";const o=require("react"),s=require("react/jsx-runtime");function B(r,t){return r.filter(a=>a.isVisible?a.isVisible(t):!0)}function k(r){return{id:r.id,label:r.label}}function y(r,t){return r.length===0?null:t&&r.some(a=>a.id===t)?t:r[0].id}function E(r){const{steps:t,state:a,initialStepId:i,onStepChange:n}=r,e=o.useMemo(()=>B(t,a),[t,a]),c=o.useMemo(()=>e.map(k),[e]),f=o.useMemo(()=>y(e,i),[i]),[u,d]=o.useState(f);o.useEffect(()=>{if(e.length===0){u!==null&&d(null);return}e.some(h=>h.id===u)||d(e[0].id)},[e,u]);const v=o.useRef(n);o.useEffect(()=>{v.current=n},[n]);const w=o.useCallback(p=>{d(h=>{var N;return h===p?h:((N=v.current)==null||N.call(v,p),p)})},[]),l=o.useMemo(()=>e.findIndex(p=>p.id===u),[e,u]),z=l>=0?e[l]:null,g=z?k(z):null,m=e.length,x=l<=0,j=m===0?!0:l===m-1,b=z!=null&&z.isComplete?z.isComplete(a):!0,W=o.useCallback(()=>{l<0||l>=e.length-1||w(e[l+1].id)},[l,e,w]),M=o.useCallback(()=>{l<=0||w(e[l-1].id)},[l,e,w]),C=o.useCallback(p=>{e.some(h=>h.id===p)&&w(p)},[e,w]),S=o.useCallback(()=>{const p=y(e,i);p&&w(p)},[e,i,w]);return{visibleSteps:c,currentStep:g,currentStepIndex:l,totalSteps:m,isFirstStep:x,isLastStep:j,canAdvance:b,goNext:W,goBack:M,goToStep:C,reset:S}}function R({totalSteps:r,currentStepIndex:t,currentStepLabel:a,className:i,...n}){const e=Math.max(r,0),c=Math.max(0,Math.min(t,e-1)),f=e>0?(c+1)/e*100:0,u=e>0?c+1:0,d={width:`${f}%`};return s.jsxs("div",{role:"group","aria-label":n["aria-label"]??"Wizard progress",className:["pe-wizard-progress",i].filter(Boolean).join(" "),...n,children:[s.jsxs("div",{className:"pe-wizard-progress-topline",children:[s.jsxs("span",{"data-testid":"pe-wizard-progress-step",children:["Step ",u," of ",e]}),a?s.jsx("span",{"data-testid":"pe-wizard-progress-label",children:a}):null]}),s.jsx("div",{className:"pe-wizard-progress-track",role:"progressbar","aria-valuemin":0,"aria-valuemax":e,"aria-valuenow":u,"aria-valuetext":a,children:s.jsx("div",{className:"pe-wizard-progress-bar",style:d})})]})}function $({selected:r=!1,title:t,description:a,onSelect:i,onClick:n,className:e,type:c,disabled:f,...u}){const d=["pe-wizard-option-card"];return r&&d.push("pe-wizard-option-card--selected"),e&&d.push(e),s.jsxs("button",{type:c??"button",role:"radio","aria-checked":r,"aria-disabled":f?!0:void 0,disabled:f,className:d.join(" "),onClick:v=>{f||(n==null||n(v),v.defaultPrevented||i==null||i())},...u,children:[s.jsx("span",{className:"pe-wizard-option-card-title",children:t}),a?s.jsx("span",{className:"pe-wizard-option-card-description",children:a}):null]})}function I({canAdvance:r,isFirstStep:t,isLastStep:a,backLabel:i="Back",continueLabel:n="Continue",submitLabel:e="Submit",busyLabel:c,busy:f=!1,onBack:u,onContinue:d,onSubmit:v,leadingActions:w,trailingActions:l,hideBack:z=!1,className:g,...m}){const x=f||!r,j=f&&c?c:a?e:n,b=()=>{x||(a?v==null||v():d==null||d())};return s.jsxs("div",{className:["pe-wizard-nav",g].filter(Boolean).join(" "),...m,children:[w?s.jsx("div",{className:"pe-wizard-nav-leading",children:w}):null,z?null:s.jsx("button",{type:"button",className:"pe-wizard-nav-back",onClick:u,disabled:t||f,"aria-label":typeof i=="string"?i:void 0,children:i}),s.jsx("button",{type:"button",className:"pe-wizard-nav-primary",onClick:b,disabled:x,"aria-disabled":x,children:j}),l?s.jsx("div",{className:"pe-wizard-nav-trailing",children:l}):null]})}function P({items:r,className:t,...a}){return s.jsx("div",{className:["pe-wizard-review-list",t].filter(Boolean).join(" "),role:"list",...a,children:r.map(i=>{const n=["pe-wizard-review-item"];i.missing&&n.push("pe-wizard-review-item--missing");const e=typeof i.onEdit=="function",c=s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"pe-wizard-review-item-label",children:i.label}),s.jsx("span",{className:"pe-wizard-review-item-value",children:i.missing&&(i.value===null||i.value===void 0||i.value==="")?"Missing":i.value})]});return e?s.jsx("button",{type:"button",role:"listitem",className:n.join(" "),"data-testid":`pe-wizard-review-${i.id}`,onClick:i.onEdit,"aria-label":typeof i.label=="string"?`${i.editLabel??"Edit"} ${i.label}`:void 0,children:c},i.id):s.jsx("div",{role:"listitem",className:n.join(" "),"data-testid":`pe-wizard-review-${i.id}`,children:c},i.id)})})}exports.WizardNavigation=I;exports.WizardOptionCard=$;exports.WizardProgress=R;exports.WizardReviewList=P;exports.useWizardSteps=E;