formik-form-components 0.2.20 → 0.2.22

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
@@ -1,5 +1,5 @@
1
1
  import { useFormikContext, Formik, Form as Form$1, ErrorMessage } from 'formik';
2
- import { forwardRef, memo, createElement, useState, useEffect } from 'react';
2
+ import { forwardRef, memo, createElement, useState, useMemo, useEffect } from 'react';
3
3
  import { Box, useTheme, FormControl, Typography, FormHelperText, TextField, InputLabel, FormLabel, RadioGroup, FormControlLabel, Radio, Stack, Rating, Autocomplete, MenuItem, Chip, Switch, InputAdornment, IconButton, Checkbox, Tooltip, Dialog, DialogTitle, DialogContent, DialogActions, Button, CircularProgress, Paper, Menu } from '@mui/material';
4
4
  import { DatePicker } from '@mui/x-date-pickers/DatePicker';
5
5
  import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
@@ -1478,79 +1478,99 @@ var AppMultiSelector_default = AppMultiSelector;
1478
1478
  var AppPhoneNoInput = ({
1479
1479
  name,
1480
1480
  label,
1481
- required,
1481
+ required = false,
1482
+ defaultCountry = "us",
1483
+ placeholder,
1482
1484
  sx,
1483
1485
  containerSx,
1484
1486
  labelSx,
1485
1487
  inputSx,
1486
- errorSx,
1487
- ...otherProps
1488
+ errorSx
1488
1489
  }) => {
1489
- const { values, errors, touched, setFieldValue, getFieldProps } = useFormikContext();
1490
- const fieldError = _19.get(errors, name);
1491
- const isTouched = _19.get(touched, name);
1492
- return /* @__PURE__ */ jsxs(Box, { sx: [{ mb: 2 }, containerSx, sx], children: [
1493
- label && /* @__PURE__ */ jsxs(
1494
- Typography,
1495
- {
1496
- variant: "subtitle2",
1497
- sx: [{
1498
- mb: 0.5,
1499
- color: isTouched && fieldError ? "error.main" : "text.primary"
1500
- }, labelSx],
1501
- children: [
1502
- label,
1503
- required && /* @__PURE__ */ jsx(
1504
- Typography,
1505
- {
1506
- component: "span",
1507
- sx: {
1508
- color: "error.main",
1509
- ml: 0.3
1490
+ const { values, errors, touched, setFieldValue, setFieldTouched } = useFormikContext();
1491
+ const fieldError = useMemo(() => _19.get(errors, name), [errors, name]);
1492
+ const isTouched = useMemo(() => _19.get(touched, name), [touched, name]);
1493
+ return /* @__PURE__ */ jsxs(
1494
+ Box,
1495
+ {
1496
+ sx: [{ mb: 2 }, containerSx, sx],
1497
+ "data-testid": `phone-input-${name}`,
1498
+ children: [
1499
+ label && /* @__PURE__ */ jsxs(
1500
+ Typography,
1501
+ {
1502
+ variant: "subtitle2",
1503
+ sx: [
1504
+ {
1505
+ mb: 0.5,
1506
+ color: isTouched && fieldError ? "error.main" : "text.primary"
1510
1507
  },
1511
- children: "*"
1512
- }
1513
- )
1514
- ]
1515
- }
1516
- ),
1517
- /* @__PURE__ */ jsx(
1518
- PhoneInput,
1519
- {
1520
- country: "us",
1521
- specialLabel: "",
1522
- inputStyle: {
1523
- width: "100%",
1524
- border: isTouched && fieldError ? "1px solid #f44336" : "1px solid #ccc",
1525
- padding: "10px",
1526
- borderRadius: "4px",
1527
- ...inputSx
1528
- },
1529
- containerStyle: {
1530
- width: "100%"
1531
- },
1532
- ...otherProps,
1533
- ...getFieldProps(name),
1534
- value: values[name],
1535
- onChange: (value) => setFieldValue(name, value)
1536
- }
1537
- ),
1538
- isTouched && fieldError && /* @__PURE__ */ jsxs(
1539
- Typography,
1540
- {
1541
- variant: "caption",
1542
- sx: [{
1543
- mt: 0.5,
1544
- display: "block",
1545
- color: "error.main"
1546
- }, errorSx],
1547
- children: [
1548
- String(fieldError),
1549
- " "
1550
- ]
1551
- }
1552
- )
1553
- ] });
1508
+ labelSx
1509
+ ],
1510
+ children: [
1511
+ label,
1512
+ required && /* @__PURE__ */ jsx(
1513
+ Typography,
1514
+ {
1515
+ component: "span",
1516
+ sx: {
1517
+ color: "error.main",
1518
+ ml: 0.3
1519
+ },
1520
+ children: "*"
1521
+ }
1522
+ )
1523
+ ]
1524
+ }
1525
+ ),
1526
+ /* @__PURE__ */ jsx(
1527
+ PhoneInput,
1528
+ {
1529
+ country: defaultCountry,
1530
+ specialLabel: "",
1531
+ placeholder,
1532
+ inputProps: {
1533
+ name,
1534
+ id: name,
1535
+ required,
1536
+ "aria-describedby": fieldError ? `${name}-error` : void 0,
1537
+ "aria-invalid": !!fieldError,
1538
+ "aria-required": required
1539
+ },
1540
+ inputStyle: {
1541
+ width: "100%",
1542
+ border: isTouched && fieldError ? "1px solid #f44336" : "1px solid #ccc",
1543
+ padding: "10px",
1544
+ borderRadius: "4px",
1545
+ ...inputSx
1546
+ },
1547
+ containerStyle: {
1548
+ width: "100%"
1549
+ },
1550
+ value: values[name],
1551
+ onChange: (value) => setFieldValue(name, value),
1552
+ onBlur: () => setFieldTouched(name, true)
1553
+ }
1554
+ ),
1555
+ isTouched && fieldError && /* @__PURE__ */ jsx(
1556
+ Typography,
1557
+ {
1558
+ variant: "caption",
1559
+ id: `${name}-error`,
1560
+ sx: [
1561
+ {
1562
+ mt: 0.5,
1563
+ display: "block",
1564
+ color: "error.main"
1565
+ },
1566
+ errorSx
1567
+ ],
1568
+ children: String(fieldError)
1569
+ }
1570
+ )
1571
+ ]
1572
+ }
1573
+ );
1554
1574
  };
1555
1575
  var AppPhoneNoInput_default = AppPhoneNoInput;
1556
1576
  var AppRadioGroup = forwardRef(({