@jbpark/ui-kit 3.2.1 → 3.4.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/dist/Button.d.mts +12 -0
- package/dist/Button.d.mts.map +1 -1
- package/dist/Button.mjs +5 -2
- package/dist/Button.mjs.map +1 -1
- package/dist/components/atoms/checkbox/checkbox.d.mts +7 -3
- package/dist/components/atoms/checkbox/checkbox.d.mts.map +1 -1
- package/dist/components/atoms/checkbox/checkbox.mjs +17 -9
- package/dist/components/atoms/checkbox/checkbox.mjs.map +1 -1
- package/dist/components/atoms/checkbox/group.d.mts +8 -9
- package/dist/components/atoms/checkbox/group.d.mts.map +1 -1
- package/dist/components/atoms/checkbox/group.mjs +11 -12
- package/dist/components/atoms/checkbox/group.mjs.map +1 -1
- package/dist/components/atoms/color-picker.d.mts +6 -2
- package/dist/components/atoms/color-picker.d.mts.map +1 -1
- package/dist/components/atoms/color-picker.mjs +18 -10
- package/dist/components/atoms/color-picker.mjs.map +1 -1
- package/dist/components/atoms/date-picker.d.mts +2 -0
- package/dist/components/atoms/date-picker.d.mts.map +1 -1
- package/dist/components/atoms/date-picker.mjs +15 -9
- package/dist/components/atoms/date-picker.mjs.map +1 -1
- package/dist/components/atoms/float-button/back-top.d.mts +1 -0
- package/dist/components/atoms/float-button/back-top.d.mts.map +1 -1
- package/dist/components/atoms/float-button/back-top.mjs +11 -3
- package/dist/components/atoms/float-button/back-top.mjs.map +1 -1
- package/dist/components/atoms/input/input.d.mts +2 -1
- package/dist/components/atoms/input/input.d.mts.map +1 -1
- package/dist/components/atoms/input/input.mjs +5 -2
- package/dist/components/atoms/input/input.mjs.map +1 -1
- package/dist/components/atoms/input/search.d.mts +2 -0
- package/dist/components/atoms/input/search.d.mts.map +1 -1
- package/dist/components/atoms/input/search.mjs +9 -4
- package/dist/components/atoms/input/search.mjs.map +1 -1
- package/dist/components/atoms/option-group.d.mts +15 -0
- package/dist/components/atoms/option-group.d.mts.map +1 -0
- package/dist/components/atoms/option-group.mjs +9 -0
- package/dist/components/atoms/option-group.mjs.map +1 -0
- package/dist/components/atoms/popover.d.mts +6 -0
- package/dist/components/atoms/popover.d.mts.map +1 -1
- package/dist/components/atoms/popover.mjs +75 -160
- package/dist/components/atoms/popover.mjs.map +1 -1
- package/dist/components/atoms/radio/group.d.mts +6 -9
- package/dist/components/atoms/radio/group.d.mts.map +1 -1
- package/dist/components/atoms/radio/group.mjs +26 -23
- package/dist/components/atoms/radio/group.mjs.map +1 -1
- package/dist/components/atoms/radio/radio.d.mts +7 -3
- package/dist/components/atoms/radio/radio.d.mts.map +1 -1
- package/dist/components/atoms/radio/radio.mjs +18 -11
- package/dist/components/atoms/radio/radio.mjs.map +1 -1
- package/dist/components/atoms/select.d.mts +1 -1
- package/dist/components/atoms/select.d.mts.map +1 -1
- package/dist/components/atoms/select.mjs.map +1 -1
- package/dist/components/atoms/skeleton/button.mjs +2 -2
- package/dist/components/atoms/skeleton/button.mjs.map +1 -1
- package/dist/components/atoms/skeleton/skeleton.mjs +2 -2
- package/dist/components/atoms/skeleton/skeleton.mjs.map +1 -1
- package/dist/components/atoms/spin.d.mts +1 -2
- package/dist/components/atoms/spin.d.mts.map +1 -1
- package/dist/components/atoms/spin.mjs +12 -10
- package/dist/components/atoms/spin.mjs.map +1 -1
- package/dist/components/atoms/switch.d.mts.map +1 -1
- package/dist/components/atoms/switch.mjs +6 -8
- package/dist/components/atoms/switch.mjs.map +1 -1
- package/dist/components/organisms/index.d.mts +2 -1
- package/dist/components/organisms/toast.d.mts +41 -0
- package/dist/components/organisms/toast.d.mts.map +1 -0
- package/dist/components/organisms/toast.mjs +197 -0
- package/dist/components/organisms/toast.mjs.map +1 -0
- package/dist/core/badge.d.mts +1 -1
- package/dist/core/button.d.mts +2 -2
- package/dist/core/radio-group.d.mts +5 -1
- package/dist/core/radio-group.d.mts.map +1 -1
- package/dist/core/radio-group.mjs +7 -1
- package/dist/core/radio-group.mjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/style.css +40 -123
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.mjs","names":["input"],"sources":["../../../../src/components/atoms/input/input.tsx"],"sourcesContent":["import { input } from '@repo/ui/core';\n\nconst { Input: Core } = input;\n\nconst Input = ({ ...props }: React.
|
|
1
|
+
{"version":3,"file":"input.mjs","names":["input"],"sources":["../../../../src/components/atoms/input/input.tsx"],"sourcesContent":["import { input } from '@repo/ui/core';\n\nconst { Input: Core } = input;\n\nconst Input = ({ ref, ...props }: React.ComponentPropsWithRef<'input'>) => {\n return <Core ref={ref} {...props} />;\n};\n\nexport default Input;\n"],"mappings":";;;;AAEA,MAAM,EAAE,OAAO,SAASA;AAExB,MAAM,SAAS,EAAE,KAAK,GAAG,YAAkD;AACzE,QAAO,oBAAC;EAAU;EAAK,GAAI;GAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.mts","names":[],"sources":["../../../../src/components/atoms/input/search.tsx"],"mappings":";;;UAaiB,KAAA,SAAc,KAAA,CAAM,qBAAA;EACnC,UAAA;EACA,QAAA,IACE,CAAA,EAAG,KAAA,CAAM,WAAA,CAAY,gBAAA;IAAsB,MAAA;MAAU,KAAA;IAAA;EAAA;EAEvD,QAAA,IAAY,KAAA;AAAA;AAAA,cAGR,MAAA;EAAA
|
|
1
|
+
{"version":3,"file":"search.d.mts","names":[],"sources":["../../../../src/components/atoms/input/search.tsx"],"mappings":";;;UAaiB,KAAA,SAAc,KAAA,CAAM,qBAAA;EACnC,UAAA;EACA,QAAA,IACE,CAAA,EAAG,KAAA,CAAM,WAAA,CAAY,gBAAA;IAAsB,MAAA;MAAU,KAAA;IAAA;EAAA;EAEvD,QAAA,IAAY,KAAA;AAAA;AAAA,cAGR,MAAA;EAAA;;;;;;;;;;;KAWH,KAAA,GAAK,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -9,7 +9,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
9
9
|
|
|
10
10
|
//#region src/components/atoms/input/search.tsx
|
|
11
11
|
const { Input: Core } = input_exports;
|
|
12
|
-
const Search$1 = ({ ref, className, defaultValue, value, allowClear = true, onChange, onSearch: _onSearch, ...props }) => {
|
|
12
|
+
const Search$1 = ({ ref, className, defaultValue, value, disabled, allowClear = true, onChange, onKeyDown: _onKeyDown, onSearch: _onSearch, ...props }) => {
|
|
13
13
|
const inputRef = useRef(null);
|
|
14
14
|
const setRefs = (node) => {
|
|
15
15
|
inputRef.current = node;
|
|
@@ -27,6 +27,7 @@ const Search$1 = ({ ref, className, defaultValue, value, allowClear = true, onCh
|
|
|
27
27
|
onChange?.({ target: { value: "" } });
|
|
28
28
|
};
|
|
29
29
|
const onSearch = () => {
|
|
30
|
+
if (disabled) return;
|
|
30
31
|
if (inputRef.current) _onSearch?.(inputRef.current.value);
|
|
31
32
|
};
|
|
32
33
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -34,10 +35,12 @@ const Search$1 = ({ ref, className, defaultValue, value, allowClear = true, onCh
|
|
|
34
35
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
35
36
|
className: cn("relative grow", "inline-flex items-center"),
|
|
36
37
|
children: [/* @__PURE__ */ jsx(Core, {
|
|
38
|
+
...props,
|
|
37
39
|
ref: setRefs,
|
|
38
40
|
inputMode: "search",
|
|
39
41
|
type: "search",
|
|
40
42
|
enterKeyHint: "search",
|
|
43
|
+
disabled,
|
|
41
44
|
className: cn("rounded-r-none", "[&::-webkit-search-cancel-button]:hidden", "[&::-webkit-search-decoration]:hidden"),
|
|
42
45
|
value,
|
|
43
46
|
defaultValue,
|
|
@@ -46,18 +49,20 @@ const Search$1 = ({ ref, className, defaultValue, value, allowClear = true, onCh
|
|
|
46
49
|
onChange?.(e);
|
|
47
50
|
},
|
|
48
51
|
onKeyDown: (e) => {
|
|
52
|
+
_onKeyDown?.(e);
|
|
49
53
|
if (e.key === "Enter") onSearch();
|
|
50
|
-
}
|
|
51
|
-
...props
|
|
54
|
+
}
|
|
52
55
|
}), /* @__PURE__ */ jsx("button", {
|
|
53
56
|
type: "button",
|
|
54
57
|
"aria-label": "지우기",
|
|
55
|
-
|
|
58
|
+
disabled,
|
|
59
|
+
className: cn("absolute right-2", "shrink-0 cursor-pointer", "disabled:cursor-not-allowed disabled:opacity-50", (!allowClear || !hasValue) && "hidden"),
|
|
56
60
|
onClick: onClear,
|
|
57
61
|
children: /* @__PURE__ */ jsx(CircleX, { className: "size-4" })
|
|
58
62
|
})]
|
|
59
63
|
}), /* @__PURE__ */ jsx(Button, {
|
|
60
64
|
icon: /* @__PURE__ */ jsx(Search, {}),
|
|
65
|
+
disabled,
|
|
61
66
|
className: cn("rounded-l-none", "size-9"),
|
|
62
67
|
onClick: onSearch
|
|
63
68
|
})]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.mjs","names":["input","Search","SearchOutlined"],"sources":["../../../../src/components/atoms/input/search.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, useState } from 'react';\n\nimport { CircleX, Search as SearchOutlined } from 'lucide-react';\n\nimport { input } from '@repo/ui/core';\nimport { cn } from '@repo/ui/utils';\n\nimport Button from '../button';\n\nconst { Input: Core } = input;\n\nexport interface Props extends React.ComponentPropsWithRef<'input'> {\n allowClear?: boolean;\n onChange?: (\n e: React.ChangeEvent<HTMLInputElement> | { target: { value: string } },\n ) => void;\n onSearch?: (value: string) => void;\n}\n\nconst Search = ({\n ref,\n className,\n defaultValue,\n value,\n allowClear = true,\n onChange,\n onSearch: _onSearch,\n ...props\n}: Props) => {\n const inputRef = useRef<HTMLInputElement>(null);\n\n const setRefs = (node: HTMLInputElement | null) => {\n inputRef.current = node;\n\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n };\n\n const [uncontrolledHasValue, setUncontrolledHasValue] =\n useState(!!defaultValue);\n const hasValue = value !== undefined ? !!value : uncontrolledHasValue;\n\n const onClear = () => {\n if (!inputRef.current) {\n return;\n }\n\n if (value === undefined) {\n inputRef.current.value = '';\n setUncontrolledHasValue(false);\n }\n\n
|
|
1
|
+
{"version":3,"file":"search.mjs","names":["input","Search","SearchOutlined"],"sources":["../../../../src/components/atoms/input/search.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, useState } from 'react';\n\nimport { CircleX, Search as SearchOutlined } from 'lucide-react';\n\nimport { input } from '@repo/ui/core';\nimport { cn } from '@repo/ui/utils';\n\nimport Button from '../button';\n\nconst { Input: Core } = input;\n\nexport interface Props extends React.ComponentPropsWithRef<'input'> {\n allowClear?: boolean;\n onChange?: (\n e: React.ChangeEvent<HTMLInputElement> | { target: { value: string } },\n ) => void;\n onSearch?: (value: string) => void;\n}\n\nconst Search = ({\n ref,\n className,\n defaultValue,\n value,\n disabled,\n allowClear = true,\n onChange,\n onKeyDown: _onKeyDown,\n onSearch: _onSearch,\n ...props\n}: Props) => {\n const inputRef = useRef<HTMLInputElement>(null);\n\n const setRefs = (node: HTMLInputElement | null) => {\n inputRef.current = node;\n\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n };\n\n const [uncontrolledHasValue, setUncontrolledHasValue] =\n useState(!!defaultValue);\n const hasValue = value !== undefined ? !!value : uncontrolledHasValue;\n\n const onClear = () => {\n if (!inputRef.current) {\n return;\n }\n\n if (value === undefined) {\n inputRef.current.value = '';\n setUncontrolledHasValue(false);\n }\n\n onChange?.({ target: { value: '' } });\n };\n\n const onSearch = () => {\n if (disabled) {\n return;\n }\n if (inputRef.current) {\n _onSearch?.(inputRef.current.value);\n }\n };\n\n return (\n <div\n className={cn(\n 'flex items-center',\n 'rounded-md',\n className,\n //\n )}\n >\n <div\n className={cn(\n 'relative grow',\n 'inline-flex items-center',\n //\n )}\n >\n <Core\n {...props}\n ref={setRefs}\n inputMode=\"search\"\n type=\"search\"\n enterKeyHint=\"search\"\n disabled={disabled}\n className={cn(\n 'rounded-r-none',\n '[&::-webkit-search-cancel-button]:hidden',\n '[&::-webkit-search-decoration]:hidden',\n //\n )}\n value={value}\n defaultValue={defaultValue}\n onChange={e => {\n if (value === undefined) {\n setUncontrolledHasValue(!!e.target.value);\n }\n onChange?.(e);\n }}\n onKeyDown={e => {\n _onKeyDown?.(e);\n if (e.key === 'Enter') {\n onSearch();\n }\n }}\n />\n <button\n type=\"button\"\n aria-label=\"지우기\"\n disabled={disabled}\n className={cn(\n 'absolute right-2',\n 'shrink-0 cursor-pointer',\n 'disabled:cursor-not-allowed disabled:opacity-50',\n (!allowClear || !hasValue) && 'hidden',\n )}\n onClick={onClear}\n >\n <CircleX className=\"size-4\" />\n </button>\n </div>\n <Button\n icon={<SearchOutlined />}\n disabled={disabled}\n className={cn(\n 'rounded-l-none',\n 'size-9',\n //\n )}\n onClick={onSearch}\n />\n </div>\n );\n};\n\nSearch.displayName = 'Search';\n\nexport default Search;\n"],"mappings":";;;;;;;;;;AAWA,MAAM,EAAE,OAAO,SAASA;AAUxB,MAAMC,YAAU,EACd,KACA,WACA,cACA,OACA,UACA,aAAa,MACb,UACA,WAAW,YACX,UAAU,WACV,GAAG,YACQ;CACX,MAAM,WAAW,OAAyB,KAAK;CAE/C,MAAM,WAAW,SAAkC;AACjD,WAAS,UAAU;AAEnB,MAAI,OAAO,QAAQ,WACjB,KAAI,KAAK;WACA,IACT,KAAI,UAAU;;CAIlB,MAAM,CAAC,sBAAsB,2BAC3B,SAAS,CAAC,CAAC,aAAa;CAC1B,MAAM,WAAW,UAAU,SAAY,CAAC,CAAC,QAAQ;CAEjD,MAAM,gBAAgB;AACpB,MAAI,CAAC,SAAS,QACZ;AAGF,MAAI,UAAU,QAAW;AACvB,YAAS,QAAQ,QAAQ;AACzB,2BAAwB,MAAM;;AAGhC,aAAW,EAAE,QAAQ,EAAE,OAAO,IAAI,EAAE,CAAC;;CAGvC,MAAM,iBAAiB;AACrB,MAAI,SACF;AAEF,MAAI,SAAS,QACX,aAAY,SAAS,QAAQ,MAAM;;AAIvC,QACE,qBAAC;EACC,WAAW,GACT,qBACA,cACA,UAED;aAED,qBAAC;GACC,WAAW,GACT,iBACA,2BAED;cAED,oBAAC;IACC,GAAI;IACJ,KAAK;IACL,WAAU;IACV,MAAK;IACL,cAAa;IACH;IACV,WAAW,GACT,kBACA,4CACA,wCAED;IACM;IACO;IACd,WAAU,MAAK;AACb,SAAI,UAAU,OACZ,yBAAwB,CAAC,CAAC,EAAE,OAAO,MAAM;AAE3C,gBAAW,EAAE;;IAEf,YAAW,MAAK;AACd,kBAAa,EAAE;AACf,SAAI,EAAE,QAAQ,QACZ,WAAU;;KAGd,EACF,oBAAC;IACC,MAAK;IACL,cAAW;IACD;IACV,WAAW,GACT,oBACA,2BACA,oDACC,CAAC,cAAc,CAAC,aAAa,SAC/B;IACD,SAAS;cAET,oBAAC,WAAQ,WAAU,WAAW;KACvB;IACL,EACN,oBAAC;GACC,MAAM,oBAACC,WAAiB;GACd;GACV,WAAW,GACT,kBACA,SAED;GACD,SAAS;IACT;GACE;;AAIV,SAAO,cAAc"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/components/atoms/option-group.d.ts
|
|
2
|
+
type OptionValue = string | number | boolean;
|
|
3
|
+
interface Option {
|
|
4
|
+
label: string;
|
|
5
|
+
value: OptionValue;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
type Options = string[] | number[] | boolean[] | Option[];
|
|
9
|
+
interface OptionGroupClassNames {
|
|
10
|
+
wrapper?: string;
|
|
11
|
+
item?: string;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { OptionGroupClassNames, OptionValue, Options };
|
|
15
|
+
//# sourceMappingURL=option-group.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-group.d.mts","names":[],"sources":["../../../src/components/atoms/option-group.ts"],"mappings":";KAAY,WAAA;AAAA,UAEK,MAAA;EACf,KAAA;EACA,KAAA,EAAO,WAAA;EACP,QAAA;AAAA;AAAA,KAGU,OAAA,qCAA4C,MAAA;AAAA,UAEvC,qBAAA;EACf,OAAA;EACA,IAAA;AAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/components/atoms/option-group.ts
|
|
2
|
+
const normalizeOptions = (options) => options.map((item) => typeof item === "object" ? item : {
|
|
3
|
+
label: `${item}`,
|
|
4
|
+
value: item
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { normalizeOptions };
|
|
9
|
+
//# sourceMappingURL=option-group.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-group.mjs","names":[],"sources":["../../../src/components/atoms/option-group.ts"],"sourcesContent":["export type OptionValue = string | number | boolean;\n\nexport interface Option {\n label: string;\n value: OptionValue;\n disabled?: boolean;\n}\n\nexport type Options = string[] | number[] | boolean[] | Option[];\n\nexport interface OptionGroupClassNames {\n wrapper?: string;\n item?: string;\n}\n\nexport const normalizeOptions = (options: Options): Option[] =>\n options.map(item =>\n typeof item === 'object'\n ? item\n : {\n label: `${item}`,\n value: item,\n },\n );\n"],"mappings":";AAeA,MAAa,oBAAoB,YAC/B,QAAQ,KAAI,SACV,OAAO,SAAS,WACZ,OACA;CACE,OAAO,GAAG;CACV,OAAO;CACR,CACN"}
|
|
@@ -6,6 +6,9 @@ interface Props extends Omit<React.ComponentPropsWithoutRef<'div'>, 'title' | 'c
|
|
|
6
6
|
title?: React.ReactNode;
|
|
7
7
|
placement?: Placement;
|
|
8
8
|
content: React.ReactNode;
|
|
9
|
+
open?: boolean;
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
onOpenChange?: (open: boolean) => void;
|
|
9
12
|
}
|
|
10
13
|
declare const Popover: ({
|
|
11
14
|
title,
|
|
@@ -13,6 +16,9 @@ declare const Popover: ({
|
|
|
13
16
|
className,
|
|
14
17
|
content,
|
|
15
18
|
children,
|
|
19
|
+
open: _open,
|
|
20
|
+
defaultOpen,
|
|
21
|
+
onOpenChange,
|
|
16
22
|
...props
|
|
17
23
|
}: Props) => react_jsx_runtime0.JSX.Element;
|
|
18
24
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.d.mts","names":[],"sources":["../../../src/components/atoms/popover.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"popover.d.mts","names":[],"sources":["../../../src/components/atoms/popover.tsx"],"mappings":";;;KASK,SAAA;AAAA,UAcY,KAAA,SAAc,IAAA,CAC7B,KAAA,CAAM,wBAAA;EAGN,KAAA,GAAQ,KAAA,CAAM,SAAA;EACd,SAAA,GAAY,SAAA;EACZ,OAAA,EAAS,KAAA,CAAM,SAAA;EACf,IAAA;EACA,WAAA;EACA,YAAA,IAAgB,IAAA;AAAA;AAAA,cA4GZ,OAAA;EAAW,KAAA;EAAA,SAAA;EAAA,SAAA;EAAA,OAAA;EAAA,QAAA;EAAA,IAAA,EAAA,KAAA;EAAA,WAAA;EAAA,YAAA;EAAA,GAAA;AAAA,GAUd,KAAA,KAAK,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -2,6 +2,7 @@ import { cn, renderConditional } from "../../utils.mjs";
|
|
|
2
2
|
import { popover_exports } from "../../core/popover.mjs";
|
|
3
3
|
import Typography from "../../Typography.mjs";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useControllableState } from "@jbpark/use-hooks";
|
|
5
6
|
|
|
6
7
|
//#region src/components/atoms/popover.tsx
|
|
7
8
|
const { Popover: CorePopover, PopoverContent, PopoverTrigger } = popover_exports;
|
|
@@ -61,167 +62,81 @@ const vBorderShape = "before:border-l-[9px] before:border-r-[9px] before:border-
|
|
|
61
62
|
const hBorderShape = "before:border-t-[9px] before:border-b-[9px] before:border-t-transparent before:border-b-transparent";
|
|
62
63
|
const vFillShape = "after:border-l-8 after:border-r-8 after:border-l-transparent after:border-r-transparent";
|
|
63
64
|
const hFillShape = "after:border-t-8 after:border-b-8 after:border-t-transparent after:border-b-transparent";
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const bottomFill = "after:border-b-8 after:border-b-popover";
|
|
70
|
-
const leftFill = "after:border-l-8 after:border-l-popover";
|
|
71
|
-
const rightFill = "after:border-r-8 after:border-r-popover";
|
|
72
|
-
const arrowStyles = {
|
|
73
|
-
top: [
|
|
74
|
-
"absolute left-1/2 -translate-x-1/2 top-full",
|
|
75
|
-
beforeBase,
|
|
76
|
-
"before:top-0 before:left-1/2 before:-translate-x-1/2",
|
|
77
|
-
vBorderShape,
|
|
78
|
-
topBorder,
|
|
79
|
-
afterBase,
|
|
80
|
-
"after:-top-px after:left-1/2 after:-translate-x-1/2",
|
|
81
|
-
vFillShape,
|
|
82
|
-
topFill
|
|
83
|
-
].join(" "),
|
|
84
|
-
topLeft: [
|
|
85
|
-
"absolute left-4 top-full",
|
|
86
|
-
beforeBase,
|
|
87
|
-
"before:top-0 before:left-0",
|
|
88
|
-
vBorderShape,
|
|
89
|
-
topBorder,
|
|
90
|
-
afterBase,
|
|
91
|
-
"after:-top-px after:left-px",
|
|
92
|
-
vFillShape,
|
|
93
|
-
topFill
|
|
94
|
-
].join(" "),
|
|
95
|
-
topRight: [
|
|
96
|
-
"absolute right-4 top-full",
|
|
97
|
-
beforeBase,
|
|
98
|
-
"before:top-0 before:right-0",
|
|
99
|
-
vBorderShape,
|
|
100
|
-
topBorder,
|
|
101
|
-
afterBase,
|
|
102
|
-
"after:-top-px after:right-px",
|
|
103
|
-
vFillShape,
|
|
104
|
-
topFill
|
|
105
|
-
].join(" "),
|
|
106
|
-
bottom: [
|
|
107
|
-
"absolute left-1/2 -translate-x-1/2 bottom-full",
|
|
108
|
-
beforeBase,
|
|
109
|
-
"before:bottom-0 before:left-1/2 before:-translate-x-1/2",
|
|
110
|
-
vBorderShape,
|
|
111
|
-
bottomBorder,
|
|
112
|
-
afterBase,
|
|
113
|
-
"after:-bottom-px after:left-1/2 after:-translate-x-1/2",
|
|
114
|
-
vFillShape,
|
|
115
|
-
bottomFill
|
|
116
|
-
].join(" "),
|
|
117
|
-
bottomLeft: [
|
|
118
|
-
"absolute left-4 bottom-full",
|
|
119
|
-
beforeBase,
|
|
120
|
-
"before:bottom-0 before:left-0",
|
|
121
|
-
vBorderShape,
|
|
122
|
-
bottomBorder,
|
|
123
|
-
afterBase,
|
|
124
|
-
"after:-bottom-px after:left-px",
|
|
125
|
-
vFillShape,
|
|
126
|
-
bottomFill
|
|
127
|
-
].join(" "),
|
|
128
|
-
bottomRight: [
|
|
129
|
-
"absolute right-4 bottom-full",
|
|
130
|
-
beforeBase,
|
|
131
|
-
"before:bottom-0 before:right-0",
|
|
132
|
-
vBorderShape,
|
|
133
|
-
bottomBorder,
|
|
134
|
-
afterBase,
|
|
135
|
-
"after:-bottom-px after:right-px",
|
|
136
|
-
vFillShape,
|
|
137
|
-
bottomFill
|
|
138
|
-
].join(" "),
|
|
139
|
-
left: [
|
|
140
|
-
"absolute top-1/2 -translate-y-1/2 left-full",
|
|
141
|
-
beforeBase,
|
|
142
|
-
"before:left-0 before:top-1/2 before:-translate-y-1/2",
|
|
143
|
-
hBorderShape,
|
|
144
|
-
leftBorder,
|
|
145
|
-
afterBase,
|
|
146
|
-
"after:-left-px after:top-1/2 after:-translate-y-1/2",
|
|
147
|
-
hFillShape,
|
|
148
|
-
leftFill
|
|
149
|
-
].join(" "),
|
|
150
|
-
leftTop: [
|
|
151
|
-
"absolute top-4 left-full",
|
|
152
|
-
beforeBase,
|
|
153
|
-
"before:left-0 before:top-0",
|
|
154
|
-
hBorderShape,
|
|
155
|
-
leftBorder,
|
|
156
|
-
afterBase,
|
|
157
|
-
"after:-left-px after:top-px",
|
|
158
|
-
hFillShape,
|
|
159
|
-
leftFill
|
|
160
|
-
].join(" "),
|
|
161
|
-
leftBottom: [
|
|
162
|
-
"absolute bottom-4 left-full",
|
|
163
|
-
beforeBase,
|
|
164
|
-
"before:left-0 before:bottom-0",
|
|
165
|
-
hBorderShape,
|
|
166
|
-
leftBorder,
|
|
167
|
-
afterBase,
|
|
168
|
-
"after:-left-px after:bottom-px",
|
|
169
|
-
hFillShape,
|
|
170
|
-
leftFill
|
|
171
|
-
].join(" "),
|
|
172
|
-
right: [
|
|
173
|
-
"absolute top-1/2 -translate-y-1/2 right-full",
|
|
174
|
-
beforeBase,
|
|
175
|
-
"before:right-0 before:top-1/2 before:-translate-y-1/2",
|
|
176
|
-
hBorderShape,
|
|
177
|
-
rightBorder,
|
|
178
|
-
afterBase,
|
|
179
|
-
"after:-right-px after:top-1/2 after:-translate-y-1/2",
|
|
180
|
-
hFillShape,
|
|
181
|
-
rightFill
|
|
182
|
-
].join(" "),
|
|
183
|
-
rightTop: [
|
|
184
|
-
"absolute top-4 right-full",
|
|
185
|
-
beforeBase,
|
|
186
|
-
"before:right-0 before:top-0",
|
|
187
|
-
hBorderShape,
|
|
188
|
-
rightBorder,
|
|
189
|
-
afterBase,
|
|
190
|
-
"after:-right-px after:top-px",
|
|
191
|
-
hFillShape,
|
|
192
|
-
rightFill
|
|
193
|
-
].join(" "),
|
|
194
|
-
rightBottom: [
|
|
195
|
-
"absolute bottom-4 right-full",
|
|
196
|
-
beforeBase,
|
|
197
|
-
"before:right-0 before:bottom-0",
|
|
198
|
-
hBorderShape,
|
|
199
|
-
rightBorder,
|
|
200
|
-
afterBase,
|
|
201
|
-
"after:-right-px after:bottom-px",
|
|
202
|
-
hFillShape,
|
|
203
|
-
rightFill
|
|
204
|
-
].join(" ")
|
|
65
|
+
const borderShapeBySide = {
|
|
66
|
+
top: vBorderShape,
|
|
67
|
+
bottom: vBorderShape,
|
|
68
|
+
left: hBorderShape,
|
|
69
|
+
right: hBorderShape
|
|
205
70
|
};
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
71
|
+
const fillShapeBySide = {
|
|
72
|
+
top: vFillShape,
|
|
73
|
+
bottom: vFillShape,
|
|
74
|
+
left: hFillShape,
|
|
75
|
+
right: hFillShape
|
|
76
|
+
};
|
|
77
|
+
const borderColorBySide = {
|
|
78
|
+
top: "before:border-t-[9px] before:border-t-border",
|
|
79
|
+
bottom: "before:border-b-[9px] before:border-b-border",
|
|
80
|
+
left: "before:border-l-[9px] before:border-l-border",
|
|
81
|
+
right: "before:border-r-[9px] before:border-r-border"
|
|
82
|
+
};
|
|
83
|
+
const fillColorBySide = {
|
|
84
|
+
top: "after:border-t-8 after:border-t-popover",
|
|
85
|
+
bottom: "after:border-b-8 after:border-b-popover",
|
|
86
|
+
left: "after:border-l-8 after:border-l-popover",
|
|
87
|
+
right: "after:border-r-8 after:border-r-popover"
|
|
88
|
+
};
|
|
89
|
+
const offsetAxisBySide = {
|
|
90
|
+
top: "x",
|
|
91
|
+
bottom: "x",
|
|
92
|
+
left: "y",
|
|
93
|
+
right: "y"
|
|
94
|
+
};
|
|
95
|
+
const startEdgeByAxis = {
|
|
96
|
+
x: "left",
|
|
97
|
+
y: "top"
|
|
98
|
+
};
|
|
99
|
+
const endEdgeByAxis = {
|
|
100
|
+
x: "right",
|
|
101
|
+
y: "bottom"
|
|
102
|
+
};
|
|
103
|
+
const getArrowClassName = (side, align) => {
|
|
104
|
+
const axis = offsetAxisBySide[side];
|
|
105
|
+
const alignEdge = align === "start" ? startEdgeByAxis[axis] : align === "end" ? endEdgeByAxis[axis] : null;
|
|
106
|
+
const positionAlign = alignEdge ? `${alignEdge}-4` : `${startEdgeByAxis[axis]}-1/2 -translate-${axis}-1/2`;
|
|
107
|
+
const beforeAlign = alignEdge ? `before:${alignEdge}-0` : `before:${startEdgeByAxis[axis]}-1/2 before:-translate-${axis}-1/2`;
|
|
108
|
+
const afterAlign = alignEdge ? `after:${alignEdge}-px` : `after:${startEdgeByAxis[axis]}-1/2 after:-translate-${axis}-1/2`;
|
|
109
|
+
return cn(`absolute ${positionAlign} ${side}-full`, beforeBase, `before:${side}-0`, beforeAlign, borderShapeBySide[side], borderColorBySide[side], afterBase, `after:-${side}-px`, afterAlign, fillShapeBySide[side], fillColorBySide[side]);
|
|
110
|
+
};
|
|
111
|
+
const Popover = ({ title, placement = "top", className, content, children, open: _open, defaultOpen, onOpenChange, ...props }) => {
|
|
112
|
+
const [open, setOpen] = useControllableState({
|
|
113
|
+
value: _open,
|
|
114
|
+
defaultValue: defaultOpen ?? false,
|
|
115
|
+
onChange: onOpenChange
|
|
116
|
+
});
|
|
117
|
+
const { side, align } = placementMap[placement];
|
|
118
|
+
return /* @__PURE__ */ jsxs(CorePopover, {
|
|
119
|
+
open,
|
|
120
|
+
onOpenChange: setOpen,
|
|
121
|
+
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
122
|
+
asChild: true,
|
|
123
|
+
children
|
|
124
|
+
}), /* @__PURE__ */ jsxs(PopoverContent, {
|
|
125
|
+
...props,
|
|
126
|
+
align,
|
|
127
|
+
side,
|
|
128
|
+
sideOffset: 16,
|
|
129
|
+
className: cn("relative w-auto", className),
|
|
130
|
+
children: [
|
|
131
|
+
renderConditional(title, (v) => /* @__PURE__ */ jsx(Typography.Title, {
|
|
132
|
+
level: 6,
|
|
133
|
+
children: v
|
|
134
|
+
})),
|
|
135
|
+
content,
|
|
136
|
+
/* @__PURE__ */ jsx("div", { className: getArrowClassName(side, align) })
|
|
137
|
+
]
|
|
138
|
+
})]
|
|
139
|
+
});
|
|
225
140
|
};
|
|
226
141
|
|
|
227
142
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.mjs","names":["popover"],"sources":["../../../src/components/atoms/popover.tsx"],"sourcesContent":["import { popover } from '@repo/ui/core';\nimport { cn, renderConditional } from '@repo/ui/utils';\n\nimport Typography from './typography';\n\nconst { Popover: CorePopover, PopoverContent, PopoverTrigger } = popover;\n\ntype Placement =\n | 'top'\n | 'left'\n | 'right'\n | 'bottom'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight'\n | 'leftTop'\n | 'leftBottom'\n | 'rightTop'\n | 'rightBottom';\n\
|
|
1
|
+
{"version":3,"file":"popover.mjs","names":["popover"],"sources":["../../../src/components/atoms/popover.tsx"],"sourcesContent":["import { useControllableState } from '@jbpark/use-hooks';\n\nimport { popover } from '@repo/ui/core';\nimport { cn, renderConditional } from '@repo/ui/utils';\n\nimport Typography from './typography';\n\nconst { Popover: CorePopover, PopoverContent, PopoverTrigger } = popover;\n\ntype Placement =\n | 'top'\n | 'left'\n | 'right'\n | 'bottom'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight'\n | 'leftTop'\n | 'leftBottom'\n | 'rightTop'\n | 'rightBottom';\n\nexport interface Props extends Omit<\n React.ComponentPropsWithoutRef<'div'>,\n 'title' | 'content'\n> {\n title?: React.ReactNode;\n placement?: Placement;\n content: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\ntype Side = 'top' | 'bottom' | 'left' | 'right';\ntype Align = 'start' | 'center' | 'end';\n\nconst placementMap: Record<Placement, { side: Side; align: Align }> = {\n top: { side: 'top', align: 'center' },\n left: { side: 'left', align: 'center' },\n right: { side: 'right', align: 'center' },\n bottom: { side: 'bottom', align: 'center' },\n topLeft: { side: 'top', align: 'start' },\n topRight: { side: 'top', align: 'end' },\n bottomLeft: { side: 'bottom', align: 'start' },\n bottomRight: { side: 'bottom', align: 'end' },\n leftTop: { side: 'left', align: 'start' },\n leftBottom: { side: 'left', align: 'end' },\n rightTop: { side: 'right', align: 'start' },\n rightBottom: { side: 'right', align: 'end' },\n};\n\nconst beforeBase = 'before:content-[\"\"] before:absolute before:h-0 before:w-0';\nconst afterBase = 'after:content-[\"\"] after:absolute after:h-0 after:w-0';\n\nconst vBorderShape =\n 'before:border-l-[9px] before:border-r-[9px] before:border-l-transparent before:border-r-transparent';\nconst hBorderShape =\n 'before:border-t-[9px] before:border-b-[9px] before:border-t-transparent before:border-b-transparent';\nconst vFillShape =\n 'after:border-l-8 after:border-r-8 after:border-l-transparent after:border-r-transparent';\nconst hFillShape =\n 'after:border-t-8 after:border-b-8 after:border-t-transparent after:border-b-transparent';\n\n// Top/bottom placements draw a vertical-edge triangle (border-l/border-r) —\n// the arrow points up/down, so its left/right edges form the point. Left/\n// right placements draw the horizontal-edge equivalent.\nconst borderShapeBySide: Record<Side, string> = {\n top: vBorderShape,\n bottom: vBorderShape,\n left: hBorderShape,\n right: hBorderShape,\n};\nconst fillShapeBySide: Record<Side, string> = {\n top: vFillShape,\n bottom: vFillShape,\n left: hFillShape,\n right: hFillShape,\n};\nconst borderColorBySide: Record<Side, string> = {\n top: 'before:border-t-[9px] before:border-t-border',\n bottom: 'before:border-b-[9px] before:border-b-border',\n left: 'before:border-l-[9px] before:border-l-border',\n right: 'before:border-r-[9px] before:border-r-border',\n};\nconst fillColorBySide: Record<Side, string> = {\n top: 'after:border-t-8 after:border-t-popover',\n bottom: 'after:border-b-8 after:border-b-popover',\n left: 'after:border-l-8 after:border-l-popover',\n right: 'after:border-r-8 after:border-r-popover',\n};\n\n// `side` picks which edge of the content the arrow sits against; `align`\n// slides it along that edge. The offset axis (x for top/bottom, y for\n// left/right) is perpendicular to `side` — `align: 'center'` centers the\n// arrow with a translate, while `start`/`end` pin it 16px from that edge.\nconst offsetAxisBySide: Record<Side, 'x' | 'y'> = {\n top: 'x',\n bottom: 'x',\n left: 'y',\n right: 'y',\n};\nconst startEdgeByAxis = { x: 'left', y: 'top' } as const;\nconst endEdgeByAxis = { x: 'right', y: 'bottom' } as const;\n\nconst getArrowClassName = (side: Side, align: Align) => {\n const axis = offsetAxisBySide[side];\n const alignEdge =\n align === 'start'\n ? startEdgeByAxis[axis]\n : align === 'end'\n ? endEdgeByAxis[axis]\n : null;\n\n const positionAlign = alignEdge\n ? `${alignEdge}-4`\n : `${startEdgeByAxis[axis]}-1/2 -translate-${axis}-1/2`;\n const beforeAlign = alignEdge\n ? `before:${alignEdge}-0`\n : `before:${startEdgeByAxis[axis]}-1/2 before:-translate-${axis}-1/2`;\n const afterAlign = alignEdge\n ? `after:${alignEdge}-px`\n : `after:${startEdgeByAxis[axis]}-1/2 after:-translate-${axis}-1/2`;\n\n return cn(\n `absolute ${positionAlign} ${side}-full`,\n beforeBase,\n `before:${side}-0`,\n beforeAlign,\n borderShapeBySide[side],\n borderColorBySide[side],\n afterBase,\n `after:-${side}-px`,\n afterAlign,\n fillShapeBySide[side],\n fillColorBySide[side],\n );\n};\n\nconst Popover = ({\n title,\n placement = 'top',\n className,\n content,\n children,\n open: _open,\n defaultOpen,\n onOpenChange,\n ...props\n}: Props) => {\n const [open, setOpen] = useControllableState<boolean>({\n value: _open,\n defaultValue: defaultOpen ?? false,\n onChange: onOpenChange,\n });\n\n const { side, align } = placementMap[placement];\n\n return (\n <CorePopover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>{children}</PopoverTrigger>\n <PopoverContent\n {...props}\n align={align}\n side={side}\n sideOffset={16}\n className={cn('relative w-auto', className)}\n >\n {renderConditional(title, v => (\n <Typography.Title level={6}>{v}</Typography.Title>\n ))}\n {content}\n <div className={getArrowClassName(side, align)} />\n </PopoverContent>\n </CorePopover>\n );\n};\n\nexport default Popover;\n"],"mappings":";;;;;;;AAOA,MAAM,EAAE,SAAS,aAAa,gBAAgB,mBAAmBA;AA+BjE,MAAM,eAAgE;CACpE,KAAK;EAAE,MAAM;EAAO,OAAO;EAAU;CACrC,MAAM;EAAE,MAAM;EAAQ,OAAO;EAAU;CACvC,OAAO;EAAE,MAAM;EAAS,OAAO;EAAU;CACzC,QAAQ;EAAE,MAAM;EAAU,OAAO;EAAU;CAC3C,SAAS;EAAE,MAAM;EAAO,OAAO;EAAS;CACxC,UAAU;EAAE,MAAM;EAAO,OAAO;EAAO;CACvC,YAAY;EAAE,MAAM;EAAU,OAAO;EAAS;CAC9C,aAAa;EAAE,MAAM;EAAU,OAAO;EAAO;CAC7C,SAAS;EAAE,MAAM;EAAQ,OAAO;EAAS;CACzC,YAAY;EAAE,MAAM;EAAQ,OAAO;EAAO;CAC1C,UAAU;EAAE,MAAM;EAAS,OAAO;EAAS;CAC3C,aAAa;EAAE,MAAM;EAAS,OAAO;EAAO;CAC7C;AAED,MAAM,aAAa;AACnB,MAAM,YAAY;AAElB,MAAM,eACJ;AACF,MAAM,eACJ;AACF,MAAM,aACJ;AACF,MAAM,aACJ;AAKF,MAAM,oBAA0C;CAC9C,KAAK;CACL,QAAQ;CACR,MAAM;CACN,OAAO;CACR;AACD,MAAM,kBAAwC;CAC5C,KAAK;CACL,QAAQ;CACR,MAAM;CACN,OAAO;CACR;AACD,MAAM,oBAA0C;CAC9C,KAAK;CACL,QAAQ;CACR,MAAM;CACN,OAAO;CACR;AACD,MAAM,kBAAwC;CAC5C,KAAK;CACL,QAAQ;CACR,MAAM;CACN,OAAO;CACR;AAMD,MAAM,mBAA4C;CAChD,KAAK;CACL,QAAQ;CACR,MAAM;CACN,OAAO;CACR;AACD,MAAM,kBAAkB;CAAE,GAAG;CAAQ,GAAG;CAAO;AAC/C,MAAM,gBAAgB;CAAE,GAAG;CAAS,GAAG;CAAU;AAEjD,MAAM,qBAAqB,MAAY,UAAiB;CACtD,MAAM,OAAO,iBAAiB;CAC9B,MAAM,YACJ,UAAU,UACN,gBAAgB,QAChB,UAAU,QACR,cAAc,QACd;CAER,MAAM,gBAAgB,YAClB,GAAG,UAAU,MACb,GAAG,gBAAgB,MAAM,kBAAkB,KAAK;CACpD,MAAM,cAAc,YAChB,UAAU,UAAU,MACpB,UAAU,gBAAgB,MAAM,yBAAyB,KAAK;CAClE,MAAM,aAAa,YACf,SAAS,UAAU,OACnB,SAAS,gBAAgB,MAAM,wBAAwB,KAAK;AAEhE,QAAO,GACL,YAAY,cAAc,GAAG,KAAK,QAClC,YACA,UAAU,KAAK,KACf,aACA,kBAAkB,OAClB,kBAAkB,OAClB,WACA,UAAU,KAAK,MACf,YACA,gBAAgB,OAChB,gBAAgB,MACjB;;AAGH,MAAM,WAAW,EACf,OACA,YAAY,OACZ,WACA,SACA,UACA,MAAM,OACN,aACA,cACA,GAAG,YACQ;CACX,MAAM,CAAC,MAAM,WAAW,qBAA8B;EACpD,OAAO;EACP,cAAc,eAAe;EAC7B,UAAU;EACX,CAAC;CAEF,MAAM,EAAE,MAAM,UAAU,aAAa;AAErC,QACE,qBAAC;EAAkB;EAAM,cAAc;aACrC,oBAAC;GAAe;GAAS;IAA0B,EACnD,qBAAC;GACC,GAAI;GACG;GACD;GACN,YAAY;GACZ,WAAW,GAAG,mBAAmB,UAAU;;IAE1C,kBAAkB,QAAO,MACxB,oBAAC,WAAW;KAAM,OAAO;eAAI;MAAqB,CAClD;IACD;IACD,oBAAC,SAAI,WAAW,kBAAkB,MAAM,MAAM,GAAI;;IACnC;GACL"}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
+
import { OptionGroupClassNames, OptionValue, Options } from "../option-group.mjs";
|
|
1
2
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
3
|
|
|
3
4
|
//#region src/components/atoms/radio/group.d.ts
|
|
4
|
-
type OptionValue = string | number | boolean;
|
|
5
|
-
type Option = {
|
|
6
|
-
label: string;
|
|
7
|
-
value: OptionValue;
|
|
8
|
-
disabled?: boolean;
|
|
9
|
-
};
|
|
10
|
-
type Options = string[] | number[] | boolean[] | Option[];
|
|
11
5
|
interface Props extends Omit<React.ComponentPropsWithoutRef<'ul'>, 'onChange' | 'defaultValue' | 'value'> {
|
|
12
6
|
options?: Options;
|
|
13
7
|
orientation?: 'vertical' | 'horizontal';
|
|
14
8
|
placement?: 'left' | 'right';
|
|
15
|
-
classNames?:
|
|
9
|
+
classNames?: OptionGroupClassNames;
|
|
16
10
|
defaultValue?: OptionValue;
|
|
17
11
|
value?: OptionValue;
|
|
12
|
+
/** Native form field name — participates in `FormData` when set. */
|
|
13
|
+
name?: string;
|
|
18
14
|
optionType?: 'default' | 'button';
|
|
19
15
|
buttonStyle?: 'solid' | 'outlined';
|
|
20
16
|
size?: 'small' | 'middle' | 'large';
|
|
@@ -27,6 +23,7 @@ declare const RadioGroup: ({
|
|
|
27
23
|
className,
|
|
28
24
|
classNames,
|
|
29
25
|
options: _options,
|
|
26
|
+
name,
|
|
30
27
|
optionType,
|
|
31
28
|
buttonStyle,
|
|
32
29
|
size,
|
|
@@ -37,5 +34,5 @@ declare const RadioGroup: ({
|
|
|
37
34
|
...props
|
|
38
35
|
}: Props) => react_jsx_runtime0.JSX.Element;
|
|
39
36
|
//#endregion
|
|
40
|
-
export {
|
|
37
|
+
export { RadioGroup };
|
|
41
38
|
//# sourceMappingURL=group.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.d.mts","names":[],"sources":["../../../../src/components/atoms/radio/group.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"group.d.mts","names":[],"sources":["../../../../src/components/atoms/radio/group.tsx"],"mappings":";;;;UAwBiB,KAAA,SAAc,IAAA,CAC7B,KAAA,CAAM,wBAAA;EAGN,OAAA,GAAU,OAAA;EACV,WAAA;EACA,SAAA;EACA,UAAA,GAAa,qBAAA;EACb,YAAA,GAAe,WAAA;EACf,KAAA,GAAQ,WAAA;EAFK;EAIb,IAAA;EACA,UAAA;EACA,WAAA;EACA,IAAA;EACA,QAAA;EACA,QAAA,IAAY,KAAA,EAAO,WAAA;AAAA;AAAA,cAGf,UAAA;EAAc,WAAA;EAAA,SAAA;EAAA,SAAA;EAAA,UAAA;EAAA,OAAA,EAAA,QAAA;EAAA,IAAA;EAAA,UAAA;EAAA,WAAA;EAAA,IAAA;EAAA,QAAA;EAAA,YAAA;EAAA,KAAA,EAAA,MAAA;EAAA,QAAA,EAAA,SAAA;EAAA,GAAA;AAAA,GAejB,KAAA,KAAK,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -3,33 +3,32 @@
|
|
|
3
3
|
import { cn } from "../../../utils.mjs";
|
|
4
4
|
import { radio_group_exports } from "../../../core/radio-group.mjs";
|
|
5
5
|
import Button from "../../../Button.mjs";
|
|
6
|
+
import { normalizeOptions } from "../option-group.mjs";
|
|
6
7
|
import { RadioGroupContext } from "./context.mjs";
|
|
7
8
|
import Radio from "./radio.mjs";
|
|
8
|
-
import { useId
|
|
9
|
+
import { useId } from "react";
|
|
9
10
|
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
import { useControllableState } from "@jbpark/use-hooks";
|
|
10
12
|
|
|
11
13
|
//#region src/components/atoms/radio/group.tsx
|
|
12
|
-
const { RadioGroup: Core } = radio_group_exports;
|
|
13
|
-
const RadioGroup = ({ orientation = "horizontal", placement = "left", className, classNames = {}, options: _options = [], optionType = "default", buttonStyle = "solid", size, disabled, defaultValue, value: _value, onChange: _onChange = () => {}, ...props }) => {
|
|
14
|
-
const [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
label: `${item}`,
|
|
19
|
-
value: item
|
|
14
|
+
const { RadioGroup: Core, RadioGroupItem: Item } = radio_group_exports;
|
|
15
|
+
const RadioGroup = ({ orientation = "horizontal", placement = "left", className, classNames = {}, options: _options = [], name, optionType = "default", buttonStyle = "solid", size, disabled, defaultValue, value: _value, onChange: _onChange = () => {}, ...props }) => {
|
|
16
|
+
const [value, setValue] = useControllableState({
|
|
17
|
+
value: _value,
|
|
18
|
+
defaultValue,
|
|
19
|
+
onChange: _onChange
|
|
20
20
|
});
|
|
21
|
+
const options = normalizeOptions(_options);
|
|
21
22
|
const isButton = optionType === "button";
|
|
22
23
|
const onChange = (checked, optionValue) => {
|
|
23
24
|
if (!checked) return;
|
|
24
|
-
|
|
25
|
-
_onChange(optionValue);
|
|
25
|
+
setValue(optionValue);
|
|
26
26
|
};
|
|
27
27
|
const baseId = useId();
|
|
28
28
|
const getOptionId = (index) => `${baseId}-${index}`;
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const item = options.find((_, index) => getOptionId(index) === optionId);
|
|
29
|
+
const checkedItemValue = value === void 0 ? "" : String(value);
|
|
30
|
+
const onValueChange = (itemValue) => {
|
|
31
|
+
const item = options.find((option) => String(option.value) === itemValue);
|
|
33
32
|
if (!item) return;
|
|
34
33
|
onChange(true, item.value);
|
|
35
34
|
};
|
|
@@ -40,13 +39,17 @@ const RadioGroup = ({ orientation = "horizontal", placement = "left", className,
|
|
|
40
39
|
const checked = value === item.value;
|
|
41
40
|
return /* @__PURE__ */ jsx("li", {
|
|
42
41
|
className: cn("flex", classNames?.wrapper),
|
|
43
|
-
children: isButton ? /* @__PURE__ */ jsx(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
className: cn("rounded-none", index === 0 && "rounded-l-lg", index === options.length - 1 && "rounded-r-lg", checked && buttonStyle === "outlined" && "border-primary"),
|
|
42
|
+
children: isButton ? /* @__PURE__ */ jsx(Item, {
|
|
43
|
+
asChild: true,
|
|
44
|
+
value: String(item.value),
|
|
47
45
|
disabled: disabled || item.disabled,
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
47
|
+
variant: checked ? buttonStyle : "outlined",
|
|
48
|
+
size,
|
|
49
|
+
disabled: disabled || item.disabled,
|
|
50
|
+
className: cn("rounded-none border", checked && (buttonStyle === "outlined" ? "border-primary" : "border-transparent"), index === 0 && (orientation === "vertical" ? "rounded-t-lg" : "rounded-l-lg"), index === options.length - 1 && (orientation === "vertical" ? "rounded-b-lg" : "rounded-r-lg")),
|
|
51
|
+
children: item.label
|
|
52
|
+
})
|
|
50
53
|
}) : /* @__PURE__ */ jsx(Radio, {
|
|
51
54
|
id: getOptionId(index),
|
|
52
55
|
placement,
|
|
@@ -60,12 +63,12 @@ const RadioGroup = ({ orientation = "horizontal", placement = "left", className,
|
|
|
60
63
|
}, String(item.value));
|
|
61
64
|
})
|
|
62
65
|
});
|
|
63
|
-
if (isButton) return list;
|
|
64
66
|
return /* @__PURE__ */ jsx(RadioGroupContext.Provider, {
|
|
65
67
|
value: true,
|
|
66
68
|
children: /* @__PURE__ */ jsx(Core, {
|
|
67
69
|
className: "block",
|
|
68
|
-
|
|
70
|
+
name,
|
|
71
|
+
value: checkedItemValue,
|
|
69
72
|
onValueChange,
|
|
70
73
|
children: list
|
|
71
74
|
})
|