Skip to content

Commit 00b3c71

Browse files
📝 Add docstrings to itasimo/header
Docstrings generation was requested by @itasimo. * #57 (comment) The following files were modified: * `src/components/glass.tsx` * `src/components/header.tsx` * `src/components/ui/navigation-menu.tsx`
1 parent ef4ca0e commit 00b3c71

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

src/components/glass.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import { cn } from "@/lib/utils"
22

33
type GlassProps = React.HTMLAttributes<HTMLDivElement>
44

5+
/**
6+
* Render a div with a glass-like visual treatment that wraps provided children.
7+
*
8+
* Merges the caller-provided `className` with the component's default styling:
9+
* rounded corners, border, translucent white background, padding, and backdrop blur.
10+
*
11+
* @param children - Content rendered inside the glass-styled container
12+
* @returns A `div` element with merged classes and the provided `children`
13+
*/
514
export function Glass({ children, ...props }: GlassProps) {
615
return (
716
<div

src/components/header.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ import {
1515
navigationMenuTriggerStyle,
1616
} from "@/components/ui/navigation-menu"
1717

18-
// --- Custom Hook for Media Query ---
18+
/**
19+
* Subscribes to a CSS media query and exposes whether it currently matches.
20+
*
21+
* @param query - A valid CSS media query string (e.g. `"(max-width: 768px)"`)
22+
* @returns `true` if the media query currently matches, `false` otherwise
23+
*
24+
* Observes changes and updates the returned value when the query match state changes; listener is cleaned up on unmount or when `query` changes.
25+
*/
1926
function useMediaQuery(query: string): boolean {
2027
const [matches, setMatches] = React.useState(false)
2128

@@ -66,15 +73,29 @@ const components: {
6673
},
6774
]
6875

69-
// --- Icon Button Handlers ---
76+
/**
77+
* Handle clicks on the user/profile icon.
78+
*
79+
* Logs "User icon clicked" to the console.
80+
*/
7081
function handleUserIconClick() {
7182
console.log("User icon clicked")
7283
}
7384

85+
/**
86+
* Handle clicks on the globe (language) icon.
87+
*
88+
* Logs "Globe icon clicked" to the console.
89+
*/
7490
function handleGlobeIconClick() {
7591
console.log("Globe icon clicked")
7692
}
7793

94+
/**
95+
* Log that the moon (theme) icon was clicked.
96+
*
97+
* Logs the string "Moon icon clicked" to the console.
98+
*/
7899
function handleMoonIconClick() {
79100
console.log("Moon icon clicked")
80101
}
@@ -247,7 +268,14 @@ const DesktopLayout = () => {
247268
)
248269
}
249270

250-
// --- Main Header Component ---
271+
/**
272+
* Render the responsive header that switches between mobile and desktop layouts.
273+
*
274+
* While the app hydrates, the component renders the mobile layout by default to avoid a layout flash;
275+
* after mount it selects mobile or desktop based on the "(max-width: 768px)" media query.
276+
*
277+
* @returns A React element for the header: initially the mobile layout until hydration completes, then the mobile layout when the viewport is 768px wide or narrower, otherwise the desktop layout.
278+
*/
251279
export function Header() {
252280
const [mounted, setMounted] = React.useState(false)
253281
const isMobile = useMediaQuery("(max-width: 768px)") // TODO: Adjust breakpoint

src/components/ui/navigation-menu.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import type * as React from "react"
55

66
import { cn } from "@/lib/utils"
77

8+
/**
9+
* Root wrapper for Radix NavigationMenu that applies shared styling, data attributes, and optionally renders a viewport.
10+
*
11+
* @param viewport - When `true` (default), renders the associated `NavigationMenuViewport` element; when `false`, omits the viewport.
12+
* @returns The rendered NavigationMenu root element with forwarded props.
13+
*/
814
function NavigationMenu({
915
className,
1016
children,
@@ -26,6 +32,12 @@ function NavigationMenu({
2632
)
2733
}
2834

35+
/**
36+
* Wraps Radix's `NavigationMenuPrimitive.List`, adding layout classes and a `data-slot` attribute while forwarding all other props.
37+
*
38+
* @param className - Additional class names to merge with the component's base layout classes
39+
* @returns The rendered `NavigationMenuPrimitive.List` element with merged classes and `data-slot="navigation-menu-list"`
40+
*/
2941
function NavigationMenuList({ className, ...props }: React.ComponentProps<typeof NavigationMenuPrimitive.List>) {
3042
return (
3143
<NavigationMenuPrimitive.List
@@ -36,6 +48,11 @@ function NavigationMenuList({ className, ...props }: React.ComponentProps<typeof
3648
)
3749
}
3850

51+
/**
52+
* Renders a NavigationMenu item wrapper that applies positioning and a `data-slot` attribute.
53+
*
54+
* @returns The wrapped `NavigationMenuPrimitive.Item` element with `data-slot="navigation-menu-item"` and merged `className` including `"relative"`.
55+
*/
3956
function NavigationMenuItem({ className, ...props }: React.ComponentProps<typeof NavigationMenuPrimitive.Item>) {
4057
return (
4158
<NavigationMenuPrimitive.Item data-slot="navigation-menu-item" className={cn("relative", className)} {...props} />
@@ -46,6 +63,13 @@ const navigationMenuTriggerStyle = cva(
4663
"group inline-flex h-9 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium text-text-primary transition-[color,box-shadow] outline-none hover:bg-grey focus:bg-grey focus-visible:ring-[3px] focus-visible:ring-text-primary/50 focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-grey/50 data-[state=open]:hover:bg-grey data-[state=open]:focus:bg-grey"
4764
)
4865

66+
/**
67+
* Renders a styled navigation menu trigger with a chevron icon.
68+
*
69+
* Renders a NavigationMenuPrimitive.Trigger element with preset styling, a `data-slot="navigation-menu-trigger"` attribute, and a down-pointing chevron that rotates when the trigger is open.
70+
*
71+
* @returns The rendered trigger element for the navigation menu.
72+
*/
4973
function NavigationMenuTrigger({
5074
className,
5175
children,
@@ -67,6 +91,12 @@ function NavigationMenuTrigger({
6791
)
6892
}
6993

94+
/**
95+
* Wraps Radix's `NavigationMenuPrimitive.Content`, applying layout, animation, and theme-related classes and forwarding all props.
96+
*
97+
* @param props - Props passed to the underlying `NavigationMenuPrimitive.Content`. The `className` prop, if provided, is merged with the component's internal classes.
98+
* @returns A `NavigationMenuPrimitive.Content` element with a `data-slot="navigation-menu-content"` attribute, merged classes, and forwarded props.
99+
*/
70100
function NavigationMenuContent({ className, ...props }: React.ComponentProps<typeof NavigationMenuPrimitive.Content>) {
71101
return (
72102
<NavigationMenuPrimitive.Content
@@ -81,6 +111,11 @@ function NavigationMenuContent({ className, ...props }: React.ComponentProps<typ
81111
)
82112
}
83113

114+
/**
115+
* Renders a centered, absolutely positioned container that hosts the NavigationMenu viewport.
116+
*
117+
* @returns A React element containing the Radix NavigationMenu viewport wrapped in an absolutely positioned, centered container.
118+
*/
84119
function NavigationMenuViewport({
85120
className,
86121
...props
@@ -99,6 +134,11 @@ function NavigationMenuViewport({
99134
)
100135
}
101136

137+
/**
138+
* Render a styled NavigationMenu link element with a consistent `data-slot` and utility classes.
139+
*
140+
* @returns A `NavigationMenuPrimitive.Link` element with base layout, typography, and state-aware styling; additional props are forwarded to the underlying element.
141+
*/
102142
function NavigationMenuLink({ className, ...props }: React.ComponentProps<typeof NavigationMenuPrimitive.Link>) {
103143
return (
104144
<NavigationMenuPrimitive.Link
@@ -112,6 +152,11 @@ function NavigationMenuLink({ className, ...props }: React.ComponentProps<typeof
112152
)
113153
}
114154

155+
/**
156+
* Renders the navigation menu indicator: an animated, diamond-shaped visual used to point to active menu content.
157+
*
158+
* @returns A NavigationMenuPrimitive.Indicator element containing the rotated square indicator.
159+
*/
115160
function NavigationMenuIndicator({
116161
className,
117162
...props

0 commit comments

Comments
 (0)