-
Notifications
You must be signed in to change notification settings - Fork 0
Polish FileTree, Prompt, and TopicSwitcher in docs example #23
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
028f7c0
Add agent-focused MDX components
KayleeWilliams 66c54b2
Polish FileTree, Prompt, and TopicSwitcher in docs example
KayleeWilliams 75752f1
Fix MDX component review issues
KayleeWilliams d659735
Fix review comments for MDX docs components
KayleeWilliams 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,20 @@ | ||
| import type { HTMLAttributes, ReactNode } from "react"; | ||
|
|
||
| export type AudienceTarget = "agent" | "human"; | ||
|
|
||
| export type AudienceProps = HTMLAttributes<HTMLDivElement> & { | ||
| target: AudienceTarget; | ||
| children?: ReactNode; | ||
| }; | ||
|
|
||
| export function Audience({ target, children, ...rest }: AudienceProps) { | ||
| if (target === "agent") { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div data-leadtype-audience={target} {...rest}> | ||
| {children} | ||
| </div> | ||
| ); | ||
| } |
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,143 @@ | ||
| import type { | ||
| DetailsHTMLAttributes, | ||
| HTMLAttributes, | ||
| LiHTMLAttributes, | ||
| ReactNode, | ||
| } from "react"; | ||
| import { useState } from "react"; | ||
|
|
||
| function FolderIcon() { | ||
| return ( | ||
| <svg | ||
| aria-hidden="true" | ||
| data-leadtype-file-tree-icon="folder" | ||
| fill="none" | ||
| height="14" | ||
| viewBox="0 0 16 16" | ||
| width="14" | ||
| > | ||
| <path | ||
| d="M1.75 3.5h4.379a.75.75 0 0 1 .53.22L8.19 5.25h6.06a.75.75 0 0 1 .75.75v6.5a.75.75 0 0 1-.75.75H1.75a.75.75 0 0 1-.75-.75v-8.25a.75.75 0 0 1 .75-.75Z" | ||
| fill="currentColor" | ||
| fillOpacity="0.16" | ||
| stroke="currentColor" | ||
| strokeWidth="1.1" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } | ||
|
|
||
| function FileIcon() { | ||
| return ( | ||
| <svg | ||
| aria-hidden="true" | ||
| data-leadtype-file-tree-icon="file" | ||
| fill="none" | ||
| height="14" | ||
| viewBox="0 0 16 16" | ||
| width="14" | ||
| > | ||
| <path | ||
| d="M3.75 2h5.5L13 5.75v8.5a.75.75 0 0 1-.75.75h-8.5a.75.75 0 0 1-.75-.75v-11.5A.75.75 0 0 1 3.75 2Z" | ||
| fill="currentColor" | ||
| fillOpacity="0.08" | ||
| stroke="currentColor" | ||
| strokeWidth="1.1" | ||
| /> | ||
| <path | ||
| d="M9.25 2v3.25a.5.5 0 0 0 .5.5H13" | ||
| stroke="currentColor" | ||
| strokeLinecap="round" | ||
| strokeWidth="1.1" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } | ||
|
|
||
| function ChevronIcon() { | ||
| return ( | ||
| <svg | ||
| aria-hidden="true" | ||
| data-leadtype-file-tree-chevron="" | ||
| fill="none" | ||
| height="10" | ||
| viewBox="0 0 16 16" | ||
| width="10" | ||
| > | ||
| <path | ||
| d="m6 4 4 4-4 4" | ||
| stroke="currentColor" | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth="1.6" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } | ||
|
|
||
| export type FileTreeProps = HTMLAttributes<HTMLDivElement> & { | ||
| root?: string; | ||
| children?: ReactNode; | ||
| }; | ||
|
|
||
| export function FileTree({ root, children, ...rest }: FileTreeProps) { | ||
| return ( | ||
| <div data-leadtype-file-tree="" {...rest}> | ||
| {root ? ( | ||
| <div data-leadtype-file-tree-root=""> | ||
| <FolderIcon /> | ||
| <span data-leadtype-file-tree-name="">{root}/</span> | ||
| </div> | ||
| ) : null} | ||
| <ul data-leadtype-file-tree-list="">{children}</ul> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export type FolderProps = DetailsHTMLAttributes<HTMLDetailsElement> & { | ||
| name: string; | ||
| defaultOpen?: boolean; | ||
| children?: ReactNode; | ||
| }; | ||
|
|
||
| export function Folder({ | ||
| name, | ||
| defaultOpen = true, | ||
| children, | ||
| ...rest | ||
| }: FolderProps) { | ||
| const [isOpen, setIsOpen] = useState(defaultOpen); | ||
|
|
||
| return ( | ||
| <li data-leadtype-file-tree-item=""> | ||
| <details | ||
| data-leadtype-file-tree-folder="" | ||
| onToggle={(event) => | ||
| setIsOpen((event.target as HTMLDetailsElement).open) | ||
| } | ||
| open={isOpen} | ||
| {...rest} | ||
| > | ||
| <summary data-leadtype-file-tree-summary=""> | ||
| <ChevronIcon /> | ||
| <FolderIcon /> | ||
| <span data-leadtype-file-tree-name="">{name}/</span> | ||
| </summary> | ||
| <ul data-leadtype-file-tree-list="">{children}</ul> | ||
| </details> | ||
| </li> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ); | ||
| } | ||
|
|
||
| export type FileProps = LiHTMLAttributes<HTMLLIElement> & { | ||
| name: string; | ||
| }; | ||
|
|
||
| export function File({ name, ...rest }: FileProps) { | ||
| return ( | ||
| <li data-leadtype-file-tree-file="" {...rest}> | ||
| <FileIcon /> | ||
| <span data-leadtype-file-tree-name="">{name}</span> | ||
| </li> | ||
| ); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 41
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 112
🏁 Script executed:
git ls-files | grep file-tree.tsxRepository: inthhq/leadtype
Length of output: 110
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 890
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 915
🏁 Script executed:
cat -n apps/example/src/components/docs-mdx/file-tree.tsx | head -130Repository: inthhq/leadtype
Length of output: 3927
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 114
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 943
🏁 Script executed:
rg -A 5 "onToggle" apps/example/src/components/docs-mdx/file-tree.tsxRepository: inthhq/leadtype
Length of output: 209
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 87
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 41
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 449
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 50374
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 168
🏁 Script executed:
rg "<Folder" apps/example/src --max-count=10Repository: inthhq/leadtype
Length of output: 50374
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 41
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 50374
🏁 Script executed:
Repository: inthhq/leadtype
Length of output: 668
Prevent prop override: omit
open/onTogglefromFolderProps.FolderPropscurrently extendsDetailsHTMLAttributes<HTMLDetailsElement>, and{...rest}is spread after the internalopenandonToggleprops. Since JSX applies props left-to-right, caller-suppliedopenoronToggleinrestwill override the internal state management, breaking the component's ability to track folder open/closed state.Additionally, the
onTogglehandler usesevent.target as HTMLDetailsElement— a type assertion that violates the coding guideline to leverage type narrowing.event.currentTargetis properly typed without needing a cast.Proposed fix
🤖 Prompt for AI Agents