Skip to content

Commit 1df1684

Browse files
authored
Merge pull request #475 from star-hamster/dev
doc(icon): 修改文档预览
2 parents e6e004e + 85abf80 commit 1df1684

File tree

3 files changed

+127
-104
lines changed

3 files changed

+127
-104
lines changed

example/examples/src/routes/Icon/index.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,22 @@ export default class IconPage extends React.Component<IconPageProps> {
274274
const {route} = this.props;
275275
const description = route.params.description;
276276
const title = route.params.title;
277+
const xml = `
278+
<svg width="20" height="20" viewBox="0 0 20 20">
279+
<path
280+
fill-rule="evenodd"
281+
fill="#000"
282+
d="M19 8h-1.26c-.19-.73-.48-1.42-.85-2.06l.94-.94a.996.996 0 0 0 0-1.41l-1.41-1.41a.996.996 0 0 0-1.41 0l-.94.94c-.65-.38-1.34-.67-2.07-.86V1c0-.55-.45-1-1-1H9c-.55 0-1 .45-1 1v1.26c-.76.2-1.47.5-2.13.89L5 2.28a.972.972 0 0 0-1.36 0L2.28 3.64c-.37.38-.37.98 0 1.36l.87.87c-.39.66-.69 1.37-.89 2.13H1c-.55 0-1 .45-1 1v2c0 .55.45 1 1 1h1.26c.19.73.48 1.42.85 2.06l-.94.94a.996.996 0 0 0 0 1.41l1.41 1.41c.39.39 1.02.39 1.41 0l.94-.94c.64.38 1.33.66 2.06.85V19c0 .55.45 1 1 1h2c.55 0 1-.45 1-1v-1.26c.76-.2 1.47-.5 2.13-.89l.88.87c.37.37.98.37 1.36 0l1.36-1.36c.37-.38.37-.98 0-1.36l-.87-.87c.4-.65.7-1.37.89-2.13H19c.55 0 1-.45 1-1V9c0-.55-.45-1-1-1zm-9 7c-2.76 0-5-2.24-5-5s2.24-5 5-5v10z"
283+
/>
284+
</svg>
285+
`;
277286
return (
278287
<Container>
279288
<Layout>
280289
<Header title={title} description={description} />
281290
<Body>
282291
<Card title="自定义图标">
292+
<Icon name="apple" size={18} color="#50CB42" />
283293
<Icon
284294
paths={[
285295
'M19 0H7c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h5.59l3.71 3.71c.17.18.42.29.7.29.55 0 1-.45 1-1v-3h1c.55 0 1-.45 1-1V1c0-.55-.45-1-1-1zM7 13c-1.1 0-2-.9-2-2V4H1c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h1v3a1.003 1.003 0 0 0 1.71.71L7.41 16H13c.55 0 1-.45 1-1v-.17L12.17 13H7z',
@@ -295,7 +305,28 @@ export default class IconPage extends React.Component<IconPageProps> {
295305
size={18}
296306
style={styles.icon}
297307
/>
298-
<Icon name="apple" size={18} color="#50CB42" />
308+
<Icon
309+
size={40}
310+
xml={`
311+
<svg
312+
width="130"
313+
height="130"
314+
fill="blue"
315+
stroke="red"
316+
color="green"
317+
viewBox="-16 -16 544 544"
318+
>
319+
<path
320+
d="M318.37,85.45L422.53,190.11,158.89,455,54.79,350.38ZM501.56,60.2L455.11,13.53a45.93,45.93,0,0,0-65.11,0L345.51,58.24,449.66,162.9l51.9-52.15A35.8,35.8,0,0,0,501.56,60.2ZM0.29,497.49a11.88,11.88,0,0,0,14.34,14.17l116.06-28.28L26.59,378.72Z"
321+
strokeWidth="32"
322+
/>
323+
<path d="M0,0L512,512" stroke="currentColor" strokeWidth="32" />
324+
</svg>
325+
`}
326+
/>
327+
<Icon size={46} xml={xml} />
328+
<Icon name="apple" height={42} width={40} fill="#E3BD8D" stroke="#4d4030" />
329+
<Icon name="apple" height={42} width={40} fill="#E2D849" stroke="#FF9900" />
299330
</Card>
300331
<Card title="UIW Icon" extra={<LinkButtons />}>
301332
<View style={styles.list}>

packages/core/src/Icon/README.md

Lines changed: 88 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,79 @@ Icon 图标
33

44
图标组件通过 [`react-native-svg`](https://github.com/react-native-community/react-native-svg) 支持 svg 图标,基于这一特性封装图标组件库,它不是基于字体文件封装的组件,相比字体图标组件易于扩展体积较小。预览[所有的图标](https://uiwjs.github.io/icons)
55

6-
![](https://user-images.githubusercontent.com/66067296/137710056-d7fe4b94-7b98-4e18-a235-5a4e70beaa05.png)<!--rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
76

8-
### 基础示例
7+
### 基础实例
98

10-
```js
11-
import { Icon } from '@uiw/react-native';
9+
```jsx mdx:preview
10+
import React from "react"
11+
import { Icon } from '@uiw/react-native';
1212

13-
class Demo extends Component {
14-
render() {
15-
return (
16-
<View>
17-
<Icon name='apple' size={46} color='#50CB42' />
18-
<Icon name='apple' size={46} fill='red' />
19-
</View>
20-
)
21-
}
13+
export default function Demo() {
14+
return (
15+
<>
16+
<Icon name='apple' size={46} color='#50CB42' />
17+
<Icon name='apple' size={46} fill='red' />
18+
</>
19+
)
20+
}
21+
```
22+
23+
### 自定义图标轮廓颜色
24+
25+
```jsx mdx:preview
26+
import React from "react"
27+
import { Icon } from '@uiw/react-native';
28+
29+
export default function Demo() {
30+
return (
31+
<>
32+
<Icon name='apple' height={42} width={40} fill='#E3BD8D' stroke='#4d4030' />
33+
<Icon name='apple' height={42} width={40} fill='#E2D849' stroke='#FF9900' />
34+
</>
35+
)
2236
}
2337
```
2438

25-
### 自定义按钮
39+
### 自定义图标
2640

27-
```js
28-
import { Icon } from '@uiw/react-native';
41+
```jsx mdx:preview
42+
import React from "react"
43+
import { Icon } from '@uiw/react-native';
44+
import { View } from 'react-native';
2945

30-
class Demo extends Component {
31-
render() {
32-
return (
46+
export default function Demo() {
47+
return (
48+
<>
49+
<Icon
50+
size={30}
51+
paths={[
52+
"M25 10 L98 65 L70 25 L16 77 L11 30 L0 4 L90 50 L50 10 L11 22 L77 95 L20 25"
53+
]}
54+
/>
55+
<View style={{ width:5 , display:"inline-block"}}></View>
3356
<Icon
34-
fill="red"
57+
size={30}
3558
paths={[
3659
'M19 8h-1.26c-.19-.73-.48-1.42-.85-2.06l.94-.94a.996.996 0 0 0 0-1.41l-1.41-1.41a.996.996 0 0 0-1.41 0l-.94.94c-.65-.38-1.34-.67-2.07-.86V1c0-.55-.45-1-1-1H9c-.55 0-1 .45-1 1v1.26c-.76.2-1.47.5-2.13.89L5 2.28a.972.972 0 0 0-1.36 0L2.28 3.64c-.37.38-.37.98 0 1.36l.87.87c-.39.66-.69 1.37-.89 2.13H1c-.55 0-1 .45-1 1v2c0 .55.45 1 1 1h1.26c.19.73.48 1.42.85 2.06l-.94.94a.996.996 0 0 0 0 1.41l1.41 1.41c.39.39 1.02.39 1.41 0l.94-.94c.64.38 1.33.66 2.06.85V19c0 .55.45 1 1 1h2c.55 0 1-.45 1-1v-1.26c.76-.2 1.47-.5 2.13-.89l.88.87c.37.37.98.37 1.36 0l1.36-1.36c.37-.38.37-.98 0-1.36l-.87-.87c.4-.65.7-1.37.89-2.13H19c.55 0 1-.45 1-1V9c0-.55-.45-1-1-1zm-9 7c-2.76 0-5-2.24-5-5s2.24-5 5-5v10z'
3760
]}
38-
size={18}
39-
style={styles.icon}
4061
/>
41-
)
42-
}
62+
<View style={{ width:5 , display:"inline-block"}}></View>
63+
<Icon
64+
size={30}
65+
paths={[
66+
"M4 0C1.79086 0 0 1.79086 0 4V28C0 30.2091 1.79086 32 4 32H28C30.2091 32 32 30.2091 32 28V4C32 1.79086 30.2091 0 28 0H4ZM17 6C17 5.44772 17.4477 5 18 5H20C20.5523 5 21 5.44772 21 6V25C21 25.5523 20.5523 26 20 26H18C17.4477 26 17 25.5523 17 25V6ZM12 11C11.4477 11 11 11.4477 11 12V25C11 25.5523 11.4477 26 12 26H14C14.5523 26 15 25.5523 15 25V12C15 11.4477 14.5523 11 14 11H12ZM6 18C5.44772 18 5 18.4477 5 19V25C5 25.5523 5.44772 26 6 26H8C8.55228 26 9 25.5523 9 25V19C9 18.4477 8.55228 18 8 18H6ZM24 14C23.4477 14 23 14.4477 23 15V25C23 25.5523 23.4477 26 24 26H26C26.5523 26 27 25.5523 27 25V15C27 14.4477 26.5523 14 26 14H24Z"
67+
]}
68+
/>
69+
</>
70+
)
4371
}
4472
```
4573

4674
### SVG 图标支持
4775

48-
```js
49-
import { Icon } from '@uiw/react-native';
76+
```jsx
77+
import React from "react";
78+
import { Icon } from '@uiw/react-native';
5079

5180
const xml = `
5281
<svg width="20" height="20" viewBox="0 0 20 20">
@@ -58,101 +87,59 @@ const xml = `
5887
</svg>
5988
`;
6089

61-
class Demo extends Component {
62-
render() {
63-
return <Icon xml={xml} />;
64-
}
90+
export default function Demo() {
91+
return <Icon name='apple' size={46} fill='red' />
6592
}
6693
```
6794

6895
### 包中集成的所有图标
6996

7097
⚠️ 此示例,只是在文档中预览 Icon 图标,并展示图标名称,也可以通过图标 web 官网,网站预览[所有的图标](https://uiwjs.github.io/icons)
7198

72-
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true&noCode=true-->
73-
```jsx
74-
import { useEffect } from 'react';
75-
import ReactDOM from 'react-dom';
99+
```jsx mdx:preview&noCode=true
100+
import React from "react"
101+
import { Icon } from '@uiw/react-native';
102+
import { View , StyleSheet} from 'react-native';
76103
import svgPaths from '@uiw/icons/fonts/w-icon.json';
77104

78-
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)
105+
const styles = StyleSheet.create({
106+
itemStyle : {
107+
fontSize: 14,
108+
width: 130,
109+
backgroundColor: '#eaeaea',
110+
marginBottom: 10,
111+
marginRight: 10,
112+
paddingHorizontal:0,
113+
paddingVertical:20,
114+
display: 'flex',
115+
flexDirection: 'column',
116+
alignItems: 'center',
117+
justifyContent: 'center',
118+
fill: '#525252',
126119
}
120+
})
121+
122+
export default function Demo() {
127123
return (
128-
<div style={{ display: 'flex', flexDirection: 'row', flexWrap: 'wrap' }}>
124+
<View style={{ display: "flex", flexDirection: "row", flexWrap: "wrap" }}>
129125
{Object.keys(svgPaths).map((keyname, idx) => {
130126
return (
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-
}}
127+
<View
128+
key={idx}
129+
style={styles.itemStyle}
141130
>
142-
<svg viewBox="0 0 24 24" width="21">
131+
<svg viewBox="0 0 24 24" width="23">
143132
{svgPaths[keyname].map((path, pathIdx) => (
144133
<path d={path} key={pathIdx} fillRule="evenodd"/>
145134
))}
146135
</svg>
147-
<span style={{ color: '#757575' }}>{keyname}</span>
148-
</div>
136+
<span style={{ fontSize: 12,color: '#757575' }}>{keyname}</span>
137+
</View>
149138
);
150-
})}
151-
</div>
152-
);
139+
})}
140+
</View>
141+
)
153142
}
154-
155-
ReactDOM.render(<Demo />, _mount_);
156143
```
157144

158145
### Props

website/src/index.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
body {
22
font-size: 14px;
33
font-family: 'Segoe UI Emoji';
4-
font-family: 'Segoe UI Emoji', -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;
4+
font-family: 'Segoe UI Emoji', -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif,
5+
Apple Color Emoji, Segoe UI Emoji;
6+
}
7+
8+
* {
9+
outline: none;
510
}
611

712
a {
813
text-decoration: none;
9-
}
14+
}

0 commit comments

Comments
 (0)