@saasbase-io/core-elements 1.18.0 → 1.20.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,57 +1,284 @@
1
1
  import { LitElement } from '../../../../../node_modules/lit';
2
- export type NameFieldValidateType = "success" | "required" | "format";
3
- export declare class SbNameField extends LitElement {
2
+ import { NameFieldContent, NameFieldProps } from './field.types';
3
+ /**
4
+ * A self-validating name field for auth widget forms.
5
+ * @element sb-name-field
6
+ *
7
+ * @part name-field (rtg-field)
8
+ * @part name-field-content (rtg-field-content): label + description wrapper
9
+ * @part name-field-label (rtg-field-label)
10
+ * @part name-field-mark (span): decorative marker with text or `"*"` in label
11
+ * @part name-field-description (rtg-field-description)
12
+ * @part name-field-input (rtg-input)
13
+ * @part name-field-error (rtg-field-error)
14
+ *
15
+ * @fires sb-name-field:validate
16
+ * { id, parentId, name, value, valid, type, message }
17
+ * - id: inputId
18
+ * - parentId: rootId
19
+ * - type: "required" | "format" | "success" | "minlength" | "maxlength"
20
+ */
21
+ export declare class SbNameField extends LitElement implements NameFieldProps {
4
22
  private static readonly _ROOT;
5
- private static readonly _FIRST;
6
- private static readonly _LAST;
23
+ private static readonly _CONTENT;
24
+ private static readonly _LABEL;
25
+ private static readonly _MARK;
26
+ private static readonly _DESCRIPTION;
27
+ private static readonly _INPUT;
28
+ private static readonly _ERROR;
29
+ static readonly TAG: string;
30
+ private static readonly _PATTERN;
31
+ /**
32
+ * The stable CSS part names exposed for external targeting.
33
+ */
7
34
  static get parts(): {
8
35
  root: string;
9
- firstField: string;
10
- lastField: string;
11
- input: string;
36
+ content: string;
12
37
  label: string;
13
- error: string;
14
38
  mark: string;
15
39
  description: string;
40
+ input: string;
41
+ error: string;
16
42
  };
43
+ /**
44
+ * The name of the custom event fired on validate.
45
+ */
17
46
  static get validateEventName(): string;
18
- firstLabel: string;
19
- lastLabel: string;
47
+ /**
48
+ * A unique value used as a substring in the generated part/child IDs, when
49
+ * the `child-id` prop is not provided.
50
+ */
20
51
  seed: string;
52
+ /**
53
+ * The `id` value given to the root child/part and used as the base of other
54
+ * child/part IDs.
55
+ */
21
56
  childId?: string;
57
+ /**
58
+ * The `id` value given to the input child/part to override the auto-generated
59
+ * input ID, derived from the `rootId`.
60
+ */
61
+ fieldId?: string;
62
+ /**
63
+ * The `name` prop of the input part, used by the parent form.
64
+ */
22
65
  name: string;
23
- required?: boolean;
66
+ /**
67
+ * Whether the label and description are grouped together above the input, or
68
+ * split up with the input in-between them.
69
+ */
70
+ content: NameFieldContent;
71
+ /**
72
+ * The text content of the field label.
73
+ */
74
+ label: string;
75
+ /**
76
+ * The text used as the input placeholder.
77
+ */
78
+ placeholder?: string;
79
+ /**
80
+ * The text content of the field description.
81
+ */
82
+ description?: string;
83
+ /**
84
+ * The text rendered in the field label as a custom mark.
85
+ */
86
+ mark?: string;
87
+ /**
88
+ * When provided with `required`, a caret mark is rendered in the field label.
89
+ */
90
+ caret?: boolean;
91
+ /**
92
+ * Whether the field is in a disabled state.
93
+ */
24
94
  disabled?: boolean;
25
- firstName: string;
26
- lastName: string;
27
- firstPlaceholder: string;
28
- lastPlaceholder: string;
95
+ /**
96
+ * When provided, the parent form cannot be submitted without this field.
97
+ */
98
+ required?: boolean;
99
+ /**
100
+ * The minimum number of characters required for a valid name.
101
+ */
102
+ minlength?: number;
103
+ /**
104
+ * The maximum number of characters accepted for a valid name.
105
+ */
106
+ maxlength?: number;
107
+ /**
108
+ * The regex pattern for a valid name, used in place of `_PATTERN`.
109
+ */
110
+ pattern?: string;
111
+ /**
112
+ * Error message shown when the field is required but empty upon submission.
113
+ */
29
114
  requiredError: string;
115
+ /**
116
+ * Custom error message shown when the name is shorter than minlength.
117
+ */
118
+ minlengthError?: string;
119
+ /**
120
+ * Custom error message shown when the name is longer than maxlength.
121
+ */
122
+ maxlengthError?: string;
123
+ /**
124
+ * Error message shown when the field is invalid upon submission.
125
+ */
30
126
  formatError: string;
31
- mark?: string;
32
- caret?: boolean;
33
- private _first;
34
- private _firstInvalid;
35
- private _firstError;
36
- private _last;
37
- private _lastInvalid;
38
- private _lastError;
127
+ /**
128
+ * Indicates that the field is in an invalid state.
129
+ */
130
+ private _invalid;
131
+ /**
132
+ * The text rendered in field error when in an invalid state.
133
+ */
134
+ private _error;
135
+ /**
136
+ * The current value of the name input.
137
+ */
138
+ private _value;
139
+ /**
140
+ * Reference to the nearest `form` ancestor.
141
+ */
142
+ private _form;
143
+ /**
144
+ * Overrides default behavior to render into light DOM.
145
+ */
39
146
  protected createRenderRoot(): this;
147
+ /**
148
+ * The `id` of the root element. Equal to `childId` when provided, otherwise
149
+ * derived from the component's part name and `seed`.
150
+ */
40
151
  get rootId(): string;
41
- private _renderMark;
152
+ /**
153
+ * The `id` of the field content element, derived from `rootId` with the
154
+ * content part name appended.
155
+ */
156
+ get contentId(): string;
157
+ /**
158
+ * The `id` of the field label element, derived from `rootId` with the label
159
+ * part name appended.
160
+ */
161
+ get labelId(): string;
162
+ /**
163
+ * The `id` of the field description element, derived from `rootId` with the
164
+ * description part name appended.
165
+ */
166
+ get descriptionId(): string;
167
+ /**
168
+ * The `id` of the mark element, derived from `rootId` with the mark part name
169
+ * appended.
170
+ */
171
+ get markId(): string;
172
+ /**
173
+ * The `id` of the input element, equal to `fieldId` when provided, otherwise
174
+ * derived from `rootId` with the input part name appended.
175
+ */
176
+ get inputId(): string;
177
+ /**
178
+ * The `id` of the field error element, derived from `rootId` with the error
179
+ * part name appended.
180
+ */
181
+ get errorId(): string;
182
+ /**
183
+ * Returns the normalized value of `_value` by trimming leading/trailing
184
+ * whitespace and collapsing consecutive interior spaces into one.
185
+ */
186
+ private get _normalizedValue();
187
+ /**
188
+ * Returns sanitized `minlength` and `maxlength` values, filtering out
189
+ * non-positive numbers and discarding `maxlength` if it is less than
190
+ * `minlength` to prevent conflicting length constraints.
191
+ */
192
+ private get _lengths();
193
+ /**
194
+ * Returns the resolved regex pattern, using a `RegExp` built from the
195
+ * `pattern` prop when provided, otherwise falling back to `_PATTERN`.
196
+ */
197
+ private get _pattern();
198
+ /**
199
+ * Adds the input, form submit, and form reset event listeners.
200
+ */
201
+ connectedCallback(): void;
202
+ /**
203
+ * Removes the input, form submit, and form reset event listeners.
204
+ */
205
+ disconnectedCallback(): void;
206
+ /**
207
+ * The public validate method that calls the private `_validate()` method for
208
+ * manual, external validation.
209
+ */
210
+ validate(): boolean;
211
+ /**
212
+ * Defines and dispatches the validate event.
213
+ */
42
214
  private _dispatchValidate;
43
- private _validateName;
215
+ /**
216
+ * Handles the required condition validation, accepting empty non-required
217
+ * fields and non-empty required fields, otherwise dispatching and displaying
218
+ * the required error.
219
+ */
220
+ private _validateRequired;
221
+ /**
222
+ * Handles the minlength condition validation, determining if a valid
223
+ * `minlength` prop was provided, dispatching and displaying the minlength
224
+ * error if the value is shorter than accepted.
225
+ */
226
+ private _validateMinlength;
227
+ /**
228
+ * Handles the maxlength condition validation, determining if a valid
229
+ * `maxlength` prop was provided, dispatching and displaying the maxlength
230
+ * error if the value is longer than accepted.
231
+ */
232
+ private _validateMaxlength;
233
+ /**
234
+ * Handles the format condition validation, testing against `_pattern`, and
235
+ * dispatching and displaying the format error for an invalid value.
236
+ */
237
+ private _validateFormat;
238
+ /**
239
+ * Resets the `_invalid` and `_error` private props and dispatches the
240
+ * validate event, indicating a successfully validated and valid name.
241
+ */
242
+ private _doValidateSuccess;
243
+ /**
244
+ * Handles validation and dispatches the success event if the required,
245
+ * length, and format conditions are met.
246
+ */
44
247
  private _validate;
45
- validate(): boolean;
248
+ /**
249
+ * Handles the input event, updating the private `_value` prop.
250
+ */
46
251
  private _handleInput;
47
- connectedCallback(): void;
48
- disconnectedCallback(): void;
49
- private _renderFirstField;
50
- private _renderLastField;
252
+ /**
253
+ * Handles the form submit event, running the `_validate()` method and
254
+ * preventing the default submission behavior if invalid.
255
+ */
256
+ private _handleFormSubmit;
257
+ /**
258
+ * Handles the form reset event, resetting the input element's `value` as well
259
+ * as the name field's private props: `_value`, `_invalid`, and `_error`.
260
+ */
261
+ private _handleFormReset;
262
+ /**
263
+ * Conditionally returns the mark template for the field label. When `caret`
264
+ * and `required` are provided, the mark becomes an asterisk. When `mark` is
265
+ * provided, its value is rendered inside the element.
266
+ * If both a caret and custom text mark have their conditions met, the custom
267
+ * mark will be prioritised and rendered instead of the asterisk.
268
+ */
269
+ private _renderMark;
270
+ /**
271
+ * Returns the field label template with the label text and optional mark.
272
+ */
273
+ private _renderLabel;
274
+ /**
275
+ * Returns the field description template if `description` is defined.
276
+ */
277
+ private _renderDescription;
278
+ /**
279
+ * Returns the field error template with the `_error` message if the
280
+ * `_invalid` state is `true`.
281
+ */
282
+ private _renderError;
51
283
  render(): import('../../../../../node_modules/lit-html').TemplateResult<1>;
52
284
  }
53
- declare global {
54
- interface HTMLElementTagNameMap {
55
- "sb-name-field": SbNameField;
56
- }
57
- }
@@ -1,12 +1,15 @@
1
1
  import { Meta, StoryObj } from '@storybook/web-components-vite';
2
- import { SbNameField } from '../_name-field';
3
2
  declare const meta: Meta;
4
3
  export default meta;
5
- type Story = StoryObj<SbNameField>;
4
+ type Story = StoryObj;
6
5
  export declare const Basic: Story;
7
- export declare const Required: Story;
8
- export declare const FormatValidation: Story;
9
- export declare const MarkAndCaret: Story;
6
+ export declare const Label: Story;
7
+ export declare const Placeholder: Story;
8
+ export declare const Description: Story;
9
+ export declare const Content: Story;
10
10
  export declare const Disabled: Story;
11
- export declare const Form: Story;
11
+ export declare const Caret: Story;
12
+ export declare const Mark: Story;
12
13
  export declare const Validate: Story;
14
+ export declare const Form: Story;
15
+ export declare const FormGroup: Story;
@@ -40,6 +40,12 @@ export type UsernameFieldProps = Omit<BaseFieldPropsWithLength, "content"> & {
40
40
  content: UsernameFieldContent;
41
41
  pattern?: string;
42
42
  };
43
+ export type NameFieldValidateType = BaseFieldValidateTypeWithLength;
44
+ export type NameFieldContent = BaseFieldContent;
45
+ export type NameFieldProps = Omit<BaseFieldPropsWithLength, "content"> & {
46
+ content: NameFieldContent;
47
+ pattern?: string;
48
+ };
43
49
  export type PasswordFieldValidateType = BaseFieldValidateTypeWithLength;
44
50
  export type PasswordFieldVariant = "toggle" | "simple";
45
51
  export type PasswordFieldContent = BaseFieldContent;
@@ -77,33 +83,4 @@ export type IdentifierFieldProps = Omit<BaseFieldProps, "label" | "content" | "f
77
83
  content: IdentifierFieldContent;
78
84
  autocomplete?: IdentifierFieldAutocomplete;
79
85
  };
80
- export type NameFieldValidateType = BaseFieldValidateType;
81
- export type NameFieldContent = BaseFieldContent;
82
- export type NameFieldProps = {
83
- seed: string;
84
- childId?: string;
85
- fieldId?: string;
86
- /**
87
- * Base form field name (e.g. "name", "full_name")
88
- */
89
- name: string;
90
- content: NameFieldContent;
91
- /**
92
- * Label for first name input (e.g. "First name")
93
- */
94
- firstLabel: string;
95
- /**
96
- * Label for last name input (e.g. "Last name")
97
- */
98
- lastLabel: string;
99
- firstPlaceholder?: string;
100
- lastPlaceholder?: string;
101
- description?: string;
102
- mark?: string;
103
- caret?: boolean;
104
- disabled?: boolean;
105
- required?: boolean;
106
- requiredError: string;
107
- formatError: string;
108
- };
109
86
  export {};
@@ -5,7 +5,7 @@ import { SbNameField } from './_name-field';
5
5
  import { SbPasswordField } from './_password-field';
6
6
  import { SbPhoneField } from './_phone-field';
7
7
  import { SbUsernameField } from './_username-field';
8
- export { SbConfirmField, SbEmailField, SbIdentifierField, SbPasswordField, SbPhoneField, SbUsernameField, SbNameField, };
8
+ export { SbConfirmField, SbEmailField, SbIdentifierField, SbNameField, SbPasswordField, SbPhoneField, SbUsernameField, };
9
9
  declare global {
10
10
  interface HTMLElementTagNameMap {
11
11
  "sb-email-field": SbEmailField;
@@ -1,7 +1,7 @@
1
1
  import { LitElement } from '../../../../../node_modules/lit';
2
2
  import { PasskeyButtonProps, PasskeyButtonSize, PasskeyButtonSpinnerAlign, PasskeyButtonVariant } from './passkey-button.types';
3
3
  /**
4
- * A button for passkey authentication.
4
+ * A button for passkey authentication in auth widgets.
5
5
  * @element sb-passkey-button
6
6
  *
7
7
  * @part passkey-button (rtg-button)
@@ -12,6 +12,8 @@ import { PasskeyButtonProps, PasskeyButtonSize, PasskeyButtonSpinnerAlign, Passk
12
12
  export declare class SbPasskeyButton extends LitElement implements PasskeyButtonProps {
13
13
  private static readonly _ROOT;
14
14
  private static readonly _SPINNER;
15
+ static readonly TAG: string;
16
+ static readonly CLICK_EVENT: string;
15
17
  /**
16
18
  * The stable CSS part names exposed for external targeting.
17
19
  */
@@ -20,17 +22,11 @@ export declare class SbPasskeyButton extends LitElement implements PasskeyButton
20
22
  spinner: string;
21
23
  };
22
24
  /**
23
- * The name of the custom event fired on click.
24
- */
25
- static get clickEventName(): string;
26
- /**
27
- * A unique value used as a substring in the generated part/child IDs, when
28
- * the `child-id` prop is not provided.
25
+ * A unique substring for fallback part IDs generated.
29
26
  */
30
27
  seed: string;
31
28
  /**
32
- * The `id` value given to the root child/part and used as the base of other
33
- * child/part IDs.
29
+ * The `id` of the root part and the base of sub-part IDs.
34
30
  */
35
31
  childId?: string;
36
32
  /**
@@ -58,7 +54,7 @@ export declare class SbPasskeyButton extends LitElement implements PasskeyButton
58
54
  */
59
55
  loading?: boolean;
60
56
  /**
61
- * The event identifier/name as defined in auth service.
57
+ * The event name as defined in the loginflow auth service.
62
58
  */
63
59
  event?: string;
64
60
  /**
@@ -75,8 +71,7 @@ export declare class SbPasskeyButton extends LitElement implements PasskeyButton
75
71
  */
76
72
  get rootId(): string;
77
73
  /**
78
- * The `id` of the spinner element, derived from `rootId` with the spinner
79
- * part name appended.
74
+ * The `id` of the spinner element, derived from `rootId` and the part name.
80
75
  */
81
76
  get spinnerId(): string;
82
77
  /**
@@ -91,14 +86,6 @@ export declare class SbPasskeyButton extends LitElement implements PasskeyButton
91
86
  * Removes the click event listener.
92
87
  */
93
88
  disconnectedCallback(): void;
94
- /**
95
- * Defines and dispatches the click event.
96
- */
97
- private _dispatchClick;
98
- /**
99
- * Emits the provided `event` to the auth service to process.
100
- */
101
- private _emitClickEvent;
102
89
  /**
103
90
  * Handles the click event, preventing execution when disabled/loading, firing
104
91
  * the click event, and emitting to auth service.