You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SplitButton.js 3.3 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  3. import React from 'react';
  4. import PropTypes from 'prop-types';
  5. import Button from './Button';
  6. import ButtonGroup from './ButtonGroup';
  7. import Dropdown from './Dropdown';
  8. var propTypes = {
  9. /**
  10. * An html id attribute for the Toggle button, necessary for assistive technologies, such as screen readers.
  11. * @type {string|number}
  12. * @required
  13. */
  14. id: PropTypes.any,
  15. /**
  16. * Accessible label for the toggle; the value of `title` if not specified.
  17. */
  18. toggleLabel: PropTypes.string,
  19. /** An `href` passed to the non-toggle Button */
  20. href: PropTypes.string,
  21. /** An anchor `target` passed to the non-toggle Button */
  22. target: PropTypes.string,
  23. /** An `onClick` handler passed to the non-toggle Button */
  24. onClick: PropTypes.func,
  25. /** The content of the non-toggle Button. */
  26. title: PropTypes.node.isRequired,
  27. /** A `type` passed to the non-toggle Button */
  28. type: PropTypes.string,
  29. /** Disables both Buttons */
  30. disabled: PropTypes.bool,
  31. /** An ARIA accessible role applied to the Menu component. When set to 'menu', The dropdown */
  32. menuRole: PropTypes.string,
  33. /** Whether to render the dropdown menu in the DOM before the first time it is shown */
  34. renderMenuOnMount: PropTypes.bool,
  35. /**
  36. * Which event when fired outside the component will cause it to be closed.
  37. *
  38. * _see [DropdownMenu](#menu-props) for more details_
  39. */
  40. rootCloseEvent: PropTypes.string,
  41. /** @ignore */
  42. bsPrefix: PropTypes.string,
  43. /** @ignore */
  44. variant: PropTypes.string,
  45. /** @ignore */
  46. size: PropTypes.string
  47. };
  48. var defaultProps = {
  49. toggleLabel: 'Toggle dropdown',
  50. type: 'button'
  51. };
  52. var SplitButton = React.forwardRef(function (_ref, ref) {
  53. var id = _ref.id,
  54. bsPrefix = _ref.bsPrefix,
  55. size = _ref.size,
  56. variant = _ref.variant,
  57. title = _ref.title,
  58. type = _ref.type,
  59. toggleLabel = _ref.toggleLabel,
  60. children = _ref.children,
  61. onClick = _ref.onClick,
  62. href = _ref.href,
  63. target = _ref.target,
  64. menuRole = _ref.menuRole,
  65. renderMenuOnMount = _ref.renderMenuOnMount,
  66. rootCloseEvent = _ref.rootCloseEvent,
  67. props = _objectWithoutPropertiesLoose(_ref, ["id", "bsPrefix", "size", "variant", "title", "type", "toggleLabel", "children", "onClick", "href", "target", "menuRole", "renderMenuOnMount", "rootCloseEvent"]);
  68. return /*#__PURE__*/React.createElement(Dropdown, _extends({
  69. ref: ref
  70. }, props, {
  71. as: ButtonGroup
  72. }), /*#__PURE__*/React.createElement(Button, {
  73. size: size,
  74. variant: variant,
  75. disabled: props.disabled,
  76. bsPrefix: bsPrefix,
  77. href: href,
  78. target: target,
  79. onClick: onClick,
  80. type: type
  81. }, title), /*#__PURE__*/React.createElement(Dropdown.Toggle, {
  82. split: true,
  83. id: id,
  84. size: size,
  85. variant: variant,
  86. disabled: props.disabled,
  87. childBsPrefix: bsPrefix
  88. }, /*#__PURE__*/React.createElement("span", {
  89. className: "sr-only"
  90. }, toggleLabel)), /*#__PURE__*/React.createElement(Dropdown.Menu, {
  91. role: menuRole,
  92. renderOnMount: renderMenuOnMount,
  93. rootCloseEvent: rootCloseEvent
  94. }, children));
  95. });
  96. SplitButton.propTypes = propTypes;
  97. SplitButton.defaultProps = defaultProps;
  98. SplitButton.displayName = 'SplitButton';
  99. export default SplitButton;