UNPKG

@mui/joy

Version:

Joy UI is an open-source React component library that implements MUI's own design principles. It's comprehensive and can be used in production out of the box.

160 lines (159 loc) 5.53 kB
'use client'; import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["children", "component", "htmlFor", "id", "slots", "slotProps"]; import * as React from 'react'; import PropTypes from 'prop-types'; import { unstable_composeClasses as composeClasses } from '@mui/base/composeClasses'; import { styled, useThemeProps } from '../styles'; import useSlot from '../utils/useSlot'; import { getFormLabelUtilityClass } from './formLabelClasses'; import FormControlContext from '../FormControl/FormControlContext'; import { jsxs as _jsxs } from "react/jsx-runtime"; const useUtilityClasses = () => { const slots = { root: ['root'], asterisk: ['asterisk'] }; return composeClasses(slots, getFormLabelUtilityClass, {}); }; const FormLabelRoot = styled('label', { name: 'JoyFormLabel', slot: 'Root', overridesResolver: (props, styles) => styles.root })(({ theme }) => ({ '--Icon-fontSize': 'calc(var(--FormLabel-lineHeight) * 1em)', WebkitTapHighlightColor: 'transparent', alignSelf: 'var(--FormLabel-alignSelf)', // to not fill the block space. It seems like a bug when clicking on empty space (within the label area), even though it is not. display: 'flex', gap: '2px', alignItems: 'center', flexWrap: 'wrap', userSelect: 'none', fontFamily: theme.vars.fontFamily.body, fontSize: `var(--FormLabel-fontSize, ${theme.vars.fontSize.sm})`, fontWeight: theme.vars.fontWeight.md, lineHeight: `var(--FormLabel-lineHeight, ${theme.vars.lineHeight.sm})`, color: `var(--FormLabel-color, ${theme.vars.palette.text.primary})`, margin: 'var(--FormLabel-margin, 0px)' })); const AsteriskComponent = styled('span', { name: 'JoyFormLabel', slot: 'Asterisk', overridesResolver: (props, styles) => styles.asterisk })({ color: 'var(--FormLabel-asteriskColor)' }); /** * * Demos: * * - [Input](https://mui.com/joy-ui/react-input/) * * API: * * - [FormLabel API](https://mui.com/joy-ui/api/form-label/) */ const FormLabel = /*#__PURE__*/React.forwardRef(function FormLabel(inProps, ref) { var _ref, _inProps$required; const props = useThemeProps({ props: inProps, name: 'JoyFormLabel' }); const { children, component = 'label', htmlFor, id, slots = {}, slotProps = {} } = props, other = _objectWithoutPropertiesLoose(props, _excluded); const formControl = React.useContext(FormControlContext); const required = (_ref = (_inProps$required = inProps.required) != null ? _inProps$required : formControl == null ? void 0 : formControl.required) != null ? _ref : false; const ownerState = _extends({}, props, { required }); const classes = useUtilityClasses(); const externalForwardedProps = _extends({}, other, { component, slots, slotProps }); const [SlotRoot, rootProps] = useSlot('root', { additionalProps: { htmlFor: htmlFor != null ? htmlFor : formControl == null ? void 0 : formControl.htmlFor, id: id != null ? id : formControl == null ? void 0 : formControl.labelId }, ref, className: classes.root, elementType: FormLabelRoot, externalForwardedProps, ownerState }); const [SlotAsterisk, asteriskProps] = useSlot('asterisk', { additionalProps: { 'aria-hidden': true }, className: classes.asterisk, elementType: AsteriskComponent, externalForwardedProps, ownerState }); return /*#__PURE__*/_jsxs(SlotRoot, _extends({}, rootProps, { children: [children, required && /*#__PURE__*/_jsxs(SlotAsterisk, _extends({}, asteriskProps, { children: ["\u2009", '*'] }))] })); }); process.env.NODE_ENV !== "production" ? FormLabel.propTypes /* remove-proptypes */ = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * The content of the component. */ children: PropTypes.node, /** * The component used for the root node. * Either a string to use a HTML element or a component. */ component: PropTypes.elementType, /** * @ignore */ htmlFor: PropTypes.string, /** * @ignore */ id: PropTypes.string, /** * The asterisk is added if required=`true` */ required: PropTypes.bool, /** * The props used for each slot inside. * @default {} */ slotProps: PropTypes.shape({ asterisk: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]) }), /** * The components used for each slot inside. * @default {} */ slots: PropTypes.shape({ asterisk: PropTypes.elementType, root: PropTypes.elementType }), /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]) } : void 0; export default FormLabel;