@momentum-design/components 0.18.4 → 0.18.6
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/browser/index.js +427 -62
- package/dist/browser/index.js.map +4 -4
- package/dist/components/checkbox/checkbox.component.d.ts +71 -0
- package/dist/components/checkbox/checkbox.component.js +150 -0
- package/dist/components/checkbox/checkbox.constants.d.ts +6 -0
- package/dist/components/checkbox/checkbox.constants.js +7 -0
- package/dist/components/checkbox/checkbox.styles.d.ts +2 -0
- package/dist/components/checkbox/checkbox.styles.js +106 -0
- package/dist/components/checkbox/index.d.ts +8 -0
- package/dist/components/checkbox/index.js +5 -0
- package/dist/components/formfieldwrapper/formfieldwrapper.constants.d.ts +3 -3
- package/dist/components/formfieldwrapper/formfieldwrapper.constants.js +3 -3
- package/dist/components/formfieldwrapper/formfieldwrapper.utils.js +4 -4
- package/dist/components/input/index.d.ts +10 -0
- package/dist/components/input/index.js +7 -0
- package/dist/components/input/input.component.d.ts +208 -0
- package/dist/components/input/input.component.js +401 -0
- package/dist/components/input/input.constants.d.ts +25 -0
- package/dist/components/input/input.constants.js +29 -0
- package/dist/components/input/input.styles.d.ts +2 -0
- package/dist/components/input/input.styles.js +118 -0
- package/dist/components/input/input.types.d.ts +4 -0
- package/dist/components/input/input.types.js +1 -0
- package/dist/custom-elements.json +2569 -1222
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/react/checkbox/index.d.ts +27 -0
- package/dist/react/checkbox/index.js +36 -0
- package/dist/react/index.d.ts +5 -3
- package/dist/react/index.js +5 -3
- package/dist/react/input/index.d.ts +39 -0
- package/dist/react/input/index.js +48 -0
- package/dist/utils/mixins/DataAriaLabelMixin.d.ts +6 -0
- package/dist/utils/mixins/DataAriaLabelMixin.js +29 -0
- package/package.json +1 -1
@@ -0,0 +1,401 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
import { html, nothing } from 'lit';
|
11
|
+
import { property, query } from 'lit/decorators.js';
|
12
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
13
|
+
import styles from './input.styles';
|
14
|
+
import FormfieldWrapper from '../formfieldwrapper';
|
15
|
+
import { NameMixin } from '../../utils/mixins/NameMixin';
|
16
|
+
import { AUTO_CAPITALIZE, DEFAULTS, PREFIX_TEXT_OPTIONS } from './input.constants';
|
17
|
+
import { ValueMixin } from '../../utils/mixins/ValueMixin';
|
18
|
+
import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
|
19
|
+
/**
|
20
|
+
* mdc-input is a component that allows users to input text.
|
21
|
+
* It contains:
|
22
|
+
* - label field - describe the input field.
|
23
|
+
* - input field - contains the value
|
24
|
+
* - help text or validation message - displayed below the input field.
|
25
|
+
* - trailing button - it displays a clear the input field.
|
26
|
+
* - prefix text - displayed before the input field.
|
27
|
+
* - leading icon - displayed before the input field.
|
28
|
+
* - clear-aria-label - aria label for the trailing button.
|
29
|
+
* - all the attributes of the input field.
|
30
|
+
*
|
31
|
+
* @tagname mdc-input
|
32
|
+
*
|
33
|
+
* @dependency mdc-icon
|
34
|
+
* @dependency mdc-text
|
35
|
+
* @dependency mdc-button
|
36
|
+
*
|
37
|
+
* @cssproperty --mdc-input-disabled-border-color - Border color for the input container when disabled
|
38
|
+
* @cssproperty --mdc-input-disabled-text-color - Text color for the input field when disabled
|
39
|
+
* @cssproperty --mdc-input-disabled-background-color - Background color for the input field when disabled
|
40
|
+
* @cssproperty --mdc-input-border-color - Border color for the input container
|
41
|
+
* @cssproperty --mdc-input-text-color - Text color for the input field
|
42
|
+
* @cssproperty --mdc-input-background-color - Background color for the input field
|
43
|
+
* @cssproperty --mdc-input-selection-background-color - Background color for the selected text
|
44
|
+
* @cssproperty --mdc-input-selection-text-color - Text color for the selected text
|
45
|
+
* @cssproperty --mdc-input-support-text-color - Text color for the help text
|
46
|
+
* @cssproperty --mdc-input-hover-background-color - Background color for the input field when hovered
|
47
|
+
* @cssproperty --mdc-input-focused-background-color - Background color for the input field when focused
|
48
|
+
* @cssproperty --mdc-input-focused-border-color - Border color for the input container when focused
|
49
|
+
* @cssproperty --mdc-input-error-border-color - Border color for the input container when error
|
50
|
+
* @cssproperty --mdc-input-warning-border-color - Border color for the input container when warning
|
51
|
+
* @cssproperty --mdc-input-success-border-color - Border color for the input container when success
|
52
|
+
* @cssproperty --mdc-input-primary-border-color - Border color for the input container when primary
|
53
|
+
*
|
54
|
+
*/
|
55
|
+
class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper))) {
|
56
|
+
checkValidity() {
|
57
|
+
this.setValidityFromInput();
|
58
|
+
return this.internals.checkValidity();
|
59
|
+
}
|
60
|
+
reportValidity() {
|
61
|
+
this.setValidityFromInput();
|
62
|
+
return this.internals.reportValidity();
|
63
|
+
}
|
64
|
+
/** @internal */
|
65
|
+
get form() {
|
66
|
+
return this.internals.form;
|
67
|
+
}
|
68
|
+
constructor() {
|
69
|
+
super();
|
70
|
+
/**
|
71
|
+
* The placeholder text that is displayed when the input field is empty.
|
72
|
+
*/
|
73
|
+
this.placeholder = '';
|
74
|
+
/**
|
75
|
+
* required attribute of the input field.
|
76
|
+
* If true, the consumer should indicate it on the label that the input field is required.
|
77
|
+
*/
|
78
|
+
this.required = false;
|
79
|
+
/**
|
80
|
+
* readonly attribute of the input field. If true, the input field is read-only.
|
81
|
+
*/
|
82
|
+
this.readonly = false;
|
83
|
+
/**
|
84
|
+
* The trailing button when set to true, shows a clear button that clears the input field.
|
85
|
+
* @default false
|
86
|
+
*/
|
87
|
+
this.trailingButton = false;
|
88
|
+
/**
|
89
|
+
* The autocapitalize attribute of the input field.
|
90
|
+
* @default 'off'
|
91
|
+
*/
|
92
|
+
this.autocapitalize = AUTO_CAPITALIZE.OFF;
|
93
|
+
/**
|
94
|
+
* The autocomplete attribute of the input field.
|
95
|
+
* @default 'off'
|
96
|
+
*/
|
97
|
+
this.autocomplete = 'off';
|
98
|
+
/**
|
99
|
+
* If true, the input field is focused when the component is rendered.
|
100
|
+
* @default false
|
101
|
+
*/
|
102
|
+
this.autofocus = false;
|
103
|
+
/**
|
104
|
+
* Aria label for the trailing button. If trailing button is set to true, this label is used for the clear button.
|
105
|
+
* @default ''
|
106
|
+
*/
|
107
|
+
this.clearAriaLabel = '';
|
108
|
+
/** @internal */
|
109
|
+
this.internals = this.attachInternals();
|
110
|
+
}
|
111
|
+
connectedCallback() {
|
112
|
+
super.connectedCallback();
|
113
|
+
this.updateComplete.then(() => {
|
114
|
+
if (this.inputElement) {
|
115
|
+
this.inputElement.checkValidity();
|
116
|
+
this.setValidityFromInput();
|
117
|
+
this.internals.setFormValue(this.inputElement.value);
|
118
|
+
}
|
119
|
+
}).catch((error) => {
|
120
|
+
if (this.onerror) {
|
121
|
+
this.onerror(error);
|
122
|
+
}
|
123
|
+
});
|
124
|
+
}
|
125
|
+
updated(changedProperties) {
|
126
|
+
super.updated(changedProperties);
|
127
|
+
if (changedProperties.has('value')) {
|
128
|
+
this.handleValueChange();
|
129
|
+
}
|
130
|
+
}
|
131
|
+
/**
|
132
|
+
* Handles the value change of the input field.
|
133
|
+
* Sets the form value and updates the validity of the input field.
|
134
|
+
* @returns void
|
135
|
+
*/
|
136
|
+
handleValueChange() {
|
137
|
+
this.internals.setFormValue(this.value);
|
138
|
+
this.updateComplete.then(() => {
|
139
|
+
this.setValidityFromInput();
|
140
|
+
}).catch((error) => {
|
141
|
+
if (this.onerror) {
|
142
|
+
this.onerror(error);
|
143
|
+
}
|
144
|
+
});
|
145
|
+
}
|
146
|
+
/**
|
147
|
+
* This function is called when the attribute changes.
|
148
|
+
* It updates the validity of the input field based on the input field's validity.
|
149
|
+
*
|
150
|
+
* @param name - attribute name
|
151
|
+
* @param old - old value
|
152
|
+
* @param value - new value
|
153
|
+
*/
|
154
|
+
attributeChangedCallback(name, old, value) {
|
155
|
+
super.attributeChangedCallback(name, old, value);
|
156
|
+
const validationRelatedAttributes = [
|
157
|
+
'maxlength',
|
158
|
+
'minlength',
|
159
|
+
'pattern',
|
160
|
+
'required',
|
161
|
+
];
|
162
|
+
if (validationRelatedAttributes.includes(name)) {
|
163
|
+
this.updateComplete.then(() => {
|
164
|
+
this.setValidityFromInput();
|
165
|
+
}).catch((error) => {
|
166
|
+
if (this.onerror) {
|
167
|
+
this.onerror(error);
|
168
|
+
}
|
169
|
+
});
|
170
|
+
}
|
171
|
+
}
|
172
|
+
/**
|
173
|
+
* Sets the validity of the input field based on the input field's validity.
|
174
|
+
* @returns void
|
175
|
+
*/
|
176
|
+
setValidityFromInput() {
|
177
|
+
if (this.inputElement) {
|
178
|
+
this.internals.setValidity(this.inputElement.validity, this.inputElement.validationMessage, this.inputElement);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
/**
|
182
|
+
* Updates the value of the input field.
|
183
|
+
* Sets the form value.
|
184
|
+
* @returns void
|
185
|
+
*/
|
186
|
+
updateValue() {
|
187
|
+
this.value = this.inputElement.value;
|
188
|
+
this.internals.setFormValue(this.inputElement.value);
|
189
|
+
}
|
190
|
+
/**
|
191
|
+
* Handles the input event of the input field.
|
192
|
+
* Updates the value and sets the validity of the input field.
|
193
|
+
*
|
194
|
+
*/
|
195
|
+
onInput() {
|
196
|
+
this.updateValue();
|
197
|
+
this.setValidityFromInput();
|
198
|
+
}
|
199
|
+
/**
|
200
|
+
* Handles the change event of the input field.
|
201
|
+
* Updates the value and sets the validity of the input field.
|
202
|
+
*
|
203
|
+
* The 'change' event does not bubble up through the shadow DOM as it was not composed.
|
204
|
+
* Therefore, we need to re-dispatch the same event to ensure it is propagated correctly.
|
205
|
+
* Read more: https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
|
206
|
+
*
|
207
|
+
* @param event - Event which contains information about the value change.
|
208
|
+
*/
|
209
|
+
onChange(event) {
|
210
|
+
this.updateValue();
|
211
|
+
this.setValidityFromInput();
|
212
|
+
const EventConstructor = event.constructor;
|
213
|
+
this.dispatchEvent(new EventConstructor(event.type, event));
|
214
|
+
}
|
215
|
+
/**
|
216
|
+
* Renders the leading icon before the input field.
|
217
|
+
* If the leading icon is not set, it will not be displayed.
|
218
|
+
*
|
219
|
+
* @returns void
|
220
|
+
*/
|
221
|
+
renderLeadingIcon() {
|
222
|
+
if (!this.leadingIcon) {
|
223
|
+
return nothing;
|
224
|
+
}
|
225
|
+
return html `
|
226
|
+
<mdc-icon
|
227
|
+
class="leading-icon"
|
228
|
+
part="leading-icon"
|
229
|
+
name=${this.leadingIcon}
|
230
|
+
size="${DEFAULTS.ICON_SIZE_VALUE}"
|
231
|
+
length-unit="${DEFAULTS.ICON_SIZE_UNIT}">
|
232
|
+
</mdc-icon>
|
233
|
+
`;
|
234
|
+
}
|
235
|
+
/**
|
236
|
+
* Renders the prefix text before the input field.
|
237
|
+
* If the prefix text is more than 10 characters,
|
238
|
+
* - it will not be displayed.
|
239
|
+
* - the validation messsage will be displayed.
|
240
|
+
*
|
241
|
+
* Note: We are setting aria-hidden so that the screen reader does not read the prefix text.
|
242
|
+
* The consumers should set the appropriate aria-label for the input field using 'data-aria-label' attribute.
|
243
|
+
* @returns void
|
244
|
+
*/
|
245
|
+
renderPrefixText() {
|
246
|
+
if (!this.prefixText) {
|
247
|
+
return nothing;
|
248
|
+
}
|
249
|
+
return html `
|
250
|
+
<mdc-text
|
251
|
+
class="prefix-text"
|
252
|
+
tagname="${DEFAULTS.PREFIX_TEXT_TAG}"
|
253
|
+
type="${DEFAULTS.PREFIX_TEXT_TYPE}"
|
254
|
+
aria-hidden="true"
|
255
|
+
>
|
256
|
+
${this.prefixText.slice(0, PREFIX_TEXT_OPTIONS.MAX_LENGTH)}
|
257
|
+
</mdc-text>
|
258
|
+
`;
|
259
|
+
}
|
260
|
+
/**
|
261
|
+
* Clears the input field.
|
262
|
+
*/
|
263
|
+
clearInputText() {
|
264
|
+
var _a;
|
265
|
+
this.value = '';
|
266
|
+
// focus the input field after clearing the text
|
267
|
+
(_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.focus();
|
268
|
+
}
|
269
|
+
/**
|
270
|
+
* Renders the trailing button to clear the input field if the trailingButton is set to true.
|
271
|
+
* @returns void
|
272
|
+
*/
|
273
|
+
renderTrailingButton() {
|
274
|
+
if (!this.trailingButton) {
|
275
|
+
return nothing;
|
276
|
+
}
|
277
|
+
return html `
|
278
|
+
<mdc-button
|
279
|
+
class='${!this.value ? 'hidden' : ''}'
|
280
|
+
prefix-icon='${DEFAULTS.CLEAR_BUTTON_ICON}'
|
281
|
+
variant='${DEFAULTS.CLEAR_BUTTON_VARIANT}'
|
282
|
+
size="${DEFAULTS.CLEAR_BUTTON_SIZE}"
|
283
|
+
aria-label="${this.clearAriaLabel}"
|
284
|
+
@click=${this.clearInputText}
|
285
|
+
?disabled=${this.disabled || this.readonly || !this.value}
|
286
|
+
></mdc-button>
|
287
|
+
`;
|
288
|
+
}
|
289
|
+
render() {
|
290
|
+
var _a;
|
291
|
+
return html `
|
292
|
+
${this.renderLabel()}
|
293
|
+
<div class="input-container mdc-focus-ring" part="input-container">
|
294
|
+
<slot name="input-leading-icon">${this.renderLeadingIcon()}</slot>
|
295
|
+
<div class="input-section" part="input-section">
|
296
|
+
<slot name="input-prefix-text">${this.renderPrefixText()}</slot>
|
297
|
+
<slot name="input">
|
298
|
+
<input
|
299
|
+
aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
|
300
|
+
class='input'
|
301
|
+
part='input'
|
302
|
+
id="${this.id}"
|
303
|
+
name="${this.name}"
|
304
|
+
.value="${this.value}"
|
305
|
+
?disabled="${this.disabled}"
|
306
|
+
?readonly="${this.readonly}"
|
307
|
+
?required="${this.required}"
|
308
|
+
type="text"
|
309
|
+
placeholder=${ifDefined(this.placeholder)}
|
310
|
+
minlength=${ifDefined(this.minlength)}
|
311
|
+
maxlength=${ifDefined(this.maxlength)}
|
312
|
+
autocapitalize=${this.autocapitalize}
|
313
|
+
autocomplete=${this.autocomplete}
|
314
|
+
?autofocus="${this.autofocus}"
|
315
|
+
dirname=${ifDefined(this.dirname)}
|
316
|
+
pattern=${ifDefined(this.pattern)}
|
317
|
+
list=${ifDefined(this.list)}
|
318
|
+
size=${ifDefined(this.size)}
|
319
|
+
@input=${this.onInput}
|
320
|
+
@change=${this.onChange}
|
321
|
+
/>
|
322
|
+
</slot>
|
323
|
+
</div>
|
324
|
+
<slot name="trailing-button">${this.renderTrailingButton()}</slot>
|
325
|
+
</div>
|
326
|
+
${this.helpText ? this.renderHelperText() : nothing}
|
327
|
+
`;
|
328
|
+
}
|
329
|
+
}
|
330
|
+
/** @internal */
|
331
|
+
Input.formAssociated = true;
|
332
|
+
Input.styles = [...FormfieldWrapper.styles, ...styles];
|
333
|
+
__decorate([
|
334
|
+
property({ type: String }),
|
335
|
+
__metadata("design:type", Object)
|
336
|
+
], Input.prototype, "placeholder", void 0);
|
337
|
+
__decorate([
|
338
|
+
property({ type: Boolean }),
|
339
|
+
__metadata("design:type", Object)
|
340
|
+
], Input.prototype, "required", void 0);
|
341
|
+
__decorate([
|
342
|
+
property({ type: Boolean }),
|
343
|
+
__metadata("design:type", Object)
|
344
|
+
], Input.prototype, "readonly", void 0);
|
345
|
+
__decorate([
|
346
|
+
property({ type: String, attribute: 'prefix-text' }),
|
347
|
+
__metadata("design:type", String)
|
348
|
+
], Input.prototype, "prefixText", void 0);
|
349
|
+
__decorate([
|
350
|
+
property({ type: String, attribute: 'leading-icon' }),
|
351
|
+
__metadata("design:type", String)
|
352
|
+
], Input.prototype, "leadingIcon", void 0);
|
353
|
+
__decorate([
|
354
|
+
property({ type: Boolean, attribute: 'trailing-button' }),
|
355
|
+
__metadata("design:type", Object)
|
356
|
+
], Input.prototype, "trailingButton", void 0);
|
357
|
+
__decorate([
|
358
|
+
property({ type: Number }),
|
359
|
+
__metadata("design:type", Number)
|
360
|
+
], Input.prototype, "maxlength", void 0);
|
361
|
+
__decorate([
|
362
|
+
property({ type: Number }),
|
363
|
+
__metadata("design:type", Number)
|
364
|
+
], Input.prototype, "minlength", void 0);
|
365
|
+
__decorate([
|
366
|
+
property({ type: String }),
|
367
|
+
__metadata("design:type", String)
|
368
|
+
], Input.prototype, "autocapitalize", void 0);
|
369
|
+
__decorate([
|
370
|
+
property({ type: String }),
|
371
|
+
__metadata("design:type", Object)
|
372
|
+
], Input.prototype, "autocomplete", void 0);
|
373
|
+
__decorate([
|
374
|
+
property({ type: Boolean }),
|
375
|
+
__metadata("design:type", Object)
|
376
|
+
], Input.prototype, "autofocus", void 0);
|
377
|
+
__decorate([
|
378
|
+
property({ type: String }),
|
379
|
+
__metadata("design:type", String)
|
380
|
+
], Input.prototype, "dirname", void 0);
|
381
|
+
__decorate([
|
382
|
+
property({ type: String }),
|
383
|
+
__metadata("design:type", String)
|
384
|
+
], Input.prototype, "pattern", void 0);
|
385
|
+
__decorate([
|
386
|
+
property({ type: String }),
|
387
|
+
__metadata("design:type", String)
|
388
|
+
], Input.prototype, "list", void 0);
|
389
|
+
__decorate([
|
390
|
+
property({ type: Number }),
|
391
|
+
__metadata("design:type", Object)
|
392
|
+
], Input.prototype, "size", void 0);
|
393
|
+
__decorate([
|
394
|
+
property({ type: String, attribute: 'clear-aria-label' }),
|
395
|
+
__metadata("design:type", Object)
|
396
|
+
], Input.prototype, "clearAriaLabel", void 0);
|
397
|
+
__decorate([
|
398
|
+
query('input'),
|
399
|
+
__metadata("design:type", HTMLInputElement)
|
400
|
+
], Input.prototype, "inputElement", void 0);
|
401
|
+
export default Input;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
declare const TAG_NAME: "mdc-input";
|
2
|
+
declare const AUTO_CAPITALIZE: {
|
3
|
+
readonly OFF: "off";
|
4
|
+
readonly NONE: "none";
|
5
|
+
readonly ON: "on";
|
6
|
+
readonly SENTENCES: "sentences";
|
7
|
+
readonly WORDS: "words";
|
8
|
+
readonly CHARACTERS: "characters";
|
9
|
+
};
|
10
|
+
declare const PREFIX_TEXT_OPTIONS: {
|
11
|
+
MAX_LENGTH: number;
|
12
|
+
HELPERTEXT: string;
|
13
|
+
VALIDATION: "error";
|
14
|
+
};
|
15
|
+
declare const DEFAULTS: {
|
16
|
+
VALIDATION: "default";
|
17
|
+
ICON_SIZE_VALUE: number;
|
18
|
+
ICON_SIZE_UNIT: string;
|
19
|
+
CLEAR_BUTTON_ICON: string;
|
20
|
+
CLEAR_BUTTON_VARIANT: "tertiary";
|
21
|
+
CLEAR_BUTTON_SIZE: 20;
|
22
|
+
PREFIX_TEXT_TYPE: "body-midsize-regular";
|
23
|
+
PREFIX_TEXT_TAG: "span";
|
24
|
+
};
|
25
|
+
export { TAG_NAME, PREFIX_TEXT_OPTIONS, AUTO_CAPITALIZE, DEFAULTS };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import utils from '../../utils/tag-name';
|
2
|
+
import { BUTTON_VARIANTS, ICON_BUTTON_SIZES } from '../button/button.constants';
|
3
|
+
import { VALIDATION } from '../formfieldwrapper/formfieldwrapper.constants';
|
4
|
+
import { TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
|
5
|
+
const TAG_NAME = utils.constructTagName('input');
|
6
|
+
const AUTO_CAPITALIZE = {
|
7
|
+
OFF: 'off',
|
8
|
+
NONE: 'none',
|
9
|
+
ON: 'on',
|
10
|
+
SENTENCES: 'sentences',
|
11
|
+
WORDS: 'words',
|
12
|
+
CHARACTERS: 'characters',
|
13
|
+
};
|
14
|
+
const PREFIX_TEXT_OPTIONS = {
|
15
|
+
MAX_LENGTH: 10,
|
16
|
+
HELPERTEXT: 'Prefix text should not exceed 10 characters',
|
17
|
+
VALIDATION: VALIDATION.ERROR,
|
18
|
+
};
|
19
|
+
const DEFAULTS = {
|
20
|
+
VALIDATION: VALIDATION.DEFAULT,
|
21
|
+
ICON_SIZE_VALUE: 1,
|
22
|
+
ICON_SIZE_UNIT: 'rem',
|
23
|
+
CLEAR_BUTTON_ICON: 'cancel-bold',
|
24
|
+
CLEAR_BUTTON_VARIANT: BUTTON_VARIANTS.TERTIARY,
|
25
|
+
CLEAR_BUTTON_SIZE: ICON_BUTTON_SIZES[20],
|
26
|
+
PREFIX_TEXT_TYPE: TYPE.BODY_MIDSIZE_REGULAR,
|
27
|
+
PREFIX_TEXT_TAG: VALID_TEXT_TAGS.SPAN,
|
28
|
+
};
|
29
|
+
export { TAG_NAME, PREFIX_TEXT_OPTIONS, AUTO_CAPITALIZE, DEFAULTS };
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import { css } from 'lit';
|
2
|
+
import { hostFocusRingStyles } from '../../utils/styles';
|
3
|
+
const styles = [css `
|
4
|
+
:host{
|
5
|
+
--mdc-input-disabled-border-color: var(--mds-color-theme-outline-primary-disabled);
|
6
|
+
--mdc-input-disabled-text-color: var(--mds-color-theme-text-primary-disabled);
|
7
|
+
--mdc-input-disabled-background-color: var(--mds-color-theme-background-primary-disabled);
|
8
|
+
--mdc-input-border-color: var(--mds-color-theme-outline-input-normal);
|
9
|
+
--mdc-input-text-color: var(--mds-color-theme-text-primary-normal);
|
10
|
+
--mdc-input-background-color: var(--mds-color-theme-background-primary-ghost);
|
11
|
+
--mdc-input-selection-background-color: var(--mds-color-theme-background-accent-active);
|
12
|
+
--mdc-input-selection-text-color: var(--mds-color-theme-inverted-text-primary-normal);
|
13
|
+
--mdc-input-support-text-color: var(--mds-color-theme-text-secondary-normal);
|
14
|
+
--mdc-input-hover-background-color: var(--mds-color-theme-background-primary-hover);
|
15
|
+
--mdc-input-focused-background-color: var(--mds-color-theme-background-primary-active);
|
16
|
+
--mdc-input-focused-border-color: var(--mds-color-theme-outline-input-active);
|
17
|
+
--mdc-input-error-border-color: var(--mds-color-theme-text-error-normal);
|
18
|
+
--mdc-input-warning-border-color: var(--mds-color-theme-text-warning-normal);
|
19
|
+
--mdc-input-success-border-color: var(--mds-color-theme-text-success-normal);
|
20
|
+
--mdc-input-primary-border-color: var(--mds-color-theme-text-accent-normal);
|
21
|
+
}
|
22
|
+
|
23
|
+
:host, .input-container, .input-section, .input{
|
24
|
+
width: 100%;
|
25
|
+
}
|
26
|
+
|
27
|
+
:host([readonly]) .leading-icon {
|
28
|
+
color: var(--mdc-input-support-text-color);
|
29
|
+
}
|
30
|
+
|
31
|
+
:host([disabled]) .input,
|
32
|
+
:host([disabled]) .input::placeholder,
|
33
|
+
:host([disabled]) .prefix-text{
|
34
|
+
color: var(--mdc-input-disabled-text-color);
|
35
|
+
}
|
36
|
+
|
37
|
+
:host([disabled]) .input,
|
38
|
+
:host([readonly]) .input{
|
39
|
+
border-color: var(--mdc-input-disabled-border-color);
|
40
|
+
background: var(--mdc-input-disabled-background-color);
|
41
|
+
}
|
42
|
+
|
43
|
+
:host([disabled][help-text-type="default"]) .input-container,
|
44
|
+
:host([disabled][help-text-type="success"]) .input-container,
|
45
|
+
:host([disabled][help-text-type="warning"]) .input-container,
|
46
|
+
:host([disabled][help-text-type="error"]) .input-container,
|
47
|
+
:host([disabled][help-text-type="priority"]) .input-container{
|
48
|
+
border-color: var(--mdc-input-disabled-border-color);
|
49
|
+
}
|
50
|
+
|
51
|
+
.leading-icon{
|
52
|
+
aspect-ratio: 1;
|
53
|
+
}
|
54
|
+
|
55
|
+
.input-container{
|
56
|
+
height: 2rem;
|
57
|
+
border-radius: 0.5rem;
|
58
|
+
border: 0.0625rem solid var(--mdc-input-border-color);
|
59
|
+
display: flex;
|
60
|
+
align-items: center;
|
61
|
+
gap: 0.375rem;
|
62
|
+
padding: 0.34375rem 0.375rem 0.34375rem 0.75rem;
|
63
|
+
}
|
64
|
+
|
65
|
+
.input-section{
|
66
|
+
display: flex;
|
67
|
+
gap: 0.25rem;
|
68
|
+
}
|
69
|
+
|
70
|
+
.input {
|
71
|
+
border: none;
|
72
|
+
color: var(--mdc-input-text-color);
|
73
|
+
background-color: var(--mdc-input-background-color);
|
74
|
+
outline: none;
|
75
|
+
}
|
76
|
+
|
77
|
+
.input::selection {
|
78
|
+
background-color: var(--mdc-input-selection-background-color);
|
79
|
+
color: var(--mdc-input-selection-text-color);
|
80
|
+
}
|
81
|
+
|
82
|
+
.prefix-text{
|
83
|
+
color: var(--mdc-input-support-text-color);
|
84
|
+
white-space: nowrap; // restirct prefix text to be in one line
|
85
|
+
}
|
86
|
+
|
87
|
+
:host(:not([disabled])) .input-container:hover{
|
88
|
+
background-color: var(--mdc-input-hover-background-color);
|
89
|
+
}
|
90
|
+
|
91
|
+
:host(:not([disabled])) .input-container:active, :host(:not([disabled])) .input-container:focus-within{
|
92
|
+
background-color: var(--mdc-input-focused-background-color);
|
93
|
+
border-color: var(--mdc-input-focused-border-color);
|
94
|
+
}
|
95
|
+
|
96
|
+
.input::placeholder{
|
97
|
+
color: var(--mdc-input-support-text-color);
|
98
|
+
}
|
99
|
+
|
100
|
+
:host([help-text-type="error"]) .input-container {
|
101
|
+
border-color: var(--mdc-input-error-border-color);
|
102
|
+
}
|
103
|
+
:host([help-text-type="warning"]) .input-container {
|
104
|
+
border-color: var(--mdc-input-warning-border-color);
|
105
|
+
}
|
106
|
+
:host([help-text-type="success"]) .input-container {
|
107
|
+
border-color: var(--mdc-input-success-border-color);
|
108
|
+
}
|
109
|
+
:host([help-text-type="priority"]) .input-container {
|
110
|
+
border-color: var(--mdc-input-primary-border-color);
|
111
|
+
}
|
112
|
+
|
113
|
+
.hidden{
|
114
|
+
opacity: 0;
|
115
|
+
pointer-events: none;
|
116
|
+
}
|
117
|
+
`, ...hostFocusRingStyles(true)];
|
118
|
+
export default styles;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|