2020-07-14 02:06:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import './toolbar_button.scss';
|
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { EuiButton, PropsOf, EuiButtonProps } from '@elastic/eui';
|
|
|
|
|
2020-09-16 10:30:19 +02:00
|
|
|
const groupPositionToClassMap = {
|
|
|
|
none: null,
|
|
|
|
left: 'lnsToolbarButton--groupLeft',
|
|
|
|
center: 'lnsToolbarButton--groupCenter',
|
|
|
|
right: 'lnsToolbarButton--groupRight',
|
|
|
|
};
|
|
|
|
|
2020-07-14 02:06:58 +02:00
|
|
|
export type ToolbarButtonProps = PropsOf<typeof EuiButton> & {
|
|
|
|
/**
|
|
|
|
* Determines prominence
|
|
|
|
*/
|
|
|
|
fontWeight?: 'normal' | 'bold';
|
|
|
|
/**
|
|
|
|
* Smaller buttons also remove extra shadow for less prominence
|
|
|
|
*/
|
|
|
|
size?: EuiButtonProps['size'];
|
2020-09-16 10:30:19 +02:00
|
|
|
/**
|
|
|
|
* Determines if the button will have a down arrow or not
|
|
|
|
*/
|
|
|
|
hasArrow?: boolean;
|
|
|
|
/**
|
|
|
|
* Adjusts the borders for groupings
|
|
|
|
*/
|
|
|
|
groupPosition?: 'none' | 'left' | 'center' | 'right';
|
2020-07-14 02:06:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export const ToolbarButton: React.FunctionComponent<ToolbarButtonProps> = ({
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
fontWeight = 'normal',
|
|
|
|
size = 'm',
|
2020-09-16 10:30:19 +02:00
|
|
|
hasArrow = true,
|
|
|
|
groupPosition = 'none',
|
2020-07-14 02:06:58 +02:00
|
|
|
...rest
|
|
|
|
}) => {
|
|
|
|
const classes = classNames(
|
|
|
|
'lnsToolbarButton',
|
2020-09-16 10:30:19 +02:00
|
|
|
groupPositionToClassMap[groupPosition],
|
2020-07-14 02:06:58 +02:00
|
|
|
[`lnsToolbarButton--${fontWeight}`, `lnsToolbarButton--${size}`],
|
|
|
|
className
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
<EuiButton
|
|
|
|
className={classes}
|
|
|
|
iconSide="right"
|
2020-09-16 10:30:19 +02:00
|
|
|
iconType={hasArrow ? 'arrowDown' : ''}
|
2020-07-14 02:06:58 +02:00
|
|
|
color="text"
|
|
|
|
contentProps={{
|
|
|
|
className: 'lnsToolbarButton__content',
|
|
|
|
}}
|
|
|
|
textProps={{
|
|
|
|
className: 'lnsToolbarButton__text',
|
|
|
|
}}
|
|
|
|
{...rest}
|
|
|
|
size={size}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</EuiButton>
|
|
|
|
);
|
|
|
|
};
|