Skip to content

Commit

Permalink
feat(config): search bar style
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <[email protected]>
  • Loading branch information
ZTL-UwU committed Jul 12, 2024
1 parent 19e76c1 commit 67879af
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 18 deletions.
3 changes: 2 additions & 1 deletion components/layout/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<LayoutMobileNav />
<LayoutHeaderNav class="hidden lg:flex flex-1" />
<div class="flex flex-1 justify-end gap-2">
<LayoutSearchButton v-if="!config.search.inAside" />
<LayoutSearchButton v-if="!config.search.inAside && config.search.style === 'input'" />
<div class="flex">
<LayoutSearchButton v-if="!config.search.inAside && config.search.style === 'button'" />
<ThemePopover v-if="config.theme.customizable" />
<DarkModeToggle v-if="config.header.darkModeToggle" />
<NuxtLink
Expand Down
40 changes: 25 additions & 15 deletions components/layout/SearchButton.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
<template>
<UiButton
v-if="enable"
variant="outline"
class="pr-1.5 h-8 self-center w-full rounded-md font-normal text-muted-foreground hover:text-accent-foreground"
:class="[inAside ? 'mb-4' : 'md:w-40 lg:w-64']"
@click="isOpen = true"
>
<span class="overflow-hidden mr-auto">
Search...
</span>
<Kbd class="hidden md:block ml-auto">
<span class="text-xs">⌘</span>K
</Kbd>
</UiButton>
<template v-if="enable">
<UiButton
v-if="style === 'input'"
variant="outline"
class="pr-1.5 h-8 self-center w-full rounded-md font-normal text-muted-foreground hover:text-accent-foreground"
:class="[inAside ? 'mb-4' : 'md:w-40 lg:w-64']"
@click="isOpen = true"
>
<span class="overflow-hidden mr-auto">
Search...
</span>
<Kbd class="hidden md:block ml-auto">
<span class="text-xs">⌘</span>K
</Kbd>
</UiButton>
<UiButton
v-else
variant="ghost"
size="icon"
@click="isOpen = true"
>
<Icon name="lucide:search" size="16" />
</UiButton>
</template>

<LayoutSearchDialog v-model:open="isOpen" />
</template>

<script setup lang="ts">
const isOpen = ref(false);
const { enable, inAside } = useConfig().value.search;
const { enable, inAside, style } = useConfig().value.search;
</script>
2 changes: 1 addition & 1 deletion components/layout/SearchDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<VisuallyHidden as-child>
<UiDialogDescription aria-describedby="undefined" />
</VisuallyHidden>
<UiCommand v-model:search-term="input" class="h-svh md:h-[350px]">
<UiCommand v-model:search-term="input" class="h-svh sm:h-[350px]">
<UiCommandInput
placeholder="Search documentation..."
@keydown.enter="handleEnter"
Expand Down
1 change: 1 addition & 0 deletions composables/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const defaultConfig: DefaultConfig = {
search: {
enable: true,
inAside: false,
style: 'input',
},
};

Expand Down
5 changes: 4 additions & 1 deletion content/1.getting-started/4.changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ description: Changes made to shadcn-docs.

#### :icon{name="lucide:settings"} Config

- [`main.padded`](/api/configuration#main)
Added two new configs.

1. [`main.padded`](/api/configuration#main)
2. [`search.style`](/api/configuration#search)

## `v0.4.0`

Expand Down
3 changes: 3 additions & 0 deletions content/2.api/1.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,7 @@ interface INav {
::field{name="inAside" type="boolean" defaultValue="false"}
Whether to show the search bar in the sidebar.
::
::field{name="style" type="'input' | 'button'" defaultValue="input"}
Whether the search bar is displayed as a input or a button.
::
::
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ interface DefaultConfig {
search: {
enable: boolean;
inAside: boolean;
style: 'input' | 'button';
};
}

Expand Down

0 comments on commit 67879af

Please sign in to comment.