Skip to content

Commit f2364fa

Browse files
committed
doc(Icon): update README.md
1 parent 4c192e7 commit f2364fa

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

packages/core/src/Icon/README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,74 @@ class Demo extends Component {
7171

7272
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true&noCode=true-->
7373
```jsx
74+
import { useEffect } from 'react';
7475
import ReactDOM from 'react-dom';
7576
import svgPaths from '@uiw/icons/fonts/w-icon.json';
7677

7778
function Demo() {
79+
useEffect(()=>{
80+
const dv = document.createElement('div')
81+
dv.id='dv'
82+
dv.setAttribute('style',`
83+
width: 100px;
84+
padding: 4px 10px;
85+
border: 1px solid #fff;
86+
text-align: center;
87+
border-radius: 5px;
88+
background: #fff;
89+
box-shadow: 0 3px 6px -4px #0000001f, 0 6px 16px #00000014, 0 9px 28px 8px #0000000d;
90+
pointer-events: none;
91+
font-size: 12px;
92+
position: fixed;
93+
top: 70px;
94+
left: 0;
95+
right: 0;
96+
margin: 0 auto;
97+
z-index: 9;
98+
display: none;
99+
color: green;
100+
`)
101+
dv.innerText = '复制成功!'
102+
document.body.appendChild(dv)
103+
},[])
104+
const onClick = (keyname) => {
105+
if (window.clipboardData) {
106+
window.clipboardData.setData('text', `<Icon name="${keyname}" />`);
107+
message()
108+
} else {
109+
(function (s) {
110+
document.oncopy = function (e) {
111+
e.clipboardData.setData('text', s);
112+
e.preventDefault();
113+
document.oncopy = null;
114+
};
115+
})(`<Icon name="${keyname}" size={46} />`);
116+
document.execCommand('Copy');
117+
message()
118+
}
119+
}
120+
const message = () => {
121+
document.getElementById('dv').style.display = 'block';
122+
const timer = setTimeout(()=>{
123+
document.getElementById('dv').style.display = 'none';
124+
clearTimeout(timer)
125+
},3000)
126+
}
78127
return (
79128
<div style={{ display: 'flex', flexDirection: 'row', flexWrap: 'wrap' }}>
80129
{Object.keys(svgPaths).map((keyname, idx) => {
81130
return (
82-
<div key={idx} style={{ display: 'flex', flexDirection: 'column', width: 180, paddingBottom: 14 }}>
131+
<div
132+
key={idx}
133+
onClick={()=>onClick(keyname)}
134+
style={{
135+
display: 'flex',
136+
cursor: 'pointer',
137+
flexDirection: 'column',
138+
width: 180,
139+
paddingBottom: 14,
140+
}}
141+
>
83142
<svg viewBox="0 0 24 24" width="21">
84143
{svgPaths[keyname].map((path, pathIdx) => (
85144
<path d={path} key={pathIdx} fillRule="evenodd"/>

0 commit comments

Comments
 (0)