stack/docs/src/components/mdx/stack-container.tsx
Madison 0ab5fcc165
[Docs][UI] - Components pop-up dynamic-codeblock (#877)
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

Adds a dynamic popup codeblock on components pages for components that
have live examples with prop manipulation.

<img width="1253" height="298" alt="image"
src="https://github.com/user-attachments/assets/6d046c5f-77c1-4bec-98ed-fd0c2e347635"
/>


<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Adds a dynamic code block overlay feature to documentation pages,
enhancing code example interaction with new components, hooks, and
styling.
> 
>   - **Behavior**:
> - Adds `DynamicCodeblockOverlay` in `dynamic-code-block-overlay.tsx`
for interactive code display with syntax highlighting, copy,
expand/collapse, and close features.
> - Integrates `CodeOverlayProvider` and `useCodeOverlay` in
`use-code-overlay.tsx` to manage overlay state and behavior.
> - Updates `DocsLayout` in `docs.tsx` to include the code overlay in
the documentation layout.
>   - **Components**:
> - `DynamicCodeblock` in `dynamic-code-block.tsx` now supports overlay
mode with a floating "View Code" button.
> - `StackContainer` in `stack-container.tsx` updated for better layout
and styling.
>   - **Styling**:
> - Adds `stack-reset.css` for isolating stack component styles from
global styles.
> - Updates `stack-team-switcher.tsx` to use new styling and layout for
team switcher demos.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for 4ef6c67bd8. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>

----


<!-- ELLIPSIS_HIDDEN -->

<!-- RECURSEML_SUMMARY:START -->
## Review by RecurseML

_🔍 Review performed on
[8424c4d..9c860b3](8424c4d624...9c860b3067)_

 No bugs found, your code is sparkling clean

<details>
<summary> Files analyzed, no issues (5)</summary>

  • `docs/src/components/mdx/dynamic-code-block-overlay.tsx`
  • `docs/src/components/mdx/dynamic-code-block.tsx`
  • `docs/src/components/layouts/docs.tsx`
  • `docs/src/hooks/use-code-overlay.tsx`
  • `docs/src/components/stack-auth/stack-team-switcher.tsx`
</details>

<details>
<summary>⏭️ Files skipped (trigger manually) (2)</summary>

| Locations | Trigger Analysis |
|-----------|------------------|
`docs/src/components/mdx/stack-container.tsx` |
[![analyze](0af8763e3d/?repo_owner=stack-auth&repo_name=stack-auth&pr_number=877)
`docs/src/components/mdx/stack-reset.css` |
[![analyze](675653c9b4/?repo_owner=stack-auth&repo_name=stack-auth&pr_number=877)
</details>

[![Need help? Join our
Discord](https://img.shields.io/badge/Need%20help%3F%20Join%20our%20Discord-5865F2?style=plastic&logo=discord&logoColor=white)](https://discord.gg/n3SsVDAW6U)
<!-- RECURSEML_SUMMARY:END -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* New Features
* Interactive code overlay in docs with syntax-highlighted view,
copy-to-clipboard, expand/collapse, ESC-to-close, and floating “View
Code” trigger; responsive sizing and auto-open behavior.
* Adds overlay provider/hooks to control overlay state and exposes a
reusable overlay component and trigger.

* Refactor
* Integrates the overlay into DocsLayout and updates sidebar composition
without changing public APIs.

* Style
* Adjusts Stack layout/title positioning, adds scoped stack CSS reset,
and updates team-switcher demo wrappers.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
2025-09-10 01:54:20 -05:00

111 lines
2.9 KiB
TypeScript

'use client';
import { type ReactNode } from 'react';
import { cn } from '../../lib/cn';
export type StackContainerProps = {
/**
* Title for the container
*/
title?: string,
/**
* Container content
*/
children: ReactNode,
/**
* Color theme for the container (default: blue)
*/
color?: 'blue' | 'purple' | 'green' | 'amber',
/**
* Size variant for the container (default: medium)
*/
size?: 'small' | 'medium' | 'large' | 'xlarge' | 'full',
/**
* Additional CSS classes to apply to the container
*/
className?: string,
}
export function StackContainer({
title,
children,
color = 'blue',
size = 'medium',
className,
}: StackContainerProps) {
// Define color variants
const colorVariants = {
blue: {
border: 'border-blue-500/40 dark:border-blue-400/20',
title: 'text-blue-700 dark:text-blue-400',
label: 'text-blue-600/80 dark:text-blue-400/70'
},
purple: {
border: 'border-purple-500/40 dark:border-purple-400/20',
title: 'text-purple-700 dark:text-purple-400',
label: 'text-purple-600/80 dark:text-purple-400/70'
},
green: {
border: 'border-emerald-500/40 dark:border-emerald-400/20',
title: 'text-emerald-700 dark:text-emerald-400',
label: 'text-emerald-600/80 dark:text-emerald-400/70'
},
amber: {
border: 'border-amber-600/40 dark:border-amber-400/20',
title: 'text-amber-800 dark:text-amber-500',
label: 'text-amber-700/80 dark:text-amber-400/70'
}
};
// Define size variants
const sizeVariants = {
small: 'max-w-xs',
medium: 'max-w-md',
large: 'max-w-2xl',
xlarge: 'max-w-4xl',
full: 'max-w-full'
};
const colors = colorVariants[color];
const sizeClass = sizeVariants[size];
return (
<div className="flex justify-center w-full my-8">
<div
className={cn(
'relative overflow-hidden rounded-lg border border-dashed',
'bg-gray-200/90 dark:bg-slate-900/30',
'border-gray-700/80 dark:border-gray-600/40',
'w-full',
'shadow-sm',
colors.border,
sizeClass,
className
)}
>
{/* Component demo label */}
<div className="absolute top-0 right-0 px-2 py-1 text-xs font-medium rounded-bl-md bg-gray-200/90 dark:bg-slate-800/80 border-l border-b border-gray-400/60 dark:border-gray-600/40">
<span className={colors.label}>Component Demo</span>
</div>
<div className="relative p-6">
{title && (
<h3 className={cn("absolute top-4 left-1/2 transform -translate-x-1/2 text-sm font-medium", colors.title)}>
{title}
</h3>
)}
{/* Component renders naturally - no forced layout */}
<div className="relative z-10">
{children}
</div>
</div>
</div>
</div>
);
}