@wordpress/components
Version:
UI components for WordPress.
8 lines (7 loc) • 5.31 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/base-control/index.tsx"],
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { VisuallyHidden } from '../visually-hidden';\nimport { Wrapper, StyledField, StyledLabel, StyledHelp, StyledVisualLabel } from './styles/base-control-styles';\nimport { contextConnectWithoutRef, useContextSystem } from '../context';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nexport { useBaseControlProps } from './hooks';\nconst UnconnectedBaseControl = props => {\n const {\n id,\n label,\n hideLabelFromVision = false,\n help,\n className,\n children\n } = useContextSystem(props, 'BaseControl');\n return /*#__PURE__*/_jsxs(Wrapper, {\n className: className,\n children: [/*#__PURE__*/_jsxs(StyledField, {\n className: \"components-base-control__field\",\n children: [label && id && (hideLabelFromVision ? /*#__PURE__*/_jsx(VisuallyHidden, {\n as: \"label\",\n htmlFor: id,\n children: label\n }) : /*#__PURE__*/_jsx(StyledLabel, {\n className: \"components-base-control__label\",\n htmlFor: id,\n children: label\n })), label && !id && (hideLabelFromVision ? /*#__PURE__*/_jsx(VisuallyHidden, {\n as: \"label\",\n children: label\n }) : /*#__PURE__*/_jsx(VisualLabel, {\n children: label\n })), children]\n }), !!help && /*#__PURE__*/_jsx(StyledHelp, {\n id: id ? id + '__help' : undefined,\n className: \"components-base-control__help\",\n children: help\n })]\n });\n};\nconst UnforwardedVisualLabel = (props, ref) => {\n const {\n className,\n children,\n ...restProps\n } = props;\n return /*#__PURE__*/_jsx(StyledVisualLabel, {\n ref: ref,\n ...restProps,\n className: clsx('components-base-control__label', className),\n children: children\n });\n};\nexport const VisualLabel = forwardRef(UnforwardedVisualLabel);\n\n/**\n * `BaseControl` is a low-level component used to generate labels and help text for components handling user inputs.\n *\n * ```jsx\n * import { BaseControl, useBaseControlProps } from '@wordpress/components';\n *\n * // Render a `BaseControl` for a textarea input\n * const MyCustomTextareaControl = ({ children, ...baseProps }) => (\n * \t// `useBaseControlProps` is a convenience hook to get the props for the `BaseControl`\n * \t// and the inner control itself. Namely, it takes care of generating a unique `id`,\n * \t// properly associating it with the `label` and `help` elements.\n * \tconst { baseControlProps, controlProps } = useBaseControlProps( baseProps );\n *\n * \treturn (\n * \t\t<BaseControl { ...baseControlProps }>\n * \t\t\t<textarea { ...controlProps }>\n * \t\t\t { children }\n * \t\t\t</textarea>\n * \t\t</BaseControl>\n * \t);\n * );\n * ```\n */\nexport const BaseControl = Object.assign(contextConnectWithoutRef(UnconnectedBaseControl, 'BaseControl'), {\n /**\n * `BaseControl.VisualLabel` is used to render a purely visual label inside a `BaseControl` component.\n *\n * It should only be used in cases where the children being rendered inside `BaseControl` are already accessibly labeled,\n * e.g., a button, but we want an additional visual label for that section equivalent to the labels `BaseControl` would\n * otherwise use if the `label` prop was passed.\n *\n * ```jsx\n * import { BaseControl } from '@wordpress/components';\n *\n * const MyBaseControl = () => (\n * \t<BaseControl help=\"This button is already accessibly labeled.\">\n * \t\t<BaseControl.VisualLabel>Author</BaseControl.VisualLabel>\n * \t\t<Button>Select an author</Button>\n * \t</BaseControl>\n * );\n * ```\n */\n VisualLabel\n});\nexport default BaseControl;"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAIjB,qBAA2B;AAK3B,6BAA+B;AAC/B,iCAAiF;AACjF,qBAA2D;AAC3D,yBAA2C;AAC3C,mBAAoC;AACpC,IAAM,yBAAyB,WAAS;AACtC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,sBAAsB;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,EACF,QAAI,iCAAiB,OAAO,aAAa;AACzC,SAAoB,uCAAAA,MAAM,oCAAS;AAAA,IACjC;AAAA,IACA,UAAU,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