@saasbase-io/core-elements 1.12.0 → 1.13.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.
- package/dist/components/renderers/_updated/field/_identifier-field.d.ts +242 -0
- package/dist/components/renderers/_updated/field/field.stories/identifier-field.stories.d.ts +15 -0
- package/dist/components/renderers/_updated/field/field.types.d.ts +11 -0
- package/dist/components/renderers/_updated/field/index.d.ts +3 -1
- package/dist/index.js +706 -645
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3873 -3547
- package/dist/index.mjs.map +1 -1
- package/dist/types/auth.d.ts +1 -0
- package/dist/types/components/rtg.d.ts +2 -1
- package/package.json +1 -1
|
@@ -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
|
}
|