mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-13 20:56:11 +01:00
traverse toy
This commit is contained in:
1 parent
de80519f06
commit
cae63a70b0
15 files changed
+346
-36
No files matched your search
@@ -1,23 +1,53 @@
|
||||
.options {
|
||||
width: max-content;
|
||||
|
||||
position: relative;
|
||||
display: grid;
|
||||
|
||||
border-radius: var(--radius-max);
|
||||
|
||||
background-color: var(--gray-3);
|
||||
&[data-size="minor"] {
|
||||
.option {
|
||||
padding: var(--space-2) var(--space-3);
|
||||
font-size: 0.75em;
|
||||
}
|
||||
}
|
||||
|
||||
.indicator {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
|
||||
background-color: var(--accent-3);
|
||||
outline: var(--outline-focus);
|
||||
border-radius: var(--radius-max);
|
||||
|
||||
transition: var(--duration-brief);
|
||||
}
|
||||
|
||||
&[data-variant="solid"] {
|
||||
background-color: var(--gray-3);
|
||||
|
||||
.indicator {
|
||||
background-color: var(--accent-3);
|
||||
}
|
||||
}
|
||||
|
||||
&[data-variant="underline"] {
|
||||
border-radius: 0;
|
||||
|
||||
.indicator {
|
||||
top: auto;
|
||||
bottom: 0;
|
||||
|
||||
background: linear-gradient(transparent, var(--accent-a2));
|
||||
|
||||
outline: none;
|
||||
border-radius: 0;
|
||||
|
||||
border-bottom: var(--space-1) solid var(--accent-9);
|
||||
}
|
||||
}
|
||||
|
||||
.option {
|
||||
position: relative;
|
||||
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
import { type ReactNode } from "react";
|
||||
import styles from "./index.module.css";
|
||||
|
||||
export interface SegmentedControlOption<Value extends string | number> {
|
||||
value: Value;
|
||||
export interface SegmentedControlOption {
|
||||
value: string;
|
||||
label: ReactNode;
|
||||
}
|
||||
|
||||
export interface SegmentedControlProps<Value extends string | number> {
|
||||
options: readonly SegmentedControlOption<Value>[];
|
||||
value: Value;
|
||||
onValueChange(value: Value): void;
|
||||
export interface SegmentedControlProps {
|
||||
options: readonly SegmentedControlOption[];
|
||||
value: string;
|
||||
onValueChange(value: string): void;
|
||||
size?: "regular" | "minor";
|
||||
variant?: "solid" | "underline";
|
||||
}
|
||||
|
||||
export function SegmentedControl<Value extends string | number>({
|
||||
export function SegmentedControl({
|
||||
options,
|
||||
value,
|
||||
onValueChange,
|
||||
}: SegmentedControlProps<Value>) {
|
||||
size = "regular",
|
||||
variant = "solid",
|
||||
}: SegmentedControlProps) {
|
||||
const selectedIndex = options.findIndex((option) => option.value === value);
|
||||
const segmentWidth = 100 / options.length;
|
||||
|
||||
@@ -24,7 +28,11 @@ export function SegmentedControl<Value extends string | number>({
|
||||
<div
|
||||
className={styles.options}
|
||||
role="radiogroup"
|
||||
style={{ gridTemplateColumns: `repeat(${options.length}, 1fr)` }}
|
||||
data-size={size}
|
||||
data-variant={variant}
|
||||
style={{
|
||||
gridTemplateColumns: `repeat(${options.length}, minmax(0, 1fr))`,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className={styles.indicator}
|
||||
|
||||
Reference in new issue
Block a user