Files
Aislo/ui_template/ui_template_segment.ts
T
eomsangdonandClaude Opus 5.5 bfe27d0ad7 feat(848-3): 부품 「바뀜」 상태(나 = 파랑 굵은 선 · 위 = 주황 점선) · M02 문서 통째 「초기화」 — 수식 길 고침까지 걷음 · 확인창 목록
- ui_template 입력 · 고르기 · 단추 · 분할 고르기 = setUiDiff(data-diff) · 오류 · 포커스 선이 먼저 · 부품 모음 「바뀜 표시」 줄
- M02 머리 [M01 값으로] → [초기화] = 그 기초와 같게 · 옛 칸 + 따로 문서 · 끊은 부름 · 기계 고침(재생성 할일) · 미리 보기 답 목록
- 바탕 기초 없는 SK · 가져온 식 = 옛 칸만(지킬 줄 보존)
- 시험: test_848_3_reset_whole(임시 storage · 금액 = 처음) · 낡은 소스 글자 시험 둘 고침(804_7 단추 이름 줄 지움 · 552_2 부품 수 13 → 13 이상)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:29:12 +09:00

88 lines
3.5 KiB
TypeScript
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.
/* =============================================================================
* ui_template_segment.ts
* 부품 「분할 고르기」(552-2 · 부품 모음 `#/b01-account?view=ui-kit`) — 붙은 칸 둘 ~ 다섯 중 하나
*
* 꼴 = 글 · 아이콘(+ title) · 글 + 아이콘
* 크기 = data-size 20 · 24 · 28 · 32(기본 28)
* 줄 = 한 줄(기본) · `columns: 2` = 2 × 2 처럼 여러 줄 칸(긴 이름 넷 · 599-1 D03 긋기 방식)
* 풂 = `clearable: true` — 고른 칸을 다시 누르면 모두 풀림(`onChange("")` · 켬끔 고르기 · 589-9 긋기 방식 = 켜면 긋기 시작)
* 상태 = 마우스 `:hover` · 눌림 `:active` · 막힘 `disabled` · 고름 = aria-checked — CSS 는 `[data-state]` 로도 받음
* 바뀜 = `setUiDiff(root, "mine" | "upper")`(889 · 틀에)
* 쓰기 = `createSegment({ options: [{ value: "list", label: "목록" }, { value: "card", label: "카드" }], value: "list", onChange })`
* 대신 = B01 `.b01-sys-seg` · `.b01-home__seg` · `.b01-proj-seg` · B04 `b04-surface__sheet-method` · B05 `b05-routerec__pills` ·
* B06 `b06-design__btn(--active)` · CAD `.cad-inspector-tabs` · E04 · E06 · E07 `*-toggle` · M02 `m02-dfip__chips`
* ========================================================================== */
import { setUiSize, type UiSize } from "./ui_template_button";
import { icon, type IconName } from "./ui_template_icons";
import "./ui_template_segment.css";
export interface SegmentOption {
value: string;
label?: string;
icon?: IconName;
/** 아이콘만이면 필수 */
title?: string;
disabled?: boolean;
}
export interface SegmentHandle {
root: HTMLDivElement;
get: () => string;
/** 고름을 바꿈(onChange 는 안 부름) */
set: (value: string) => void;
}
export function createSegment(opts: {
options: SegmentOption[];
value: string;
onChange?: (value: string) => void;
/** 20 · 24 · 28 · 32 권함 */
size?: UiSize;
ariaLabel?: string;
/** 한 줄 칸 수 — 넘으면 다음 줄(없음 = 한 줄) */
columns?: number;
/** 고른 칸을 다시 누르면 풂 — `onChange("")` */
clearable?: boolean;
}): SegmentHandle {
const root = document.createElement("div");
root.className = "ui-segment";
root.setAttribute("role", "radiogroup");
if (opts.ariaLabel) root.setAttribute("aria-label", opts.ariaLabel);
setUiSize(root, opts.size ?? 28);
if (opts.columns) {
root.dataset.columns = String(opts.columns);
root.style.setProperty("--ui-segment-columns", String(opts.columns));
}
let current = opts.value;
const items = opts.options.map((o) => {
const b = document.createElement("button");
b.type = "button";
b.className = "ui-segment__item";
b.setAttribute("role", "radio");
b.dataset.value = o.value;
if (o.icon) b.append(icon(o.icon, 16));
if (o.label) b.append(o.label);
if (o.title) b.title = o.title;
if (o.title && !o.label) b.setAttribute("aria-label", o.title);
b.disabled = o.disabled ?? false;
b.addEventListener("click", () => {
if (current === o.value) {
if (!opts.clearable) return;
set("");
return opts.onChange?.("");
}
set(o.value);
opts.onChange?.(o.value);
});
return b;
});
const set = (value: string): void => {
current = value;
for (const b of items) b.setAttribute("aria-checked", String(b.dataset.value === value));
};
set(current);
root.append(...items);
return { root, get: () => current, set };
}