forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorSchemeToggle.vue
122 lines (105 loc) · 2.8 KB
/
ColorSchemeToggle.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
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
<!--
This source file is part of the Swift.org open source project
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
-->
<template>
<fieldset
class="color-scheme-toggle"
role="radiogroup"
>
<legend class="visuallyhidden">{{ $t('color-scheme.select') }}</legend>
<label
v-for="option in options"
:key="option"
>
<input
type="radio"
@input="setPreferredColorScheme"
:checked="option == preferredColorScheme"
:value="option"
/>
<div class="text">{{ $t(`color-scheme.${option}`) }}</div>
</label>
</fieldset>
</template>
<script>
import AppStore from 'docc-render/stores/AppStore';
import ColorScheme from 'docc-render/constants/ColorScheme';
export default {
name: 'ColorSchemeToggle',
data: () => ({ appState: AppStore.state }),
computed: {
options: ({ supportsAutoColorScheme }) => [
ColorScheme.light,
ColorScheme.dark,
...(supportsAutoColorScheme ? [ColorScheme.auto] : []),
],
preferredColorScheme: ({ appState }) => appState.preferredColorScheme,
supportsAutoColorScheme: ({ appState }) => appState.supportsAutoColorScheme,
},
methods: {
setPreferredColorScheme: (event) => {
AppStore.setPreferredColorScheme(event.target.value);
},
},
watch: {
preferredColorScheme: {
immediate: true,
handler(preferredColorScheme) {
document.body.dataset.colorScheme = preferredColorScheme;
},
},
},
};
</script>
<style scoped lang="scss">
@import 'docc-render/styles/_core.scss';
.color-scheme-toggle {
--toggle-color-fill: var(--color-button-background);
--toggle-color-text: var(--color-fill-blue);
@include font-styles(caption);
border: 1px solid var(--toggle-color-fill);
border-radius: var(--toggle-border-radius-outer, $border-radius);
display: inline-flex;
padding: 1px;
@include prefers-dark {
--toggle-color-text: var(--color-figure-blue);
}
@media print {
display: none;
}
:root.no-js & {
visibility: hidden;
}
}
input {
@include visuallyhidden;
appearance: none;
}
label {
@include on-keyboard-focus-within() {
@include focus-outline();
}
}
.text {
border: 1px solid transparent;
border-radius: var(--toggle-border-radius-inner, 2px);
color: var(--toggle-color-text);
display: inline-block;
text-align: center;
padding: 1px 6px;
min-width: 42px;
box-sizing: border-box;
&:hover {
cursor: pointer;
}
input:checked + & {
--toggle-color-text: var(--color-button-text);
background: var(--toggle-color-fill);
border-color: var(--toggle-color-fill);
}
}
</style>