import React from 'react'; import PropTypes from 'prop-types'; import ControlGroupContext from './ControlGroupContext'; import { ComponentProps } from '../utils/types'; interface ControlGroupPropsBase { children?: React.ReactNode; /** * A layout defines how controls are aligned and displayed. */ controlsLayout?: 'fill' | 'fillJoin' | 'none' | 'stack'; /** * A React ref which is set to the DOM element when the component mounts and null when it unmounts. */ elementRef?: React.Ref; /** * Highlight the control group as having an error and optionally provide error text. * If error text is provided, displays it below the control. * In addition to passing this prop, set the error prop on child components. */ error?: boolean | string; help?: React.ReactNode; /** * Hide the `label` visually but still render it for screen readers. * Only enable this prop if the purpose of the control is clear enough from the context. * Enabling this prop will hide `tooltip`. */ hideLabel?: boolean; label: string; /** * Override the `for` attribute of the `label`. See the component description for details. */ labelFor?: string; labelPosition?: 'left' | 'top'; /** * When labelPosition is left, the width of the label in pixels or a value with a unit. */ labelWidth?: number | string; /** * Sets the control required and adds an asterisk before the `label`. */ required?: boolean; /** * Displays a tooltip beside the `label`. */ tooltip?: React.ReactNode; /** * If a `tooltip` is provided, sets its default placement. */ tooltipDefaultPlacement?: 'above' | 'below' | 'left' | 'right'; } type ControlGroupProps = ComponentProps; /** * `ControlGroup` places a label and optional help text around one or more controls. The `ControlGroup` * will automatically add aria attributes to associate the controls with the labels and help text to * address accessibility requirements. * * `ControlGroup` provides layouts to assist in aligning and laying out controls, but the defaults are * not helpful in all cases, nor will the layout options address all cases. Consider setting * `controlsLayout` to none and manually positioning the controls as required. * * `ControlGroup` uses the HTML `label` tag. The rules for determining which child component is linked * to the label's `for` attribute are: * 1. If one or more `children` are `Text` components, the first one is used. * 2. If there aren't any `Text` components, the first child is used. * * If the linked child supports an `inputId` prop and it's set, its value is used for the label's `for` * attribute. If `inputId` is supported but not set a generated id is used instead. If `inputId` isn't * supported `id` is used. The `labelFor` prop may be used to override the `for` attribute. */ declare function ControlGroup({ children, controlsLayout, error, help, hideLabel, label, labelFor, labelPosition, labelWidth, required, tooltip, tooltipDefaultPlacement, ...otherProps }: ControlGroupProps): React.JSX.Element; declare namespace ControlGroup { var propTypes: { children: PropTypes.Requireable; controlsLayout: PropTypes.Requireable; elementRef: PropTypes.Requireable; error: PropTypes.Requireable>; help: PropTypes.Requireable; hideLabel: PropTypes.Requireable; label: PropTypes.Validator; labelFor: PropTypes.Requireable; labelPosition: PropTypes.Requireable; labelWidth: PropTypes.Requireable>; required: PropTypes.Requireable; tooltip: PropTypes.Requireable; tooltipDefaultPlacement: PropTypes.Requireable; }; } export default ControlGroup; export { ControlGroupContext }; export type { ControlGroupPropsBase };