refactor(ui): add size variants to Switch and consolidate styles
Introduce sm/md/lg sizes on the Switch component driven by CSS custom properties, move switch styling into a dedicated switch.css, and remove the duplicated overrides from styles.css and ToolbarCustomizeDialog. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
|||||||
|
.ui-switch {
|
||||||
|
--ui-switch-width: 46px;
|
||||||
|
--ui-switch-height: 26px;
|
||||||
|
--ui-switch-thumb-size: 18px;
|
||||||
|
--ui-switch-inset: 4px;
|
||||||
|
position: relative;
|
||||||
|
width: var(--ui-switch-width);
|
||||||
|
min-width: var(--ui-switch-width);
|
||||||
|
height: var(--ui-switch-height);
|
||||||
|
display: inline-flex;
|
||||||
|
flex: 0 0 var(--ui-switch-width);
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 999px;
|
||||||
|
outline: none;
|
||||||
|
appearance: none;
|
||||||
|
color: inherit;
|
||||||
|
background: #d8dde5;
|
||||||
|
vertical-align: middle;
|
||||||
|
transition: background-color 0.18s ease, box-shadow 0.18s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-switch[data-size="sm"] {
|
||||||
|
--ui-switch-width: 32px;
|
||||||
|
--ui-switch-height: 18px;
|
||||||
|
--ui-switch-thumb-size: 14px;
|
||||||
|
--ui-switch-inset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-switch[data-size="md"] {
|
||||||
|
--ui-switch-width: 36px;
|
||||||
|
--ui-switch-height: 20px;
|
||||||
|
--ui-switch-thumb-size: 14px;
|
||||||
|
--ui-switch-inset: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-switch[data-state="checked"] {
|
||||||
|
background: #30343a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-switch:focus-visible {
|
||||||
|
box-shadow: 0 0 0 2px #fff, 0 0 0 4px #8b95a5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-switch-thumb {
|
||||||
|
width: var(--ui-switch-thumb-size);
|
||||||
|
height: var(--ui-switch-thumb-size);
|
||||||
|
display: block;
|
||||||
|
flex: 0 0 var(--ui-switch-thumb-size);
|
||||||
|
margin: 0;
|
||||||
|
transform: translateX(var(--ui-switch-inset));
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: 0 1px 2px rgba(17, 24, 39, 0.2);
|
||||||
|
pointer-events: none;
|
||||||
|
transition: transform 0.18s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-switch[data-state="checked"] .ui-switch-thumb {
|
||||||
|
transform: translateX(calc(var(--ui-switch-width) - var(--ui-switch-thumb-size) - var(--ui-switch-inset)));
|
||||||
|
}
|
||||||
@@ -2,10 +2,17 @@
|
|||||||
|
|
||||||
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
||||||
import type { ComponentProps } from "react";
|
import type { ComponentProps } from "react";
|
||||||
|
import "./switch.css";
|
||||||
|
|
||||||
export function Switch({ className = "", ...props }: ComponentProps<typeof SwitchPrimitive.Root>) {
|
export type SwitchSize = "sm" | "md" | "lg";
|
||||||
|
|
||||||
|
type SwitchProps = ComponentProps<typeof SwitchPrimitive.Root> & {
|
||||||
|
size?: SwitchSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function Switch({ className = "", size = "lg", ...props }: SwitchProps) {
|
||||||
return (
|
return (
|
||||||
<SwitchPrimitive.Root className={["ui-switch", className].filter(Boolean).join(" ")} {...props}>
|
<SwitchPrimitive.Root className={["ui-switch", className].filter(Boolean).join(" ")} data-size={size} {...props}>
|
||||||
<SwitchPrimitive.Thumb className="ui-switch-thumb" />
|
<SwitchPrimitive.Thumb className="ui-switch-thumb" />
|
||||||
</SwitchPrimitive.Root>
|
</SwitchPrimitive.Root>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -424,26 +424,6 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toolbar-customize-switch .ui-switch {
|
|
||||||
width: 32px;
|
|
||||||
height: 18px;
|
|
||||||
background: #d8dde5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.toolbar-customize-switch .ui-switch[data-state="checked"] {
|
|
||||||
background: #303030;
|
|
||||||
}
|
|
||||||
|
|
||||||
.toolbar-customize-switch .ui-switch-thumb {
|
|
||||||
width: 14px;
|
|
||||||
height: 14px;
|
|
||||||
transform: translateX(2px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.toolbar-customize-switch .ui-switch[data-state="checked"] .ui-switch-thumb {
|
|
||||||
transform: translateX(16px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.toolbar-customize-footer-actions {
|
.toolbar-customize-footer-actions {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ export function ToolbarCustomizeDialog<TId extends string>({
|
|||||||
|
|
||||||
<footer className="toolbar-customize-footer">
|
<footer className="toolbar-customize-footer">
|
||||||
<label className="toolbar-customize-switch">
|
<label className="toolbar-customize-switch">
|
||||||
<Switch checked={draftShowToolNames} onCheckedChange={setDraftShowToolNames} />
|
<Switch size="sm" checked={draftShowToolNames} onCheckedChange={setDraftShowToolNames} />
|
||||||
<span>{t("showToolNames")}</span>
|
<span>{t("showToolNames")}</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="toolbar-customize-footer-actions">
|
<div className="toolbar-customize-footer-actions">
|
||||||
|
|||||||
@@ -292,33 +292,6 @@ button:disabled {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui-switch {
|
|
||||||
position: relative;
|
|
||||||
width: 46px;
|
|
||||||
height: 26px;
|
|
||||||
border: 0;
|
|
||||||
border-radius: 999px;
|
|
||||||
background: #d7dce4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ui-switch[data-state="checked"] {
|
|
||||||
background: #303846;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ui-switch-thumb {
|
|
||||||
display: block;
|
|
||||||
width: 18px;
|
|
||||||
height: 18px;
|
|
||||||
transform: translateX(4px);
|
|
||||||
border-radius: 999px;
|
|
||||||
background: #fff;
|
|
||||||
transition: transform 0.18s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ui-switch[data-state="checked"] .ui-switch-thumb {
|
|
||||||
transform: translateX(24px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.model-tabs {
|
.model-tabs {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
|||||||
Reference in New Issue
Block a user