@fluid-topics/ftds-base-input 2.1.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/README.md +19 -0
- package/build/define.d.ts +1 -0
- package/build/define.js +3 -0
- package/build/definitions.d.ts +5 -0
- package/build/definitions.js +4 -0
- package/build/ftds-base-input.d.ts +32 -0
- package/build/ftds-base-input.js +207 -0
- package/build/ftds-base-input.light.js +1884 -0
- package/build/ftds-base-input.min.js +1999 -0
- package/build/ftds-base-input.properties.d.ts +21 -0
- package/build/ftds-base-input.properties.js +1 -0
- package/build/ftds-base-input.styles.d.ts +44 -0
- package/build/ftds-base-input.styles.js +223 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +4 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
The design system base input component
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ftds-base-input
|
|
7
|
+
yarn add @fluid-topics/ftds-base-input
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { html } from "lit"
|
|
14
|
+
import "@fluid-topics/ftds-base-input"
|
|
15
|
+
|
|
16
|
+
function render() {
|
|
17
|
+
return html` <ftds-base-input foo="bar"></ftds-base-input> `
|
|
18
|
+
}
|
|
19
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/define.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DesignSystemSize, ElementDefinitionsMap, FtdsBase, Status } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
import { FtdsBaseInputProperties } from "./ftds-base-input.properties";
|
|
3
|
+
import { FtdsIcon, FtdsIconVariants } from "@fluid-topics/ftds-icon";
|
|
4
|
+
export declare class FtdsBaseInput extends FtdsBase implements FtdsBaseInputProperties {
|
|
5
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
6
|
+
static styles: import("lit").CSSResult[];
|
|
7
|
+
status: Status;
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
label: string;
|
|
10
|
+
hideLabel: boolean;
|
|
11
|
+
raiseLabel: boolean;
|
|
12
|
+
helperText?: string;
|
|
13
|
+
appendIcon?: FtdsIcon | true;
|
|
14
|
+
appendIconVariant?: FtdsIconVariants;
|
|
15
|
+
appendIconLabel?: string;
|
|
16
|
+
appendIconIsClickable: boolean;
|
|
17
|
+
prependIcon?: FtdsIcon | true;
|
|
18
|
+
prependIconVariant?: FtdsIconVariants;
|
|
19
|
+
prependIconLabel?: string;
|
|
20
|
+
prependIconIsClickable: boolean;
|
|
21
|
+
errorMessages: string[];
|
|
22
|
+
warningMessages: string[];
|
|
23
|
+
hasFocus: boolean;
|
|
24
|
+
private container?;
|
|
25
|
+
private mainSlot;
|
|
26
|
+
private setFocusState;
|
|
27
|
+
private focusSlottedInput;
|
|
28
|
+
get shouldShowLabel(): string | false;
|
|
29
|
+
get iconSize(): DesignSystemSize.medium | DesignSystemSize.small;
|
|
30
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
31
|
+
private renderIcon;
|
|
32
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
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
|
+
import { html, nothing, } from "lit";
|
|
8
|
+
import { property, query, state, } from "lit/decorators.js";
|
|
9
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
10
|
+
import { when } from "lit/directives/when.js";
|
|
11
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
12
|
+
import { DesignSystemFamily, DesignSystemSize, FtdsBase, Status, } from "@fluid-topics/ft-wc-utils";
|
|
13
|
+
import { styles } from "./ftds-base-input.styles";
|
|
14
|
+
import { FtdsInputHelperText } from "@fluid-topics/ftds-input-helper-text";
|
|
15
|
+
import { FtdsInputLabel } from "@fluid-topics/ftds-input-label";
|
|
16
|
+
import { FtdsIcon, } from "@fluid-topics/ftds-icon";
|
|
17
|
+
import { FtTooltip } from "@fluid-topics/ft-tooltip";
|
|
18
|
+
import { FtdsButton } from "@fluid-topics/ftds-button";
|
|
19
|
+
export class FtdsBaseInput extends FtdsBase {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments);
|
|
22
|
+
this.status = Status.default;
|
|
23
|
+
this.disabled = false;
|
|
24
|
+
this.label = "";
|
|
25
|
+
this.hideLabel = false;
|
|
26
|
+
this.raiseLabel = false;
|
|
27
|
+
this.appendIconIsClickable = false;
|
|
28
|
+
this.prependIconIsClickable = false;
|
|
29
|
+
this.errorMessages = [];
|
|
30
|
+
this.warningMessages = [];
|
|
31
|
+
this.hasFocus = false;
|
|
32
|
+
}
|
|
33
|
+
setFocusState(focused) {
|
|
34
|
+
this.hasFocus = focused;
|
|
35
|
+
this.toggleAttribute("focused", focused);
|
|
36
|
+
}
|
|
37
|
+
focusSlottedInput() {
|
|
38
|
+
const nodes = this.mainSlot.assignedElements({ flatten: true });
|
|
39
|
+
const input = nodes.find((el) => el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement);
|
|
40
|
+
input === null || input === void 0 ? void 0 : input.focus();
|
|
41
|
+
}
|
|
42
|
+
get shouldShowLabel() {
|
|
43
|
+
return !this.hideLabel && this.label;
|
|
44
|
+
}
|
|
45
|
+
get iconSize() {
|
|
46
|
+
switch (this.size) {
|
|
47
|
+
case DesignSystemSize.large:
|
|
48
|
+
return DesignSystemSize.medium;
|
|
49
|
+
case DesignSystemSize.medium:
|
|
50
|
+
return DesignSystemSize.small;
|
|
51
|
+
default:
|
|
52
|
+
return DesignSystemSize.medium;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
render() {
|
|
56
|
+
const classes = {
|
|
57
|
+
"ftds-input": true,
|
|
58
|
+
"disabled": this.disabled,
|
|
59
|
+
"no-label": !this.shouldShowLabel,
|
|
60
|
+
"focused": this.hasFocus,
|
|
61
|
+
"with-prepend-icon": !!this.prependIcon, // For the icons, we set the with-xxx-icon whether we have an actual icon or we have a "true" boolean meaning the component will handle the icon itself
|
|
62
|
+
"with-append-icon": !!this.appendIcon,
|
|
63
|
+
[this.status]: true,
|
|
64
|
+
...this.getDesignSystemBaseClasses(),
|
|
65
|
+
};
|
|
66
|
+
return html `
|
|
67
|
+
<div class="${classMap(classes)}">
|
|
68
|
+
|
|
69
|
+
<div class="inside-structure" @click=${() => this.focusSlottedInput()}>
|
|
70
|
+
<slot part="label" name="label">
|
|
71
|
+
${when(this.shouldShowLabel, () => html `
|
|
72
|
+
<ftds-input-label
|
|
73
|
+
aria-hidden="true"
|
|
74
|
+
text="${this.label}"
|
|
75
|
+
?raised=${this.raiseLabel}
|
|
76
|
+
.size=${this.size}
|
|
77
|
+
></ftds-input-label>
|
|
78
|
+
`)}
|
|
79
|
+
</slot>
|
|
80
|
+
<div class="inside-structure--icon prepend">
|
|
81
|
+
<slot part="prepend-icon" name="prepend-icon">
|
|
82
|
+
${this.renderIcon("prepend")}
|
|
83
|
+
</slot>
|
|
84
|
+
</div>
|
|
85
|
+
<div class="inside-structure--input">
|
|
86
|
+
<slot
|
|
87
|
+
@focusin=${() => this.setFocusState(true)}
|
|
88
|
+
@focusout=${() => this.setFocusState(false)}
|
|
89
|
+
></slot>
|
|
90
|
+
</div>
|
|
91
|
+
<div class="inside-structure--icon append">
|
|
92
|
+
<slot part="append-icon" name="append-icon">
|
|
93
|
+
${this.renderIcon("append")}
|
|
94
|
+
</slot>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<slot part="helper-text" name="helper-text">
|
|
99
|
+
<ftds-input-helper-text
|
|
100
|
+
.helperText=${this.helperText}
|
|
101
|
+
.errorMessages=${this.errorMessages}
|
|
102
|
+
.warningMessages=${this.warningMessages}
|
|
103
|
+
></ftds-input-helper-text>
|
|
104
|
+
</slot>
|
|
105
|
+
|
|
106
|
+
</div>
|
|
107
|
+
`;
|
|
108
|
+
}
|
|
109
|
+
renderIcon(position) {
|
|
110
|
+
const icon = position === "append" ? this.appendIcon : this.prependIcon;
|
|
111
|
+
const iconVariant = position === "append" ? this.appendIconVariant : this.prependIconVariant;
|
|
112
|
+
const eventName = position === "append" ? "append-icon-click" : "prepend-icon-click";
|
|
113
|
+
const isClickable = position === "append" ? this.appendIconIsClickable : this.prependIconIsClickable;
|
|
114
|
+
const iconText = position === "append" ? this.appendIconLabel : this.prependIconLabel;
|
|
115
|
+
if (!icon || icon === true) { // is prependIcon or appendIcon are simply "true", we let the component set its own icon, we simply prepare the space for it
|
|
116
|
+
return nothing;
|
|
117
|
+
}
|
|
118
|
+
else if (isClickable) {
|
|
119
|
+
return html `
|
|
120
|
+
<ftds-button
|
|
121
|
+
.label=${iconText}
|
|
122
|
+
.icon=${icon}
|
|
123
|
+
.iconVariant=${iconVariant}
|
|
124
|
+
.size=${this.iconSize}
|
|
125
|
+
family="${DesignSystemFamily.neutral}"
|
|
126
|
+
|
|
127
|
+
@click=${(e) => {
|
|
128
|
+
e.stopPropagation();
|
|
129
|
+
this.dispatchEvent(new CustomEvent(eventName, e));
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
</ftds-button>
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return html `
|
|
137
|
+
<ftds-icon aria-label="${ifDefined(iconText)}" aria-hidden="${!!iconText}" .icon=${icon} .variant=${iconVariant}></ftds-icon>`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
FtdsBaseInput.elementDefinitions = {
|
|
142
|
+
"ftds-input-helper-text": FtdsInputHelperText,
|
|
143
|
+
"ftds-input-label": FtdsInputLabel,
|
|
144
|
+
"ftds-icon": FtdsIcon,
|
|
145
|
+
"ftds-button": FtdsButton,
|
|
146
|
+
"ft-tooltip": FtTooltip,
|
|
147
|
+
};
|
|
148
|
+
FtdsBaseInput.styles = [
|
|
149
|
+
styles,
|
|
150
|
+
];
|
|
151
|
+
__decorate([
|
|
152
|
+
property()
|
|
153
|
+
], FtdsBaseInput.prototype, "status", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
property({ type: Boolean })
|
|
156
|
+
], FtdsBaseInput.prototype, "disabled", void 0);
|
|
157
|
+
__decorate([
|
|
158
|
+
property()
|
|
159
|
+
], FtdsBaseInput.prototype, "label", void 0);
|
|
160
|
+
__decorate([
|
|
161
|
+
property({ type: Boolean })
|
|
162
|
+
], FtdsBaseInput.prototype, "hideLabel", void 0);
|
|
163
|
+
__decorate([
|
|
164
|
+
property({ type: Boolean })
|
|
165
|
+
], FtdsBaseInput.prototype, "raiseLabel", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
property()
|
|
168
|
+
], FtdsBaseInput.prototype, "helperText", void 0);
|
|
169
|
+
__decorate([
|
|
170
|
+
property()
|
|
171
|
+
], FtdsBaseInput.prototype, "appendIcon", void 0);
|
|
172
|
+
__decorate([
|
|
173
|
+
property()
|
|
174
|
+
], FtdsBaseInput.prototype, "appendIconVariant", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
property()
|
|
177
|
+
], FtdsBaseInput.prototype, "appendIconLabel", void 0);
|
|
178
|
+
__decorate([
|
|
179
|
+
property({ type: Boolean })
|
|
180
|
+
], FtdsBaseInput.prototype, "appendIconIsClickable", void 0);
|
|
181
|
+
__decorate([
|
|
182
|
+
property()
|
|
183
|
+
], FtdsBaseInput.prototype, "prependIcon", void 0);
|
|
184
|
+
__decorate([
|
|
185
|
+
property()
|
|
186
|
+
], FtdsBaseInput.prototype, "prependIconVariant", void 0);
|
|
187
|
+
__decorate([
|
|
188
|
+
property()
|
|
189
|
+
], FtdsBaseInput.prototype, "prependIconLabel", void 0);
|
|
190
|
+
__decorate([
|
|
191
|
+
property({ type: Boolean })
|
|
192
|
+
], FtdsBaseInput.prototype, "prependIconIsClickable", void 0);
|
|
193
|
+
__decorate([
|
|
194
|
+
state()
|
|
195
|
+
], FtdsBaseInput.prototype, "errorMessages", void 0);
|
|
196
|
+
__decorate([
|
|
197
|
+
state()
|
|
198
|
+
], FtdsBaseInput.prototype, "warningMessages", void 0);
|
|
199
|
+
__decorate([
|
|
200
|
+
state()
|
|
201
|
+
], FtdsBaseInput.prototype, "hasFocus", void 0);
|
|
202
|
+
__decorate([
|
|
203
|
+
query(".ftds-base-input")
|
|
204
|
+
], FtdsBaseInput.prototype, "container", void 0);
|
|
205
|
+
__decorate([
|
|
206
|
+
query("slot:not([name])")
|
|
207
|
+
], FtdsBaseInput.prototype, "mainSlot", void 0);
|