@saasbase-io/core-elements 1.5.0 → 1.7.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,235 @@
1
+ import { LitElement } from '../../../../../node_modules/lit';
2
+ import { PhoneFieldContent, PhoneFieldProps } from './field.types';
3
+ /**
4
+ * A self-validating phone field for auth widget forms.
5
+ * @element sb-phone-field
6
+ *
7
+ * @part phone-field (rtg-field)
8
+ * @part phone-field-content (rtg-field-content): label + description wrapper
9
+ * @part phone-field-label (rtg-field-label)
10
+ * @part phone-field-mark (span): decorative marker with text or `"*"` in label
11
+ * @part phone-field-description (rtg-field-description)
12
+ * @part phone-field-input (rtg-input)
13
+ * @part phone-field-error (rtg-field-error)
14
+ *
15
+ * @fires sb-phone-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 SbPhoneField extends LitElement implements PhoneFieldProps {
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: PhoneFieldContent;
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 phone 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 the normalized value of `_value` by stripping all whitespace.
163
+ */
164
+ private get _normalizedValue();
165
+ /**
166
+ * Adds the input, form submit, and form reset event listeners.
167
+ */
168
+ connectedCallback(): void;
169
+ /**
170
+ * Removes the input, form submit, and form reset event listeners.
171
+ */
172
+ disconnectedCallback(): void;
173
+ /**
174
+ * The public validate method that calls the private `_validate()` method for
175
+ * manual, external validation.
176
+ */
177
+ validate(): boolean;
178
+ /**
179
+ * Defines and dispatches the validate event.
180
+ */
181
+ private _dispatchValidate;
182
+ /**
183
+ * Handles the required condition validation, accepting empty non-required
184
+ * fields and non-empty required fields, otherwise dispatching and displaying
185
+ * the required error.
186
+ */
187
+ private _validateRequired;
188
+ /**
189
+ * Handles the format condition validation with `_PATTERN`, accepting empty
190
+ * non-required fields and non-empty fields that satisfy the pattern,
191
+ * otherwise dispatching and displaying the format error.
192
+ */
193
+ private _validateFormat;
194
+ /**
195
+ * Handles validation and dispatches the success event if the required and
196
+ * format conditions are met.
197
+ */
198
+ private _validate;
199
+ /**
200
+ * Handles the input event, updating the private `_value` prop.
201
+ */
202
+ private _handleInput;
203
+ /**
204
+ * Handles the form submit event, running the `_validate()` method and
205
+ * preventing the default submission behavior if invalid.
206
+ */
207
+ private _handleFormSubmit;
208
+ /**
209
+ * Handles the form reset event, resetting the input element's `value` as well
210
+ * as the phone field's private props: `_value`, `_invalid`, and `_error`.
211
+ */
212
+ private _handleFormReset;
213
+ /**
214
+ * Conditionally returns the mark template for the field label. When `caret`
215
+ * and `required` are provided, the mark becomes an asterisk. When `mark` is
216
+ * provided, its value is rendered inside the element.
217
+ * If both a caret and custom text mark have their conditions met, the custom
218
+ * mark will be prioritised and rendered instead of the asterisk.
219
+ */
220
+ private _renderMark;
221
+ /**
222
+ * Returns the field label template with the label text and optional mark.
223
+ */
224
+ private _renderLabel;
225
+ /**
226
+ * Returns the field description template if `description` is defined.
227
+ */
228
+ private _renderDescription;
229
+ /**
230
+ * Returns the field error template with the `_error` message if the
231
+ * `_invalid` state is `true`.
232
+ */
233
+ private _renderError;
234
+ render(): import('../../../../../node_modules/lit-html').TemplateResult<1>;
235
+ }
@@ -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,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,28 @@
1
+ type BaseFieldContent = "split" | "group";
2
+ type BaseFieldProps = {
3
+ seed: string;
4
+ childId?: string;
5
+ fieldId?: string;
6
+ name: string;
7
+ content: BaseFieldContent;
8
+ label: string;
9
+ placeholder?: string;
10
+ description?: string;
11
+ mark?: string;
12
+ caret?: boolean;
13
+ disabled?: boolean;
14
+ required?: boolean;
15
+ requiredError: string;
16
+ formatError: string;
17
+ };
18
+ export type EmailFieldValidateType = "success" | "required" | "format";
19
+ export type EmailFieldContent = BaseFieldContent;
20
+ export type EmailFieldProps = Omit<BaseFieldProps, "content"> & {
21
+ content: EmailFieldContent;
22
+ };
23
+ export type PhoneFieldValidateType = "success" | "required" | "format";
24
+ export type PhoneFieldContent = BaseFieldContent;
25
+ export type PhoneFieldProps = Omit<BaseFieldProps, "content"> & {
26
+ content: PhoneFieldContent;
27
+ };
28
+ export {};
@@ -0,0 +1,9 @@
1
+ import { SbEmailField } from './_email-field';
2
+ import { SbPhoneField } from './_phone-field';
3
+ export { SbEmailField, SbPhoneField };
4
+ declare global {
5
+ interface HTMLElementTagNameMap {
6
+ "sb-email-field": SbEmailField;
7
+ "sb-phone-field": SbPhoneField;
8
+ }
9
+ }
@@ -1,3 +1,4 @@
1
+ export * from './field';
1
2
  export * from './form';
2
3
  export * from './passkey-button';
3
4
  export * from './provider';