@saasbase-io/core-elements 1.12.0 → 1.14.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.
@@ -0,0 +1,77 @@
1
+ import { LitElement } from '../../../../../node_modules/lit';
2
+ import { ErrorContent, ErrorIcon, ErrorProps, ErrorVariant } from './error.types';
3
+ /**
4
+ * A destructive alert used for displaying auth errors.
5
+ * @element sb-error
6
+ *
7
+ * @part error (rtg-alert)
8
+ * @part error-icon (svg)
9
+ * @part error-title (rtg-alert-title)
10
+ * @part error-description (rtg-alert-description)
11
+ */
12
+ export declare class SbError extends LitElement implements ErrorProps {
13
+ private static readonly _ROOT;
14
+ private static readonly _ICON;
15
+ private static readonly _TITLE;
16
+ private static readonly _DESCRIPTION;
17
+ /**
18
+ * The stable CSS part names exposed for external targeting.
19
+ */
20
+ static get parts(): {
21
+ root: string;
22
+ icon: string;
23
+ title: string;
24
+ description: string;
25
+ };
26
+ /**
27
+ * A unique substring for fallback part IDs generated.
28
+ */
29
+ seed: string;
30
+ /**
31
+ * The `id` of the root part and the base of sub-part IDs.
32
+ */
33
+ childId?: string;
34
+ /**
35
+ * The visual variant of the alert.
36
+ */
37
+ variant: ErrorVariant;
38
+ /**
39
+ * The text content (title and/or description) of the error alert.
40
+ */
41
+ content: ErrorContent;
42
+ /**
43
+ * The Lucide icon rendered in the error alert.
44
+ */
45
+ icon?: ErrorIcon;
46
+ /**
47
+ * Overrides default behavior to render into light DOM.
48
+ */
49
+ protected createRenderRoot(): this;
50
+ /**
51
+ * The `id` of the root element. Equal to `childId` when provided, otherwise
52
+ * derived from the component's part name and `seed`.
53
+ */
54
+ get rootId(): string;
55
+ /**
56
+ * The `id` of the spinner element, derived from `rootId` with the icon part
57
+ * name appended.
58
+ */
59
+ get iconId(): string;
60
+ /**
61
+ * The `id` of the spinner element, derived from `rootId` with the title part
62
+ * name appended.
63
+ */
64
+ get titleId(): string;
65
+ /**
66
+ * The `id` of the spinner element, derived from `rootId` with the description
67
+ * part name appended.
68
+ */
69
+ get descriptionId(): string;
70
+ /**
71
+ * Uses the `variant` prop to derive the `variant` prop passed to `rtg-alert`.
72
+ * - `"default"` error = `"destructive"` alert
73
+ * - `"tonal"` error = `"destructive-tonal"` alert
74
+ */
75
+ private get _variant();
76
+ render(): import('../../../../../node_modules/lit-html').TemplateResult<1>;
77
+ }
@@ -0,0 +1,3 @@
1
+ import { TemplateResult } from '../../../../../node_modules/lit';
2
+ import { ErrorIcon } from './error.types';
3
+ export declare const ERROR_ICONS: Record<ErrorIcon, (id: string, part: string) => TemplateResult<1>>;
@@ -0,0 +1,8 @@
1
+ import { Meta, StoryObj } from '@storybook/web-components-vite';
2
+ declare const meta: Meta;
3
+ export default meta;
4
+ type Story = StoryObj;
5
+ export declare const Basic: Story;
6
+ export declare const Variant: Story;
7
+ export declare const Content: Story;
8
+ export declare const Icon: Story;
@@ -1,3 +1,4 @@
1
+ export type ErrorVariant = "default" | "tonal";
1
2
  export type ErrorIcon = "badge-alert" | "badge-x" | "circle-alert" | "circle-x" | "shield-alert" | "shield-x";
2
3
  export type ErrorContent = {
3
4
  title: string;
@@ -11,7 +12,8 @@ export type ErrorContent = {
11
12
  };
12
13
  export type ErrorProps = {
13
14
  seed: string;
14
- icon?: ErrorIcon;
15
+ childId?: string;
16
+ variant: ErrorVariant;
15
17
  content: ErrorContent;
16
- tonal?: boolean;
18
+ icon?: ErrorIcon;
17
19
  };
@@ -1,4 +1,5 @@
1
1
  import { SbError } from './_error';
2
+ export { SbError };
2
3
  declare global {
3
4
  interface HTMLElementTagNameMap {
4
5
  "sb-error": SbError;
@@ -0,0 +1,242 @@
1
+ import { LitElement } from '../../../../../node_modules/lit';
2
+ import { IdentifierFieldAutocomplete, IdentifierFieldContent, IdentifierFieldIdentifier, IdentifierFieldProps } from './field.types';
3
+ /**
4
+ * A self-validating identifier field for auth widget forms.
5
+ * @element sb-identifier-field
6
+ *
7
+ * @part identifier-field (rtg-field)
8
+ * @part identifier-field-content (rtg-field-content): label + description wrapper
9
+ * @part identifier-field-label (rtg-field-label)
10
+ * @part identifier-field-mark (span): decorative marker with text or `"*"` in label
11
+ * @part identifier-field-description (rtg-field-description)
12
+ * @part identifier-field-input (rtg-input)
13
+ * @part identifier-field-error (rtg-field-error)
14
+ *
15
+ * @fires sb-identifier-field:validate
16
+ * { id, parentId, name, identifiers, value, valid, type, message }
17
+ * - id: inputId
18
+ * - parentId: rootId
19
+ * - type: "required"
20
+ */
21
+ export declare class SbIdentifierField extends LitElement implements IdentifierFieldProps {
22
+ private static readonly _ROOT;
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
+ /**
30
+ * The stable CSS part names exposed for external targeting.
31
+ */
32
+ static get parts(): {
33
+ root: string;
34
+ content: string;
35
+ label: string;
36
+ mark: string;
37
+ description: string;
38
+ input: string;
39
+ error: string;
40
+ };
41
+ /**
42
+ * The name of the custom event fired on validate.
43
+ */
44
+ static get validateEventName(): string;
45
+ /**
46
+ * A unique substring for fallback part IDs generated.
47
+ */
48
+ seed: string;
49
+ /**
50
+ * The `id` of the root part and the base of sub-part IDs.
51
+ */
52
+ childId?: string;
53
+ /**
54
+ * The `id` value given to the input child/part to override the auto-generated
55
+ * input ID, derived from the `rootId`.
56
+ */
57
+ fieldId?: string;
58
+ /**
59
+ * The `name` prop of the input part, used by the parent form.
60
+ */
61
+ name: string;
62
+ /**
63
+ * The identifiers enabled in the identifier field.
64
+ */
65
+ identifiers: IdentifierFieldIdentifier[];
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: IdentifierFieldContent;
71
+ /**
72
+ * The text content of the field label. If undefined, a label is generated
73
+ * using the `identifiers` items.
74
+ */
75
+ label?: string;
76
+ /**
77
+ * The text used as the input placeholder.
78
+ */
79
+ placeholder?: string;
80
+ /**
81
+ * The text content of the field description.
82
+ */
83
+ description?: string;
84
+ /**
85
+ * The text rendered in the field label as a custom mark.
86
+ */
87
+ mark?: string;
88
+ /**
89
+ * When provided with `required`, a caret mark is rendered in the field label.
90
+ */
91
+ caret?: boolean;
92
+ /**
93
+ * Whether the field is in a disabled state.
94
+ */
95
+ disabled?: boolean;
96
+ /**
97
+ * The `autocomplete` prop given to the field input.
98
+ */
99
+ autocomplete?: IdentifierFieldAutocomplete;
100
+ /**
101
+ * When provided, the parent form cannot be submitted without this field.
102
+ */
103
+ required?: boolean;
104
+ /**
105
+ * Error message shown when the field is required but empty upon submission.
106
+ */
107
+ requiredError: string;
108
+ /**
109
+ * Indicates that the field is in an invalid state.
110
+ */
111
+ private _invalid;
112
+ /**
113
+ * The text rendered in field error when in an invalid state.
114
+ */
115
+ private _error;
116
+ /**
117
+ * The current value of the identifier input.
118
+ */
119
+ private _value;
120
+ /**
121
+ * Reference to the nearest `form` ancestor.
122
+ */
123
+ private _form;
124
+ /**
125
+ * Overrides default behavior to render into light DOM.
126
+ */
127
+ protected createRenderRoot(): this;
128
+ /**
129
+ * The `id` of the root element. Equal to `childId` when provided, otherwise
130
+ * derived from the component's part name and `seed`.
131
+ */
132
+ get rootId(): string;
133
+ /**
134
+ * The `id` of the field content element, derived from `rootId` with the
135
+ * content part name appended.
136
+ */
137
+ get contentId(): string;
138
+ /**
139
+ * The `id` of the field label element, derived from `rootId` with the label
140
+ * part name appended.
141
+ */
142
+ get labelId(): string;
143
+ /**
144
+ * The `id` of the field description element, derived from `rootId` with the
145
+ * description part name appended.
146
+ */
147
+ get descriptionId(): string;
148
+ /**
149
+ * The `id` of the mark element, derived from `rootId` with the mark part name
150
+ * appended.
151
+ */
152
+ get markId(): string;
153
+ /**
154
+ * The `id` of the input element, equal to `fieldId` when provided, otherwise
155
+ * derived from `rootId` with the input part name appended.
156
+ */
157
+ get inputId(): string;
158
+ /**
159
+ * The `id` of the field error element, derived from `rootId` with the error
160
+ * part name appended.
161
+ */
162
+ get errorId(): string;
163
+ /**
164
+ * Returns a the normalized value of `_value` by trimming whitespace and
165
+ * converting letters to lowercase.
166
+ */
167
+ private get _normalizedValue();
168
+ /**
169
+ * The fallback label text generated, formatting the `identifiers` array into
170
+ * a readable field label string.
171
+ */
172
+ private get _label();
173
+ /**
174
+ * The type of the field input, using identifier-specific types if possible,
175
+ * otherwise using `"text"`.
176
+ */
177
+ private get _type();
178
+ /**
179
+ * Adds the input, form submit, and form reset event listeners.
180
+ */
181
+ connectedCallback(): void;
182
+ /**
183
+ * Removes the input, form submit, and form reset event listeners.
184
+ */
185
+ disconnectedCallback(): void;
186
+ /**
187
+ * The public validate method that calls the private `_validate()` method for
188
+ * manual, external validation.
189
+ */
190
+ validate(): boolean;
191
+ /**
192
+ * Defines and dispatches the validate event.
193
+ */
194
+ private _dispatchValidate;
195
+ /**
196
+ * Handles the required condition validation, accepting empty non-required
197
+ * fields and non-empty required fields, otherwise dispatching and displaying
198
+ * the required error.
199
+ */
200
+ private _validateRequired;
201
+ /**
202
+ * Handles validation and dispatches the success event if the required
203
+ * condition is met.
204
+ */
205
+ private _validate;
206
+ /**
207
+ * Handles the input event, updating the private `_value` prop.
208
+ */
209
+ private _handleInput;
210
+ /**
211
+ * Handles the form submit event, running the `_validate()` method and
212
+ * preventing the default submission behavior if invalid.
213
+ */
214
+ private _handleFormSubmit;
215
+ /**
216
+ * Handles the form reset event, resetting the input element's `value` as well
217
+ * as the identifier field's private props: `_value`, `_invalid`, and `_error`.
218
+ */
219
+ private _handleFormReset;
220
+ /**
221
+ * Conditionally returns the mark template for the field label. When `caret`
222
+ * and `required` are provided, the mark becomes an asterisk. When `mark` is
223
+ * provided, its value is rendered inside the element.
224
+ * If both a caret and custom text mark have their conditions met, the custom
225
+ * mark will be prioritised and rendered instead of the asterisk.
226
+ */
227
+ private _renderMark;
228
+ /**
229
+ * Returns the field label template with the label text and optional mark.
230
+ */
231
+ private _renderLabel;
232
+ /**
233
+ * Returns the field description template if `description` is defined.
234
+ */
235
+ private _renderDescription;
236
+ /**
237
+ * Returns the field error template with the `_error` message if the
238
+ * `_invalid` state is `true`.
239
+ */
240
+ private _renderError;
241
+ render(): import('../../../../../node_modules/lit-html').TemplateResult<1>;
242
+ }
@@ -0,0 +1,15 @@
1
+ import { Meta, StoryObj } from '@storybook/web-components-vite';
2
+ declare const meta: Meta;
3
+ export default meta;
4
+ type Story = StoryObj;
5
+ export declare const Basic: Story;
6
+ export declare const Identifiers: Story;
7
+ export declare const Label: Story;
8
+ export declare const Placeholder: Story;
9
+ export declare const Description: Story;
10
+ export declare const Content: Story;
11
+ export declare const Disabled: Story;
12
+ export declare const Caret: Story;
13
+ export declare const Mark: Story;
14
+ export declare const Validate: Story;
15
+ export declare const Form: Story;
@@ -1,3 +1,4 @@
1
+ import { RtgInputAutocomplete, SbAuthIdentifier } from '../../../../types';
1
2
  type BaseFieldValidateType = "success" | "required" | "format";
2
3
  type BaseFieldValidateTypeWithLength = BaseFieldValidateType | "minlength" | "maxlength";
3
4
  type BaseFieldContent = "split" | "group";
@@ -66,4 +67,14 @@ export type ConfirmFieldProps = Omit<BaseFieldProps, "content" | "formatError">
66
67
  pair: string;
67
68
  matchError: string;
68
69
  };
70
+ export type IdentifierFieldValidateType = Exclude<BaseFieldValidateType, "format">;
71
+ export type IdentifierFieldIdentifier = SbAuthIdentifier;
72
+ export type IdentifierFieldContent = BaseFieldContent;
73
+ export type IdentifierFieldAutocomplete = RtgInputAutocomplete;
74
+ export type IdentifierFieldProps = Omit<BaseFieldProps, "label" | "content" | "formatError"> & {
75
+ label?: string;
76
+ identifiers: IdentifierFieldIdentifier[];
77
+ content: IdentifierFieldContent;
78
+ autocomplete?: IdentifierFieldAutocomplete;
79
+ };
69
80
  export {};
@@ -1,9 +1,10 @@
1
1
  import { SbConfirmField } from './_confirm-field';
2
2
  import { SbEmailField } from './_email-field';
3
+ import { SbIdentifierField } from './_identifier-field';
3
4
  import { SbPasswordField } from './_password-field';
4
5
  import { SbPhoneField } from './_phone-field';
5
6
  import { SbUsernameField } from './_username-field';
6
- export { SbConfirmField, SbEmailField, SbPasswordField, SbPhoneField, SbUsernameField, };
7
+ export { SbConfirmField, SbEmailField, SbIdentifierField, SbPasswordField, SbPhoneField, SbUsernameField, };
7
8
  declare global {
8
9
  interface HTMLElementTagNameMap {
9
10
  "sb-email-field": SbEmailField;
@@ -11,5 +12,6 @@ declare global {
11
12
  "sb-username-field": SbUsernameField;
12
13
  "sb-password-field": SbPasswordField;
13
14
  "sb-confirm-field": SbConfirmField;
15
+ "sb-identifier-field": SbIdentifierField;
14
16
  }
15
17
  }
@@ -1,13 +1,13 @@
1
+ export * from './error';
1
2
  export * from './field';
2
3
  export * from './form';
3
4
  export * from './passkey-button';
4
5
  export * from './provider';
5
- export * from './sb-error';
6
+ export * from './sb-container';
6
7
  export * from './sb-gap';
7
8
  export * from './sb-header';
8
9
  export * from './sb-logo';
9
10
  export * from './sb-otp';
10
11
  export * from './sb-subtitle';
11
- export * from './sb-container';
12
12
  export * from './sb-title';
13
13
  export * from './watermark';
@@ -1,5 +1,5 @@
1
1
  import { PropertyValues } from '../../../../node_modules/lit';
2
- import { BaseElement } from '../..';
2
+ import { BaseElement } from '../../wrappers/base-element/base-element';
3
3
  export declare class SbContainer extends BaseElement {
4
4
  id: string;
5
5
  type: "flex_column" | "flex_row";