UNPKG

@atlaskit/atlassian-navigation

Version:

A horizontal navigation component for Atlassian products.

89 lines (88 loc) 2.73 kB
/** @jsx jsx */ import { Fragment } from 'react'; import { css, jsx } from '@emotion/react'; import Button from '@atlaskit/button/custom-theme-button'; import AddIcon from '@atlaskit/icon/glyph/editor/add'; import Tooltip from '@atlaskit/tooltip'; import { CREATE_BREAKPOINT, gridSize } from '../../common/constants'; import { useTheme } from '../../theme'; import { IconButton } from '../IconButton'; import { getCreateButtonTheme } from './styles'; const wrapperStyles = css({ display: 'flex', alignItems: 'center', // eslint-disable-next-line @repo/internal/styles/no-nested-styles '& [data-hide-on-smallscreens]': { // eslint-disable-next-line @repo/internal/styles/no-nested-styles [`@media (max-width: ${CREATE_BREAKPOINT - 1}px)`]: { display: 'none !important' } }, // eslint-disable-next-line @repo/internal/styles/no-nested-styles '& [data-hide-on-largescreens]': { // eslint-disable-next-line @repo/internal/styles/no-nested-styles [`@media (min-width: ${CREATE_BREAKPOINT}px)`]: { display: 'none !important' } }, // eslint-disable-next-line @repo/internal/styles/no-nested-styles '&&': { marginLeft: gridSize * 1.5 } }); const TooltipSwitch = ({ buttonTooltip, children }) => buttonTooltip ? jsx(Tooltip, { content: buttonTooltip, hideTooltipOnClick: true }, children) : jsx(Fragment, null, children); /** * _Create__ * * A call to action button that can be passed into `AtlassianNavigation`'s * `renderCreate` prop. It is shown after all other primary buttons. * * - [Examples](https://atlassian.design/components/atlassian-navigation/examples#create) * - [Code](https://atlassian.design/components/atlassian-navigation/code) */ export const Create = ({ onClick, href, text, buttonTooltip, iconButtonTooltip, testId }) => { const theme = useTheme(); return jsx("div", { css: wrapperStyles, "data-testid": "create-button-wrapper" }, jsx(TooltipSwitch, { buttonTooltip: buttonTooltip }, jsx(Button, { id: "createGlobalItem", onClick: onClick, href: href // eslint-disable-next-line @repo/internal/react/no-unsafe-overrides , theme: getCreateButtonTheme(theme), testId: testId && `${testId}-button`, "data-hide-on-smallscreens": true }, text)), jsx(IconButton, { id: "createGlobalItemIconButton", testId: testId && `${testId}-icon-button`, icon: jsx(AddIcon, { label: text }), onClick: onClick, href: href, tooltip: iconButtonTooltip // eslint-disable-next-line @repo/internal/react/no-unsafe-overrides , theme: getCreateButtonTheme(theme), "aria-label": text, "data-hide-on-largescreens": true })); }; export default Create;