@fluid-topics/ft-base-input 1.2.70
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 +23 -0
- package/build/ft-base-input.d.ts +29 -0
- package/build/ft-base-input.js +186 -0
- package/build/ft-base-input.light.js +716 -0
- package/build/ft-base-input.min.js +939 -0
- package/build/ft-base-input.properties.d.ts +19 -0
- package/build/ft-base-input.properties.js +1 -0
- package/build/ft-base-input.styles.d.ts +36 -0
- package/build/ft-base-input.styles.js +205 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +6 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
A base input structure for Admin Design System inputs.
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ft-base-input
|
|
7
|
+
yarn add @fluid-topics/ft-base-input
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { html } from "lit"
|
|
14
|
+
import "@fluid-topics/ft-base-input"
|
|
15
|
+
|
|
16
|
+
function render() {
|
|
17
|
+
return html`
|
|
18
|
+
<ft-base-input>
|
|
19
|
+
<my-input/>
|
|
20
|
+
</ft-base-input>
|
|
21
|
+
`
|
|
22
|
+
}
|
|
23
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ElementDefinitionsMap, FtdsBase, Status } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
import { FtdsBaseInputProperties } from "./ft-base-input.properties";
|
|
3
|
+
import { FtIcon } from "@fluid-topics/ft-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?: FtIcon | true;
|
|
14
|
+
appendIconLabel?: string;
|
|
15
|
+
appendIconIsClickable: boolean;
|
|
16
|
+
prependIcon?: FtIcon | true;
|
|
17
|
+
prependIconLabel?: string;
|
|
18
|
+
prependIconIsClickable: boolean;
|
|
19
|
+
errorMessages: string[];
|
|
20
|
+
warningMessages: string[];
|
|
21
|
+
hasFocus: boolean;
|
|
22
|
+
private container?;
|
|
23
|
+
private mainSlot;
|
|
24
|
+
private setFocusState;
|
|
25
|
+
private focusSlottedInput;
|
|
26
|
+
get shouldShowLabel(): string | false;
|
|
27
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
28
|
+
private renderIcon;
|
|
29
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
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 { FtdsBase, Status, } from "@fluid-topics/ft-wc-utils";
|
|
12
|
+
import { styles } from "./ft-base-input.styles";
|
|
13
|
+
import { FtdsInputHelperText } from "@fluid-topics/ft-input-helper-text";
|
|
14
|
+
import { FtdsInputLabel } from "@fluid-topics/ft-input-label";
|
|
15
|
+
import { FtIcon } from "@fluid-topics/ft-icon";
|
|
16
|
+
import { FtTooltip } from "@fluid-topics/ft-tooltip";
|
|
17
|
+
class FtdsBaseInput extends FtdsBase {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.status = Status.default;
|
|
21
|
+
this.disabled = false;
|
|
22
|
+
this.label = "";
|
|
23
|
+
this.hideLabel = false;
|
|
24
|
+
this.raiseLabel = false;
|
|
25
|
+
this.appendIconIsClickable = false;
|
|
26
|
+
this.prependIconIsClickable = false;
|
|
27
|
+
this.errorMessages = [];
|
|
28
|
+
this.warningMessages = [];
|
|
29
|
+
this.hasFocus = false;
|
|
30
|
+
}
|
|
31
|
+
setFocusState(focused) {
|
|
32
|
+
this.hasFocus = focused;
|
|
33
|
+
this.toggleAttribute("focused", focused);
|
|
34
|
+
}
|
|
35
|
+
focusSlottedInput() {
|
|
36
|
+
const nodes = this.mainSlot.assignedElements({ flatten: true });
|
|
37
|
+
const input = nodes.find(el => el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement);
|
|
38
|
+
input === null || input === void 0 ? void 0 : input.focus();
|
|
39
|
+
}
|
|
40
|
+
get shouldShowLabel() {
|
|
41
|
+
return !this.hideLabel && this.label;
|
|
42
|
+
}
|
|
43
|
+
render() {
|
|
44
|
+
const classes = {
|
|
45
|
+
"ftds-input": true,
|
|
46
|
+
"disabled": this.disabled,
|
|
47
|
+
"no-label": !this.shouldShowLabel,
|
|
48
|
+
"focused": this.hasFocus,
|
|
49
|
+
"with-prepend-icon": !!this.prependIcon,
|
|
50
|
+
"with-append-icon": !!this.appendIcon,
|
|
51
|
+
[this.status]: true,
|
|
52
|
+
...this.getDesignSystemBaseClasses(),
|
|
53
|
+
};
|
|
54
|
+
return html `
|
|
55
|
+
<div class="${classMap(classes)}">
|
|
56
|
+
|
|
57
|
+
<div class="inside-structure" @click=${() => this.focusSlottedInput()}>
|
|
58
|
+
<slot part="label" name="label">
|
|
59
|
+
${when(this.shouldShowLabel, () => html `
|
|
60
|
+
<ftds-input-label
|
|
61
|
+
aria-hidden="true"
|
|
62
|
+
text="${this.label}"
|
|
63
|
+
?raised=${this.raiseLabel}
|
|
64
|
+
.size="${this.size}"
|
|
65
|
+
></ftds-input-label>
|
|
66
|
+
`)}
|
|
67
|
+
</slot>
|
|
68
|
+
<div class="inside-structure--icon prepend">
|
|
69
|
+
<slot part="prepend-icon" name="prepend-icon">
|
|
70
|
+
${this.renderIcon("prepend")}
|
|
71
|
+
</slot>
|
|
72
|
+
</div>
|
|
73
|
+
<div class="inside-structure--input">
|
|
74
|
+
<slot
|
|
75
|
+
@focusin=${() => this.setFocusState(true)}
|
|
76
|
+
@focusout=${() => this.setFocusState(false)}
|
|
77
|
+
></slot>
|
|
78
|
+
</div>
|
|
79
|
+
<div class="inside-structure--icon append">
|
|
80
|
+
<slot part="append-icon" name="append-icon">
|
|
81
|
+
${this.renderIcon("append")}
|
|
82
|
+
</slot>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<slot part="helper-text" name="helper-text">
|
|
87
|
+
<ftds-input-helper-text
|
|
88
|
+
.helperText="${this.helperText}"
|
|
89
|
+
.errorMessages="${this.errorMessages}"
|
|
90
|
+
.warningMessages="${this.warningMessages}"
|
|
91
|
+
></ftds-input-helper-text>
|
|
92
|
+
</slot>
|
|
93
|
+
|
|
94
|
+
</div>
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
renderIcon(position) {
|
|
98
|
+
const icon = position === "append" ? this.appendIcon : this.prependIcon;
|
|
99
|
+
const eventName = position === "append" ? "append-icon-click" : "prepend-icon-click";
|
|
100
|
+
const isClickable = position === "append" ? this.appendIconIsClickable : this.prependIconIsClickable;
|
|
101
|
+
const iconText = position === "append" ? this.appendIconLabel : this.prependIconLabel;
|
|
102
|
+
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
|
|
103
|
+
return nothing;
|
|
104
|
+
}
|
|
105
|
+
else if (isClickable) {
|
|
106
|
+
return html `
|
|
107
|
+
<ft-tooltip .text=${iconText}>
|
|
108
|
+
<button
|
|
109
|
+
.aria-label=${iconText}
|
|
110
|
+
@click=${(e) => {
|
|
111
|
+
e.stopPropagation();
|
|
112
|
+
this.dispatchEvent(new CustomEvent(eventName, e));
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
<ft-icon .value=${icon}></ft-icon>
|
|
116
|
+
</button>
|
|
117
|
+
</ft-tooltip>
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
return html `
|
|
122
|
+
<ft-icon .value=${icon}></ft-icon>`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
FtdsBaseInput.elementDefinitions = {
|
|
127
|
+
"ftds-input-helper-text": FtdsInputHelperText,
|
|
128
|
+
"ftds-input-label": FtdsInputLabel,
|
|
129
|
+
"ft-icon": FtIcon,
|
|
130
|
+
"ft-tooltip": FtTooltip
|
|
131
|
+
};
|
|
132
|
+
FtdsBaseInput.styles = [
|
|
133
|
+
styles,
|
|
134
|
+
];
|
|
135
|
+
__decorate([
|
|
136
|
+
property()
|
|
137
|
+
], FtdsBaseInput.prototype, "status", void 0);
|
|
138
|
+
__decorate([
|
|
139
|
+
property({ type: Boolean })
|
|
140
|
+
], FtdsBaseInput.prototype, "disabled", void 0);
|
|
141
|
+
__decorate([
|
|
142
|
+
property()
|
|
143
|
+
], FtdsBaseInput.prototype, "label", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
property({ type: Boolean })
|
|
146
|
+
], FtdsBaseInput.prototype, "hideLabel", void 0);
|
|
147
|
+
__decorate([
|
|
148
|
+
property({ type: Boolean })
|
|
149
|
+
], FtdsBaseInput.prototype, "raiseLabel", void 0);
|
|
150
|
+
__decorate([
|
|
151
|
+
property()
|
|
152
|
+
], FtdsBaseInput.prototype, "helperText", void 0);
|
|
153
|
+
__decorate([
|
|
154
|
+
property()
|
|
155
|
+
], FtdsBaseInput.prototype, "appendIcon", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
property()
|
|
158
|
+
], FtdsBaseInput.prototype, "appendIconLabel", void 0);
|
|
159
|
+
__decorate([
|
|
160
|
+
property({ type: Boolean })
|
|
161
|
+
], FtdsBaseInput.prototype, "appendIconIsClickable", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
property()
|
|
164
|
+
], FtdsBaseInput.prototype, "prependIcon", void 0);
|
|
165
|
+
__decorate([
|
|
166
|
+
property()
|
|
167
|
+
], FtdsBaseInput.prototype, "prependIconLabel", void 0);
|
|
168
|
+
__decorate([
|
|
169
|
+
property({ type: Boolean })
|
|
170
|
+
], FtdsBaseInput.prototype, "prependIconIsClickable", void 0);
|
|
171
|
+
__decorate([
|
|
172
|
+
state()
|
|
173
|
+
], FtdsBaseInput.prototype, "errorMessages", void 0);
|
|
174
|
+
__decorate([
|
|
175
|
+
state()
|
|
176
|
+
], FtdsBaseInput.prototype, "warningMessages", void 0);
|
|
177
|
+
__decorate([
|
|
178
|
+
state()
|
|
179
|
+
], FtdsBaseInput.prototype, "hasFocus", void 0);
|
|
180
|
+
__decorate([
|
|
181
|
+
query(".ft-base-input")
|
|
182
|
+
], FtdsBaseInput.prototype, "container", void 0);
|
|
183
|
+
__decorate([
|
|
184
|
+
query("slot:not([name])")
|
|
185
|
+
], FtdsBaseInput.prototype, "mainSlot", void 0);
|
|
186
|
+
export { FtdsBaseInput };
|