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
@@ -86,7 +86,6 @@ export class ClientBlitzKitAPI extends AbstractBlitzKitAPI {
|
|||||||
return fetchJSON<BlitzScripts>(alias("api", "definitions/scripts.json"));
|
return fetchJSON<BlitzScripts>(alias("api", "definitions/scripts.json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cache()
|
|
||||||
strings(locale: string) {
|
strings(locale: string) {
|
||||||
return fetchJSON<Strings>(alias("api", `strings/${locale}.json`));
|
return fetchJSON<Strings>(alias("api", `strings/${locale}.json`));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Strings } from "@blitzkit/i18n";
|
|||||||
import locales from "@blitzkit/i18n/locales.json";
|
import locales from "@blitzkit/i18n/locales.json";
|
||||||
import { DeepPartial } from "@blitzkit/protos";
|
import { DeepPartial } from "@blitzkit/protos";
|
||||||
import { merge } from "lodash-es";
|
import { merge } from "lodash-es";
|
||||||
import { Cache } from "../cache";
|
|
||||||
import { ServerBlitzKitAPI11 } from "./11_scripts";
|
import { ServerBlitzKitAPI11 } from "./11_scripts";
|
||||||
|
|
||||||
export abstract class ServerBlitzKitAPI12 extends ServerBlitzKitAPI11 {
|
export abstract class ServerBlitzKitAPI12 extends ServerBlitzKitAPI11 {
|
||||||
@@ -11,7 +10,6 @@ export abstract class ServerBlitzKitAPI12 extends ServerBlitzKitAPI11 {
|
|||||||
{ import: "default" },
|
{ import: "default" },
|
||||||
);
|
);
|
||||||
|
|
||||||
@Cache()
|
|
||||||
async strings(locale: string) {
|
async strings(locale: string) {
|
||||||
const localized = (await this.globbedStrings[
|
const localized = (await this.globbedStrings[
|
||||||
`../../../../../i18n/strings/${locale}.json`
|
`../../../../../i18n/strings/${locale}.json`
|
||||||
|
|||||||
@@ -6,8 +6,13 @@
|
|||||||
|
|
||||||
"settings": {
|
"settings": {
|
||||||
"language": "Language",
|
"language": "Language",
|
||||||
"device_language": "Device language",
|
"device_preference": "Device preference",
|
||||||
"auto_load_models": "Auto-load models",
|
"auto_load_models": "Auto-load models",
|
||||||
|
"reduce_motion": {
|
||||||
|
"title": "Reduce motion",
|
||||||
|
"on": "On",
|
||||||
|
"off": "Off"
|
||||||
|
},
|
||||||
"developer_mode": "Developer mode"
|
"developer_mode": "Developer mode"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,13 @@ styles += "}";
|
|||||||
/* Gap between consecutive items in a staggered entrance */
|
/* Gap between consecutive items in a staggered entrance */
|
||||||
--duration-stagger: 20ms;
|
--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);
|
--easing-standard: cubic-bezier(0.4, 0, 0.6, 1);
|
||||||
|
|
||||||
--tank-card-min-width: 8rem;
|
--tank-card-min-width: 8rem;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
gap: var(--space-4);
|
gap: var(--space-4);
|
||||||
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
width: 100%;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
max-width: min(40rem, 100%);
|
max-width: min(40rem, 100%);
|
||||||
padding: var(--space-4);
|
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 { useState } from "react";
|
||||||
import { getBestLocale } from "../../core/i18n/getBestLocale";
|
import { getBestLocale } from "../../core/i18n/getBestLocale";
|
||||||
import type { LocaleOption } from "../../core/i18n/getLocaleOptions";
|
import type { LocaleOption } from "../../core/i18n/getLocaleOptions";
|
||||||
@@ -49,8 +49,7 @@ export function LocaleSelect({ options }: LocaleSelectProps) {
|
|||||||
</Select.ItemIndicator>
|
</Select.ItemIndicator>
|
||||||
|
|
||||||
<Select.ItemText>
|
<Select.ItemText>
|
||||||
{strings.settings.device_language}
|
{strings.settings.device_preference}
|
||||||
<GlobeIcon />
|
|
||||||
</Select.ItemText>
|
</Select.ItemText>
|
||||||
</Select.Item>
|
</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 { ReactNode } from "react";
|
||||||
import type { LocaleOption } from "../../core/i18n/getLocaleOptions";
|
import type { LocaleOption } from "../../core/i18n/getLocaleOptions";
|
||||||
import { withLocale } from "../../hocs/withLocale";
|
import { withLocale } from "../../hocs/withLocale";
|
||||||
import { useStrings } from "../../hooks/useStrings";
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
import { App } from "../../stores/app";
|
import { App, ReduceMotion } from "../../stores/app";
|
||||||
import { Dialog } from "../Dialog";
|
import { Dialog } from "../Dialog";
|
||||||
import { LocaleSelect } from "../LocaleSelect";
|
import { LocaleSelect } from "../LocaleSelect";
|
||||||
|
import { Select } from "../Select";
|
||||||
import { Switch } from "../Switch";
|
import { Switch } from "../Switch";
|
||||||
import { Text } from "../Text";
|
import { Text } from "../Text";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
@@ -25,6 +27,10 @@ export const SettingsDialog = withLocale(
|
|||||||
(state) => state.autoLoadModels,
|
(state) => state.autoLoadModels,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
const reduceMotion = App.useDeferred(
|
||||||
|
(state) => state.reduceMotion,
|
||||||
|
ReduceMotion.Device,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog.Root>
|
<Dialog.Root>
|
||||||
@@ -43,6 +49,65 @@ export const SettingsDialog = withLocale(
|
|||||||
<LocaleSelect options={localeOptions} />
|
<LocaleSelect options={localeOptions} />
|
||||||
</div>
|
</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}>
|
<div className={styles.row}>
|
||||||
<Text>{strings.settings.auto_load_models}</Text>
|
<Text>{strings.settings.auto_load_models}</Text>
|
||||||
<Switch
|
<Switch
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import ColorAlias from "../components/ColorAlias.astro";
|
|||||||
import ColorScale from "../components/ColorScale.astro";
|
import ColorScale from "../components/ColorScale.astro";
|
||||||
import NavbarBig from "../components/NavbarBig.astro";
|
import NavbarBig from "../components/NavbarBig.astro";
|
||||||
import NavbarSmall from "../components/NavbarSmall.astro";
|
import NavbarSmall from "../components/NavbarSmall.astro";
|
||||||
|
import ReduceMotion from "../components/ReduceMotion.astro";
|
||||||
import SystemTheme from "../components/SystemTheme.astro";
|
import SystemTheme from "../components/SystemTheme.astro";
|
||||||
import VisibilityFlags from "../components/VisibilityFlags.astro";
|
import VisibilityFlags from "../components/VisibilityFlags.astro";
|
||||||
import type { Tool } from "../config/tools";
|
import type { Tool } from "../config/tools";
|
||||||
@@ -38,6 +39,7 @@ const { locale, accent, solidNavbar = false, tool } = Astro.props;
|
|||||||
<BaseStyles />
|
<BaseStyles />
|
||||||
|
|
||||||
<VisibilityFlags />
|
<VisibilityFlags />
|
||||||
|
<ReduceMotion />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
|
|||||||
@@ -6,9 +6,16 @@ export interface WargamingLogin {
|
|||||||
expires: number;
|
expires: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ReduceMotion {
|
||||||
|
Device,
|
||||||
|
On,
|
||||||
|
Off,
|
||||||
|
}
|
||||||
|
|
||||||
export interface App {
|
export interface App {
|
||||||
developerMode: boolean;
|
developerMode: boolean;
|
||||||
autoLoadModels: boolean;
|
autoLoadModels: boolean;
|
||||||
|
reduceMotion: ReduceMotion;
|
||||||
policiesAgreementIndex: number;
|
policiesAgreementIndex: number;
|
||||||
logins: {
|
logins: {
|
||||||
wargaming?: WargamingLogin;
|
wargaming?: WargamingLogin;
|
||||||
@@ -19,6 +26,7 @@ export const App = new Soapstone<App>(
|
|||||||
{
|
{
|
||||||
developerMode: false,
|
developerMode: false,
|
||||||
autoLoadModels: true,
|
autoLoadModels: true,
|
||||||
|
reduceMotion: ReduceMotion.Device,
|
||||||
policiesAgreementIndex: -1,
|
policiesAgreementIndex: -1,
|
||||||
logins: {},
|
logins: {},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user