UNPKG

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