UNPKG

5.42 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5exports.__esModule = true;
6exports.default = void 0;
7
8var React = _interopRequireWildcard(require("react"));
9
10var _propTypes = _interopRequireDefault(require("prop-types"));
11
12var _Button = _interopRequireDefault(require("./Button"));
13
14var _ButtonGroup = _interopRequireDefault(require("./ButtonGroup"));
15
16var _Dropdown = _interopRequireDefault(require("./Dropdown"));
17
18var _types = require("./types");
19
20var _jsxRuntime = require("react/jsx-runtime");
21
22function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
24function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
26const propTypes = {
27 /**
28 * An html id attribute for the Toggle button, necessary for assistive technologies, such as screen readers.
29 * @type {string}
30 * @required
31 */
32 id: _propTypes.default.string,
33
34 /**
35 * Accessible label for the toggle; the value of `title` if not specified.
36 */
37 toggleLabel: _propTypes.default.string,
38
39 /** An `href` passed to the non-toggle Button */
40 href: _propTypes.default.string,
41
42 /** An anchor `target` passed to the non-toggle Button */
43 target: _propTypes.default.string,
44
45 /** An `onClick` handler passed to the non-toggle Button */
46 onClick: _propTypes.default.func,
47
48 /** The content of the non-toggle Button. */
49 title: _propTypes.default.node.isRequired,
50
51 /** A `type` passed to the non-toggle Button */
52 type: _propTypes.default.string,
53
54 /** Disables both Buttons */
55 disabled: _propTypes.default.bool,
56
57 /**
58 * Aligns the dropdown menu.
59 *
60 * _see [DropdownMenu](#dropdown-menu-props) for more details_
61 *
62 * @type {"start"|"end"|{ sm: "start"|"end" }|{ md: "start"|"end" }|{ lg: "start"|"end" }|{ xl: "start"|"end"}|{ xxl: "start"|"end"} }
63 */
64 align: _types.alignPropType,
65
66 /** An ARIA accessible role applied to the Menu component. When set to 'menu', The dropdown */
67 menuRole: _propTypes.default.string,
68
69 /** Whether to render the dropdown menu in the DOM before the first time it is shown */
70 renderMenuOnMount: _propTypes.default.bool,
71
72 /**
73 * Which event when fired outside the component will cause it to be closed.
74 *
75 * _see [DropdownMenu](#dropdown-menu-props) for more details_
76 */
77 rootCloseEvent: _propTypes.default.string,
78
79 /** @ignore */
80 bsPrefix: _propTypes.default.string,
81
82 /** @ignore */
83 variant: _propTypes.default.string,
84
85 /** @ignore */
86 size: _propTypes.default.string
87};
88const defaultProps = {
89 toggleLabel: 'Toggle dropdown',
90 type: 'button'
91};
92/**
93 * A convenience component for simple or general use split button dropdowns. Renders a
94 * `ButtonGroup` containing a `Button` and a `Button` toggle for the `Dropdown`. All `children`
95 * are passed directly to the default `Dropdown.Menu`. This component accepts all of [`Dropdown`'s
96 * props](#dropdown-props).
97 *
98 * _All unknown props are passed through to the `Dropdown` component._
99 * The Button `variant`, `size` and `bsPrefix` props are passed to the button and toggle,
100 * and menu-related props are passed to the `Dropdown.Menu`
101 */
102
103const SplitButton = /*#__PURE__*/React.forwardRef(({
104 id,
105 bsPrefix,
106 size,
107 variant,
108 title,
109 type,
110 toggleLabel,
111 children,
112 onClick,
113 href,
114 target,
115 menuRole,
116 renderMenuOnMount,
117 rootCloseEvent,
118 ...props
119}, ref) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Dropdown.default, {
120 ref: ref,
121 ...props,
122 as: _ButtonGroup.default,
123 children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
124 size: size,
125 variant: variant,
126 disabled: props.disabled,
127 bsPrefix: bsPrefix,
128 href: href,
129 target: target,
130 onClick: onClick,
131 type: type,
132 children: title
133 }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.default.Toggle, {
134 split: true,
135 id: id,
136 size: size,
137 variant: variant,
138 disabled: props.disabled,
139 childBsPrefix: bsPrefix,
140 children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
141 className: "visually-hidden",
142 children: toggleLabel
143 })
144 }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.default.Menu, {
145 role: menuRole,
146 renderOnMount: renderMenuOnMount,
147 rootCloseEvent: rootCloseEvent,
148 children: children
149 })]
150}));
151SplitButton.propTypes = propTypes;
152SplitButton.defaultProps = defaultProps;
153SplitButton.displayName = 'SplitButton';
154var _default = SplitButton;
155exports.default = _default;
156module.exports = exports.default;
\No newline at end of file