@nysds/nys-stepper 1.19.1 → 1.19.2

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,124 @@
1
+ import { LitElement } from "lit";
2
+ /**
3
+ * A single step within `nys-stepper`. Represents one stage in a multi-step process.
4
+ *
5
+ * Mark as `current` to indicate the active progress point. Previous steps become clickable for navigation.
6
+ * Set `href` for page-based navigation, or omit it and listen to `nys-step-click` for SPA/framework routing.
7
+ *
8
+ * ## Step states
9
+ *
10
+ * Three boolean attributes control step appearance and behavior:
11
+ *
12
+ * - **`current`** — The furthest step the user has reached (the progress boundary). Only one step should
13
+ * have `current` at a time; if multiple are set the parent stepper keeps the first and removes the rest.
14
+ * Steps after `current` are not navigable and do not fire `nys-step-click`. Update `current` in your
15
+ * application state when the user advances.
16
+ *
17
+ * - **`selected`** — Which step's content is currently displayed. Defaults to the `current` step if not
18
+ * explicitly set. If `selected` is placed on a step after `current`, the stepper silently corrects it
19
+ * to match `current`. When managing state from a framework, always set `selected` explicitly — without
20
+ * it the stepper's fallback will reset in-sidebar navigation on every state update.
21
+ *
22
+ * - **`previous`** — Auto-applied by the parent stepper to every step before `current`. Do not set this
23
+ * manually. Steps with `previous` are clickable and fire `nys-step-click`.
24
+ *
25
+ * ## `nys-step-click` firing conditions
26
+ *
27
+ * The event fires only when ALL of the following are true:
28
+ * 1. The step has `previous` or `current` (i.e. it is navigable).
29
+ * 2. The step does NOT already have `selected` (clicking the already-viewed step is a no-op).
30
+ *
31
+ * Steps that are neither `previous` nor `current` (future steps) never fire the event.
32
+ *
33
+ * ## `href` and navigation
34
+ *
35
+ * If `href` is set, the stepper calls `window.location.href = href` after dispatching `nys-step-click`
36
+ * — but only if the event was **not canceled**. To handle navigation yourself (SPA routing, fetch, etc.),
37
+ * always call `e.preventDefault()` in your listener. Omitting `href` entirely is simpler for SPAs.
38
+ *
39
+ * ## `onClick` vs `nys-step-click`
40
+ *
41
+ * The `onClick` property (a function reference, not a DOM attribute) is called **before** the
42
+ * `nys-step-click` event is dispatched. Use it for imperative pre-navigation logic. In React, pass it
43
+ * as the `onClick` prop on `NysStep`.
44
+ *
45
+ * ## Accessibility
46
+ * - The step label renders with `role="button"` and is keyboard-focusable (`tabindex="0"`) for navigable
47
+ * steps (`current`, `previous`). Future steps get `tabindex="-1"` and are not reachable by keyboard.
48
+ * - Enter and Space activate the step (same as click).
49
+ * - `aria-label` is set to `"{label} Step"` for screen reader announcement.
50
+ *
51
+ * ## Common patterns
52
+ *
53
+ * **Initial state:** Set `current` on the first step. `selected` defaults to it.
54
+ * ```html
55
+ * <nys-step label="Step 1" current></nys-step>
56
+ * <nys-step label="Step 2"></nys-step>
57
+ * ```
58
+ *
59
+ * **User completed step 1, now on step 2:**
60
+ * ```html
61
+ * <nys-step label="Step 1"></nys-step>
62
+ * <nys-step label="Step 2" current></nys-step>
63
+ * ```
64
+ *
65
+ * **User went back to review step 1 (progress still at step 2):**
66
+ * ```html
67
+ * <nys-step label="Step 1" selected></nys-step>
68
+ * <nys-step label="Step 2" current></nys-step>
69
+ * ```
70
+ *
71
+ * @summary Individual step for use within nys-stepper with navigation support.
72
+ * @element nys-step
73
+ *
74
+ * @fires nys-step-click - Fired when a navigable (`previous` or `current`) non-selected step is clicked
75
+ * or activated by keyboard. Detail: `{ href: string, label: string }`. Cancelable — call
76
+ * `e.preventDefault()` to suppress `window.location.href` navigation.
77
+ *
78
+ * @example Step with page navigation
79
+ * ```html
80
+ * <nys-step label="Personal Info" href="/step-1"></nys-step>
81
+ * ```
82
+ *
83
+ * @example Step with SPA navigation (no href)
84
+ * ```js
85
+ * step.addEventListener('nys-step-click', (e) => {
86
+ * e.preventDefault(); // no href set, but good practice
87
+ * showStepContent(e.detail.label);
88
+ * });
89
+ * ```
90
+ */
91
+ export declare class NysStep extends LitElement {
92
+ static styles: import("lit").CSSResult;
93
+ /**
94
+ * Which step is currently being displayed. If not set, defaults to the `current` step.
95
+ * Setting this on a step after `current` is silently corrected to match `current`.
96
+ * When controlling state from a framework, always set this explicitly.
97
+ */
98
+ selected: boolean;
99
+ /** The furthest step the user has reached (progress boundary). Steps before this are navigable. */
100
+ current: boolean;
101
+ /** Step label text displayed alongside the step number. */
102
+ label: string;
103
+ /**
104
+ * URL navigated to when the step is activated, via `window.location.href`.
105
+ * Navigation is suppressed if the `nys-step-click` listener calls `e.preventDefault()`.
106
+ * Omit for SPA/framework routing and handle navigation in the event listener instead.
107
+ */
108
+ href: string;
109
+ /**
110
+ * @internal Auto-applied by `nys-stepper` to every step that comes before `current`.
111
+ * Marks the step as navigable and clickable. Do not set this manually — the parent stepper
112
+ * adds and removes it on every render based on which step has `current`.
113
+ */
114
+ previous: boolean;
115
+ /** @internal Propagated by the parent stepper. Do not set manually. */
116
+ isCompactExpanded: boolean;
117
+ /** Optional function called before `nys-step-click` is dispatched. Use for pre-navigation logic. */
118
+ onClick?: (e: Event) => void;
119
+ /** @internal 1-indexed position. Auto-assigned by the parent stepper on first render. Do not set manually. */
120
+ stepNumber: number;
121
+ private _handleActivate;
122
+ private _handleKeydown;
123
+ render(): import("lit-html").TemplateResult<1>;
124
+ }
@@ -0,0 +1,158 @@
1
+ import { LitElement } from "lit";
2
+ import "./nys-step";
3
+ /**
4
+ * A multi-step progress indicator for forms or wizards. Manages `nys-step` children with selection and navigation.
5
+ *
6
+ * Add `nys-step` elements as children. Mark one step as `current` to indicate the progress boundary; all steps
7
+ * before it become navigable. Compact view on mobile expands to show all steps. Use the `actions` slot for
8
+ * persistent navigation buttons (e.g., Save & Exit). Do not place the stepper inside a `<form>` element —
9
+ * put form fields in the main content area alongside it.
10
+ *
11
+ * ## When to use
12
+ * - Linear, ordered forms or wizards with more than 2 sections.
13
+ *
14
+ * ## When not to use
15
+ * - Forms with only 1 or 2 sections — use a simpler layout.
16
+ * - Non-linear forms where sections can be completed in any order.
17
+ *
18
+ * ## Compact mode (mobile)
19
+ * On small screens the stepper collapses to a compact view: step labels are hidden and progress
20
+ * is shown as a bar indicator with a "Step x of y" counter. Clicking or pressing Enter/Space on
21
+ * the counter expands the full step list (counter text changes to "Back to Form"). Collapsing
22
+ * again returns the user to the form view.
23
+ *
24
+ * ## actions slot constraints
25
+ * The `actions` slot must contain exactly one `<div>` as its direct child. That `<div>` may only
26
+ * contain `<nys-button>` elements — any other element is removed with a console warning.
27
+ * The stepper automatically forces `size="sm"` on every button in the slot. Buttons with the
28
+ * `fullWidth` attribute get `flex: 1 1 0` injected so they share available width equally.
29
+ *
30
+ * ## Multiple `current` conflict
31
+ * If more than one `nys-step` has the `current` attribute, only the first one is kept; the rest
32
+ * are silently removed. Always mark exactly one step as `current`.
33
+ *
34
+ * ## id auto-generation
35
+ * If no `id` is provided, a unique id is generated automatically in the form
36
+ * `nys-stepper-{n}-{timestamp}`.
37
+ *
38
+ * ## Accessibility
39
+ * - The compact counter is rendered as a `role="button"` with `aria-expanded` and a descriptive
40
+ * `aria-label` that announces the current step (e.g., "Expand step navigation. You are on Step 2 of 4").
41
+ * - Keyboard: Enter or Space toggles the compact view.
42
+ * - Each `nys-step` label is keyboard-focusable and activatable for navigable steps.
43
+ * - Visual focus indicators are provided on all interactive elements.
44
+ *
45
+ * @summary Multi-step progress indicator with navigation and mobile-friendly compact view.
46
+ * @element nys-stepper
47
+ *
48
+ * @slot - Default slot for `nys-step` elements. Only `nys-step` children are accepted; others are removed.
49
+ * @slot actions - Persistent navigation buttons. Must contain exactly one `<div>` wrapping only `<nys-button>` elements.
50
+ *
51
+ * @example Basic stepper
52
+ * ```html
53
+ * <nys-stepper label="Application Progress">
54
+ * <nys-step label="Personal Info" current></nys-step>
55
+ * <nys-step label="Contact Details"></nys-step>
56
+ * <nys-step label="Review"></nys-step>
57
+ * </nys-stepper>
58
+ * ```
59
+ *
60
+ * @example Grid layout with sidebar placement
61
+ * Use NYSDS grid utilities to position the stepper as a sidebar alongside form content.
62
+ * **Layout requirements:**
63
+ * - Wrap in `nys-grid-container` > `nys-grid-row`
64
+ * - Use mobile-first classes: `nys-grid-col-12` (stacks on mobile) plus `nys-desktop:nys-grid-col-*`
65
+ * - Columns must total 12 (e.g., 3+9 or 4+8)
66
+ * - Recommended: stepper 3-4 cols, content 8-9 cols
67
+ * ```html
68
+ * <div class="nys-grid-container">
69
+ * <div class="nys-grid-row">
70
+ * <nys-stepper label="Application" class="nys-grid-col-12 nys-desktop:nys-grid-col-3">
71
+ * <nys-step label="Personal Info"></nys-step>
72
+ * <nys-step label="Contact" current></nys-step>
73
+ * <nys-step label="Review"></nys-step>
74
+ * </nys-stepper>
75
+ * <main class="nys-grid-col-12 nys-desktop:nys-grid-col-9" id="main-content">
76
+ * <!-- Form content for current step -->
77
+ * <nys-textinput label="Email" required></nys-textinput>
78
+ * <nys-textinput label="Phone"></nys-textinput>
79
+ * </main>
80
+ * </div>
81
+ * </div>
82
+ * ```
83
+ *
84
+ * @example Navigation buttons in actions slot
85
+ * Add Previous/Next buttons using the actions slot. Wrap buttons in a `<div>`.
86
+ * ```html
87
+ * <nys-stepper label="Application">
88
+ * <nys-step label="Step 1"></nys-step>
89
+ * <nys-step label="Step 2" current></nys-step>
90
+ * <nys-step label="Step 3"></nys-step>
91
+ * <div slot="actions">
92
+ * <nys-button label="Save and Exit" variant="outline" size="sm" fullWidth></nys-button>
93
+ * </div>
94
+ * </nys-stepper>
95
+ * ```
96
+ *
97
+ * @example SPA / programmatic navigation
98
+ * Two state variables drive the stepper in any framework or vanilla JS:
99
+ * - `currentStep` (progress boundary) → set `current` on the matching step
100
+ * - `viewingStep` (displayed content) → set `selected` on the matching step
101
+ *
102
+ * Always set both explicitly. Always call `e.preventDefault()` in the
103
+ * `nys-step-click` listener to suppress href navigation. Do NOT nest inside a
104
+ * `<form>` element.
105
+ * ```js
106
+ * let currentStep = 0; // furthest reached
107
+ * let viewingStep = 0; // currently displayed
108
+ *
109
+ * function updateStepper(steps) {
110
+ * steps.forEach((step, i) => {
111
+ * step.toggleAttribute('current', i === currentStep);
112
+ * step.toggleAttribute('selected', i === viewingStep);
113
+ * });
114
+ * }
115
+ *
116
+ * document.querySelector('nys-stepper').addEventListener('nys-step-click', (e) => {
117
+ * e.preventDefault();
118
+ * const steps = Array.from(document.querySelectorAll('nys-step'));
119
+ * const clicked = e.composedPath().find(el => el.tagName?.toLowerCase() === 'nys-step');
120
+ * const index = steps.indexOf(clicked);
121
+ * if (index !== -1) { viewingStep = index; updateStepper(steps); }
122
+ * });
123
+ *
124
+ * // Advance to next step (call on form submit / "Continue" click)
125
+ * function advance(steps) {
126
+ * if (currentStep < steps.length - 1) {
127
+ * currentStep++;
128
+ * viewingStep = currentStep;
129
+ * updateStepper(steps);
130
+ * }
131
+ * }
132
+ * ```
133
+ */
134
+ export declare class NysStepper extends LitElement {
135
+ static styles: import("lit").CSSResult;
136
+ /** Unique identifier. Auto-generated as `nys-stepper-{n}-{timestamp}` if not provided. */
137
+ id: string;
138
+ /** Name attribute for form association. */
139
+ name: string;
140
+ /** Title displayed above the step list and compact counter. */
141
+ label: string;
142
+ /** Progress text displayed in compact mode (e.g., "Step 2 of 5"). Auto-managed — do not set manually. */
143
+ counterText: string;
144
+ /** Whether compact mobile view is expanded to show all steps. Toggled by clicking the counter. */
145
+ isCompactExpanded: boolean;
146
+ private _stepsNumbered;
147
+ constructor();
148
+ connectedCallback(): void;
149
+ disconnectedCallback(): void;
150
+ private _validateSteps;
151
+ private _validateButtonSlot;
152
+ private _onStepClick;
153
+ private _updateCounter;
154
+ willUpdate(): void;
155
+ private _toggleCompact;
156
+ private _handleCounterKeydown;
157
+ render(): import("lit-html").TemplateResult<1>;
158
+ }
@@ -5,7 +5,7 @@ import { property as i } from "lit/decorators.js";
5
5
  * █ █ █ █▄▄▄█ ▀▀▀▄▄ █ █ ▀▀▀▄▄
6
6
  * █ ▀█ █ █▄▄▄█ █▄▄▀ █▄▄▄█
7
7
  *
8
- * Stepper Component v1.19.1
8
+ * Stepper Component v1.19.2
9
9
  * Part of the New York State Design System
10
10
  * Repository: https://github.com/its-hcd/nysds
11
11
  * License: MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nysds/nys-stepper",
3
- "version": "1.19.1",
3
+ "version": "1.19.2",
4
4
  "description": "The Stepper component from the NYS Design System.",
5
5
  "module": "dist/nys-stepper.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "lit-analyze": "lit-analyzer '**/*.ts'"
24
24
  },
25
25
  "dependencies": {
26
- "@nysds/nys-button": "^1.19.1"
26
+ "@nysds/nys-button": "^1.19.2"
27
27
  },
28
28
  "devDependencies": {
29
29
  "lit": "^3.3.1",
@@ -40,5 +40,6 @@
40
40
  "forms"
41
41
  ],
42
42
  "author": "New York State Design System Team",
43
- "license": "MIT"
43
+ "license": "MIT",
44
+ "sideEffects": true
44
45
  }