Skip to content

Commit

Permalink
display all components/Icons file
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Aug 4, 2023
1 parent 170a509 commit 90e1cef
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
6 changes: 0 additions & 6 deletions src/components/Icons/Swap_2.svg

This file was deleted.

6 changes: 1 addition & 5 deletions src/components/Icons/ZkSyncFull.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { useIsDarkMode } from 'state/user/hooks'

const ZkSyncFull = () => {
const isDarkMode = useIsDarkMode()
const fill = isDarkMode ? 'white' : 'black'
const ZkSyncFull = ({ color: fill }: { color: string }) => {
return (
<svg width="125" height="25" viewBox="0 0 125 25" fill="none" xmlns="http://www.w3.org/2000/svg">
<mask
Expand Down
10 changes: 0 additions & 10 deletions src/components/Icons/flame 8.svg

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/About/AboutKyberSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ function AboutKyberSwap() {
<img src={isDarkMode ? BTTCDark : BTTCLight} alt="btt" width="100%" />
<OptimismLogoFull />
{/* <SolanaLogoFull /> */}
<ZkSyncFull />
<ZkSyncFull color={theme.text} />
<LineaFull />
</Powered>
</Text>
Expand Down
40 changes: 35 additions & 5 deletions src/pages/Icons/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { rgba } from 'polished'
import { useCallback, useEffect, useState } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import { Text } from 'rebass'
import styled from 'styled-components'

import sprite from 'assets/svg/sprite.svg'
import { NotificationType } from 'components/Announcement/type'
import * as IconComponents from 'components/Icons'
import { ICON_IDS } from 'constants/index'
import useCopyClipboard from 'hooks/useCopyClipboard'
import useTheme from 'hooks/useTheme'
import { useNotify } from 'state/application/hooks'

const allSvgFiles = import.meta.glob('../../assets/svg/*')
const allIconComponentsFiles = import.meta.glob('../../components/Icons/*')

const Wrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -63,8 +64,10 @@ const camelizeSnake = (st: string) =>

export default function Icons() {
const [svgComponents, setSvgComponents] = useState<any>([])
const [iconComponents, setIconComponents] = useState<any>([])
const [copied, setCopied] = useCopyClipboard(2000)
const notify = useNotify()
const theme = useTheme()

const onClick = useCallback(
(id: string) => {
Expand Down Expand Up @@ -100,6 +103,24 @@ export default function Icons() {
)
})
.catch(console.error)

const componentArr = Object.keys(allIconComponentsFiles).map(key => ({
id: key.split('/').pop()?.replace('.tsx', ''),
fn: allIconComponentsFiles[key](),
}))
Promise.all(componentArr.map(el => el.fn))
.then(data => {
setIconComponents(
data.map((e: any, i) => {
const id = componentArr[i].id
return {
render: e.default || (() => null),
id,
}
}),
)
})
.catch(console.error)
}, [])
return (
<>
Expand Down Expand Up @@ -135,10 +156,19 @@ export default function Icons() {
</Wrapper>
<h2>All icons in: folder /components/Icons </h2>
<Wrapper>
{Object.entries(IconComponents).map(([key, component]) => {
{iconComponents.map((el: any) => {
const key: string = el.id
return (
<IconWrapperV2 key={key} onClick={() => onClick(`import { ${key} } from 'components/Icons'`)}>
{component?.({})}
<IconWrapperV2 key={key} onClick={() => onClick(`import ${key} from 'components/Icons/${key}'`)}>
{(() => {
try {
return typeof el?.render === 'function'
? el.render({ color: theme.text })
: React.createElement(el?.render)
} catch (error) {
return 'Display Error'
}
})()}
<Text fontSize={10} style={{ wordBreak: 'break-all' }}>
{key}.tsx
</Text>
Expand Down

0 comments on commit 90e1cef

Please sign in to comment.