ToolbarButton.tsx 796 Bytes
Newer Older
陈帅's avatar
陈帅 committed
1 2 3 4 5 6
import React from 'react';
import { Tooltip } from 'antd';
import { Command } from 'gg-editor';
import IconFont from '../../common/IconFont';
import styles from './index.less';

陈帅's avatar
use ts  
陈帅 committed
7 8 9 10 11 12 13 14 15 16
const upperFirst = (str: string) => {
  return str.toLowerCase().replace(/( |^)[a-z]/g, (l: string) => l.toUpperCase());
};

interface ToolbarButtonProps {
  command: string;
  icon?: string;
  text?: string;
}
const ToolbarButton: React.SFC<ToolbarButtonProps> = props => {
陈帅's avatar
陈帅 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  const { command, icon, text } = props;

  return (
    <Command name={command}>
      <Tooltip
        title={text || upperFirst(command)}
        placement="bottom"
        overlayClassName={styles.tooltip}
      >
        <IconFont type={`icon-${icon || command}`} />
      </Tooltip>
    </Command>
  );
};

export default ToolbarButton;