UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

69 lines 1.79 kB
import React, { useMemo } from 'react'; import StringField from "../String/index.js"; import useTranslation from "../../hooks/useTranslation.js"; import withComponentMarkers from "../../../../shared/helpers/withComponentMarkers.js"; import { jsx as _jsx } from "react/jsx-runtime"; function Address(props) { const { element: Element = StringField, ...rest } = props; if (Element === StringField) { Object.assign(rest, { autoComplete: 'street-address', inputMode: 'text', trim: true, ...rest }); } return _jsx(Element, { ...rest }); } withComponentMarkers(Address, { _supportsSpacingProps: true }); Address.Postal = function PostalAddress(props) { const { label, errorRequired, errorPattern } = useTranslation().PostalAddress; const errorMessages = useMemo(() => ({ 'Field.errorRequired': errorRequired, 'Field.errorPattern': errorPattern, ...props.errorMessages }), [errorPattern, errorRequired, props.errorMessages]); const postalAddressProps = { label, errorMessages, ...props }; return _jsx(Address, { ...postalAddressProps }); }; Address.Postal['_supportsSpacingProps'] = true; Address.Street = function StreetAddress(props) { const { label, errorRequired, errorPattern } = useTranslation().StreetAddress; const errorMessages = useMemo(() => ({ 'Field.errorRequired': errorRequired, 'Field.errorPattern': errorPattern, ...props.errorMessages }), [errorPattern, errorRequired, props.errorMessages]); const streetAddressProps = { label, errorMessages, ...props }; return _jsx(Address, { ...streetAddressProps }); }; Address.Street['_supportsSpacingProps'] = true; export default Address; //# sourceMappingURL=Address.js.map