11import React , { useEffect , useState } from "react" ;
2-
2+ import dynamic from 'next/dynamic' ;
33import { harperFetch } from "../../utils/HarperFetch" ;
44
5- import { shapes } from '../../data/shapes' ;
5+ import { shapes } from "../../data/shapes" ;
6+
7+ const Shape = dynamic ( import ( 'react-clip-path' ) , { ssr : false } )
8+ import Switch from "react-switch" ;
9+
10+ import {
11+ ShapeCards ,
12+ ShapeCard ,
13+ ShapeName ,
14+ ShapePallete ,
15+ ShapeDetailsItems ,
16+ ShapeActions ,
17+ ShapeHeader ,
18+ CopyIcon ,
19+ DownloadIcon ,
20+ LikeIcon ,
21+ } from "../utils/StyledComponents" ;
622
723const App = ( props ) => {
824 const [ data , setData ] = useState ( [ ] ) ;
@@ -19,16 +35,114 @@ const App = (props) => {
1935 });*/
2036
2137 console . log ( shapes ) ;
38+ let modifiedShapes = shapes . map ( ( shape , index ) => {
39+ shape . showAdvanced = false ;
40+ return shape ;
41+ } ) ;
42+ console . log ( modifiedShapes ) ;
2243
23- await setData ( shapes ) ;
44+ await setData ( modifiedShapes ) ;
2445 setLoading ( false ) ;
2546 } , [ ] ) ;
2647
27- return (
28- < div >
29- Test
30- </ div >
31- )
48+ const handleSwicth = ( shapeName ) => {
49+ console . log ( shapeName ) ;
50+
51+
52+ let modifiedShapes = data . map ( ( shape , index ) => {
53+ if ( shape . name === shapeName ) {
54+ return {
55+ ...shape ,
56+ showAdvanced : ! shape . showAdvanced
57+ }
58+ }
59+ return shape ;
60+ } ) ;
61+ console . log ( modifiedShapes ) ;
62+ setData ( ...[ modifiedShapes ] ) ;
63+ }
64+
65+ const getShapeFileName = ( name ) => {
66+ return name . split ( " " ) . join ( "-" ) ;
67+ } ;
68+
69+ async function performCopy ( event , formula ) {
70+ event . preventDefault ( ) ;
71+ try {
72+ await navigator . clipboard . writeText ( formula ) ;
73+ console . log ( "The clip-path formula copied to clipboard" ) ;
74+ } catch ( err ) {
75+ console . error ( "Failed to copy: " , err ) ;
76+ }
77+ }
78+
79+ return (
80+ < ShapePallete >
81+ < h2 > Available Shapes({ shapes . length } )</ h2 >
82+ < ShapeCards >
83+ { data . map ( ( shape , index ) => (
84+ < React . Fragment key = { index } >
85+ < ShapeCard >
86+ < ShapeHeader >
87+ < ShapeName > { shape . name } </ ShapeName >
88+ < ShapeActions >
89+ < span title = "Like" >
90+ < LikeIcon size = { 24 } />
91+ </ span > { " " }
92+ < span title = "Download" >
93+ < DownloadIcon
94+ size = { 24 }
95+ onClick = { ( event ) =>
96+ saveAsPng (
97+ event ,
98+ `${ getShapeFileName ( shape . name ) } -id` ,
99+ getShapeFileName ( shape . name )
100+ )
101+ }
102+ />
103+ </ span >
104+ </ ShapeActions >
105+ </ ShapeHeader >
106+ < Shape
107+ width = "300px"
108+ height = "300px"
109+ name = { shape . name }
110+ id = { `${ getShapeFileName ( shape . name ) } -id` }
111+ backgroundColor = "#eb3d86"
112+ showShadow = { shape . showAdvanced }
113+ />
114+
115+ < label htmlFor = { `${ getShapeFileName ( shape . name ) } -form` } >
116+ < span > Show Advanced</ span > { ' ' }
117+ < Switch
118+ onChange = { ( ) => handleSwicth ( shape . name ) }
119+ checked = { shape . showAdvanced }
120+ id = { `${ getShapeFileName ( shape . name ) } -form` }
121+ />
122+ </ label >
123+
124+ { shape . showAdvanced && (
125+ < ShapeDetailsItems >
126+ < span >
127+ < b > Clip-Path:</ b > { " " }
128+ < code >
129+ < b > { shape . formula } </ b >
130+ </ code >
131+ </ span > { " " }
132+ < span title = "Copy" >
133+ < CopyIcon
134+ size = { 24 }
135+ onClick = { ( event ) => performCopy ( event , shape . formula ) }
136+ />
137+ </ span >
138+ </ ShapeDetailsItems >
139+ ) }
140+ </ ShapeCard >
141+ </ React . Fragment >
142+ ) ) }
143+ </ ShapeCards >
144+ </ ShapePallete >
145+ ) ;
32146} ;
33147
34148export default App ;
0 commit comments