@atlaskit/atlassian-navigation
Version:
A horizontal navigation component for Atlassian products.
79 lines (78 loc) • 2.83 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "testId", "tooltip", "isSelected", "isHighlighted"];
/** @jsx jsx */
import { forwardRef } from 'react';
import { css, jsx } from '@emotion/react';
import Button from '@atlaskit/button/custom-theme-button';
import Tooltip from '@atlaskit/tooltip';
import { gridSize } from '../../common/constants';
import { useTheme } from '../../theme';
import { getPrimaryButtonTheme } from './styles';
var VAR_BUTTON_SELECTED_COLOR = '--button-selected-color';
var VAR_BUTTON_SELECTED_BORDER_COLOR = '--button-selected-border-color';
var buttonBaseStyles = css({
display: 'flex',
height: '100%',
position: 'relative',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'column'
});
var buttonHighlightedStyles = css({
// eslint-disable-next-line @repo/internal/styles/no-nested-styles
'&& > *': {
color: "var(".concat(VAR_BUTTON_SELECTED_COLOR, ")")
},
'&:after': {
height: 3,
position: 'absolute',
right: gridSize / 2,
bottom: 0,
left: gridSize / 2,
backgroundColor: "var(".concat(VAR_BUTTON_SELECTED_BORDER_COLOR, ")"),
borderTopLeftRadius: 1,
borderTopRightRadius: 1,
content: '""'
}
});
/**
* __Primary button__
*
* A primary button allows you to add top-level navigation items.
* Should be passed into `AtlassianNavigation`'s `primaryItems` prop.
*
* - [Examples](https://atlassian.design/components/atlassian-navigation/examples#dropdown-menu)
* - [Code](https://atlassian.design/components/atlassian-navigation/code)
*/
export var PrimaryButton = /*#__PURE__*/forwardRef(function (props, ref) {
var _ref;
var children = props.children,
testId = props.testId,
tooltip = props.tooltip,
isSelected = props.isSelected,
isHighlighted = props.isHighlighted,
buttonProps = _objectWithoutProperties(props, _excluded);
var theme = useTheme();
var button = jsx("div", {
style: (_ref = {}, _defineProperty(_ref, VAR_BUTTON_SELECTED_COLOR, theme.mode.primaryButton.selected.color), _defineProperty(_ref, VAR_BUTTON_SELECTED_BORDER_COLOR, theme.mode.primaryButton.selected.borderColor), _ref),
css: [buttonBaseStyles, isHighlighted && buttonHighlightedStyles]
}, jsx(Button, _extends({
appearance: "primary",
testId: testId,
ref: ref,
isSelected: isSelected
// eslint-disable-next-line @repo/internal/react/no-unsafe-overrides
,
theme: getPrimaryButtonTheme(theme)
}, buttonProps), children));
if (tooltip) {
return jsx(Tooltip, {
content: tooltip,
hideTooltipOnClick: true
}, button);
}
return button;
});
export default PrimaryButton;