@saptanshuwanjari/react-component-library 0.1.0 → 0.1.6

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Saptanshu Wanjari
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Saptanshu Wanjari
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,56 +1,56 @@
1
- # React Component Library
2
-
3
- A modern, lightweight React component library featuring robust DataTable and Form components built with the Compound Component pattern.
4
-
5
- ## Features
6
-
7
- - 🎯 **DataTable**: Powerful data table with sorting, filtering, and pagination
8
- - 📝 **Form**: Flexible form system with validation using react-hook-form and Zod
9
- - 🎨 **Styled with Tailwind CSS**: Fully customizable with Tailwind
10
- - 📦 **Tree-shakeable**: Only import what you need
11
- - 🔷 **TypeScript**: Full type safety
12
-
13
- ## Installation
14
-
15
- ```bash
16
- npm install @your-org/react-component-library
17
- ```
18
-
19
- ## Usage
20
-
21
- ```tsx
22
- import { Form, DataTable } from '@your-org/react-component-library';
23
-
24
- // Form example
25
- <Form.Root schema={mySchema} onSubmit={handleSubmit}>
26
- <Form.InputField name="email" label="Email" />
27
- <Form.Submit>Submit</Form.Submit>
28
- </Form.Root>
29
-
30
- // DataTable example
31
- <DataTable.Root data={data}>
32
- <DataTable.Header>
33
- <DataTable.Column>Name</DataTable.Column>
34
- </DataTable.Header>
35
- <DataTable.Body />
36
- </DataTable.Root>
37
- ```
38
-
39
- ## Development
40
-
41
- This library is built with `tsup` for fast bundling. The `example/` folder contains a Next.js app for testing components locally.
42
-
43
- ```bash
44
- # Install dependencies
45
- npm install
46
-
47
- # Start development mode
48
- npm run dev
49
-
50
- # Build for production
51
- npm run build
52
- ```
53
-
54
- ## License
55
-
56
- MIT
1
+ # React Component Library
2
+
3
+ A modern, lightweight React component library featuring robust DataTable and Form components built with the Compound Component pattern.
4
+
5
+ ## Features
6
+
7
+ - 🎯 **DataTable**: Powerful data table with sorting, filtering, and pagination
8
+ - 📝 **Form**: Flexible form system with validation using react-hook-form and Zod
9
+ - 🎨 **Styled with Tailwind CSS**: Fully customizable with Tailwind
10
+ - 📦 **Tree-shakeable**: Only import what you need
11
+ - 🔷 **TypeScript**: Full type safety
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @your-org/react-component-library
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```tsx
22
+ import { Form, DataTable } from '@your-org/react-component-library';
23
+
24
+ // Form example
25
+ <Form.Root schema={mySchema} onSubmit={handleSubmit}>
26
+ <Form.InputField name="email" label="Email" />
27
+ <Form.Submit>Submit</Form.Submit>
28
+ </Form.Root>
29
+
30
+ // DataTable example
31
+ <DataTable.Root data={data}>
32
+ <DataTable.Header>
33
+ <DataTable.Column>Name</DataTable.Column>
34
+ </DataTable.Header>
35
+ <DataTable.Body />
36
+ </DataTable.Root>
37
+ ```
38
+
39
+ ## Development
40
+
41
+ This library is built with `tsup` for fast bundling. The `example/` folder contains a Next.js app for testing components locally.
42
+
43
+ ```bash
44
+ # Install dependencies
45
+ npm install
46
+
47
+ # Start development mode
48
+ npm run dev
49
+
50
+ # Build for production
51
+ npm run build
52
+ ```
53
+
54
+ ## License
55
+
56
+ MIT
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
3
+ var React2 = require('react');
4
4
  var zod = require('@hookform/resolvers/zod');
5
5
  var reactHookForm = require('react-hook-form');
6
6
  var jsxRuntime = require('react/jsx-runtime');
@@ -8,7 +8,6 @@ var lucideReact = require('lucide-react');
8
8
  var clsx = require('clsx');
9
9
  var tailwindMerge = require('tailwind-merge');
10
10
  var reactTable = require('@tanstack/react-table');
11
- var reactSlot = require('@radix-ui/react-slot');
12
11
  var classVarianceAuthority = require('class-variance-authority');
13
12
  var SelectPrimitive = require('@radix-ui/react-select');
14
13
  var PopoverPrimitive = require('@radix-ui/react-popover');
@@ -32,12 +31,13 @@ function _interopNamespace(e) {
32
31
  return Object.freeze(n);
33
32
  }
34
33
 
34
+ var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
35
35
  var SelectPrimitive__namespace = /*#__PURE__*/_interopNamespace(SelectPrimitive);
36
36
  var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespace(PopoverPrimitive);
37
37
  var CheckboxPrimitive__namespace = /*#__PURE__*/_interopNamespace(CheckboxPrimitive);
38
38
 
39
39
  // src/components/form/root.tsx
40
- var FormContext = react.createContext(null);
40
+ var FormContext = React2.createContext(null);
41
41
  var DEFAULT_FORM_KEY = "__default_form__";
42
42
  var formRegistry = /* @__PURE__ */ new Map();
43
43
  function Root({
@@ -52,8 +52,8 @@ function Root({
52
52
  formId
53
53
  }) {
54
54
  const resolver = schema ? zod.zodResolver(schema) : void 0;
55
- const [isPending, startTransition] = react.useTransition();
56
- const [isEditing, setIsEditing] = react.useState(!enableEditMode);
55
+ const [isPending, startTransition] = React2.useTransition();
56
+ const [isEditing, setIsEditing] = React2.useState(!enableEditMode);
57
57
  const methods = reactHookForm.useForm({
58
58
  resolver,
59
59
  defaultValues
@@ -67,7 +67,7 @@ function Root({
67
67
  }
68
68
  return onSubmit(data);
69
69
  });
70
- react.useEffect(() => {
70
+ React2.useEffect(() => {
71
71
  const key = formId ?? DEFAULT_FORM_KEY;
72
72
  formRegistry.set(key, setIsEditing);
73
73
  return () => {
@@ -91,7 +91,7 @@ function Root({
91
91
  }
92
92
  var root_default = Root;
93
93
  function useFormCtx() {
94
- const ctx = react.useContext(FormContext);
94
+ const ctx = React2.useContext(FormContext);
95
95
  if (!ctx) throw new Error("Form components must be used inside Form.Root");
96
96
  return ctx;
97
97
  }
@@ -125,7 +125,7 @@ var Input = ({ className = "", ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
125
125
  ...props
126
126
  }
127
127
  );
128
- var InputField = react.memo(function InputField2({
128
+ var InputField = React2.memo(function InputField2({
129
129
  name,
130
130
  label,
131
131
  placeholder,
@@ -150,12 +150,12 @@ var InputField = react.memo(function InputField2({
150
150
  ) });
151
151
  });
152
152
  var input_field_default = InputField;
153
- var PasswordField = react.memo(function PasswordField2({
153
+ var PasswordField = React2.memo(function PasswordField2({
154
154
  name,
155
155
  label,
156
156
  placeholder
157
157
  }) {
158
- const [show, setShow] = react.useState(false);
158
+ const [show, setShow] = React2.useState(false);
159
159
  return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
160
160
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Lock, { className: "h-4 w-4 text-muted-foreground" }) }),
161
161
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -188,7 +188,7 @@ var Textarea = ({ className = "", ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
188
188
  ...props
189
189
  }
190
190
  );
191
- var TextareaField = react.memo(function TextareaField2({
191
+ var TextareaField = React2.memo(function TextareaField2({
192
192
  name,
193
193
  label,
194
194
  placeholder,
@@ -227,7 +227,7 @@ var Input2 = ({ className = "", ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
227
227
  ...props
228
228
  }
229
229
  );
230
- var SelectField = react.memo(function SelectField2({
230
+ var SelectField = React2.memo(function SelectField2({
231
231
  name,
232
232
  label,
233
233
  placeholder = "Select an option",
@@ -262,7 +262,7 @@ var Checkbox = ({ checked, onCheckedChange, disabled, id }) => /* @__PURE__ */ j
262
262
  className: "h-4 w-4 rounded border-gray-300"
263
263
  }
264
264
  );
265
- var CheckboxField = react.memo(function CheckboxField2({
265
+ var CheckboxField = React2.memo(function CheckboxField2({
266
266
  name,
267
267
  label,
268
268
  description
@@ -310,12 +310,12 @@ var Button = ({ children, className = "", ...props }) => /* @__PURE__ */ jsxRunt
310
310
  children
311
311
  }
312
312
  );
313
- var DateField = react.memo(function DateField2({
313
+ var DateField = React2.memo(function DateField2({
314
314
  name,
315
315
  label,
316
316
  placeholder = "Select date"
317
317
  }) {
318
- const [open, setOpen] = react.useState(false);
318
+ const [open, setOpen] = React2.useState(false);
319
319
  const { isEditing } = useFormCtx();
320
320
  return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => !isEditing ? /* @__PURE__ */ jsxRuntime.jsxs(
321
321
  Button,
@@ -351,7 +351,7 @@ var Input3 = ({ className = "", ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
351
351
  var InputGroup = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative flex items-center", children });
352
352
  var InputGroupAddon = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute left-3 flex items-center", children });
353
353
  var InputGroupInput = (props) => /* @__PURE__ */ jsxRuntime.jsx(Input3, { className: "pl-10", ...props });
354
- var FileField = react.memo(function FileField2({
354
+ var FileField = React2.memo(function FileField2({
355
355
  name,
356
356
  label,
357
357
  accept,
@@ -405,7 +405,7 @@ var AvatarFallback = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { c
405
405
  var Label = ({ htmlFor, children, className }) => /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor, className, children });
406
406
  var Input4 = (props) => /* @__PURE__ */ jsxRuntime.jsx("input", { ...props });
407
407
  var Button2 = ({ children, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("button", { className: "px-3 py-1 text-sm rounded hover:bg-accent", ...props, children });
408
- var ProfilePictureField = react.memo(function ProfilePictureField2({
408
+ var ProfilePictureField = React2.memo(function ProfilePictureField2({
409
409
  name,
410
410
  label,
411
411
  className,
@@ -413,7 +413,7 @@ var ProfilePictureField = react.memo(function ProfilePictureField2({
413
413
  fallback = "User"
414
414
  }) {
415
415
  const { isEditing } = useFormCtx();
416
- const [preview, setPreview] = react.useState(null);
416
+ const [preview, setPreview] = React2.useState(null);
417
417
  return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => {
418
418
  const currentValue = field.value;
419
419
  const displayUrl = preview || (typeof currentValue === "string" ? currentValue : null);
@@ -498,7 +498,7 @@ var Button4 = ({ children, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
498
498
  }
499
499
  );
500
500
  function EditButton({ children, formId, ...props }) {
501
- const ctx = react.useContext(FormContext);
501
+ const ctx = React2.useContext(FormContext);
502
502
  if (ctx) {
503
503
  const { isEditing, setIsEditing } = ctx;
504
504
  if (isEditing) return null;
@@ -585,9 +585,9 @@ var Form = Object.assign(root_default, {
585
585
  LinkField: link_field_default
586
586
  });
587
587
  var form_default = Form;
588
- var DataTableContext = react.createContext(null);
588
+ var DataTableContext = React2.createContext(null);
589
589
  function useDataTable() {
590
- const context = react.useContext(DataTableContext);
590
+ const context = React2.useContext(DataTableContext);
591
591
  if (!context) {
592
592
  throw new Error("DataTable components must be used within DataTable.Root");
593
593
  }
@@ -601,14 +601,14 @@ function Root2({
601
601
  defaultPageSize = 10,
602
602
  children
603
603
  }) {
604
- const [viewMode, setViewMode] = react.useState(defaultViewMode);
605
- const [sorting, setSorting] = react.useState([]);
606
- const [columnFilters, setColumnFilters] = react.useState([]);
607
- const [columnVisibility, setColumnVisibility] = react.useState({});
608
- const [globalFilter, setGlobalFilter] = react.useState("");
609
- const [pagination, setPagination] = react.useState({ pageIndex: 0, pageSize: defaultPageSize });
610
- const [activeFilters, setActiveFilters] = react.useState({});
611
- const filteredData = react.useMemo(() => {
604
+ const [viewMode, setViewMode] = React2.useState(defaultViewMode);
605
+ const [sorting, setSorting] = React2.useState([]);
606
+ const [columnFilters, setColumnFilters] = React2.useState([]);
607
+ const [columnVisibility, setColumnVisibility] = React2.useState({});
608
+ const [globalFilter, setGlobalFilter] = React2.useState("");
609
+ const [pagination, setPagination] = React2.useState({ pageIndex: 0, pageSize: defaultPageSize });
610
+ const [activeFilters, setActiveFilters] = React2.useState({});
611
+ const filteredData = React2.useMemo(() => {
612
612
  if (Object.keys(activeFilters).length === 0) return data;
613
613
  return data.filter((row) => {
614
614
  return Object.entries(activeFilters).every(([filterId, filterValue]) => {
@@ -675,6 +675,120 @@ function Input5({ className, type, ...props }) {
675
675
  }
676
676
  );
677
677
  }
678
+ function setRef(ref, value) {
679
+ if (typeof ref === "function") {
680
+ return ref(value);
681
+ } else if (ref !== null && ref !== void 0) {
682
+ ref.current = value;
683
+ }
684
+ }
685
+ function composeRefs(...refs) {
686
+ return (node) => {
687
+ let hasCleanup = false;
688
+ const cleanups = refs.map((ref) => {
689
+ const cleanup = setRef(ref, node);
690
+ if (!hasCleanup && typeof cleanup == "function") {
691
+ hasCleanup = true;
692
+ }
693
+ return cleanup;
694
+ });
695
+ if (hasCleanup) {
696
+ return () => {
697
+ for (let i = 0; i < cleanups.length; i++) {
698
+ const cleanup = cleanups[i];
699
+ if (typeof cleanup == "function") {
700
+ cleanup();
701
+ } else {
702
+ setRef(refs[i], null);
703
+ }
704
+ }
705
+ };
706
+ }
707
+ };
708
+ }
709
+ // @__NO_SIDE_EFFECTS__
710
+ function createSlot(ownerName) {
711
+ const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
712
+ const Slot2 = React2__namespace.forwardRef((props, forwardedRef) => {
713
+ const { children, ...slotProps } = props;
714
+ const childrenArray = React2__namespace.Children.toArray(children);
715
+ const slottable = childrenArray.find(isSlottable);
716
+ if (slottable) {
717
+ const newElement = slottable.props.children;
718
+ const newChildren = childrenArray.map((child) => {
719
+ if (child === slottable) {
720
+ if (React2__namespace.Children.count(newElement) > 1) return React2__namespace.Children.only(null);
721
+ return React2__namespace.isValidElement(newElement) ? newElement.props.children : null;
722
+ } else {
723
+ return child;
724
+ }
725
+ });
726
+ return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React2__namespace.isValidElement(newElement) ? React2__namespace.cloneElement(newElement, void 0, newChildren) : null });
727
+ }
728
+ return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
729
+ });
730
+ Slot2.displayName = `${ownerName}.Slot`;
731
+ return Slot2;
732
+ }
733
+ var Slot = /* @__PURE__ */ createSlot("Slot");
734
+ // @__NO_SIDE_EFFECTS__
735
+ function createSlotClone(ownerName) {
736
+ const SlotClone = React2__namespace.forwardRef((props, forwardedRef) => {
737
+ const { children, ...slotProps } = props;
738
+ if (React2__namespace.isValidElement(children)) {
739
+ const childrenRef = getElementRef(children);
740
+ const props2 = mergeProps(slotProps, children.props);
741
+ if (children.type !== React2__namespace.Fragment) {
742
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
743
+ }
744
+ return React2__namespace.cloneElement(children, props2);
745
+ }
746
+ return React2__namespace.Children.count(children) > 1 ? React2__namespace.Children.only(null) : null;
747
+ });
748
+ SlotClone.displayName = `${ownerName}.SlotClone`;
749
+ return SlotClone;
750
+ }
751
+ var SLOTTABLE_IDENTIFIER = /* @__PURE__ */ Symbol("radix.slottable");
752
+ function isSlottable(child) {
753
+ return React2__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
754
+ }
755
+ function mergeProps(slotProps, childProps) {
756
+ const overrideProps = { ...childProps };
757
+ for (const propName in childProps) {
758
+ const slotPropValue = slotProps[propName];
759
+ const childPropValue = childProps[propName];
760
+ const isHandler = /^on[A-Z]/.test(propName);
761
+ if (isHandler) {
762
+ if (slotPropValue && childPropValue) {
763
+ overrideProps[propName] = (...args) => {
764
+ const result = childPropValue(...args);
765
+ slotPropValue(...args);
766
+ return result;
767
+ };
768
+ } else if (slotPropValue) {
769
+ overrideProps[propName] = slotPropValue;
770
+ }
771
+ } else if (propName === "style") {
772
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
773
+ } else if (propName === "className") {
774
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
775
+ }
776
+ }
777
+ return { ...slotProps, ...overrideProps };
778
+ }
779
+ function getElementRef(element) {
780
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
781
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
782
+ if (mayWarn) {
783
+ return element.ref;
784
+ }
785
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
786
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
787
+ if (mayWarn) {
788
+ return element.props.ref;
789
+ }
790
+ return element.props.ref || element.ref;
791
+ }
678
792
  var buttonVariants = classVarianceAuthority.cva(
679
793
  "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
680
794
  {
@@ -709,7 +823,7 @@ function Button6({
709
823
  asChild = false,
710
824
  ...props
711
825
  }) {
712
- const Comp = asChild ? reactSlot.Slot : "button";
826
+ const Comp = asChild ? Slot : "button";
713
827
  return /* @__PURE__ */ jsxRuntime.jsx(
714
828
  Comp,
715
829
  {