forked from vexip-ui/vexip-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle-padding.vue
59 lines (49 loc) · 1.36 KB
/
toggle-padding.vue
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
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { isClient } from '@vexip-ui/utils'
const rootCls = isClient ? document.documentElement.classList : undefined
const active = ref(false)
onMounted(() => {
active.value = !!rootCls && rootCls.contains('padding')
})
function togglePadding(value: boolean) {
if (!isClient || !rootCls) return
requestAnimationFrame(() => {
active.value = value
if (value) {
rootCls.add('padding')
} else {
rootCls.remove('padding')
}
localStorage.setItem('vexip-dev-prefer-no-padding', String(!value))
})
}
</script>
<template>
<div
:class="['toggle-padding', active && 'toggle-padding--active']"
@click="togglePadding(!active)"
>
Padding
</div>
</template>
<style lang="scss">
.toggle-padding {
display: flex;
align-items: center;
padding: 2px 10px;
color: var(--vxp-color-error-base);
cursor: pointer;
user-select: none;
background-color: var(--vxp-color-error-opacity-8);
border: 1px solid var(--vxp-color-error-opacity-6);
border-radius: var(--vxp-radius-base);
transition: var(--vxp-transition-color), var(--vxp-transition-background),
var(--vxp-transition-border);
&--active {
color: var(--vxp-color-success-base);
background-color: var(--vxp-color-success-opacity-8);
border: 1px solid var(--vxp-color-success-opacity-6);
}
}
</style>