-
-
Notifications
You must be signed in to change notification settings - Fork 405
Refactor: replace CodeLangToggle with CodeExampleClient for improved (#430) #431
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||||||||||||||||||||||||
| "use client"; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import { useLayoutEffect, useRef, useState, type ReactNode } from "react"; | ||||||||||||||||||||||||||||
| import { LangToggle } from "./CodeLangToggle"; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| type LangItem = { | ||||||||||||||||||||||||||||
| key: string; | ||||||||||||||||||||||||||||
| label: string; | ||||||||||||||||||||||||||||
| kind: string; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export function CodeExampleClient({ | ||||||||||||||||||||||||||||
| languages, | ||||||||||||||||||||||||||||
| panels, | ||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||
| languages: LangItem[]; | ||||||||||||||||||||||||||||
| panels: Record<string, ReactNode>; | ||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||
| const [activeLang, setActiveLang] = useState(languages[0]?.key ?? "ts"); | ||||||||||||||||||||||||||||
| const contentRef = useRef<HTMLDivElement>(null); | ||||||||||||||||||||||||||||
| const [height, setHeight] = useState<number | undefined>(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| useLayoutEffect(() => { | ||||||||||||||||||||||||||||
| const el = contentRef.current; | ||||||||||||||||||||||||||||
| if (!el) return; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const measure = () => setHeight(el.scrollHeight); | ||||||||||||||||||||||||||||
| measure(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const observer = new ResizeObserver(measure); | ||||||||||||||||||||||||||||
| observer.observe(el); | ||||||||||||||||||||||||||||
| return () => observer.disconnect(); | ||||||||||||||||||||||||||||
| }, [activeLang]); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||
| <div className="flex items-center gap-2 justify-center py-2 text-xs text-muted-foreground mb-4"> | ||||||||||||||||||||||||||||
| <LangToggle | ||||||||||||||||||||||||||||
| active={activeLang} | ||||||||||||||||||||||||||||
| onActiveChange={setActiveLang} | ||||||||||||||||||||||||||||
| languages={languages} | ||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| <div className="rounded-[18px] bg-primary/20 p-1"> | ||||||||||||||||||||||||||||
| <div className="rounded-[14px] bg-primary/20 p-0.5 shadow-sm"> | ||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||
| className="bg-background rounded-xl overflow-hidden transition-[height] duration-300 ease-in-out" | ||||||||||||||||||||||||||||
| style={height !== undefined ? { height: `${height}px` } : undefined} | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| <div ref={contentRef}> | ||||||||||||||||||||||||||||
| {languages.map((l) => ( | ||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||
| key={l.key} | ||||||||||||||||||||||||||||
| className={activeLang === l.key ? "block" : "hidden"} | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| {panels[l.key]} | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
| <div className="sr-only" aria-live="polite"> | ||||||||||||||||||||||||||||
| Language example toggled | ||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||
|
Comment on lines
+63
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Static aria-live text never triggers a screen-reader announcement. Screen readers announce live regions only when their content changes. This text is hardcoded and identical on every render, so switching languages never actually announces anything to assistive tech, despite that being the intent of this region. 🔊 Proposed fix+ const activeLabel =
+ languages.find((l) => l.key === activeLang)?.label ?? activeLang;
+
return (
<>
...
<div className="sr-only" aria-live="polite">
- Language example toggled
+ Showing {activeLabel} example
</div>
</>
);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export default CodeExampleClient; | ||||||||||||||||||||||||||||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: usesend/useSend
Length of output: 828
🏁 Script executed:
Repository: usesend/useSend
Length of output: 7623
Remove the
as anycast onlang.CodeBlockalready acceptsBundledLanguage | "text", so this only weakens type safety and can hide future language mismatches.🤖 Prompt for AI Agents