-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathRightSlider.vue
More file actions
294 lines (280 loc) · 10 KB
/
RightSlider.vue
File metadata and controls
294 lines (280 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<script setup lang="ts">
import type { Format } from 'vue-pick-colors'
import {
codeBlockThemeOptions,
colorOptions,
fontFamilyOptions,
fontSizeOptions,
legendOptions,
themeOptions,
} from '@md/shared/configs'
import { X } from 'lucide-vue-next'
import PickColors from 'vue-pick-colors'
import { useStore } from '@/stores'
const store = useStore()
// 控制是否启用动画
const enableAnimation = ref(false)
// 监听 RightSlider 开关状态变化
watch(() => store.isOpenRightSlider, () => {
if (store.isMobile) {
// 在移动端,用户操作时启用动画
enableAnimation.value = true
}
})
// 监听设备类型变化,重置动画状态
watch(() => store.isMobile, () => {
enableAnimation.value = false
})
const { primaryColor } = storeToRefs(store)
const isOpen = ref(false)
const addPostInputVal = ref(``)
watch(isOpen, () => {
if (isOpen.value) {
addPostInputVal.value = ``
}
})
const pickColorsContainer = useTemplateRef<HTMLElement | undefined>(`pickColorsContainer`)
const format = ref<Format>(`rgb`)
const formatOptions = ref<Format[]>([`rgb`, `hex`, `hsl`, `hsv`])
</script>
<template>
<!-- 移动端遮罩层 -->
<div
v-if="store.isMobile && store.isOpenRightSlider"
class="fixed inset-0 bg-black/50 z-40"
@click="store.isOpenRightSlider = false"
/>
<div
class="overflow-hidden mobile-right-drawer"
:class="{
// 移动端样式
'fixed top-0 right-0 w-full h-full z-55 bg-background border-l shadow-lg': store.isMobile,
'animate': store.isMobile && enableAnimation,
// 桌面端样式
'border-l-2 order-2 border-gray/20 bg-white transition-width duration-300 dark:bg-[#191919]': !store.isMobile,
'w-100': !store.isMobile && store.isOpenRightSlider,
'w-0 border-l-0': !store.isMobile && !store.isOpenRightSlider,
}"
:style="{
transform: store.isMobile ? (store.isOpenRightSlider ? 'translateX(0)' : 'translateX(100%)') : 'none',
}"
>
<div
class="space-y-4 h-full overflow-auto p-4"
:class="{
// 移动端不需要额外的transform
'pt-0': store.isMobile,
// 桌面端保持原有的动画
'transition-transform': !store.isMobile,
'translate-x-0': !store.isMobile && store.isOpenRightSlider,
'translate-x-full': !store.isMobile && !store.isOpenRightSlider,
}"
>
<!-- 移动端标题栏 -->
<div v-if="store.isMobile" class="sticky top-0 z-10 flex items-center justify-between -mx-4 px-4 py-3 border-b mb-4 bg-background">
<h2 class="text-lg font-semibold">
样式设置
</h2>
<Button variant="ghost" size="sm" @click="store.isOpenRightSlider = false">
<X class="h-4 w-4" />
</Button>
</div>
<div class="space-y-2">
<h2>主题</h2>
<div class="grid grid-cols-3 justify-items-center gap-2">
<Button
v-for="{ label, value } in themeOptions" :key="value" class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': store.theme === value,
}" @click="store.themeChanged(value)"
>
{{ label }}
</Button>
</div>
</div>
<div class="space-y-2">
<h2>字体</h2>
<div class="grid grid-cols-3 justify-items-center gap-2">
<Button
v-for="{ label, value } in fontFamilyOptions" :key="value" variant="outline" class="w-full"
:class="{ 'border-black dark:border-white border-2': store.fontFamily === value }" @click="store.fontChanged(value)"
>
{{ label }}
</Button>
</div>
</div>
<div class="space-y-2">
<h2>字号</h2>
<div class="grid grid-cols-5 justify-items-center gap-2">
<Button
v-for="{ value, desc } in fontSizeOptions" :key="value" variant="outline" class="w-full" :class="{
'border-black dark:border-white border-2': store.fontSize === value,
}" @click="store.sizeChanged(value)"
>
{{ desc }}
</Button>
</div>
</div>
<div class="space-y-2">
<h2>主题色</h2>
<div class="grid grid-cols-3 justify-items-center gap-2">
<Button
v-for="{ label, value } in colorOptions" :key="value" class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': store.primaryColor === value,
}" @click="store.colorChanged(value)"
>
<span
class="mr-2 inline-block h-4 w-4 rounded-full" :style="{
background: value,
}"
/>
{{ label }}
</Button>
</div>
</div>
<div class="space-y-2">
<h2>自定义主题色</h2>
<div ref="pickColorsContainer">
<PickColors
v-if="pickColorsContainer" v-model:value="primaryColor" show-alpha :format="format"
:format-options="formatOptions" :theme="store.isDark ? 'dark' : 'light'"
:popup-container="pickColorsContainer" @change="store.colorChanged"
/>
</div>
</div>
<div class="space-y-2">
<h2>代码块主题</h2>
<div>
<Select v-model="store.codeBlockTheme" @update:model-value="store.codeBlockThemeChanged">
<SelectTrigger>
<SelectValue placeholder="Select a code block theme" />
</SelectTrigger>
<SelectContent>
<SelectItem v-for="{ label, value } in codeBlockThemeOptions" :key="label" :value="value">
{{ label }}
</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div class="space-y-2">
<h2>图注格式</h2>
<div class="grid grid-cols-3 justify-items-center gap-2">
<Button
v-for="{ label, value } in legendOptions" :key="value" class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': store.legend === value,
}" @click="store.legendChanged(value)"
>
{{ label }}
</Button>
</div>
</div>
<div class="space-y-2">
<h2>Mac 代码块</h2>
<div class="grid grid-cols-5 justify-items-center gap-2">
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': store.isMacCodeBlock,
}" @click="!store.isMacCodeBlock && store.macCodeBlockChanged()"
>
开启
</Button>
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': !store.isMacCodeBlock,
}" @click="store.isMacCodeBlock && store.macCodeBlockChanged()"
>
关闭
</Button>
</div>
</div>
<div class="space-y-2">
<h2>代码块行号</h2>
<div class="grid grid-cols-5 justify-items-center gap-2">
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': store.isShowLineNumber,
}" @click="!store.isShowLineNumber && store.showLineNumberChanged()"
>
开启
</Button>
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': !store.isShowLineNumber,
}" @click="store.isShowLineNumber && store.showLineNumberChanged()"
>
关闭
</Button>
</div>
</div>
<div class="space-y-2">
<h2>微信外链转底部引用</h2>
<div class="grid grid-cols-5 justify-items-center gap-2">
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': store.isCiteStatus,
}" @click="!store.isCiteStatus && store.citeStatusChanged()"
>
开启
</Button>
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': !store.isCiteStatus,
}" @click="store.isCiteStatus && store.citeStatusChanged()"
>
关闭
</Button>
</div>
</div>
<div class="space-y-2">
<h2>段落首行缩进</h2>
<div class="grid grid-cols-5 justify-items-center gap-2">
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': store.isUseIndent,
}" @click="!store.isUseIndent && store.useIndentChanged()"
>
开启
</Button>
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': !store.isUseIndent,
}" @click="store.isUseIndent && store.useIndentChanged()"
>
关闭
</Button>
</div>
</div>
<div class="space-y-2">
<h2>段落两端对齐</h2>
<div class="grid grid-cols-5 justify-items-center gap-2">
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': store.isUseJustify,
}" @click="!store.isUseJustify && store.useJustifyChanged()"
>
开启
</Button>
<Button
class="w-full" variant="outline" :class="{
'border-black dark:border-white border-2': !store.isUseJustify,
}" @click="store.isUseJustify && store.useJustifyChanged()"
>
关闭
</Button>
</div>
</div>
<div class="space-y-2">
<h2>样式配置</h2>
<Button variant="destructive" @click="store.resetStyleConfirm">
重置
</Button>
</div>
</div>
</div>
</template>
<style scoped>
/* 移动端右侧栏动画 - 只有添加了 animate 类才启用 */
.mobile-right-drawer.animate {
transition: transform 300ms cubic-bezier(0.16, 1, 0.3, 1);
}
</style>