sh-ui-cli 0.15.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/sh-ui.mjs +6 -0
- package/data/changelog/versions.json +366 -0
- package/data/registry/flutter/foundation/sh_ui_tokens.dart +385 -0
- package/data/registry/flutter/registry.json +336 -0
- package/data/registry/flutter/widgets/sh_ui_accordion.dart +255 -0
- package/data/registry/flutter/widgets/sh_ui_app_shell.dart +267 -0
- package/data/registry/flutter/widgets/sh_ui_avatar.dart +95 -0
- package/data/registry/flutter/widgets/sh_ui_badge.dart +82 -0
- package/data/registry/flutter/widgets/sh_ui_breadcrumb.dart +107 -0
- package/data/registry/flutter/widgets/sh_ui_button.dart +201 -0
- package/data/registry/flutter/widgets/sh_ui_card.dart +159 -0
- package/data/registry/flutter/widgets/sh_ui_carousel.dart +204 -0
- package/data/registry/flutter/widgets/sh_ui_checkbox.dart +154 -0
- package/data/registry/flutter/widgets/sh_ui_color_picker.dart +264 -0
- package/data/registry/flutter/widgets/sh_ui_combobox.dart +614 -0
- package/data/registry/flutter/widgets/sh_ui_context_menu.dart +71 -0
- package/data/registry/flutter/widgets/sh_ui_date_picker.dart +648 -0
- package/data/registry/flutter/widgets/sh_ui_dialog.dart +567 -0
- package/data/registry/flutter/widgets/sh_ui_dropdown_menu.dart +251 -0
- package/data/registry/flutter/widgets/sh_ui_file_upload.dart +200 -0
- package/data/registry/flutter/widgets/sh_ui_header.dart +488 -0
- package/data/registry/flutter/widgets/sh_ui_input.dart +664 -0
- package/data/registry/flutter/widgets/sh_ui_label.dart +145 -0
- package/data/registry/flutter/widgets/sh_ui_menubar.dart +98 -0
- package/data/registry/flutter/widgets/sh_ui_pagination.dart +276 -0
- package/data/registry/flutter/widgets/sh_ui_popover.dart +248 -0
- package/data/registry/flutter/widgets/sh_ui_progress.dart +47 -0
- package/data/registry/flutter/widgets/sh_ui_radio.dart +108 -0
- package/data/registry/flutter/widgets/sh_ui_select.dart +904 -0
- package/data/registry/flutter/widgets/sh_ui_separator.dart +42 -0
- package/data/registry/flutter/widgets/sh_ui_sidebar.dart +1116 -0
- package/data/registry/flutter/widgets/sh_ui_skeleton.dart +129 -0
- package/data/registry/flutter/widgets/sh_ui_slider.dart +147 -0
- package/data/registry/flutter/widgets/sh_ui_spinner.dart +56 -0
- package/data/registry/flutter/widgets/sh_ui_switch.dart +109 -0
- package/data/registry/flutter/widgets/sh_ui_tabs.dart +329 -0
- package/data/registry/flutter/widgets/sh_ui_textarea.dart +126 -0
- package/data/registry/flutter/widgets/sh_ui_toast.dart +362 -0
- package/data/registry/flutter/widgets/sh_ui_toggle.dart +229 -0
- package/data/registry/flutter/widgets/sh_ui_tooltip.dart +62 -0
- package/data/registry/react/components/accordion/index.tsx +85 -0
- package/data/registry/react/components/accordion/styles.css +94 -0
- package/data/registry/react/components/animations/animations.css +51 -0
- package/data/registry/react/components/avatar/index.tsx +75 -0
- package/data/registry/react/components/avatar/styles.css +36 -0
- package/data/registry/react/components/badge/index.tsx +42 -0
- package/data/registry/react/components/badge/styles.css +57 -0
- package/data/registry/react/components/base/base.css +102 -0
- package/data/registry/react/components/breadcrumb/index.tsx +154 -0
- package/data/registry/react/components/breadcrumb/styles.css +82 -0
- package/data/registry/react/components/breakpoints/breakpoints.css +17 -0
- package/data/registry/react/components/button/index.tsx +47 -0
- package/data/registry/react/components/button/styles.css +93 -0
- package/data/registry/react/components/card/index.tsx +86 -0
- package/data/registry/react/components/card/styles.css +73 -0
- package/data/registry/react/components/carousel/index.tsx +432 -0
- package/data/registry/react/components/carousel/styles.css +155 -0
- package/data/registry/react/components/checkbox/index.tsx +98 -0
- package/data/registry/react/components/checkbox/styles.css +75 -0
- package/data/registry/react/components/code-panel/copy.tsx +56 -0
- package/data/registry/react/components/code-panel/index.tsx +193 -0
- package/data/registry/react/components/code-panel/styles.css +124 -0
- package/data/registry/react/components/color-picker/index.tsx +466 -0
- package/data/registry/react/components/color-picker/styles.css +166 -0
- package/data/registry/react/components/combobox/index.tsx +167 -0
- package/data/registry/react/components/combobox/styles.css +151 -0
- package/data/registry/react/components/context-menu/index.tsx +253 -0
- package/data/registry/react/components/context-menu/styles.css +140 -0
- package/data/registry/react/components/date-picker/index.tsx +757 -0
- package/data/registry/react/components/date-picker/styles.css +279 -0
- package/data/registry/react/components/dialog/index.tsx +97 -0
- package/data/registry/react/components/dialog/styles.css +127 -0
- package/data/registry/react/components/dropdown-menu/index.tsx +257 -0
- package/data/registry/react/components/dropdown-menu/styles.css +150 -0
- package/data/registry/react/components/file-upload/index.tsx +489 -0
- package/data/registry/react/components/file-upload/styles.css +170 -0
- package/data/registry/react/components/focus-ring/focus-ring.css +23 -0
- package/data/registry/react/components/form/context.ts +92 -0
- package/data/registry/react/components/form/field.test.tsx +230 -0
- package/data/registry/react/components/form/field.tsx +236 -0
- package/data/registry/react/components/form/focus-first-error.ts +54 -0
- package/data/registry/react/components/form/form.section.test.tsx +58 -0
- package/data/registry/react/components/form/form.test.tsx +146 -0
- package/data/registry/react/components/form/form.tsx +180 -0
- package/data/registry/react/components/form/index.tsx +61 -0
- package/data/registry/react/components/form/steps.test.tsx +106 -0
- package/data/registry/react/components/form/steps.tsx +193 -0
- package/data/registry/react/components/form/store.test.ts +206 -0
- package/data/registry/react/components/form/store.ts +318 -0
- package/data/registry/react/components/form/styles.css +47 -0
- package/data/registry/react/components/form/types.ts +104 -0
- package/data/registry/react/components/form/use-sh-ui-form.ts +15 -0
- package/data/registry/react/components/form/utils.test.ts +44 -0
- package/data/registry/react/components/form/utils.ts +49 -0
- package/data/registry/react/components/form/validation.test.ts +67 -0
- package/data/registry/react/components/form/validation.ts +64 -0
- package/data/registry/react/components/form-rhf/README.md +27 -0
- package/data/registry/react/components/form-rhf/index.tsx +289 -0
- package/data/registry/react/components/form-rhf/rhf.test.tsx +42 -0
- package/data/registry/react/components/form-tanstack/README.md +27 -0
- package/data/registry/react/components/form-tanstack/index.tsx +352 -0
- package/data/registry/react/components/form-tanstack/tanstack.test.tsx +45 -0
- package/data/registry/react/components/form-yup/README.md +22 -0
- package/data/registry/react/components/form-yup/index.tsx +50 -0
- package/data/registry/react/components/form-yup/yup.test.ts +27 -0
- package/data/registry/react/components/header/index.tsx +257 -0
- package/data/registry/react/components/header/styles.css +190 -0
- package/data/registry/react/components/input/index.tsx +517 -0
- package/data/registry/react/components/input/styles.css +203 -0
- package/data/registry/react/components/label/index.tsx +54 -0
- package/data/registry/react/components/label/styles.css +90 -0
- package/data/registry/react/components/menubar/index.tsx +34 -0
- package/data/registry/react/components/menubar/styles.css +45 -0
- package/data/registry/react/components/pagination/index.tsx +271 -0
- package/data/registry/react/components/pagination/styles.css +105 -0
- package/data/registry/react/components/popover/index.tsx +115 -0
- package/data/registry/react/components/popover/styles.css +65 -0
- package/data/registry/react/components/progress/index.tsx +56 -0
- package/data/registry/react/components/progress/styles.css +41 -0
- package/data/registry/react/components/radio/index.tsx +67 -0
- package/data/registry/react/components/radio/styles.css +80 -0
- package/data/registry/react/components/select/index.tsx +236 -0
- package/data/registry/react/components/select/styles.css +193 -0
- package/data/registry/react/components/separator/index.tsx +48 -0
- package/data/registry/react/components/separator/styles.css +15 -0
- package/data/registry/react/components/sidebar/index.tsx +1084 -0
- package/data/registry/react/components/sidebar/styles.css +502 -0
- package/data/registry/react/components/skeleton/index.tsx +24 -0
- package/data/registry/react/components/skeleton/styles.css +24 -0
- package/data/registry/react/components/slider/index.tsx +300 -0
- package/data/registry/react/components/slider/styles.css +64 -0
- package/data/registry/react/components/spinner/index.tsx +40 -0
- package/data/registry/react/components/spinner/styles.css +37 -0
- package/data/registry/react/components/switch/index.tsx +41 -0
- package/data/registry/react/components/switch/styles.css +83 -0
- package/data/registry/react/components/tabs/index.tsx +93 -0
- package/data/registry/react/components/tabs/styles.css +148 -0
- package/data/registry/react/components/textarea/index.tsx +25 -0
- package/data/registry/react/components/textarea/styles.css +54 -0
- package/data/registry/react/components/theme/index.tsx +91 -0
- package/data/registry/react/components/toast/index.tsx +257 -0
- package/data/registry/react/components/toast/styles.css +290 -0
- package/data/registry/react/components/toggle/index.tsx +133 -0
- package/data/registry/react/components/toggle/styles.css +85 -0
- package/data/registry/react/components/tooltip/index.tsx +85 -0
- package/data/registry/react/components/tooltip/styles.css +44 -0
- package/data/registry/react/components/z-index/z-index.css +16 -0
- package/data/registry/react/hooks/use-active-section.ts +104 -0
- package/data/registry/react/hooks/use-media-query.ts +27 -0
- package/data/registry/react/lib/cn.ts +39 -0
- package/data/registry/react/peer-versions.json +10 -0
- package/data/registry/react/registry.json +835 -0
- package/data/summaries/flutter.json +42 -0
- package/data/summaries/react.json +50 -0
- package/data/tokens/build.mjs +553 -0
- package/data/tokens/src/primitives.json +146 -0
- package/data/tokens/src/semantic.json +146 -0
- package/package.json +9 -2
- package/src/add.mjs +41 -15
- package/src/list.mjs +3 -11
- package/src/mcp.mjs +308 -0
- package/src/paths.mjs +59 -0
- package/src/remove.mjs +4 -11
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* ───────────── Checkbox ───────────── */
|
|
2
|
+
|
|
3
|
+
.sh-ui-checkbox {
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
width: 1.125rem;
|
|
8
|
+
height: 1.125rem;
|
|
9
|
+
border: 1px solid var(--border-strong);
|
|
10
|
+
border-radius: calc(var(--radius) - 2px);
|
|
11
|
+
background: var(--background);
|
|
12
|
+
color: var(--primary-foreground);
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
flex-shrink: 0;
|
|
15
|
+
transition: background-color var(--duration-fast), border-color var(--duration-fast);
|
|
16
|
+
-webkit-tap-highlight-color: transparent;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.sh-ui-checkbox:hover:not([data-disabled]) {
|
|
20
|
+
border-color: var(--foreground);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.sh-ui-checkbox:focus-visible {
|
|
24
|
+
outline: var(--border-width-strong) solid var(--foreground);
|
|
25
|
+
outline-offset: 2px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.sh-ui-checkbox[data-checked],
|
|
29
|
+
.sh-ui-checkbox[data-indeterminate] {
|
|
30
|
+
background: var(--primary);
|
|
31
|
+
border-color: var(--primary);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.sh-ui-checkbox[data-disabled] {
|
|
35
|
+
opacity: var(--opacity-disabled);
|
|
36
|
+
cursor: not-allowed;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* 모바일/터치: 최소 탭 영역 */
|
|
40
|
+
@media (hover: none) and (pointer: coarse) {
|
|
41
|
+
.sh-ui-checkbox {
|
|
42
|
+
width: 1.25rem;
|
|
43
|
+
height: 1.25rem;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* ───────────── Indicator ───────────── */
|
|
48
|
+
|
|
49
|
+
.sh-ui-checkbox__indicator {
|
|
50
|
+
display: inline-flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* ───────────── CheckboxGroup ───────────── */
|
|
56
|
+
|
|
57
|
+
.sh-ui-checkbox-group {
|
|
58
|
+
display: flex;
|
|
59
|
+
gap: 0.625rem;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.sh-ui-checkbox-group[data-orientation="vertical"] {
|
|
63
|
+
flex-direction: column;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.sh-ui-checkbox-group[data-orientation="horizontal"] {
|
|
67
|
+
flex-direction: row;
|
|
68
|
+
flex-wrap: wrap;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@media (prefers-reduced-motion: reduce) {
|
|
72
|
+
.sh-ui-checkbox {
|
|
73
|
+
transition: none;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
|
|
5
|
+
export function CodePanelCopyButton({ code }: { code: string }) {
|
|
6
|
+
const [copied, setCopied] = useState(false);
|
|
7
|
+
|
|
8
|
+
async function onClick() {
|
|
9
|
+
try {
|
|
10
|
+
await navigator.clipboard.writeText(code);
|
|
11
|
+
setCopied(true);
|
|
12
|
+
setTimeout(() => setCopied(false), 1500);
|
|
13
|
+
} catch {
|
|
14
|
+
// clipboard API 사용 불가 환경은 무시
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<button
|
|
20
|
+
type="button"
|
|
21
|
+
className="sh-ui-code__copy"
|
|
22
|
+
onClick={onClick}
|
|
23
|
+
aria-label="코드 복사"
|
|
24
|
+
>
|
|
25
|
+
{copied ? <CheckIcon /> : <CopyIcon />}
|
|
26
|
+
<span className="sh-ui-code__copy-label">{copied ? "복사됨" : "복사"}</span>
|
|
27
|
+
</button>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function CopyIcon() {
|
|
32
|
+
return (
|
|
33
|
+
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" aria-hidden>
|
|
34
|
+
<rect
|
|
35
|
+
x="5" y="5" width="8" height="8" rx="1.5"
|
|
36
|
+
stroke="currentColor" strokeWidth="1.5"
|
|
37
|
+
/>
|
|
38
|
+
<path
|
|
39
|
+
d="M10.5 5V3.5A1.5 1.5 0 0 0 9 2H4.5A1.5 1.5 0 0 0 3 3.5V8a1.5 1.5 0 0 0 1.5 1.5H5"
|
|
40
|
+
stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"
|
|
41
|
+
/>
|
|
42
|
+
</svg>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function CheckIcon() {
|
|
47
|
+
return (
|
|
48
|
+
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" aria-hidden>
|
|
49
|
+
<path
|
|
50
|
+
d="M3.5 8.5l3 3 6-7"
|
|
51
|
+
stroke="currentColor" strokeWidth="1.75"
|
|
52
|
+
strokeLinecap="round" strokeLinejoin="round"
|
|
53
|
+
/>
|
|
54
|
+
</svg>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { codeToHtml } from "shiki";
|
|
2
|
+
import { CodePanelCopyButton } from "./copy";
|
|
3
|
+
import "./styles.css";
|
|
4
|
+
|
|
5
|
+
function cx(...args: (string | undefined | false | null)[]) {
|
|
6
|
+
return args.filter(Boolean).join(" ");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CodePanelProps
|
|
10
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {
|
|
11
|
+
/** 하이라이팅할 코드 문자열. children을 제공하지 않을 때 필수. */
|
|
12
|
+
code?: string;
|
|
13
|
+
/**
|
|
14
|
+
* shiki가 지원하는 언어 ID (예: `"tsx"`, `"typescript"`, `"bash"`, `"json"`).
|
|
15
|
+
* 미지원 언어면 plain text로 폴백.
|
|
16
|
+
*
|
|
17
|
+
* @default "text"
|
|
18
|
+
*/
|
|
19
|
+
language?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 상단 헤더에 표시할 파일명. 지정하면 헤더가 그려지고 그 안에 복사 버튼이 들어가며,
|
|
22
|
+
* 미지정 시 우상단에 floating 복사 버튼만 표시된다.
|
|
23
|
+
*/
|
|
24
|
+
filename?: string;
|
|
25
|
+
/**
|
|
26
|
+
* 좌측 줄 번호 표시 여부.
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
showLineNumbers?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* 복사 버튼 숨기기. 코드 발췌가 클립보드 복사용이 아닐 때 사용.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
hideCopy?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* compound 모드. 직접 `CodePanelHeader`/`CodePanelFilename`/`CodePanelCopy`/`CodePanelBody`를
|
|
37
|
+
* 조합해 헤더 액션 추가나 복사 버튼 위치 변경 등을 한다. 지정 시 `code`/`language` 등은 무시.
|
|
38
|
+
*/
|
|
39
|
+
children?: React.ReactNode;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 코드 블록 + 복사 버튼 패널. shiki로 SSR에서 하이라이팅.
|
|
44
|
+
*
|
|
45
|
+
* 기본 사용(자식 생략) — `code` prop만 넘기면 기본 레이아웃을 렌더한다.
|
|
46
|
+
* 커스텀 구성 — `CodePanelHeader`, `CodePanelFilename`, `CodePanelCopy`,
|
|
47
|
+
* `CodePanelBody`를 직접 조합하여 헤더 액션 추가·복사 버튼 위치 변경 등이 가능하다.
|
|
48
|
+
*/
|
|
49
|
+
export async function CodePanel({
|
|
50
|
+
code,
|
|
51
|
+
language = "text",
|
|
52
|
+
filename,
|
|
53
|
+
showLineNumbers = true,
|
|
54
|
+
hideCopy,
|
|
55
|
+
className,
|
|
56
|
+
children,
|
|
57
|
+
...rest
|
|
58
|
+
}: CodePanelProps) {
|
|
59
|
+
const classes = cx("sh-ui-code", className);
|
|
60
|
+
|
|
61
|
+
if (children !== undefined) {
|
|
62
|
+
return (
|
|
63
|
+
<div className={classes} {...rest}>
|
|
64
|
+
{children}
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (code === undefined) {
|
|
70
|
+
throw new Error("CodePanel: `code` prop 또는 children 중 하나가 필요합니다.");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const trimmed = code.replace(/\n$/, "");
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div className={classes} {...rest}>
|
|
77
|
+
{filename ? (
|
|
78
|
+
<CodePanelHeader>
|
|
79
|
+
<CodePanelFilename>{filename}</CodePanelFilename>
|
|
80
|
+
{!hideCopy && <CodePanelCopy code={trimmed} />}
|
|
81
|
+
</CodePanelHeader>
|
|
82
|
+
) : (
|
|
83
|
+
!hideCopy && (
|
|
84
|
+
<div className="sh-ui-code__copy-floating">
|
|
85
|
+
<CodePanelCopy code={trimmed} />
|
|
86
|
+
</div>
|
|
87
|
+
)
|
|
88
|
+
)}
|
|
89
|
+
<CodePanelBody
|
|
90
|
+
code={trimmed}
|
|
91
|
+
language={language}
|
|
92
|
+
showLineNumbers={showLineNumbers}
|
|
93
|
+
/>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* ───────── CodePanelHeader ───────── */
|
|
99
|
+
|
|
100
|
+
/** 파일명·복사 버튼 등을 담는 코드 블록 상단 바. CodePanel 자식으로 사용. */
|
|
101
|
+
export function CodePanelHeader({
|
|
102
|
+
className,
|
|
103
|
+
children,
|
|
104
|
+
...props
|
|
105
|
+
}: React.HTMLAttributes<HTMLDivElement>) {
|
|
106
|
+
return (
|
|
107
|
+
<div className={cx("sh-ui-code__header", className)} {...props}>
|
|
108
|
+
{children}
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* ───────── CodePanelFilename ───────── */
|
|
114
|
+
|
|
115
|
+
/** CodePanelHeader 안에 표시되는 파일명 라벨. */
|
|
116
|
+
export function CodePanelFilename({
|
|
117
|
+
className,
|
|
118
|
+
children,
|
|
119
|
+
...props
|
|
120
|
+
}: React.HTMLAttributes<HTMLSpanElement>) {
|
|
121
|
+
return (
|
|
122
|
+
<span className={cx("sh-ui-code__filename", className)} {...props}>
|
|
123
|
+
{children}
|
|
124
|
+
</span>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/* ───────── CodePanelCopy ─────────
|
|
129
|
+
* 클립보드 복사 버튼. 내부적으로 client 컴포넌트를 사용한다.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
export interface CodePanelCopyProps {
|
|
133
|
+
/** 클립보드에 복사할 코드 문자열. 부모(주로 CodePanel)가 명시적으로 전달한다. */
|
|
134
|
+
code: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 클립보드 복사 버튼. 부모가 복사할 코드 문자열을 명시적으로 전달한다. */
|
|
138
|
+
export function CodePanelCopy({ code }: CodePanelCopyProps) {
|
|
139
|
+
return <CodePanelCopyButton code={code} />;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* ───────── CodePanelBody ─────────
|
|
143
|
+
* shiki로 코드를 하이라이팅하여 렌더하는 async 컴포넌트.
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
export interface CodePanelBodyProps
|
|
147
|
+
extends Omit<
|
|
148
|
+
React.HTMLAttributes<HTMLDivElement>,
|
|
149
|
+
"children" | "dangerouslySetInnerHTML"
|
|
150
|
+
> {
|
|
151
|
+
/** 하이라이팅할 코드 문자열. */
|
|
152
|
+
code: string;
|
|
153
|
+
/**
|
|
154
|
+
* shiki 언어 ID.
|
|
155
|
+
* @default "text"
|
|
156
|
+
*/
|
|
157
|
+
language?: string;
|
|
158
|
+
/**
|
|
159
|
+
* 좌측 줄 번호 표시 여부.
|
|
160
|
+
* @default true
|
|
161
|
+
*/
|
|
162
|
+
showLineNumbers?: boolean;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* shiki로 코드를 SSR 하이라이팅하여 렌더하는 async 컴포넌트.
|
|
167
|
+
* 라이트/다크 테마는 `github-light`/`github-dark`를 사용하며, 부모 테마 클래스에 따라 자동 전환된다.
|
|
168
|
+
*/
|
|
169
|
+
export async function CodePanelBody({
|
|
170
|
+
code,
|
|
171
|
+
language = "text",
|
|
172
|
+
showLineNumbers = true,
|
|
173
|
+
className,
|
|
174
|
+
...rest
|
|
175
|
+
}: CodePanelBodyProps) {
|
|
176
|
+
const trimmed = code.replace(/\n$/, "");
|
|
177
|
+
const html = await codeToHtml(trimmed, {
|
|
178
|
+
lang: language,
|
|
179
|
+
themes: { light: "github-light", dark: "github-dark" },
|
|
180
|
+
defaultColor: false,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div
|
|
185
|
+
className={cx("sh-ui-code__body", className)}
|
|
186
|
+
data-line-numbers={showLineNumbers || undefined}
|
|
187
|
+
dangerouslySetInnerHTML={{ __html: html }}
|
|
188
|
+
{...rest}
|
|
189
|
+
/>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { CodePanelCopyButton };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
.sh-ui-code {
|
|
2
|
+
position: relative;
|
|
3
|
+
border: 1px solid var(--border);
|
|
4
|
+
border-radius: var(--radius);
|
|
5
|
+
background: var(--background-subtle);
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
font-size: 0.8125rem;
|
|
8
|
+
line-height: 1.6;
|
|
9
|
+
margin: var(--space-4) 0;
|
|
10
|
+
}
|
|
11
|
+
@media (max-width: 640px) {
|
|
12
|
+
.sh-ui-code { font-size: var(--text-xs); }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* 헤더 (filename 있을 때) */
|
|
16
|
+
.sh-ui-code__header {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: space-between;
|
|
20
|
+
gap: var(--space-2);
|
|
21
|
+
padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
|
|
22
|
+
border-bottom: 1px solid var(--border);
|
|
23
|
+
background: var(--background-muted);
|
|
24
|
+
font-size: var(--text-xs);
|
|
25
|
+
color: var(--foreground-muted);
|
|
26
|
+
}
|
|
27
|
+
.sh-ui-code__filename {
|
|
28
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
29
|
+
color: var(--foreground);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* 헤더 없을 때 우상단에 떠있는 복사 버튼 */
|
|
33
|
+
.sh-ui-code__copy-floating {
|
|
34
|
+
position: absolute;
|
|
35
|
+
top: var(--space-2);
|
|
36
|
+
right: var(--space-2);
|
|
37
|
+
z-index: 1;
|
|
38
|
+
opacity: 0;
|
|
39
|
+
transition: opacity var(--duration-fast);
|
|
40
|
+
}
|
|
41
|
+
.sh-ui-code:hover .sh-ui-code__copy-floating,
|
|
42
|
+
.sh-ui-code:focus-within .sh-ui-code__copy-floating {
|
|
43
|
+
opacity: 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* 복사 버튼 */
|
|
47
|
+
.sh-ui-code__copy {
|
|
48
|
+
display: inline-flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: 0.375rem;
|
|
51
|
+
padding: var(--space-1) var(--space-2);
|
|
52
|
+
background: var(--background);
|
|
53
|
+
color: var(--foreground-muted);
|
|
54
|
+
border: 1px solid var(--border);
|
|
55
|
+
border-radius: calc(var(--radius) - 2px);
|
|
56
|
+
font-size: var(--text-xs);
|
|
57
|
+
line-height: 1;
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
transition: color var(--duration-fast), border-color var(--duration-fast), background-color var(--duration-fast);
|
|
60
|
+
-webkit-tap-highlight-color: transparent;
|
|
61
|
+
}
|
|
62
|
+
.sh-ui-code__copy:hover {
|
|
63
|
+
color: var(--foreground);
|
|
64
|
+
border-color: var(--border-strong);
|
|
65
|
+
}
|
|
66
|
+
.sh-ui-code__copy:focus-visible {
|
|
67
|
+
outline: var(--border-width-strong) solid var(--foreground);
|
|
68
|
+
outline-offset: 2px;
|
|
69
|
+
}
|
|
70
|
+
.sh-ui-code__copy-label {
|
|
71
|
+
font-size: var(--text-xs);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* 코드 본문 — shiki 출력(<pre class="shiki">...) */
|
|
75
|
+
.sh-ui-code__body {
|
|
76
|
+
overflow-x: auto;
|
|
77
|
+
}
|
|
78
|
+
.sh-ui-code__body pre {
|
|
79
|
+
margin: 0;
|
|
80
|
+
padding: var(--space-3) var(--space-4);
|
|
81
|
+
background: transparent !important;
|
|
82
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
83
|
+
font-size: inherit;
|
|
84
|
+
line-height: inherit;
|
|
85
|
+
border: none;
|
|
86
|
+
border-radius: 0;
|
|
87
|
+
}
|
|
88
|
+
.sh-ui-code__body code {
|
|
89
|
+
background: transparent;
|
|
90
|
+
padding: 0;
|
|
91
|
+
font-size: inherit;
|
|
92
|
+
display: block;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* shiki dual theme — 기본은 light, .dark 스코프에선 dark.
|
|
96
|
+
span에는 color만 주고 background-color는 절대 강제하지 않는다.
|
|
97
|
+
(강제하면 --shiki-*-bg 변수가 상속돼 라인마다 띠가 생긴다.) */
|
|
98
|
+
.sh-ui-code__body .shiki,
|
|
99
|
+
.sh-ui-code__body .shiki span {
|
|
100
|
+
color: var(--shiki-light) !important;
|
|
101
|
+
background-color: transparent !important;
|
|
102
|
+
}
|
|
103
|
+
.dark .sh-ui-code__body .shiki,
|
|
104
|
+
.dark .sh-ui-code__body .shiki span {
|
|
105
|
+
color: var(--shiki-dark) !important;
|
|
106
|
+
background-color: transparent !important;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* 라인 번호 */
|
|
110
|
+
.sh-ui-code__body[data-line-numbers] pre code {
|
|
111
|
+
counter-reset: step;
|
|
112
|
+
counter-increment: step 0;
|
|
113
|
+
}
|
|
114
|
+
.sh-ui-code__body[data-line-numbers] pre code .line::before {
|
|
115
|
+
content: counter(step);
|
|
116
|
+
counter-increment: step;
|
|
117
|
+
display: inline-block;
|
|
118
|
+
width: 1.75rem;
|
|
119
|
+
margin-right: var(--space-4);
|
|
120
|
+
text-align: right;
|
|
121
|
+
color: var(--foreground-muted);
|
|
122
|
+
opacity: 0.7;
|
|
123
|
+
user-select: none;
|
|
124
|
+
}
|