UNPKG

1.72 kBJavaScriptView Raw
1import classNames from 'classnames';
2import * as React from 'react';
3import { useContext } from 'react';
4import { useDropdownToggle } from '@restart/ui/DropdownToggle';
5import DropdownContext from '@restart/ui/DropdownContext';
6import useMergedRefs from '@restart/hooks/useMergedRefs';
7import Button from './Button';
8import InputGroupContext from './InputGroupContext';
9import { useBootstrapPrefix } from './ThemeProvider';
10import useWrappedRefWithWarning from './useWrappedRefWithWarning';
11import { jsx as _jsx } from "react/jsx-runtime";
12const DropdownToggle = /*#__PURE__*/React.forwardRef(({
13 bsPrefix,
14 split,
15 className,
16 childBsPrefix,
17 // Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
18 as: Component = Button,
19 ...props
20}, ref) => {
21 const prefix = useBootstrapPrefix(bsPrefix, 'dropdown-toggle');
22 const dropdownContext = useContext(DropdownContext);
23 const isInputGroup = useContext(InputGroupContext);
24
25 if (childBsPrefix !== undefined) {
26 props.bsPrefix = childBsPrefix;
27 }
28
29 const [toggleProps] = useDropdownToggle();
30 toggleProps.ref = useMergedRefs(toggleProps.ref, useWrappedRefWithWarning(ref, 'DropdownToggle')); // This intentionally forwards size and variant (if set) to the
31 // underlying component, to allow it to render size and style variants.
32
33 return /*#__PURE__*/_jsx(Component, {
34 className: classNames(className, prefix, split && `${prefix}-split`, !!isInputGroup && (dropdownContext == null ? void 0 : dropdownContext.show) && 'show'),
35 ...toggleProps,
36 ...props
37 });
38});
39DropdownToggle.displayName = 'DropdownToggle';
40export default DropdownToggle;
\No newline at end of file