index.tsx 1.1 KB
Newer Older
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import React from 'react';
import { Icon, Typography, Tooltip } from 'antd';
import styles from './index.less';
const firstUpperCase = (pathString: string) => {
  return pathString
    .replace('.', '')
    .split(/\/|\-/)
    .map(s => s.toLowerCase().replace(/( |^)[a-z]/g, L => L.toUpperCase()))
    .filter(s => s)
    .join('');
};
const BlockCodeView: React.SFC<{
  url: string;
}> = ({ url }) => {
  console.log(url);
  const blockUrl = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${firstUpperCase(
    url,
  )} --npm-client=cnpm  --path=${url}`;
  return (
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
20 21
    <div className={styles['copy-block-view']}>
      <p className={styles['copy-block-text']}>ไธ‹่ฝฝๅˆฐ้กน็›ฎไธญ๏ผš</p>
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
22
      <Typography.Paragraph copyable>
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
23
        <div className={styles['copy-block-code']}>{blockUrl}</div>
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
24 25 26 27 28 29 30 31 32
      </Typography.Paragraph>
    </div>
  );
};

export default ({ url }: { url: string }) => {
  return (
    <Tooltip placement="topLeft" title={<BlockCodeView url={url} />} trigger="click">
      <div className={styles['copy-block']}>
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
33
        <Icon type="download" />
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
34 35 36 37
      </div>
    </Tooltip>
  );
};