mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-04 23:32:54 +01:00
respect reduce motion
This commit is contained in:
10 files changed
+123
-8
No files matched your search
@@ -76,6 +76,13 @@ styles += "}";
|
||||
/* Gap between consecutive items in a staggered entrance */
|
||||
--duration-stagger: 20ms;
|
||||
|
||||
/* The spinner keeps turning so loading still reads as loading */
|
||||
&[data-reduce-motion="true"] {
|
||||
--duration-brief: 0s;
|
||||
--duration-subtle: 0s;
|
||||
--duration-stagger: 0s;
|
||||
}
|
||||
|
||||
--easing-standard: cubic-bezier(0.4, 0, 0.6, 1);
|
||||
|
||||
--tank-card-min-width: 8rem;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
gap: var(--space-4);
|
||||
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
max-width: min(40rem, 100%);
|
||||
padding: var(--space-4);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CaretDownIcon, DotFilledIcon, GlobeIcon } from "@radix-ui/react-icons";
|
||||
import { CaretDownIcon, DotFilledIcon } from "@radix-ui/react-icons";
|
||||
import { useState } from "react";
|
||||
import { getBestLocale } from "../../core/i18n/getBestLocale";
|
||||
import type { LocaleOption } from "../../core/i18n/getLocaleOptions";
|
||||
@@ -49,8 +49,7 @@ export function LocaleSelect({ options }: LocaleSelectProps) {
|
||||
</Select.ItemIndicator>
|
||||
|
||||
<Select.ItemText>
|
||||
{strings.settings.device_language}
|
||||
<GlobeIcon />
|
||||
{strings.settings.device_preference}
|
||||
</Select.ItemText>
|
||||
</Select.Item>
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<script>
|
||||
import { App, ReduceMotion } from "../stores/app";
|
||||
|
||||
// Runs before hydration so nothing animates before the setting applies
|
||||
const root = document.documentElement;
|
||||
const media = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
|
||||
function apply() {
|
||||
let reduceMotion: boolean;
|
||||
|
||||
switch (App.state.reduceMotion) {
|
||||
case ReduceMotion.Device:
|
||||
reduceMotion = media.matches;
|
||||
break;
|
||||
|
||||
case ReduceMotion.On:
|
||||
reduceMotion = true;
|
||||
break;
|
||||
|
||||
case ReduceMotion.Off:
|
||||
reduceMotion = false;
|
||||
break;
|
||||
}
|
||||
|
||||
root.dataset.reduceMotion = `${reduceMotion}`;
|
||||
}
|
||||
|
||||
apply();
|
||||
media.addEventListener("change", apply);
|
||||
App.on((state) => state.reduceMotion, apply);
|
||||
</script>
|
||||
@@ -1,10 +1,12 @@
|
||||
import { CaretDownIcon, DotFilledIcon } from "@radix-ui/react-icons";
|
||||
import type { ReactNode } from "react";
|
||||
import type { LocaleOption } from "../../core/i18n/getLocaleOptions";
|
||||
import { withLocale } from "../../hocs/withLocale";
|
||||
import { useStrings } from "../../hooks/useStrings";
|
||||
import { App } from "../../stores/app";
|
||||
import { App, ReduceMotion } from "../../stores/app";
|
||||
import { Dialog } from "../Dialog";
|
||||
import { LocaleSelect } from "../LocaleSelect";
|
||||
import { Select } from "../Select";
|
||||
import { Switch } from "../Switch";
|
||||
import { Text } from "../Text";
|
||||
import styles from "./index.module.css";
|
||||
@@ -25,6 +27,10 @@ export const SettingsDialog = withLocale(
|
||||
(state) => state.autoLoadModels,
|
||||
true,
|
||||
);
|
||||
const reduceMotion = App.useDeferred(
|
||||
(state) => state.reduceMotion,
|
||||
ReduceMotion.Device,
|
||||
);
|
||||
|
||||
return (
|
||||
<Dialog.Root>
|
||||
@@ -43,6 +49,65 @@ export const SettingsDialog = withLocale(
|
||||
<LocaleSelect options={localeOptions} />
|
||||
</div>
|
||||
|
||||
<div className={styles.row}>
|
||||
<Text>{strings.settings.reduce_motion.title}</Text>
|
||||
|
||||
<Select.Root
|
||||
value={`${reduceMotion}`}
|
||||
onValueChange={(value) => {
|
||||
App.mutate((draft) => {
|
||||
draft.reduceMotion = Number(value);
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Select.Trigger>
|
||||
<Select.Value />
|
||||
|
||||
<Select.Icon>
|
||||
<CaretDownIcon />
|
||||
</Select.Icon>
|
||||
</Select.Trigger>
|
||||
|
||||
<Select.Portal>
|
||||
<Select.Content>
|
||||
<Select.Viewport>
|
||||
<Select.Item value={`${ReduceMotion.Device}`}>
|
||||
<Select.ItemIndicator>
|
||||
<DotFilledIcon />
|
||||
</Select.ItemIndicator>
|
||||
|
||||
<Select.ItemText>
|
||||
{strings.settings.device_preference}
|
||||
</Select.ItemText>
|
||||
</Select.Item>
|
||||
|
||||
<Select.Separator />
|
||||
|
||||
<Select.Item value={`${ReduceMotion.On}`}>
|
||||
<Select.ItemIndicator>
|
||||
<DotFilledIcon />
|
||||
</Select.ItemIndicator>
|
||||
|
||||
<Select.ItemText>
|
||||
{strings.settings.reduce_motion.on}
|
||||
</Select.ItemText>
|
||||
</Select.Item>
|
||||
|
||||
<Select.Item value={`${ReduceMotion.Off}`}>
|
||||
<Select.ItemIndicator>
|
||||
<DotFilledIcon />
|
||||
</Select.ItemIndicator>
|
||||
|
||||
<Select.ItemText>
|
||||
{strings.settings.reduce_motion.off}
|
||||
</Select.ItemText>
|
||||
</Select.Item>
|
||||
</Select.Viewport>
|
||||
</Select.Content>
|
||||
</Select.Portal>
|
||||
</Select.Root>
|
||||
</div>
|
||||
|
||||
<div className={styles.row}>
|
||||
<Text>{strings.settings.auto_load_models}</Text>
|
||||
<Switch
|
||||
|
||||
@@ -6,6 +6,7 @@ import ColorAlias from "../components/ColorAlias.astro";
|
||||
import ColorScale from "../components/ColorScale.astro";
|
||||
import NavbarBig from "../components/NavbarBig.astro";
|
||||
import NavbarSmall from "../components/NavbarSmall.astro";
|
||||
import ReduceMotion from "../components/ReduceMotion.astro";
|
||||
import SystemTheme from "../components/SystemTheme.astro";
|
||||
import VisibilityFlags from "../components/VisibilityFlags.astro";
|
||||
import type { Tool } from "../config/tools";
|
||||
@@ -38,6 +39,7 @@ const { locale, accent, solidNavbar = false, tool } = Astro.props;
|
||||
<BaseStyles />
|
||||
|
||||
<VisibilityFlags />
|
||||
<ReduceMotion />
|
||||
|
||||
<style>
|
||||
:root {
|
||||
|
||||
@@ -6,9 +6,16 @@ export interface WargamingLogin {
|
||||
expires: number;
|
||||
}
|
||||
|
||||
export enum ReduceMotion {
|
||||
Device,
|
||||
On,
|
||||
Off,
|
||||
}
|
||||
|
||||
export interface App {
|
||||
developerMode: boolean;
|
||||
autoLoadModels: boolean;
|
||||
reduceMotion: ReduceMotion;
|
||||
policiesAgreementIndex: number;
|
||||
logins: {
|
||||
wargaming?: WargamingLogin;
|
||||
@@ -19,6 +26,7 @@ export const App = new Soapstone<App>(
|
||||
{
|
||||
developerMode: false,
|
||||
autoLoadModels: true,
|
||||
reduceMotion: ReduceMotion.Device,
|
||||
policiesAgreementIndex: -1,
|
||||
logins: {},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user