Skip to content

Commit 4633c17

Browse files
authored
feat(app): redesign appearance settings (anomalyco#1678)
* feat(app): redesign appearance settings * feat(app): replace hide taskbar toggle with switch
1 parent d58d79a commit 4633c17

8 files changed

Lines changed: 418 additions & 82 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Switch as SwitchPrimitive } from "@base-ui/react/switch"
2+
3+
import { cn } from "@/lib/utils"
4+
5+
function Switch({
6+
className,
7+
size = "default",
8+
...props
9+
}: SwitchPrimitive.Root.Props & {
10+
size?: "sm" | "default"
11+
}) {
12+
return (
13+
<SwitchPrimitive.Root
14+
data-slot="switch"
15+
data-size={size}
16+
className={cn(
17+
"peer group/switch relative inline-flex shrink-0 items-center rounded-full border-2 transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=default]:h-5 data-[size=default]:w-11 data-[size=sm]:h-4 data-[size=sm]:w-7 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-unchecked:border-transparent data-unchecked:bg-input/90 data-disabled:cursor-not-allowed data-disabled:opacity-50",
18+
className
19+
)}
20+
{...props}
21+
>
22+
<SwitchPrimitive.Thumb
23+
data-slot="switch-thumb"
24+
className="pointer-events-none block rounded-full bg-background shadow-sm ring-0 transition-transform not-dark:bg-clip-padding group-data-[size=default]/switch:h-4 group-data-[size=default]/switch:w-6 group-data-[size=sm]/switch:h-3 group-data-[size=sm]/switch:w-4 data-checked:translate-x-[calc(100%-8px)] rtl:data-checked:-translate-x-[calc(100%-8px)] dark:data-checked:bg-primary-foreground data-unchecked:translate-x-0 rtl:data-unchecked:translate-x-0 dark:data-unchecked:bg-foreground"
25+
/>
26+
</SwitchPrimitive.Root>
27+
)
28+
}
29+
30+
export { Switch }
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"use client"
2+
3+
import * as React from "react"
4+
import { Toggle as TogglePrimitive } from "@base-ui/react/toggle"
5+
import { ToggleGroup as ToggleGroupPrimitive } from "@base-ui/react/toggle-group"
6+
import { type VariantProps } from "class-variance-authority"
7+
8+
import { cn } from "@/lib/utils"
9+
import { toggleVariants } from "@/components/ui/toggle"
10+
11+
const ToggleGroupContext = React.createContext<
12+
VariantProps<typeof toggleVariants> & {
13+
spacing?: number
14+
orientation?: "horizontal" | "vertical"
15+
}
16+
>({
17+
size: "default",
18+
variant: "default",
19+
spacing: 0,
20+
orientation: "horizontal",
21+
})
22+
23+
function ToggleGroup({
24+
className,
25+
variant,
26+
size,
27+
spacing = 0,
28+
orientation = "horizontal",
29+
children,
30+
...props
31+
}: ToggleGroupPrimitive.Props &
32+
VariantProps<typeof toggleVariants> & {
33+
spacing?: number
34+
orientation?: "horizontal" | "vertical"
35+
}) {
36+
return (
37+
<ToggleGroupPrimitive
38+
data-slot="toggle-group"
39+
data-variant={variant}
40+
data-size={size}
41+
data-spacing={spacing}
42+
data-orientation={orientation}
43+
style={{ "--gap": spacing } as React.CSSProperties}
44+
className={cn(
45+
"group/toggle-group flex w-fit flex-row items-center gap-[--spacing(var(--gap))] data-[spacing=0]:data-[variant=outline]:rounded-3xl data-vertical:flex-col data-vertical:items-stretch",
46+
className
47+
)}
48+
{...props}
49+
>
50+
<ToggleGroupContext.Provider
51+
value={{ variant, size, spacing, orientation }}
52+
>
53+
{children}
54+
</ToggleGroupContext.Provider>
55+
</ToggleGroupPrimitive>
56+
)
57+
}
58+
59+
function ToggleGroupItem({
60+
className,
61+
children,
62+
variant = "default",
63+
size = "default",
64+
...props
65+
}: TogglePrimitive.Props & VariantProps<typeof toggleVariants>) {
66+
const context = React.useContext(ToggleGroupContext)
67+
68+
return (
69+
<TogglePrimitive
70+
data-slot="toggle-group-item"
71+
data-variant={context.variant || variant}
72+
data-size={context.size || size}
73+
data-spacing={context.spacing}
74+
className={cn(
75+
"shrink-0 group-data-[spacing=0]/toggle-group:rounded-none group-data-[spacing=0]/toggle-group:px-3 group-data-[spacing=0]/toggle-group:shadow-none focus:z-10 focus-visible:z-10 group-data-[spacing=0]/toggle-group:has-data-[icon=inline-end]:pe-2.5 group-data-[spacing=0]/toggle-group:has-data-[icon=inline-start]:ps-2.5 group-data-horizontal/toggle-group:data-[spacing=0]:first:rounded-s-3xl group-data-vertical/toggle-group:data-[spacing=0]:first:rounded-t-3xl group-data-horizontal/toggle-group:data-[spacing=0]:last:rounded-e-3xl group-data-vertical/toggle-group:data-[spacing=0]:last:rounded-b-3xl data-[state=on]:bg-muted group-data-horizontal/toggle-group:data-[spacing=0]:data-[variant=outline]:border-s-0 group-data-vertical/toggle-group:data-[spacing=0]:data-[variant=outline]:border-t-0 group-data-horizontal/toggle-group:data-[spacing=0]:data-[variant=outline]:first:border-s group-data-vertical/toggle-group:data-[spacing=0]:data-[variant=outline]:first:border-t",
76+
toggleVariants({
77+
variant: context.variant || variant,
78+
size: context.size || size,
79+
}),
80+
className
81+
)}
82+
{...props}
83+
>
84+
{children}
85+
</TogglePrimitive>
86+
)
87+
}
88+
89+
export { ToggleGroup, ToggleGroupItem }
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Toggle as TogglePrimitive } from "@base-ui/react/toggle"
2+
import { cva, type VariantProps } from "class-variance-authority"
3+
4+
import { cn } from "@/lib/utils"
5+
6+
const toggleVariants = cva(
7+
"group/toggle inline-flex items-center justify-center gap-1 rounded-3xl text-sm font-medium whitespace-nowrap transition-colors outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/30 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-pressed:bg-muted dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
8+
{
9+
variants: {
10+
variant: {
11+
default: "bg-transparent",
12+
outline: "border border-input bg-transparent hover:bg-muted",
13+
},
14+
size: {
15+
default:
16+
"h-9 min-w-9 px-3 has-data-[icon=inline-end]:pe-2.5 has-data-[icon=inline-start]:ps-2.5",
17+
sm: "h-8 min-w-8 px-3 has-data-[icon=inline-end]:pe-2 has-data-[icon=inline-start]:ps-2",
18+
lg: "h-10 min-w-10 px-4 has-data-[icon=inline-end]:pe-3 has-data-[icon=inline-start]:ps-3",
19+
},
20+
},
21+
defaultVariants: {
22+
variant: "default",
23+
size: "default",
24+
},
25+
}
26+
)
27+
28+
function Toggle({
29+
className,
30+
variant = "default",
31+
size = "default",
32+
...props
33+
}: TogglePrimitive.Props & VariantProps<typeof toggleVariants>) {
34+
return (
35+
<TogglePrimitive
36+
data-slot="toggle"
37+
className={cn(toggleVariants({ variant, size, className }))}
38+
{...props}
39+
/>
40+
)
41+
}
42+
43+
export { Toggle, toggleVariants }
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/** @jsxImportSource react */
2+
import {
3+
Select,
4+
SelectContent,
5+
SelectGroup,
6+
SelectItem,
7+
SelectTrigger,
8+
SelectValue,
9+
} from "@/components/ui/select";
10+
import { LANGUAGE_OPTIONS, t } from "../../../../i18n";
11+
import type { AppearanceViewProps } from "../pages/appearance-view";
12+
import {
13+
SettingsSection,
14+
SettingsSectionHeader,
15+
SettingsSectionHeaderContent,
16+
SettingsSectionHeaderDescription,
17+
SettingsSectionHeaderTitle,
18+
} from "../settings-section";
19+
20+
interface LanguageSectionProps extends Pick<AppearanceViewProps, "busy" | "language" | "setLanguage"> {}
21+
22+
export function LanguageSection(props: LanguageSectionProps) {
23+
return (
24+
<SettingsSection>
25+
<SettingsSectionHeader>
26+
<SettingsSectionHeaderContent>
27+
<SettingsSectionHeaderTitle>{t("settings.language")}</SettingsSectionHeaderTitle>
28+
<SettingsSectionHeaderDescription>{t("settings.language.description")}</SettingsSectionHeaderDescription>
29+
</SettingsSectionHeaderContent>
30+
31+
<div className="flex shrink-0 items-center gap-2">
32+
<div className="w-64 max-w-full">
33+
<Select
34+
value={props.language}
35+
items={LANGUAGE_OPTIONS}
36+
onValueChange={(value) => {
37+
if (value) props.setLanguage(value);
38+
}}
39+
disabled={props.busy}
40+
>
41+
<SelectTrigger className="w-full" aria-label={t("settings.language")}>
42+
<SelectValue placeholder={t("settings.language")} />
43+
</SelectTrigger>
44+
<SelectContent>
45+
<SelectGroup>
46+
{LANGUAGE_OPTIONS.map((option) => (
47+
<SelectItem key={option.value} value={option.value}>
48+
{option.nativeName}
49+
</SelectItem>
50+
))}
51+
</SelectGroup>
52+
</SelectContent>
53+
</Select>
54+
</div>
55+
</div>
56+
</SettingsSectionHeader>
57+
</SettingsSection>
58+
);
59+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/** @jsxImportSource react */
2+
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
3+
import { cn } from "@/lib/utils";
4+
import type { ReactNode } from "react";
5+
import { t } from "../../../../i18n";
6+
import type { AppearanceViewProps } from "../pages/appearance-view";
7+
import {
8+
SettingsSection,
9+
SettingsSectionHeader,
10+
SettingsSectionHeaderContent,
11+
SettingsSectionHeaderDescription,
12+
SettingsSectionHeaderTitle,
13+
} from "../settings-section";
14+
15+
type ThemeMode = AppearanceViewProps["themeMode"];
16+
17+
interface ThemeSectionProps
18+
extends Pick<AppearanceViewProps, "busy" | "themeMode" | "setThemeMode"> {}
19+
20+
export function ThemeSection(props: ThemeSectionProps) {
21+
return (
22+
<SettingsSection className="items-center">
23+
<SettingsSectionHeader className="w-full">
24+
<SettingsSectionHeaderContent>
25+
<SettingsSectionHeaderTitle>{t("settings.appearance_title")}</SettingsSectionHeaderTitle>
26+
<SettingsSectionHeaderDescription>{t("settings.appearance_hint")}</SettingsSectionHeaderDescription>
27+
</SettingsSectionHeaderContent>
28+
</SettingsSectionHeader>
29+
30+
<ThemePicker
31+
className="pt-1"
32+
busy={props.busy}
33+
themeMode={props.themeMode}
34+
setThemeMode={props.setThemeMode}
35+
/>
36+
37+
<div className="text-xs text-muted-foreground">{t("settings.theme_system_hint")}</div>
38+
</SettingsSection>
39+
);
40+
}
41+
42+
interface ThemePickerProps {
43+
className?: string;
44+
busy: boolean;
45+
themeMode: ThemeMode;
46+
setThemeMode: (value: ThemeMode) => void;
47+
}
48+
49+
function ThemePicker(props: ThemePickerProps) {
50+
return (
51+
<ToggleGroup
52+
value={[props.themeMode]}
53+
onValueChange={(value) => {
54+
if (value[0] === null) {
55+
return;
56+
}
57+
58+
props.setThemeMode(value[0] as ThemeMode);
59+
}}
60+
disabled={props.busy}
61+
className={cn("w-full gap-6 max-w-xl", props.className)}
62+
>
63+
<ThemePickerItem
64+
value="system"
65+
label={t("settings.theme_system")}
66+
>
67+
<ThemePreview value="system" />
68+
<ThemePickerLabel>{t("settings.theme_system")}</ThemePickerLabel>
69+
</ThemePickerItem>
70+
<ThemePickerItem
71+
value="light"
72+
label={t("settings.theme_light")}
73+
>
74+
<ThemePreview value="light" className="bg-white" />
75+
<ThemePickerLabel>{t("settings.theme_light")}</ThemePickerLabel>
76+
</ThemePickerItem>
77+
<ThemePickerItem
78+
value="dark"
79+
label={t("settings.theme_dark")}
80+
>
81+
<ThemePreview value="dark" className="bg-black" />
82+
<ThemePickerLabel>{t("settings.theme_dark")}</ThemePickerLabel>
83+
</ThemePickerItem>
84+
</ToggleGroup>
85+
);
86+
}
87+
88+
interface ThemePickerItemProps {
89+
value: ThemeMode;
90+
label: string;
91+
children: ReactNode;
92+
}
93+
94+
function ThemePickerItem(props: ThemePickerItemProps) {
95+
return (
96+
<ToggleGroupItem
97+
value={props.value}
98+
aria-label={props.label}
99+
className="group/theme h-auto flex-1 flex-col gap-3 rounded-sm px-0 py-0 hover:bg-transparent aria-pressed:bg-transparent"
100+
>
101+
{props.children}
102+
</ToggleGroupItem>
103+
);
104+
}
105+
106+
interface ThemePreviewProps {
107+
value: ThemeMode;
108+
className?: string;
109+
}
110+
111+
function ThemePreview(props: ThemePreviewProps) {
112+
return (
113+
<div
114+
className={cn(
115+
"aspect-4/3 w-full overflow-hidden rounded-md border transition-shadow group-data-pressed/theme:ring-2 group-data-pressed/theme:ring-primary group-data-pressed/theme:ring-offset-2 group-data-pressed/theme:ring-offset-background group-hover/theme:ring-1 group-hover/theme:ring-primary/40 group-hover/theme:ring-offset-2 group-hover/theme:ring-offset-background",
116+
props.className,
117+
)}
118+
>
119+
{props.value === "system" && (
120+
<div className="flex h-full">
121+
<div className="w-1/2 bg-white" />
122+
<div className="w-1/2 bg-black" />
123+
</div>
124+
)}
125+
</div>
126+
);
127+
}
128+
129+
interface ThemePickerLabelProps {
130+
children: string;
131+
}
132+
133+
function ThemePickerLabel(props: ThemePickerLabelProps) {
134+
return (
135+
<span className="text-sm text-muted-foreground group-data-pressed/theme:text-foreground">
136+
{props.children}
137+
</span>
138+
);
139+
}

0 commit comments

Comments
 (0)