From a398398b272d258efa7923d51ad0b67cebb26302 Mon Sep 17 00:00:00 2001 From: SpyC0der77 Date: Mon, 20 Jan 2025 11:12:18 -0500 Subject: [PATCH] Add search functionality to Sidebar and create Input component --- src/components/Sidebar.tsx | 48 +++++++++++++++++++++++++++---------- src/components/ui/input.tsx | 22 +++++++++++++++++ 2 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 src/components/ui/input.tsx diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 2a7d3f8..73263a7 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -1,10 +1,11 @@ 'use client' -import React, { useRef } from 'react' +import React, { useRef, useState } from 'react' import { useDrag } from 'react-dnd' import { Button } from "@/components/ui/button" import { roboto } from '../app/fonts' import { useElements } from '../context/ElementsContext' +import { Input } from "@/components/ui/input" interface DraggableElementProps { type: string @@ -40,20 +41,41 @@ const DraggableElement: React.FC = ({ type, content }) => export const Sidebar: React.FC = () => { const { elements, getElementContent } = useElements() + const [searchQuery, setSearchQuery] = useState('') + + const filteredElements = Array.from(elements.values()).filter(element => + getElementContent(element.type).toLowerCase().includes(searchQuery.toLowerCase()) + ) return ( -
-

Elements

-
- {Array.from(elements.values()).map((element) => ( - - ))} +
+
+
+ {filteredElements.map((element) => ( + + ))} +
+
+
+ {/*
+ + +
*/} + setSearchQuery(e.target.value)} + />
) -} - +} \ No newline at end of file diff --git a/src/components/ui/input.tsx b/src/components/ui/input.tsx new file mode 100644 index 0000000..69b64fb --- /dev/null +++ b/src/components/ui/input.tsx @@ -0,0 +1,22 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +const Input = React.forwardRef>( + ({ className, type, ...props }, ref) => { + return ( + + ) + } +) +Input.displayName = "Input" + +export { Input }