@saasbase-io/core-elements 1.4.0 → 1.6.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,236 @@
1
+ import { LitElement } from '../../../../../node_modules/lit';
2
+ import { EmailFieldContent, EmailFieldProps } from './field.types';
3
+ /**
4
+ * A self-validating email field for auth widget forms.
5
+ * @element sb-email-field
6
+ *
7
+ * @part email-field (rtg-field)
8
+ * @part email-field-content (rtg-field-content): label + description wrapper
9
+ * @part email-field-label (rtg-field-label)
10
+ * @part email-field-mark (span): decorative marker with text or `"*"` in label
11
+ * @part email-field-description (rtg-field-description)
12
+ * @part email-field-input (rtg-input)
13
+ * @part email-field-error (rtg-field-error)
14
+ *
15
+ * @fires sb-email-field:validate
16
+ * { id, parentId, name, value, valid, type, message }
17
+ * - id: inputId
18
+ * - parentId: rootId
19
+ * - type: "required" | "format" | "success"
20
+ */
21
+ export declare class SbEmailField extends LitElement implements EmailFieldProps {
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
+ private static readonly _PATTERN;
30
+ /**
31
+ * The stable CSS part names exposed for external targeting.
32
+ */
33
+ static get parts(): {
34
+ root: string;
35
+ content: string;
36
+ label: string;
37
+ mark: string;
38
+ description: string;
39
+ input: string;
40
+ error: string;
41
+ };
42
+ /**
43
+ * The name of the custom event fired on validate.
44
+ */
45
+ static get validateEventName(): string;
46
+ /**
47
+ * A unique value used as a substring in the generated part/child IDs, when
48
+ * the `child-id` prop is not provided.
49
+ */
50
+ seed: string;
51
+ /**
52
+ * The `id` value given to the root child/part and used as the base of other
53
+ * child/part IDs.
54
+ */
55
+ childId?: string;
56
+ /**
57
+ * The `id` value given to the input child/part to override the auto-generated
58
+ * input ID, derived from the `rootId`.
59
+ */
60
+ fieldId?: string;
61
+ /**
62
+ * The `name` prop of the input part, used by the parent form.
63
+ */
64
+ name: string;
65
+ /**
66
+ * Whether the label and description are grouped together above the input, or
67
+ * split up with the input in-between them.
68
+ */
69
+ content: EmailFieldContent;
70
+ /**
71
+ * The text content of the field label.
72
+ */
73
+ label: string;
74
+ /**
75
+ * The text used as the input placeholder.
76
+ */
77
+ placeholder?: string;
78
+ /**
79
+ * The text content of the field description.
80
+ */
81
+ description?: string;
82
+ /**
83
+ * The text rendered in the field label as a custom mark.
84
+ */
85
+ mark?: string;
86
+ /**
87
+ * When provided with `required`, a caret mark is rendered in the field label.
88
+ */
89
+ caret?: boolean;
90
+ /**
91
+ * Whether the field is in a disabled state.
92
+ */
93
+ disabled?: boolean;
94
+ /**
95
+ * When provided, the parent form cannot be submitted without this field.
96
+ */
97
+ required?: boolean;
98
+ /**
99
+ * Error message shown when the field is required but empty upon submission.
100
+ */
101
+ requiredError: string;
102
+ /**
103
+ * Error message shown when the field is invalid upon submission.
104
+ */
105
+ formatError: string;
106
+ /**
107
+ * Indicates that the field is in an invalid state.
108
+ */
109
+ private _invalid;
110
+ /**
111
+ * The text rendered in field error when in an invalid state.
112
+ */
113
+ private _error;
114
+ /**
115
+ * The current value of the email input.
116
+ */
117
+ private _value;
118
+ /**
119
+ * Reference to the nearest `form` ancestor.
120
+ */
121
+ private _form;
122
+ /**
123
+ * Overrides default behavior to render into light DOM.
124
+ */
125
+ protected createRenderRoot(): this;
126
+ /**
127
+ * The `id` of the root element. Equal to `childId` when provided, otherwise
128
+ * derived from the component's part name and `seed`.
129
+ */
130
+ get rootId(): string;
131
+ /**
132
+ * The `id` of the field content element, derived from `rootId` with the
133
+ * content part name appended.
134
+ */
135
+ get contentId(): string;
136
+ /**
137
+ * The `id` of the field label element, derived from `rootId` with the label
138
+ * part name appended.
139
+ */
140
+ get labelId(): string;
141
+ /**
142
+ * The `id` of the field description element, derived from `rootId` with the
143
+ * description part name appended.
144
+ */
145
+ get descriptionId(): string;
146
+ /**
147
+ * The `id` of the mark element, derived from `rootId` with the mark part name
148
+ * appended.
149
+ */
150
+ get markId(): string;
151
+ /**
152
+ * The `id` of the input element, equal to `fieldId` when provided, otherwise
153
+ * derived from `rootId` with the input part name appended.
154
+ */
155
+ get inputId(): string;
156
+ /**
157
+ * The `id` of the field error element, derived from `rootId` with the error
158
+ * part name appended.
159
+ */
160
+ get errorId(): string;
161
+ /**
162
+ * Returns a the normalized value of `_value` by trimming whitespace and
163
+ * converting letters to lowercase.
164
+ */
165
+ private get _normalizedValue();
166
+ /**
167
+ * Adds the input, form submit, and form reset event listeners.
168
+ */
169
+ connectedCallback(): void;
170
+ /**
171
+ * Removes the input, form submit, and form reset event listeners.
172
+ */
173
+ disconnectedCallback(): void;
174
+ /**
175
+ * The public validate method that calls the private `_validate()` method for
176
+ * manual, external validation.
177
+ */
178
+ validate(): boolean;
179
+ /**
180
+ * Defines and dispatches the validate event.
181
+ */
182
+ private _dispatchValidate;
183
+ /**
184
+ * Handles the required condition validation, accepting empty non-required
185
+ * fields and non-empty required fields, otherwise dispatching and displaying
186
+ * the required error.
187
+ */
188
+ private _validateRequired;
189
+ /**
190
+ * Handles the format condition validation with `_PATTERN`, accepting empty
191
+ * non-required fields and non-empty fields that satisfy the pattern,
192
+ * otherwise dispatching and displaying the format error.
193
+ */
194
+ private _validateFormat;
195
+ /**
196
+ * Handles validation and dispatches the success event if the required and
197
+ * format conditions are met.
198
+ */
199
+ private _validate;
200
+ /**
201
+ * Handles the input event, updating the private `_value` prop.
202
+ */
203
+ private _handleInput;
204
+ /**
205
+ * Handles the form submit event, running the `_validate()` method and
206
+ * preventing the default submission behavior if invalid.
207
+ */
208
+ private _handleFormSubmit;
209
+ /**
210
+ * Handles the form reset event, resetting the input element's `value` as well
211
+ * as the email field's private props: `_value`, `_invalid`, and `_error`.
212
+ */
213
+ private _handleFormReset;
214
+ /**
215
+ * Conditionally returns the mark template for the field label. When `caret`
216
+ * and `required` are provided, the mark becomes an asterisk. When `mark` is
217
+ * provided, its value is rendered inside the element.
218
+ * If both a caret and custom text mark have their conditions met, the custom
219
+ * mark will be prioritised and rendered instead of the asterisk.
220
+ */
221
+ private _renderMark;
222
+ /**
223
+ * Returns the field label template with the label text and optional mark.
224
+ */
225
+ private _renderLabel;
226
+ /**
227
+ * Returns the field description template if `description` is defined.
228
+ */
229
+ private _renderDescription;
230
+ /**
231
+ * Returns the field error template with the `_error` message if the
232
+ * `_invalid` state is `true`.
233
+ */
234
+ private _renderError;
235
+ render(): import('../../../../../node_modules/lit-html').TemplateResult<1>;
236
+ }
@@ -0,0 +1,14 @@
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 Label: Story;
7
+ export declare const Placeholder: Story;
8
+ export declare const Description: Story;
9
+ export declare const Content: Story;
10
+ export declare const Disabled: Story;
11
+ export declare const Caret: Story;
12
+ export declare const Mark: Story;
13
+ export declare const Validate: Story;
14
+ export declare const Form: Story;
@@ -0,0 +1,20 @@
1
+ type FieldContent = "split" | "group";
2
+ export type EmailFieldValidateType = "success" | "required" | "format";
3
+ export type EmailFieldContent = FieldContent;
4
+ export type EmailFieldProps = {
5
+ seed: string;
6
+ childId?: string;
7
+ fieldId?: string;
8
+ name: string;
9
+ content: EmailFieldContent;
10
+ label: string;
11
+ placeholder?: string;
12
+ description?: string;
13
+ mark?: string;
14
+ caret?: boolean;
15
+ disabled?: boolean;
16
+ required?: boolean;
17
+ requiredError: string;
18
+ formatError: string;
19
+ };
20
+ export {};
@@ -0,0 +1,7 @@
1
+ import { SbEmailField } from './_email-field';
2
+ export { SbEmailField };
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ "sb-email-field": SbEmailField;
6
+ }
7
+ }
@@ -1,4 +1,6 @@
1
+ export * from './field';
1
2
  export * from './form';
3
+ export * from './passkey-button';
2
4
  export * from './provider';
3
5
  export * from './sb-error';
4
6
  export * from './sb-gap';
@@ -0,0 +1,112 @@
1
+ import { LitElement } from '../../../../../node_modules/lit';
2
+ import { PasskeyButtonProps, PasskeyButtonSize, PasskeyButtonSpinnerAlign, PasskeyButtonVariant } from './passkey-button.types';
3
+ /**
4
+ * A button for passkey authentication.
5
+ * @element sb-passkey-button
6
+ *
7
+ * @part passkey-button (rtg-button)
8
+ * @part passkey-button-spinner (rtg-spinner): loading indicator
9
+ *
10
+ * @fires sb-passkey-button:click { id, event }
11
+ */
12
+ export declare class SbPasskeyButton extends LitElement implements PasskeyButtonProps {
13
+ private static readonly _ROOT;
14
+ private static readonly _SPINNER;
15
+ /**
16
+ * The stable CSS part names exposed for external targeting.
17
+ */
18
+ static get parts(): {
19
+ root: string;
20
+ spinner: string;
21
+ };
22
+ /**
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.
29
+ */
30
+ seed: string;
31
+ /**
32
+ * The `id` value given to the root child/part and used as the base of other
33
+ * child/part IDs.
34
+ */
35
+ childId?: string;
36
+ /**
37
+ * The visual variant of the button.
38
+ */
39
+ variant: PasskeyButtonVariant;
40
+ /**
41
+ * The size of the button.
42
+ */
43
+ size: PasskeyButtonSize;
44
+ /**
45
+ * The text used as the button label.
46
+ */
47
+ label: string;
48
+ /**
49
+ * Whether the loading spinner should be rendered before or after the label.
50
+ */
51
+ spinnerAlign: PasskeyButtonSpinnerAlign;
52
+ /**
53
+ * When provided, the button reflects a disabled state.
54
+ */
55
+ disabled?: boolean;
56
+ /**
57
+ * When provided, a loading state is applied.
58
+ */
59
+ loading?: boolean;
60
+ /**
61
+ * The event identifier/name as defined in auth service.
62
+ */
63
+ event?: string;
64
+ /**
65
+ * Whether the button is in a loading state.
66
+ */
67
+ private _loading;
68
+ /**
69
+ * Overrides default behavior to render into light DOM.
70
+ */
71
+ protected createRenderRoot(): this;
72
+ /**
73
+ * The `id` of the root element. Equal to `childId` when provided, otherwise
74
+ * derived from the component's part name and `seed`.
75
+ */
76
+ get rootId(): string;
77
+ /**
78
+ * The `id` of the spinner element, derived from `rootId` with the spinner
79
+ * part name appended.
80
+ */
81
+ get spinnerId(): string;
82
+ /**
83
+ * The loading state, derived from the private `_loading` and `loading` prop.
84
+ */
85
+ get isLoading(): boolean | undefined;
86
+ /**
87
+ * Adds the click event listener.
88
+ */
89
+ connectedCallback(): void;
90
+ /**
91
+ * Removes the click event listener.
92
+ */
93
+ 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
+ /**
103
+ * Handles the click event, preventing execution when disabled/loading, firing
104
+ * the click event, and emitting to auth service.
105
+ */
106
+ private _handleClick;
107
+ /**
108
+ * Returns the loading spinner template.
109
+ */
110
+ private _renderSpinner;
111
+ render(): import('../../../../../node_modules/lit-html').TemplateResult<1>;
112
+ }
@@ -0,0 +1,7 @@
1
+ import { SbPasskeyButton } from './_passkey-button';
2
+ export { SbPasskeyButton };
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ "sb-passkey-button": SbPasskeyButton;
6
+ }
7
+ }
@@ -0,0 +1,11 @@
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 Size: Story;
8
+ export declare const Label: Story;
9
+ export declare const Disabled: Story;
10
+ export declare const Loading: Story;
11
+ export declare const SpinnerAlign: Story;
@@ -0,0 +1,15 @@
1
+ import { IconAlign, RtgButtonBasicSize, RtgButtonBasicVariant } from '../../../../types';
2
+ export type PasskeyButtonVariant = RtgButtonBasicVariant;
3
+ export type PasskeyButtonSize = RtgButtonBasicSize;
4
+ export type PasskeyButtonSpinnerAlign = IconAlign;
5
+ export type PasskeyButtonProps = {
6
+ seed: string;
7
+ childId?: string;
8
+ variant: PasskeyButtonVariant;
9
+ size: PasskeyButtonSize;
10
+ label: string;
11
+ spinnerAlign: PasskeyButtonSpinnerAlign;
12
+ disabled?: boolean;
13
+ loading?: boolean;
14
+ event?: string;
15
+ };