@spectrum-web-components/textfield 0.0.0-20241209155954

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/README.md ADDED
@@ -0,0 +1,180 @@
1
+ ## Description
2
+
3
+ `sp-textfield` components are text boxes that allow users to input custom text entries with a keyboard. Various decorations can be displayed around the field to communicate the entry requirements.
4
+
5
+ ### Usage
6
+
7
+ [![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/textfield?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/textfield)
8
+ [![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/textfield?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/textfield)
9
+ [![Try it on webcomponents.dev](https://img.shields.io/badge/Try%20it%20on-webcomponents.dev-green?style=for-the-badge)](https://webcomponents.dev/edit/collection/fO75441E1Q5ZlI0e9pgq/EcE2Yrwz0MDIGkCzbyvl/src/index.ts)
10
+
11
+ ```
12
+ yarn add @spectrum-web-components/textfield
13
+ ```
14
+
15
+ Import the side effectful registration of `<sp-textfield>` via:
16
+
17
+ ```
18
+ import '@spectrum-web-components/textfield/sp-textfield.js';
19
+ ```
20
+
21
+ When looking to leverage the `Textfield` base class as a type and/or for extension purposes, do so via:
22
+
23
+ ```
24
+ import { Textfield } from '@spectrum-web-components/textfield';
25
+ ```
26
+
27
+ ## Sizes
28
+
29
+ <sp-tabs selected="m" auto label="Size Attribute Options">
30
+ <sp-tab value="s">Small</sp-tab>
31
+ <sp-tab-panel value="s">
32
+
33
+ ```html
34
+ <sp-field-label size="s" for="name-0-s">Name</sp-field-label>
35
+ <sp-textfield
36
+ size="s"
37
+ id="name-0-s"
38
+ placeholder="Enter your name"
39
+ ></sp-textfield>
40
+ ```
41
+
42
+ </sp-tab-panel>
43
+ <sp-tab value="m">Medium</sp-tab>
44
+ <sp-tab-panel value="m">
45
+
46
+ ```html
47
+ <sp-field-label for="name-0-m">Name</sp-field-label>
48
+ <sp-textfield id="name-0-m" placeholder="Enter your name"></sp-textfield>
49
+ ```
50
+
51
+ </sp-tab-panel>
52
+ <sp-tab value="l">Large</sp-tab>
53
+ <sp-tab-panel value="l">
54
+
55
+ ```html
56
+ <sp-field-label size="l" for="name-0-l">Name</sp-field-label>
57
+ <sp-textfield
58
+ size="l"
59
+ id="name-0-l"
60
+ placeholder="Enter your name"
61
+ ></sp-textfield>
62
+ ```
63
+
64
+ </sp-tab-panel>
65
+ <sp-tab value="xl">Extra Large</sp-tab>
66
+ <sp-tab-panel value="xl">
67
+
68
+ ```html
69
+ <sp-field-label size="xl" for="name-0-xl">Name</sp-field-label>
70
+ <sp-textfield
71
+ size="xl"
72
+ id="name-0-xl"
73
+ placeholder="Enter your name"
74
+ ></sp-textfield>
75
+ ```
76
+
77
+ </sp-tab-panel>
78
+ </sp-tabs>
79
+
80
+ ## Variants
81
+
82
+ ### Valid
83
+
84
+ Dictate the validity state of the text entry with the `valid` attribute.
85
+
86
+ ```html
87
+ <sp-field-label for="name-1" required>Name</sp-field-label>
88
+ <sp-textfield
89
+ id="name-1"
90
+ placeholder="Enter your name"
91
+ valid
92
+ value="My Name"
93
+ ></sp-textfield>
94
+ ```
95
+
96
+ ### Invalid
97
+
98
+ Dictate the invalidity state of the text entry with the `invalid` attribute.
99
+
100
+ ```html
101
+ <sp-field-label for="name-2" required>Name</sp-field-label>
102
+ <sp-textfield id="name-2" invalid placeholder="Enter your name"></sp-textfield>
103
+ ```
104
+
105
+ ### Quiet
106
+
107
+ The quiet style works best when a clear layout (vertical stack, table, grid) assists in a user's ability to parse the element. Too many quiet components in a small space can be hard to read.
108
+
109
+ ```html
110
+ <sp-field-label for="name-3">Name (quietly)</sp-field-label>
111
+ <sp-textfield id="name-3" placeholder="Enter your name" quiet></sp-textfield>
112
+ ```
113
+
114
+ ### Types
115
+
116
+ When inputting URLs, telephone numbers, email addresses, or passwords, specify a `type` to provide
117
+ user affordances like mobile keyboards and obscured characters:
118
+
119
+ - `url`
120
+ - `tel`
121
+ - `email`
122
+ - `password`
123
+ - `text` (default)
124
+
125
+ ```html
126
+ <sp-field-label for="tel-1">Telephone</sp-field-label>
127
+ <sp-textfield
128
+ id="tel-1"
129
+ type="tel"
130
+ placeholder="Enter your phone number"
131
+ ></sp-textfield>
132
+ <sp-field-label for="password-1">Password</sp-field-label>
133
+ <sp-textfield id="password-1" type="password"></sp-textfield>
134
+ ```
135
+
136
+ If the `type` attribute is not specified, or if it does not match any of these values, the default type adopted is "text."
137
+
138
+ ## Help text
139
+
140
+ Help text can be accessibly associated with an `<sp-textfield>` element by using the `help-text` or `negative-help-text` slots. When using the `negative-help-text` slot, `<sp-textfield>` will self manage the presence of this content based on the value of the `invalid` property on your `<sp-textfield>` element. Content within the `help-text` slot will be show by default. When your `<sp-textfield>` should receive help text based on state outside of the complexity of `invalid` or not, manage the content addressed to the `help-text` from above to ensure that it displays the right messaging and possesses the right `variant`.
141
+
142
+ <sp-tabs selected="self" auto label="Help text usage in textfields">
143
+ <sp-tab value="self">Self managed</sp-tab>
144
+ <sp-tab-panel value="self">
145
+
146
+ ```html
147
+ <sp-field-label for="self">Stay "Positive"</sp-field-label>
148
+ <sp-textfield id="self" pattern="[P][o][s][i][t][i][v][e]" value="Positive">
149
+ <sp-help-text slot="help-text">
150
+ Tell us how you are feeling today.
151
+ </sp-help-text>
152
+ <sp-help-text slot="negative-help-text">Please be "Positive".</sp-help-text>
153
+ </sp-textfield>
154
+ ```
155
+
156
+ </sp-tab-panel>
157
+ <sp-tab value="above">Managed from above</sp-tab>
158
+ <sp-tab-panel value="above">
159
+
160
+ ```html
161
+ <sp-field-label for="managed">Stay "Positive"</sp-field-label>
162
+ <sp-textfield
163
+ id="managed"
164
+ pattern="[P][o][s][i][t][i][v][e]"
165
+ value="Positive"
166
+ oninput='
167
+ const helpText = this.querySelector(`[slot="help-text"]`);
168
+ helpText.textContent = this.invalid ? `Please be "Positive".` : `Tell us how you are feeling today.`;
169
+ helpText.variant = this.invalid ? `negative` : `neutral`;
170
+ '
171
+ >
172
+ <sp-help-text slot="neutral-text">
173
+ Tell us how you're feeling today.
174
+ </sp-help-text>
175
+ <sp-help-text slot="help-text">Please be "Positive".</sp-help-text>
176
+ </sp-textfield>
177
+ ```
178
+
179
+ </sp-tab-panel>
180
+ </sp-tabs>
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@spectrum-web-components/textfield",
3
+ "version": "0.0.0-20241209155954",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "",
8
+ "license": "Apache-2.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/adobe/spectrum-web-components.git",
12
+ "directory": "packages/textfield"
13
+ },
14
+ "author": "",
15
+ "homepage": "https://opensource.adobe.com/spectrum-web-components/components/textfield",
16
+ "bugs": {
17
+ "url": "https://github.com/adobe/spectrum-web-components/issues"
18
+ },
19
+ "main": "./src/index.js",
20
+ "module": "./src/index.js",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "development": "./src/index.dev.js",
25
+ "default": "./src/index.js"
26
+ },
27
+ "./package.json": "./package.json",
28
+ "./src/Textfield.js": {
29
+ "development": "./src/Textfield.dev.js",
30
+ "default": "./src/Textfield.js"
31
+ },
32
+ "./src/index.js": {
33
+ "development": "./src/index.dev.js",
34
+ "default": "./src/index.js"
35
+ },
36
+ "./src/textfield-overrides.css.js": "./src/textfield-overrides.css.js",
37
+ "./src/textfield.css.js": "./src/textfield.css.js",
38
+ "./sp-textfield.js": {
39
+ "development": "./sp-textfield.dev.js",
40
+ "default": "./sp-textfield.js"
41
+ }
42
+ },
43
+ "scripts": {
44
+ "test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
45
+ },
46
+ "files": [
47
+ "**/*.d.ts",
48
+ "**/*.js",
49
+ "**/*.js.map",
50
+ "custom-elements.json",
51
+ "!stories/",
52
+ "!test/"
53
+ ],
54
+ "keywords": [
55
+ "spectrum css",
56
+ "web components",
57
+ "lit-element",
58
+ "lit-html"
59
+ ],
60
+ "dependencies": {
61
+ "@spectrum-web-components/base": "0.0.0-20241209155954",
62
+ "@spectrum-web-components/help-text": "0.0.0-20241209155954",
63
+ "@spectrum-web-components/icon": "0.0.0-20241209155954",
64
+ "@spectrum-web-components/icons-ui": "0.0.0-20241209155954",
65
+ "@spectrum-web-components/icons-workflow": "0.0.0-20241209155954",
66
+ "@spectrum-web-components/shared": "0.0.0-20241209155954"
67
+ },
68
+ "devDependencies": {
69
+ "@spectrum-css/textfield": "^8.0.0-s2-foundations.16"
70
+ },
71
+ "types": "./src/index.d.ts",
72
+ "customElements": "custom-elements.json",
73
+ "sideEffects": [
74
+ "./sp-*.js",
75
+ "./**/*.dev.js"
76
+ ]
77
+ }
@@ -0,0 +1,6 @@
1
+ import { Textfield } from './src/Textfield.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'sp-textfield': Textfield;
5
+ }
6
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ import { Textfield } from "./src/Textfield.dev.js";
3
+ import { defineElement } from "@spectrum-web-components/base/src/define-element.js";
4
+ defineElement("sp-textfield", Textfield);
5
+ //# sourceMappingURL=sp-textfield.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["sp-textfield.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Textfield } from './src/Textfield.dev.js'\nimport { defineElement } from '@spectrum-web-components/base/src/define-element.js';\n\ndefineElement('sp-textfield', Textfield);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-textfield': Textfield;\n }\n}\n"],
5
+ "mappings": ";AAYA,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAE9B,cAAc,gBAAgB,SAAS;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";import{Textfield as e}from"./src/Textfield.js";import{defineElement as t}from"@spectrum-web-components/base/src/define-element.js";t("sp-textfield",e);
2
+ //# sourceMappingURL=sp-textfield.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["sp-textfield.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Textfield } from './src/Textfield.js';\nimport { defineElement } from '@spectrum-web-components/base/src/define-element.js';\n\ndefineElement('sp-textfield', Textfield);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-textfield': Textfield;\n }\n}\n"],
5
+ "mappings": "aAYA,OAAS,aAAAA,MAAiB,qBAC1B,OAAS,iBAAAC,MAAqB,sDAE9BA,EAAc,eAAgBD,CAAS",
6
+ "names": ["Textfield", "defineElement"]
7
+ }
@@ -0,0 +1,144 @@
1
+ import { CSSResultArray, nothing, PropertyValues, TemplateResult } from '@spectrum-web-components/base';
2
+ import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
3
+ import '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js';
4
+ import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';
5
+ declare const textfieldTypes: readonly ["text", "url", "tel", "email", "password"];
6
+ export type TextfieldType = (typeof textfieldTypes)[number];
7
+ declare const TextfieldBase_base: typeof Focusable & {
8
+ new (...args: any[]): import("@spectrum-web-components/base").SizedElementInterface;
9
+ prototype: import("@spectrum-web-components/base").SizedElementInterface;
10
+ } & {
11
+ new (...args: any[]): import("@spectrum-web-components/help-text/src/manage-help-text.js").HelpTextElementInterface;
12
+ prototype: import("@spectrum-web-components/help-text/src/manage-help-text.js").HelpTextElementInterface;
13
+ };
14
+ /**
15
+ * @fires input - The value of the element has changed.
16
+ * @fires change - An alteration to the value of the element has been committed by the user.
17
+ */
18
+ export declare class TextfieldBase extends TextfieldBase_base {
19
+ static get styles(): CSSResultArray;
20
+ protected appliedLabel?: string;
21
+ /**
22
+ * A regular expression outlining the keys that will be allowed to update the value of the form control.
23
+ */
24
+ allowedKeys: string;
25
+ /**
26
+ * @private
27
+ */
28
+ focused: boolean;
29
+ protected inputElement: HTMLInputElement | HTMLTextAreaElement;
30
+ /**
31
+ * Whether the `value` held by the form control is invalid.
32
+ */
33
+ invalid: boolean;
34
+ /**
35
+ * A string applied via `aria-label` to the form control when a user visible label is not provided.
36
+ */
37
+ label: string;
38
+ /**
39
+ * Name of the form control.
40
+ */
41
+ name: string | undefined;
42
+ /**
43
+ * Text that appears in the form control when it has no value set
44
+ */
45
+ placeholder: string;
46
+ set type(val: TextfieldType);
47
+ get type(): TextfieldType;
48
+ /**
49
+ * @private
50
+ * This binding allows for invalid value for `type` to still be reflected to the DOM
51
+ */
52
+ private _type;
53
+ /**
54
+ * Pattern the `value` must match to be valid
55
+ */
56
+ pattern?: string;
57
+ /**
58
+ * Whether a form control delivered with the `multiline` attribute will change size
59
+ * vertically to accomodate longer input
60
+ */
61
+ grows: boolean;
62
+ /**
63
+ * Defines the maximum string length that the user can enter
64
+ */
65
+ maxlength: number;
66
+ /**
67
+ * Defines the minimum string length that the user can enter
68
+ */
69
+ minlength: number;
70
+ /**
71
+ * Whether the form control should accept a value longer than one line
72
+ */
73
+ multiline: boolean;
74
+ /**
75
+ * Whether a user can interact with the value of the form control
76
+ */
77
+ readonly: boolean;
78
+ /**
79
+ * The specific number of rows the form control should provide in the user interface
80
+ */
81
+ rows: number;
82
+ /**
83
+ * Whether the `value` held by the form control is valid.
84
+ */
85
+ valid: boolean;
86
+ /**
87
+ * The value held by the form control
88
+ */
89
+ set value(value: string | number);
90
+ get value(): string | number;
91
+ protected _value: string | number;
92
+ /**
93
+ * Whether to display the form control with no visible background
94
+ */
95
+ quiet: boolean;
96
+ /**
97
+ * Whether the form control will be found to be invalid when it holds no `value`
98
+ */
99
+ required: boolean;
100
+ /**
101
+ * What form of assistance should be provided when attempting to supply a value to the form control
102
+ */
103
+ autocomplete?: 'list' | 'none' | HTMLInputElement['autocomplete'] | HTMLTextAreaElement['autocomplete'];
104
+ get focusElement(): HTMLInputElement | HTMLTextAreaElement;
105
+ /**
106
+ * Sets the start and end positions of the current selection.
107
+ *
108
+ * @param selectionStart The 0-based index of the first selected character. An index greater than the length of the
109
+ * element's value is treated as pointing to the end of the value.
110
+ * @param selectionEnd The 0-based index of the character after the last selected character. An index greater than
111
+ * the length of the element's value is treated as pointing to the end of the value.
112
+ * @param [selectionDirection="none"] A string indicating the direction in which the selection is considered to
113
+ * have been performed.
114
+ */
115
+ setSelectionRange(selectionStart: number, selectionEnd: number, selectionDirection?: 'forward' | 'backward' | 'none'): void;
116
+ /**
117
+ * Selects all the text.
118
+ */
119
+ select(): void;
120
+ protected handleInput(_event: Event): void;
121
+ protected handleChange(): void;
122
+ protected onFocus(): void;
123
+ protected onBlur(_event: FocusEvent): void;
124
+ protected handleInputElementPointerdown(): void;
125
+ protected renderStateIcons(): TemplateResult | typeof nothing;
126
+ protected get displayValue(): string;
127
+ private get renderMultiline();
128
+ private get renderInput();
129
+ protected renderField(): TemplateResult;
130
+ protected render(): TemplateResult;
131
+ protected update(changedProperties: PropertyValues): void;
132
+ checkValidity(): boolean;
133
+ }
134
+ /**
135
+ * @element sp-textfield
136
+ * @slot help-text - default or non-negative help text to associate to your form element
137
+ * @slot negative-help-text - negative help text to associate to your form element when `invalid`
138
+ */
139
+ export declare class Textfield extends TextfieldBase {
140
+ set value(value: string);
141
+ get value(): string;
142
+ protected _value: string;
143
+ }
144
+ export {};