@saasbase-io/core-elements 1.9.0 → 1.11.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,250 @@
1
+ import { LitElement } from '../../../../../node_modules/lit';
2
+ import { ConfirmFieldContent, ConfirmFieldProps, ConfirmFieldVariant } from './field.types';
3
+ /**
4
+ * A self-validating confirm password field for auth widget forms.
5
+ * @element sb-confirm-field
6
+ *
7
+ * @part confirm-field (rtg-field)
8
+ * @part confirm-field-content (rtg-field-content): label + description wrapper
9
+ * @part confirm-field-label (rtg-field-label)
10
+ * @part confirm-field-mark (span): decorative marker with text or `"*"` in label
11
+ * @part confirm-field-description (rtg-field-description)
12
+ * @part confirm-field-input (rtg-input/rtg-password-input)
13
+ * @part confirm-field-error (rtg-field-error)
14
+ *
15
+ * @fires sb-confirm-field:validate
16
+ * { id, parentId, name, value, pairSelector, pairValue, valid, type, message }
17
+ * - id: inputId
18
+ * - parentId: rootId
19
+ * - type: "required" | "format" | "success" | "minlength" | "maxlength"
20
+ */
21
+ export declare class SbConfirmField extends LitElement implements ConfirmFieldProps {
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 value used as a substring in the generated part/child IDs, when
47
+ * the `child-id` prop is not provided.
48
+ */
49
+ seed: string;
50
+ /**
51
+ * The `id` value given to the root child/part and used as the base of other
52
+ * child/part IDs.
53
+ */
54
+ childId?: string;
55
+ /**
56
+ * The `id` value given to the input child/part to override the auto-generated
57
+ * input ID, derived from the `rootId`.
58
+ */
59
+ fieldId?: string;
60
+ /**
61
+ * The `name` prop of the input part, used by the parent form.
62
+ */
63
+ name: string;
64
+ /**
65
+ * The variant of the confirm field input, where `"toggle"` renders a
66
+ * hide/show button addon in the input element.
67
+ */
68
+ variant: ConfirmFieldVariant;
69
+ /**
70
+ * Whether the label and description are grouped together above the input, or
71
+ * split up with the input in-between them.
72
+ */
73
+ content: ConfirmFieldContent;
74
+ /**
75
+ * A CSS selector for the paired `sb-password-field`.
76
+ */
77
+ pair: string;
78
+ /**
79
+ * The text content of the field label.
80
+ */
81
+ label: string;
82
+ /**
83
+ * The text used as the input placeholder.
84
+ */
85
+ placeholder?: string;
86
+ /**
87
+ * The text content of the field description.
88
+ */
89
+ description?: string;
90
+ /**
91
+ * The text rendered in the field label as a custom mark.
92
+ */
93
+ mark?: string;
94
+ /**
95
+ * When provided with `required`, a caret mark is rendered in the field label.
96
+ */
97
+ caret?: boolean;
98
+ /**
99
+ * Whether the field is in a disabled state.
100
+ */
101
+ disabled?: boolean;
102
+ /**
103
+ * When provided, the parent form cannot be submitted without this field.
104
+ */
105
+ required?: boolean;
106
+ /**
107
+ * Error message shown when the field is required but empty upon submission.
108
+ */
109
+ requiredError: string;
110
+ /**
111
+ * Error message shown when the confirm value does not match the `pair`
112
+ * password field's value.
113
+ */
114
+ matchError: string;
115
+ /**
116
+ * Indicates that the field is in an invalid state.
117
+ */
118
+ private _invalid;
119
+ /**
120
+ * The error message rendered in field error when in an invalid state.
121
+ */
122
+ private _error;
123
+ /**
124
+ * The current value of the confirm input.
125
+ */
126
+ private _value;
127
+ /**
128
+ * Reference to the nearest `form` ancestor.
129
+ */
130
+ private _form;
131
+ /**
132
+ * Overrides default behavior to render into light DOM.
133
+ */
134
+ protected createRenderRoot(): this;
135
+ /**
136
+ * The `id` of the root element. Equal to `childId` when provided, otherwise
137
+ * derived from the component's part name and `seed`.
138
+ */
139
+ get rootId(): string;
140
+ /**
141
+ * The `id` of the field content element, derived from `rootId` with the
142
+ * content part name appended.
143
+ */
144
+ get contentId(): string;
145
+ /**
146
+ * The `id` of the field label element, derived from `rootId` with the label
147
+ * part name appended.
148
+ */
149
+ get labelId(): string;
150
+ /**
151
+ * The `id` of the field description element, derived from `rootId` with the
152
+ * description part name appended.
153
+ */
154
+ get descriptionId(): string;
155
+ /**
156
+ * The `id` of the mark element, derived from `rootId` with the mark part name
157
+ * appended.
158
+ */
159
+ get markId(): string;
160
+ /**
161
+ * The `id` of the input element, equal to `fieldId` when provided, otherwise
162
+ * derived from `rootId` with the input part name appended.
163
+ */
164
+ get inputId(): string;
165
+ /**
166
+ * The `id` of the field error element, derived from `rootId` with the error
167
+ * part name appended.
168
+ */
169
+ get errorId(): string;
170
+ /**
171
+ * Adds the input, form submit, and form reset event listeners.
172
+ */
173
+ connectedCallback(): void;
174
+ /**
175
+ * Removes the input, form submit, and form reset event listeners.
176
+ */
177
+ disconnectedCallback(): void;
178
+ /**
179
+ * The public validate method that calls the private `_validate()` method for
180
+ * manual, external validation.
181
+ */
182
+ validate(): boolean;
183
+ /**
184
+ * Returns the paired password field's value or an empty string if the pair
185
+ * cannot be found.
186
+ */
187
+ private _pairValue;
188
+ /**
189
+ * Defines and dispatches the validate event.
190
+ */
191
+ private _dispatchValidate;
192
+ /**
193
+ * Handles the required condition validation, accepting empty non-required
194
+ * fields and non-empty required fields, otherwise dispatching and displaying
195
+ * the required error.
196
+ */
197
+ private _validateRequired;
198
+ /**
199
+ * Handles the match condition validation, obtaining the paired field's value,
200
+ * comparing it to the confirm field's value, dispatching and displaying the
201
+ * match error if the values do not match.
202
+ */
203
+ private _validateMatch;
204
+ /**
205
+ * Resets the `_invalid` and `_error` private props and dispatches the
206
+ * validate event, indicating a successfully validated and valid confirm.
207
+ */
208
+ private _doValidateSuccess;
209
+ /**
210
+ * Handles validation and dispatches the success event if the required,
211
+ * length, and format conditions are met.
212
+ */
213
+ private _validate;
214
+ /**
215
+ * Handles the input event, updating the private `_value` prop.
216
+ */
217
+ private _handleInput;
218
+ /**
219
+ * Handles the form submit event, running the `_validate()` method and
220
+ * preventing the default submission behavior if invalid.
221
+ */
222
+ private _handleFormSubmit;
223
+ /**
224
+ * Handles the form reset event, resetting the input element's `value` as well
225
+ * as the confirm field's private props: `_value`, `_invalid`, and `_error`.
226
+ */
227
+ private _handleFormReset;
228
+ /**
229
+ * Conditionally returns the mark template for the field label. When `caret`
230
+ * and `required` are provided, the mark becomes an asterisk. When `mark` is
231
+ * provided, its value is rendered inside the element.
232
+ * If both a caret and custom text mark have their conditions met, the custom
233
+ * mark will be prioritised and rendered instead of the asterisk.
234
+ */
235
+ private _renderMark;
236
+ /**
237
+ * Returns the field label template with the label text and optional mark.
238
+ */
239
+ private _renderLabel;
240
+ /**
241
+ * Returns the field description template if `description` is defined.
242
+ */
243
+ private _renderDescription;
244
+ /**
245
+ * Returns the field error template with the `_error` message if the
246
+ * `_invalid` state is `true`.
247
+ */
248
+ private _renderError;
249
+ render(): import('../../../../../node_modules/lit-html').TemplateResult<1>;
250
+ }
@@ -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 Label: Story;
7
+ export declare const Placeholder: Story;
8
+ export declare const Description: Story;
9
+ export declare const Variant: 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;
@@ -57,4 +57,13 @@ export type PasswordFieldProps = Omit<BaseFieldPropsWithLength, "content"> & {
57
57
  content: PasswordFieldContent;
58
58
  rules: PasswordFieldRule[];
59
59
  };
60
+ export type ConfirmFieldValidateType = Exclude<BaseFieldValidateType, "format"> | "match";
61
+ export type ConfirmFieldVariant = PasswordFieldVariant;
62
+ export type ConfirmFieldContent = BaseFieldContent;
63
+ export type ConfirmFieldProps = Omit<BaseFieldProps, "content" | "formatError"> & {
64
+ variant: ConfirmFieldVariant;
65
+ content: ConfirmFieldContent;
66
+ pair: string;
67
+ matchError: string;
68
+ };
60
69
  export {};
@@ -1,13 +1,15 @@
1
+ import { SbConfirmField } from './_confirm-field';
1
2
  import { SbEmailField } from './_email-field';
2
3
  import { SbPasswordField } from './_password-field';
3
4
  import { SbPhoneField } from './_phone-field';
4
5
  import { SbUsernameField } from './_username-field';
5
- export { SbEmailField, SbPasswordField, SbPhoneField, SbUsernameField };
6
+ export { SbConfirmField, SbEmailField, SbPasswordField, SbPhoneField, SbUsernameField, };
6
7
  declare global {
7
8
  interface HTMLElementTagNameMap {
8
9
  "sb-email-field": SbEmailField;
9
10
  "sb-phone-field": SbPhoneField;
10
11
  "sb-username-field": SbUsernameField;
11
12
  "sb-password-field": SbPasswordField;
13
+ "sb-confirm-field": SbConfirmField;
12
14
  }
13
15
  }
@@ -0,0 +1,111 @@
1
+ import { LitElement } from '../../../../../node_modules/lit';
2
+ import { Provider, ProviderButtonContent, ProviderButtonIconAlign, ProviderButtonSize, ProviderButtonVariant, ProviderFieldOverride, ProviderFieldProps } from './provider.types';
3
+ /**
4
+ * A wrapper field, containing and styling auth provider buttons.
5
+ * @element sb-provider-field
6
+ *
7
+ * @part provider-field (rtg-field)
8
+ * @part provider-field-button (sb-provider-button)
9
+ */
10
+ export declare class SbProviderField extends LitElement implements ProviderFieldProps {
11
+ private static readonly _ROOT;
12
+ private static readonly _BUTTON;
13
+ /**
14
+ * The stable CSS part names exposed for external targeting.
15
+ */
16
+ static get parts(): {
17
+ root: string;
18
+ button: string;
19
+ };
20
+ /**
21
+ * A unique value used as a substring in the generated part/child IDs, when
22
+ * the `child-id` prop is not provided.
23
+ */
24
+ seed: string;
25
+ /**
26
+ * The `id` value given to the root child/part and used as the base of other
27
+ * child/part IDs.
28
+ */
29
+ childId?: string;
30
+ /**
31
+ * The providers included as provider buttons in this field.
32
+ */
33
+ providers: Provider[];
34
+ /**
35
+ * The `content` prop passed to each of the provider buttons.
36
+ */
37
+ content?: ProviderButtonContent;
38
+ /**
39
+ * The `variant` prop passed to each of the provider buttons.
40
+ */
41
+ variant?: ProviderButtonVariant;
42
+ /**
43
+ * The `size` prop passed to each of the provider buttons.
44
+ */
45
+ size?: ProviderButtonSize;
46
+ /**
47
+ * The `prompt` prop passed to each of the provider buttons.
48
+ */
49
+ prompt?: string;
50
+ /**
51
+ * The `icon-align` prop passed to each of the provider buttons.
52
+ */
53
+ iconAlign?: ProviderButtonIconAlign;
54
+ /**
55
+ * The `label` prop passed to each of the provider buttons.
56
+ */
57
+ label?: string;
58
+ /**
59
+ * The `disabled` prop passed to each of the provider buttons.
60
+ */
61
+ disabled?: boolean;
62
+ /**
63
+ * The `loading` prop passed to each of the provider buttons.
64
+ */
65
+ loading?: boolean;
66
+ /**
67
+ * The `event` prop passed to each of the provider buttons.
68
+ */
69
+ event?: string;
70
+ /**
71
+ * A list of provider-specific prop overrides.
72
+ */
73
+ overrides: ProviderFieldOverride[];
74
+ /**
75
+ * Overrides default behavior to render into light DOM.
76
+ */
77
+ protected createRenderRoot(): this;
78
+ /**
79
+ * The `id` of the root element. Equal to `childId` when provided, otherwise
80
+ * derived from the component's part name and `seed`.
81
+ */
82
+ get rootId(): string;
83
+ /**
84
+ * The `id` of the provider button element, derived from `rootId` with the
85
+ * button part name appended.
86
+ */
87
+ get buttonId(): string;
88
+ /**
89
+ * The number of columns within the field, given to the root element via its
90
+ * `data-columns` attribute. In hyphenated values (e.g. `"two-three"`), the
91
+ * first part is the number of columns in the first row, and the second part
92
+ * is the number of columns in the second row.
93
+ */
94
+ get columns(): "one" | "three" | "two-three" | "three-four" | "four";
95
+ /**
96
+ * The `providers` array without any duplicates.
97
+ */
98
+ private get _providers();
99
+ /**
100
+ * The `overrides` array without any duplicate `provider` entries (i.e. no
101
+ * two override items have the same `provider` value).
102
+ */
103
+ private get _overrides();
104
+ /**
105
+ * Returns the template for the button part, specifically an
106
+ * `sb-provider-button` element with props originating from `overrides` if
107
+ * given, otherwise the general prop given to this field component.
108
+ */
109
+ private _renderButton;
110
+ render(): import('../../../../../node_modules/lit-html').TemplateResult<1>;
111
+ }
@@ -1,7 +1,9 @@
1
1
  import { SbProviderButton } from './_provider-button';
2
- export { SbProviderButton };
2
+ import { SbProviderField } from './_provider-field';
3
+ export { SbProviderButton, SbProviderField };
3
4
  declare global {
4
5
  interface HTMLElementTagNameMap {
5
6
  "sb-provider-button": SbProviderButton;
7
+ "sb-provider-field": SbProviderField;
6
8
  }
7
9
  }
@@ -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 Content: Story;
7
+ export declare const Variant: Story;
8
+ export declare const Size: Story;
9
+ export declare const Prompt: Story;
10
+ export declare const IconAlign: Story;
11
+ export declare const Label: Story;
12
+ export declare const Disabled: Story;
13
+ export declare const Loading: Story;
14
+ export declare const Overrides: Story;
@@ -4,17 +4,32 @@ export type ProviderButtonContent = "icon" | "icon-label" | "label";
4
4
  export type ProviderButtonVariant = RtgButtonBasicVariant;
5
5
  export type ProviderButtonSize = RtgButtonBasicSize;
6
6
  export type ProviderButtonIconAlign = IconAlign;
7
- export type ProviderButtonProps = {
8
- seed: string;
7
+ type BaseProviderButtonProps = {
8
+ seed?: string;
9
9
  childId?: string;
10
10
  provider: Provider;
11
+ content?: ProviderButtonContent;
12
+ variant?: ProviderButtonVariant;
13
+ size?: ProviderButtonSize;
14
+ prompt?: string;
15
+ iconAlign?: ProviderButtonIconAlign;
16
+ label?: string;
17
+ disabled?: boolean;
18
+ loading?: boolean;
19
+ event?: string;
20
+ };
21
+ export type ProviderButtonProps = Omit<BaseProviderButtonProps, "seed" | "content" | "variant" | "size" | "prompt" | "iconAlign"> & {
22
+ seed: string;
11
23
  content: ProviderButtonContent;
12
24
  variant: ProviderButtonVariant;
13
25
  size: ProviderButtonSize;
14
26
  prompt: string;
15
27
  iconAlign: ProviderButtonIconAlign;
16
- label?: string;
17
- disabled?: boolean;
18
- loading?: boolean;
19
- event?: string;
20
28
  };
29
+ export type ProviderFieldOverride = BaseProviderButtonProps;
30
+ export type ProviderFieldProps = Omit<BaseProviderButtonProps, "seed" | "provider"> & {
31
+ seed: string;
32
+ providers: Provider[];
33
+ overrides: ProviderFieldOverride[];
34
+ };
35
+ export {};