From 608f0210a09ca3eb2346442ee60152c13069f445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mime=20=C4=8Cuvalo?= Date: Sat, 27 Apr 2024 12:13:38 +0100 Subject: [PATCH] examples: add filter input (#3625) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was @Taha-Hassan-Git 's idea originally but I thought it wasn't necessary at the time (with our much shorter list of examples just a couple months ago!). I think now that we have a plethora of examples that @Taha-Hassan-Git 's original instinct here was correct and we should a filter box. Screenshot 2024-04-26 at 15 22 08 ### Change Type - [ ] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [x] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Release Notes - Examples: add a filter box. --- apps/examples/src/ExamplePage.tsx | 15 ++++++++++++++- apps/examples/src/styles.css | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/apps/examples/src/ExamplePage.tsx b/apps/examples/src/ExamplePage.tsx index 94b4fbcae..221f0d71f 100644 --- a/apps/examples/src/ExamplePage.tsx +++ b/apps/examples/src/ExamplePage.tsx @@ -28,6 +28,10 @@ export function ExamplePage({ children: React.ReactNode }) { const categories = examples.map((e) => e.id) + const [filterValue, setFilterValue] = useState('') + const handleFilterChange = (e: React.ChangeEvent) => { + setFilterValue(e.target.value) + } return ( @@ -69,6 +73,12 @@ export function ExamplePage({ Develop +
    {categories.map((currentCategory) => (
  • @@ -76,7 +86,10 @@ export function ExamplePage({
      {examples .find((category) => category.id === currentCategory) - ?.value.map((sidebarExample) => ( + ?.value.filter((example) => + example.title.toLowerCase().includes(filterValue.toLowerCase()) + ) + .map((sidebarExample) => ( ul > li) { + display: block; +} + ul.example__sidebar__category__items { list-style: none; padding: 0px 0px 0px 4px;