UNPKG

@etsoo/materialui

Version:

TypeScript Material-UI Implementation

40 lines (39 loc) 2.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SwitchField = SwitchField; const jsx_runtime_1 = require("react/jsx-runtime"); const OutlinedInput_1 = __importDefault(require("@mui/material/OutlinedInput")); const react_1 = __importDefault(require("react")); const SwitchAnt_1 = require("./SwitchAnt"); const FormControl_1 = __importDefault(require("@mui/material/FormControl")); const InputLabel_1 = __importDefault(require("@mui/material/InputLabel")); const Box_1 = __importDefault(require("@mui/material/Box")); const FormHelperText_1 = __importDefault(require("@mui/material/FormHelperText")); /** * SwitchField * @param props Props * @returns Component */ function SwitchField(props) { // Destruct const { activeColor, startLabel, endLabel, value = true, fullWidth, helperText, label, name, required, checked, variant = "outlined", ...rest } = props; // Outlined const outlined = variant === "outlined"; // Group const group = ((0, jsx_runtime_1.jsx)(SwitchAnt_1.SwitchAnt, { activeColor: activeColor, name: name, startLabel: startLabel, endLabel: endLabel, value: value, checked: checked })); // Layout return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsxs)(FormControl_1.default, { fullWidth: fullWidth, ...rest, children: [label && ((0, jsx_runtime_1.jsx)(InputLabel_1.default, { required: required, variant: variant, shrink: true, children: label })), outlined ? ((0, jsx_runtime_1.jsx)(OutlinedInput_1.default, { label: label && required ? label + " *" : label, notched: true, endAdornment: group, sx: { cursor: "default", display: "flex", gap: 1, paddingX: 2, paddingY: "7px", width: fullWidth ? "100%" : "auto", "& input": { display: "none" } } })) : ((0, jsx_runtime_1.jsx)(Box_1.default, { paddingLeft: 2, paddingY: "7px", children: group }))] }), helperText && (0, jsx_runtime_1.jsx)(FormHelperText_1.default, { children: helperText })] })); }