-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathTextAppearanceSelector.svelte
More file actions
234 lines (220 loc) · 8.32 KB
/
TextAppearanceSelector.svelte
File metadata and controls
234 lines (220 loc) · 8.32 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
<!--
@component
The navbar component. We have sliders that update reactively to both font size and line height.
3 buttons to change the style from normal, sepia and dark.
-->
<svelte:options accessors={true} />
<script module>
export function showFonts(
/** @type {unknown[]} */ choices,
/** @type {boolean} */ contentsMode = false
) {
return !contentsMode && choices.length > 1;
}
export function showFontSize() {
return config.mainFeatures['text-font-size-slider'];
}
export function showLineHeight(/** @type {boolean} */ contentsMode = false) {
return !contentsMode && config.mainFeatures['text-line-height-slider'];
}
export function showThemes() {
return themes.length > 1;
}
export function showTextAppearance(
/** @type {unknown[]} */ choices,
/** @type {boolean} */ contentsMode = false
) {
return (
showFontSize() ||
showLineHeight(contentsMode) ||
showThemes() ||
showFonts(choices, contentsMode)
);
}
</script>
<script>
import config from '$assets/config';
import {
bodyFontSize,
bodyLineHeight,
contentsFontSize,
currentFont,
fontChoices,
language,
languages,
modal,
ModalType,
monoIconColor,
theme,
themeColors,
themes
} from '$lib/data/stores';
import { ImageIcon, TextAppearanceIcon } from '$lib/icons';
import Modal from './Modal.svelte';
import Slider from './Slider.svelte';
let modalId = 'textAppearanceSelector';
let modalThis;
export function showModal() {
modalThis.showModal();
}
export let options = {};
$: contentsMode = options?.contentsMode ?? false;
export let vertOffset = '1rem'; //Prop that will have the navbar's height (in rem) passed in
//The positioningCSS positions the modal 1rem below the navbar and 1rem from the right edge of the screen (on mobile it will be centered)
$: positioningCSS =
'position:absolute; top:' +
(Number(vertOffset.replace('rem', '')) + 1) +
'rem; inset-inline-end:1rem;';
$: barColor = $themeColors['SliderBarColor'];
$: progressColor = $themeColors['SliderProgressColor'];
const _showFontSize = showFontSize();
$: _showFonts = showFonts($fontChoices, contentsMode);
const _showThemes = showThemes();
$: _showLineHeight = showLineHeight(contentsMode);
$: _showTextAppearance = showTextAppearance($fontChoices, contentsMode);
// TEMP: Use TextAppearance button to rotate through languages to test i18n
const arrayRotate = (arr) => {
arr.push(arr.shift());
return arr;
};
const rotate = (items, current) => {
let mod = [...items];
while (mod[0] != current) {
mod = arrayRotate(mod);
}
return mod[1];
};
const handleClick = (event) => {
console.log(event);
if (event.shiftKey) {
rotateLanguages();
}
};
const rotateLanguages = () => {
$language = rotate(languages, $language);
};
const buttonBackground = (theme) => {
const backgroundColor = config.styles.find((x) => x.name === 'ui.background').properties[
'background-color'
];
if (backgroundColor.startsWith('#')) {
return backgroundColor;
}
return config.themes.find((x) => x.name === theme).colorSets.find((c) => c.type === 'main')
.colors[backgroundColor];
};
const buttonBorder = (theme, currentTheme) => {
return (
(theme === currentTheme ? '3px' : '1px') +
' solid ' +
(theme === 'Dark' ? '#FFFFFF' : '#888888')
);
};
const formatLineHeight = (lineHeight) => {
const displayValue = (lineHeight / 100).toLocaleString(undefined, {
minimumFractionDigits: 2
});
return displayValue;
};
</script>
<!-- TextAppearanceSelector -->
{#if _showTextAppearance}
<!-- svelte-ignore a11y_consider_explicit_label -->
<Modal bind:this={modalThis} id={modalId} addCSS={positioningCSS}>
<div class="grid gap-4">
<!-- Sliders for when text appearence text size is implemented place holder no functionality-->
{#if _showFontSize}
<div class="grid gap-4 items-center range-row m-2">
<TextAppearanceIcon color={$monoIconColor} />
{#if contentsMode}
<Slider
bind:value={$contentsFontSize}
{barColor}
{progressColor}
min={config.mainFeatures['text-size-min']}
max={config.mainFeatures['text-size-max']}
/>
{:else}
<Slider
bind:value={$bodyFontSize}
{barColor}
{progressColor}
min={config.mainFeatures['text-size-min']}
max={config.mainFeatures['text-size-max']}
/>
{/if}
<div class="text-md text-{$monoIconColor} place-self-end">
{contentsMode ? $contentsFontSize : $bodyFontSize}
</div>
</div>
{/if}
{#if _showLineHeight}
<div class="grid gap-4 items-center range-row m-2">
<ImageIcon.FormatLineSpacing color={$monoIconColor} />
<Slider
bind:value={$bodyLineHeight}
{barColor}
{progressColor}
min="100"
max="250"
/>
<div class="text-md text-{$monoIconColor} place-self-end">
{formatLineHeight($bodyLineHeight)}
</div>
</div>
{/if}
{#if _showFonts}
<div class="grid gap-4 items-center range-row m-2">
<ImageIcon.FontChoice color={$monoIconColor} />
<button
class="dy-btn-sm col-span-2 rounded"
style:border="1px dotted"
style:font-family={$currentFont}
style:font-size="large"
style:color={$monoIconColor}
on:click={() => modal.open(ModalType.Font)}
>{config.fonts.find((x) => x.family === $currentFont)?.name}</button
>
</div>
{/if}
<!-- Theme Selction buttons-->
{#if _showThemes}
<div
class="grid gap-2 m-2"
class:grid-cols-2={themes.length === 2}
class:grid-cols-3={themes.length === 3}
>
{#if themes.includes('Normal')}
<button
class="dy-btn-sm"
style:background-color={buttonBackground('Normal')}
style:border={buttonBorder('Normal', $theme)}
on:click={() => ($theme = 'Normal')}
></button>
{/if}
{#if themes.includes('Sepia')}
<button
class="dy-btn-sm"
style:background-color={buttonBackground('Sepia')}
style:border={buttonBorder('Sepia', $theme)}
on:click={() => ($theme = 'Sepia')}
></button>
{/if}
{#if themes.includes('Dark')}
<button
class="dy-btn-sm"
style:background-color={buttonBackground('Dark')}
style:border={buttonBorder('Dark', $theme)}
on:click={() => ($theme = 'Dark')}
></button>
{/if}
</div>
{/if}
</div>
</Modal>
{/if}
<style>
.range-row {
grid-template-columns: 1.5rem auto 1.5rem;
}
</style>