From aaafbfdf4c6a17cec9b02351604a82aacb69fbeb Mon Sep 17 00:00:00 2001 From: MengLinMaker Date: Thu, 31 Oct 2024 23:08:01 +1100 Subject: [PATCH] docs(search): add cmdk style example --- apps/docs/src/examples/search.module.css | 60 ++++++++++++++----- apps/docs/src/examples/search.tsx | 40 +++++-------- .../routes/docs/core/components/search.mdx | 45 +++++++++++++- 3 files changed, 103 insertions(+), 42 deletions(-) diff --git a/apps/docs/src/examples/search.module.css b/apps/docs/src/examples/search.module.css index d58a5c85..83f3a559 100644 --- a/apps/docs/src/examples/search.module.css +++ b/apps/docs/src/examples/search.module.css @@ -1,4 +1,5 @@ .search__control { + overflow: hidden; display: inline-flex; justify-content: space-between; width: 250px; @@ -14,11 +15,6 @@ color 250ms; } -.search__control[data-invalid] { - border-color: hsl(0 72% 51%); - color: hsl(0 72% 51%); -} - .search__control_multi { width: 100%; min-width: 250px; @@ -49,8 +45,6 @@ align-items: center; width: auto; outline: none; - border-top-left-radius: 6px; - border-bottom-left-radius: 6px; padding: 0 10px; background-color: hsl(240 5% 96%); border-right: 1px solid hsl(240 6% 90%); @@ -145,7 +139,6 @@ .search__item[data-highlighted] { outline: none; box-sizing: border-box; - background-color: hsl(240 5% 96%); box-shadow: inset 0 0 0 2px hsl(200 98% 39%); } @@ -205,11 +198,6 @@ border-color: hsl(240 4% 46%); } -[data-kb-theme="dark"] .search__control[data-invalid] { - border-color: hsl(0 72% 51%); - color: hsl(0 72% 51%); -} - [data-kb-theme="dark"] .search__input::placeholder { color: hsl(0 100% 100% / 0.5); } @@ -245,13 +233,53 @@ } .search__root_cmdk { - min-height: 250px; + min-height: 240px; min-width: 250px; + display: flex; + flex-direction: column; +} + +.search__control_cmdk { + overflow: hidden; + display: inline-flex; + justify-content: space-between; + border-radius: 12px 12px 0 0; + font-size: 16px; + line-height: 1; + outline: none; + background-color: white; + border: 1px solid hsl(240 6% 90%); + color: hsl(240 4% 16%); + transition: + border-color 250ms, + color 250ms; } .search__content_cmdk { - height: 200px; + height: 100%; + flex-grow: 1; background-color: white; - border-radius: 6px; + border-radius: 0 0 12px 12px; border: 1px solid hsl(240 6% 90%); + border-top: none; + display: flex; + flex-direction: column; +} + +.search__no_result_cmdk { + text-align: center; + margin: auto; + padding-bottom: 24px; + color: hsl(240 4% 46%); +} + +[data-kb-theme="dark"] .search__control_cmdk { + background-color: hsl(240 4% 16%); + border: 1px solid hsl(240 5% 34%); + color: hsl(0 100% 100% / 0.9); +} + +[data-kb-theme="dark"] .search__content_cmdk { + background-color: hsl(240 4% 16%); + border: 1px solid hsl(240 5% 34%); } diff --git a/apps/docs/src/examples/search.tsx b/apps/docs/src/examples/search.tsx index f9fe3815..4c97f1da 100644 --- a/apps/docs/src/examples/search.tsx +++ b/apps/docs/src/examples/search.tsx @@ -328,10 +328,6 @@ const RAW_EMOJI_DATA: EmojiDatum[] = ([] as any) emoji: "šŸ™", name: "slightly frowning face", }, - { - emoji: "ā˜¹", - name: "frowning face", - }, { emoji: "šŸ˜®", name: "face with open mouth", @@ -656,12 +652,13 @@ export function DebounceExample() { ); } -export function CmdkExample() { +export function CmdkStyleExample() { const [options, setOptions] = createSignal([]); const [emoji, setEmoji] = createSignal(); return ( <> { setOptions(queryEmojiData(query)); @@ -671,31 +668,26 @@ export function CmdkExample() { optionLabel="name" placeholder="Search an emojiā€¦" itemComponent={(props: any) => ( - + {props.item.rawValue.emoji} )} class={style.search__root_cmdk} > -
- - - - - - - - - -
+ + + + + + -
- - - - šŸ˜¬ No emoji found - - + + +
+ + + šŸ˜¬ No emoji found +
diff --git a/apps/docs/src/routes/docs/core/components/search.mdx b/apps/docs/src/routes/docs/core/components/search.mdx index 88ff933b..f938e9b0 100644 --- a/apps/docs/src/routes/docs/core/components/search.mdx +++ b/apps/docs/src/routes/docs/core/components/search.mdx @@ -1,5 +1,5 @@ import { Preview, TabsSnippets, Kbd, Callout } from "../../../../components"; -import { BasicExample, DebounceExample, CmdkExample } from "../../../../examples/search"; +import { BasicExample, DebounceExample, CmdkStyleExample } from "../../../../examples/search"; # Search @@ -344,7 +344,7 @@ Show a debouncing icon by adding a `loadingComponent` to `Search.Indicator`. optionValue="name" optionLabel="name" placeholder="Search an emojiā€¦" - itemComponent={(props: any) => ( + itemComponent={(props: any) => ( {props.item.rawValue.emoji} @@ -375,6 +375,47 @@ Show a debouncing icon by adding a `loadingComponent` to `Search.Indicator`. ``` +### Cmdk style + +To achieve the command menu look, add the `open` prop to permanently open dropdown. Replace `Search.Portal` and `Search.Content` with a `div` to directly mount your content below the search input. + + + + + + ```tsx + setOptions(queryEmojiData(query))} + onChange={result => setEmoji(result)} + debounceOptionsMillisecond={300} + optionValue="name" + optionLabel="name" + placeholder="Search an emojiā€¦" + itemComponent={(props: any) => ( + + {props.item.rawValue.emoji} + + )} + > + + + + + + + + +
+ + + šŸ˜¬ No emoji found + +
+
+ ``` + ## API Reference ### Search