UNPKG

@gluestack-ui/core

Version:

Universal UI components for React Native, Expo, and Next.js

38 lines 2.02 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { forwardRef } from 'react'; import { combineContextAndProps } from '@gluestack-ui/utils/common'; import { useFormControlContext } from './useFormControl'; import { mergeRefs } from '@gluestack-ui/utils/common'; const FormControlLabel = ({ Label: StyledFormControlLabel, LabelAstrick: StyledFormControlLabelAstrick, }) => forwardRef((_a, ref) => { var { children } = _a, props = __rest(_a, ["children"]); const formControlContext = useFormControlContext(); const _b = combineContextAndProps(formControlContext, props), { isRequired } = _b, combinedProps = __rest(_b, ["isRequired"]); const _ref = React.useRef(null); const mergedRef = mergeRefs([_ref, ref]); React.useEffect(() => { if (_ref.current) { if (props.htmlFor) { _ref.current.htmlFor = props.htmlFor; } else if (combinedProps === null || combinedProps === void 0 ? void 0 : combinedProps.id) { _ref.current.htmlFor = combinedProps.id; } } }, [combinedProps === null || combinedProps === void 0 ? void 0 : combinedProps.id, props.htmlFor]); return (<StyledFormControlLabel ref={mergedRef} {...combinedProps} id={combinedProps === null || combinedProps === void 0 ? void 0 : combinedProps.labelId}> {children} {isRequired && (<StyledFormControlLabelAstrick>*</StyledFormControlLabelAstrick>)} </StyledFormControlLabel>); }); export default FormControlLabel; //# sourceMappingURL=FormControlLabel.jsx.map