@forgedevstack/bear 1.0.5 → 1.0.7
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/components/BottomSheet/BottomSheet.cjs +1 -0
- package/dist/components/BottomSheet/BottomSheet.d.ts +3 -0
- package/dist/components/BottomSheet/BottomSheet.js +102 -0
- package/dist/components/BottomSheet/BottomSheet.types.d.ts +13 -0
- package/dist/components/BottomSheet/index.d.ts +2 -0
- package/dist/components/Button/Button.cjs +1 -1
- package/dist/components/Button/Button.js +40 -38
- package/dist/components/Button/Button.types.d.ts +4 -0
- package/dist/components/Calendar/Calendar.cjs +1 -1
- package/dist/components/Calendar/Calendar.const.cjs +1 -1
- package/dist/components/Calendar/Calendar.const.d.ts +1 -0
- package/dist/components/Calendar/Calendar.const.js +6 -5
- package/dist/components/Calendar/Calendar.helpers.cjs +1 -1
- package/dist/components/Calendar/Calendar.helpers.js +4 -4
- package/dist/components/Calendar/Calendar.js +128 -128
- package/dist/components/Cascader/Cascader.cjs +1 -0
- package/dist/components/Cascader/Cascader.const.cjs +1 -0
- package/dist/components/Cascader/Cascader.const.d.ts +33 -0
- package/dist/components/Cascader/Cascader.const.js +21 -0
- package/dist/components/Cascader/Cascader.d.ts +17 -0
- package/dist/components/Cascader/Cascader.js +227 -0
- package/dist/components/Cascader/Cascader.types.d.ts +94 -0
- package/dist/components/Cascader/index.d.ts +2 -0
- package/dist/components/CommandPalette/CommandPalette.cjs +1 -0
- package/dist/components/CommandPalette/CommandPalette.const.cjs +1 -0
- package/dist/components/CommandPalette/CommandPalette.const.d.ts +25 -0
- package/dist/components/CommandPalette/CommandPalette.const.js +13 -0
- package/dist/components/CommandPalette/CommandPalette.d.ts +18 -0
- package/dist/components/CommandPalette/CommandPalette.js +190 -0
- package/dist/components/CommandPalette/CommandPalette.types.d.ts +90 -0
- package/dist/components/CommandPalette/CommandPalette.utils.cjs +1 -0
- package/dist/components/CommandPalette/CommandPalette.utils.d.ts +17 -0
- package/dist/components/CommandPalette/CommandPalette.utils.js +63 -0
- package/dist/components/CommandPalette/index.d.ts +2 -0
- package/dist/components/CreditInput/CreditInput.cjs +1 -0
- package/dist/components/CreditInput/CreditInput.const.cjs +1 -0
- package/dist/components/CreditInput/CreditInput.const.d.ts +37 -0
- package/dist/components/CreditInput/CreditInput.const.js +66 -0
- package/dist/components/CreditInput/CreditInput.d.ts +15 -0
- package/dist/components/CreditInput/CreditInput.js +214 -0
- package/dist/components/CreditInput/CreditInput.types.d.ts +93 -0
- package/dist/components/CreditInput/CreditInput.utils.cjs +1 -0
- package/dist/components/CreditInput/CreditInput.utils.d.ts +48 -0
- package/dist/components/CreditInput/CreditInput.utils.js +79 -0
- package/dist/components/CreditInput/index.d.ts +2 -0
- package/dist/components/DatePicker/DatePicker.cjs +1 -1
- package/dist/components/DatePicker/DatePicker.js +108 -84
- package/dist/components/DatePicker/DatePicker.types.d.ts +2 -1
- package/dist/components/Drawer/Drawer.cjs +1 -1
- package/dist/components/Drawer/Drawer.js +75 -44
- package/dist/components/EmojiPicker/EmojiPicker.cjs +1 -0
- package/dist/components/EmojiPicker/EmojiPicker.const.cjs +1 -0
- package/dist/components/EmojiPicker/EmojiPicker.const.d.ts +5 -0
- package/dist/components/EmojiPicker/EmojiPicker.const.js +10 -0
- package/dist/components/EmojiPicker/EmojiPicker.d.ts +3 -0
- package/dist/components/EmojiPicker/EmojiPicker.js +63 -0
- package/dist/components/EmojiPicker/EmojiPicker.types.d.ts +6 -0
- package/dist/components/EmojiPicker/index.d.ts +3 -0
- package/dist/components/Form/Form.cjs +1 -0
- package/dist/components/Form/Form.const.cjs +1 -0
- package/dist/components/Form/Form.const.d.ts +33 -0
- package/dist/components/Form/Form.const.js +27 -0
- package/dist/components/Form/Form.context.cjs +1 -0
- package/dist/components/Form/Form.context.d.ts +13 -0
- package/dist/components/Form/Form.context.js +12 -0
- package/dist/components/Form/Form.d.ts +18 -0
- package/dist/components/Form/Form.js +230 -0
- package/dist/components/Form/Form.types.d.ts +166 -0
- package/dist/components/Form/Form.utils.cjs +1 -0
- package/dist/components/Form/Form.utils.d.ts +17 -0
- package/dist/components/Form/Form.utils.js +31 -0
- package/dist/components/Form/index.d.ts +3 -0
- package/dist/components/Kanban/Kanban.cjs +1 -0
- package/dist/components/Kanban/Kanban.d.ts +3 -0
- package/dist/components/Kanban/Kanban.js +90 -0
- package/dist/components/Kanban/Kanban.types.d.ts +21 -0
- package/dist/components/Kanban/index.d.ts +2 -0
- package/dist/components/MentionsInput/MentionsInput.cjs +1 -0
- package/dist/components/MentionsInput/MentionsInput.d.ts +3 -0
- package/dist/components/MentionsInput/MentionsInput.js +140 -0
- package/dist/components/MentionsInput/MentionsInput.types.d.ts +21 -0
- package/dist/components/MentionsInput/index.d.ts +2 -0
- package/dist/components/NotificationCenter/NotificationCenter.cjs +1 -0
- package/dist/components/NotificationCenter/NotificationCenter.const.cjs +1 -0
- package/dist/components/NotificationCenter/NotificationCenter.const.d.ts +25 -0
- package/dist/components/NotificationCenter/NotificationCenter.const.js +28 -0
- package/dist/components/NotificationCenter/NotificationCenter.d.ts +15 -0
- package/dist/components/NotificationCenter/NotificationCenter.js +223 -0
- package/dist/components/NotificationCenter/NotificationCenter.types.d.ts +117 -0
- package/dist/components/NotificationCenter/NotificationCenter.utils.cjs +1 -0
- package/dist/components/NotificationCenter/NotificationCenter.utils.d.ts +11 -0
- package/dist/components/NotificationCenter/NotificationCenter.utils.js +19 -0
- package/dist/components/NotificationCenter/index.d.ts +2 -0
- package/dist/components/PhoneInput/PhoneInput.cjs +1 -0
- package/dist/components/PhoneInput/PhoneInput.const.cjs +1 -0
- package/dist/components/PhoneInput/PhoneInput.const.d.ts +33 -0
- package/dist/components/PhoneInput/PhoneInput.const.js +82 -0
- package/dist/components/PhoneInput/PhoneInput.d.ts +16 -0
- package/dist/components/PhoneInput/PhoneInput.js +194 -0
- package/dist/components/PhoneInput/PhoneInput.types.d.ts +108 -0
- package/dist/components/PhoneInput/PhoneInput.utils.cjs +1 -0
- package/dist/components/PhoneInput/PhoneInput.utils.d.ts +25 -0
- package/dist/components/PhoneInput/PhoneInput.utils.js +39 -0
- package/dist/components/PhoneInput/index.d.ts +2 -0
- package/dist/components/RichEditor/RichEditor.cjs +1 -1
- package/dist/components/RichEditor/RichEditor.const.cjs +2 -2
- package/dist/components/RichEditor/RichEditor.const.d.ts +4 -1
- package/dist/components/RichEditor/RichEditor.const.js +51 -18
- package/dist/components/RichEditor/RichEditor.js +106 -105
- package/dist/components/RichEditor/components/ToolbarColorPicker/ToolbarColorPicker.cjs +1 -1
- package/dist/components/RichEditor/components/ToolbarColorPicker/ToolbarColorPicker.js +105 -95
- package/dist/components/RichEditor/components/ToolbarMore/ToolbarMore.cjs +1 -1
- package/dist/components/RichEditor/components/ToolbarMore/ToolbarMore.d.ts +2 -0
- package/dist/components/RichEditor/components/ToolbarMore/ToolbarMore.js +47 -29
- package/dist/components/SegmentedControl/SegmentedControl.cjs +1 -0
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +3 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +58 -0
- package/dist/components/SegmentedControl/SegmentedControl.types.d.ts +16 -0
- package/dist/components/SegmentedControl/index.d.ts +2 -0
- package/dist/components/SignPad/SignPad.cjs +1 -1
- package/dist/components/SignPad/SignPad.js +94 -86
- package/dist/components/SliderRange/SliderRange.cjs +1 -0
- package/dist/components/SliderRange/SliderRange.d.ts +3 -0
- package/dist/components/SliderRange/SliderRange.js +142 -0
- package/dist/components/SliderRange/SliderRange.types.d.ts +17 -0
- package/dist/components/SliderRange/index.d.ts +2 -0
- package/dist/components/TagsInput/TagsInput.cjs +1 -0
- package/dist/components/TagsInput/TagsInput.d.ts +3 -0
- package/dist/components/TagsInput/TagsInput.js +100 -0
- package/dist/components/TagsInput/TagsInput.types.d.ts +16 -0
- package/dist/components/TagsInput/index.d.ts +2 -0
- package/dist/components/TimePicker/TimePicker.cjs +1 -1
- package/dist/components/TimePicker/TimePicker.constants.cjs +1 -1
- package/dist/components/TimePicker/TimePicker.constants.d.ts +22 -1
- package/dist/components/TimePicker/TimePicker.constants.js +36 -19
- package/dist/components/TimePicker/TimePicker.js +97 -131
- package/dist/components/TimePicker/TimePicker.types.d.ts +47 -6
- package/dist/components/TimePicker/components/TimePickerColumnsDropdown/TimePickerColumnsDropdown.cjs +1 -0
- package/dist/components/TimePicker/components/TimePickerColumnsDropdown/TimePickerColumnsDropdown.d.ts +3 -0
- package/dist/components/TimePicker/components/TimePickerColumnsDropdown/TimePickerColumnsDropdown.js +81 -0
- package/dist/components/TimePicker/components/TimePickerColumnsDropdown/index.d.ts +1 -0
- package/dist/components/TimePicker/components/TimePickerDialDropdown/TimePickerDialDropdown.cjs +1 -0
- package/dist/components/TimePicker/components/TimePickerDialDropdown/TimePickerDialDropdown.d.ts +3 -0
- package/dist/components/TimePicker/components/TimePickerDialDropdown/TimePickerDialDropdown.js +84 -0
- package/dist/components/TimePicker/components/TimePickerDialDropdown/index.d.ts +1 -0
- package/dist/components/TimePicker/helpers/ClockFaceSvg.cjs +1 -0
- package/dist/components/TimePicker/helpers/ClockFaceSvg.d.ts +18 -0
- package/dist/components/TimePicker/helpers/ClockFaceSvg.js +67 -0
- package/dist/components/TimePicker/helpers/index.d.ts +2 -0
- package/dist/components/TimePicker/index.d.ts +1 -1
- package/dist/components/VirtualList/VirtualList.cjs +1 -0
- package/dist/components/VirtualList/VirtualList.d.ts +3 -0
- package/dist/components/VirtualList/VirtualList.js +68 -0
- package/dist/components/VirtualList/VirtualList.types.d.ts +10 -0
- package/dist/components/VirtualList/index.d.ts +2 -0
- package/dist/components/index.cjs +1 -1
- package/dist/components/index.d.ts +28 -2
- package/dist/components/index.js +177 -146
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +36 -32
- package/dist/hooks/useDragDrop/index.d.ts +2 -0
- package/dist/hooks/useDragDrop/useDragDrop.cjs +1 -0
- package/dist/hooks/useDragDrop/useDragDrop.d.ts +22 -0
- package/dist/hooks/useDragDrop/useDragDrop.js +56 -0
- package/dist/hooks/useDragDrop/useDragDrop.types.d.ts +55 -0
- package/dist/hooks/useLazyLoad/index.d.ts +2 -0
- package/dist/hooks/useLazyLoad/useLazyLoad.cjs +1 -0
- package/dist/hooks/useLazyLoad/useLazyLoad.d.ts +26 -0
- package/dist/hooks/useLazyLoad/useLazyLoad.js +27 -0
- package/dist/hooks/useLazyLoad/useLazyLoad.types.d.ts +25 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +290 -255
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.cjs +0 -1
- package/dist/components/DateTimePicker/DateTimePicker.d.ts +0 -3
- package/dist/components/DateTimePicker/DateTimePicker.js +0 -178
- package/dist/components/DateTimePicker/DateTimePicker.types.d.ts +0 -26
- package/dist/components/DateTimePicker/DateTimePicker.utils.cjs +0 -1
- package/dist/components/DateTimePicker/DateTimePicker.utils.d.ts +0 -2
- package/dist/components/DateTimePicker/DateTimePicker.utils.js +0 -16
- package/dist/components/DateTimePicker/index.d.ts +0 -2
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsxs as m, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { useState as x } from "react";
|
|
3
|
+
import { cn as t } from "../../utils/cn.js";
|
|
4
|
+
import { BEAR_EMOJIS as d } from "./EmojiPicker.const.js";
|
|
5
|
+
const h = {
|
|
6
|
+
sm: "bear-w-8 bear-h-8 bear-text-lg",
|
|
7
|
+
md: "bear-w-10 bear-h-10 bear-text-xl",
|
|
8
|
+
lg: "bear-w-12 bear-h-12 bear-text-2xl"
|
|
9
|
+
}, i = Object.keys(d), u = ({
|
|
10
|
+
onSelect: a,
|
|
11
|
+
size: s = "md",
|
|
12
|
+
maxHeight: b = 280,
|
|
13
|
+
className: n
|
|
14
|
+
}) => {
|
|
15
|
+
const [o, c] = x(i[0]), g = d[o] ?? [];
|
|
16
|
+
return /* @__PURE__ */ m(
|
|
17
|
+
"div",
|
|
18
|
+
{
|
|
19
|
+
className: t(
|
|
20
|
+
"Bear-EmojiPicker bear-flex bear-flex-col bear-rounded-lg bear-bg-white dark:bear-bg-zinc-800 bear-border bear-border-gray-200 dark:bear-border-zinc-700 bear-shadow-lg bear-overflow-hidden",
|
|
21
|
+
n
|
|
22
|
+
),
|
|
23
|
+
children: [
|
|
24
|
+
/* @__PURE__ */ e("div", { className: "bear-flex bear-gap-1 bear-p-2 bear-border-b bear-border-gray-200 dark:bear-border-zinc-700 bear-overflow-x-auto", children: i.map((r) => /* @__PURE__ */ e(
|
|
25
|
+
"button",
|
|
26
|
+
{
|
|
27
|
+
type: "button",
|
|
28
|
+
onClick: () => c(r),
|
|
29
|
+
className: t(
|
|
30
|
+
"bear-px-3 bear-py-1.5 bear-rounded-md bear-text-sm bear-font-medium bear-transition-colors bear-shrink-0",
|
|
31
|
+
o === r ? "bear-bg-gray-200 dark:bear-bg-zinc-700 bear-text-gray-900 dark:bear-text-white" : "bear-text-gray-600 dark:bear-text-zinc-400 hover:bear-text-gray-900 dark:hover:bear-text-white hover:bear-bg-gray-100 dark:hover:bear-bg-zinc-700/50"
|
|
32
|
+
),
|
|
33
|
+
children: r
|
|
34
|
+
},
|
|
35
|
+
r
|
|
36
|
+
)) }),
|
|
37
|
+
/* @__PURE__ */ e(
|
|
38
|
+
"div",
|
|
39
|
+
{
|
|
40
|
+
className: "bear-p-2 bear-overflow-y-auto bear-grid bear-grid-cols-8 bear-gap-1 bear-bg-gray-50 dark:bear-bg-zinc-900/50",
|
|
41
|
+
style: { maxHeight: typeof b == "number" ? `${b}px` : b },
|
|
42
|
+
children: g.map((r, l) => /* @__PURE__ */ e(
|
|
43
|
+
"button",
|
|
44
|
+
{
|
|
45
|
+
type: "button",
|
|
46
|
+
onClick: () => a == null ? void 0 : a(r),
|
|
47
|
+
className: t(
|
|
48
|
+
"bear-flex bear-items-center bear-justify-center bear-rounded-lg bear-transition-colors hover:bear-bg-gray-200 dark:hover:bear-bg-zinc-700",
|
|
49
|
+
h[s]
|
|
50
|
+
),
|
|
51
|
+
children: r
|
|
52
|
+
},
|
|
53
|
+
`${r}-${l}`
|
|
54
|
+
))
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
u as EmojiPicker
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),l=require("react"),T=require("../../utils/cn.cjs"),B=require("./Form.context.cjs"),M=require("./Form.utils.cjs"),j=require("./Form.const.cjs"),q=({children:I,initialValues:u={},onSubmit:g,onError:a,layout:x="vertical",validateOnChange:b=!0,validateOnBlur:y=!0,className:v,testId:S,...C})=>{const[o,i]=l.useState(()=>({...j.FORM_INITIAL_STATE,fields:Object.fromEntries(Object.entries(u).map(([e,t])=>[e,{value:t,error:void 0,touched:!1,validating:!1,dirty:!1}]))})),c=l.useRef({}),_=l.useCallback((e,t)=>{i(s=>({...s,fields:{...s.fields,[e]:{...s.fields[e],value:t,dirty:!0}}}))},[]),n=l.useCallback(e=>{var t;return(t=o.fields[e])==null?void 0:t.value},[o.fields]),O=l.useCallback((e,t)=>{i(s=>({...s,fields:{...s.fields,[e]:{...s.fields[e],error:t}},errors:{...s.errors,[e]:t}}))},[]),E=l.useCallback(e=>{i(t=>{const s={...t.errors};return delete s[e],{...t,fields:{...t.fields,[e]:{...t.fields[e],error:void 0}},errors:s}})},[]),F=l.useCallback(async e=>{var f;const t=c.current[e];if(!t)return!0;i(d=>({...d,fields:{...d.fields,[e]:{...d.fields[e],validating:!0}}}));const s=(f=o.fields[e])==null?void 0:f.value,r=await M.validateFieldValue(s,t);return i(d=>({...d,fields:{...d.fields,[e]:{...d.fields[e],error:r??void 0,validating:!1}},errors:r?{...d.errors,[e]:r}:(()=>{const A={...d.errors};return delete A[e],A})()})),!r},[o.fields]),h=l.useCallback(async()=>{const e=Object.keys(c.current);return(await Promise.all(e.map(F))).every(Boolean)},[F]),R=l.useCallback(e=>{const t=e??u;i({...j.FORM_INITIAL_STATE,fields:Object.fromEntries(Object.entries(t).map(([s,r])=>[s,{value:r,error:void 0,touched:!1,validating:!1,dirty:!1}]))})},[u]),k=l.useCallback((e,t)=>{var s;return t&&(c.current[e]=t),o.fields[e]||i(r=>({...r,fields:{...r.fields,[e]:{value:u[e]??"",error:void 0,touched:!1,validating:!1,dirty:!1}}})),{name:e,value:((s=o.fields[e])==null?void 0:s.value)??u[e]??"",onChange:r=>{_(e,r),b&&t&&setTimeout(()=>F(e),0)},onBlur:()=>{i(r=>({...r,fields:{...r.fields,[e]:{...r.fields[e],touched:!0}}})),y&&t&&F(e)}}},[o.fields,u,_,F,b,y]),N=l.useCallback(e=>async t=>{if(t.preventDefault(),i(f=>({...f,isSubmitting:!0,isSubmitted:!0})),!await h()){i(f=>({...f,isSubmitting:!1})),a==null||a(o.errors);return}const r=Object.fromEntries(Object.entries(o.fields).map(([f,d])=>[f,d.value]));try{await e(r)}finally{i(f=>({...f,isSubmitting:!1}))}},[h,o.fields,o.errors,a]),L=l.useMemo(()=>({state:o,register:k,setValue:_,getValue:n,setError:O,clearError:E,validateField:F,validateForm:h,reset:R,handleSubmit:N,layout:x}),[o,k,_,n,O,E,F,h,R,N,x]);return m.jsx(B.FormContext.Provider,{value:L,children:m.jsx("form",{className:T.cn("Bear-Form",j.FORM_LAYOUT_CLASSES[x],v),onSubmit:g?N(g):void 0,"data-testid":S,...C,children:I})})},w=({name:I,label:u,required:g,rules:a,helperText:x,children:b,className:y})=>{const{register:v,state:S,layout:C}=B.useFormContext(),o={...a,required:g??(a==null?void 0:a.required)},i=v(I,o),c=S.fields[I],_=(c==null?void 0:c.touched)&&(c==null?void 0:c.error);return m.jsxs("div",{className:T.cn("Bear-FormItem",j.FORM_ITEM_LAYOUT_CLASSES[C],y),children:[u&&m.jsxs("label",{className:T.cn("Bear-FormItem__label bear-text-sm bear-font-medium bear-text-zinc-300",C==="horizontal"&&j.FORM_LABEL_WIDTH_HORIZONTAL),children:[u,(g||(a==null?void 0:a.required))&&m.jsx("span",{className:"Bear-FormItem__required bear-text-red-500 bear-ml-0.5",children:"*"})]}),m.jsxs("div",{className:"Bear-FormItem__content bear-flex-1",children:[m.jsx("div",{className:"Bear-FormItem__control",children:typeof b=="function"?b(i):l.isValidElement(b)?l.cloneElement(b,{...i,onChange:n=>{const O=n&&typeof n=="object"&&"target"in n&&n.target&&typeof n.target.value<"u"?n.target.value:n;i.onChange(O)}}):b}),_&&m.jsx("p",{className:"Bear-FormItem__error bear-mt-1 bear-text-xs bear-text-red-400",children:c.error}),x&&!_&&m.jsx("p",{className:"Bear-FormItem__helper bear-mt-1 bear-text-xs bear-text-zinc-500",children:x})]})]})};q.Item=w;exports.Form=q;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={required:"This field is required",email:"Please enter a valid email address",pattern:"Invalid format"},r={fields:{},isSubmitting:!1,isValid:!0,isSubmitted:!1,errors:{}},a=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,l={vertical:"Bear-Form--vertical bear-flex bear-flex-col bear-gap-4",horizontal:"Bear-Form--horizontal bear-flex bear-flex-col bear-gap-4",inline:"Bear-Form--inline bear-flex bear-flex-wrap bear-items-end bear-gap-4"},i={vertical:"Bear-FormItem--vertical bear-flex bear-flex-col bear-gap-1.5",horizontal:"Bear-FormItem--horizontal bear-flex bear-flex-row bear-items-start bear-gap-4",inline:"Bear-FormItem--inline bear-flex bear-flex-col bear-gap-1"},t="bear-w-32 bear-shrink-0";exports.EMAIL_REGEX=a;exports.FORM_DEFAULT_TRANSLATIONS=e;exports.FORM_INITIAL_STATE=r;exports.FORM_ITEM_LAYOUT_CLASSES=i;exports.FORM_LABEL_WIDTH_HORIZONTAL=t;exports.FORM_LAYOUT_CLASSES=l;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { FormTranslations, FormState } from './Form.types';
|
|
2
|
+
/**
|
|
3
|
+
* Default form translations
|
|
4
|
+
*/
|
|
5
|
+
export declare const FORM_DEFAULT_TRANSLATIONS: FormTranslations;
|
|
6
|
+
/**
|
|
7
|
+
* Initial form state
|
|
8
|
+
*/
|
|
9
|
+
export declare const FORM_INITIAL_STATE: FormState;
|
|
10
|
+
/**
|
|
11
|
+
* Email validation regex
|
|
12
|
+
*/
|
|
13
|
+
export declare const EMAIL_REGEX: RegExp;
|
|
14
|
+
/**
|
|
15
|
+
* Layout classes
|
|
16
|
+
*/
|
|
17
|
+
export declare const FORM_LAYOUT_CLASSES: {
|
|
18
|
+
readonly vertical: "Bear-Form--vertical bear-flex bear-flex-col bear-gap-4";
|
|
19
|
+
readonly horizontal: "Bear-Form--horizontal bear-flex bear-flex-col bear-gap-4";
|
|
20
|
+
readonly inline: "Bear-Form--inline bear-flex bear-flex-wrap bear-items-end bear-gap-4";
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Form item layout classes
|
|
24
|
+
*/
|
|
25
|
+
export declare const FORM_ITEM_LAYOUT_CLASSES: {
|
|
26
|
+
readonly vertical: "Bear-FormItem--vertical bear-flex bear-flex-col bear-gap-1.5";
|
|
27
|
+
readonly horizontal: "Bear-FormItem--horizontal bear-flex bear-flex-row bear-items-start bear-gap-4";
|
|
28
|
+
readonly inline: "Bear-FormItem--inline bear-flex bear-flex-col bear-gap-1";
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Label width for horizontal layout
|
|
32
|
+
*/
|
|
33
|
+
export declare const FORM_LABEL_WIDTH_HORIZONTAL = "bear-w-32 bear-shrink-0";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const e = {
|
|
2
|
+
required: "This field is required",
|
|
3
|
+
email: "Please enter a valid email address",
|
|
4
|
+
pattern: "Invalid format"
|
|
5
|
+
}, r = {
|
|
6
|
+
fields: {},
|
|
7
|
+
isSubmitting: !1,
|
|
8
|
+
isValid: !0,
|
|
9
|
+
isSubmitted: !1,
|
|
10
|
+
errors: {}
|
|
11
|
+
}, a = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i, l = {
|
|
12
|
+
vertical: "Bear-Form--vertical bear-flex bear-flex-col bear-gap-4",
|
|
13
|
+
horizontal: "Bear-Form--horizontal bear-flex bear-flex-col bear-gap-4",
|
|
14
|
+
inline: "Bear-Form--inline bear-flex bear-flex-wrap bear-items-end bear-gap-4"
|
|
15
|
+
}, i = {
|
|
16
|
+
vertical: "Bear-FormItem--vertical bear-flex bear-flex-col bear-gap-1.5",
|
|
17
|
+
horizontal: "Bear-FormItem--horizontal bear-flex bear-flex-row bear-items-start bear-gap-4",
|
|
18
|
+
inline: "Bear-FormItem--inline bear-flex bear-flex-col bear-gap-1"
|
|
19
|
+
}, t = "bear-w-32 bear-shrink-0";
|
|
20
|
+
export {
|
|
21
|
+
a as EMAIL_REGEX,
|
|
22
|
+
e as FORM_DEFAULT_TRANSLATIONS,
|
|
23
|
+
r as FORM_INITIAL_STATE,
|
|
24
|
+
i as FORM_ITEM_LAYOUT_CLASSES,
|
|
25
|
+
t as FORM_LABEL_WIDTH_HORIZONTAL,
|
|
26
|
+
l as FORM_LAYOUT_CLASSES
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),e=t.createContext(null),n=()=>{const o=t.useContext(e);if(!o)throw new Error("useFormContext must be used within a Form component");return o},r=()=>t.useContext(e);exports.FormContext=e;exports.useFormContext=n;exports.useFormContextSafe=r;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FormContextValue } from './Form.types';
|
|
2
|
+
/**
|
|
3
|
+
* Form context
|
|
4
|
+
*/
|
|
5
|
+
export declare const FormContext: import('react').Context<FormContextValue | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Hook to access form context
|
|
8
|
+
*/
|
|
9
|
+
export declare const useFormContext: () => FormContextValue;
|
|
10
|
+
/**
|
|
11
|
+
* Hook to safely access form context (returns null if not in Form)
|
|
12
|
+
*/
|
|
13
|
+
export declare const useFormContextSafe: () => FormContextValue | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createContext as n, useContext as o } from "react";
|
|
2
|
+
const e = n(null), s = () => {
|
|
3
|
+
const t = o(e);
|
|
4
|
+
if (!t)
|
|
5
|
+
throw new Error("useFormContext must be used within a Form component");
|
|
6
|
+
return t;
|
|
7
|
+
}, m = () => o(e);
|
|
8
|
+
export {
|
|
9
|
+
e as FormContext,
|
|
10
|
+
s as useFormContext,
|
|
11
|
+
m as useFormContextSafe
|
|
12
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { FormProps, FormItemProps } from './Form.types';
|
|
3
|
+
/**
|
|
4
|
+
* Form - Form management component with validation
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* <Form onSubmit={handleSubmit} initialValues={{ email: '' }}>
|
|
9
|
+
* <Form.Item name="email" label="Email" rules={{ required: true, email: true }}>
|
|
10
|
+
* <Input />
|
|
11
|
+
* </Form.Item>
|
|
12
|
+
* <Button type="submit">Submit</Button>
|
|
13
|
+
* </Form>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const Form: FC<FormProps> & {
|
|
17
|
+
Item: FC<FormItemProps>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { jsx as g, jsxs as B } from "react/jsx-runtime";
|
|
2
|
+
import { useState as M, useRef as V, useCallback as u, useMemo as q, isValidElement as z, cloneElement as k } from "react";
|
|
3
|
+
import { cn as E } from "../../utils/cn.js";
|
|
4
|
+
import { FormContext as D, useFormContext as H } from "./Form.context.js";
|
|
5
|
+
import { validateFieldValue as P } from "./Form.utils.js";
|
|
6
|
+
import { FORM_INITIAL_STATE as w, FORM_LAYOUT_CLASSES as U, FORM_LABEL_WIDTH_HORIZONTAL as Y, FORM_ITEM_LAYOUT_CLASSES as p } from "./Form.const.js";
|
|
7
|
+
const W = ({
|
|
8
|
+
children: I,
|
|
9
|
+
initialValues: n = {},
|
|
10
|
+
onSubmit: x,
|
|
11
|
+
onError: l,
|
|
12
|
+
layout: F = "vertical",
|
|
13
|
+
validateOnChange: m = !0,
|
|
14
|
+
validateOnBlur: h = !0,
|
|
15
|
+
className: N,
|
|
16
|
+
testId: S,
|
|
17
|
+
...v
|
|
18
|
+
}) => {
|
|
19
|
+
const [o, i] = M(() => ({
|
|
20
|
+
...w,
|
|
21
|
+
fields: Object.fromEntries(
|
|
22
|
+
Object.entries(n).map(([e, t]) => [
|
|
23
|
+
e,
|
|
24
|
+
{ value: t, error: void 0, touched: !1, validating: !1, dirty: !1 }
|
|
25
|
+
])
|
|
26
|
+
)
|
|
27
|
+
})), a = V({}), b = u((e, t) => {
|
|
28
|
+
i((r) => ({
|
|
29
|
+
...r,
|
|
30
|
+
fields: {
|
|
31
|
+
...r.fields,
|
|
32
|
+
[e]: {
|
|
33
|
+
...r.fields[e],
|
|
34
|
+
value: t,
|
|
35
|
+
dirty: !0
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
}, []), c = u((e) => {
|
|
40
|
+
var t;
|
|
41
|
+
return (t = o.fields[e]) == null ? void 0 : t.value;
|
|
42
|
+
}, [o.fields]), y = u((e, t) => {
|
|
43
|
+
i((r) => ({
|
|
44
|
+
...r,
|
|
45
|
+
fields: {
|
|
46
|
+
...r.fields,
|
|
47
|
+
[e]: {
|
|
48
|
+
...r.fields[e],
|
|
49
|
+
error: t
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
errors: { ...r.errors, [e]: t }
|
|
53
|
+
}));
|
|
54
|
+
}, []), A = u((e) => {
|
|
55
|
+
i((t) => {
|
|
56
|
+
const r = { ...t.errors };
|
|
57
|
+
return delete r[e], {
|
|
58
|
+
...t,
|
|
59
|
+
fields: {
|
|
60
|
+
...t.fields,
|
|
61
|
+
[e]: {
|
|
62
|
+
...t.fields[e],
|
|
63
|
+
error: void 0
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
errors: r
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}, []), _ = u(async (e) => {
|
|
70
|
+
var f;
|
|
71
|
+
const t = a.current[e];
|
|
72
|
+
if (!t) return !0;
|
|
73
|
+
i((d) => ({
|
|
74
|
+
...d,
|
|
75
|
+
fields: {
|
|
76
|
+
...d.fields,
|
|
77
|
+
[e]: {
|
|
78
|
+
...d.fields[e],
|
|
79
|
+
validating: !0
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}));
|
|
83
|
+
const r = (f = o.fields[e]) == null ? void 0 : f.value, s = await P(r, t);
|
|
84
|
+
return i((d) => ({
|
|
85
|
+
...d,
|
|
86
|
+
fields: {
|
|
87
|
+
...d.fields,
|
|
88
|
+
[e]: {
|
|
89
|
+
...d.fields[e],
|
|
90
|
+
error: s ?? void 0,
|
|
91
|
+
validating: !1
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
errors: s ? { ...d.errors, [e]: s } : (() => {
|
|
95
|
+
const T = { ...d.errors };
|
|
96
|
+
return delete T[e], T;
|
|
97
|
+
})()
|
|
98
|
+
})), !s;
|
|
99
|
+
}, [o.fields]), O = u(async () => {
|
|
100
|
+
const e = Object.keys(a.current);
|
|
101
|
+
return (await Promise.all(e.map(_))).every(Boolean);
|
|
102
|
+
}, [_]), L = u((e) => {
|
|
103
|
+
i({
|
|
104
|
+
...w,
|
|
105
|
+
fields: Object.fromEntries(
|
|
106
|
+
Object.entries(e ?? n).map(([r, s]) => [
|
|
107
|
+
r,
|
|
108
|
+
{ value: s, error: void 0, touched: !1, validating: !1, dirty: !1 }
|
|
109
|
+
])
|
|
110
|
+
)
|
|
111
|
+
});
|
|
112
|
+
}, [n]), R = u((e, t) => {
|
|
113
|
+
var r;
|
|
114
|
+
return t && (a.current[e] = t), o.fields[e] || i((s) => ({
|
|
115
|
+
...s,
|
|
116
|
+
fields: {
|
|
117
|
+
...s.fields,
|
|
118
|
+
[e]: {
|
|
119
|
+
value: n[e] ?? "",
|
|
120
|
+
error: void 0,
|
|
121
|
+
touched: !1,
|
|
122
|
+
validating: !1,
|
|
123
|
+
dirty: !1
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})), {
|
|
127
|
+
name: e,
|
|
128
|
+
value: ((r = o.fields[e]) == null ? void 0 : r.value) ?? n[e] ?? "",
|
|
129
|
+
onChange: (s) => {
|
|
130
|
+
b(e, s), m && t && setTimeout(() => _(e), 0);
|
|
131
|
+
},
|
|
132
|
+
onBlur: () => {
|
|
133
|
+
i((s) => ({
|
|
134
|
+
...s,
|
|
135
|
+
fields: {
|
|
136
|
+
...s.fields,
|
|
137
|
+
[e]: {
|
|
138
|
+
...s.fields[e],
|
|
139
|
+
touched: !0
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
})), h && t && _(e);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}, [o.fields, n, b, _, m, h]), j = u(
|
|
146
|
+
(e) => async (t) => {
|
|
147
|
+
if (t.preventDefault(), i((f) => ({ ...f, isSubmitting: !0, isSubmitted: !0 })), !await O()) {
|
|
148
|
+
i((f) => ({ ...f, isSubmitting: !1 })), l == null || l(o.errors);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const s = Object.fromEntries(
|
|
152
|
+
Object.entries(o.fields).map(([f, d]) => [f, d.value])
|
|
153
|
+
);
|
|
154
|
+
try {
|
|
155
|
+
await e(s);
|
|
156
|
+
} finally {
|
|
157
|
+
i((f) => ({ ...f, isSubmitting: !1 }));
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
[O, o.fields, o.errors, l]
|
|
161
|
+
), C = q(
|
|
162
|
+
() => ({
|
|
163
|
+
state: o,
|
|
164
|
+
register: R,
|
|
165
|
+
setValue: b,
|
|
166
|
+
getValue: c,
|
|
167
|
+
setError: y,
|
|
168
|
+
clearError: A,
|
|
169
|
+
validateField: _,
|
|
170
|
+
validateForm: O,
|
|
171
|
+
reset: L,
|
|
172
|
+
handleSubmit: j,
|
|
173
|
+
layout: F
|
|
174
|
+
}),
|
|
175
|
+
[o, R, b, c, y, A, _, O, L, j, F]
|
|
176
|
+
);
|
|
177
|
+
return /* @__PURE__ */ g(D.Provider, { value: C, children: /* @__PURE__ */ g(
|
|
178
|
+
"form",
|
|
179
|
+
{
|
|
180
|
+
className: E("Bear-Form", U[F], N),
|
|
181
|
+
onSubmit: x ? j(x) : void 0,
|
|
182
|
+
"data-testid": S,
|
|
183
|
+
...v,
|
|
184
|
+
children: I
|
|
185
|
+
}
|
|
186
|
+
) });
|
|
187
|
+
}, Z = ({
|
|
188
|
+
name: I,
|
|
189
|
+
label: n,
|
|
190
|
+
required: x,
|
|
191
|
+
rules: l,
|
|
192
|
+
helperText: F,
|
|
193
|
+
children: m,
|
|
194
|
+
className: h
|
|
195
|
+
}) => {
|
|
196
|
+
const { register: N, state: S, layout: v } = H(), o = {
|
|
197
|
+
...l,
|
|
198
|
+
required: x ?? (l == null ? void 0 : l.required)
|
|
199
|
+
}, i = N(I, o), a = S.fields[I], b = (a == null ? void 0 : a.touched) && (a == null ? void 0 : a.error);
|
|
200
|
+
return /* @__PURE__ */ B("div", { className: E("Bear-FormItem", p[v], h), children: [
|
|
201
|
+
n && /* @__PURE__ */ B(
|
|
202
|
+
"label",
|
|
203
|
+
{
|
|
204
|
+
className: E(
|
|
205
|
+
"Bear-FormItem__label bear-text-sm bear-font-medium bear-text-zinc-300",
|
|
206
|
+
v === "horizontal" && Y
|
|
207
|
+
),
|
|
208
|
+
children: [
|
|
209
|
+
n,
|
|
210
|
+
(x || (l == null ? void 0 : l.required)) && /* @__PURE__ */ g("span", { className: "Bear-FormItem__required bear-text-red-500 bear-ml-0.5", children: "*" })
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
),
|
|
214
|
+
/* @__PURE__ */ B("div", { className: "Bear-FormItem__content bear-flex-1", children: [
|
|
215
|
+
/* @__PURE__ */ g("div", { className: "Bear-FormItem__control", children: typeof m == "function" ? m(i) : z(m) ? k(m, {
|
|
216
|
+
...i,
|
|
217
|
+
onChange: (c) => {
|
|
218
|
+
const y = c && typeof c == "object" && "target" in c && c.target && typeof c.target.value < "u" ? c.target.value : c;
|
|
219
|
+
i.onChange(y);
|
|
220
|
+
}
|
|
221
|
+
}) : m }),
|
|
222
|
+
b && /* @__PURE__ */ g("p", { className: "Bear-FormItem__error bear-mt-1 bear-text-xs bear-text-red-400", children: a.error }),
|
|
223
|
+
F && !b && /* @__PURE__ */ g("p", { className: "Bear-FormItem__helper bear-mt-1 bear-text-xs bear-text-zinc-500", children: F })
|
|
224
|
+
] })
|
|
225
|
+
] });
|
|
226
|
+
};
|
|
227
|
+
W.Item = Z;
|
|
228
|
+
export {
|
|
229
|
+
W as Form
|
|
230
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { ReactNode, FormHTMLAttributes } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Validation rule types
|
|
4
|
+
*/
|
|
5
|
+
export type ValidationRule = {
|
|
6
|
+
/** Required field validation */
|
|
7
|
+
required?: boolean | string;
|
|
8
|
+
/** Minimum length validation */
|
|
9
|
+
minLength?: {
|
|
10
|
+
value: number;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
/** Maximum length validation */
|
|
14
|
+
maxLength?: {
|
|
15
|
+
value: number;
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
18
|
+
/** Minimum value validation (for numbers) */
|
|
19
|
+
min?: {
|
|
20
|
+
value: number;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
/** Maximum value validation (for numbers) */
|
|
24
|
+
max?: {
|
|
25
|
+
value: number;
|
|
26
|
+
message: string;
|
|
27
|
+
};
|
|
28
|
+
/** Pattern validation (regex) */
|
|
29
|
+
pattern?: {
|
|
30
|
+
value: RegExp;
|
|
31
|
+
message: string;
|
|
32
|
+
};
|
|
33
|
+
/** Custom validation function */
|
|
34
|
+
validate?: (value: unknown) => boolean | string | Promise<boolean | string>;
|
|
35
|
+
/** Email validation */
|
|
36
|
+
email?: boolean | string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Form field state
|
|
40
|
+
*/
|
|
41
|
+
export interface FormFieldState {
|
|
42
|
+
/** Current value */
|
|
43
|
+
value: unknown;
|
|
44
|
+
/** Error message if validation failed */
|
|
45
|
+
error?: string;
|
|
46
|
+
/** Whether field has been touched */
|
|
47
|
+
touched: boolean;
|
|
48
|
+
/** Whether field is currently being validated */
|
|
49
|
+
validating: boolean;
|
|
50
|
+
/** Whether field is dirty (value changed) */
|
|
51
|
+
dirty: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Form state
|
|
55
|
+
*/
|
|
56
|
+
export interface FormState {
|
|
57
|
+
/** Field states by name */
|
|
58
|
+
fields: Record<string, FormFieldState>;
|
|
59
|
+
/** Whether form is currently submitting */
|
|
60
|
+
isSubmitting: boolean;
|
|
61
|
+
/** Whether form is valid */
|
|
62
|
+
isValid: boolean;
|
|
63
|
+
/** Whether form has been submitted */
|
|
64
|
+
isSubmitted: boolean;
|
|
65
|
+
/** Form-level errors */
|
|
66
|
+
errors: Record<string, string>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Form context value
|
|
70
|
+
*/
|
|
71
|
+
export interface FormContextValue {
|
|
72
|
+
/** Current form state */
|
|
73
|
+
state: FormState;
|
|
74
|
+
/** Register a field */
|
|
75
|
+
register: (name: string, rules?: ValidationRule) => {
|
|
76
|
+
name: string;
|
|
77
|
+
value: unknown;
|
|
78
|
+
onChange: (value: unknown) => void;
|
|
79
|
+
onBlur: () => void;
|
|
80
|
+
};
|
|
81
|
+
/** Set field value */
|
|
82
|
+
setValue: (name: string, value: unknown) => void;
|
|
83
|
+
/** Get field value */
|
|
84
|
+
getValue: (name: string) => unknown;
|
|
85
|
+
/** Set field error */
|
|
86
|
+
setError: (name: string, error: string) => void;
|
|
87
|
+
/** Clear field error */
|
|
88
|
+
clearError: (name: string) => void;
|
|
89
|
+
/** Validate a field */
|
|
90
|
+
validateField: (name: string) => Promise<boolean>;
|
|
91
|
+
/** Validate all fields */
|
|
92
|
+
validateForm: () => Promise<boolean>;
|
|
93
|
+
/** Reset form */
|
|
94
|
+
reset: (values?: Record<string, unknown>) => void;
|
|
95
|
+
/** Handle form submission */
|
|
96
|
+
handleSubmit: (onSubmit: (data: Record<string, unknown>) => void | Promise<void>) => (e: React.FormEvent) => void;
|
|
97
|
+
/** Form layout */
|
|
98
|
+
layout: FormLayout;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Form layout options
|
|
102
|
+
*/
|
|
103
|
+
export type FormLayout = 'vertical' | 'horizontal' | 'inline';
|
|
104
|
+
/**
|
|
105
|
+
* Form component props
|
|
106
|
+
*/
|
|
107
|
+
export interface FormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit' | 'onError'> {
|
|
108
|
+
/** Child elements */
|
|
109
|
+
children: ReactNode;
|
|
110
|
+
/** Initial form values */
|
|
111
|
+
initialValues?: Record<string, unknown>;
|
|
112
|
+
/** Form submission handler */
|
|
113
|
+
onSubmit?: (data: Record<string, unknown>) => void | Promise<void>;
|
|
114
|
+
/** Form validation error handler */
|
|
115
|
+
onError?: (errors: Record<string, string>) => void;
|
|
116
|
+
/** Form layout */
|
|
117
|
+
layout?: FormLayout;
|
|
118
|
+
/** Whether to validate on change */
|
|
119
|
+
validateOnChange?: boolean;
|
|
120
|
+
/** Whether to validate on blur */
|
|
121
|
+
validateOnBlur?: boolean;
|
|
122
|
+
/** Custom class name */
|
|
123
|
+
className?: string;
|
|
124
|
+
/** Test ID */
|
|
125
|
+
testId?: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Field props from register
|
|
129
|
+
*/
|
|
130
|
+
export interface FormFieldProps {
|
|
131
|
+
name: string;
|
|
132
|
+
value: unknown;
|
|
133
|
+
onChange: (value: unknown) => void;
|
|
134
|
+
onBlur: () => void;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Form.Item props
|
|
138
|
+
*/
|
|
139
|
+
export interface FormItemProps {
|
|
140
|
+
/** Field name */
|
|
141
|
+
name: string;
|
|
142
|
+
/** Field label */
|
|
143
|
+
label?: string;
|
|
144
|
+
/** Required indicator */
|
|
145
|
+
required?: boolean;
|
|
146
|
+
/** Validation rules */
|
|
147
|
+
rules?: ValidationRule;
|
|
148
|
+
/** Helper text */
|
|
149
|
+
helperText?: string;
|
|
150
|
+
/** Children (form control or render prop) */
|
|
151
|
+
children: ReactNode | ((field: FormFieldProps) => ReactNode);
|
|
152
|
+
/** Custom class name */
|
|
153
|
+
className?: string;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Form translations
|
|
157
|
+
*/
|
|
158
|
+
export interface FormTranslations {
|
|
159
|
+
required: string;
|
|
160
|
+
email: string;
|
|
161
|
+
minLength: string;
|
|
162
|
+
maxLength: string;
|
|
163
|
+
min: string;
|
|
164
|
+
max: string;
|
|
165
|
+
pattern: string;
|
|
166
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./Form.const.cjs"),r=async(i,t)=>{const n=typeof i=="string"?i:String(i??""),e=typeof i=="number"?i:Number(i);if(t.required&&(i==null||n.trim()===""))return typeof t.required=="string"?t.required:m.FORM_DEFAULT_TRANSLATIONS.required;if(i==null||n==="")return null;if(t.email&&!m.EMAIL_REGEX.test(n))return typeof t.email=="string"?t.email:m.FORM_DEFAULT_TRANSLATIONS.email;if(t.minLength&&n.length<t.minLength.value)return t.minLength.message;if(t.maxLength&&n.length>t.maxLength.value)return t.maxLength.message;if(t.min&&!isNaN(e)&&e<t.min.value)return t.min.message;if(t.max&&!isNaN(e)&&e>t.max.value)return t.max.message;if(t.pattern&&!t.pattern.value.test(n))return t.pattern.message;if(t.validate){const a=await t.validate(i);if(typeof a=="string")return a;if(a===!1)return m.FORM_DEFAULT_TRANSLATIONS.pattern}return null};exports.validateFieldValue=r;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ValidationRule } from './Form.types';
|
|
2
|
+
/**
|
|
3
|
+
* Validate a single field value against rules
|
|
4
|
+
*/
|
|
5
|
+
export declare const validateFieldValue: (value: unknown, rules: ValidationRule) => Promise<string | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Deep clone an object
|
|
8
|
+
*/
|
|
9
|
+
export declare const deepClone: <T>(obj: T) => T;
|
|
10
|
+
/**
|
|
11
|
+
* Get nested value from object by path
|
|
12
|
+
*/
|
|
13
|
+
export declare const getNestedValue: (obj: Record<string, unknown>, path: string) => unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Set nested value in object by path
|
|
16
|
+
*/
|
|
17
|
+
export declare const setNestedValue: (obj: Record<string, unknown>, path: string, value: unknown) => Record<string, unknown>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FORM_DEFAULT_TRANSLATIONS as m, EMAIL_REGEX as f } from "./Form.const.js";
|
|
2
|
+
const g = async (i, t) => {
|
|
3
|
+
const n = typeof i == "string" ? i : String(i ?? ""), e = typeof i == "number" ? i : Number(i);
|
|
4
|
+
if (t.required && (i == null || n.trim() === ""))
|
|
5
|
+
return typeof t.required == "string" ? t.required : m.required;
|
|
6
|
+
if (i == null || n === "")
|
|
7
|
+
return null;
|
|
8
|
+
if (t.email && !f.test(n))
|
|
9
|
+
return typeof t.email == "string" ? t.email : m.email;
|
|
10
|
+
if (t.minLength && n.length < t.minLength.value)
|
|
11
|
+
return t.minLength.message;
|
|
12
|
+
if (t.maxLength && n.length > t.maxLength.value)
|
|
13
|
+
return t.maxLength.message;
|
|
14
|
+
if (t.min && !isNaN(e) && e < t.min.value)
|
|
15
|
+
return t.min.message;
|
|
16
|
+
if (t.max && !isNaN(e) && e > t.max.value)
|
|
17
|
+
return t.max.message;
|
|
18
|
+
if (t.pattern && !t.pattern.value.test(n))
|
|
19
|
+
return t.pattern.message;
|
|
20
|
+
if (t.validate) {
|
|
21
|
+
const a = await t.validate(i);
|
|
22
|
+
if (typeof a == "string")
|
|
23
|
+
return a;
|
|
24
|
+
if (a === !1)
|
|
25
|
+
return m.pattern;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
g as validateFieldValue
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),K=require("react"),m=require("../../utils/cn.cjs");require("../../context/BearProvider.cjs");const P=require("../../hooks/useDragDrop/useDragDrop.cjs"),S="bear-kanban",$=({columns:n,onColumnsChange:o,onCardMove:p,renderCard:h,renderColumnHeader:u,disabled:y=!1,className:v})=>{const w=K.useCallback((r,e,i,b,d)=>{const l=n.find(a=>a.id===r),s=n.find(a=>a.id===e);if(!l||!s)return;const f=n.map(a=>{if(a.id===r){const c=a.cards.filter((x,g)=>g!==i);return{...a,cards:c}}if(a.id===e){const c=r===e&&i<b?b-1:b,x=[...a.cards];return x.splice(Math.max(0,c),0,d),{...a,cards:x}}return a});o==null||o(f),p==null||p(d.id,r,e,i,b)},[n,o,p]),{getDragProps:N,getDropProps:j,isDragging:_,draggedId:z,dragOverId:k}=P.useDragDrop({disabled:y,dragType:S,onDrop:(r,e,i,b,d)=>{var D;const l=String(r),s=String(e),f=l.split("-")[0],a=parseInt(l.split("-")[1],10)||0,c=s.endsWith("-col")?s.replace("-col",""):s.split("-")[0],x=s.endsWith("-col")?((D=n.find(q=>q.id===c))==null?void 0:D.cards.length)??0:parseInt(s.split("-")[1],10),g=d;g!=null&&g.id&&w(f,c,a,x,g)}});return t.jsx("div",{className:m.cn("Bear-Kanban bear-flex bear-gap-4 bear-overflow-x-auto bear-pb-4",y&&"bear-opacity-50 bear-pointer-events-none",v),children:n.map(r=>t.jsxs("div",{...j(`${r.id}-col`,r,0),className:m.cn("Bear-Kanban__column bear-flex-shrink-0 bear-w-72 bear-flex bear-flex-col bear-rounded-lg bear-bg-gray-100 dark:bear-bg-zinc-800/80 bear-border bear-border-gray-200 dark:bear-border-zinc-700 bear-transition-colors",k===`${r.id}-col`&&"bear-border-bear-500 bear-bg-bear-500/5"),children:[t.jsx("div",{className:"bear-px-4 bear-py-3 bear-border-b bear-border-gray-200 dark:bear-border-zinc-700",children:u?u(r):t.jsx("h3",{className:"bear-text-sm bear-font-semibold bear-text-gray-900 dark:bear-text-white",children:r.title})}),t.jsx("div",{className:"bear-flex-1 bear-flex bear-flex-col bear-gap-2 bear-p-3 bear-min-h-[120px]",children:r.cards.map((e,i)=>{const b=`${r.id}-${i}`,d=_&&z===b;return t.jsx("div",{...j(b,e,i),...N(b,e,i),className:m.cn("Bear-Kanban__card bear-rounded-lg bear-bg-white dark:bear-bg-zinc-700/80 bear-border bear-border-gray-200 dark:bear-border-zinc-600 bear-p-3 bear-cursor-grab active:bear-cursor-grabbing bear-transition-all bear-shadow-sm",d&&"bear-opacity-50 bear-scale-95",k===b&&"bear-border-bear-500 bear-bg-bear-500/10"),children:h?h(e,r.id):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bear-font-medium bear-text-gray-900 dark:bear-text-white",children:e.title}),e.description&&t.jsx("div",{className:"bear-text-sm bear-text-gray-600 dark:bear-text-zinc-400 bear-mt-1",children:e.description}),e.meta&&t.jsx("div",{className:"bear-text-xs bear-text-gray-500 dark:bear-text-zinc-500 bear-mt-2",children:e.meta})]})},e.id)})})]},r.id))})};exports.Kanban=$;
|