@sonamu-kit/react-components 0.4.9 → 0.4.10
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.
|
@@ -34,26 +34,35 @@ var s = a("inline-flex items-center justify-center gap-2 whitespace-nowrap round
|
|
|
34
34
|
variant: "default",
|
|
35
35
|
size: "default"
|
|
36
36
|
}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
});
|
|
38
|
+
function c(e) {
|
|
39
|
+
let t = [], i = [], a = () => {
|
|
40
|
+
let e = i.join("");
|
|
41
|
+
e.trim() !== "" && t.push(/* @__PURE__ */ r("span", { children: e }, `text-${t.length}`)), i = [];
|
|
42
|
+
};
|
|
43
|
+
for (let r of n.Children.toArray(e)) n.isValidElement(r) ? (a(), t.push(r)) : i.push(r);
|
|
44
|
+
return a(), t;
|
|
45
|
+
}
|
|
46
|
+
var l = n.forwardRef(({ className: a, variant: l, size: u, icon: d, children: f, loading: p, disabled: m, asChild: h = !1, ...g }, _) => {
|
|
47
|
+
let v = h ? o : "button", y = n.Children.count(f) === 0, b = p ? /* @__PURE__ */ r(t, { className: "animate-spin" }) : d, x = h ? f : c(f);
|
|
48
|
+
return /* @__PURE__ */ r(v, {
|
|
40
49
|
"data-slot": "button",
|
|
41
50
|
className: e(s({
|
|
42
|
-
variant:
|
|
43
|
-
size:
|
|
51
|
+
variant: l,
|
|
52
|
+
size: u,
|
|
44
53
|
className: a
|
|
45
54
|
})),
|
|
46
|
-
ref:
|
|
47
|
-
disabled:
|
|
48
|
-
...
|
|
49
|
-
children:
|
|
55
|
+
ref: _,
|
|
56
|
+
disabled: m || p,
|
|
57
|
+
...g,
|
|
58
|
+
children: y ? b : b ? /* @__PURE__ */ i("span", {
|
|
50
59
|
className: "contents",
|
|
51
|
-
children: [
|
|
52
|
-
}) :
|
|
60
|
+
children: [b, x]
|
|
61
|
+
}) : x
|
|
53
62
|
});
|
|
54
63
|
});
|
|
55
|
-
|
|
64
|
+
l.displayName = "Button";
|
|
56
65
|
//#endregion
|
|
57
|
-
export {
|
|
66
|
+
export { l as Button, s as buttonVariants };
|
|
58
67
|
|
|
59
68
|
//# sourceMappingURL=button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","names":[],"sources":["../../../src/components/ui/button.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport { cva } from \"class-variance-authority\";\nimport { type VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\nimport LoaderIcon from \"~icons/lucide/loader-2\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst buttonVariantsConfig = {\n variant: {\n // semantic variants (shadcn/ui 기본)\n default: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n destructive:\n \"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60\",\n outline:\n \"border bg-background text-foreground hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50\",\n secondary: \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n ghost: \"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50\",\n link: \"text-primary underline-offset-4 hover:underline\",\n\n // solid color variants\n red: \"bg-red-500 text-white hover:bg-red-600\",\n yellow: \"bg-yellow-500 text-white hover:bg-yellow-600\",\n green: \"bg-green-500 text-white hover:bg-green-600\",\n blue: \"bg-blue-500 text-white hover:bg-blue-600\",\n cyan: \"bg-cyan-500 text-white hover:bg-cyan-600\",\n purple: \"bg-purple-500 text-white hover:bg-purple-600\",\n pink: \"bg-pink-500 text-white hover:bg-pink-600\",\n orange: \"bg-orange-500 text-white hover:bg-orange-600\",\n },\n size: {\n // button sizes\n // - 아이콘만 있는 버튼: 정사각형 (px-0 aspect-square)\n // - 텍스트 / 아이콘 + 텍스트 버튼: 일반 패딩 유지 (가로 자동 확장)\n xs: \"h-6 px-2 py-1 text-xs [&_svg]:size-3 has-[>svg]:px-1.5 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n sm: \"h-7 px-3 py-1.5 text-xs [&_svg]:size-3.5 has-[>svg]:px-2 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n default:\n \"h-9 px-4 py-2 [&_svg]:size-4 has-[>svg]:px-3 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n lg: \"h-11 px-6 py-3 text-base [&_svg]:size-5 has-[>svg]:px-4 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n xl: \"h-13 px-8 py-4 text-lg [&_svg]:size-6 has-[>svg]:px-6 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n },\n} as const;\n\nconst buttonVariants = cva(\n \"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-button text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive cursor-pointer\",\n {\n variants: buttonVariantsConfig,\n defaultVariants: {\n variant: \"default\",\n size: \"default\",\n },\n },\n);\n\ntype ButtonProps = React.ComponentProps<\"button\"> &\n VariantProps<typeof buttonVariants> & {\n asChild?: boolean;\n icon?: React.ReactElement;\n loading?: boolean;\n };\n\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n (\n { className, variant, size, icon, children, loading, disabled, asChild = false, ...props },\n ref,\n ) => {\n const Comp = asChild ? Slot : \"button\";\n\n const iconOnly = React.Children.count(children) === 0;\n\n const leadingIcon = loading ? <LoaderIcon className=\"animate-spin\" /> : icon;\n\n return (\n <Comp\n data-slot=\"button\"\n className={cn(buttonVariants({ variant, size, className }))}\n ref={ref}\n disabled={disabled || loading}\n {...props}\n >\n {iconOnly ? (\n leadingIcon\n ) : leadingIcon ? (\n <span className=\"contents\">\n {leadingIcon}\n {
|
|
1
|
+
{"version":3,"file":"button.js","names":[],"sources":["../../../src/components/ui/button.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport { cva } from \"class-variance-authority\";\nimport { type VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\nimport LoaderIcon from \"~icons/lucide/loader-2\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst buttonVariantsConfig = {\n variant: {\n // semantic variants (shadcn/ui 기본)\n default: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n destructive:\n \"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60\",\n outline:\n \"border bg-background text-foreground hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50\",\n secondary: \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n ghost: \"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50\",\n link: \"text-primary underline-offset-4 hover:underline\",\n\n // solid color variants\n red: \"bg-red-500 text-white hover:bg-red-600\",\n yellow: \"bg-yellow-500 text-white hover:bg-yellow-600\",\n green: \"bg-green-500 text-white hover:bg-green-600\",\n blue: \"bg-blue-500 text-white hover:bg-blue-600\",\n cyan: \"bg-cyan-500 text-white hover:bg-cyan-600\",\n purple: \"bg-purple-500 text-white hover:bg-purple-600\",\n pink: \"bg-pink-500 text-white hover:bg-pink-600\",\n orange: \"bg-orange-500 text-white hover:bg-orange-600\",\n },\n size: {\n // button sizes\n // - 아이콘만 있는 버튼: 정사각형 (px-0 aspect-square)\n // - 텍스트 / 아이콘 + 텍스트 버튼: 일반 패딩 유지 (가로 자동 확장)\n // `:only-child`는 텍스트 노드를 세지 않으므로, Button이 글자를 span으로 감싸 이 판정을 맞춥니다(wrapText).\n xs: \"h-6 px-2 py-1 text-xs [&_svg]:size-3 has-[>svg]:px-1.5 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n sm: \"h-7 px-3 py-1.5 text-xs [&_svg]:size-3.5 has-[>svg]:px-2 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n default:\n \"h-9 px-4 py-2 [&_svg]:size-4 has-[>svg]:px-3 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n lg: \"h-11 px-6 py-3 text-base [&_svg]:size-5 has-[>svg]:px-4 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n xl: \"h-13 px-8 py-4 text-lg [&_svg]:size-6 has-[>svg]:px-6 has-[>svg:only-child]:px-0 has-[>svg:only-child]:aspect-square\",\n },\n} as const;\n\nconst buttonVariants = cva(\n \"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-button text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive cursor-pointer\",\n {\n variants: buttonVariantsConfig,\n defaultVariants: {\n variant: \"default\",\n size: \"default\",\n },\n },\n);\n\ntype ButtonProps = React.ComponentProps<\"button\"> &\n VariantProps<typeof buttonVariants> & {\n asChild?: boolean;\n icon?: React.ReactElement;\n loading?: boolean;\n };\n\n/**\n * 이어진 글자(문자열·숫자) 자식을 span 하나로 묶습니다.\n *\n * 크기 variant는 `has-[>svg:only-child]`로 아이콘만 있는 버튼을 알아보는데, CSS `:only-child`는 텍스트 노드를 세지 않습니다.\n * 그래서 `<Button><PlusIcon />추가</Button>`이 아이콘 전용으로 판정되어 패딩 0·정사각형이 됩니다.\n * 글자를 요소로 만들어 주면 판정이 맞습니다.\n *\n * - 이어진 글자를 하나로 묶는 것은 브라우저가 이어진 텍스트 노드를 flex 항목 하나로 다루는 것과 같게 하려는 것입니다.\n * 조각마다 감싸면 `{label}{count}` 사이에 gap이 끼어듭니다.\n * - 공백뿐인 글자는 flex 컨테이너가 원래 그리지 않으므로 버립니다. 감싸면 그 자리에 gap이 생깁니다.\n * - 이미 `<span>`으로 감싼 글자는 요소라서 건드리지 않습니다.\n *\n * shadcn처럼 자동 판정을 없애고 `size=\"icon\"`을 두는 쪽이 더 단순하지만, 아이콘 전용 버튼을 쓰는 모든 앱을 고쳐야 하는\n * 깨지는 변경이라 이 방법을 택했습니다(SON-554).\n */\nfunction wrapText(children: React.ReactNode): React.ReactNode {\n const nodes: React.ReactNode[] = [];\n let text: React.ReactNode[] = [];\n const flush = () => {\n const joined = text.join(\"\");\n if (joined.trim() !== \"\") {\n nodes.push(<span key={`text-${nodes.length}`}>{joined}</span>);\n }\n text = [];\n };\n\n for (const child of React.Children.toArray(children)) {\n // toArray가 null·boolean을 걸러 내므로, 요소가 아니면 글자(문자열·숫자)입니다.\n if (React.isValidElement(child)) {\n flush();\n nodes.push(child);\n } else {\n text.push(child);\n }\n }\n flush();\n\n return nodes;\n}\n\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n (\n { className, variant, size, icon, children, loading, disabled, asChild = false, ...props },\n ref,\n ) => {\n const Comp = asChild ? Slot : \"button\";\n\n const iconOnly = React.Children.count(children) === 0;\n\n const leadingIcon = loading ? <LoaderIcon className=\"animate-spin\" /> : icon;\n // asChild는 Slot에 자식 하나를 그대로 넘겨야 하므로 감싸지 않습니다.\n const content = asChild ? children : wrapText(children);\n\n return (\n <Comp\n data-slot=\"button\"\n className={cn(buttonVariants({ variant, size, className }))}\n ref={ref}\n disabled={disabled || loading}\n {...props}\n >\n {iconOnly ? (\n leadingIcon\n ) : leadingIcon ? (\n <span className=\"contents\">\n {leadingIcon}\n {content}\n </span>\n ) : (\n content\n )}\n </Comp>\n );\n },\n);\nButton.displayName = \"Button\";\n\nexport { Button, buttonVariants, buttonVariantsConfig, type ButtonProps };\n"],"mappings":";;;;;;AA4CA,IAAM,IAAiB,EACrB,6aACA;CACE,UAAU;EAtCZ,SAAS;GAEP,SAAS;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AAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonamu-kit/react-components",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "CartaNova <dev@cartanova.ai>",
|
|
6
6
|
"repository": {
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
"dev": "vite",
|
|
133
133
|
"build": "vite build",
|
|
134
134
|
"lint": "oxlint src",
|
|
135
|
-
"test": "vitest run --config vitest.config.ts
|
|
135
|
+
"test": "vitest run --config vitest.config.ts",
|
|
136
136
|
"test:exports": "node --test tests/package-exports.test.mjs",
|
|
137
137
|
"preview": "vite preview",
|
|
138
138
|
"storybook": "storybook dev -p 6006",
|