-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add FocusChin to guide toolbar v2 with dedicated controls for focus state #920
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
thomaswhyyou
merged 10 commits into
main
from
thomas-kno-12204-toolbar-beta-qa-and-feedback-items-6
Apr 1, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
30183cb
add FocusChin to the guide toolbar v2 with dedicated controls
thomaswhyyou a76f5b7
clean up
thomaswhyyou d23bccc
add a todo
thomaswhyyou 641d56b
unfocus when switching the list filter if focused guide becomes not v…
thomaswhyyou 5f75a16
use guide order index number based on the guide group display seq
thomaswhyyou 9a3e61b
show an empty state message when no guides under the current filter
thomaswhyyou 0353751
changeset
thomaswhyyou 0927690
change focus lock -> focus mode
thomaswhyyou 38a5460
truncate a long guide key in FocusChin
thomaswhyyou 91adc51
auto scroll to a focused guide if it goes outside of scroll view
thomaswhyyou 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 @@ | ||
| --- | ||
| "@knocklabs/react": patch | ||
| --- | ||
|
|
||
| [Guides] Add FocusChin to highlight focus mode w/ dedicated controls |
166 changes: 166 additions & 0 deletions
166
packages/react/src/modules/guide/components/Toolbar/V2/FocusChin.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,166 @@ | ||
| import { useGuideContext, useStore } from "@knocklabs/react-core"; | ||
| import { Button } from "@telegraph/button"; | ||
| import { Box, Stack } from "@telegraph/layout"; | ||
| import { Tooltip } from "@telegraph/tooltip"; | ||
| import { Text } from "@telegraph/typography"; | ||
| import { ChevronLeft, ChevronRight, X } from "lucide-react"; | ||
| import * as React from "react"; | ||
|
|
||
| import { GUIDE_ROW_DATA_SELECTOR } from "./GuideRow"; | ||
| import { InspectionResultOk } from "./useInspectGuideClientStore"; | ||
|
|
||
| // Extra scroll overshoot so the focused guide plus ~1-2 neighbors are visible, | ||
| // reducing how often consecutive next/prev clicks trigger a scroll. | ||
| const SCROLL_OVERSHOOT = 60; | ||
|
|
||
| const maybeScrollGuideIntoView = (container: HTMLElement, guideKey: string) => { | ||
| requestAnimationFrame(() => { | ||
| const el = container.querySelector( | ||
| `[${GUIDE_ROW_DATA_SELECTOR}="${CSS.escape(guideKey)}"]`, | ||
| ); | ||
| if (!el || !(el instanceof HTMLElement)) return; | ||
|
|
||
| const containerRect = container.getBoundingClientRect(); | ||
| const elRect = el.getBoundingClientRect(); | ||
|
|
||
| if (elRect.top < containerRect.top) { | ||
| container.scrollTo({ | ||
| top: | ||
| container.scrollTop - | ||
| (containerRect.top - elRect.top) - | ||
| SCROLL_OVERSHOOT, | ||
| behavior: "smooth", | ||
| }); | ||
| } else if (elRect.bottom > containerRect.bottom) { | ||
| container.scrollTo({ | ||
| top: | ||
| container.scrollTop + | ||
| (elRect.bottom - containerRect.bottom) + | ||
| SCROLL_OVERSHOOT, | ||
| behavior: "smooth", | ||
| }); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| type Props = { | ||
| guides: InspectionResultOk["guides"]; | ||
| guideListRef: React.RefObject<HTMLDivElement | null>; | ||
| }; | ||
|
|
||
| export const FocusChin = ({ guides, guideListRef }: Props) => { | ||
| const { client } = useGuideContext(); | ||
| const { debugSettings } = useStore(client.store, (state) => ({ | ||
| debugSettings: state.debug, | ||
| })); | ||
|
|
||
| const focusedKeys = Object.keys(debugSettings?.focusedGuideKeys || {}); | ||
|
|
||
| const isFocused = focusedKeys.length > 0; | ||
| if (!isFocused) { | ||
| return null; | ||
| } | ||
|
|
||
| const currentKey = focusedKeys[0]!; | ||
|
|
||
| return ( | ||
| <Box | ||
| borderTop="px" | ||
| px="3" | ||
| py="1" | ||
| overflow="hidden" | ||
| backgroundColor="blue-2" | ||
| > | ||
| <Stack align="center" justify="space-between" gap="4"> | ||
| <Text | ||
| as="span" | ||
| size="1" | ||
| weight="medium" | ||
| color="blue" | ||
| style={{ | ||
| display: "block", | ||
| overflow: "hidden", | ||
| textOverflow: "ellipsis", | ||
| whiteSpace: "nowrap", | ||
| minWidth: 0, | ||
| }} | ||
| > | ||
| Focus mode: {currentKey} | ||
| </Text> | ||
| <Stack align="center" gap="1" style={{ flexShrink: 0 }}> | ||
| <Tooltip label="Focus previous guide"> | ||
| <Button | ||
| size="0" | ||
| variant="ghost" | ||
| color="blue" | ||
| leadingIcon={{ icon: ChevronLeft, alt: "Previous guide" }} | ||
| onClick={() => { | ||
| const selectableGuides = guides.filter( | ||
| (g) => !!g.annotation.selectable.status, | ||
| ); | ||
| const currIndex = selectableGuides.findIndex( | ||
| (g) => g.key === currentKey, | ||
| ); | ||
| const prevGuide = | ||
| currIndex <= 0 ? undefined : selectableGuides[currIndex - 1]; | ||
|
|
||
| if (!prevGuide) return; | ||
|
|
||
| client.setDebug({ | ||
| ...debugSettings, | ||
| focusedGuideKeys: { [prevGuide.key]: true }, | ||
| }); | ||
|
|
||
| if (guideListRef.current) { | ||
| maybeScrollGuideIntoView(guideListRef.current, prevGuide.key); | ||
| } | ||
| }} | ||
| /> | ||
| </Tooltip> | ||
| <Tooltip label="Focus next guide"> | ||
| <Button | ||
| size="0" | ||
| variant="ghost" | ||
| color="blue" | ||
| leadingIcon={{ icon: ChevronRight, alt: "Next guide" }} | ||
| onClick={() => { | ||
| const selectableGuides = guides.filter( | ||
| (g) => !!g.annotation.selectable.status, | ||
| ); | ||
| const currIndex = selectableGuides.findIndex( | ||
| (g) => g.key === currentKey, | ||
| ); | ||
| const nextGuide = | ||
| currIndex < 0 || currIndex + 1 > selectableGuides.length - 1 | ||
| ? undefined | ||
| : selectableGuides[currIndex + 1]; | ||
|
|
||
| if (!nextGuide) return; | ||
|
|
||
| client.setDebug({ | ||
| ...debugSettings, | ||
| focusedGuideKeys: { [nextGuide.key]: true }, | ||
| }); | ||
|
|
||
| if (guideListRef.current) { | ||
| maybeScrollGuideIntoView(guideListRef.current, nextGuide.key); | ||
| } | ||
| }} | ||
| /> | ||
| </Tooltip> | ||
| <Tooltip label="Exit focus lock"> | ||
| <Button | ||
| size="0" | ||
| variant="ghost" | ||
| color="blue" | ||
| leadingIcon={{ icon: X, alt: "Clear focus" }} | ||
| onClick={() => { | ||
| client.setDebug({ ...debugSettings, focusedGuideKeys: {} }); | ||
| }} | ||
| /> | ||
| </Tooltip> | ||
| </Stack> | ||
| </Stack> | ||
| </Box> | ||
| ); | ||
| }; | ||
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
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.
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.