Skip to content

Commit 299e4c8

Browse files
authored
Refresh shadcn auth component comments (#262)
1 parent 2b2f9ab commit 299e4c8

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

.agents/skills/shadcn-ui/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ description: Use when adding or updating shadcn/ui or compatible registry compon
3131
4. Keep generated file structure intact.
3232
- Generated files are an exception to the repo's normal single-export preference
3333
- Multiple exports are allowed if the generator created them
34+
- Generated comments are allowed; keep them unless they conflict with repo-specific behavior or become misleading after follow-up edits
3435

3536
5. Make only minimal repo-specific follow-up changes.
3637
- Add missing dependencies to the target package's `package.json`
@@ -50,6 +51,7 @@ description: Use when adding or updating shadcn/ui or compatible registry compon
5051
- rename generated `packages/world/components/auth/auth.tsx` to `packages/world/components/auth/auth-router.tsx`, and update relevant names such as `Auth` / `AuthProps` to `AuthRouter` / `AuthRouterProps`; alias Better Auth UI's `AuthView` type as `BetterAuthView`
5152
- keep `packages/world/components/auth/auth-link.tsx` and `packages/world/components/auth/auth-provider.tsx`; adapt them to upstream changes when applicable
5253
- Add or update tests so coverage stays at 100%
54+
- Each generated source file should have its own corresponding test file; do not combine tests for multiple generated source files into one test file
5355

5456
6. Prefer bundled Radix over individual `@radix-ui/*` packages.
5557
- This repo uses the bundled `radix-ui` package

packages/world/components/auth/auth-router.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,23 @@ export type AuthRouterProps = {
1414
path?: string;
1515
socialLayout?: SocialLayout;
1616
socialPosition?: "top" | "bottom";
17+
/** @remarks `BetterAuthView` */
1718
view?: BetterAuthView;
1819
};
1920

21+
/**
22+
* Render the selected authentication view component.
23+
*
24+
* The view is determined by the explicit `view` prop or, if absent, resolved from `path` using the application's auth view paths.
25+
*
26+
* @param path - Route path used to resolve an auth view when `view` is not provided
27+
* @param socialLayout - Social layout to apply to the component
28+
* @param socialPosition - Social position to apply to the component
29+
* @param view - Explicit auth view to render
30+
* @returns The rendered authentication view element
31+
* @throws Error if neither `view` nor `path` is provided
32+
* @throws Error if the resolved view is not a valid auth view
33+
*/
2034
export function AuthRouter({
2135
className,
2236
view,

packages/world/components/ui/sidebar.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ function SidebarProvider({
7878
const isMobile = useIsMobile();
7979
const [openMobile, setOpenMobile] = React.useState(false);
8080

81+
// This is the internal state of the sidebar.
82+
// We use openProp and setOpenProp for control from outside the component.
8183
const [_open, _setOpen] = React.useState(() =>
8284
getStoredSidebarOpen(defaultOpen),
8385
);
@@ -96,10 +98,12 @@ function SidebarProvider({
9698
[setOpenProp, open],
9799
);
98100

101+
// Helper to toggle the sidebar.
99102
const toggleSidebar = React.useCallback(() => {
100103
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open);
101104
}, [isMobile, setOpen, setOpenMobile]);
102105

106+
// Adds a keyboard shortcut to toggle the sidebar.
103107
React.useEffect(() => {
104108
const handleKeyDown = (event: KeyboardEvent) => {
105109
if (
@@ -115,6 +119,8 @@ function SidebarProvider({
115119
return () => window.removeEventListener("keydown", handleKeyDown);
116120
}, [toggleSidebar]);
117121

122+
// We add a state so that we can do data-state="expanded" or "collapsed".
123+
// This makes it easier to style the sidebar with Tailwind classes.
118124
const state = open ? "expanded" : "collapsed";
119125

120126
const contextValue = React.useMemo<SidebarContextProps>(
@@ -218,6 +224,7 @@ function Sidebar({
218224
data-side={side}
219225
data-slot="sidebar"
220226
>
227+
{/* This is what handles the sidebar gap on desktop */}
221228
<div
222229
data-slot="sidebar-gap"
223230
className={cn(
@@ -234,6 +241,7 @@ function Sidebar({
234241
data-side={side}
235242
className={cn(
236243
"fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex",
244+
// Adjust the padding for floating and inset variants.
237245
variant === "floating" || variant === "inset"
238246
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
239247
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
@@ -590,6 +598,7 @@ function SidebarMenuSkeleton({
590598
}: React.ComponentProps<"div"> & {
591599
showIcon?: boolean;
592600
}) {
601+
// Random width between 50 to 90%.
593602
const [width] = React.useState(() => {
594603
return `${Math.floor(Math.random() * 40) + 50}%`;
595604
});

0 commit comments

Comments
 (0)