UNPKG

@nish1896/rhf-mui-components

Version:

A suite of 25+ production-ready react-hook-form components built with material-ui. Fully typed, tree-shakable, and optimized for enterprise-grade forms.

35 lines (34 loc) 1.08 kB
import { RHFMuiConfigContext } from "../config/ConfigProvider.js"; import { Fragment, useContext } from "react"; import { jsx } from "react/jsx-runtime"; import MuiFormLabel from "@mui/material/FormLabel"; import { styled } from "@mui/material/styles"; //#region src/common/FormLabel.tsx /** * When label was a typography component, the asterisk was * rendering in a new line, the "StyledFormLabel" component * addresses this issue. */ const StyledFormLabel = styled(MuiFormLabel)(() => ({ display: "flex", flexDirection: "row" })); const FormLabel = ({ label, required, error, isVisible, disabled, formLabelProps }) => { const { defaultFormLabelSx } = useContext(RHFMuiConfigContext); const { sx, ...otherLabelProps } = formLabelProps ?? {}; const appliedLabelSx = { ...defaultFormLabelSx, ...sx }; if (!isVisible) return null; return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(StyledFormLabel, { ...otherLabelProps, disabled, required, error, sx: appliedLabelSx, children: label }) }); }; //#endregion export { FormLabel as default };