-
Notifications
You must be signed in to change notification settings - Fork 4k
Update search scope UI #3750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+305
−199
Merged
Update search scope UI #3750
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
77bf94c
Update search scope UI
zenoachtig 76b2efc
Merge branch 'main' into update-search-scope-ui
zenoachtig 330fac5
Merge branch 'main' into update-search-scope-ui
zenoachtig 5699699
Review
zenoachtig 997d7c7
Merge branch 'main' into update-search-scope-ui
zenoachtig f04a65d
Fix section display for sites with 1 section
zenoachtig d995dd7
Merge branch 'main' into update-search-scope-ui
zenoachtig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "gitbook": patch | ||
| --- | ||
|
|
||
| Update search scope UI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
packages/gitbook/src/components/Search/SearchScopeControl.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| 'use client'; | ||
|
|
||
| import { t, useLanguage } from '@/intl/client'; | ||
| import type { SiteSection } from '@gitbook/api'; | ||
| import { Button, DropdownChevron, DropdownMenu, DropdownMenuItem } from '../primitives'; | ||
| import { useSearch } from './useSearch'; | ||
|
|
||
| interface SearchScopeControlProps { | ||
| spaceTitle: string; | ||
| section?: Pick<SiteSection, 'title' | 'icon'>; | ||
| withVariants: boolean; | ||
| withSiteVariants: boolean; | ||
| withSections: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Toolbar to toggle between search modes (global or scoped to a space). | ||
| * Only visible when the space is in a collection. | ||
| */ | ||
| export function SearchScopeControl(props: SearchScopeControlProps) { | ||
| const { withVariants, withSections } = props; | ||
|
|
||
| const [state] = useSearch(); | ||
| const language = useLanguage(); | ||
|
|
||
| if (!state) { | ||
| return null; | ||
| } | ||
|
|
||
| // Whether to include all variants in the search | ||
| const sectionScopeIsExtended = ['default', 'all'].includes(state.scope); | ||
| const variantScopeIsExtended = ['extended', 'all'].includes(state.scope); | ||
|
|
||
| return ( | ||
| <div className="flex items-center gap-1"> | ||
| <span className="mr-1">{t(language, 'search_scope_title')}</span> | ||
| {withSections ? ( | ||
| <SearchScopeSectionControl isExtended={sectionScopeIsExtended} {...props} /> | ||
| ) : null} | ||
|
|
||
| {withVariants && (!withSections || !sectionScopeIsExtended) ? ( | ||
| <SearchScopeVariantControl isExtended={variantScopeIsExtended} {...props} /> | ||
| ) : null} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function SearchScopeSectionControl(props: SearchScopeControlProps & { isExtended: boolean }) { | ||
| const { isExtended, section } = props; | ||
|
|
||
| const language = useLanguage(); | ||
| const [, setSearchState] = useSearch(); | ||
|
|
||
| return ( | ||
| <DropdownMenu | ||
| button={ | ||
| <Button | ||
| variant="blank" | ||
| size="medium" | ||
| className="px-2 text-tint-strong" | ||
| icon={isExtended ? undefined : section?.icon} | ||
| > | ||
| <div className="flex items-center gap-2"> | ||
| {t( | ||
| language, | ||
| isExtended | ||
| ? 'search_scope_section_all' | ||
| : 'search_scope_section_current', | ||
| section?.title ?? '' | ||
| )} | ||
| <DropdownChevron /> | ||
| </div> | ||
| </Button> | ||
| } | ||
| > | ||
| <DropdownMenuItem | ||
| leadingIcon="infinity" | ||
| className="gap-3" | ||
| active={isExtended} | ||
| onClick={() => | ||
| setSearchState((prev) => (prev ? { ...prev, scope: 'default' } : null)) | ||
| } | ||
| > | ||
| <div className="flex flex-col"> | ||
| <span className="text-tint-strong"> | ||
| {t(language, 'search_scope_section_all')} | ||
| </span> | ||
| <span className="text-tint-subtle text-xs"> | ||
| {t(language, 'search_scope_section_all_description')} | ||
| </span> | ||
| </div> | ||
| </DropdownMenuItem> | ||
| <DropdownMenuItem | ||
| leadingIcon={section?.icon ?? 'crosshairs'} | ||
| className="gap-3" | ||
| active={!isExtended} | ||
| onClick={() => | ||
| setSearchState((prev) => (prev ? { ...prev, scope: 'current' } : null)) | ||
| } | ||
| > | ||
| <div className="flex flex-col"> | ||
| <span className="text-tint-strong"> | ||
| {t(language, 'search_scope_section_current', section?.title ?? '')} | ||
| </span> | ||
| <span className="text-tint-subtle text-xs"> | ||
| {t(language, 'search_scope_section_current_description')} | ||
| </span> | ||
| </div> | ||
| </DropdownMenuItem> | ||
| </DropdownMenu> | ||
| ); | ||
| } | ||
|
|
||
| function SearchScopeVariantControl(props: SearchScopeControlProps & { isExtended: boolean }) { | ||
| const { isExtended, spaceTitle, withSections } = props; | ||
|
|
||
| const language = useLanguage(); | ||
| const [, setSearchState] = useSearch(); | ||
|
|
||
| return ( | ||
| <DropdownMenu | ||
| button={ | ||
| <Button variant="blank" size="medium" className="px-2"> | ||
| <div className="flex items-center gap-2"> | ||
| <span className="text-tint-strong"> | ||
| {t( | ||
| language, | ||
| isExtended | ||
| ? 'search_scope_variant_all' | ||
| : 'search_scope_variant_current', | ||
| spaceTitle ?? '' | ||
| )} | ||
| </span> | ||
| <DropdownChevron /> | ||
| </div> | ||
| </Button> | ||
| } | ||
| > | ||
| <DropdownMenuItem | ||
| className="gap-3" | ||
| active={!isExtended} | ||
| onClick={() => | ||
| setSearchState((prev) => | ||
| prev ? { ...prev, scope: withSections ? 'current' : 'default' } : null | ||
| ) | ||
| } | ||
| > | ||
| <div className="flex flex-col"> | ||
| <span className="text-tint-strong"> | ||
| {t(language, 'search_scope_variant_current', spaceTitle ?? '')} | ||
| </span> | ||
| <span className="text-tint-subtle text-xs"> | ||
| {t(language, 'search_scope_variant_current_description')} | ||
| </span> | ||
| </div> | ||
| </DropdownMenuItem> | ||
| <DropdownMenuItem | ||
| className="gap-3" | ||
| active={isExtended} | ||
| onClick={() => | ||
| setSearchState((prev) => (prev ? { ...prev, scope: 'extended' } : null)) | ||
| } | ||
| > | ||
| <div className="flex flex-col"> | ||
| <span className="text-tint-strong"> | ||
| {t(language, 'search_scope_variant_all')} | ||
| </span> | ||
| <span className="text-tint-subtle text-xs"> | ||
| {t(language, 'search_scope_variant_all_description')} | ||
| </span> | ||
| </div> | ||
| </DropdownMenuItem> | ||
| </DropdownMenu> | ||
| ); | ||
| } | ||
133 changes: 0 additions & 133 deletions
133
packages/gitbook/src/components/Search/SearchScopeToggle.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.