-
Notifications
You must be signed in to change notification settings - Fork 699
Feature/kbar #1161
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
Merged
Feature/kbar #1161
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b64f980
Added CommandBar component for kbar
mwritter 10d0e78
Merge branch 'main' into feature/kbar
mwritter cf5d079
Added Kbar results section
mwritter 373d580
Kbar init integration
mwritter 0f57f7c
Kbar clean up
mwritter f80cc48
Kbar clean up
mwritter 253244c
Kbar clean up
mwritter f4813f1
More Kbar clean up - use internal_shortcut to show we're not using kb…
mwritter 5b2bbbf
Kbar clean up, tried to optimize kbar results
mwritter dbc04de
clean up
mwritter 7b6a8dd
merged in main
mwritter 5676874
little refactor
mwritter 11f7dfd
Added test for platform-key util
mwritter c47512b
Added test for use-modes
mwritter c97d300
Merge branch 'main' into feature/kbar
mwritter 394b428
pnpm
mwritter 80062f6
Fixing tests
mwritter abf954c
Fixing tests
mwritter 4697ae2
oof
mwritter b4b2495
Add some test clean up
mwritter 79f9821
Clean up
mwritter e82eb75
Added some comments, and added back to default mode text
mwritter ffa1eeb
added changeset
mwritter 57c5dfb
Update .changeset/long-suns-smoke.md
mwritter 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 @@ | ||
| --- | ||
| 'spectacle': minor | ||
| --- | ||
|
|
||
| Utilize `Kbar` to allow users to quickly search and use the current commands Spectacle supports within presentations. Fixes #1115 |
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| strict-peer-dependencies=false | ||
| prefer-workspace-packages=true | ||
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
72 changes: 72 additions & 0 deletions
72
packages/spectacle/src/components/command-bar/command-bar-actions.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,72 @@ | ||
| import { | ||
| KEYBOARD_SHORTCUTS_IDS, | ||
| SpectacleMode, | ||
| SPECTACLE_MODES | ||
| } from '../../utils/constants'; | ||
| import useModes from '../../hooks/use-modes'; | ||
|
|
||
| /** | ||
| * Kbar default actions, those that do not depend on dynamic logic, can be added here. | ||
| * To register actions dynamically use 'useRegisterActions' and make sure the action | ||
| * is registed within the KBarProvider. | ||
| * @see https://kbar.vercel.app/docs/concepts/actions | ||
| * Kbar action shortcuts dont seem to support all keybindings. If you need to utilize | ||
| * keybindings that are not supported you'll have to implement the keybinding seperately. | ||
| * @see useMousetrap | ||
| * To display keybindings that are not supported in the Kbar results, please use | ||
| * KEYBOARD_SHORTCUTS instead of Kbar actions 'shortcut' property. | ||
| * @see CommandBarResults getShortcutKeys | ||
| */ | ||
|
|
||
| const spectacleModeDisplay = { | ||
| [SPECTACLE_MODES.DEFAULT_MODE]: 'Default Mode', | ||
| [SPECTACLE_MODES.PRESENTER_MODE]: 'Presenter Mode', | ||
| [SPECTACLE_MODES.OVERVIEW_MODE]: 'Overview Mode', | ||
| [SPECTACLE_MODES.PRINT_MODE]: 'Print Mode', | ||
| [SPECTACLE_MODES.EXPORT_MODE]: 'Export Mode' | ||
| }; | ||
|
|
||
| const getName = (currentMode: string, mode: SpectacleMode) => { | ||
| const defaultMode = SPECTACLE_MODES.DEFAULT_MODE; | ||
|
|
||
| return currentMode === mode | ||
| ? `← Back to ${spectacleModeDisplay[defaultMode]}` | ||
| : spectacleModeDisplay[mode]; | ||
| }; | ||
|
|
||
| const useCommandBarActions = () => { | ||
| const { toggleMode, getCurrentMode } = useModes(); | ||
| const currentMode = getCurrentMode(); | ||
| return [ | ||
| { | ||
| id: KEYBOARD_SHORTCUTS_IDS.PRESENTER_MODE, | ||
| name: getName(currentMode, SPECTACLE_MODES.PRESENTER_MODE), | ||
| keywords: 'presenter', | ||
| perform: () => toggleMode({ newMode: SPECTACLE_MODES.PRESENTER_MODE }), | ||
| section: 'Mode' | ||
| }, | ||
| { | ||
| id: KEYBOARD_SHORTCUTS_IDS.OVERVIEW_MODE, | ||
| name: getName(currentMode, SPECTACLE_MODES.OVERVIEW_MODE), | ||
| keywords: 'overview', | ||
| perform: () => toggleMode({ newMode: SPECTACLE_MODES.OVERVIEW_MODE }), | ||
| section: 'Mode' | ||
| }, | ||
| { | ||
| id: KEYBOARD_SHORTCUTS_IDS.PRINT_MODE, | ||
| name: getName(currentMode, SPECTACLE_MODES.PRINT_MODE), | ||
| keywords: 'export', | ||
| perform: () => toggleMode({ newMode: SPECTACLE_MODES.PRINT_MODE }), | ||
| section: 'Mode' | ||
| }, | ||
| { | ||
| id: KEYBOARD_SHORTCUTS_IDS.EXPORT_MODE, | ||
| name: getName(currentMode, SPECTACLE_MODES.EXPORT_MODE), | ||
| keywords: 'export', | ||
| perform: () => toggleMode({ newMode: SPECTACLE_MODES.EXPORT_MODE }), | ||
| section: 'Mode' | ||
| } | ||
| ]; | ||
| }; | ||
|
|
||
| export default useCommandBarActions; |
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,20 @@ | ||
| import { ReactNode } from 'react'; | ||
| import { KBarProvider } from 'kbar'; | ||
| import useCommandBarActions from './command-bar-actions'; | ||
| import CommandBarSearch from './search'; | ||
|
|
||
| const CommandBar = ({ children }: CommandBarProps): JSX.Element => { | ||
| const actions = useCommandBarActions(); | ||
| return ( | ||
| <KBarProvider actions={actions}> | ||
| <CommandBarSearch /> | ||
| {children} | ||
| </KBarProvider> | ||
| ); | ||
| }; | ||
|
|
||
| export type CommandBarProps = { | ||
| children: ReactNode; | ||
| }; | ||
|
|
||
| export default CommandBar; |
90 changes: 90 additions & 0 deletions
90
packages/spectacle/src/components/command-bar/results/index.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,90 @@ | ||
| import styled from 'styled-components'; | ||
| import { ActionImpl, KBarResults, useMatches } from 'kbar'; | ||
| import { prettifyShortcut } from '../../../utils/platform-keys'; | ||
| import { | ||
| KeyboardShortcutTypes, | ||
| KEYBOARD_SHORTCUTS, | ||
| SYSTEM_FONT | ||
| } from '../../../utils/constants'; | ||
| import { Text } from '../../typography'; | ||
|
|
||
| type RenderParams = { | ||
| item: ActionImpl | string; | ||
| active: boolean; | ||
| }; | ||
|
|
||
| function getShortcutKeys({ id, shortcut = [] }: ActionImpl): string[] { | ||
| if (id in KEYBOARD_SHORTCUTS && !shortcut?.length) { | ||
| const _id = id as KeyboardShortcutTypes; | ||
| return prettifyShortcut(KEYBOARD_SHORTCUTS[_id]); | ||
| } | ||
| return prettifyShortcut(shortcut); | ||
| } | ||
|
|
||
| const ResultCommand = styled.div<Partial<RenderParams>>` | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| background-color: ${(p) => (p.active ? 'lightsteelblue' : 'transparent')}; | ||
| padding: 0.5rem 1rem; | ||
| cursor: pointer; | ||
| height: 30px; | ||
| `; | ||
|
|
||
| const ResultSectionHeader = styled(Text)` | ||
| background-color: white; | ||
| color: gray; | ||
| margin: 0 2rem; | ||
| padding: 0.5rem 0; | ||
| font-size: small; | ||
| font-weight: bold; | ||
| font-family: ${SYSTEM_FONT}; | ||
| `; | ||
|
|
||
| const ResultShortcut = styled.span` | ||
| display: flex; | ||
| gap: 5px; | ||
| `; | ||
|
|
||
| const ResultShortcutKey = styled.kbd` | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| background-color: #eee; | ||
| border-radius: 5px; | ||
| border: 1px solid #b4b4b4; | ||
| padding: 5px 10px; | ||
| min-width: 20px; | ||
| height: 25px; | ||
| white-space: nowrap; | ||
| font-family: ${SYSTEM_FONT}; | ||
| `; | ||
|
|
||
| function onRender({ item, active }: RenderParams) { | ||
| if (typeof item === 'string') { | ||
| return <ResultSectionHeader>{item}</ResultSectionHeader>; | ||
| } else { | ||
| return ( | ||
| <ResultCommand active={active}> | ||
| <Text fontFamily={SYSTEM_FONT}>{item.name}</Text> | ||
| <ResultShortcut> | ||
| {getShortcutKeys(item).map( | ||
| (key) => | ||
| key && ( | ||
| <ResultShortcutKey key={`${item.id}-${key}`}> | ||
| {key} | ||
| </ResultShortcutKey> | ||
| ) | ||
| )} | ||
| </ResultShortcut> | ||
| </ResultCommand> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| const CommandBarResults = () => { | ||
| const { results } = useMatches(); | ||
| return <KBarResults items={results} onRender={onRender} />; | ||
| }; | ||
|
|
||
| export default CommandBarResults; |
36 changes: 36 additions & 0 deletions
36
packages/spectacle/src/components/command-bar/search/index.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,36 @@ | ||
| import styled from 'styled-components'; | ||
| import { KBarPortal, KBarPositioner, KBarAnimator, KBarSearch } from 'kbar'; | ||
| import CommandBarResults from '../results'; | ||
|
|
||
| const KBarSearchStyled = styled(KBarSearch)` | ||
| padding: 12px 16px; | ||
| font-size: 16px; | ||
| width: 100%; | ||
| box-sizing: border-box; | ||
| outline: none; | ||
| border: none; | ||
| `; | ||
|
|
||
| const KBarAnimatorStyled = styled(KBarAnimator)` | ||
| max-width: 600px; | ||
| width: 100%; | ||
| background: white; | ||
| border-radius: 8px; | ||
| overflow: hidden; | ||
| box-shadow: rgb(0 0 0 / 50%) 0px 16px 70px; | ||
| `; | ||
|
|
||
| const CommandBarSearch = () => { | ||
| return ( | ||
| <KBarPortal> | ||
| <KBarPositioner> | ||
| <KBarAnimatorStyled> | ||
| <KBarSearchStyled /> | ||
| <CommandBarResults /> | ||
| </KBarAnimatorStyled> | ||
| </KBarPositioner> | ||
| </KBarPortal> | ||
| ); | ||
| }; | ||
|
|
||
| export default CommandBarSearch; |
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
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.