From f0b1a665a99b067edc3789c8d49da04a2d23b006 Mon Sep 17 00:00:00 2001 From: isaacmaamouche Date: Fri, 30 Aug 2024 17:22:37 +0200 Subject: [PATCH] feat: click icon to copy component name --- .../build-app/components/IconsList/index.tsx | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/website/build-app/components/IconsList/index.tsx b/website/build-app/components/IconsList/index.tsx index 9c7cc97a1..88b5fe75b 100644 --- a/website/build-app/components/IconsList/index.tsx +++ b/website/build-app/components/IconsList/index.tsx @@ -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, @@ -36,6 +38,43 @@ export type IconListProps = { | 'brands' | 'flags' } + +const handleClickToCopy = (componentName: string) => { + const component = `<${componentName} />` + navigator.clipboard.writeText(component) + + toast( + +

+ {component} copied to your clipboard +

+
, + { position: 'bottom-center' } + ) +} + +const StyledCard = styled(Card)` + 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, @@ -66,15 +105,7 @@ export const IconsList = ({ isIconFont, name }: IconListProps) => { } return ( - + handleClickToCopy(componentName)}> {Icon ? : } { > {componentName} - + ) })}