index.tsx 1.02 KB
Newer Older
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
1
import React from 'react';
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
2
import { Icon, Typography, Popover } from 'antd';
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
3 4 5 6 7 8 9 10 11 12 13 14
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 }) => {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
15
  const blockUrl = `npx umi block add ant-design-pro/${firstUpperCase(url)}  --path=${url}`;
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
16
  return (
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
17
    <div className={styles['copy-block-view']}>
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
18
      <Typography.Paragraph copyable>
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
19
        <code className={styles['copy-block-code']}>{blockUrl}</code>
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
20 21 22 23 24 25 26
      </Typography.Paragraph>
    </div>
  );
};

export default ({ url }: { url: string }) => {
  return (
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
27 28 29 30 31 32
    <Popover
      title="ไธ‹่ฝฝๆญค้กต้ขๅˆฐๆœฌๅœฐ้กน็›ฎ"
      placement="topLeft"
      content={<BlockCodeView url={url} />}
      trigger="click"
    >
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
33
      <div className={styles['copy-block']}>
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
34
        <Icon type="download" />
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
35
      </div>
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
36
    </Popover>
้™ˆๅธ…'s avatar
commit  
้™ˆๅธ… committed
37 38
  );
};