@atlaskit/button
Version:
A button triggers an event or action. They let users know what will happen next.
150 lines (146 loc) • 7.21 kB
JavaScript
/* split-button.tsx generated by @compiled/babel-plugin v0.39.1 */
"use strict";
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SplitButtonWithSlots = exports.SplitButtonContainer = exports.SplitButton = exports.Divider = void 0;
require("./split-button.compiled.css");
var React = _interopRequireWildcard(require("react"));
var _runtime = require("@compiled/react/runtime");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _splitButtonContext = require("./split-button-context");
var _utils = require("./utils");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var dividerStyles = {
baseDivider: "_1bsbe4h9 _kqswh2mm _1pbykb7n",
dividerDisabled: "_bfhk9xzm _80om13gf",
dividerOffset: "_195g1n1a"
};
var dividerAppearanceStyles = {
default: "_bfhkmuej",
primary: "_bfhkveue _tzy41wzo",
navigation: "_1mouu2gc _195g1h5n _4t3i7vkz _bfhkdud1 _tzy419lr"
};
var dividerHeightStyles = {
default: "_4t3iviql",
compact: "_4t3i1k8s"
};
// The divider height is calculated by subtracting twice the border width from the button height.
// This ensures the divider does not intersect with the button's border, avoiding visual issues
// caused by overlapping alpha colors (color.border) at the intersection.
var defaultDividerHeightStyles = {
default: "_4t3im1ee",
compact: "_4t3i1hvu"
};
/**
* TODO: Add JSDoc
*/
var Divider = exports.Divider = function Divider(_ref) {
var appearance = _ref.appearance,
spacing = _ref.spacing,
_ref$isDisabled = _ref.isDisabled,
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled;
var isDefaultDivider = appearance === 'default' && !isDisabled;
return /*#__PURE__*/React.createElement("div", {
className: (0, _runtime.ax)([dividerStyles.baseDivider, isDefaultDivider && defaultDividerHeightStyles[spacing], !isDefaultDivider && dividerHeightStyles[spacing], isDisabled && dividerStyles.dividerDisabled, !isDisabled && dividerAppearanceStyles[appearance], dividerStyles.dividerOffset])
});
};
var buttonStyles = {
splitButton: "_1e0c116y _kqswh2mm _4cvr1h6o _o5721q9c",
primaryButton: "_traeidpf _anlpidpf _p9ykidpf _bepvidpf",
secondaryButton: "_1j4hidpf _1553idpf _1qgbidpf _y1n3idpf",
defaultAppearanceContainer: "_2rkofajl _12ji1l7x _1cwg1n1a _1qu2nqa1 _12y3t94y",
defaultAppearanceContainerT26Shape: "_2rko1qi0",
defaultAppearanceDisabledContainer: "_12jibk0g"
};
/**
* TODO: Add JSdoc
*/
var SplitButtonContainer = exports.SplitButtonContainer = function SplitButtonContainer(_ref2) {
var appearance = _ref2.appearance,
children = _ref2.children,
_ref2$isDisabled = _ref2.isDisabled,
isDisabled = _ref2$isDisabled === void 0 ? false : _ref2$isDisabled;
return /*#__PURE__*/React.createElement("div", {
className: (0, _runtime.ax)([appearance === 'default' && buttonStyles.defaultAppearanceContainer, appearance === 'default' && (0, _platformFeatureFlags.fg)('platform-dst-shape-theme-default') && buttonStyles.defaultAppearanceContainerT26Shape, appearance === 'default' && isDisabled && buttonStyles.defaultAppearanceDisabledContainer, buttonStyles.splitButton])
}, children);
};
/**
* __Split Button__
*
* A split button lets people perform an action or choose from a small group of similar actions.
*
* - [Examples](https://atlassian.design/components/button/split-button/examples)
* - [Code](https://atlassian.design/components/button/split-button/code)
* - [Usage](https://atlassian.design/components/button/split-button/usage)
*/
var SplitButton = exports.SplitButton = function SplitButton(_ref3) {
var children = _ref3.children,
_ref3$appearance = _ref3.appearance,
appearance = _ref3$appearance === void 0 ? 'default' : _ref3$appearance,
_ref3$spacing = _ref3.spacing,
spacing = _ref3$spacing === void 0 ? 'default' : _ref3$spacing,
_ref3$isDisabled = _ref3.isDisabled,
isDisabled = _ref3$isDisabled === void 0 ? false : _ref3$isDisabled;
var _getActions = (0, _utils.getActions)(children),
PrimaryAction = _getActions.PrimaryAction,
SecondaryAction = _getActions.SecondaryAction;
return /*#__PURE__*/React.createElement(SplitButtonContainer, {
appearance: appearance,
isDisabled: isDisabled
}, /*#__PURE__*/React.createElement(_splitButtonContext.SplitButtonContext.Provider, {
value: {
appearance: appearance,
spacing: spacing,
isDisabled: isDisabled
}
}, /*#__PURE__*/React.createElement("div", {
className: (0, _runtime.ax)([buttonStyles.primaryButton])
}, PrimaryAction), /*#__PURE__*/React.createElement(Divider, {
appearance: appearance,
spacing: spacing,
isDisabled: isDisabled
}), /*#__PURE__*/React.createElement("div", {
className: (0, _runtime.ax)([buttonStyles.secondaryButton])
}, SecondaryAction)));
};
// TODO: Fill in the component {description} and ensure links point to the correct {packageName} location.
// Remove links that the component does not have (such as usage). If there are no links remove them all.
/**
* __Split button with slots__
*
* A split button with slots {description}.
*
* - [Examples](https://atlassian.design/components/{packageName}/examples)
* - [Code](https://atlassian.design/components/{packageName}/code)
* - [Usage](https://atlassian.design/components/{packageName}/usage)
*/
var SplitButtonWithSlots = exports.SplitButtonWithSlots = function SplitButtonWithSlots(_ref4) {
var primaryAction = _ref4.primaryAction,
secondaryAction = _ref4.secondaryAction,
_ref4$appearance = _ref4.appearance,
appearance = _ref4$appearance === void 0 ? 'default' : _ref4$appearance,
_ref4$spacing = _ref4.spacing,
spacing = _ref4$spacing === void 0 ? 'default' : _ref4$spacing,
_ref4$isDisabled = _ref4.isDisabled,
isDisabled = _ref4$isDisabled === void 0 ? false : _ref4$isDisabled;
return /*#__PURE__*/React.createElement(SplitButtonContainer, {
appearance: appearance,
isDisabled: isDisabled
}, /*#__PURE__*/React.createElement(_splitButtonContext.SplitButtonContext.Provider, {
value: {
appearance: appearance,
spacing: spacing,
isDisabled: isDisabled
}
}, /*#__PURE__*/React.createElement("div", {
className: (0, _runtime.ax)([buttonStyles.primaryButton])
}, primaryAction), /*#__PURE__*/React.createElement(Divider, {
appearance: appearance,
spacing: spacing,
isDisabled: isDisabled
}), /*#__PURE__*/React.createElement("div", {
className: (0, _runtime.ax)([buttonStyles.secondaryButton])
}, secondaryAction)));
};