Skip to content

Commit da069fc

Browse files
authored
Migrate hardcoded CSS values to design tokens (#62)
1 parent f288f90 commit da069fc

File tree

17 files changed

+114
-85
lines changed

17 files changed

+114
-85
lines changed

src/components/EasySearch.vue

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { ref, onMounted, onUnmounted } from "vue";
33
import { easySearch, isCommandPaletteOpen } from "$stores";
44
import { debounce } from "$utils/debounce";
5+
import Input from "$lib/components/forms/Input.vue";
56
67
interface Props {
78
onSearch?: () => void;
@@ -10,7 +11,7 @@ interface Props {
1011
const props = defineProps<Props>();
1112
1213
const error = ref("");
13-
const inputEl = ref<HTMLInputElement | null>(null);
14+
const inputEl = ref<InstanceType<typeof Input> | null>(null);
1415
1516
const search = debounce(() => props.onSearch?.(), 100);
1617
@@ -37,10 +38,15 @@ function trySearch() {
3738
search();
3839
}
3940
41+
function getInputElement() {
42+
return inputEl.value?.$el?.querySelector("input") as HTMLInputElement | null;
43+
}
44+
4045
function handleKeyDown(e: KeyboardEvent) {
4146
if (isCommandPaletteOpen.value) return;
4247
43-
const inputIsFocused = document.activeElement === inputEl.value;
48+
const input = getInputElement();
49+
const inputIsFocused = document.activeElement === input;
4450
if (inputIsFocused) return;
4551
4652
if (e.key.length > 1 || /\p{C}/u.test(e.key)) return;
@@ -51,7 +57,7 @@ function handleKeyDown(e: KeyboardEvent) {
5157
return;
5258
}
5359
54-
inputEl.value?.focus();
60+
input?.focus();
5561
}
5662
5763
onMounted(() => {
@@ -76,39 +82,20 @@ function handleSubmit(e: Event) {
7682

7783
<template>
7884
<form @submit="handleSubmit">
79-
<input
85+
<Input
8086
ref="inputEl"
8187
type="text"
8288
placeholder="Search..."
83-
:value="easySearch"
89+
:model-value="easySearch"
90+
:error="error"
91+
full-width
8492
@input="handleInput"
8593
/>
86-
87-
<template v-if="error">
88-
<br />
89-
<span style="color: red">{{ error }}</span>
90-
</template>
9194
</form>
9295
</template>
9396

9497
<style scoped>
95-
input {
96-
width: 90%;
97-
margin: 0 auto;
98-
border: 1px solid transparent;
99-
box-shadow: -3px 4px 2px #0000000f;
100-
}
101-
:root[data-theme="dark"] input {
102-
background-color: #151515;
103-
color: white;
104-
border: 1px solid #6b6b6b;
105-
box-shadow: 1px 1px 1px 2px #0000006e;
106-
}
107-
input::-webkit-input-placeholder {
108-
opacity: 0.5;
109-
}
110-
input:focus {
111-
outline: 1px solid #a5b5ff;
112-
box-shadow: -3px 4px 2px #894aff0f;
98+
form {
99+
width: 100%;
113100
}
114101
</style>

src/components/Header.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ header {
2828
display: flex;
2929
justify-content: space-between;
3030
max-width: 600px;
31-
margin: 20px auto;
31+
margin: var(--space-5) auto;
3232
display: flex;
3333
align-items: center;
3434
}
@@ -42,14 +42,15 @@ button {
4242
cursor: pointer;
4343
margin: 0;
4444
z-index: 2;
45-
padding: 10px 20px;
45+
padding: var(--space-3) var(--space-5);
4646
}
4747
.active {
4848
color: var(--hsl-bg);
4949
background: var(--hsl);
5050
transition: 0.25s;
5151
}
5252
button:focus {
53-
border: 1px solid var(--hsl);
53+
outline: var(--border-width-2) solid var(--color-border-focus);
54+
outline-offset: var(--border-width-2);
5455
}
5556
</style>

src/components/Loader.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ const chars = computed(() => Array.from(str.value));
3434
<style scoped>
3535
section {
3636
text-align: center;
37-
padding-top: 50px;
37+
padding-top: var(--space-12);
3838
}
3939
.chars span {
4040
display: inline-block;
41-
width: 25px;
41+
width: var(--space-6);
4242
text-align: center;
4343
line-height: 1em;
4444
}

src/components/advanced-search/AdvancedSearch.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ interface Props {
1010
1111
defineProps<Props>();
1212
13-
const onClose = (index: number) => () => {
13+
function handleClose(index: number) {
1414
boxes.value = [...boxes.value.slice(0, index), ...boxes.value.slice(index + 1)];
15-
};
15+
}
1616
17-
const updateBox = (index: number) => (box: Box) => {
17+
function handleBoxChange(index: number, box: Box) {
1818
boxes.value = [...boxes.value.slice(0, index), box, ...boxes.value.slice(index + 1)];
19-
};
19+
}
2020
2121
onMounted(() => {
2222
if (boxes.value.length === 0) {
@@ -36,8 +36,8 @@ function addRule() {
3636
v-for="(box, i) in boxes"
3737
:key="i"
3838
:box="box"
39-
@box-change="updateBox(i)"
40-
@close="onClose(i)"
39+
@boxChange="(b) => handleBoxChange(i, b)"
40+
@close="() => handleClose(i)"
4141
/>
4242
</form>
4343

@@ -53,6 +53,6 @@ function addRule() {
5353
justify-content: flex-end;
5454
}
5555
.buttons :deep(*) {
56-
margin: 5px;
56+
margin: var(--space-1);
5757
}
5858
</style>

src/components/advanced-search/BoxContent.vue

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,43 @@ function handleDataChange(data: any) {
5454

5555
<hr />
5656

57-
<component :is="component" :data="props.data" @data-change="handleDataChange" />
57+
<component
58+
v-if="component"
59+
:is="component"
60+
:data="props.data"
61+
@data-change="handleDataChange"
62+
/>
5863
</div>
5964
</template>
6065

6166
<style scoped>
6267
.content {
63-
padding: 40px;
68+
padding: var(--space-10);
6469
display: grid;
6570
justify-content: center;
6671
margin-top: -1px;
6772
position: relative;
73+
z-index: 1;
74+
isolation: isolate;
6875
}
6976
button {
7077
position: absolute;
71-
top: 5px;
72-
right: 10px;
78+
top: var(--space-1);
79+
right: var(--space-3);
7380
background: none;
7481
border: none;
7582
font-size: 2em;
76-
padding: 3px;
83+
padding: var(--space-1);
7784
line-height: 0.8em;
7885
margin: 0;
79-
z-index: 2;
86+
z-index: 3;
8087
cursor: pointer;
8188
}
89+
button:hover {
90+
opacity: 0.7;
91+
}
8292
hr {
83-
margin: 10px -40px;
93+
margin: var(--space-3) calc(var(--space-10) * -1);
8494
opacity: 0.4;
8595
}
8696
</style>

src/components/advanced-search/BoxSet.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ function handleDataChange(data: any) {
5555
<style scoped>
5656
.box {
5757
display: grid;
58-
padding: 20px 0;
59-
margin-bottom: 20px;
58+
padding: var(--space-5) 0;
59+
margin-bottom: var(--space-5);
6060
}
6161
.dropdown-container {
6262
display: flex;
6363
justify-content: center;
64-
margin: -25px;
64+
margin: calc(var(--space-6) * -1);
6565
z-index: 2;
6666
}
6767
</style>

src/components/advanced-search/Button.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ const btnClass = computed(() => ["styled", props.disabled && "disabled"].filter(
2727
<style scoped>
2828
button {
2929
margin: 0;
30-
padding: 5px 15px;
31-
border-radius: 4px;
32-
box-shadow: 0px 4px 3px 0px #00000017;
30+
padding: var(--space-2) var(--space-4);
31+
border-radius: var(--radius-md);
32+
box-shadow: var(--shadow-sm);
3333
cursor: pointer;
3434
}
35-
button:focus,
35+
button:focus {
36+
outline: var(--border-width-2) solid var(--color-border-focus);
37+
outline-offset: var(--border-width-2);
38+
}
3639
button:active {
3740
color: var(--hsl);
38-
border: 1px solid var(--hsl);
41+
border: var(--border-width-1) solid var(--hsl);
3942
background: hsl(var(--hue), 100%, 95%);
4043
}
4144
button:active {

src/components/advanced-search/Dropdown.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ function handleChange(e: Event) {
4141

4242
<style scoped>
4343
select {
44-
box-shadow: 0px 4px 3px 0px #00000017;
44+
box-shadow: var(--shadow-sm);
4545
cursor: pointer;
4646
}
4747
select:focus {
48-
outline: none;
48+
outline: var(--border-width-2) solid var(--color-border-focus);
49+
outline-offset: var(--border-width-2);
4950
}
5051
select:disabled {
5152
opacity: 1;

src/components/table-container/InfoContainer.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ const htmlEntityNames = computed(() => symbolHtmlNamesMap.value.get(props.codepo
103103

104104
<style scoped>
105105
div.container {
106-
border-radius: 8px;
107-
padding: 20px;
106+
border-radius: var(--radius-xl);
107+
padding: var(--space-5);
108108
}
109109
.basic-info {
110110
display: grid;
111111
}
112112
td {
113-
padding: 5px;
113+
padding: var(--space-2);
114114
}
115115
td:nth-child(1) {
116116
font-weight: bold;
@@ -126,11 +126,11 @@ h1 {
126126
height: 64px;
127127
width: 64px;
128128
font-size: 3em;
129-
border: 1px solid grey;
129+
border: var(--border-width-1) solid var(--color-border);
130130
display: flex;
131131
align-items: center;
132132
justify-content: center;
133-
margin: 12px 0;
133+
margin: var(--space-3) 0;
134134
}
135135
header {
136136
display: flex;

src/components/table-container/ResultsRow.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ watch(
9292
font-size: 0.8rem;
9393
}
9494
.row.active {
95-
border: 1px solid blue;
95+
border: var(--border-width-1) solid var(--color-border-focus);
9696
}
9797
.content {
9898
width: 100%;

0 commit comments

Comments
 (0)