Files
aigc-home/calliope-web/src/lib/components/ui/Switch.svelte
T
施工员andmultica-agent e42212a16f feat(ui): fusion design tokens and shared component reskin (HEL-651 A batch)
- app.css: HEL-649 §一 tokens (bg/line/accent/status/text/type/space/radius/shadow/motion), legacy names aliased, reduced-motion via prefers-reduced-motion and data-reduce
- shared .a-btn/.status-chip/.a-panel/inputs reskinned; new .a-tag/.a-progress/.a-sprocket/.a-stage/.a-float
- tailwind colors/radii reference the same CSS variables
- ui primitives (StatusChip/ProgressBar/Modal/Button/ConfirmDialog/Skeleton/Switch/Card/Toast) on tokens
- running state -> --run, awaiting confirm -> --warn, --cloud purple removed, old palette literals -> tokens

Co-authored-by: multica-agent <github@multica.ai>
2026-09-30 08:29:37 +08:00

66 lines
1.3 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts">
interface Props {
checked: boolean;
label: string;
disabled?: boolean;
onchange?: (next: boolean) => void;
}
let { checked, label, disabled = false, onchange }: Props = $props();
</script>
<!-- §3.10 开关: 34×19 capsule; on = --accent-lo track + ink knob, off = --bg-4. -->
<button
type="button"
class="switch"
class:on={checked}
role="switch"
aria-checked={checked}
aria-label={label}
{disabled}
onclick={() => onchange?.(!checked)}
>
<span class="knob"></span>
</button>
<style>
.switch {
flex-shrink: 0;
width: 34px;
height: 19px;
border-radius: var(--r-pill);
border: 1px solid var(--line-2);
background: var(--bg-4);
position: relative;
cursor: pointer;
padding: 0;
transition:
background-color var(--d-state) ease,
border-color var(--d-state) ease;
}
.switch:disabled {
opacity: 0.45;
cursor: not-allowed;
}
.knob {
position: absolute;
top: 1px;
left: 1px;
width: 15px;
height: 15px;
border-radius: var(--r-pill);
background: var(--text-3);
transition:
transform var(--d-state) var(--ease-out),
background-color var(--d-state) ease;
}
.switch.on {
background: var(--accent-lo);
border-color: var(--accent-lo);
}
.switch.on .knob {
transform: translateX(15px);
background: var(--accent-ink);
}
</style>