@oneplatformdev/ui 0.1.10-103 → 0.1.10-109
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/AlertDialog/AlertDialog.d.ts.map +1 -1
- package/AlertDialog/AlertDialog.js +40 -46
- package/AlertDialog/AlertDialog.js.map +1 -1
- package/AlertDialog/AlertDialogRoot.d.ts.map +1 -1
- package/AlertDialog/AlertDialogRoot.js +37 -33
- package/AlertDialog/AlertDialogRoot.js.map +1 -1
- package/CHANGELOG.md +57 -0
- package/Combobox/Combobox.d.ts.map +1 -1
- package/Combobox/Combobox.js +107 -106
- package/Combobox/Combobox.js.map +1 -1
- package/Search/Search.d.ts.map +1 -1
- package/Search/Search.js +35 -33
- package/Search/Search.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlertDialog.d.ts","sourceRoot":"","sources":["../../src/AlertDialog/AlertDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,EAAE,EAEF,iBAAiB,EAGlB,MAAM,OAAO,CAAC;AAYf,OAAO,
|
|
1
|
+
{"version":3,"file":"AlertDialog.d.ts","sourceRoot":"","sources":["../../src/AlertDialog/AlertDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,EAAE,EAEF,iBAAiB,EAGlB,MAAM,OAAO,CAAC;AAYf,OAAO,EAIL,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAwH7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CA0B/D,CAAA;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1,62 +1,62 @@
|
|
|
1
1
|
import { jsxs as g, jsx as t } from "react/jsx-runtime";
|
|
2
|
-
import { cloneElement as
|
|
3
|
-
import { AlertDialogRoot as y, AlertDialogContent as
|
|
2
|
+
import { cloneElement as p, useId as b, Children as j } from "react";
|
|
3
|
+
import { AlertDialogRoot as y, AlertDialogContent as P, AlertDialogTrigger as E, AlertDialogHeader as u, AlertDialogTitle as B, AlertDialogDescription as v, AlertDialogFooter as f, AlertDialogAction as A, AlertDialogCancel as R } from "./AlertDialogRoot.js";
|
|
4
4
|
import { isValidReactElement as s } from "@oneplatformdev/utils";
|
|
5
5
|
const F = (o) => {
|
|
6
|
-
const { slotProps: e = {}, children: r } = o,
|
|
7
|
-
return /* @__PURE__ */ t(E, { asChild: !0, ...
|
|
6
|
+
const { slotProps: e = {}, children: r } = o, n = e.trigger ?? {};
|
|
7
|
+
return /* @__PURE__ */ t(E, { asChild: !0, ...n, children: r });
|
|
8
8
|
}, H = (o) => {
|
|
9
9
|
const {
|
|
10
10
|
title: e = "",
|
|
11
11
|
description: r = "",
|
|
12
|
-
slotProps:
|
|
13
|
-
children:
|
|
14
|
-
} = o,
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
{ ...
|
|
18
|
-
) : /* @__PURE__ */ t(
|
|
19
|
-
e && s(e, B) ?
|
|
12
|
+
slotProps: n = {},
|
|
13
|
+
children: i
|
|
14
|
+
} = o, c = n.header ?? {}, a = n.title ?? {}, l = n.description ?? {};
|
|
15
|
+
return i ? s(i, u) ? p(
|
|
16
|
+
i,
|
|
17
|
+
{ ...i.props || {}, ...c }
|
|
18
|
+
) : /* @__PURE__ */ t(u, { ...c, children: i }) : /* @__PURE__ */ g(u, { children: [
|
|
19
|
+
e && s(e, B) ? p(
|
|
20
20
|
e,
|
|
21
21
|
{ ...e.props || {}, ...a }
|
|
22
22
|
) : /* @__PURE__ */ t(B, { ...a, children: e }),
|
|
23
|
-
r && s(r, v) ?
|
|
23
|
+
r && s(r, v) ? p(
|
|
24
24
|
r,
|
|
25
|
-
{ ...r.props || {}, ...
|
|
26
|
-
) : /* @__PURE__ */ t(v, { ...
|
|
25
|
+
{ ...r.props || {}, ...l }
|
|
26
|
+
) : /* @__PURE__ */ t(v, { ...l, children: r })
|
|
27
27
|
] });
|
|
28
28
|
}, I = (o) => {
|
|
29
29
|
const {
|
|
30
30
|
slotProps: e = {},
|
|
31
31
|
children: r,
|
|
32
|
-
onCancel:
|
|
33
|
-
onConfirm:
|
|
34
|
-
cancelLabel:
|
|
32
|
+
onCancel: n,
|
|
33
|
+
onConfirm: i,
|
|
34
|
+
cancelLabel: c = "Cancel",
|
|
35
35
|
actionLabel: a = "Continue",
|
|
36
|
-
variant:
|
|
37
|
-
} = o, k = b(),
|
|
38
|
-
return r ? s(r,
|
|
36
|
+
variant: l = "confirm"
|
|
37
|
+
} = o, k = b(), D = e.footer ?? {}, x = e.cancelButton ?? {}, m = e.actionButton ?? {};
|
|
38
|
+
return r ? s(r, f) ? p(
|
|
39
39
|
r,
|
|
40
|
-
{ ...r.props || {}, ...
|
|
41
|
-
) : /* @__PURE__ */ t(
|
|
42
|
-
if (!
|
|
43
|
-
const h =
|
|
44
|
-
return s(
|
|
45
|
-
}) }) : /* @__PURE__ */ g(
|
|
46
|
-
|
|
40
|
+
{ ...r.props || {}, ...D }
|
|
41
|
+
) : /* @__PURE__ */ t(f, { ...D, children: j.map(r, (d, T) => {
|
|
42
|
+
if (!d || !s(d)) return;
|
|
43
|
+
const h = d, C = p(h, { ...h.props || {}, key: h.key || `footer-${k}-action-${T}` });
|
|
44
|
+
return s(d, A) || s(d, R) ? C : /* @__PURE__ */ t(A, { asChild: !0, children: C });
|
|
45
|
+
}) }) : /* @__PURE__ */ g(f, { children: [
|
|
46
|
+
l !== "alert" && /* @__PURE__ */ t(
|
|
47
47
|
R,
|
|
48
48
|
{
|
|
49
|
-
onClick:
|
|
49
|
+
onClick: n,
|
|
50
50
|
...x,
|
|
51
|
-
children:
|
|
51
|
+
children: c
|
|
52
52
|
}
|
|
53
53
|
),
|
|
54
54
|
/* @__PURE__ */ t(
|
|
55
|
-
|
|
55
|
+
A,
|
|
56
56
|
{
|
|
57
|
-
onClick:
|
|
58
|
-
...
|
|
59
|
-
variant:
|
|
57
|
+
onClick: i,
|
|
58
|
+
...m,
|
|
59
|
+
variant: m.variant || l === "destructive" ? "destructive" : "default",
|
|
60
60
|
children: a
|
|
61
61
|
}
|
|
62
62
|
)
|
|
@@ -65,22 +65,16 @@ const F = (o) => {
|
|
|
65
65
|
const {
|
|
66
66
|
trigger: e,
|
|
67
67
|
header: r,
|
|
68
|
-
footer:
|
|
69
|
-
slotProps:
|
|
70
|
-
children:
|
|
68
|
+
footer: n,
|
|
69
|
+
slotProps: i = {},
|
|
70
|
+
children: c,
|
|
71
71
|
...a
|
|
72
|
-
} = o,
|
|
72
|
+
} = o, l = i.content ?? {};
|
|
73
73
|
return /* @__PURE__ */ g(y, { ...a, children: [
|
|
74
74
|
/* @__PURE__ */ t(F, { ...o, children: e }),
|
|
75
|
-
|
|
76
|
-
n,
|
|
77
|
-
{
|
|
78
|
-
...n.props || {},
|
|
79
|
-
...c
|
|
80
|
-
}
|
|
81
|
-
) : /* @__PURE__ */ t(u, { ...c, children: n }) : /* @__PURE__ */ g(u, { ...c, children: [
|
|
75
|
+
c ? /* @__PURE__ */ t(P, { ...l, children: c }) : /* @__PURE__ */ g(P, { ...l, children: [
|
|
82
76
|
/* @__PURE__ */ t(H, { ...o, children: r }),
|
|
83
|
-
/* @__PURE__ */ t(I, { ...o, children:
|
|
77
|
+
/* @__PURE__ */ t(I, { ...o, children: n })
|
|
84
78
|
] })
|
|
85
79
|
] });
|
|
86
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlertDialog.js","sources":["../../src/AlertDialog/AlertDialog.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n FC,\n Key,\n PropsWithChildren,\n ReactElement,\n useId,\n} from 'react';\nimport {\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogContent,\n AlertDialogDescription,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogRoot,\n AlertDialogTitle,\n AlertDialogTrigger,\n} from './AlertDialogRoot';\nimport {\n AlertDialogContentProps,\n AlertDialogDescriptionProps,\n AlertDialogFooterProps,\n AlertDialogHeaderProps,\n AlertDialogProps,\n AlertDialogTitleProps,\n} from './AlertDialog.types';\n\nimport { isValidReactElement } from '@oneplatformdev/utils';\n\nconst RenderAlertDialogTrigger: FC<PropsWithChildren<AlertDialogProps>> = (\n props\n) => {\n const { slotProps = {}, children } = props;\n const triggerProps = slotProps.trigger ?? {};\n return <AlertDialogTrigger asChild {...triggerProps}>{children}</AlertDialogTrigger>;\n};\n\nconst RenderAlertDialogHeader: FC<PropsWithChildren<AlertDialogProps>> = (props) => {\n const {\n title = '',\n description = '',\n slotProps = {},\n children,\n } = props;\n\n const headerProps = slotProps.header ?? {};\n const titleProps = slotProps.title ?? {};\n const descriptionProps = slotProps.description ?? {};\n\n if(children) {\n return isValidReactElement(children, AlertDialogHeader)\n ? cloneElement<AlertDialogHeaderProps>(\n children as ReactElement<AlertDialogHeaderProps>,\n { ...((children as ReactElement<AlertDialogHeaderProps>).props || {}), ...headerProps }\n )\n : <AlertDialogHeader {...headerProps}>{children}</AlertDialogHeader>\n }\n\n return (\n <AlertDialogHeader>\n {Boolean(title) && isValidReactElement(title, AlertDialogTitle)\n ? cloneElement<AlertDialogTitleProps>(\n title as ReactElement<AlertDialogTitleProps>,\n { ...((title as ReactElement<AlertDialogTitleProps>).props || {}), ...titleProps }\n )\n : <AlertDialogTitle {...titleProps}>{title}</AlertDialogTitle>}\n\n {Boolean(description) && isValidReactElement(description, AlertDialogDescription)\n ? cloneElement<AlertDialogDescriptionProps>(\n description as ReactElement<AlertDialogDescriptionProps>,\n { ...((description as ReactElement<AlertDialogDescriptionProps>).props || {}), ...descriptionProps }\n )\n : <AlertDialogDescription {...descriptionProps}>{description}</AlertDialogDescription>\n }\n </AlertDialogHeader>\n )\n}\n\nconst RenderAlertDialogFooter: FC<PropsWithChildren<AlertDialogProps>> = (props) => {\n const {\n slotProps = {},\n children,\n onCancel,\n onConfirm,\n cancelLabel = 'Cancel',\n actionLabel = 'Continue',\n variant = 'confirm',\n } = props;\n const footerId = useId();\n\n const footerProps = slotProps.footer ?? {};\n const cancelButtonProps = slotProps.cancelButton ?? {};\n const actionButtonProps = slotProps.actionButton ?? {};\n\n if(children) {\n return isValidReactElement(children, AlertDialogFooter)\n ? cloneElement<AlertDialogFooterProps>(\n children as ReactElement<AlertDialogFooterProps>,\n { ...((children as ReactElement<AlertDialogFooterProps>).props || {}), ...footerProps }\n )\n : (\n <AlertDialogFooter {...footerProps}>\n {Children.map(children, (child, i) => {\n if(!child || !isValidReactElement(child)) return;\n\n const reactChild = child as ReactElement;\n const clonedChild = cloneElement(reactChild, {...(reactChild.props || {}), key: (reactChild.key || `footer-${footerId}-action-${i}` as unknown as Key)});\n\n if(isValidReactElement(child, AlertDialogAction) || isValidReactElement(child, AlertDialogCancel)) {\n return clonedChild;\n }\n\n return (\n <AlertDialogAction asChild>\n {clonedChild}\n </AlertDialogAction>\n )\n })}\n </AlertDialogFooter>\n )\n }\n\n return (\n <AlertDialogFooter>\n {variant !== 'alert' && (\n <AlertDialogCancel\n onClick={onCancel}\n {...cancelButtonProps}\n >\n {cancelLabel}\n </AlertDialogCancel>\n )}\n <AlertDialogAction\n onClick={onConfirm}\n {...actionButtonProps}\n variant={\n actionButtonProps.variant || variant === 'destructive' ? 'destructive' : 'default'\n }\n >\n {actionLabel}\n </AlertDialogAction>\n </AlertDialogFooter>\n )\n}\n\n/**\n * Component for show Alert Dialog.\n * @public\n * @see [Documentation](#)\n * @example\n * > Import:\n * ```tsx\n * import { AlertDialog } from '@oneplatformdev/ui/AlertDialog';\n * ```\n * > Simple example:\n * ```tsx\n * <AlertDialog\n * trigger={'Trigger text'} // may be any ReactNode | Button | string\n * variant='alert' // 'confirm' (default) | 'alert' | 'destructive'\n * title='Dialog title'\n * description='Description text...'\n * />\n * ```\n * > Base example:\n * ```tsx\n * <AlertDialog\n * trigger={<Button variant=\"outline\">Simple Trigger</Button>}\n * title='Dialog title'\n * description='Description text...'\n * onCancel={(event) => console.log(event, 'Cancel')}\n * onConfirm={(event) => console.log(event, 'Confirm')}\n * />\n * ```\n * > Trigger example: Button with icon children\n * ```tsx\n * <AlertDialog\n * trigger={<Button variant=\"outline\" size=\"icon\"><PencilLine /></Button>}\n * title=\"Dialog title with icon trigger\"\n * description=\"Description text...\"\n * onCancel={(event) => console.log(event, 'Cancel')}\n * onConfirm={(event) => console.log(event, 'Confirm')}\n * />\n * ```\n *\n * > Full content example:\n * ```tsx\n * <AlertDialog trigger={<Button variant=\"outline\">Full Content Trigger</Button>}>\n * Full Content...\n * </AlertDialog>\n * ```\n *\n * > Full control example:\n * ```tsx\n * <AlertDialog\n * open={true}\n * onOpenChange={(nextState) => console.log(nextState)}\n * trigger={<Button variant=\"outline\">Control Trigger</Button>}\n * header={<div>Custom Header</div>}\n * footer={[\n * <Button key='cancel' variant=\"outline\" onClick={() => {}}>On Action</Button>,\n * <Button key='action' variant=\"outline\" onClick={() => {}}>On Action</Button>,\n * ]}\n * />\n * ```\n */\nexport const AlertDialog: FC<PropsWithChildren<AlertDialogProps>> = (props) => {\n const {\n trigger,\n header,\n footer,\n slotProps = {},\n children,\n ...rest\n } = props;\n\n const contentProps = slotProps.content ?? {};\n\n return (\n <AlertDialogRoot {...rest}>\n <RenderAlertDialogTrigger {...props}>{trigger}</RenderAlertDialogTrigger>\n {children\n ? isValidReactElement(children, AlertDialogContent)\n ? cloneElement<AlertDialogContentProps>(\n children as ReactElement<AlertDialogContentProps>,\n {\n ...((children as ReactElement<AlertDialogContentProps>).props || {}),\n ...contentProps\n })\n : <AlertDialogContent {...contentProps}>{children}</AlertDialogContent>\n : (\n <AlertDialogContent {...contentProps}>\n <RenderAlertDialogHeader {...props}>{header}</RenderAlertDialogHeader>\n <RenderAlertDialogFooter {...props}>{footer}</RenderAlertDialogFooter>\n </AlertDialogContent>\n )\n }\n </AlertDialogRoot>\n )\n}\n\nexport default AlertDialog;\n"],"names":["RenderAlertDialogTrigger","props","slotProps","children","triggerProps","AlertDialogTrigger","RenderAlertDialogHeader","title","description","headerProps","titleProps","descriptionProps","isValidReactElement","AlertDialogHeader","cloneElement","jsx","AlertDialogTitle","AlertDialogDescription","RenderAlertDialogFooter","onCancel","onConfirm","cancelLabel","actionLabel","variant","footerId","useId","footerProps","cancelButtonProps","actionButtonProps","AlertDialogFooter","child","i","reactChild","clonedChild","AlertDialogAction","AlertDialogCancel","AlertDialog","trigger","header","footer","rest","contentProps","jsxs","AlertDialogRoot","AlertDialogContent"],"mappings":";;;;AA+BA,MAAMA,IAAoE,CACxEC,MACG;AACH,QAAM,EAAE,WAAAC,IAAY,IAAI,UAAAC,MAAaF,GAC/BG,IAAeF,EAAU,WAAW,CAAA;AAC1C,2BAAQG,GAAA,EAAmB,SAAO,IAAE,GAAGD,GAAe,UAAAD,GAAS;AACjE,GAEMG,IAAmE,CAACL,MAAU;AAClF,QAAM;AAAA,IACJ,OAAAM,IAAQ;AAAA,IACR,aAAAC,IAAc;AAAA,IACd,WAAAN,IAAY,CAAA;AAAA,IACZ,UAAAC;AAAA,EAAA,IACEF,GAEEQ,IAAcP,EAAU,UAAU,CAAA,GAClCQ,IAAaR,EAAU,SAAS,CAAA,GAChCS,IAAmBT,EAAU,eAAe,CAAA;AAElD,SAAGC,IACMS,EAAoBT,GAAUU,CAAiB,IAClDC;AAAA,IACAX;AAAA,IACA,EAAE,GAAKA,EAAkD,SAAS,CAAA,GAAK,GAAGM,EAAA;AAAA,EAAY,IAEtF,gBAAAM,EAACF,GAAA,EAAmB,GAAGJ,GAAc,UAAAN,EAAA,CAAS,sBAIjDU,GAAA,EACE,UAAA;AAAA,IAAQN,KAAUK,EAAoBL,GAAOS,CAAgB,IAC1DF;AAAA,MACAP;AAAA,MACA,EAAE,GAAKA,EAA8C,SAAS,CAAA,GAAK,GAAGG,EAAA;AAAA,IAAW,IAEjF,gBAAAK,EAACC,GAAA,EAAkB,GAAGN,GAAa,UAAAH,GAAM;AAAA,IA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children,\n cloneElement,\n FC,\n Key,\n PropsWithChildren,\n ReactElement,\n useId,\n} from 'react';\nimport {\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogContent,\n AlertDialogDescription,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogRoot,\n AlertDialogTitle,\n AlertDialogTrigger,\n} from './AlertDialogRoot';\nimport {\n AlertDialogDescriptionProps,\n AlertDialogFooterProps,\n AlertDialogHeaderProps,\n AlertDialogProps,\n AlertDialogTitleProps,\n} from './AlertDialog.types';\n\nimport { isValidReactElement } from '@oneplatformdev/utils';\n\nconst RenderAlertDialogTrigger: FC<PropsWithChildren<AlertDialogProps>> = (\n props\n) => {\n const { slotProps = {}, children } = props;\n const triggerProps = slotProps.trigger ?? {};\n return <AlertDialogTrigger asChild {...triggerProps}>{children}</AlertDialogTrigger>;\n};\n\nconst RenderAlertDialogHeader: FC<PropsWithChildren<AlertDialogProps>> = (props) => {\n const {\n title = '',\n description = '',\n slotProps = {},\n children,\n } = props;\n\n const headerProps = slotProps.header ?? {};\n const titleProps = slotProps.title ?? {};\n const descriptionProps = slotProps.description ?? {};\n\n if(children) {\n return isValidReactElement(children, AlertDialogHeader)\n ? cloneElement<AlertDialogHeaderProps>(\n children as ReactElement<AlertDialogHeaderProps>,\n { ...((children as ReactElement<AlertDialogHeaderProps>).props || {}), ...headerProps }\n )\n : <AlertDialogHeader {...headerProps}>{children}</AlertDialogHeader>\n }\n\n return (\n <AlertDialogHeader>\n {Boolean(title) && isValidReactElement(title, AlertDialogTitle)\n ? cloneElement<AlertDialogTitleProps>(\n title as ReactElement<AlertDialogTitleProps>,\n { ...((title as ReactElement<AlertDialogTitleProps>).props || {}), ...titleProps }\n )\n : <AlertDialogTitle {...titleProps}>{title}</AlertDialogTitle>}\n\n {Boolean(description) && isValidReactElement(description, AlertDialogDescription)\n ? cloneElement<AlertDialogDescriptionProps>(\n description as ReactElement<AlertDialogDescriptionProps>,\n { ...((description as ReactElement<AlertDialogDescriptionProps>).props || {}), ...descriptionProps }\n )\n : <AlertDialogDescription {...descriptionProps}>{description}</AlertDialogDescription>\n }\n </AlertDialogHeader>\n )\n}\n\nconst RenderAlertDialogFooter: FC<PropsWithChildren<AlertDialogProps>> = (props) => {\n const {\n slotProps = {},\n children,\n onCancel,\n onConfirm,\n cancelLabel = 'Cancel',\n actionLabel = 'Continue',\n variant = 'confirm',\n } = props;\n const footerId = useId();\n\n const footerProps = slotProps.footer ?? {};\n const cancelButtonProps = slotProps.cancelButton ?? {};\n const actionButtonProps = slotProps.actionButton ?? {};\n\n if(children) {\n return isValidReactElement(children, AlertDialogFooter)\n ? cloneElement<AlertDialogFooterProps>(\n children as ReactElement<AlertDialogFooterProps>,\n { ...((children as ReactElement<AlertDialogFooterProps>).props || {}), ...footerProps }\n )\n : (\n <AlertDialogFooter {...footerProps}>\n {Children.map(children, (child, i) => {\n if(!child || !isValidReactElement(child)) return;\n\n const reactChild = child as ReactElement;\n const clonedChild = cloneElement(reactChild, {...(reactChild.props || {}), key: (reactChild.key || `footer-${footerId}-action-${i}` as unknown as Key)});\n\n if(isValidReactElement(child, AlertDialogAction) || isValidReactElement(child, AlertDialogCancel)) {\n return clonedChild;\n }\n\n return (\n <AlertDialogAction asChild>\n {clonedChild}\n </AlertDialogAction>\n )\n })}\n </AlertDialogFooter>\n )\n }\n\n return (\n <AlertDialogFooter>\n {variant !== 'alert' && (\n <AlertDialogCancel\n onClick={onCancel}\n {...cancelButtonProps}\n >\n {cancelLabel}\n </AlertDialogCancel>\n )}\n <AlertDialogAction\n onClick={onConfirm}\n {...actionButtonProps}\n variant={\n actionButtonProps.variant || variant === 'destructive' ? 'destructive' : 'default'\n }\n >\n {actionLabel}\n </AlertDialogAction>\n </AlertDialogFooter>\n )\n}\n\n/**\n * Component for show Alert Dialog.\n * @public\n * @see [Documentation](#)\n * @example\n * > Import:\n * ```tsx\n * import { AlertDialog } from '@oneplatformdev/ui/AlertDialog';\n * ```\n * > Simple example:\n * ```tsx\n * <AlertDialog\n * trigger={'Trigger text'} // may be any ReactNode | Button | string\n * variant='alert' // 'confirm' (default) | 'alert' | 'destructive'\n * title='Dialog title'\n * description='Description text...'\n * />\n * ```\n * > Base example:\n * ```tsx\n * <AlertDialog\n * trigger={<Button variant=\"outline\">Simple Trigger</Button>}\n * title='Dialog title'\n * description='Description text...'\n * onCancel={(event) => console.log(event, 'Cancel')}\n * onConfirm={(event) => console.log(event, 'Confirm')}\n * />\n * ```\n * > Trigger example: Button with icon children\n * ```tsx\n * <AlertDialog\n * trigger={<Button variant=\"outline\" size=\"icon\"><PencilLine /></Button>}\n * title=\"Dialog title with icon trigger\"\n * description=\"Description text...\"\n * onCancel={(event) => console.log(event, 'Cancel')}\n * onConfirm={(event) => console.log(event, 'Confirm')}\n * />\n * ```\n *\n * > Full content example:\n * ```tsx\n * <AlertDialog trigger={<Button variant=\"outline\">Full Content Trigger</Button>}>\n * Full Content...\n * </AlertDialog>\n * ```\n *\n * > Full control example:\n * ```tsx\n * <AlertDialog\n * open={true}\n * onOpenChange={(nextState) => console.log(nextState)}\n * trigger={<Button variant=\"outline\">Control Trigger</Button>}\n * header={<div>Custom Header</div>}\n * footer={[\n * <Button key='cancel' variant=\"outline\" onClick={() => {}}>On Action</Button>,\n * <Button key='action' variant=\"outline\" onClick={() => {}}>On Action</Button>,\n * ]}\n * />\n * ```\n */\nexport const AlertDialog: FC<PropsWithChildren<AlertDialogProps>> = (props) => {\n const {\n trigger,\n header,\n footer,\n slotProps = {},\n children,\n ...rest\n } = props;\n\n const contentProps = slotProps.content ?? {};\n\n return (\n <AlertDialogRoot {...rest}>\n <RenderAlertDialogTrigger {...props}>{trigger}</RenderAlertDialogTrigger>\n {children\n ? <AlertDialogContent {...contentProps}>{children}</AlertDialogContent>\n : (\n <AlertDialogContent {...contentProps}>\n <RenderAlertDialogHeader {...props}>{header}</RenderAlertDialogHeader>\n <RenderAlertDialogFooter {...props}>{footer}</RenderAlertDialogFooter>\n </AlertDialogContent>\n )\n }\n </AlertDialogRoot>\n )\n}\n\nexport default AlertDialog;\n"],"names":["RenderAlertDialogTrigger","props","slotProps","children","triggerProps","AlertDialogTrigger","RenderAlertDialogHeader","title","description","headerProps","titleProps","descriptionProps","isValidReactElement","AlertDialogHeader","cloneElement","jsx","AlertDialogTitle","AlertDialogDescription","RenderAlertDialogFooter","onCancel","onConfirm","cancelLabel","actionLabel","variant","footerId","useId","footerProps","cancelButtonProps","actionButtonProps","AlertDialogFooter","child","i","reactChild","clonedChild","AlertDialogAction","AlertDialogCancel","AlertDialog","trigger","header","footer","rest","contentProps","jsxs","AlertDialogRoot","AlertDialogContent"],"mappings":";;;;AA8BA,MAAMA,IAAoE,CACxEC,MACG;AACH,QAAM,EAAE,WAAAC,IAAY,IAAI,UAAAC,MAAaF,GAC/BG,IAAeF,EAAU,WAAW,CAAA;AAC1C,2BAAQG,GAAA,EAAmB,SAAO,IAAE,GAAGD,GAAe,UAAAD,GAAS;AACjE,GAEMG,IAAmE,CAACL,MAAU;AAClF,QAAM;AAAA,IACJ,OAAAM,IAAQ;AAAA,IACR,aAAAC,IAAc;AAAA,IACd,WAAAN,IAAY,CAAA;AAAA,IACZ,UAAAC;AAAA,EAAA,IACEF,GAEEQ,IAAcP,EAAU,UAAU,CAAA,GAClCQ,IAAaR,EAAU,SAAS,CAAA,GAChCS,IAAmBT,EAAU,eAAe,CAAA;AAElD,SAAGC,IACMS,EAAoBT,GAAUU,CAAiB,IAClDC;AAAA,IACAX;AAAA,IACA,EAAE,GAAKA,EAAkD,SAAS,CAAA,GAAK,GAAGM,EAAA;AAAA,EAAY,IAEtF,gBAAAM,EAACF,GAAA,EAAmB,GAAGJ,GAAc,UAAAN,EAAA,CAAS,sBAIjDU,GAAA,EACE,UAAA;AAAA,IAAQN,KAAUK,EAAoBL,GAAOS,CAAgB,IAC1DF;AAAA,MACAP;AAAA,MACA,EAAE,GAAKA,EAA8C,SAAS,CAAA,GAAK,GAAGG,EAAA;AAAA,IAAW,IAEjF,gBAAAK,EAAC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AO,CAAC,2CAY3F;AAED,iBAAS,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,oBAAoB,CAAC,OAAO,CAAC,2CAmB3F;AAGD,iBAAS,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,2CAS5D;AAED,iBAAS,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,2CAY5D;AACD,iBAAS,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,oBAAoB,CAAC,KAAK,CAAC,2CASvF;AAED,iBAAS,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,oBAAoB,CAAC,WAAW,CAAC,2CASnG;AAGD,iBAAS,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,oBAAoB,CAAC,MAAM,CAAC,GAAG,WAAW,2CAQvG;AACD,iBAAS,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,oBAAoB,CAAC,MAAM,CAAC,GAAG,WAAW,2CAQvG;AAED,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACrB,CAAC"}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { jsx as o, jsxs as
|
|
2
|
-
import * as
|
|
3
|
-
import { cn as
|
|
1
|
+
import { jsx as o, jsxs as d } from "react/jsx-runtime";
|
|
2
|
+
import * as r from "@radix-ui/react-alert-dialog";
|
|
3
|
+
import { cn as l } from "@oneplatformdev/utils";
|
|
4
4
|
import "../Button/Button.js";
|
|
5
5
|
import { buttonVariants as i } from "../Button/buttonVariants.js";
|
|
6
6
|
function x(t) {
|
|
7
|
-
return /* @__PURE__ */ o(
|
|
7
|
+
return /* @__PURE__ */ o(r.Root, { "data-slot": "alert-dialog", ...t });
|
|
8
8
|
}
|
|
9
9
|
function N(t) {
|
|
10
|
-
return /* @__PURE__ */ o(
|
|
10
|
+
return /* @__PURE__ */ o(r.Trigger, { "data-slot": "alert-dialog-trigger", ...t });
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
return /* @__PURE__ */ o(
|
|
12
|
+
function c(t) {
|
|
13
|
+
return /* @__PURE__ */ o(r.Portal, { "data-slot": "alert-dialog-portal", asChild: !0, ...t });
|
|
14
14
|
}
|
|
15
15
|
function m(t) {
|
|
16
16
|
const { className: a, ...e } = t;
|
|
17
17
|
return /* @__PURE__ */ o(
|
|
18
|
-
|
|
18
|
+
r.Overlay,
|
|
19
19
|
{
|
|
20
20
|
"data-slot": "alert-dialog-overlay",
|
|
21
|
-
className:
|
|
21
|
+
className: l(
|
|
22
22
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
|
23
23
|
a
|
|
24
24
|
),
|
|
@@ -28,14 +28,18 @@ function m(t) {
|
|
|
28
28
|
}
|
|
29
29
|
function A(t) {
|
|
30
30
|
const { className: a, ...e } = t;
|
|
31
|
-
return /* @__PURE__ */ c
|
|
31
|
+
return /* @__PURE__ */ d(c, { children: [
|
|
32
32
|
/* @__PURE__ */ o(m, {}),
|
|
33
33
|
/* @__PURE__ */ o(
|
|
34
|
-
|
|
34
|
+
r.Content,
|
|
35
35
|
{
|
|
36
36
|
"data-slot": "alert-dialog-content",
|
|
37
|
-
className:
|
|
38
|
-
"
|
|
37
|
+
className: l(
|
|
38
|
+
"fixed top-[50%] left-[50%] z-50 translate-x-[-50%] translate-y-[-50%]",
|
|
39
|
+
"grid w-full max-w-[calc(100%-2rem)] sm:max-w-lg gap-4 p-6",
|
|
40
|
+
"bg-background border rounded-lg shadow-lg",
|
|
41
|
+
"overflow-x-hidden break-words",
|
|
42
|
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 duration-200",
|
|
39
43
|
a
|
|
40
44
|
),
|
|
41
45
|
...e
|
|
@@ -49,18 +53,18 @@ function D(t) {
|
|
|
49
53
|
"div",
|
|
50
54
|
{
|
|
51
55
|
"data-slot": "alert-dialog-header",
|
|
52
|
-
className:
|
|
56
|
+
className: l("flex flex-col gap-2 text-center sm:text-left", a),
|
|
53
57
|
...e
|
|
54
58
|
}
|
|
55
59
|
);
|
|
56
60
|
}
|
|
57
|
-
function
|
|
61
|
+
function w(t) {
|
|
58
62
|
const { className: a, ...e } = t;
|
|
59
63
|
return /* @__PURE__ */ o(
|
|
60
64
|
"div",
|
|
61
65
|
{
|
|
62
66
|
"data-slot": "alert-dialog-footer",
|
|
63
|
-
className:
|
|
67
|
+
className: l(
|
|
64
68
|
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
|
65
69
|
a
|
|
66
70
|
),
|
|
@@ -71,55 +75,55 @@ function v(t) {
|
|
|
71
75
|
function b(t) {
|
|
72
76
|
const { className: a, ...e } = t;
|
|
73
77
|
return /* @__PURE__ */ o(
|
|
74
|
-
|
|
78
|
+
r.Title,
|
|
75
79
|
{
|
|
76
80
|
"data-slot": "alert-dialog-title",
|
|
77
|
-
className:
|
|
81
|
+
className: l("text-lg font-semibold break-words", a),
|
|
78
82
|
...e
|
|
79
83
|
}
|
|
80
84
|
);
|
|
81
85
|
}
|
|
82
|
-
function
|
|
86
|
+
function v(t) {
|
|
83
87
|
const { className: a, ...e } = t;
|
|
84
88
|
return /* @__PURE__ */ o(
|
|
85
|
-
|
|
89
|
+
r.Description,
|
|
86
90
|
{
|
|
87
91
|
"data-slot": "alert-dialog-description",
|
|
88
|
-
className:
|
|
92
|
+
className: l("text-muted-foreground text-sm whitespace-pre-wrap break-words", a),
|
|
89
93
|
...e
|
|
90
94
|
}
|
|
91
95
|
);
|
|
92
96
|
}
|
|
93
|
-
function
|
|
97
|
+
function h(t) {
|
|
94
98
|
const { className: a, variant: e, size: s, ...n } = t;
|
|
95
99
|
return /* @__PURE__ */ o(
|
|
96
|
-
|
|
100
|
+
r.Action,
|
|
97
101
|
{
|
|
98
|
-
className:
|
|
102
|
+
className: l(i({ variant: e, size: s }), a),
|
|
99
103
|
...n
|
|
100
104
|
}
|
|
101
105
|
);
|
|
102
106
|
}
|
|
103
|
-
function
|
|
107
|
+
function z(t) {
|
|
104
108
|
const { className: a, variant: e = "outline", size: s, ...n } = t;
|
|
105
109
|
return /* @__PURE__ */ o(
|
|
106
|
-
|
|
110
|
+
r.Cancel,
|
|
107
111
|
{
|
|
108
|
-
className:
|
|
112
|
+
className: l(i({ variant: e, size: s }), a),
|
|
109
113
|
...n
|
|
110
114
|
}
|
|
111
115
|
);
|
|
112
116
|
}
|
|
113
117
|
export {
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
h as AlertDialogAction,
|
|
119
|
+
z as AlertDialogCancel,
|
|
116
120
|
A as AlertDialogContent,
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
v as AlertDialogDescription,
|
|
122
|
+
w as AlertDialogFooter,
|
|
119
123
|
D as AlertDialogHeader,
|
|
120
124
|
m as AlertDialogOverlay,
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
c as AlertDialogPortal,
|
|
126
|
+
r as AlertDialogPrimitive,
|
|
123
127
|
x as AlertDialogRoot,
|
|
124
128
|
b as AlertDialogTitle,
|
|
125
129
|
N as AlertDialogTrigger
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlertDialogRoot.js","sources":["../../src/AlertDialog/AlertDialogRoot.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';\n\nimport { cn } from '@oneplatformdev/utils';\nimport { ButtonProps, buttonVariants } from '../Button';\n\nfunction AlertDialogRoot(props: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {\n return <AlertDialogPrimitive.Root data-slot=\"alert-dialog\" {...props} />\n}\n\nfunction AlertDialogTrigger(props: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {\n return <AlertDialogPrimitive.Trigger data-slot=\"alert-dialog-trigger\" {...props} />;\n}\nfunction AlertDialogPortal(props: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {\n return <AlertDialogPrimitive.Portal data-slot=\"alert-dialog-portal\" asChild {...props} />;\n}\n\nfunction AlertDialogOverlay(props: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {\n const { className, ...rest } = props;\n return (\n <AlertDialogPrimitive.Overlay\n data-slot=\"alert-dialog-overlay\"\n className={cn(\n \"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50\",\n className\n )}\n {...rest}\n />\n )\n}\n\nfunction AlertDialogContent(props: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {\n const { className, ...rest } = props;\n return (\n <AlertDialogPortal>\n <AlertDialogOverlay />\n <AlertDialogPrimitive.Content\n data-slot=\"alert-dialog-content\"\n className={cn(\n
|
|
1
|
+
{"version":3,"file":"AlertDialogRoot.js","sources":["../../src/AlertDialog/AlertDialogRoot.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';\n\nimport { cn } from '@oneplatformdev/utils';\nimport { ButtonProps, buttonVariants } from '../Button';\n\nfunction AlertDialogRoot(props: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {\n return <AlertDialogPrimitive.Root data-slot=\"alert-dialog\" {...props} />\n}\n\nfunction AlertDialogTrigger(props: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {\n return <AlertDialogPrimitive.Trigger data-slot=\"alert-dialog-trigger\" {...props} />;\n}\nfunction AlertDialogPortal(props: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {\n return <AlertDialogPrimitive.Portal data-slot=\"alert-dialog-portal\" asChild {...props} />;\n}\n\nfunction AlertDialogOverlay(props: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {\n const { className, ...rest } = props;\n return (\n <AlertDialogPrimitive.Overlay\n data-slot=\"alert-dialog-overlay\"\n className={cn(\n \"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50\",\n className\n )}\n {...rest}\n />\n )\n}\n\nfunction AlertDialogContent(props: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {\n const { className, ...rest } = props;\n return (\n <AlertDialogPortal>\n <AlertDialogOverlay />\n <AlertDialogPrimitive.Content\n data-slot=\"alert-dialog-content\"\n className={cn(\n 'fixed top-[50%] left-[50%] z-50 translate-x-[-50%] translate-y-[-50%]',\n 'grid w-full max-w-[calc(100%-2rem)] sm:max-w-lg gap-4 p-6',\n 'bg-background border rounded-lg shadow-lg',\n 'overflow-x-hidden break-words',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 duration-200',\n className\n )}\n {...rest}\n />\n </AlertDialogPortal>\n )\n}\n\n\nfunction AlertDialogHeader(props: React.ComponentProps<\"div\">) {\n const { className, ...rest } = props;\n return (\n <div\n data-slot=\"alert-dialog-header\"\n className={cn(\"flex flex-col gap-2 text-center sm:text-left\", className)}\n {...rest}\n />\n )\n}\n\nfunction AlertDialogFooter(props: React.ComponentProps<\"div\">) {\n const { className, ...rest } = props;\n return (\n <div\n data-slot=\"alert-dialog-footer\"\n className={cn(\n \"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\",\n className\n )}\n {...rest}\n />\n )\n}\nfunction AlertDialogTitle(props: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {\n const { className, ...rest } = props;\n return (\n <AlertDialogPrimitive.Title\n data-slot=\"alert-dialog-title\"\n className={cn(\"text-lg font-semibold break-words\", className)}\n {...rest}\n />\n )\n}\n\nfunction AlertDialogDescription(props: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {\n const { className, ...rest } = props;\n return (\n <AlertDialogPrimitive.Description\n data-slot=\"alert-dialog-description\"\n className={cn(\"text-muted-foreground text-sm whitespace-pre-wrap break-words\", className)}\n {...rest}\n />\n )\n}\n\n\nfunction AlertDialogAction(props: React.ComponentProps<typeof AlertDialogPrimitive.Action> & ButtonProps) {\n const { className, variant, size, ...rest } = props;\n return (\n <AlertDialogPrimitive.Action\n className={cn(buttonVariants({ variant, size }), className)}\n {...rest}\n />\n )\n}\nfunction AlertDialogCancel(props: React.ComponentProps<typeof AlertDialogPrimitive.Cancel> & ButtonProps) {\n const { className, variant = 'outline', size, ...rest } = props\n return (\n <AlertDialogPrimitive.Cancel\n className={cn(buttonVariants({ variant, size }), className)}\n {...rest}\n />\n )\n}\n\nexport {\n AlertDialogRoot,\n AlertDialogPortal,\n AlertDialogOverlay,\n AlertDialogTrigger,\n AlertDialogContent,\n AlertDialogHeader,\n AlertDialogFooter,\n AlertDialogTitle,\n AlertDialogDescription,\n AlertDialogAction,\n AlertDialogCancel,\n AlertDialogPrimitive\n};\n"],"names":["AlertDialogRoot","props","AlertDialogPrimitive","AlertDialogTrigger","AlertDialogPortal","jsx","AlertDialogOverlay","className","rest","cn","AlertDialogContent","AlertDialogHeader","AlertDialogFooter","AlertDialogTitle","AlertDialogDescription","AlertDialogAction","variant","size","buttonVariants","AlertDialogCancel"],"mappings":";;;;;AAQA,SAASA,EAAgBC,GAA+D;AACtF,2BAAQC,EAAqB,MAArB,EAA0B,aAAU,gBAAgB,GAAGD,GAAO;AACxE;AAEA,SAASE,EAAmBF,GAAkE;AAC5F,2BAAQC,EAAqB,SAArB,EAA6B,aAAU,wBAAwB,GAAGD,GAAO;AACnF;AACA,SAASG,EAAkBH,GAAiE;AAC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AAE,WAAAM,GAAW,GAAGC,EAAA,IAASP;AAC/B,SACE,gBAAAI;AAAA,IAACH,EAAqB;AAAA,IAArB;AAAA,MACC,aAAU;AAAA,MACV,WAAWO,EAAG,qCAAqCF,CAAS;AAAA,MAC3D,GAAGC;AAAA,IAAA;AAAA,EAAA;AAGV;AAEA,SAASM,EAAuBb,GAAsE;AACpG,QAAM,EAAE,WAAAM,GAAW,GAAGC,EAAA,IAASP;AAC/B,SACE,gBAAAI;AAAA,IAACH,EAAqB;AAAA,IAArB;AAAA,MACC,aAAU;AAAA,MACV,WAAWO,EAAG,iEAAiEF,CAAS;AAAA,MACvF,GAAGC;AAAA,IAAA;AAAA,EAAA;AAGV;AAGA,SAASO,EAAkBd,GAA+E;AACxG,QAAM,EAAE,WAAAM,GAAW,SAAAS,GAAS,MAAAC,GAAM,GAAGT,MAASP;AAC9C,SACE,gBAAAI;AAAA,IAACH,EAAqB;AAAA,IAArB;AAAA,MACC,WAAWO,EAAGS,EAAe,EAAE,SAAAF,GAAS,MAAAC,EAAA,CAAM,GAAGV,CAAS;AAAA,MACzD,GAAGC;AAAA,IAAA;AAAA,EAAA;AAGV;AACA,SAASW,EAAkBlB,GAA+E;AACxG,QAAM,EAAE,WAAAM,GAAW,SAAAS,IAAU,WAAW,MAAAC,GAAM,GAAGT,MAASP;AAC1D,SACE,gBAAAI;AAAA,IAACH,EAAqB;AAAA,IAArB;AAAA,MACC,WAAWO,EAAGS,EAAe,EAAE,SAAAF,GAAS,MAAAC,EAAA,CAAM,GAAGV,CAAS;AAAA,MACzD,GAAGC;AAAA,IAAA;AAAA,EAAA;AAGV;"}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
## 0.1.10-109 (2025-12-15)
|
|
2
|
+
|
|
3
|
+
### 🧱 Updated Dependencies
|
|
4
|
+
|
|
5
|
+
- Updated @oneplatformdev/utils to 0.1.1-158
|
|
6
|
+
- Updated @oneplatformdev/hooks to 0.1.0-144
|
|
7
|
+
- Updated @oneplatformdev/tokens to 0.0.1-131
|
|
8
|
+
|
|
9
|
+
## 0.1.10-108 (2025-12-15)
|
|
10
|
+
|
|
11
|
+
### 🧱 Updated Dependencies
|
|
12
|
+
|
|
13
|
+
- Updated @oneplatformdev/utils to 0.1.1-157
|
|
14
|
+
- Updated @oneplatformdev/hooks to 0.1.0-143
|
|
15
|
+
- Updated @oneplatformdev/tokens to 0.0.1-130
|
|
16
|
+
|
|
17
|
+
## 0.1.10-107 (2025-12-15)
|
|
18
|
+
|
|
19
|
+
### 🧱 Updated Dependencies
|
|
20
|
+
|
|
21
|
+
- Updated @oneplatformdev/utils to 0.1.1-156
|
|
22
|
+
- Updated @oneplatformdev/hooks to 0.1.0-142
|
|
23
|
+
- Updated @oneplatformdev/tokens to 0.0.1-129
|
|
24
|
+
|
|
25
|
+
## 0.1.10-106 (2025-12-15)
|
|
26
|
+
|
|
27
|
+
### 🧱 Updated Dependencies
|
|
28
|
+
|
|
29
|
+
- Updated @oneplatformdev/utils to 0.1.1-155
|
|
30
|
+
- Updated @oneplatformdev/hooks to 0.1.0-141
|
|
31
|
+
- Updated @oneplatformdev/tokens to 0.0.1-128
|
|
32
|
+
|
|
33
|
+
## 0.1.10-105 (2025-12-15)
|
|
34
|
+
|
|
35
|
+
### 🧱 Updated Dependencies
|
|
36
|
+
|
|
37
|
+
- Updated @oneplatformdev/utils to 0.1.1-154
|
|
38
|
+
- Updated @oneplatformdev/hooks to 0.1.0-140
|
|
39
|
+
- Updated @oneplatformdev/tokens to 0.0.1-127
|
|
40
|
+
|
|
41
|
+
## 0.1.10-104 (2025-12-08)
|
|
42
|
+
|
|
43
|
+
### 🩹 Fixes
|
|
44
|
+
|
|
45
|
+
- update Dialog component title font size for better readability and add .env to .gitignore ([9646134](https://github.com/oneplatformdev/core-web/commit/9646134))
|
|
46
|
+
- adjust Dialog component styling for better alignment and update container size in CSS ([afaa5af](https://github.com/oneplatformdev/core-web/commit/afaa5af))
|
|
47
|
+
|
|
48
|
+
### 🧱 Updated Dependencies
|
|
49
|
+
|
|
50
|
+
- Updated @oneplatformdev/utils to 0.1.1-153
|
|
51
|
+
- Updated @oneplatformdev/hooks to 0.1.0-139
|
|
52
|
+
- Updated @oneplatformdev/tokens to 0.0.1-126
|
|
53
|
+
|
|
54
|
+
### ❤️ Thank You
|
|
55
|
+
|
|
56
|
+
- Bohdan Radchenko
|
|
57
|
+
|
|
1
58
|
## 0.1.10-103 (2025-12-04)
|
|
2
59
|
|
|
3
60
|
### 🩹 Fixes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.d.ts","sourceRoot":"","sources":["../../src/Combobox/Combobox.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Combobox.d.ts","sourceRoot":"","sources":["../../src/Combobox/Combobox.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAGL,aAAa,EACd,MAAM,kBAAkB,CAAC;AAqB1B,eAAO,MAAM,QAAQ,0GA+PpB,CAAC"}
|
package/Combobox/Combobox.js
CHANGED
|
@@ -1,173 +1,174 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { LoadingMask as
|
|
1
|
+
import { jsx as e, jsxs as d, Fragment as j } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as oe, useState as s, useCallback as p, useEffect as re, useMemo as M, useLayoutEffect as ae } from "react";
|
|
3
|
+
import { LoadingMask as V } from "../LoadingMask/LoadingMask.js";
|
|
4
4
|
import "../LoadingMask/RenderLoadingMask.js";
|
|
5
|
-
import { Popover as
|
|
5
|
+
import { Popover as ie, PopoverTrigger as se, PopoverContent as le } from "../Popover/Popover.js";
|
|
6
6
|
import { Button as ce } from "../Button/Button.js";
|
|
7
7
|
import "../Button/buttonVariants.js";
|
|
8
|
-
import { Command as de, CommandInput as pe, CommandList as
|
|
9
|
-
import { cn as
|
|
8
|
+
import { Command as de, CommandInput as pe, CommandList as me, CommandGroup as fe, CommandEmpty as X, CommandItem as ue } from "../Command/Command.js";
|
|
9
|
+
import { cn as R } from "@oneplatformdev/utils";
|
|
10
10
|
import { useDebounceCallback as he } from "@oneplatformdev/hooks";
|
|
11
11
|
import { X as ge, ChevronsUpDown as be } from "lucide-react";
|
|
12
12
|
import { ComboboxOptions as ve } from "./ComboboxOptions.js";
|
|
13
|
-
const
|
|
14
|
-
const { value:
|
|
15
|
-
if (!
|
|
16
|
-
const
|
|
17
|
-
return
|
|
18
|
-
}, Ee =
|
|
19
|
-
(S,
|
|
13
|
+
const ye = (S) => {
|
|
14
|
+
const { value: m, flattenOptions: n = [], selectedOption: L } = S;
|
|
15
|
+
if (!m) return "No value for render label";
|
|
16
|
+
const y = [n.find((f) => String(f.value).toLowerCase() === String(m).toLowerCase()), L].filter(Boolean).map((f) => f.label).find(Boolean);
|
|
17
|
+
return y || m;
|
|
18
|
+
}, Ee = oe(
|
|
19
|
+
(S, m) => {
|
|
20
20
|
const {
|
|
21
21
|
value: n,
|
|
22
|
-
onChange:
|
|
22
|
+
onChange: L,
|
|
23
23
|
placeholder: T,
|
|
24
|
-
disabled:
|
|
25
|
-
searchLabel:
|
|
26
|
-
fetchOptions:
|
|
27
|
-
options:
|
|
24
|
+
disabled: y,
|
|
25
|
+
searchLabel: f = "Type to search...",
|
|
26
|
+
fetchOptions: _,
|
|
27
|
+
options: N,
|
|
28
28
|
emptyLabel: A = "No options",
|
|
29
|
-
emptyAction:
|
|
29
|
+
emptyAction: C,
|
|
30
30
|
commandInputAction: I,
|
|
31
31
|
listHeadAction: w,
|
|
32
32
|
onMount: k
|
|
33
|
-
} = S,
|
|
34
|
-
const b = (
|
|
35
|
-
const
|
|
33
|
+
} = S, [F, z] = s(!1), [l, B] = s(!1), [a, P] = s(""), [u, D] = s(), [o, c] = s(!1), [r, J] = s([]), [K, Q] = s([]), h = p((t) => {
|
|
34
|
+
const b = (E) => {
|
|
35
|
+
const i = [], H = (x) => {
|
|
36
36
|
if (x)
|
|
37
37
|
for (const v of x)
|
|
38
|
-
|
|
38
|
+
i.push(v), v.items && v.items.length && H(v.items);
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
if (!
|
|
42
|
-
const O =
|
|
43
|
-
if (O) return [O, ...
|
|
40
|
+
H(E), Q((x) => {
|
|
41
|
+
if (!i.find((O) => !!n && String(O.value) === String(n))) {
|
|
42
|
+
const O = u || x.find((ne) => !!n && String(ne.value) === String(n));
|
|
43
|
+
if (O) return [O, ...i];
|
|
44
44
|
}
|
|
45
|
-
return
|
|
45
|
+
return i;
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
return b(
|
|
48
|
+
J((E) => {
|
|
49
|
+
const i = typeof t == "function" ? t(E) : t;
|
|
50
|
+
return b(i), i;
|
|
51
51
|
});
|
|
52
|
-
}, [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}, [
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
|
|
52
|
+
}, [u, n]);
|
|
53
|
+
re(() => {
|
|
54
|
+
N?.length && h(N);
|
|
55
|
+
}, [N]);
|
|
56
|
+
const Y = async () => {
|
|
57
|
+
l || (G(), P(""));
|
|
58
|
+
}, G = p(async (t) => {
|
|
59
|
+
c(!0);
|
|
60
60
|
try {
|
|
61
|
-
const b = await
|
|
61
|
+
const b = await _(t);
|
|
62
62
|
h(b);
|
|
63
63
|
} catch (b) {
|
|
64
64
|
console.error("Unexpected error while get option:", b);
|
|
65
65
|
} finally {
|
|
66
|
-
|
|
66
|
+
c(!1);
|
|
67
67
|
}
|
|
68
|
-
}, [h]),
|
|
68
|
+
}, [h]), Z = he(G, 1e3, {
|
|
69
69
|
leading: !1,
|
|
70
70
|
trailing: !0
|
|
71
|
-
}),
|
|
72
|
-
|
|
73
|
-
}, []),
|
|
74
|
-
|
|
75
|
-
}, []),
|
|
76
|
-
|
|
77
|
-
}, []),
|
|
71
|
+
}), $ = p((t) => {
|
|
72
|
+
c(!0), P(t), Z(t);
|
|
73
|
+
}, []), U = p((t) => {
|
|
74
|
+
L(t.value), D(t), c(!1);
|
|
75
|
+
}, []), ee = p(() => {
|
|
76
|
+
U({ value: "", label: "" }), D(void 0), c(!1);
|
|
77
|
+
}, []), W = M(() => !!a && !r.length && !o, [o, r.length, a]), q = M(() => !r.length && !o, [o, r.length, a]), g = M(() => ({
|
|
78
78
|
options: r,
|
|
79
79
|
setOptions: h,
|
|
80
|
-
selectedOption:
|
|
81
|
-
setSelectedOption:
|
|
80
|
+
selectedOption: u,
|
|
81
|
+
setSelectedOption: D,
|
|
82
82
|
search: a || "",
|
|
83
|
-
setSearch:
|
|
84
|
-
open:
|
|
85
|
-
setOpen:
|
|
83
|
+
setSearch: P,
|
|
84
|
+
open: l,
|
|
85
|
+
setOpen: B,
|
|
86
86
|
loading: o,
|
|
87
|
-
setLoading:
|
|
88
|
-
isEmptyList:
|
|
89
|
-
isSearchedEmptyList:
|
|
90
|
-
}), [o,
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
setLoading: c,
|
|
88
|
+
isEmptyList: q,
|
|
89
|
+
isSearchedEmptyList: W
|
|
90
|
+
}), [o, l, r, a, u, q, W, h]), te = p(async () => {
|
|
91
|
+
if (k) {
|
|
92
|
+
z(!0);
|
|
93
|
+
try {
|
|
94
|
+
await k(g);
|
|
95
|
+
} finally {
|
|
96
|
+
z(!1);
|
|
97
|
+
}
|
|
94
98
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}, [
|
|
99
|
-
|
|
100
|
-
B.current = !1;
|
|
101
|
-
}), []), /* @__PURE__ */ t("div", { className: "w-full", ref: u, children: /* @__PURE__ */ c(
|
|
102
|
-
se,
|
|
99
|
+
}, [k, g]);
|
|
100
|
+
return ae(() => {
|
|
101
|
+
te();
|
|
102
|
+
}, []), /* @__PURE__ */ e("div", { className: "w-full", ref: m, children: /* @__PURE__ */ d(
|
|
103
|
+
ie,
|
|
103
104
|
{
|
|
104
|
-
open:
|
|
105
|
-
onOpenChange: (
|
|
106
|
-
|
|
105
|
+
open: l,
|
|
106
|
+
onOpenChange: (t) => {
|
|
107
|
+
B(t), t && Y();
|
|
107
108
|
},
|
|
108
109
|
children: [
|
|
109
|
-
/* @__PURE__ */
|
|
110
|
+
/* @__PURE__ */ e(se, { asChild: !0, className: "border-input", children: /* @__PURE__ */ e(
|
|
110
111
|
ce,
|
|
111
112
|
{
|
|
112
113
|
variant: "outline",
|
|
113
114
|
role: "combobox",
|
|
114
115
|
size: "lg",
|
|
115
|
-
"aria-expanded":
|
|
116
|
-
className:
|
|
117
|
-
"w-full justify-between font-normal text-sm bg-transparent relative p-3",
|
|
116
|
+
"aria-expanded": l,
|
|
117
|
+
className: R(
|
|
118
|
+
"relative w-full justify-between font-normal text-sm bg-transparent relative p-3",
|
|
118
119
|
"border border-border",
|
|
119
|
-
|
|
120
|
+
l && "border-2 outline-hidden ring-1 ring-ring",
|
|
120
121
|
"focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring"
|
|
121
122
|
),
|
|
122
|
-
disabled:
|
|
123
|
-
children: [
|
|
124
|
-
/* @__PURE__ */
|
|
125
|
-
n ? /* @__PURE__ */
|
|
123
|
+
disabled: y || F,
|
|
124
|
+
children: F ? /* @__PURE__ */ e(V, { fullWidth: !0 }) : /* @__PURE__ */ d(j, { children: [
|
|
125
|
+
/* @__PURE__ */ e("span", { className: "truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap", children: n ? ye({ value: n, flattenOptions: K, selectedOption: u }) : /* @__PURE__ */ e("span", { className: "text-gray-400", children: T }) }),
|
|
126
|
+
n ? /* @__PURE__ */ e(
|
|
126
127
|
"div",
|
|
127
128
|
{
|
|
128
|
-
className:
|
|
129
|
+
className: R(
|
|
129
130
|
"absolute top-0 right-1",
|
|
130
131
|
"flex items-center justify-center",
|
|
131
132
|
"w-9 aspect-square [&_svg]:size-5",
|
|
132
133
|
"opacity-50 cursor-pointer hover:opacity-100"
|
|
133
134
|
),
|
|
134
|
-
onClick: (
|
|
135
|
-
|
|
135
|
+
onClick: (t) => {
|
|
136
|
+
t.stopPropagation(), ee();
|
|
136
137
|
},
|
|
137
|
-
children: /* @__PURE__ */
|
|
138
|
+
children: /* @__PURE__ */ e(ge, {})
|
|
138
139
|
}
|
|
139
|
-
) : /* @__PURE__ */
|
|
140
|
-
]
|
|
140
|
+
) : /* @__PURE__ */ e(be, { className: "opacity-50 w-4 h-4" })
|
|
141
|
+
] })
|
|
141
142
|
}
|
|
142
143
|
) }),
|
|
143
|
-
/* @__PURE__ */
|
|
144
|
+
/* @__PURE__ */ e(
|
|
144
145
|
le,
|
|
145
146
|
{
|
|
146
147
|
className: "w-(--radix-popper-anchor-width) max-w-none p-0",
|
|
147
148
|
align: "start",
|
|
148
|
-
children: /* @__PURE__ */
|
|
149
|
-
/* @__PURE__ */
|
|
149
|
+
children: /* @__PURE__ */ d(de, { shouldFilter: !1, children: [
|
|
150
|
+
/* @__PURE__ */ e(
|
|
150
151
|
pe,
|
|
151
152
|
{
|
|
152
|
-
placeholder:
|
|
153
|
+
placeholder: f,
|
|
153
154
|
value: a,
|
|
154
|
-
onValueChange:
|
|
155
|
+
onValueChange: $
|
|
155
156
|
}
|
|
156
157
|
),
|
|
157
158
|
typeof I == "function" ? I(g) : I,
|
|
158
|
-
/* @__PURE__ */
|
|
159
|
-
|
|
159
|
+
/* @__PURE__ */ e(me, { children: /* @__PURE__ */ d(
|
|
160
|
+
fe,
|
|
160
161
|
{
|
|
161
|
-
className:
|
|
162
|
+
className: R(!r.length && "p-0 shadow-none"),
|
|
162
163
|
children: [
|
|
163
|
-
o && /* @__PURE__ */
|
|
164
|
-
!o && !!a && /* @__PURE__ */
|
|
165
|
-
/* @__PURE__ */
|
|
166
|
-
typeof
|
|
167
|
-
] }) : /* @__PURE__ */
|
|
168
|
-
!o && /* @__PURE__ */
|
|
169
|
-
!!r.length && w && /* @__PURE__ */
|
|
170
|
-
|
|
164
|
+
o && /* @__PURE__ */ e(V, { fullWidth: !0 }),
|
|
165
|
+
!o && !!a && /* @__PURE__ */ e(j, { children: C ? /* @__PURE__ */ d(X, { className: "flex flex-col gap-3 py-5 px-3 items-center", children: [
|
|
166
|
+
/* @__PURE__ */ e("span", { children: A }),
|
|
167
|
+
typeof C == "function" ? C(g) : C
|
|
168
|
+
] }) : /* @__PURE__ */ e(X, { children: A }) }),
|
|
169
|
+
!o && /* @__PURE__ */ d(j, { children: [
|
|
170
|
+
!!r.length && w && /* @__PURE__ */ e(
|
|
171
|
+
ue,
|
|
171
172
|
{
|
|
172
173
|
asChild: !0,
|
|
173
174
|
className: "w-full",
|
|
@@ -175,13 +176,13 @@ const Ce = (S) => {
|
|
|
175
176
|
},
|
|
176
177
|
"combobox-list-head-action"
|
|
177
178
|
),
|
|
178
|
-
/* @__PURE__ */
|
|
179
|
+
/* @__PURE__ */ e(
|
|
179
180
|
ve,
|
|
180
181
|
{
|
|
181
182
|
value: n,
|
|
182
183
|
options: r,
|
|
183
|
-
onChangeOption:
|
|
184
|
-
setOpen:
|
|
184
|
+
onChangeOption: U,
|
|
185
|
+
setOpen: B
|
|
185
186
|
}
|
|
186
187
|
)
|
|
187
188
|
] })
|
package/Combobox/Combobox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.js","sources":["../../src/Combobox/Combobox.tsx"],"sourcesContent":["import {\n Dispatch,\n forwardRef, SetStateAction,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { LoadingMask } from '../LoadingMask';\nimport { Popover, PopoverContent, PopoverTrigger } from '../Popover';\nimport { Button } from '../Button';\nimport {\n Command,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from '../Command';\nimport { cn } from '@oneplatformdev/utils';\nimport { useDebounceCallback } from '@oneplatformdev/hooks';\nimport { ChevronsUpDown, X } from 'lucide-react';\nimport {\n ComboboxCallbackStateParams,\n ComboboxOption,\n ComboboxProps,\n} from './Combobox.types';\nimport { ComboboxOptions } from './ComboboxOptions'; // TODO: refactor next component | nlt code\n\n\nconst getSelectRenderLabel = (params: {\n value: ComboboxProps['value'];\n flattenOptions: ComboboxOption[];\n selectedOption?: ComboboxOption;\n}): string => {\n const { value, flattenOptions = [], selectedOption } = params;\n if(!value) return 'No value for render label';\n const flattenedOption = flattenOptions.find(o => String(o.value).toLowerCase() === String(value).toLowerCase());\n const label = [flattenedOption, selectedOption]\n .filter(Boolean)\n .map(o => o!.label)\n .find(Boolean);\n if(!label) return value;\n return label;\n}\n\n// TODO: refactor next component | nlt code\nexport const Combobox = forwardRef<HTMLDivElement, ComboboxProps>(\n (props, ref) => {\n const {\n value,\n onChange,\n placeholder,\n disabled,\n searchLabel = 'Type to search...',\n fetchOptions,\n options: itemOptions,\n emptyLabel = 'No options',\n emptyAction,\n commandInputAction,\n listHeadAction,\n onMount,\n } = props;\n const isMounted = useRef(false);\n const [open, setOpen] = useState(false);\n const [searchTerm, setSearchTerm] = useState('');\n const [selectedOption, setSelectedOption] = useState<ComboboxOption>();\n const [loading, setLoading] = useState(false);\n\n const [options, setOptionsDispatch] = useState<ComboboxOption[]>([]);\n const [flattenOptions, setFlattenOptions] = useState<ComboboxOption[]>([]);\n const setOptions: Dispatch<SetStateAction<ComboboxOption[]>> = useCallback((stater) => {\n const flatten = (next: ComboboxOption[]) => {\n const res: ComboboxOption[] = [];\n const walk = (nodes?: ComboboxOption[]) => {\n if (!nodes) return;\n for (const node of nodes) {\n res.push(node);\n if (node.items && node.items.length) walk(node.items);\n }\n };\n walk(next);\n setFlattenOptions((prev) => {\n const isIncludedInRes = res.find(o => !!value && String(o.value) === String(value));\n\n if(!isIncludedInRes) {\n const current = selectedOption || prev.find(o => !!value && String(o.value) === String(value))\n if(current) return [current, ...res];\n }\n\n return res;\n });\n }\n setOptionsDispatch((prev) => {\n const next: ComboboxOption[] = typeof stater === 'function' ? stater(prev) : stater;\n flatten(next);\n return next;\n });\n }, [selectedOption, value])\n\n useEffect(() => {\n itemOptions?.length && setOptions(itemOptions);\n }, [itemOptions]);\n\n const handlePopoverOpen = async () => {\n if (!open) {\n void getData();\n setSearchTerm('');\n }\n };\n\n const getData = useCallback(async (search?: string) => {\n setLoading(true);\n try {\n const fetchedOptions = await fetchOptions(search);\n setOptions(fetchedOptions);\n } catch (error) {\n console.error('Unexpected error while get option:', error);\n } finally {\n setLoading(false);\n }\n }, [setOptions]);\n\n const debouncedGetData = useDebounceCallback(getData, 1000, {\n leading: false,\n trailing: true,\n });\n\n const handleSearchChange = useCallback((value: string) => {\n setLoading(true);\n setSearchTerm(value);\n debouncedGetData(value);\n }, []);\n\n const onChangeOption = useCallback((option: ComboboxOption) => {\n onChange(option.value);\n setSelectedOption(option);\n setLoading(false);\n }, []);\n\n const handleClearSelection = useCallback(() => {\n onChangeOption({ value: '', label: '' });\n setSelectedOption(undefined);\n setLoading(false);\n }, []);\n\n const isSearchedEmptyList = useMemo(() => {\n return Boolean(searchTerm) && !options.length && !loading;\n }, [loading, options.length, searchTerm])\n\n const isEmptyList = useMemo(() => {\n return !options.length && !loading;\n }, [loading, options.length, searchTerm])\n\n const comboboxCallbackStateParams =\n useMemo((): ComboboxCallbackStateParams => {\n return {\n options,\n setOptions,\n selectedOption,\n setSelectedOption,\n search: searchTerm || '',\n setSearch: setSearchTerm,\n open,\n setOpen,\n loading,\n setLoading,\n isEmptyList,\n isSearchedEmptyList,\n };\n }, [loading, open, options, searchTerm, selectedOption, isEmptyList, isSearchedEmptyList, setOptions]);\n\n const runOnMount = useCallback(() => {\n if (!onMount) {\n isMounted.current = true;\n return;\n }\n onMount(comboboxCallbackStateParams)\n .finally(() => {\n isMounted.current = true;\n });\n }, [comboboxCallbackStateParams, onMount]);\n\n useLayoutEffect(() => {\n runOnMount();\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return (\n <div className=\"w-full\" ref={ref}>\n <Popover\n open={open}\n onOpenChange={(newOpen) => {\n setOpen(newOpen);\n if (newOpen) handlePopoverOpen();\n }}\n >\n <PopoverTrigger asChild className=\"border-input\">\n <Button\n variant=\"outline\"\n role=\"combobox\"\n size=\"lg\"\n aria-expanded={open}\n className={cn(\n 'w-full justify-between font-normal text-sm bg-transparent relative p-3',\n 'border border-border',\n open && 'border-2 outline-hidden ring-1 ring-ring',\n 'focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring'\n )}\n disabled={disabled}\n >\n <span className=\"truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap\">\n {value\n ? getSelectRenderLabel({ value, flattenOptions, selectedOption })\n : <span className=\"text-gray-400\">{placeholder}</span>\n }\n </span>\n {value ? (\n <div\n className={cn(\n 'absolute top-0 right-1',\n 'flex items-center justify-center',\n 'w-9 aspect-square [&_svg]:size-5',\n 'opacity-50 cursor-pointer hover:opacity-100'\n )}\n onClick={(e) => {\n e.stopPropagation();\n handleClearSelection();\n }}\n >\n <X />\n </div>\n ) : (\n <ChevronsUpDown className=\"opacity-50 w-4 h-4\" />\n )}\n </Button>\n </PopoverTrigger>\n <PopoverContent\n className=\"w-(--radix-popper-anchor-width) max-w-none p-0\"\n align=\"start\"\n >\n <Command shouldFilter={false}>\n <CommandInput\n placeholder={searchLabel}\n value={searchTerm}\n onValueChange={handleSearchChange}\n />\n {typeof commandInputAction === 'function'\n ? commandInputAction(comboboxCallbackStateParams)\n : commandInputAction}\n <CommandList>\n <CommandGroup\n className={cn(!options.length && 'p-0 shadow-none')}\n >\n {loading && <LoadingMask fullWidth />}\n {!loading && Boolean(searchTerm) && (\n <>\n {emptyAction ? (\n <CommandEmpty className=\"flex flex-col gap-3 py-5 px-3 items-center\">\n <span>{emptyLabel}</span>\n {typeof emptyAction === 'function'\n ? emptyAction(comboboxCallbackStateParams)\n : emptyAction}\n </CommandEmpty>\n ) : (\n <CommandEmpty>{emptyLabel}</CommandEmpty>\n )}\n </>\n )}\n {!loading && (\n <>\n {Boolean(options.length) && listHeadAction && (\n <CommandItem\n key='combobox-list-head-action'\n asChild\n className='w-full'\n >\n {typeof listHeadAction === 'function'\n ? listHeadAction(comboboxCallbackStateParams)\n : listHeadAction}\n </CommandItem>\n )}\n <ComboboxOptions\n value={value}\n options={options}\n onChangeOption={onChangeOption}\n setOpen={setOpen}\n />\n </>\n )}\n </CommandGroup>\n </CommandList>\n </Command>\n </PopoverContent>\n </Popover>\n </div>\n );\n }\n);\n"],"names":["getSelectRenderLabel","params","value","flattenOptions","selectedOption","label","o","Combobox","forwardRef","props","ref","onChange","placeholder","disabled","searchLabel","fetchOptions","itemOptions","emptyLabel","emptyAction","commandInputAction","listHeadAction","onMount","isMounted","useRef","open","setOpen","useState","searchTerm","setSearchTerm","setSelectedOption","loading","setLoading","options","setOptionsDispatch","setFlattenOptions","setOptions","useCallback","stater","flatten","next","res","walk","nodes","node","prev","current","useEffect","handlePopoverOpen","getData","search","fetchedOptions","error","debouncedGetData","useDebounceCallback","handleSearchChange","onChangeOption","option","handleClearSelection","isSearchedEmptyList","useMemo","isEmptyList","comboboxCallbackStateParams","runOnMount","useLayoutEffect","jsx","jsxs","Popover","newOpen","PopoverTrigger","Button","cn","X","ChevronsUpDown","PopoverContent","Command","CommandInput","CommandList","CommandGroup","LoadingMask","CommandEmpty","Fragment","CommandItem","ComboboxOptions"],"mappings":";;;;;;;;;;;;AAgCA,MAAMA,KAAuB,CAACC,MAIhB;AACZ,QAAM,EAAE,OAAAC,GAAO,gBAAAC,IAAiB,CAAA,GAAI,gBAAAC,MAAmBH;AACvD,MAAG,CAACC,EAAO,QAAO;AAElB,QAAMG,IAAQ,CADUF,EAAe,KAAK,CAAAG,MAAK,OAAOA,EAAE,KAAK,EAAE,YAAA,MAAkB,OAAOJ,CAAK,EAAE,aAAa,GAC9EE,CAAc,EAC3C,OAAO,OAAO,EACd,IAAI,CAAAE,MAAKA,EAAG,KAAK,EACjB,KAAK,OAAO;AACf,SAAID,KAAcH;AAEpB,GAGaK,KAAW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UAAA;AAAA,sBAAAF,KAAW,gBAAAkC,EAACc,IAAA,EAAY,WAAS,GAAA,CAAC;AAAA,sBAClC,CAAChD,KAAW,EAAQH,4BAEhB,UAAAT,IACC,gBAAA+C,EAACc,GAAA,EAAa,WAAU,8CACtB,UAAA;AAAA,wBAAA,gBAAAf,EAAC,UAAM,UAAA/C,EAAA,CAAW;AAAA,wBACjB,OAAOC,KAAgB,aACpBA,EAAY2C,CAA2B,IACvC3C;AAAA,sBAAA,EAAA,CACN,IAEA,gBAAA8C,EAACe,GAAA,EAAc,UAAA9D,EAAA,CAAW,GAE9B;AAAA,sBAED,CAACa,KACA,gBAAAmC,EAAAe,GAAA,EACG,UAAA;AAAA,wBAAA,EAAQhD,EAAQ,UAAWZ,KAC1B,gBAAA4C;AAAA,0BAACiB;AAAA,0BAAA;AAAA,4BAEC,SAAO;AAAA,4BACP,WAAU;AAAA,4BAET,UAAA,OAAO7D,KAAmB,aACvBA,EAAeyC,CAA2B,IAC1CzC;AAAA,0BAAA;AAAA,0BANA;AAAA,wBAAA;AAAA,wBASR,gBAAA4C;AAAA,0BAACkB;AAAA,0BAAA;AAAA,4BACC,OAAAhF;AAAA,4BACA,SAAA8B;AAAA,4BACA,gBAAAuB;AAAA,4BACA,SAAA9B;AAAA,0BAAA;AAAA,wBAAA;AAAA,sBACF,EAAA,CACF;AAAA,oBAAA;AAAA,kBAAA;AAAA,gBAAA,EAEJ,CACF;AAAA,cAAA,EAAA,CACF;AAAA,YAAA;AAAA,UAAA;AAAA,QACF;AAAA,MAAA;AAAA,IAAA,GAEJ;AAAA,EAEJ;AACF;"}
|
|
1
|
+
{"version":3,"file":"Combobox.js","sources":["../../src/Combobox/Combobox.tsx"],"sourcesContent":["import {\n Dispatch,\n forwardRef, SetStateAction,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useState,\n} from 'react';\nimport { LoadingMask } from '../LoadingMask';\nimport { Popover, PopoverContent, PopoverTrigger } from '../Popover';\nimport { Button } from '../Button';\nimport {\n Command,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from '../Command';\nimport { cn } from '@oneplatformdev/utils';\nimport { useDebounceCallback } from '@oneplatformdev/hooks';\nimport { ChevronsUpDown, X } from 'lucide-react';\nimport {\n ComboboxCallbackStateParams,\n ComboboxOption,\n ComboboxProps,\n} from './Combobox.types';\nimport { ComboboxOptions } from './ComboboxOptions'; // TODO: refactor next component | nlt code\n\n\nconst getSelectRenderLabel = (params: {\n value: ComboboxProps['value'];\n flattenOptions: ComboboxOption[];\n selectedOption?: ComboboxOption;\n}): string => {\n const { value, flattenOptions = [], selectedOption } = params;\n if(!value) return 'No value for render label';\n const flattenedOption = flattenOptions.find(o => String(o.value).toLowerCase() === String(value).toLowerCase());\n const label = [flattenedOption, selectedOption]\n .filter(Boolean)\n .map(o => o!.label)\n .find(Boolean);\n if(!label) return value;\n return label;\n}\n\n// TODO: refactor next component | nlt code\nexport const Combobox = forwardRef<HTMLDivElement, ComboboxProps>(\n (props, ref) => {\n const {\n value,\n onChange,\n placeholder,\n disabled,\n searchLabel = 'Type to search...',\n fetchOptions,\n options: itemOptions,\n emptyLabel = 'No options',\n emptyAction,\n commandInputAction,\n listHeadAction,\n onMount,\n } = props;\n const [initialLoading, setInitialLoading] = useState(false);\n const [open, setOpen] = useState(false);\n const [searchTerm, setSearchTerm] = useState('');\n const [selectedOption, setSelectedOption] = useState<ComboboxOption>();\n const [loading, setLoading] = useState(false);\n\n const [options, setOptionsDispatch] = useState<ComboboxOption[]>([]);\n const [flattenOptions, setFlattenOptions] = useState<ComboboxOption[]>([]);\n const setOptions: Dispatch<SetStateAction<ComboboxOption[]>> = useCallback((stater) => {\n const flatten = (next: ComboboxOption[]) => {\n const res: ComboboxOption[] = [];\n const walk = (nodes?: ComboboxOption[]) => {\n if (!nodes) return;\n for (const node of nodes) {\n res.push(node);\n if (node.items && node.items.length) walk(node.items);\n }\n };\n walk(next);\n setFlattenOptions((prev) => {\n const isIncludedInRes = res.find(o => !!value && String(o.value) === String(value));\n\n if(!isIncludedInRes) {\n const current = selectedOption || prev.find(o => !!value && String(o.value) === String(value))\n if(current) return [current, ...res];\n }\n\n return res;\n });\n }\n setOptionsDispatch((prev) => {\n const next: ComboboxOption[] = typeof stater === 'function' ? stater(prev) : stater;\n flatten(next);\n return next;\n });\n }, [selectedOption, value])\n\n useEffect(() => {\n itemOptions?.length && setOptions(itemOptions);\n }, [itemOptions]);\n\n const handlePopoverOpen = async () => {\n if (!open) {\n void getData();\n setSearchTerm('');\n }\n };\n\n const getData = useCallback(async (search?: string) => {\n setLoading(true);\n try {\n const fetchedOptions = await fetchOptions(search);\n setOptions(fetchedOptions);\n } catch (error) {\n console.error('Unexpected error while get option:', error);\n } finally {\n setLoading(false);\n }\n }, [setOptions]);\n\n const debouncedGetData = useDebounceCallback(getData, 1000, {\n leading: false,\n trailing: true,\n });\n\n const handleSearchChange = useCallback((value: string) => {\n setLoading(true);\n setSearchTerm(value);\n debouncedGetData(value);\n }, []);\n\n const onChangeOption = useCallback((option: ComboboxOption) => {\n onChange(option.value);\n setSelectedOption(option);\n setLoading(false);\n }, []);\n\n const handleClearSelection = useCallback(() => {\n onChangeOption({ value: '', label: '' });\n setSelectedOption(undefined);\n setLoading(false);\n }, []);\n\n const isSearchedEmptyList = useMemo(() => {\n return Boolean(searchTerm) && !options.length && !loading;\n }, [loading, options.length, searchTerm])\n\n const isEmptyList = useMemo(() => {\n return !options.length && !loading;\n }, [loading, options.length, searchTerm])\n\n const comboboxCallbackStateParams =\n useMemo((): ComboboxCallbackStateParams => {\n return {\n options,\n setOptions,\n selectedOption,\n setSelectedOption,\n search: searchTerm || '',\n setSearch: setSearchTerm,\n open,\n setOpen,\n loading,\n setLoading,\n isEmptyList,\n isSearchedEmptyList,\n };\n }, [loading, open, options, searchTerm, selectedOption, isEmptyList, isSearchedEmptyList, setOptions]);\n\n const runOnMount = useCallback(async () => {\n if (!onMount) return;\n setInitialLoading(true);\n try {\n await onMount(comboboxCallbackStateParams);\n } finally {\n setInitialLoading(false);\n }\n }, [onMount, comboboxCallbackStateParams]);\n\n useLayoutEffect(() => {\n runOnMount();\n }, []);\n\n return (\n <div className=\"w-full\" ref={ref}>\n <Popover\n open={open}\n onOpenChange={(newOpen) => {\n setOpen(newOpen);\n if (newOpen) handlePopoverOpen();\n }}\n >\n <PopoverTrigger asChild className=\"border-input\">\n <Button\n variant=\"outline\"\n role=\"combobox\"\n size=\"lg\"\n aria-expanded={open}\n className={cn(\n 'relative w-full justify-between font-normal text-sm bg-transparent relative p-3',\n 'border border-border',\n open && 'border-2 outline-hidden ring-1 ring-ring',\n 'focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring'\n )}\n disabled={disabled || initialLoading}\n >\n {initialLoading ? (\n <LoadingMask fullWidth />\n ) : (\n <>\n <span className=\"truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap\">\n {value\n ? getSelectRenderLabel({ value, flattenOptions, selectedOption })\n : <span className=\"text-gray-400\">{placeholder}</span>\n }\n </span>\n {value ? (\n <div\n className={cn(\n 'absolute top-0 right-1',\n 'flex items-center justify-center',\n 'w-9 aspect-square [&_svg]:size-5',\n 'opacity-50 cursor-pointer hover:opacity-100'\n )}\n onClick={(e) => {\n e.stopPropagation();\n handleClearSelection();\n }}\n >\n <X />\n </div>\n ) : (\n <ChevronsUpDown className=\"opacity-50 w-4 h-4\" />\n )}\n </>\n )}\n </Button>\n </PopoverTrigger>\n <PopoverContent\n className=\"w-(--radix-popper-anchor-width) max-w-none p-0\"\n align=\"start\"\n >\n <Command shouldFilter={false}>\n <CommandInput\n placeholder={searchLabel}\n value={searchTerm}\n onValueChange={handleSearchChange}\n />\n {typeof commandInputAction === 'function'\n ? commandInputAction(comboboxCallbackStateParams)\n : commandInputAction}\n <CommandList>\n <CommandGroup\n className={cn(!options.length && 'p-0 shadow-none')}\n >\n {loading && <LoadingMask fullWidth />}\n {!loading && Boolean(searchTerm) && (\n <>\n {emptyAction ? (\n <CommandEmpty className=\"flex flex-col gap-3 py-5 px-3 items-center\">\n <span>{emptyLabel}</span>\n {typeof emptyAction === 'function'\n ? emptyAction(comboboxCallbackStateParams)\n : emptyAction}\n </CommandEmpty>\n ) : (\n <CommandEmpty>{emptyLabel}</CommandEmpty>\n )}\n </>\n )}\n {!loading && (\n <>\n {Boolean(options.length) && listHeadAction && (\n <CommandItem\n key='combobox-list-head-action'\n asChild\n className='w-full'\n >\n {typeof listHeadAction === 'function'\n ? listHeadAction(comboboxCallbackStateParams)\n : listHeadAction}\n </CommandItem>\n )}\n <ComboboxOptions\n value={value}\n options={options}\n onChangeOption={onChangeOption}\n setOpen={setOpen}\n />\n </>\n )}\n </CommandGroup>\n </CommandList>\n </Command>\n </PopoverContent>\n </Popover>\n </div>\n );\n }\n);\n"],"names":["getSelectRenderLabel","params","value","flattenOptions","selectedOption","label","o","Combobox","forwardRef","props","ref","onChange","placeholder","disabled","searchLabel","fetchOptions","itemOptions","emptyLabel","emptyAction","commandInputAction","listHeadAction","onMount","initialLoading","setInitialLoading","useState","open","setOpen","searchTerm","setSearchTerm","setSelectedOption","loading","setLoading","options","setOptionsDispatch","setFlattenOptions","setOptions","useCallback","stater","flatten","next","res","walk","nodes","node","prev","current","useEffect","handlePopoverOpen","getData","search","fetchedOptions","error","debouncedGetData","useDebounceCallback","handleSearchChange","onChangeOption","option","handleClearSelection","isSearchedEmptyList","useMemo","isEmptyList","comboboxCallbackStateParams","runOnMount","useLayoutEffect","jsx","jsxs","Popover","newOpen","PopoverTrigger","Button","cn","LoadingMask","Fragment","e","X","ChevronsUpDown","PopoverContent","Command","CommandInput","CommandList","CommandGroup","CommandEmpty","CommandItem","ComboboxOptions"],"mappings":";;;;;;;;;;;;AA+BA,MAAMA,KAAuB,CAACC,MAIhB;AACZ,QAAM,EAAE,OAAAC,GAAO,gBAAAC,IAAiB,CAAA,GAAI,gBAAAC,MAAmBH;AACvD,MAAG,CAACC,EAAO,QAAO;AAElB,QAAM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AAA,CACF;AAAA,YAAA;AAAA,UAAA;AAAA,QACF;AAAA,MAAA;AAAA,IAAA,GAEJ;AAAA,EAEJ;AACF;"}
|
package/Search/Search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Search.d.ts","sourceRoot":"","sources":["../../src/Search/Search.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,eAAO,MAAM,MAAM,GAAI,OAAO,WAAW,
|
|
1
|
+
{"version":3,"file":"Search.d.ts","sourceRoot":"","sources":["../../src/Search/Search.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,eAAO,MAAM,MAAM,GAAI,OAAO,WAAW,4CAgDxC,CAAC"}
|
package/Search/Search.js
CHANGED
|
@@ -1,46 +1,48 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as g } from "react";
|
|
3
|
-
import { Input as
|
|
4
|
-
import { useDebounceCallback as
|
|
5
|
-
import { cn as
|
|
6
|
-
import { SearchIcon as
|
|
7
|
-
import { LoadedIcon as
|
|
8
|
-
const
|
|
1
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { useState as g, useEffect as v } from "react";
|
|
3
|
+
import { Input as C } from "../Input/Input.js";
|
|
4
|
+
import { useDebounceCallback as b } from "@oneplatformdev/hooks";
|
|
5
|
+
import { cn as x } from "@oneplatformdev/utils";
|
|
6
|
+
import { SearchIcon as I } from "lucide-react";
|
|
7
|
+
import { LoadedIcon as N } from "../LoadedIcon/LoadedIcon.js";
|
|
8
|
+
const E = (n) => {
|
|
9
9
|
const {
|
|
10
|
-
search:
|
|
11
|
-
onChange:
|
|
12
|
-
onSearch:
|
|
13
|
-
placeholder:
|
|
14
|
-
className:
|
|
15
|
-
loading:
|
|
16
|
-
slotProps:
|
|
17
|
-
name:
|
|
18
|
-
...
|
|
19
|
-
} =
|
|
20
|
-
const S =
|
|
21
|
-
|
|
10
|
+
search: e,
|
|
11
|
+
onChange: s,
|
|
12
|
+
onSearch: c,
|
|
13
|
+
placeholder: m = "Search",
|
|
14
|
+
className: i,
|
|
15
|
+
loading: l = !1,
|
|
16
|
+
slotProps: o,
|
|
17
|
+
name: h = "search",
|
|
18
|
+
...p
|
|
19
|
+
} = n, [u, a] = g(e), f = b(c, 1e3), d = (r) => {
|
|
20
|
+
const S = r.target.value;
|
|
21
|
+
a(S), s?.(r), f(r.target.value);
|
|
22
22
|
};
|
|
23
|
-
return
|
|
24
|
-
|
|
23
|
+
return v(() => {
|
|
24
|
+
a(e ?? "");
|
|
25
|
+
}, [e]), /* @__PURE__ */ t(
|
|
26
|
+
C,
|
|
25
27
|
{
|
|
26
|
-
name:
|
|
27
|
-
placeholder:
|
|
28
|
-
value:
|
|
29
|
-
className:
|
|
30
|
-
onChange:
|
|
31
|
-
...
|
|
32
|
-
...
|
|
28
|
+
name: h,
|
|
29
|
+
placeholder: m,
|
|
30
|
+
value: u,
|
|
31
|
+
className: x("min-w-[340px]", i),
|
|
32
|
+
onChange: d,
|
|
33
|
+
...p,
|
|
34
|
+
...o || {},
|
|
33
35
|
slotProps: {
|
|
34
|
-
...
|
|
36
|
+
...o || {},
|
|
35
37
|
input: {
|
|
36
|
-
startAdornment: /* @__PURE__ */
|
|
37
|
-
...
|
|
38
|
+
startAdornment: /* @__PURE__ */ t(N, { loading: l, size: "sm", children: /* @__PURE__ */ t(I, {}) }),
|
|
39
|
+
...o?.input || {}
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
);
|
|
42
44
|
};
|
|
43
45
|
export {
|
|
44
|
-
|
|
46
|
+
E as Search
|
|
45
47
|
};
|
|
46
48
|
//# sourceMappingURL=Search.js.map
|
package/Search/Search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Search.js","sources":["../../src/Search/Search.tsx"],"sourcesContent":["'use client';\n\nimport { ChangeEvent, useState } from 'react';\n\nimport { Input } from '../Input';\nimport { SearchProps } from './Search.types';\n\nimport { useDebounceCallback } from '@oneplatformdev/hooks';\nimport { cn } from '@oneplatformdev/utils';\nimport { SearchIcon } from 'lucide-react';\nimport { LoadedIcon } from '../LoadedIcon';\n\nexport const Search = (props: SearchProps) => {\n const {\n search: initialSearch,\n onChange: handleChange,\n onSearch,\n placeholder = 'Search',\n className,\n loading = false,\n slotProps,\n name = 'search',\n ...rest\n } = props;\n const [search, setSearch] = useState(initialSearch);\n const debounced = useDebounceCallback(onSearch, 1000);\n\n const onChange = (e: ChangeEvent<HTMLInputElement>) => {\n const v = e.target.value;\n setSearch(v);\n handleChange?.(e);\n debounced(e.target.value);\n };\n\n return (\n <Input\n name={name}\n placeholder={placeholder}\n value={search}\n className={cn('min-w-[340px]', className)}\n onChange={onChange}\n {...rest}\n {...(slotProps || {})}\n slotProps={{\n ...(slotProps || {}),\n input: {\n startAdornment: (\n <LoadedIcon loading={loading} size=\"sm\">\n <SearchIcon />\n </LoadedIcon>\n ),\n ...(slotProps?.input || {}),\n },\n }}\n />\n );\n};\n"],"names":["Search","props","initialSearch","handleChange","onSearch","placeholder","className","loading","slotProps","name","rest","search","setSearch","useState","debounced","useDebounceCallback","onChange","e","v","jsx","Input","cn","LoadedIcon","SearchIcon"],"mappings":";;;;;;;AAYO,MAAMA,IAAS,CAACC,MAAuB;AAC5C,QAAM;AAAA,IACJ,QAAQC;AAAA,IACR,UAAUC;AAAA,IACV,UAAAC;AAAA,IACA,aAAAC,IAAc;AAAA,IACd,WAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,WAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,GAAGC;AAAA,EAAA,IACDT,GACE,CAACU,GAAQC,CAAS,IAAIC,EAASX,CAAa,GAC5CY,IAAYC,EAAoBX,GAAU,GAAI,GAE9CY,IAAW,CAACC,MAAqC;AACrD,UAAMC,IAAID,EAAE,OAAO;AACnB,IAAAL,EAAUM,CAAC,GACXf,IAAec,CAAC,GAChBH,EAAUG,EAAE,OAAO,KAAK;AAAA,EAC1B;AAEA,
|
|
1
|
+
{"version":3,"file":"Search.js","sources":["../../src/Search/Search.tsx"],"sourcesContent":["'use client';\n\nimport { ChangeEvent, useEffect, useState } from 'react';\n\nimport { Input } from '../Input';\nimport { SearchProps } from './Search.types';\n\nimport { useDebounceCallback } from '@oneplatformdev/hooks';\nimport { cn } from '@oneplatformdev/utils';\nimport { SearchIcon } from 'lucide-react';\nimport { LoadedIcon } from '../LoadedIcon';\n\nexport const Search = (props: SearchProps) => {\n const {\n search: initialSearch,\n onChange: handleChange,\n onSearch,\n placeholder = 'Search',\n className,\n loading = false,\n slotProps,\n name = 'search',\n ...rest\n } = props;\n const [search, setSearch] = useState(initialSearch);\n const debounced = useDebounceCallback(onSearch, 1000);\n\n const onChange = (e: ChangeEvent<HTMLInputElement>) => {\n const v = e.target.value;\n setSearch(v);\n handleChange?.(e);\n debounced(e.target.value);\n };\n\n useEffect(() => {\n setSearch(initialSearch ?? '');\n }, [initialSearch]);\n\n return (\n <Input\n name={name}\n placeholder={placeholder}\n value={search}\n className={cn('min-w-[340px]', className)}\n onChange={onChange}\n {...rest}\n {...(slotProps || {})}\n slotProps={{\n ...(slotProps || {}),\n input: {\n startAdornment: (\n <LoadedIcon loading={loading} size=\"sm\">\n <SearchIcon />\n </LoadedIcon>\n ),\n ...(slotProps?.input || {}),\n },\n }}\n />\n );\n};\n"],"names":["Search","props","initialSearch","handleChange","onSearch","placeholder","className","loading","slotProps","name","rest","search","setSearch","useState","debounced","useDebounceCallback","onChange","e","v","useEffect","jsx","Input","cn","LoadedIcon","SearchIcon"],"mappings":";;;;;;;AAYO,MAAMA,IAAS,CAACC,MAAuB;AAC5C,QAAM;AAAA,IACJ,QAAQC;AAAA,IACR,UAAUC;AAAA,IACV,UAAAC;AAAA,IACA,aAAAC,IAAc;AAAA,IACd,WAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,WAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,GAAGC;AAAA,EAAA,IACDT,GACE,CAACU,GAAQC,CAAS,IAAIC,EAASX,CAAa,GAC5CY,IAAYC,EAAoBX,GAAU,GAAI,GAE9CY,IAAW,CAACC,MAAqC;AACrD,UAAMC,IAAID,EAAE,OAAO;AACnB,IAAAL,EAAUM,CAAC,GACXf,IAAec,CAAC,GAChBH,EAAUG,EAAE,OAAO,KAAK;AAAA,EAC1B;AAEA,SAAAE,EAAU,MAAM;AACd,IAAAP,EAAUV,KAAiB,EAAE;AAAA,EAC/B,GAAG,CAACA,CAAa,CAAC,GAGhB,gBAAAkB;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,MAAAZ;AAAA,MACA,aAAAJ;AAAA,MACA,OAAOM;AAAA,MACP,WAAWW,EAAG,iBAAiBhB,CAAS;AAAA,MACxC,UAAAU;AAAA,MACC,GAAGN;AAAA,MACH,GAAIF,KAAa,CAAA;AAAA,MAClB,WAAW;AAAA,QACT,GAAIA,KAAa,CAAA;AAAA,QACjB,OAAO;AAAA,UACL,kCACGe,GAAA,EAAW,SAAAhB,GAAkB,MAAK,MACjC,UAAA,gBAAAa,EAACI,KAAW,EAAA,CACd;AAAA,UAEF,GAAIhB,GAAW,SAAS,CAAA;AAAA,QAAC;AAAA,MAC3B;AAAA,IACF;AAAA,EAAA;AAGN;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneplatformdev/ui",
|
|
3
|
-
"version": "0.1.10-
|
|
3
|
+
"version": "0.1.10-109",
|
|
4
4
|
"description": "UI component library for OnePlatform",
|
|
5
5
|
"author": "One Platform Development Team",
|
|
6
6
|
"keywords": [
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
"recharts": "^3.2.0",
|
|
106
106
|
"sonner": "^2.0.7",
|
|
107
107
|
"vaul": "^1.1.2",
|
|
108
|
-
"@oneplatformdev/
|
|
109
|
-
"@oneplatformdev/
|
|
110
|
-
"@oneplatformdev/hooks": "^0.1.0-
|
|
108
|
+
"@oneplatformdev/utils": "^0.1.1-158",
|
|
109
|
+
"@oneplatformdev/tokens": "^0.0.1-131",
|
|
110
|
+
"@oneplatformdev/hooks": "^0.1.0-144"
|
|
111
111
|
}
|
|
112
112
|
}
|