Skip to content

Commit 20ae9ab

Browse files
committed
feat(settings): refactor settings form
1 parent 48ad270 commit 20ae9ab

File tree

4 files changed

+83
-103
lines changed

4 files changed

+83
-103
lines changed

src/components/views/settings/SettingsCache.vue

+13-39
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<script lang="ts" setup>
2-
import { NButton, NFormItem, NIcon, NSelect } from 'naive-ui';
2+
import { NButton, NIcon, NSelect } from 'naive-ui';
33
44
import { reactive, ref } from 'vue';
55
66
import IconRestore from '~/components/icons/IconRestore.vue';
7+
import SettingsFormItem from '~/components/views/settings/SettingsFormItem.vue';
8+
79
import { NotificationService } from '~/services/notification.service';
810
import { TraktService } from '~/services/trakt.service';
911
import { useExtensionSettingsStoreRefs } from '~/stores/settings/extension.store';
@@ -75,39 +77,31 @@ const container = ref();
7577

7678
<template>
7779
<div ref="container" class="cache-container">
78-
<NFormItem class="form-row" :show-feedback="false" label-placement="left">
79-
<template #label>
80-
<span class="from-label">{{ i18n('label_retention_trakt') }}</span>
81-
</template>
80+
<!-- Retention -->
81+
<SettingsFormItem :label="i18n('label_retention_trakt')">
8282
<NSelect
8383
v-model:value="traktCacheRetention"
8484
class="form-select"
8585
:to="container"
8686
:options="cacheOptions"
8787
/>
88-
</NFormItem>
89-
<NFormItem class="form-row" :show-feedback="false" label-placement="left">
90-
<template #label>
91-
<span class="from-label">{{ i18n('label_retention_images') }}</span>
92-
</template>
88+
</SettingsFormItem>
89+
90+
<SettingsFormItem :label="i18n('label_retention_images')">
9391
<NSelect
9492
v-model:value="tmdbCacheRetention"
9593
class="form-select"
9694
:to="container"
9795
:options="cacheOptions"
9896
/>
99-
</NFormItem>
97+
</SettingsFormItem>
10098

101-
<NFormItem
99+
<!-- Cache evict -->
100+
<SettingsFormItem
102101
v-for="({ label, click }, index) in evictScopes"
103102
:key="index"
104-
class="form-row"
105-
:show-feedback="false"
106-
label-placement="left"
103+
:label="label"
107104
>
108-
<template #label>
109-
<span class="from-label">{{ label }}</span>
110-
</template>
111105
<NButton
112106
class="evict-button"
113107
type="warning"
@@ -120,7 +114,7 @@ const container = ref();
120114
<NIcon :component="IconRestore" />
121115
</template>
122116
</NButton>
123-
</NFormItem>
117+
</SettingsFormItem>
124118
</div>
125119
</template>
126120

@@ -140,24 +134,4 @@ const container = ref();
140134
.form-select {
141135
min-width: 10rem;
142136
}
143-
144-
.from-label {
145-
color: var(--white-70);
146-
font-weight: 600;
147-
font-size: 1rem;
148-
transition: color 0.3s var(--n-bezier);
149-
}
150-
151-
.form-row {
152-
display: flex;
153-
flex: 1 1 auto;
154-
flex-wrap: wrap;
155-
justify-content: space-between;
156-
157-
&:hover {
158-
.from-label {
159-
color: var(--white-mute);
160-
}
161-
}
162-
}
163137
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<script lang="ts" setup>
2+
import { type FormItemGiProps, NFormItem } from 'naive-ui';
3+
4+
import type { PropType } from 'vue';
5+
6+
defineProps({
7+
label: {
8+
type: String,
9+
required: false,
10+
},
11+
form: {
12+
type: Object as PropType<FormItemGiProps>,
13+
required: false,
14+
},
15+
});
16+
</script>
17+
18+
<template>
19+
<NFormItem class="form-row" label-placement="left" :show-feedback="false" v-bind="form">
20+
<template #label>
21+
<span class="from-label">{{ label }}</span>
22+
</template>
23+
<slot />
24+
</NFormItem>
25+
</template>
26+
27+
<style lang="scss" scoped>
28+
.from-label {
29+
color: var(--white-70);
30+
font-weight: 600;
31+
font-size: 1rem;
32+
transition: color 0.3s var(--n-bezier);
33+
}
34+
35+
.form-row {
36+
display: flex;
37+
flex: 1 1 auto;
38+
flex-wrap: wrap;
39+
justify-content: space-between;
40+
41+
:deep(label) {
42+
max-width: 100%;
43+
text-align: start;
44+
}
45+
46+
&:hover {
47+
.from-label {
48+
color: var(--white-mute);
49+
}
50+
}
51+
}
52+
</style>

src/components/views/settings/SettingsLinks.vue

+14-38
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import IconClose from '~/components/icons/IconClose.vue';
1919
import IconConfirm from '~/components/icons/IconConfirm.vue';
2020
import IconPlus from '~/components/icons/IconPlus.vue';
2121
import IconRestore from '~/components/icons/IconRestore.vue';
22+
import SettingsFormItem from '~/components/views/settings/SettingsFormItem.vue';
2223
import {
2324
AllCustomLinkScopes,
2425
type CustomLink,
@@ -104,24 +105,18 @@ const containerRef = ref<HTMLDivElement>();
104105
<template>
105106
<div ref="containerRef" class="links-container">
106107
<!-- Header -->
107-
<NFormItem class="form-header-row" label-placement="left" :show-feedback="false">
108-
<template #label>
109-
<span class="form-header">{{ i18n('label_show_hide') }}</span>
110-
</template>
111-
<NSwitch v-model:value="aliasEnabled" class="form-header-switch">
108+
<SettingsFormItem :label="i18n('label_show_hide')">
109+
<NSwitch v-model:value="aliasEnabled" class="form-switch">
112110
<template #checked>{{ i18n('show', 'common', 'button') }}</template>
113111
<template #unchecked>{{ i18n('hide', 'common', 'button') }}</template>
114112
</NSwitch>
115-
</NFormItem>
116-
<NFormItem class="form-header-row" label-placement="left" :show-feedback="false">
117-
<template #label>
118-
<span class="form-header">{{ i18n('label_open_in_background') }}</span>
119-
</template>
120-
<NSwitch v-model:value="openLinkInBackground" class="form-header-switch">
113+
</SettingsFormItem>
114+
<SettingsFormItem :label="i18n('label_open_in_background')">
115+
<NSwitch v-model:value="openLinkInBackground" class="form-switch">
121116
<template #checked>{{ i18n('on', 'common', 'button') }}</template>
122117
<template #unchecked>{{ i18n('off', 'common', 'button') }}</template>
123118
</NSwitch>
124-
</NFormItem>
119+
</SettingsFormItem>
125120

126121
<!-- Content -->
127122
<NForm ref="formRef" :model="form">
@@ -271,32 +266,13 @@ const containerRef = ref<HTMLDivElement>();
271266
}
272267
}
273268
274-
.form-header {
275-
color: var(--white-70);
276-
font-weight: 600;
277-
font-size: 1rem;
278-
transition: color 0.3s var(--n-bezier);
279-
280-
&-row {
281-
&:hover {
282-
.form-header {
283-
color: var(--white-mute);
284-
}
285-
}
286-
287-
@media (width < 400px) {
288-
max-width: 70%;
289-
}
290-
}
291-
292-
&-switch {
293-
display: flex;
294-
flex: 1 1 auto;
295-
justify-content: flex-end;
296-
min-width: 4rem;
297-
padding: 0 0.5rem;
298-
font-size: 0.75rem;
299-
}
269+
.form-switch {
270+
display: flex;
271+
flex: 1 1 auto;
272+
justify-content: flex-end;
273+
min-width: 4rem;
274+
padding: 0 0.5rem;
275+
font-size: 0.75rem;
300276
}
301277
302278
.form-row {
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script lang="ts" setup>
2-
import { NFormItem, NSelect } from 'naive-ui';
2+
import { NSelect } from 'naive-ui';
33
44
import { ref } from 'vue';
55
6+
import SettingsFormItem from '~/components/views/settings/SettingsFormItem.vue';
67
import { LogLevel, useLogStore } from '~/stores/settings/log.store';
78
import { useI18n } from '~/utils';
89
@@ -22,17 +23,14 @@ const container = ref();
2223

2324
<template>
2425
<div ref="container" class="logs-container">
25-
<NFormItem class="form-row" :show-feedback="false" label-placement="left">
26-
<template #label>
27-
<span class="from-label">{{ i18n('label_log_level') }}</span>
28-
</template>
26+
<SettingsFormItem :label="i18n('label_log_level')">
2927
<NSelect
3028
v-model:value="logLevel"
3129
class="form-select"
3230
:to="container"
3331
:options="options"
3432
/>
35-
</NFormItem>
33+
</SettingsFormItem>
3634
</div>
3735
</template>
3836

@@ -46,24 +44,4 @@ const container = ref();
4644
.form-select {
4745
min-width: 10rem;
4846
}
49-
50-
.from-label {
51-
color: var(--white-70);
52-
font-weight: 600;
53-
font-size: 1rem;
54-
transition: color 0.3s var(--n-bezier);
55-
}
56-
57-
.form-row {
58-
display: flex;
59-
flex: 1 1 auto;
60-
flex-wrap: wrap;
61-
justify-content: space-between;
62-
63-
&:hover {
64-
.from-label {
65-
color: var(--white-mute);
66-
}
67-
}
68-
}
6947
</style>

0 commit comments

Comments
 (0)