Skip to content

Commit 00dd5d6

Browse files
committed
feat(@fluent-ui/icons): Icon rearrangement document using react-lazyload
1 parent 9d989b4 commit 00dd5d6

File tree

10 files changed

+172
-48
lines changed

10 files changed

+172
-48
lines changed

packages/fluent-ui-icons/src/utils/createIcon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function createIcon(
3333
componentName: string
3434
): React.ForwardRefExoticComponent<React.RefAttributes<SVGElement>> {
3535
const Icon = React.forwardRef<SVGElement>(
36-
({ ...rest }: React.HTMLAttributes<SVGElement>, ref): React.ReactElement => {
36+
(props: React.HTMLAttributes<SVGElement>, ref): React.ReactElement => {
3737
const style = {
3838
width: '1em',
3939
height: '1em',
@@ -42,7 +42,7 @@ function createIcon(
4242
color: 'inherit',
4343
fill: 'currentColor'
4444
}
45-
return createElement(jsx, { ...rest, style, ref })
45+
return createElement(jsx, { style, ref, ...props })
4646
}
4747
)
4848
Icon.displayName = `RemixIcon${componentName}`

packages/fluent-ui.com/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
"react-helmet": "^5.2.1",
6767
"react-instantsearch-dom": "^5.7.0",
6868
"react-intl": "^3.3.0",
69+
"react-lazyload": "^2.6.2",
6970
"react-live": "^2.2.0",
7071
"react-object-inspector": "^0.2.1",
71-
"react-virtuoso": "^0.12.1",
7272
"use-debounce": "^3.0.1"
7373
},
7474
"devDependencies": {
@@ -78,6 +78,7 @@
7878
"@types/react-filepond": "^5.0.4",
7979
"@types/react-helmet": "^5.0.8",
8080
"@types/react-instantsearch-dom": "^5.2.6",
81+
"@types/react-lazyload": "^2.5.0",
8182
"babel-preset-gatsby": "^0.1.11",
8283
"eslint": "^5.16.0",
8384
"eslint-loader": "^2.1.2",

packages/fluent-ui.com/src/docs/components/Icon/Icon.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,22 @@ langKey: "en"
99

1010
Fluent-UI Svg Icons Based on [RemixIcon](https://remixicon.com/).
1111

12+
## Imports
13+
14+
You can import the icons with one of these two options:
15+
16+
- Option 1:
17+
`
18+
import BankFillIcon from '@fluent-ui/icons/BankFill';
19+
`
20+
21+
- Option 2:
22+
`
23+
import { BankFillIcon as BankFillIcon } from '@fluent-ui/icons'
24+
`
25+
26+
The safest is option 1 but option 2 can yield the best developer experience. Make sure you follow the [minimizing bundle size](/getting-started/minimizing-bundle-size) guide before using the second approach.
27+
28+
## Icon List
29+
1230
<IconTemplate />

packages/fluent-ui.com/src/docs/components/Icon/Icon.zh.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,22 @@ langKey: "zh"
99

1010
Fluent-UI 的图标基于 [RemixIcon](https://remixicon.com/) 二次开发。
1111

12+
## 引入
13+
14+
你可以用这两种选项引入图标:
15+
16+
- 选项 1:
17+
`
18+
import BankFillIcon from '@fluent-ui/icons/BankFill';
19+
`
20+
21+
- 选项 2:
22+
`
23+
import { BankFillIcon as BankFillIcon } from '@fluent-ui/icons'
24+
`
25+
26+
更健康的方式是 选项 1 但是 选项 2 可以带来更好的开发体验。在使用 选项 2 之前,请确保遵循[最小化打包大小](/zh/getting-started/minimizing-bundle-size)指南。
27+
28+
## 图标列表
29+
1230
<IconTemplate />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Icon
3+
components: Icon
4+
api: true
5+
langKey: "en"
6+
---
7+
8+
### Props
9+
10+
| Name | Type | Default | Description |
11+
| --- | --- | --- | --- |
12+
| className | string | | The svg className. |
13+
| style | CSSProperties | | The svg styles. |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Icon(图标)
3+
components: Icon
4+
api: true
5+
langKey: "zh"
6+
---
7+
8+
### Props
9+
10+
| Name | Type | Default | Description |
11+
| --- | --- | --- | --- |
12+
| className | string | | Svg 的 className。 |
13+
| style | CSSProperties | | Svg 的 styles。 |

packages/fluent-ui.com/src/docs/components/Icon/tags.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"_comment": "We improve the search experience of our website by impoving 'tags.json' file. Feel free to create issue or pull request to help us improve this file. You can also email us <jimmy@remixdesign.cn> to share your idea.",
32
"Buildings": {
43
"home": [
54
"house",

packages/fluent-ui.com/src/docs/components/Icon/template.tsx

Lines changed: 86 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as React from 'react'
22

3-
import { Box, Typography, Dialog, Theme } from '@fluent-ui/core'
3+
import { Box, Typography, Dialog, Theme, Spinner } from '@fluent-ui/core'
44
import { createUseStyles } from '@fluent-ui/styles'
55
import * as Icons from '@fluent-ui/icons'
66
import { Styles } from 'jss'
7-
import { VirtuosoGrid } from 'react-virtuoso'
8-
const Virtuoso = VirtuosoGrid as any
97
import Highlight from '../../../components/highlight'
8+
import { toHump } from '../../../utils'
9+
import LazyLoad from 'react-lazyload'
1010
// @ts-ignore
1111
import tags from './tags.json'
1212

@@ -25,17 +25,11 @@ type Classes =
2525
| 'blackIcon'
2626
const useStyles = createUseStyles<Theme, Classes>(
2727
(theme: Theme): Styles => ({
28-
list: {
29-
display: 'flex',
30-
flexWrap: 'wrap'
31-
},
3228
iconContainer: {
33-
width: '33%',
29+
display: 'inline-block',
30+
width: '25%',
3431
'@media screen and (min-width: 600px)': {
35-
width: '25%'
36-
},
37-
'@media screen and (min-width: 960px)': {
38-
width: '20%'
32+
width: '16.6667%'
3933
}
4034
},
4135
iconWrapper: {
@@ -95,9 +89,9 @@ const useStyles = createUseStyles<Theme, Classes>(
9589
})
9690
)
9791

92+
const tagList = Object.keys(tags)
93+
9894
const Template = (): React.ReactElement => {
99-
// @ts-ignore
100-
const IconArray = Object.keys(Icons).map(key => Icons[key])
10195
const classes = useStyles()
10296

10397
const [visible, setVisible] = React.useState(false)
@@ -117,24 +111,84 @@ const Template = (): React.ReactElement => {
117111

118112
return (
119113
<Box backgroundColor="standard.light3" marginTop={20}>
120-
<Virtuoso
121-
totalCount={IconArray.length}
122-
listClassName={classes.list}
123-
itemClassName={classes.iconContainer}
124-
item={(index: number): React.ReactElement => {
125-
const Icon = IconArray[index]
126-
const name = String.prototype.substring.call(Icon.displayName, 9)
127-
return (
128-
<div className={classes.iconWrapper} onClick={handleVisible.bind(null, name)}>
129-
<Icon />
130-
<Typography className={classes.title} variant="subtitle2" color="standard.dark1">
131-
{name}
132-
</Typography>
133-
</div>
134-
)
135-
}}
136-
style={{ height: '500px' }}
137-
/>
114+
<Box padding="20px">
115+
{tagList.map(
116+
(title): React.ReactElement => {
117+
return (
118+
<Box key={title}>
119+
<Typography variant="h6" gutterBottom gutterTop>
120+
{title}
121+
</Typography>
122+
<Box>
123+
{Object.keys(tags[title]).map(
124+
(icon): React.ReactElement => {
125+
const Hump = toHump(icon)
126+
// @ts-ignore
127+
const LineIcon = Icons[`${Hump}Line`]
128+
// @ts-ignore
129+
const FillIcon = Icons[`${Hump}Fill`]
130+
// @ts-ignore
131+
const OtherIcon = Icons[Hump]
132+
// eslint-disable-next-line
133+
return React.useMemo(
134+
(): React.ReactElement => (
135+
<LazyLoad
136+
scrollContainer="#contentRoot"
137+
height={144}
138+
placeholder={<Spinner />}
139+
throttle={200}
140+
once={true}
141+
key={icon}
142+
>
143+
<div className={classes.iconContainer}>
144+
{!!LineIcon && (
145+
<Box
146+
className={classes.iconWrapper}
147+
onClick={handleVisible.bind(null, `${Hump}Line`)}
148+
>
149+
<LineIcon />
150+
<Typography
151+
className={classes.title}
152+
variant="subtitle2"
153+
>{`${Hump}Line`}</Typography>
154+
</Box>
155+
)}
156+
{!!FillIcon && (
157+
<Box
158+
className={classes.iconWrapper}
159+
onClick={handleVisible.bind(null, `${Hump}Fill`)}
160+
>
161+
<FillIcon />
162+
<Typography
163+
className={classes.title}
164+
variant="subtitle2"
165+
>{`${Hump}Fill`}</Typography>
166+
</Box>
167+
)}
168+
{!!OtherIcon && (
169+
<Box
170+
className={classes.iconWrapper}
171+
onClick={handleVisible.bind(null, Hump)}
172+
>
173+
<OtherIcon />
174+
<Typography className={classes.title} variant="subtitle2">
175+
{Hump}
176+
</Typography>
177+
</Box>
178+
)}
179+
</div>
180+
</LazyLoad>
181+
),
182+
[FillIcon, Hump, LineIcon, OtherIcon, icon]
183+
)
184+
}
185+
)}
186+
</Box>
187+
</Box>
188+
)
189+
}
190+
)}
191+
</Box>
138192
<Dialog visible={visible} onChange={handleVisible}>
139193
<Dialog.Title>{currentSelectIcon}</Dialog.Title>
140194

packages/fluent-ui.com/src/utils/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ export function toLine(name: string): string {
1515
return target
1616
}
1717

18+
export function toHump(name: string, capitalized: boolean = true): string {
19+
return capitalized
20+
? name
21+
.replace(/-(\w)/g, (all, letter): string => letter.toUpperCase())
22+
.replace(/( |^)[a-z]/g, (all): string => all.toUpperCase())
23+
: name.replace(/-(\w)/g, (all, letter): string => letter.toUpperCase())
24+
}
25+
1826
export function pathnameToLanguage(
1927
pathname: string
2028
): {

yarn.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,13 @@
25782578
"@types/react" "*"
25792579
"@types/react-instantsearch-core" "*"
25802580

2581+
"@types/react-lazyload@^2.5.0":
2582+
version "2.5.0"
2583+
resolved "https://registry.npmjs.org/@types/react-lazyload/-/react-lazyload-2.5.0.tgz#7d8dd04c9a711fc0f1ea3419786acdcc01fb11dc"
2584+
integrity sha512-+SFmsxcC0l9mSXmoQMRtTbIW6YJQH+WxDWFG5N1b1JCiyTHZqekYcNKhGFTBvKktYOi3ET75+B4SeD52V7P1uw==
2585+
dependencies:
2586+
"@types/react" "*"
2587+
25812588
"@types/react-test-renderer@^16.8.2":
25822589
version "16.9.0"
25832590
resolved "https://registry.npmjs.org/@types/react-test-renderer/-/react-test-renderer-16.9.0.tgz#d60f530ecf4c906721511603cca711b4fa830d41"
@@ -14058,6 +14065,11 @@ react-jss@^10.0.0-alpha.25:
1405814065
theming "3.2.0"
1405914066
tiny-warning "^1.0.2"
1406014067

14068+
react-lazyload@^2.6.2:
14069+
version "2.6.2"
14070+
resolved "https://registry.npmjs.org/react-lazyload/-/react-lazyload-2.6.2.tgz#6a1660de6e8653632797539189d19d64e924482c"
14071+
integrity sha512-zbFiwI3H7W0/Qvb6T/ew2NiGe2wj+soYNW7vv5Dte1eZuJDvvyUOHo8GpYfEeWoP5x4Rree2Hwop+lCISalBwg==
14072+
1406114073
react-lifecycles-compat@^3.0.4:
1406214074
version "3.0.4"
1406314075
resolved "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
@@ -14124,13 +14136,6 @@ react-transition-group@^4.2.1:
1412414136
loose-envify "^1.4.0"
1412514137
prop-types "^15.6.2"
1412614138

14127-
react-virtuoso@^0.12.1:
14128-
version "0.12.1"
14129-
resolved "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-0.12.1.tgz#82ad71156bb34538e46fb37b908fc39fa0996dcc"
14130-
integrity sha512-H5cdMHhsb+sjTxkTzIwS+uXhIzGao3GdkTw7ifyvzES9dJ/aA5I80RgTPu+VB1w4lvkRL/WlVVNHtMzJBG6+3w==
14131-
dependencies:
14132-
resize-observer-polyfill "^1.5.1"
14133-
1413414139
react@^16.9.0:
1413514140
version "16.9.0"
1413614141
resolved "https://registry.npmjs.org/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa"
@@ -14681,11 +14686,6 @@ requires-port@^1.0.0:
1468114686
resolved "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
1468214687
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
1468314688

14684-
resize-observer-polyfill@^1.5.1:
14685-
version "1.5.1"
14686-
resolved "https://registry.npmjs.org/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
14687-
integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==
14688-
1468914689
resolve-cwd@^2.0.0:
1469014690
version "2.0.0"
1469114691
resolved "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"

0 commit comments

Comments
 (0)