@conscience-technology/ovenn 0.6.7 → 0.7.0
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/assets/components/AIMessage/AIMessage.module.css +2 -1
- package/assets/components/Accordion/Accordion.module.css +3 -0
- package/assets/components/AppFrame/AppFrame.module.css +2 -0
- package/assets/components/AttachmentItem/AttachmentItem.module.css +9 -3
- package/assets/components/AttachmentThumb/AttachmentThumb.module.css +4 -0
- package/assets/components/Avatar/Avatar.module.css +26 -11
- package/assets/components/Avatar/Avatar.tsx +1 -1
- package/assets/components/AvatarUpload/AvatarUpload.module.css +4 -3
- package/assets/components/Badge/Badge.module.css +96 -70
- package/assets/components/Badge/Badge.tsx +33 -25
- package/assets/components/Breadcrumb/Breadcrumb.module.css +8 -4
- package/assets/components/Breadcrumb/Breadcrumb.tsx +1 -1
- package/assets/components/Bubble/Bubble.module.css +6 -0
- package/assets/components/Button/Button.module.css +6 -0
- package/assets/components/Calendar/Calendar.module.css +244 -0
- package/assets/components/Calendar/Calendar.tsx +419 -0
- package/assets/components/Calendar/index.ts +2 -0
- package/assets/components/Callout/Callout.module.css +1 -0
- package/assets/components/Canvas/Canvas.module.css +75 -0
- package/assets/components/Canvas/Canvas.tsx +699 -0
- package/assets/components/Canvas/alignment.ts +34 -0
- package/assets/components/Canvas/clipboard.ts +30 -0
- package/assets/components/Canvas/collision.ts +67 -0
- package/assets/components/Canvas/edgeOptions.ts +11 -0
- package/assets/components/Canvas/graph.ts +11 -0
- package/assets/components/Canvas/history.ts +41 -0
- package/assets/components/Canvas/index.ts +4 -0
- package/assets/components/Canvas/selection.ts +56 -0
- package/assets/components/Canvas/tokens.css +61 -0
- package/assets/components/Canvas/types.ts +27 -0
- package/assets/components/Canvas/useCanvasSettlement.ts +79 -0
- package/assets/components/CanvasEdge/CanvasEdge.module.css +62 -0
- package/assets/components/CanvasEdge/CanvasEdge.tsx +121 -0
- package/assets/components/CanvasEdge/geometry.ts +350 -0
- package/assets/components/CanvasEdge/index.ts +4 -0
- package/assets/components/CanvasEdge/interactions.ts +14 -0
- package/assets/components/CanvasEdge/tokens.css +29 -0
- package/assets/components/CanvasNode/CanvasNode.module.css +234 -30
- package/assets/components/CanvasNode/CanvasNode.tsx +95 -28
- package/assets/components/CanvasNode/index.ts +1 -1
- package/assets/components/CanvasNode/runningOutline.ts +59 -0
- package/assets/components/CanvasNode/tokens.css +76 -13
- package/assets/components/Card/Card.module.css +5 -0
- package/assets/components/Chart/Chart.module.css +278 -0
- package/assets/components/Chart/Chart.tsx +385 -0
- package/assets/components/Chart/entrance.tsx +57 -0
- package/assets/components/Chart/index.ts +14 -0
- package/assets/components/ChatInput/ChatInput.module.css +5 -0
- package/assets/components/Checkbox/Checkbox.module.css +39 -0
- package/assets/components/Checkbox/Checkbox.tsx +99 -14
- package/assets/components/Checkbox/index.ts +1 -1
- package/assets/components/CheckboxCard/CheckboxCard.module.css +1 -177
- package/assets/components/CheckboxCard/CheckboxCard.tsx +6 -72
- package/assets/components/Chip/Chip.module.css +20 -30
- package/assets/components/Code/Code.module.css +1 -0
- package/assets/components/CodeBlock/CodeBlock.module.css +7 -3
- package/assets/components/ColorArea/ColorArea.module.css +3 -0
- package/assets/components/ColorField/ColorField.module.css +6 -0
- package/assets/components/ColorField/ColorField.tsx +3 -1
- package/assets/components/ColorPicker/ColorPicker.module.css +310 -0
- package/assets/components/ColorPicker/ColorPicker.tsx +387 -0
- package/assets/components/ColorPicker/index.ts +16 -0
- package/assets/components/ColorSlider/ColorSlider.module.css +15 -12
- package/assets/components/ColorSlider/ColorSlider.tsx +3 -3
- package/assets/components/ColorSwatch/ColorSwatch.module.css +2 -2
- package/assets/components/ColorSwatchPicker/ColorSwatchPicker.module.css +4 -3
- package/assets/components/Combobox/Combobox.module.css +1 -1
- package/assets/components/Combobox/Combobox.tsx +1 -1
- package/assets/components/CommandPalette/CommandPalette.module.css +18 -23
- package/assets/components/CommandPalette/CommandPalette.tsx +7 -5
- package/assets/components/Comment/Comment.module.css +25 -0
- package/assets/components/Comment/Comment.tsx +44 -0
- package/assets/components/Comment/CommentComposer.module.css +26 -0
- package/assets/components/Comment/CommentComposer.tsx +56 -0
- package/assets/components/Comment/CommentEditor.module.css +8 -0
- package/assets/components/Comment/CommentEditor.tsx +43 -0
- package/assets/components/Comment/CommentMentionInput.module.css +9 -0
- package/assets/components/Comment/CommentMentionInput.tsx +150 -0
- package/assets/components/Comment/index.ts +9 -0
- package/assets/components/Comment/types.ts +1 -0
- package/assets/components/ContextMenu/ContextMenu.module.css +5 -2
- package/assets/components/ContextMenu/ContextMenu.tsx +5 -0
- package/assets/components/ControlGroup/ControlGroup.module.css +7 -1
- package/assets/components/DataTable/DataTable.module.css +2 -0
- package/assets/components/DatePicker/DatePicker.module.css +36 -3
- package/assets/components/DatePicker/DatePicker.tsx +11 -1
- package/assets/components/DatePicker/TimeSelector.tsx +1 -1
- package/assets/components/Disclosure/Disclosure.module.css +1 -0
- package/assets/components/Drawer/Drawer.module.css +11 -4
- package/assets/components/Drawer/Drawer.tsx +5 -1
- package/assets/components/DropdownMenu/DropdownMenu.tsx +5 -0
- package/assets/components/EventChip/EventChip.module.css +120 -53
- package/assets/components/EventChip/EventChip.tsx +54 -6
- package/assets/components/EventChip/index.ts +1 -1
- package/assets/components/EventListItem/EventListItem.module.css +3 -0
- package/assets/components/EventListItem/EventListItem.tsx +15 -8
- package/assets/components/FileIcon/FileIcon.module.css +2 -0
- package/assets/components/FileUpload/FileUpload.module.css +10 -3
- package/assets/components/FileUpload/FileUpload.tsx +5 -9
- package/assets/components/FileUpload/FileUploadItem.tsx +34 -0
- package/assets/components/GalleryItem/GalleryItem.module.css +16 -19
- package/assets/components/GeneratedImage/GeneratedImage.module.css +2 -0
- package/assets/components/Icon/Icon.tsx +264 -1088
- package/assets/components/Icon/LucideFamilyIcon.tsx +434 -0
- package/assets/components/Icon/MissingIcon.tsx +25 -0
- package/assets/components/Icon/SolarFamilyIcon.tsx +439 -0
- package/assets/components/Icon/catalogNames.ts +8 -0
- package/assets/components/Icon/context.tsx +1 -1
- package/assets/components/Icon/index.ts +2 -0
- package/assets/components/Icon/lucideCatalog.ts +11358 -0
- package/assets/components/Icon/phosphorCatalog.ts +3052 -0
- package/assets/components/Icon/solarCatalog.ts +16064 -0
- package/assets/components/IconButton/IconButton.module.css +3 -2
- package/assets/components/Input/Input.module.css +30 -12
- package/assets/components/Input/Input.tsx +1 -1
- package/assets/components/Kanban/Kanban.module.css +6 -0
- package/assets/components/ListItem/ListItem.module.css +9 -6
- package/assets/components/MenuItem/MenuItem.module.css +24 -22
- package/assets/components/MenuItem/MenuItem.tsx +12 -12
- package/assets/components/MessageActions/MessageActions.module.css +36 -0
- package/assets/components/MessageActions/MessageActions.tsx +53 -28
- package/assets/components/MessageQuote/MessageQuote.module.css +1 -0
- package/assets/components/MessageSources/MessageSources.module.css +2 -0
- package/assets/components/MessageState/MessageState.module.css +1 -1
- package/assets/components/MetricCard/MetricCard.module.css +96 -108
- package/assets/components/MetricCard/MetricCard.tsx +45 -23
- package/assets/components/MetricCard/tokens.css +10 -0
- package/assets/components/MiniCalendar/MiniCalendar.module.css +130 -0
- package/assets/components/MiniCalendar/MiniCalendar.tsx +161 -0
- package/assets/components/MiniCalendar/index.ts +2 -0
- package/assets/components/Modal/Modal.module.css +13 -4
- package/assets/components/Modal/Modal.tsx +4 -0
- package/assets/components/Onboarding/LayoutBuilder.tsx +12 -50
- package/assets/components/Onboarding/Onboarding.module.css +211 -278
- package/assets/components/Onboarding/OnboardingAxisPanel.tsx +81 -125
- package/assets/components/Onboarding/OnboardingPage.tsx +244 -467
- package/assets/components/Onboarding/actions.ts +5 -0
- package/assets/components/Onboarding/palette.css +8 -0
- package/assets/components/Onboarding/wizardData.ts +8 -8
- package/assets/components/ProgressBar/ProgressBar.module.css +8 -8
- package/assets/components/ProgressBar/ProgressBar.tsx +0 -5
- package/assets/components/ProgressBar/index.ts +0 -1
- package/assets/components/QuotationBar/QuotationBar.module.css +2 -0
- package/assets/components/Radio/Radio.module.css +2 -0
- package/assets/components/RadioCard/RadioCard.module.css +78 -3
- package/assets/components/RadioCard/RadioCard.tsx +34 -12
- package/assets/components/RadioCard/index.ts +1 -1
- package/assets/components/SegmentedChart/SegmentedChart.module.css +16 -0
- package/assets/components/SegmentedChart/SegmentedChart.tsx +25 -8
- package/assets/components/Select/Select.tsx +7 -4
- package/assets/components/Shortcut/Shortcut.module.css +2 -0
- package/assets/components/Sidebar/Sidebar.module.css +1 -0
- package/assets/components/Sidebar/Sidebar.tsx +2 -2
- package/assets/components/Skeleton/Skeleton.module.css +33 -0
- package/assets/components/Skeleton/Skeleton.tsx +20 -0
- package/assets/components/Skeleton/index.ts +2 -0
- package/assets/components/Skeleton/tokens.css +11 -0
- package/assets/components/Slider/Slider.module.css +3 -0
- package/assets/components/Slider/Slider.tsx +7 -2
- package/assets/components/Spinner/LottiePlayer.tsx +4 -4
- package/assets/components/Spinner/Spinner.module.css +3 -0
- package/assets/components/Spinner/lottieManifest.ts +3 -0
- package/assets/components/Stepper/Stepper.module.css +56 -8
- package/assets/components/Stepper/Stepper.tsx +13 -4
- package/assets/components/Switch/Switch.module.css +55 -42
- package/assets/components/Switch/Switch.tsx +6 -2
- package/assets/components/Switch/index.ts +1 -1
- package/assets/components/TabStrip/TabStrip.module.css +5 -1
- package/assets/components/TableCell/TableCell.module.css +8 -1
- package/assets/components/TableCell/TableCellBadge.tsx +7 -3
- package/assets/components/TableCell/TableCellImage.tsx +1 -1
- package/assets/components/TableCell/TableCellTag.tsx +23 -0
- package/assets/components/TableCell/index.ts +3 -0
- package/assets/components/TableHeader/TableHeader.module.css +4 -0
- package/assets/components/TableRow/TableRow.module.css +3 -0
- package/assets/components/TableRowEdit/TableRowEdit.module.css +2 -0
- package/assets/components/TableToolbar/TableToolbar.module.css +1 -0
- package/assets/components/Tabs/Tabs.module.css +22 -7
- package/assets/components/Tabs/Tabs.tsx +2 -1
- package/assets/components/Tag/Tag.module.css +101 -0
- package/assets/components/Tag/Tag.tsx +55 -0
- package/assets/components/Tag/index.ts +2 -0
- package/assets/components/TemplateBoundary/TemplateBoundary.tsx +22 -18
- package/assets/components/TemplateBoundary/types.ts +2 -0
- package/assets/components/Textarea/Textarea.module.css +7 -0
- package/assets/components/ThemeController.tsx +30 -3
- package/assets/components/TimePicker/TimePicker.module.css +1 -0
- package/assets/components/TimePicker/TimePicker.tsx +37 -16
- package/assets/components/TimelineView/TimelineEventBar.tsx +109 -0
- package/assets/components/TimelineView/TimelineView.module.css +203 -0
- package/assets/components/TimelineView/TimelineView.tsx +137 -0
- package/assets/components/TimelineView/axis.ts +62 -0
- package/assets/components/TimelineView/index.ts +3 -0
- package/assets/components/TimelineView/layout.ts +56 -0
- package/assets/components/TimelineView/move.ts +51 -0
- package/assets/components/TimelineView/useTimelineDrag.ts +215 -0
- package/assets/components/TimelineView/useTimelineZoom.ts +92 -0
- package/assets/components/Toast/Toast.module.css +2 -0
- package/assets/components/Toolbar/Toolbar.module.css +31 -24
- package/assets/components/Toolbar/Toolbar.tsx +4 -3
- package/assets/components/Tooltip/Tooltip.module.css +10 -0
- package/assets/components/Tooltip/Tooltip.tsx +17 -8
- package/assets/components/TopLoader/TopLoader.module.css +1 -0
- package/assets/components/TreeNav/TreeNav.module.css +1 -0
- package/assets/components/_color.ts +2 -2
- package/assets/components/_data.ts +33 -32
- package/assets/components/_utils.css +5 -0
- package/assets/components/axisOptions.ts +2 -0
- package/assets/components/component-registry.json +151 -2
- package/assets/components/index.ts +16 -0
- package/assets/components/materialScope.tsx +11 -0
- package/assets/components/reset.css +1 -0
- package/assets/components/themeBootScript.ts +3 -2
- package/assets/components/tokens.css +225 -71
- package/assets/components/useChartEntrance.ts +119 -0
- package/assets/prompts/ASSEMBLY.md +9 -7
- package/assets/prompts/CATALOG.md +18 -4
- package/assets/prompts/FEEDBACK_PROCESS.md +19 -0
- package/assets/prompts/PRINCIPLES.md +14 -0
- package/assets/prompts/WORKFLOW_DESIGN.md +46 -70
- package/assets/prompts/axes/font.md +6 -1
- package/assets/prompts/axes/icon.md +6 -4
- package/assets/prompts/axes/material.md +40 -0
- package/assets/prompts/axes/palette.md +2 -1
- package/assets/prompts/axes/shape.md +8 -0
- package/assets/prompts/components/attachment-item.md +2 -1
- package/assets/prompts/components/badge.md +32 -97
- package/assets/prompts/components/breadcrumb.md +1 -0
- package/assets/prompts/components/calendar.md +151 -0
- package/assets/prompts/components/canvas-edge.md +67 -0
- package/assets/prompts/components/canvas-node.md +25 -8
- package/assets/prompts/components/canvas.md +82 -0
- package/assets/prompts/components/card.md +10 -10
- package/assets/prompts/components/chart-bar.md +77 -0
- package/assets/prompts/components/chart-pie.md +63 -0
- package/assets/prompts/components/chart-radar.md +56 -0
- package/assets/prompts/components/chart-radial.md +56 -0
- package/assets/prompts/components/chart.md +129 -0
- package/assets/prompts/components/checkbox-card.md +26 -45
- package/assets/prompts/components/checkbox.md +23 -0
- package/assets/prompts/components/chip.md +6 -6
- package/assets/prompts/components/code-block.md +1 -0
- package/assets/prompts/components/color-picker.md +173 -0
- package/assets/prompts/components/color-slider.md +7 -7
- package/assets/prompts/components/command-palette.md +7 -6
- package/assets/prompts/components/comment.md +72 -0
- package/assets/prompts/components/context-menu.md +6 -3
- package/assets/prompts/components/data-table.md +9 -0
- package/assets/prompts/components/date-picker.md +10 -0
- package/assets/prompts/components/drawer.md +10 -0
- package/assets/prompts/components/dropdown-menu.md +3 -1
- package/assets/prompts/components/event-chip.md +60 -18
- package/assets/prompts/components/event-list-item.md +14 -10
- package/assets/prompts/components/file-upload.md +1 -1
- package/assets/prompts/components/gallery-item.md +5 -4
- package/assets/prompts/components/icon.md +30 -8
- package/assets/prompts/components/kanban.md +1 -1
- package/assets/prompts/components/list-item.md +11 -2
- package/assets/prompts/components/menu-item.md +8 -3
- package/assets/prompts/components/message-actions.md +9 -0
- package/assets/prompts/components/metric-card.md +57 -109
- package/assets/prompts/components/mini-calendar.md +72 -0
- package/assets/prompts/components/modal.md +1 -0
- package/assets/prompts/components/onboarding.md +11 -7
- package/assets/prompts/components/page-header.md +11 -2
- package/assets/prompts/components/progress-bar.md +12 -2
- package/assets/prompts/components/radio-card.md +33 -117
- package/assets/prompts/components/segmented-chart.md +19 -5
- package/assets/prompts/components/select.md +1 -0
- package/assets/prompts/components/sidebar.md +12 -3
- package/assets/prompts/components/skeleton.md +44 -0
- package/assets/prompts/components/stepper.md +15 -1
- package/assets/prompts/components/switch.md +15 -10
- package/assets/prompts/components/tab-strip.md +1 -0
- package/assets/prompts/components/table-cell.md +6 -4
- package/assets/prompts/components/table-row.md +12 -3
- package/assets/prompts/components/table-toolbar.md +9 -0
- package/assets/prompts/components/tabs.md +4 -2
- package/assets/prompts/components/tag.md +54 -0
- package/assets/prompts/components/time-picker.md +1 -0
- package/assets/prompts/components/timeline-view.md +129 -0
- package/assets/prompts/components/toast.md +1 -1
- package/assets/prompts/components/toolbar.md +17 -4
- package/assets/prompts/components/tooltip.md +21 -3
- package/assets/prompts/components/top-loader.md +1 -1
- package/assets/prompts/components/topbar.md +9 -0
- package/assets/prompts/components/tree-nav.md +1 -1
- package/assets/prompts/templates/ains.md +2 -1
- package/assets/prompts/templates/aurora.md +5 -4
- package/assets/prompts/templates/glass-button.md +6 -5
- package/assets/prompts/templates/minimal.md +8 -6
- package/assets/prompts/templates/workspace.md +3 -3
- package/assets/prompts/tokens/color.md +4 -2
- package/assets/prompts/tokens/material.md +51 -0
- package/assets/prompts/tokens/radius.md +12 -0
- package/assets/prompts/tokens/typography.md +24 -2
- package/assets/prompts/use-cases/chart-chart-area.md +1334 -0
- package/assets/prompts/use-cases/chart-chart-bar.md +1886 -0
- package/assets/prompts/use-cases/chart-chart-pie.md +1031 -0
- package/assets/prompts/use-cases/chart-chart-radar.md +785 -0
- package/assets/prompts/use-cases/chart-chart-radial.md +988 -0
- package/assets/prompts/use-cases/chart-segmented-chart.md +262 -0
- package/assets/prompts/use-cases/data-comment.md +360 -0
- package/assets/prompts/use-cases/data-data-table.md +249 -0
- package/assets/prompts/use-cases/data-list-item.md +1056 -0
- package/assets/prompts/use-cases/data-metric-card.md +673 -0
- package/assets/prompts/use-cases/data-table-row.md +966 -0
- package/assets/prompts/use-cases/data-table-toolbar.md +481 -0
- package/assets/prompts/use-cases/feedback-drawer.md +1163 -0
- package/assets/prompts/use-cases/feedback-progress-bar.md +427 -0
- package/assets/prompts/use-cases/general-toolbar.md +854 -0
- package/assets/prompts/use-cases/general-tooltip.md +652 -0
- package/assets/prompts/use-cases/input-checkbox.md +443 -0
- package/assets/prompts/use-cases/structure-card.md +603 -0
- package/assets/prompts/use-cases/structure-page-header.md +755 -0
- package/assets/prompts/use-cases/structure-sidebar.md +1132 -0
- package/assets/prompts/use-cases/structure-topbar.md +1200 -0
- package/assets/public/ovenn-wordmark.svg +19 -0
- package/package.json +6 -2
- package/src/commands/info.js +1 -1
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as Recharts from "recharts";
|
|
5
|
+
import styles from "./Chart.module.css";
|
|
6
|
+
import { useChartEntrance } from "../useChartEntrance";
|
|
7
|
+
import { chartEntrance } from "./entrance";
|
|
8
|
+
|
|
9
|
+
/* ────────────────────────────────────────────────────────────
|
|
10
|
+
Chart — Recharts 어댑터.
|
|
11
|
+
shadcn 패턴을 Ovenn 토큰 체계에 맞게 포팅.
|
|
12
|
+
- config의 color 값은 var(--chart-N) 또는 var(--primary) 등 토큰 경유
|
|
13
|
+
- ChartStyle이 config의 color를 --color-{key}로 주입
|
|
14
|
+
- 다크 테마는 data-mode="dark" 아래 선택자로 자동 반응 (ChartStyle에서 light/dark 둘 다 생성)
|
|
15
|
+
──────────────────────────────────────────────────────────── */
|
|
16
|
+
|
|
17
|
+
const THEMES = { light: "", dark: '[data-mode="dark"]' } as const;
|
|
18
|
+
|
|
19
|
+
export type ChartConfig = Record<
|
|
20
|
+
string,
|
|
21
|
+
{
|
|
22
|
+
label?: React.ReactNode;
|
|
23
|
+
icon?: React.ComponentType;
|
|
24
|
+
} & (
|
|
25
|
+
| { color?: string; theme?: never }
|
|
26
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
27
|
+
)
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
type ChartContextValue = { config: ChartConfig };
|
|
31
|
+
const ChartContext = React.createContext<ChartContextValue | null>(null);
|
|
32
|
+
|
|
33
|
+
function useChart() {
|
|
34
|
+
const ctx = React.useContext(ChartContext);
|
|
35
|
+
if (!ctx) throw new Error("useChart must be used within <ChartContainer />");
|
|
36
|
+
return ctx;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* ChartContainer ─────────────────────────────────────────── */
|
|
40
|
+
|
|
41
|
+
export type ChartContainerProps = React.ComponentProps<"div"> & {
|
|
42
|
+
config: ChartConfig;
|
|
43
|
+
/** Animate plot geometry once when it first enters the viewport. */
|
|
44
|
+
animateIn?: boolean;
|
|
45
|
+
children: React.ComponentProps<typeof Recharts.ResponsiveContainer>["children"];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const ChartContainer = React.forwardRef<HTMLDivElement, ChartContainerProps>(
|
|
49
|
+
function ChartContainer({ id, className, children, config, animateIn = true, ...props }, ref) {
|
|
50
|
+
const root = React.useRef<HTMLDivElement>(null);
|
|
51
|
+
React.useImperativeHandle(ref, () => root.current!, []);
|
|
52
|
+
const entrance = useChartEntrance(root, animateIn);
|
|
53
|
+
const uniqueId = React.useId();
|
|
54
|
+
const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;
|
|
55
|
+
return (
|
|
56
|
+
<ChartContext.Provider value={{ config }}>
|
|
57
|
+
<div
|
|
58
|
+
ref={root}
|
|
59
|
+
data-entrance={entrance.phase}
|
|
60
|
+
data-entrance-duration={entrance.duration}
|
|
61
|
+
data-slot="chart"
|
|
62
|
+
data-chart={chartId}
|
|
63
|
+
className={[styles.root, className].filter(Boolean).join(" ")}
|
|
64
|
+
{...props}
|
|
65
|
+
>
|
|
66
|
+
<ChartStyle id={chartId} config={config} />
|
|
67
|
+
<Recharts.ResponsiveContainer>{chartEntrance(children, entrance) as React.ReactElement}</Recharts.ResponsiveContainer>
|
|
68
|
+
</div>
|
|
69
|
+
</ChartContext.Provider>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
/* ChartStyle ─ config → --color-{key} CSS 변수 주입 ─────── */
|
|
75
|
+
|
|
76
|
+
function ChartStyle({ id, config }: { id: string; config: ChartConfig }) {
|
|
77
|
+
const colorConfig = Object.entries(config).filter(([, c]) => c.theme ?? c.color);
|
|
78
|
+
if (!colorConfig.length) return null;
|
|
79
|
+
|
|
80
|
+
const css = Object.entries(THEMES)
|
|
81
|
+
.map(
|
|
82
|
+
([theme, prefix]) => `
|
|
83
|
+
${prefix} [data-chart=${id}] {
|
|
84
|
+
${colorConfig
|
|
85
|
+
.map(([key, item]) => {
|
|
86
|
+
const color = item.theme?.[theme as keyof typeof item.theme] ?? item.color;
|
|
87
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
88
|
+
})
|
|
89
|
+
.filter(Boolean)
|
|
90
|
+
.join("\n")}
|
|
91
|
+
}
|
|
92
|
+
`
|
|
93
|
+
)
|
|
94
|
+
.join("\n");
|
|
95
|
+
|
|
96
|
+
return <style dangerouslySetInnerHTML={{ __html: css }} />;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* ChartTooltip ───────────────────────────────────────────── */
|
|
100
|
+
/* Recharts.Tooltip의 기본 position animation(0.4s)이 커서 따라오는 느낌으로 어색해,
|
|
101
|
+
isAnimationActive=false로 끄고 Ovenn 모션 토큰 안쪽에서 처리. */
|
|
102
|
+
|
|
103
|
+
function ChartTooltip(
|
|
104
|
+
props: React.ComponentProps<typeof Recharts.Tooltip>
|
|
105
|
+
) {
|
|
106
|
+
return <Recharts.Tooltip isAnimationActive={false} cursor={{ strokeDasharray: "3 3" }} {...props} />;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type TooltipPayloadItem = {
|
|
110
|
+
value?: number | string;
|
|
111
|
+
name?: string;
|
|
112
|
+
dataKey?: string | number;
|
|
113
|
+
color?: string;
|
|
114
|
+
type?: string;
|
|
115
|
+
payload?: Record<string, unknown>;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export type ChartTooltipContentProps = {
|
|
119
|
+
active?: boolean;
|
|
120
|
+
payload?: TooltipPayloadItem[];
|
|
121
|
+
label?: string | number;
|
|
122
|
+
className?: string;
|
|
123
|
+
indicator?: "line" | "dot";
|
|
124
|
+
/** md: 기본. sm: 밀도가 승부처인 자리(테이블·대시보드) */
|
|
125
|
+
size?: "md" | "sm";
|
|
126
|
+
hideLabel?: boolean;
|
|
127
|
+
hideIndicator?: boolean;
|
|
128
|
+
nameKey?: string;
|
|
129
|
+
labelKey?: string;
|
|
130
|
+
labelClassName?: string;
|
|
131
|
+
labelFormatter?: (
|
|
132
|
+
value: React.ReactNode,
|
|
133
|
+
payload: TooltipPayloadItem[]
|
|
134
|
+
) => React.ReactNode;
|
|
135
|
+
formatter?: (
|
|
136
|
+
value: number | string | undefined,
|
|
137
|
+
name: string | undefined,
|
|
138
|
+
item: TooltipPayloadItem,
|
|
139
|
+
index: number,
|
|
140
|
+
payload: Record<string, unknown> | undefined
|
|
141
|
+
) => React.ReactNode;
|
|
142
|
+
color?: string;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
function ChartTooltipContent({
|
|
146
|
+
active,
|
|
147
|
+
payload,
|
|
148
|
+
label,
|
|
149
|
+
className,
|
|
150
|
+
indicator = "dot",
|
|
151
|
+
size = "md",
|
|
152
|
+
hideLabel = false,
|
|
153
|
+
hideIndicator = false,
|
|
154
|
+
nameKey,
|
|
155
|
+
labelKey,
|
|
156
|
+
labelClassName,
|
|
157
|
+
labelFormatter,
|
|
158
|
+
formatter,
|
|
159
|
+
color,
|
|
160
|
+
}: ChartTooltipContentProps) {
|
|
161
|
+
const { config } = useChart();
|
|
162
|
+
|
|
163
|
+
const tooltipLabel = React.useMemo(() => {
|
|
164
|
+
if (hideLabel || !payload?.length) return null;
|
|
165
|
+
const [item] = payload;
|
|
166
|
+
const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
|
|
167
|
+
const itemConfig = getPayloadConfig(config, item, key);
|
|
168
|
+
const value =
|
|
169
|
+
!labelKey && label != null
|
|
170
|
+
? (typeof label === "string" ? (config[label]?.label ?? label) : label)
|
|
171
|
+
: itemConfig?.label;
|
|
172
|
+
|
|
173
|
+
if (labelFormatter) {
|
|
174
|
+
return (
|
|
175
|
+
<div className={[styles.tooltipLabel, labelClassName].filter(Boolean).join(" ")}>
|
|
176
|
+
{labelFormatter(value, payload)}
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (!value) return null;
|
|
181
|
+
return (
|
|
182
|
+
<div className={[styles.tooltipLabel, labelClassName].filter(Boolean).join(" ")}>
|
|
183
|
+
{value}
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
|
|
187
|
+
|
|
188
|
+
if (!active || !payload?.length) return null;
|
|
189
|
+
|
|
190
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div className={[styles.tooltip, className].filter(Boolean).join(" ")} data-size={size}>
|
|
194
|
+
{!nestLabel ? tooltipLabel : null}
|
|
195
|
+
<div className={styles.tooltipItems}>
|
|
196
|
+
{payload
|
|
197
|
+
.filter((item) => item.type !== "none")
|
|
198
|
+
.map((item, index) => {
|
|
199
|
+
const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`;
|
|
200
|
+
const itemConfig = getPayloadConfig(config, item, key);
|
|
201
|
+
const indicatorColor =
|
|
202
|
+
color ?? (item.payload?.fill as string | undefined) ?? item.color;
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<div
|
|
206
|
+
key={index}
|
|
207
|
+
className={styles.tooltipItem}
|
|
208
|
+
data-indicator={indicator}
|
|
209
|
+
data-nest={nestLabel ? "true" : "false"}
|
|
210
|
+
>
|
|
211
|
+
{formatter && item.value !== undefined && item.name ? (
|
|
212
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
213
|
+
) : (
|
|
214
|
+
<>
|
|
215
|
+
{itemConfig?.icon ? (
|
|
216
|
+
<itemConfig.icon />
|
|
217
|
+
) : (
|
|
218
|
+
!hideIndicator && (
|
|
219
|
+
<span
|
|
220
|
+
className={styles.tooltipIndicator}
|
|
221
|
+
data-indicator={indicator}
|
|
222
|
+
style={
|
|
223
|
+
{
|
|
224
|
+
"--tooltip-indicator-color": indicatorColor,
|
|
225
|
+
} as React.CSSProperties
|
|
226
|
+
}
|
|
227
|
+
/>
|
|
228
|
+
)
|
|
229
|
+
)}
|
|
230
|
+
<div className={styles.tooltipRow}>
|
|
231
|
+
<div className={styles.tooltipRowLabel}>
|
|
232
|
+
{nestLabel ? tooltipLabel : null}
|
|
233
|
+
<span className={styles.tooltipName}>
|
|
234
|
+
{itemConfig?.label ?? item.name}
|
|
235
|
+
</span>
|
|
236
|
+
</div>
|
|
237
|
+
{item.value != null && (
|
|
238
|
+
<span className={styles.tooltipValue}>
|
|
239
|
+
{typeof item.value === "number"
|
|
240
|
+
? item.value.toLocaleString()
|
|
241
|
+
: String(item.value)}
|
|
242
|
+
</span>
|
|
243
|
+
)}
|
|
244
|
+
</div>
|
|
245
|
+
</>
|
|
246
|
+
)}
|
|
247
|
+
</div>
|
|
248
|
+
);
|
|
249
|
+
})}
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* ChartLegend ────────────────────────────────────────────── */
|
|
256
|
+
|
|
257
|
+
const ChartLegend = Recharts.Legend;
|
|
258
|
+
|
|
259
|
+
type LegendPayloadItem = {
|
|
260
|
+
value?: string | number;
|
|
261
|
+
color?: string;
|
|
262
|
+
dataKey?: string | number;
|
|
263
|
+
type?: string;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export type ChartLegendContentProps = {
|
|
267
|
+
payload?: LegendPayloadItem[];
|
|
268
|
+
verticalAlign?: "top" | "middle" | "bottom";
|
|
269
|
+
/** 수평 정렬. Recharts Legend `align` prop과 별개로 content 안에서 자체 정렬. */
|
|
270
|
+
align?: "left" | "center" | "right";
|
|
271
|
+
className?: string;
|
|
272
|
+
hideIcon?: boolean;
|
|
273
|
+
nameKey?: string;
|
|
274
|
+
/** 숨긴 series 집합. 클릭 토글용. 들어있으면 flag 흐려짐. */
|
|
275
|
+
hidden?: Set<string>;
|
|
276
|
+
/** 아이템 클릭 핸들러. 넘겨주면 각 아이템이 button이 됨. */
|
|
277
|
+
onItemClick?: (key: string) => void;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
function ChartLegendContent({
|
|
281
|
+
className,
|
|
282
|
+
hideIcon = false,
|
|
283
|
+
payload,
|
|
284
|
+
verticalAlign = "bottom",
|
|
285
|
+
align = "center",
|
|
286
|
+
nameKey,
|
|
287
|
+
hidden,
|
|
288
|
+
onItemClick,
|
|
289
|
+
}: ChartLegendContentProps) {
|
|
290
|
+
const { config } = useChart();
|
|
291
|
+
if (!payload?.length) return null;
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<div
|
|
295
|
+
className={[styles.legend, className].filter(Boolean).join(" ")}
|
|
296
|
+
data-align={verticalAlign === "top" ? "top" : "bottom"}
|
|
297
|
+
data-h-align={align}
|
|
298
|
+
>
|
|
299
|
+
{payload
|
|
300
|
+
.filter((item) => item.type !== "none")
|
|
301
|
+
.map((item, i) => {
|
|
302
|
+
const lookupKey = `${nameKey ?? item.dataKey ?? "value"}`;
|
|
303
|
+
const itemKey = getPayloadConfigKey(config, item, lookupKey);
|
|
304
|
+
const itemConfig = config[itemKey];
|
|
305
|
+
const isHidden = hidden?.has(itemKey) ?? false;
|
|
306
|
+
const commonProps = {
|
|
307
|
+
className: styles.legendItem,
|
|
308
|
+
"data-hidden": isHidden ? "true" : "false",
|
|
309
|
+
};
|
|
310
|
+
const inner = (
|
|
311
|
+
<>
|
|
312
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
313
|
+
<itemConfig.icon />
|
|
314
|
+
) : (
|
|
315
|
+
<span
|
|
316
|
+
className={styles.legendSwatch}
|
|
317
|
+
style={{ backgroundColor: item.color }}
|
|
318
|
+
/>
|
|
319
|
+
)}
|
|
320
|
+
{itemConfig?.label ?? item.value}
|
|
321
|
+
</>
|
|
322
|
+
);
|
|
323
|
+
if (onItemClick) {
|
|
324
|
+
return (
|
|
325
|
+
<button
|
|
326
|
+
key={i}
|
|
327
|
+
type="button"
|
|
328
|
+
{...commonProps}
|
|
329
|
+
onClick={() => onItemClick(itemKey)}
|
|
330
|
+
>
|
|
331
|
+
{inner}
|
|
332
|
+
</button>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
return (
|
|
336
|
+
<div key={i} {...commonProps}>
|
|
337
|
+
{inner}
|
|
338
|
+
</div>
|
|
339
|
+
);
|
|
340
|
+
})}
|
|
341
|
+
</div>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/* helpers ────────────────────────────────────────────────── */
|
|
346
|
+
|
|
347
|
+
function getPayloadConfig(
|
|
348
|
+
config: ChartConfig,
|
|
349
|
+
payload: unknown,
|
|
350
|
+
key: string
|
|
351
|
+
): ChartConfig[string] | undefined {
|
|
352
|
+
return config[getPayloadConfigKey(config, payload, key)] ?? config[key];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function getPayloadConfigKey(
|
|
356
|
+
config: ChartConfig,
|
|
357
|
+
payload: unknown,
|
|
358
|
+
key: string
|
|
359
|
+
): string {
|
|
360
|
+
if (typeof payload !== "object" || payload === null) return key;
|
|
361
|
+
const inner =
|
|
362
|
+
"payload" in payload &&
|
|
363
|
+
typeof (payload as { payload?: unknown }).payload === "object" &&
|
|
364
|
+
(payload as { payload?: unknown }).payload !== null
|
|
365
|
+
? ((payload as { payload: Record<string, unknown> }).payload)
|
|
366
|
+
: undefined;
|
|
367
|
+
|
|
368
|
+
let configKey: string = key;
|
|
369
|
+
const p = payload as Record<string, unknown>;
|
|
370
|
+
if (key in p && typeof p[key] === "string") {
|
|
371
|
+
configKey = p[key] as string;
|
|
372
|
+
} else if (inner && key in inner && typeof inner[key] === "string") {
|
|
373
|
+
configKey = inner[key] as string;
|
|
374
|
+
}
|
|
375
|
+
return configKey in config ? configKey : key;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export {
|
|
379
|
+
ChartContainer,
|
|
380
|
+
ChartStyle,
|
|
381
|
+
ChartTooltip,
|
|
382
|
+
ChartTooltipContent,
|
|
383
|
+
ChartLegend,
|
|
384
|
+
ChartLegendContent,
|
|
385
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Area, Bar, Line, Pie, Radar, RadialBar } from "recharts";
|
|
3
|
+
import type { EntrancePhase } from "../useChartEntrance";
|
|
4
|
+
|
|
5
|
+
const primitives = new Set<unknown>([Area, Bar, Line, Pie, Radar, RadialBar]);
|
|
6
|
+
type Props = Record<string, unknown> & { children?: React.ReactNode };
|
|
7
|
+
type Motion = {
|
|
8
|
+
phase: EntrancePhase;
|
|
9
|
+
hasStarted: boolean;
|
|
10
|
+
duration: number;
|
|
11
|
+
easing: (t: number) => number;
|
|
12
|
+
seriesComplete: (id: string, expected: number) => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Traverse JSX, not component output. Recharts roots, fragments and SVG children retain their identity. */
|
|
16
|
+
export function chartEntrance(children: React.ReactNode, motion: Motion): React.ReactNode {
|
|
17
|
+
const ids: string[] = [];
|
|
18
|
+
const collect = (nodes: React.ReactNode, prefix: string) => React.Children.forEach(nodes, (node, index) => {
|
|
19
|
+
if (!React.isValidElement<Props>(node)) return;
|
|
20
|
+
const id = `${prefix}/${node.key ?? index}`;
|
|
21
|
+
if (primitives.has(node.type) && !node.props.hide) ids.push(id);
|
|
22
|
+
if (node.props.children) collect(node.props.children, id);
|
|
23
|
+
});
|
|
24
|
+
collect(children, "plot");
|
|
25
|
+
const bounded = (t: number) => Math.max(0, Math.min(1, motion.easing(t)));
|
|
26
|
+
const entered = motion.hasStarted;
|
|
27
|
+
const visit = (nodes: React.ReactNode, prefix: string): React.ReactNode => React.Children.map(nodes, (node, index) => {
|
|
28
|
+
if (!React.isValidElement<Props>(node)) return node;
|
|
29
|
+
const id = `${prefix}/${node.key ?? index}`;
|
|
30
|
+
const props: Props = {};
|
|
31
|
+
if (node.props.children) props.children = visit(node.props.children, id);
|
|
32
|
+
if (primitives.has(node.type)) {
|
|
33
|
+
// Keep this key after completion, so user selection/focus is never reset a second time.
|
|
34
|
+
props.key = `${id}/${entered ? "entered" : "initial"}`;
|
|
35
|
+
if (node.type === Pie && node.props.startAngle == null && node.props.endAngle == null) {
|
|
36
|
+
props.startAngle = 90;
|
|
37
|
+
props.endAngle = -270;
|
|
38
|
+
}
|
|
39
|
+
if (motion.phase === "running") {
|
|
40
|
+
props.isAnimationActive = true;
|
|
41
|
+
props.animationBegin = 0;
|
|
42
|
+
props.animationDuration = motion.duration;
|
|
43
|
+
props.animationEasing = node.type === Bar || node.type === Radar ? motion.easing : bounded;
|
|
44
|
+
props.onAnimationEnd = () => {
|
|
45
|
+
if (typeof node.props.onAnimationEnd === "function") node.props.onAnimationEnd();
|
|
46
|
+
motion.seriesComplete(id, ids.length);
|
|
47
|
+
};
|
|
48
|
+
} else if (motion.phase === "pending" || motion.phase === "off") {
|
|
49
|
+
props.isAnimationActive = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return React.cloneElement(node, props);
|
|
53
|
+
});
|
|
54
|
+
const result = visit(children, "plot");
|
|
55
|
+
// ResponsiveContainer requires one chart element, not a one-element array.
|
|
56
|
+
return React.isValidElement(children) && Array.isArray(result) ? result[0] : result;
|
|
57
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ChartContainer,
|
|
3
|
+
ChartStyle,
|
|
4
|
+
ChartTooltip,
|
|
5
|
+
ChartTooltipContent,
|
|
6
|
+
ChartLegend,
|
|
7
|
+
ChartLegendContent,
|
|
8
|
+
} from "./Chart";
|
|
9
|
+
export type {
|
|
10
|
+
ChartConfig,
|
|
11
|
+
ChartContainerProps,
|
|
12
|
+
ChartTooltipContentProps,
|
|
13
|
+
ChartLegendContentProps,
|
|
14
|
+
} from "./Chart";
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
gap: 0;
|
|
9
9
|
background: var(--bg);
|
|
10
10
|
border: var(--hairline) solid var(--border);
|
|
11
|
+
corner-shape: var(--corner-shape);
|
|
11
12
|
border-radius: var(--radius-xl);
|
|
12
13
|
box-shadow: var(--shadow-md);
|
|
13
14
|
transition: var(--transition-colors), var(--transition-ring);
|
|
@@ -30,6 +31,7 @@
|
|
|
30
31
|
(바깥 shell이 focus signal을 책임지는 자리이거나 입력이 늘 활성인 맥락). */
|
|
31
32
|
.variant-flush {
|
|
32
33
|
border: 0;
|
|
34
|
+
corner-shape: var(--corner-shape);
|
|
33
35
|
border-radius: 0;
|
|
34
36
|
box-shadow: none;
|
|
35
37
|
}
|
|
@@ -212,6 +214,7 @@
|
|
|
212
214
|
border: 0;
|
|
213
215
|
background: transparent;
|
|
214
216
|
color: var(--fg-muted);
|
|
217
|
+
corner-shape: var(--corner-shape);
|
|
215
218
|
border-radius: var(--radius-sm);
|
|
216
219
|
cursor: pointer;
|
|
217
220
|
width: var(--size-8);
|
|
@@ -252,6 +255,7 @@
|
|
|
252
255
|
border: 0;
|
|
253
256
|
background: transparent;
|
|
254
257
|
color: var(--fg-muted);
|
|
258
|
+
corner-shape: var(--corner-shape);
|
|
255
259
|
border-radius: var(--radius-sm);
|
|
256
260
|
cursor: pointer;
|
|
257
261
|
font: inherit;
|
|
@@ -297,6 +301,7 @@
|
|
|
297
301
|
border: 0;
|
|
298
302
|
background: transparent;
|
|
299
303
|
color: var(--fg-muted);
|
|
304
|
+
corner-shape: var(--corner-shape);
|
|
300
305
|
border-radius: var(--radius-sm);
|
|
301
306
|
cursor: pointer;
|
|
302
307
|
width: var(--size-8);
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
width: var(--size-4);
|
|
48
48
|
height: var(--size-4);
|
|
49
49
|
margin-top: calc((var(--lh-base) - var(--size-4)) / 2);
|
|
50
|
+
corner-shape: var(--corner-shape-mini);
|
|
50
51
|
border-radius: var(--radius-checkbox);
|
|
51
52
|
border: 1px solid var(--border-strong);
|
|
52
53
|
background: var(--bg);
|
|
@@ -66,6 +67,7 @@
|
|
|
66
67
|
position: absolute;
|
|
67
68
|
inset: 0;
|
|
68
69
|
background: var(--selected-fg);
|
|
70
|
+
corner-shape: var(--corner-shape-mini);
|
|
69
71
|
border-radius: max(var(--radius-none), calc(var(--radius-checkbox) - var(--hairline)));
|
|
70
72
|
transform: scale(0.2);
|
|
71
73
|
opacity: 0;
|
|
@@ -145,3 +147,40 @@
|
|
|
145
147
|
border-color: var(--destructive);
|
|
146
148
|
color: var(--bg);
|
|
147
149
|
}
|
|
150
|
+
|
|
151
|
+
/* Task: strike first, then collapse the whole labelled item. */
|
|
152
|
+
.root[data-variant="task"] {
|
|
153
|
+
--checkbox-task-exit-scale: 0.96;
|
|
154
|
+
|
|
155
|
+
display: inline-grid;
|
|
156
|
+
grid-template-rows: 1fr;
|
|
157
|
+
min-width: 0;
|
|
158
|
+
max-width: 100%;
|
|
159
|
+
transform-origin: left center;
|
|
160
|
+
}
|
|
161
|
+
.root[hidden] { display: none; }
|
|
162
|
+
.taskClip { display: block; min-height: 0; overflow: hidden; }
|
|
163
|
+
.taskLine { display: flex; align-items: flex-start; gap: var(--space-2); min-width: 0; }
|
|
164
|
+
.taskText { min-width: 0; }
|
|
165
|
+
.root[data-task-checked] .taskText { color: var(--fg-subtle); text-decoration: line-through; }
|
|
166
|
+
.root[data-task-state="completing"] {
|
|
167
|
+
animation: checkboxTaskExit var(--duration-slower) var(--ease-in-out) var(--duration-slow) both;
|
|
168
|
+
pointer-events: none;
|
|
169
|
+
}
|
|
170
|
+
.root[data-task-state="completing"] .taskText {
|
|
171
|
+
text-decoration: none;
|
|
172
|
+
background-image: linear-gradient(currentColor, currentColor);
|
|
173
|
+
background-repeat: no-repeat;
|
|
174
|
+
background-position: left center;
|
|
175
|
+
background-size: 0% var(--hairline);
|
|
176
|
+
animation: checkboxTaskStrike var(--duration-slow) var(--ease-out) forwards;
|
|
177
|
+
}
|
|
178
|
+
@keyframes checkboxTaskStrike { to { background-size: 100% var(--hairline); } }
|
|
179
|
+
@keyframes checkboxTaskExit {
|
|
180
|
+
from { grid-template-rows: 1fr; opacity: 1; transform: scale(1); }
|
|
181
|
+
to { grid-template-rows: 0fr; opacity: 0; transform: translateX(var(--space-2)) scale(var(--checkbox-task-exit-scale)); }
|
|
182
|
+
}
|
|
183
|
+
@media (prefers-reduced-motion: reduce) {
|
|
184
|
+
.root[data-task-state="completing"],
|
|
185
|
+
.root[data-task-state="completing"] .taskText { animation: none; }
|
|
186
|
+
}
|
|
@@ -1,39 +1,124 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { forwardRef, type InputHTMLAttributes, type ReactNode } from "react";
|
|
3
|
+
import { forwardRef, useCallback, useEffect, useRef, useState, type InputHTMLAttributes, type ReactNode } from "react";
|
|
4
4
|
|
|
5
5
|
import { Icon } from "../Icon";
|
|
6
6
|
import styles from "./Checkbox.module.css";
|
|
7
7
|
|
|
8
|
+
export type CheckboxVariant = "default" | "task";
|
|
9
|
+
|
|
8
10
|
export type CheckboxProps = Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> & {
|
|
9
11
|
children?: ReactNode;
|
|
10
12
|
/** 폼 검증 실패. border·checked bg가 destructive 톤으로 전환. */
|
|
11
13
|
invalid?: boolean;
|
|
14
|
+
/** task: 완료 시 취소선을 그린 뒤 항목을 접어 숨긴다. */
|
|
15
|
+
variant?: CheckboxVariant;
|
|
16
|
+
/** task 완료 모션 종료 후 호출. 호스트는 이때 항목을 제거할 수 있다. */
|
|
17
|
+
onComplete?: () => void;
|
|
12
18
|
};
|
|
13
19
|
|
|
14
20
|
const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
|
15
|
-
({ className, disabled, invalid, children, ...rest }, ref) => {
|
|
21
|
+
({ className, disabled, invalid, children, variant = "default", onComplete, checked, defaultChecked, onChange, ...rest }, ref) => {
|
|
16
22
|
const rootClass = [styles.root, className ?? ""].filter(Boolean).join(" ");
|
|
23
|
+
const task = variant === "task";
|
|
24
|
+
const [localChecked, setLocalChecked] = useState(Boolean(defaultChecked));
|
|
25
|
+
const value = checked ?? localChecked;
|
|
26
|
+
const previous = useRef(Boolean(value));
|
|
27
|
+
const root = useRef<HTMLLabelElement>(null);
|
|
28
|
+
const input = useRef<HTMLInputElement>(null);
|
|
29
|
+
const inputRef = useCallback((node: HTMLInputElement | null) => {
|
|
30
|
+
input.current = node;
|
|
31
|
+
if (typeof ref === "function") {
|
|
32
|
+
const cleanup: unknown = ref(node);
|
|
33
|
+
if (typeof cleanup === "function") return () => { input.current = null; cleanup(); };
|
|
34
|
+
} else if (ref) ref.current = node;
|
|
35
|
+
}, [ref]);
|
|
36
|
+
const pending = useRef(false);
|
|
37
|
+
const callback = useRef(onComplete);
|
|
38
|
+
callback.current = onComplete;
|
|
39
|
+
const [phase, setPhase] = useState<"idle" | "completing" | "hidden">("idle");
|
|
40
|
+
const finish = useCallback(() => {
|
|
41
|
+
if (!pending.current) return;
|
|
42
|
+
pending.current = false;
|
|
43
|
+
setPhase("hidden");
|
|
44
|
+
callback.current?.();
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const form = input.current?.form;
|
|
49
|
+
if (!task || checked !== undefined || !form) return;
|
|
50
|
+
let active = true;
|
|
51
|
+
const reset = (event: Event) => queueMicrotask(() => {
|
|
52
|
+
if (!active || event.defaultPrevented) return;
|
|
53
|
+
pending.current = false;
|
|
54
|
+
previous.current = Boolean(defaultChecked);
|
|
55
|
+
setLocalChecked(Boolean(defaultChecked));
|
|
56
|
+
setPhase("idle");
|
|
57
|
+
});
|
|
58
|
+
form.addEventListener("reset", reset);
|
|
59
|
+
return () => { active = false; form.removeEventListener("reset", reset); };
|
|
60
|
+
}, [task, checked, defaultChecked]);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!task || !value) {
|
|
64
|
+
pending.current = false;
|
|
65
|
+
setPhase("idle");
|
|
66
|
+
} else if (!previous.current) {
|
|
67
|
+
pending.current = true;
|
|
68
|
+
setPhase("completing");
|
|
69
|
+
}
|
|
70
|
+
previous.current = Boolean(value);
|
|
71
|
+
}, [task, value]);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (phase !== "completing" || !root.current) return;
|
|
75
|
+
const style = getComputedStyle(root.current);
|
|
76
|
+
if (matchMedia("(prefers-reduced-motion: reduce)").matches || Number.parseFloat(style.getPropertyValue("--motion-scale")) === 0) {
|
|
77
|
+
finish();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const milliseconds = (time: string) => Number.parseFloat(time) * (time.trim().endsWith("ms") ? 1 : 1000);
|
|
81
|
+
// Also finish when an animation is disabled or its end event is lost.
|
|
82
|
+
const timeout = window.setTimeout(finish, (milliseconds(style.animationDuration) || 0) + (milliseconds(style.animationDelay) || 0));
|
|
83
|
+
return () => window.clearTimeout(timeout);
|
|
84
|
+
}, [phase, finish]);
|
|
85
|
+
|
|
86
|
+
const content = <>
|
|
87
|
+
<input
|
|
88
|
+
key={variant}
|
|
89
|
+
ref={inputRef}
|
|
90
|
+
type="checkbox"
|
|
91
|
+
className={`${styles.input} visually-hidden`}
|
|
92
|
+
disabled={disabled || (task && phase === "completing")}
|
|
93
|
+
aria-invalid={invalid || undefined}
|
|
94
|
+
{...rest}
|
|
95
|
+
checked={task ? value : checked}
|
|
96
|
+
defaultChecked={task ? undefined : defaultChecked}
|
|
97
|
+
onChange={event => {
|
|
98
|
+
if (task && checked === undefined) setLocalChecked(event.currentTarget.checked);
|
|
99
|
+
onChange?.(event);
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
<span data-slot="checkbox-indicator" className={styles.indicator} aria-hidden>
|
|
103
|
+
<Icon name="check" family="lucide" />
|
|
104
|
+
</span>
|
|
105
|
+
{children != null && <span data-slot="checkbox-label" className={task ? styles.taskText : undefined}>{children}</span>}
|
|
106
|
+
</>;
|
|
17
107
|
|
|
18
108
|
return (
|
|
19
109
|
<label
|
|
110
|
+
ref={root}
|
|
20
111
|
className={rootClass}
|
|
112
|
+
data-variant={variant}
|
|
113
|
+
data-task-state={task ? phase : undefined}
|
|
114
|
+
data-task-checked={task && value || undefined}
|
|
115
|
+
hidden={task && phase === "hidden"}
|
|
116
|
+
onAnimationEnd={event => { if (event.target === event.currentTarget) finish(); }}
|
|
21
117
|
data-disabled={disabled ? "true" : "false"}
|
|
22
118
|
data-invalid={invalid || undefined}
|
|
23
119
|
data-standalone={children == null || undefined}
|
|
24
120
|
>
|
|
25
|
-
<
|
|
26
|
-
ref={ref}
|
|
27
|
-
type="checkbox"
|
|
28
|
-
className={`${styles.input} visually-hidden`}
|
|
29
|
-
disabled={disabled}
|
|
30
|
-
aria-invalid={invalid || undefined}
|
|
31
|
-
{...rest}
|
|
32
|
-
/>
|
|
33
|
-
<span className={styles.indicator} aria-hidden>
|
|
34
|
-
<Icon name="check" family="lucide" />
|
|
35
|
-
</span>
|
|
36
|
-
{children != null && <span>{children}</span>}
|
|
121
|
+
{task ? <span data-slot="checkbox-task-clip" className={styles.taskClip}><span data-slot="checkbox-task-line" className={styles.taskLine}>{content}</span></span> : content}
|
|
37
122
|
</label>
|
|
38
123
|
);
|
|
39
124
|
},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Checkbox } from "./Checkbox";
|
|
2
|
-
export type { CheckboxProps } from "./Checkbox";
|
|
2
|
+
export type { CheckboxProps, CheckboxVariant } from "./Checkbox";
|