Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display all components/Icons file #2145

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading