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

Feat: click icon to copy component name #2531

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from 1 commit
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
51 changes: 41 additions & 10 deletions website/build-app/components/IconsList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Box } from '@welcome-ui/box'
import { camelCase, startCase } from 'lodash'
import { Text } from '@welcome-ui/text'
import { Card } from '@welcome-ui/card'
import { Toast, toast } from '@welcome-ui/toast'
import styled from '@xstyled/styled-components'

import {
actions,
Expand Down Expand Up @@ -36,6 +38,43 @@ export type IconListProps = {
| 'brands'
| 'flags'
}

const handleClickToCopy = (componentName: string) => {
const component = `<${componentName} />`
navigator.clipboard.writeText(component)

toast(
<Toast.Snackbar>
<p>
<b>{component}</b> copied to your clipboard
</p>
</Toast.Snackbar>,
{ position: 'bottom-center' }
)
}

const StyledCard = styled(Card)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il faut garder la DX de le mettre dans un fichier styles.ts

display: flex;
flex-direction: column;
align-items: center;
padding: xl;
color: dark-900;
border-radius: xl;
cursor: pointer;
&,
& span {
transition: medium;
}
&:hover {
border-color: dark-900;
span {
color: dark-900;
}
}
`

export const IconsList = ({ isIconFont, name }: IconListProps) => {
const iconsByName = {
arrows: arrows,
Expand Down Expand Up @@ -66,15 +105,7 @@ export const IconsList = ({ isIconFont, name }: IconListProps) => {
}

return (
<Card
alignItems="center"
borderRadius="xl"
color="dark-900"
display="flex"
flexDirection="column"
key={key}
p="xl"
>
<StyledCard key={key} onClick={() => handleClickToCopy(componentName)}>
{Icon ? <Icon size="lg" /> : <Icons.CrossIcon size="lg" />}
<Text
as="span"
Expand All @@ -88,7 +119,7 @@ export const IconsList = ({ isIconFont, name }: IconListProps) => {
>
{componentName}
</Text>
</Card>
</StyledCard>
)
})}
</Box>
Expand Down
Loading