diff --git a/src/pages/Sketch/components/IconLibrary/IconsLibrary.jsx b/src/pages/Sketch/components/IconLibrary/IconsLibrary.jsx index c90bed0f..ad3aedfa 100644 --- a/src/pages/Sketch/components/IconLibrary/IconsLibrary.jsx +++ b/src/pages/Sketch/components/IconLibrary/IconsLibrary.jsx @@ -1,6 +1,14 @@ -import React, { useRef } from "react"; +import React, { useRef, useState } from "react"; import style from "./icon-lib.module.scss"; -import { Divider } from "@material-ui/core"; +import { + Divider, + IconButton, + InputAdornment, + makeStyles, + TextField, + Typography, +} from "@material-ui/core"; +import { Search } from "@material-ui/icons"; // Put you icon pack import here const iconPack1SVGs = importAll( @@ -31,12 +39,42 @@ function importAll(r) { } function IconPreview(props) { - const { iconPackSVGs, categoryTitle } = props; + const { iconPackSVGs, categoryTitle, searchString } = props; + const svgContainer = useRef(null); const allSVGsRef = useRef([]); + const hasCommonElements = (searchKeys, svgKeysFragments) => { + const commonElementArr = searchKeys.filter(searchKey => + svgKeysFragments.includes(searchKey), + ); + + return commonElementArr.length !== 0; + }; + + const searchKeys = searchString.split(/\W+/); + allSVGsRef.current = Object.keys(iconPackSVGs).map((imgName, index) => { + const svgKeys = imgName.slice(0, -4).split(/\W+/); + const svgKeysFragments = []; + svgKeys.forEach(svgKey => { + for (let i = 1; i <= svgKey.length; i++) { + svgKeysFragments.push(svgKey.slice(0, i)); + } + }); + return ( -