@aatulwork/customform-renderer 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -123,6 +123,22 @@ var transformFormValues = (data, formSchema) => {
123
123
  });
124
124
  return transformedData;
125
125
  };
126
+ var useFormColors = (customColors) => {
127
+ const theme = useTheme();
128
+ return {
129
+ primary: customColors?.primary || theme.palette.primary.main,
130
+ secondary: customColors?.secondary || theme.palette.secondary.main,
131
+ error: customColors?.error || theme.palette.error.main,
132
+ success: customColors?.success || theme.palette.success.main,
133
+ warning: customColors?.warning || theme.palette.warning.main,
134
+ info: customColors?.info || theme.palette.info.main,
135
+ textPrimary: customColors?.textPrimary || theme.palette.text.primary,
136
+ textSecondary: customColors?.textSecondary || theme.palette.text.secondary,
137
+ divider: customColors?.divider || theme.palette.divider,
138
+ background: customColors?.background || theme.palette.background.default,
139
+ backgroundPaper: customColors?.backgroundPaper || theme.palette.background.paper
140
+ };
141
+ };
126
142
  var TextField = ({ field, control, defaultValue, rules, errors }) => {
127
143
  return /* @__PURE__ */ jsx(
128
144
  Controller,
@@ -618,8 +634,9 @@ var useCKEditor = (options = {}) => {
618
634
  load
619
635
  };
620
636
  };
621
- var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, formSchema, services }) => {
637
+ var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, formSchema, services, colors }) => {
622
638
  const theme = useTheme();
639
+ const formColors = useFormColors(colors);
623
640
  const editorContainerRef = useRef(null);
624
641
  const fileUploadService = services?.fileUpload || defaultFileUploadService;
625
642
  const fileBaseUrl = services?.fileBaseUrl || "";
@@ -671,13 +688,13 @@ var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, fo
671
688
  if (isCKEditorLoading) {
672
689
  return /* @__PURE__ */ jsxs(Box, { children: [
673
690
  /* @__PURE__ */ jsx(FormLabel, { required: field.required, error: !!errors[field.name], children: field.label }),
674
- /* @__PURE__ */ jsx(Box, { sx: { p: 2, textAlign: "center", color: "text.secondary" }, children: "Loading editor..." })
691
+ /* @__PURE__ */ jsx(Box, { sx: { p: 2, textAlign: "center", color: formColors.textSecondary }, children: "Loading editor..." })
675
692
  ] });
676
693
  }
677
694
  if (ckEditorError || !isCKEditorReady) {
678
695
  return /* @__PURE__ */ jsxs(Box, { children: [
679
696
  /* @__PURE__ */ jsx(FormLabel, { required: field.required, error: !!errors[field.name], children: field.label }),
680
- /* @__PURE__ */ jsx(Box, { sx: { p: 2, border: "1px solid", borderColor: "error.main", borderRadius: 1 }, children: /* @__PURE__ */ jsx(FormHelperText, { error: true, children: ckEditorError?.message || "CKEditor failed to load. Please ensure the CKEditor script is loaded." }) })
697
+ /* @__PURE__ */ jsx(Box, { sx: { p: 2, border: "1px solid", borderColor: formColors.error, borderRadius: 1 }, children: /* @__PURE__ */ jsx(FormHelperText, { error: true, children: ckEditorError?.message || "CKEditor failed to load. Please ensure the CKEditor script is loaded." }) })
681
698
  ] });
682
699
  }
683
700
  return /* @__PURE__ */ jsx(
@@ -723,11 +740,11 @@ var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, fo
723
740
  minHeight: "100px"
724
741
  },
725
742
  "&:hover": {
726
- borderColor: errors[field.name] ? theme.palette.error.main : theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.87)" : theme.palette.primary.main
743
+ borderColor: errors[field.name] ? formColors.error : theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.87)" : formColors.primary
727
744
  },
728
745
  "& .ck-focused": {
729
- border: errors[field.name] ? `1px solid ${theme.palette.error.main} !important` : `1px solid ${theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.23)" : `${theme.palette.primary.main}`} !important`,
730
- boxShadow: errors[field.name] ? `0 0 0 1px ${theme.palette.error.main}` : `0 0 0 1px ${alpha(theme.palette.primary.main, 0.5)} !important`
746
+ border: errors[field.name] ? `1px solid ${formColors.error} !important` : `1px solid ${theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.23)" : formColors.primary} !important`,
747
+ boxShadow: errors[field.name] ? `0 0 0 1px ${formColors.error}` : `0 0 0 1px ${alpha(formColors.primary, 0.5)} !important`
731
748
  }
732
749
  }
733
750
  },
@@ -790,10 +807,12 @@ var FileField = ({
790
807
  setUploadingFiles,
791
808
  setError,
792
809
  clearErrors,
793
- services
810
+ services,
811
+ colors
794
812
  }) => {
795
813
  const theme = useTheme();
796
814
  const isMobile = useMediaQuery(theme.breakpoints.down("md"));
815
+ const formColors = useFormColors(colors);
797
816
  const acceptTypes = field.validation?.allowedFileTypes ? field.validation.allowedFileTypes.map((type) => `.${type.replace(".", "")}`).join(",") : void 0;
798
817
  const isMultiple = field.allowMultiple || false;
799
818
  const fileUploadService = services?.fileUpload || defaultFileUploadService;
@@ -833,15 +852,15 @@ var FileField = ({
833
852
  alignItems: "center",
834
853
  justifyContent: "center",
835
854
  border: "1px dashed",
836
- borderColor: errors[field.name] ? "error.main" : isUploading ? "primary.main" : hasFiles ? "primary.main" : "divider",
855
+ borderColor: errors[field.name] ? formColors.error : isUploading ? formColors.primary : hasFiles ? formColors.primary : formColors.divider,
837
856
  p: 1,
838
857
  cursor: isUploading ? "wait" : "pointer",
839
858
  transition: "all 0.2s ease-in-out",
840
- backgroundColor: isUploading || hasFiles ? "action.hover" : "background.paper",
859
+ backgroundColor: isUploading || hasFiles ? "action.hover" : formColors.backgroundPaper,
841
860
  opacity: isUploading ? 0.7 : 1,
842
861
  pointerEvents: isUploading ? "none" : "auto",
843
862
  "&:hover": {
844
- borderColor: isUploading ? "primary.main" : "primary.main",
863
+ borderColor: isUploading ? formColors.primary : formColors.primary,
845
864
  backgroundColor: "action.hover"
846
865
  }
847
866
  },
@@ -910,19 +929,19 @@ var FileField = ({
910
929
  ),
911
930
  isUploading ? /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", alignItems: "center", gap: 1, py: 3, width: "100%" }, children: [
912
931
  /* @__PURE__ */ jsx(CircularProgress, { size: 40 }),
913
- /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "primary.main", sx: { fontWeight: 500 }, children: "Uploading files..." }),
914
- /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", children: "Please wait while files are being uploaded" })
932
+ /* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { fontWeight: 500, color: formColors.primary }, children: "Uploading files..." }),
933
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", sx: { color: formColors.textSecondary }, children: "Please wait while files are being uploaded" })
915
934
  ] }) : !hasFiles ? /* @__PURE__ */ jsxs(Fragment, { children: [
916
- /* @__PURE__ */ jsx(CloudUploadIcon, { sx: { fontSize: 40, color: "text.secondary", mb: 1 } }),
917
- /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "text.secondary", children: [
935
+ /* @__PURE__ */ jsx(CloudUploadIcon, { sx: { fontSize: 40, color: formColors.textSecondary, mb: 1 } }),
936
+ /* @__PURE__ */ jsxs(Typography, { variant: "caption", sx: { color: formColors.textSecondary }, children: [
918
937
  "Click to upload or drag and drop",
919
938
  isMultiple && " (multiple files allowed)"
920
939
  ] }),
921
- field.validation?.allowedFileTypes && field.validation.allowedFileTypes.length > 0 && /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "text.secondary", sx: { mt: 0.5 }, children: [
940
+ field.validation?.allowedFileTypes && field.validation.allowedFileTypes.length > 0 && /* @__PURE__ */ jsxs(Typography, { variant: "caption", sx: { mt: 0.5, color: formColors.textSecondary }, children: [
922
941
  "Allowed: ",
923
942
  field.validation.allowedFileTypes.join(", ")
924
943
  ] }),
925
- field.validation?.maxFileSize && /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "text.secondary", sx: { mt: 0.5 }, children: [
944
+ field.validation?.maxFileSize && /* @__PURE__ */ jsxs(Typography, { variant: "caption", sx: { mt: 0.5, color: formColors.textSecondary }, children: [
926
945
  "Max size: ",
927
946
  formatFileSize(field.validation.maxFileSize),
928
947
  " per file"
@@ -935,10 +954,10 @@ var FileField = ({
935
954
  " uploaded"
936
955
  ] }),
937
956
  files.length === 1 && !isMultiple ? /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 2, width: "100%" }, children: [
938
- /* @__PURE__ */ jsx(InsertDriveFileIcon, { sx: { fontSize: 40, color: "primary.main" } }),
957
+ /* @__PURE__ */ jsx(InsertDriveFileIcon, { sx: { fontSize: 40, color: formColors.primary } }),
939
958
  /* @__PURE__ */ jsxs(Box, { sx: { flexGrow: 1, minWidth: 0 }, children: [
940
959
  /* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { fontWeight: 500, overflow: "hidden", textOverflow: "ellipsis", maxWidth: isMobile ? "200px" : "300px" }, children: files[0] instanceof File ? files[0].name : files[0].originalName || files[0].fileName }),
941
- /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", children: formatFileSize(files[0].size || 0) })
960
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", sx: { color: formColors.textSecondary }, children: formatFileSize(files[0].size || 0) })
942
961
  ] }),
943
962
  /* @__PURE__ */ jsx(Tooltip, { title: "Remove file", placement: "bottom", arrow: true, children: /* @__PURE__ */ jsx(
944
963
  IconButton,
@@ -953,7 +972,7 @@ var FileField = ({
953
972
  fileInput.value = "";
954
973
  }
955
974
  },
956
- sx: { color: "error.main" },
975
+ sx: { color: formColors.error },
957
976
  children: /* @__PURE__ */ jsx(CloseIcon, { fontSize: "small" })
958
977
  }
959
978
  ) })
@@ -968,15 +987,15 @@ var FileField = ({
968
987
  gap: 1.5,
969
988
  p: 1,
970
989
  borderRadius: 1,
971
- backgroundColor: "background.default",
990
+ backgroundColor: formColors.background,
972
991
  border: "1px solid",
973
- borderColor: "divider"
992
+ borderColor: formColors.divider
974
993
  },
975
994
  children: [
976
- /* @__PURE__ */ jsx(InsertDriveFileIcon, { sx: { fontSize: 32, color: "primary.main" } }),
995
+ /* @__PURE__ */ jsx(InsertDriveFileIcon, { sx: { fontSize: 32, color: formColors.primary } }),
977
996
  /* @__PURE__ */ jsxs(Box, { sx: { flexGrow: 1, minWidth: 0 }, children: [
978
997
  /* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { fontWeight: 500, overflow: "hidden", textOverflow: "ellipsis" }, children: fileName }),
979
- /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", children: formatFileSize(file.size || 0) })
998
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", sx: { color: formColors.textSecondary }, children: formatFileSize(file.size || 0) })
980
999
  ] }),
981
1000
  /* @__PURE__ */ jsx(Tooltip, { title: "Remove file", placement: "bottom", arrow: true, children: /* @__PURE__ */ jsx(
982
1001
  IconButton,
@@ -992,7 +1011,7 @@ var FileField = ({
992
1011
  formField.onChange(null);
993
1012
  }
994
1013
  },
995
- sx: { color: "error.main" },
1014
+ sx: { color: formColors.error },
996
1015
  children: /* @__PURE__ */ jsx(CloseIcon, { fontSize: "small" })
997
1016
  }
998
1017
  ) })
@@ -1005,7 +1024,7 @@ var FileField = ({
1005
1024
  ]
1006
1025
  }
1007
1026
  ),
1008
- errors[field.name] && /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "error", sx: { mt: 1, display: "block" }, children: errors[field.name]?.message })
1027
+ errors[field.name] && /* @__PURE__ */ jsx(Typography, { variant: "caption", sx: { mt: 1, display: "block", color: formColors.error }, children: errors[field.name]?.message })
1009
1028
  ] });
1010
1029
  }
1011
1030
  },
@@ -1207,7 +1226,8 @@ var FieldRenderer = (props) => {
1207
1226
  errors: props.errors,
1208
1227
  setValue: props.setValue,
1209
1228
  formSchema,
1210
- services
1229
+ services,
1230
+ colors: props.colors
1211
1231
  };
1212
1232
  switch (field.type) {
1213
1233
  case "text":
@@ -1439,10 +1459,11 @@ var formatFieldValue = (field, value, dateFormatter, services) => {
1439
1459
  return String(value);
1440
1460
  }
1441
1461
  };
1442
- var FormViewMode = ({ formSchema, initialValues, hideTitle = false, services }) => {
1462
+ var FormViewMode = ({ formSchema, initialValues, hideTitle = false, services, colors }) => {
1443
1463
  const fieldsToRender = getAllFields(formSchema);
1444
1464
  const theme = useTheme();
1445
1465
  const isMobile = useMediaQuery(theme.breakpoints.down("md"));
1466
+ const formColors = useFormColors(colors);
1446
1467
  return /* @__PURE__ */ jsxs(Box, { sx: { maxWidth: 600, mx: "auto", width: "100%" }, children: [
1447
1468
  !hideTitle && /* @__PURE__ */ jsx(Typography, { variant: "h6", gutterBottom: true, sx: { mb: 2, fontWeight: 600 }, children: formSchema.title }),
1448
1469
  formSchema.sections && formSchema.sections.length > 0 ? /* @__PURE__ */ jsx(Box, { sx: { display: "flex", flexDirection: "column", gap: 1.5 }, children: formSchema.sections.map((section, sectionIndex) => /* @__PURE__ */ jsxs(Accordion, { defaultExpanded: sectionIndex === 0, children: [
@@ -1453,13 +1474,13 @@ var FormViewMode = ({ formSchema, initialValues, hideTitle = false, services })
1453
1474
  "aria-controls": `panel-${section.id}-content`,
1454
1475
  id: `panel-${section.id}-header`,
1455
1476
  children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
1456
- /* @__PURE__ */ jsx(DoubleArrowOutlinedIcon, { fontSize: "small", color: "primary" }),
1457
- /* @__PURE__ */ jsx(Typography, { variant: "subtitle1", sx: { fontWeight: 600 }, color: "primary", children: section.title })
1477
+ /* @__PURE__ */ jsx(DoubleArrowOutlinedIcon, { fontSize: "small", sx: { color: formColors.primary } }),
1478
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle1", sx: { fontWeight: 600, color: formColors.primary }, children: section.title })
1458
1479
  ] })
1459
1480
  }
1460
1481
  ),
1461
1482
  /* @__PURE__ */ jsxs(AccordionDetails, { children: [
1462
- section.description && /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", sx: { mb: 1.5, display: "block" }, children: section.description }),
1483
+ section.description && /* @__PURE__ */ jsx(Typography, { variant: "caption", sx: { mb: 1.5, display: "block", color: formColors.textSecondary }, children: section.description }),
1463
1484
  /* @__PURE__ */ jsx(
1464
1485
  Box,
1465
1486
  {
@@ -1495,8 +1516,10 @@ var FormRenderer = ({
1495
1516
  hideTitle = false,
1496
1517
  allowResetOnValuesChange = false,
1497
1518
  mode = "edit",
1498
- services
1519
+ services,
1520
+ colors
1499
1521
  }) => {
1522
+ const formColors = useFormColors(colors);
1500
1523
  const {
1501
1524
  control,
1502
1525
  handleSubmit,
@@ -1577,7 +1600,7 @@ var FormRenderer = ({
1577
1600
  }
1578
1601
  };
1579
1602
  if (mode === "view") {
1580
- return /* @__PURE__ */ jsx(FormViewMode, { formSchema, initialValues, hideTitle, services });
1603
+ return /* @__PURE__ */ jsx(FormViewMode, { formSchema, initialValues, hideTitle, services, colors });
1581
1604
  }
1582
1605
  return /* @__PURE__ */ jsxs(Box, { component: "form", onSubmit: handleSubmit(handleFormSubmit), sx: { mx: "auto", width: "100%" }, children: [
1583
1606
  !hideTitle && /* @__PURE__ */ jsx(Typography, { variant: "h6", gutterBottom: true, sx: { mb: 2, fontWeight: 600 }, children: formSchema.title }),
@@ -1621,7 +1644,8 @@ var FormRenderer = ({
1621
1644
  setUploadingFiles,
1622
1645
  setError,
1623
1646
  clearErrors,
1624
- services
1647
+ services,
1648
+ colors
1625
1649
  }
1626
1650
  )
1627
1651
  },
@@ -1631,7 +1655,7 @@ var FormRenderer = ({
1631
1655
  }
1632
1656
  );
1633
1657
  if (sectionDisplayMode === "stepper") {
1634
- return /* @__PURE__ */ jsxs(Box, { sx: { border: "1px solid", borderColor: "divider", p: 5, backgroundColor: "background.paper" }, children: [
1658
+ return /* @__PURE__ */ jsxs(Box, { sx: { border: "1px solid", borderColor: formColors.divider, p: 5, backgroundColor: formColors.backgroundPaper }, children: [
1635
1659
  /* @__PURE__ */ jsx(Stepper, { activeStep, orientation: "horizontal", children: formSchema.sections.map((section) => /* @__PURE__ */ jsx(Step, { children: /* @__PURE__ */ jsx(StepLabel, { children: /* @__PURE__ */ jsx(Typography, { variant: "subtitle1", sx: { fontWeight: 600 }, children: section.title }) }) }, section.id)) }),
1636
1660
  /* @__PURE__ */ jsx(Box, { sx: { mt: 5 }, children: formSchema.sections.map((section, sectionIndex) => {
1637
1661
  const sectionsLength = formSchema.sections?.length || 0;
@@ -1642,15 +1666,15 @@ var FormRenderer = ({
1642
1666
  display: activeStep === sectionIndex ? "block" : "none"
1643
1667
  },
1644
1668
  children: [
1645
- section.description && /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", sx: { mb: 1.5, display: "block" }, children: section.description }),
1669
+ section.description && /* @__PURE__ */ jsx(Typography, { variant: "caption", sx: { mb: 1.5, display: "block", color: formColors.textSecondary }, children: section.description }),
1646
1670
  renderFieldsGrid(section),
1647
- /* @__PURE__ */ jsxs(Box, { sx: { mt: 2, display: "flex", gap: 1, borderTop: "1px solid", pt: 2, borderColor: "divider", justifyContent: "center" }, children: [
1671
+ /* @__PURE__ */ jsxs(Box, { sx: { mt: 2, display: "flex", gap: 1, borderTop: "1px solid", pt: 2, borderColor: formColors.divider, justifyContent: "center" }, children: [
1648
1672
  sectionIndex > 0 && /* @__PURE__ */ jsx(
1649
1673
  Button,
1650
1674
  {
1651
1675
  size: "small",
1652
1676
  variant: "outlined",
1653
- color: "success",
1677
+ sx: { borderColor: formColors.success, color: formColors.success, "&:hover": { borderColor: formColors.success, backgroundColor: `${formColors.success}15` } },
1654
1678
  startIcon: /* @__PURE__ */ jsx(ArrowBackIcon, {}),
1655
1679
  onClick: () => setActiveStep(sectionIndex - 1),
1656
1680
  children: "Previous"
@@ -1661,7 +1685,7 @@ var FormRenderer = ({
1661
1685
  {
1662
1686
  variant: "outlined",
1663
1687
  size: "small",
1664
- color: "warning",
1688
+ sx: { borderColor: formColors.warning, color: formColors.warning, "&:hover": { borderColor: formColors.warning, backgroundColor: `${formColors.warning}15` } },
1665
1689
  endIcon: /* @__PURE__ */ jsx(ArrowForwardIcon, {}),
1666
1690
  onClick: () => {
1667
1691
  if (sectionIndex < sectionsLength - 1) {
@@ -1687,13 +1711,13 @@ var FormRenderer = ({
1687
1711
  "aria-controls": `panel-${section.id}-content`,
1688
1712
  id: `panel-${section.id}-header`,
1689
1713
  children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
1690
- /* @__PURE__ */ jsx(DoubleArrowOutlinedIcon, { fontSize: "small", color: "primary" }),
1691
- /* @__PURE__ */ jsx(Typography, { variant: "subtitle1", color: "primary", sx: { fontWeight: 600 }, children: section.title })
1714
+ /* @__PURE__ */ jsx(DoubleArrowOutlinedIcon, { fontSize: "small", sx: { color: formColors.primary } }),
1715
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle1", sx: { fontWeight: 600, color: formColors.primary }, children: section.title })
1692
1716
  ] })
1693
1717
  }
1694
1718
  ),
1695
1719
  /* @__PURE__ */ jsxs(AccordionDetails, { children: [
1696
- section.description && /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", sx: { mb: 1.5, display: "block" }, children: section.description }),
1720
+ section.description && /* @__PURE__ */ jsx(Typography, { variant: "caption", sx: { mb: 1.5, display: "block", color: formColors.textSecondary }, children: section.description }),
1697
1721
  renderFieldsGrid(section)
1698
1722
  ] })
1699
1723
  ] }, section.id)) });
@@ -1735,7 +1759,8 @@ var FormRenderer = ({
1735
1759
  setUploadingFiles,
1736
1760
  setError,
1737
1761
  clearErrors,
1738
- services
1762
+ services,
1763
+ colors
1739
1764
  }
1740
1765
  )
1741
1766
  },
@@ -1752,7 +1777,7 @@ var FormRenderer = ({
1752
1777
  type: "submit",
1753
1778
  variant: "contained",
1754
1779
  size: "small",
1755
- sx: { minWidth: 120 },
1780
+ sx: { minWidth: 120, backgroundColor: formColors.primary, "&:hover": { backgroundColor: formColors.primary } },
1756
1781
  disabled: isLoading,
1757
1782
  children: isLoading ? "Submitting..." : "Submit"
1758
1783
  }