@aatulwork/customform-renderer 1.10.0 → 1.12.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/fields.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Controller, useWatch } from 'react-hook-form';
2
- import { FormControl, FormLabel, TextField as TextField$1, FormControlLabel, Checkbox, RadioGroup, Radio, Box, Typography, Switch, Input, useTheme, FormHelperText, alpha, useMediaQuery, CircularProgress, Tooltip, IconButton, InputLabel, Select, ListSubheader, MenuItem, Chip, InputAdornment, OutlinedInput } from '@mui/material';
2
+ import { FormControl, FormLabel, TextField as TextField$1, FormControlLabel, Checkbox, RadioGroup, Radio, Box, Typography, Switch, useTheme, FormHelperText, alpha, useMediaQuery, CircularProgress, Tooltip, IconButton, Select, ListSubheader, MenuItem, Chip, InputAdornment, OutlinedInput } from '@mui/material';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
- import { useMemo, useRef, useEffect, useCallback, useState } from 'react';
4
+ import { useMemo, useRef, useEffect, useCallback, useState, useId } from 'react';
5
5
  import RefreshIcon from '@mui/icons-material/Refresh';
6
6
  import { DatePicker } from '@mui/x-date-pickers/DatePicker';
7
7
  import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
@@ -154,12 +154,9 @@ var SimpleSelect = ({
154
154
  onRefresh
155
155
  }) => {
156
156
  const [filterText, setFilterText] = useState("");
157
+ const selectId = useId();
157
158
  const handleChange = (event) => {
158
159
  const val = event.target.value;
159
- if (val === "__refresh__") {
160
- onRefresh?.();
161
- return;
162
- }
163
160
  onChange(val);
164
161
  };
165
162
  const filteredOptions = filterable && filterText ? options.filter(
@@ -172,14 +169,25 @@ var SimpleSelect = ({
172
169
  setFilterText("");
173
170
  };
174
171
  return /* @__PURE__ */ jsxs(FormControl, { fullWidth, size, required, error, disabled, children: [
175
- /* @__PURE__ */ jsx(InputLabel, { children: label }),
172
+ /* @__PURE__ */ jsx(
173
+ FormLabel,
174
+ {
175
+ component: "label",
176
+ htmlFor: selectId,
177
+ required,
178
+ error,
179
+ sx: { mb: 0.5, display: "block" },
180
+ children: label
181
+ }
182
+ ),
176
183
  /* @__PURE__ */ jsxs(
177
184
  Select,
178
185
  {
186
+ id: selectId,
179
187
  value: value ?? (multiple ? [] : ""),
180
188
  onChange: handleChange,
181
189
  onClose: handleClose,
182
- input: /* @__PURE__ */ jsx(OutlinedInput, { label }),
190
+ input: /* @__PURE__ */ jsx(OutlinedInput, {}),
183
191
  MenuProps: {
184
192
  autoFocus: false
185
193
  },
@@ -381,40 +389,48 @@ var ColorField = ({ field, control, defaultValue, rules, errors }) => {
381
389
  control,
382
390
  defaultValue,
383
391
  rules,
384
- render: ({ field: formField }) => /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 2, width: "100%" }, children: [
385
- /* @__PURE__ */ jsx(
386
- FormLabel,
387
- {
388
- required: field.required,
389
- error: !!errors[field.name],
390
- children: field.label
391
- }
392
- ),
393
- /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", flex: 1, maxWidth: 200 }, children: [
392
+ render: ({ field: formField }) => {
393
+ const inputId = `color-field-${field.name}`;
394
+ return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 2, width: "100%" }, children: [
394
395
  /* @__PURE__ */ jsx(
395
- Input,
396
+ FormLabel,
396
397
  {
397
- ...formField,
398
- type: "color",
399
- sx: {
400
- width: "20%",
401
- height: "40px",
402
- cursor: "pointer",
403
- border: errors[field.name] ? "1px solid red" : "1px solid rgba(0, 0, 0, 0.23)",
404
- borderRadius: "4px",
405
- padding: "1px"
406
- },
407
- inputProps: {
408
- style: {
409
- height: "100%",
410
- cursor: "pointer"
411
- }
412
- }
398
+ component: "label",
399
+ htmlFor: inputId,
400
+ required: field.required,
401
+ error: !!errors[field.name],
402
+ children: field.label
413
403
  }
414
404
  ),
415
- errors[field.name] && /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "error", sx: { mt: 0.5 }, children: errors[field.name]?.message })
416
- ] })
417
- ] })
405
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", flex: 1, maxWidth: 200 }, children: [
406
+ /* @__PURE__ */ jsx(
407
+ Box,
408
+ {
409
+ component: "input",
410
+ type: "color",
411
+ id: inputId,
412
+ ref: formField.ref,
413
+ name: formField.name,
414
+ value: formField.value ?? "#000000",
415
+ onChange: formField.onChange,
416
+ onBlur: formField.onBlur,
417
+ sx: {
418
+ width: 30,
419
+ height: 30,
420
+ padding: 0,
421
+ cursor: "pointer",
422
+ backgroundColor: "transparent",
423
+ border: "none",
424
+ "&::-webkit-color-swatch-wrapper": { padding: 0 },
425
+ "&::-webkit-color-swatch": { border: "none", borderRadius: "4px" },
426
+ "&::-moz-color-swatch": { border: "none", borderRadius: "4px" }
427
+ }
428
+ }
429
+ ),
430
+ errors[field.name] && /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "error", sx: { mt: 0.5 }, children: errors[field.name]?.message })
431
+ ] })
432
+ ] });
433
+ }
418
434
  },
419
435
  field.name
420
436
  );