Files
Aislo/ui_template/ui_template_segment.ts
T
eomsangdonandClaude Sonnet 5.5 52e6c866d9 feat(850-1): 「위 층에서 고침」 주황 점선 표시 걷음 — 내가 고친 것(파랑)만 테두리 · 풍선 · 층 · 초기화 그대로
- 화면이 위 층 출처를 테두리로 안 칠함(기계 제어 구역 · 작업량 묶음 · 기계 보기 · 옵션 · 공식 값 · 표 칸 · 식 글 · 수량 · 단위 · 비목 · 그룹 이름 · 자원 바꿈 · 줄 틀 · 되살림 단추)
- 부품 상자 `setUiDiff` = "mine" 만 · 위 꼴 CSS · 견본 줄 걷음
- 풍선(기초에서 바뀜 — 바꾸기 전 …) · 지도 · 출처 함수 · 되돌림([↶] 은 나 칸에만) 그대로 · 시험 단언 바뀜 없음(지도 시험은 지도 값을 봄)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 07:31:46 +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")`(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 };
}