Skip to content

Commit 5ae7b6f

Browse files
committed
✨ Read only (click to copy)
1 parent ecadda0 commit 5ae7b6f

File tree

18 files changed

+141
-47
lines changed

18 files changed

+141
-47
lines changed

src/framework/components/buttons/button/button.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ button-component {
205205
& > svg {
206206
width: 20px;
207207
height: 20px;
208-
transform: translateY(-1px);
209208
}
210209

211210
&[kind="solid"] {
@@ -941,4 +940,11 @@ button-component {
941940
}
942941
}
943942
}
943+
944+
span {
945+
display: inline-block;
946+
flex: 1;
947+
overflow: hidden;
948+
text-overflow: ellipsis;
949+
}
944950
}

src/framework/components/inputs/date-input/date-input.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export interface IDateInput extends IInputBase {
1414
autocapitalize: "off" | "on";
1515
icon: string;
1616
placeholder: string;
17-
readOnly: boolean;
1817
autofocus: boolean;
1918
value: string;
2019
dateFormat: string;
@@ -49,7 +48,6 @@ export default class DateInput extends InputBase<IDateInput> {
4948
},
5049
};
5150
this.model = {
52-
readOnly: false,
5351
label: "",
5452
instructions: null,
5553
error: null,
@@ -76,7 +74,6 @@ export default class DateInput extends InputBase<IDateInput> {
7674

7775
static get observedAttributes() {
7876
return [
79-
"data-read-only",
8077
"data-label",
8178
"data-instructions",
8279
"data-name",

src/framework/components/inputs/date-input/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
data-label="Example"
33
data-icon='<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" /></svg>'
44
data-mode="single"
5+
class="mb-2"
56
></date-input-component>
67

78
<script>

src/framework/components/inputs/date-input/readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
| autocapitalize | "on" or "off" | |
1818
| icon | string | |
1919
| placeholder | string | |
20-
| readOnly | boolean | |
2120
| autofocus | boolean | |
2221
| value | string | |
2322
| dateFormat | string | |

src/framework/components/inputs/email-input/email-input.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export default class EmailInput extends InputBase<IInput> {
1616
this.model = {
1717
label: "",
1818
instructions: null,
19-
readOnly: false,
2019
error: null,
2120
name: "",
2221
required: false,
@@ -47,7 +46,6 @@ export default class EmailInput extends InputBase<IInput> {
4746
"data-maxlength",
4847
"data-minlength",
4948
"data-disabled",
50-
"data-read-only",
5149
"data-datalist",
5250
"data-autofocus",
5351
];

src/framework/components/inputs/input/index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44
data-instructions="This is an example input."
55
data-icon='<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" /></svg>'S
66
data-type="text"
7-
data-minlength="2"
8-
data-maxlength="5"
7+
class="mb-2"
98
></input-component>
9+
10+
<input-component
11+
data-label="Example"
12+
data-type="text"
13+
data-read-only="true"
14+
data-value="This is a read-only input."
15+
></input-component>
16+
1017
<script>
1118
const inputComponent = document.querySelector('input-component');
1219
inputComponent.addEventListener('input', (event) => {

src/framework/components/inputs/input/input.scss

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
width: 100%;
44
position: relative;
55

6+
&[readonly] {
7+
input-container {
8+
input {
9+
padding-right: 2.5rem;
10+
}
11+
}
12+
}
13+
614
&[state="DISABLED"] {
715
cursor: not-allowed !important;
816

@@ -91,7 +99,7 @@
9199
color: var(--grey-300);
92100
background-color: hsl(var(--white-hsl) / 0.05);
93101

94-
&:focus {
102+
&:focus:not(:read-only) {
95103
background-color: hsl(var(--white-hsl) / 0);
96104
}
97105

@@ -123,7 +131,7 @@
123131
border: var(--input-border);
124132
background-color: var(--white);
125133
transition: all 80ms var(--ease-in-out);
126-
box-shadow: 0 1px 0 hsl(0deg 0% 0% / 0.1);
134+
box-shadow: 0 1px 1px hsl(var(--black-hsl) / 0.1);
127135
outline-offset: 0;
128136

129137
&:focus-within {

src/framework/components/inputs/input/input.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { html, render, TemplateResult } from "lit-html";
33
import { unsafeHTML } from "lit-html/directives/unsafe-html";
44
import env from "~brixi/controllers/env";
55
import { InputBase, IInputBase } from "../input-base";
6+
import alerts from "~brixi/controllers/alerts";
67

7-
env.css("input");
8+
env.css(["input", "button", "toast"]);
89

910
export interface IInput extends IInputBase {
1011
label: string;
@@ -15,7 +16,7 @@ export interface IInput extends IInputBase {
1516
placeholder: string;
1617
maxlength: number;
1718
minlength: number;
18-
readOnly: boolean;
19+
readOnly?: boolean;
1920
datalist: string[];
2021
autofocus: boolean;
2122
value: string;
@@ -137,6 +138,13 @@ export default class Input extends InputBase<IInput> {
137138
);
138139
};
139140

141+
private handleCopyClick: EventListener = (e: Event) => {
142+
e.stopImmediatePropagation();
143+
window.navigator.clipboard.writeText(this.model.value).then(() => {
144+
alerts.toast("Copied to clipboard");
145+
});
146+
};
147+
140148
private renderCopy(): string | TemplateResult {
141149
let output: string | TemplateResult = "";
142150
if (this.state === "IDLING" && this.model.instructions) {
@@ -155,6 +163,32 @@ export default class Input extends InputBase<IInput> {
155163
return output;
156164
}
157165

166+
private renderReadOnlyIcon(): string | TemplateResult {
167+
let output: string | TemplateResult = "";
168+
if (this.model.readOnly) {
169+
output = html`
170+
<button class="bttn absolute r-0 b-0" kind="text" color="primary" size="slim" icon="center" dull @click=${this.handleCopyClick} type="button">
171+
<svg
172+
xmlns="http://www.w3.org/2000/svg"
173+
width="24"
174+
height="24"
175+
viewBox="0 0 24 24"
176+
stroke-width="2"
177+
stroke="currentColor"
178+
fill="none"
179+
stroke-linecap="round"
180+
stroke-linejoin="round"
181+
>
182+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
183+
<path d="M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z"></path>
184+
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
185+
</svg>
186+
</button>
187+
`;
188+
}
189+
return output;
190+
}
191+
158192
private renderLabel(): string | TemplateResult {
159193
let output: string | TemplateResult = "";
160194
if (this.model.label?.length) {
@@ -180,6 +214,9 @@ export default class Input extends InputBase<IInput> {
180214
render() {
181215
this.setAttribute("state", this.state);
182216
this.classList.add("input");
217+
if (this.model.readOnly) {
218+
this.setAttribute("readonly", `${this.model.readOnly}`);
219+
}
183220
const view = html`
184221
${this.renderLabel()} ${this.renderCopy()}
185222
<input-container>
@@ -201,7 +238,9 @@ export default class Input extends InputBase<IInput> {
201238
?disabled=${this.model.disabled}
202239
list="${this.model.datalist.length ? `${this.inputId}-datalist` : ""}"
203240
?autofocus=${this.model.autofocus}
241+
?readonly=${this.model.readOnly}
204242
/>
243+
${this.renderReadOnlyIcon()}
205244
</input-container>
206245
${this.renderDatalist()}
207246
`;

src/framework/components/inputs/number-input/number-input.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ interface INumberInput extends IInputBase {
1111
instructions: string;
1212
icon: string;
1313
placeholder: string;
14-
readOnly: boolean;
1514
autofocus: boolean;
1615
value: number | null;
1716
min: number;
@@ -27,7 +26,6 @@ export default class NumberInput extends InputBase<INumberInput> {
2726
this.model = {
2827
label: "",
2928
instructions: null,
30-
readOnly: false,
3129
error: null,
3230
name: "",
3331
required: false,
@@ -56,7 +54,6 @@ export default class NumberInput extends InputBase<INumberInput> {
5654
"data-autofocus",
5755
"data-name",
5856
"data-required",
59-
"data-read-only",
6057
];
6158
}
6259

src/framework/components/inputs/number-input/readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
| max | number | |
2727
| step | number | |
2828
| disabled | boolean | |
29-
| readOnly | boolean | |
3029
| autofocus | boolean | |
3130

3231
Not sure what Data Attributes are? Learn about [Data Attributes on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*).

0 commit comments

Comments
 (0)