mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem Prompt cards on /solutions/no-code caused horizontal page scroll on mobile. Flex/grid children don't shrink below content size by default, so long card titles and content pushed cards past the viewport width. ## Fix Added `min-w-0` to the card container and title in `TwoColumnsSection.tsx` so cards respect their grid/flex track width instead of growing with content. ## Screenshots | Before | After | |--------|-------| | <img src="https://github.com/user-attachments/assets/069fa434-c202-4761-ab25-0eaf5f71b434" width="300" /> | <img src="https://github.com/user-attachments/assets/2478bd84-1361-46e9-a076-4148b0c38706" width="300" /> | <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved code snippet layout in two-column sections by allowing the snippet container to shrink within its column. This helps prevent the container from forcing the surrounding layout wider when space is limited, keeping the section more consistent across narrow and wider layouts. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: hallidayo <22655069+Hallidayo@users.noreply.github.com> Co-authored-by: Nik Richers <nrichers@gmail.com>
118 lines
3.6 KiB
TypeScript
118 lines
3.6 KiB
TypeScript
import { ArrowUpRight, Check, Copy } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import React, { useState } from 'react'
|
|
import { Button, cn, FloatingPlate, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
import { TextLink } from 'ui-patterns/TextLink'
|
|
|
|
import SectionContainer from '@/components/Layouts/SectionContainer'
|
|
|
|
interface AIPrompt {
|
|
id: string
|
|
title: string
|
|
description?: string
|
|
code: string
|
|
language: string
|
|
docsUrl?: string
|
|
copyable?: boolean
|
|
}
|
|
|
|
export interface TwoColumnsSectionProps {
|
|
heading: string | React.ReactNode
|
|
subheading?: string
|
|
id?: string
|
|
docsUrl?: string
|
|
className?: string
|
|
aiPrompts: AIPrompt[]
|
|
leftFooter?: React.ReactNode
|
|
headingRight?: string | React.ReactNode
|
|
}
|
|
|
|
const CodeSnippet = ({ prompt }: { prompt: AIPrompt }) => {
|
|
const [text, setText] = useState('copy')
|
|
|
|
function updateCopyStatus() {
|
|
if (text === 'copy') {
|
|
setText(() => 'copied')
|
|
setTimeout(() => {
|
|
setText(() => 'copy')
|
|
}, 1000)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="relative group bg-surface-75 border border-default rounded-lg min-w-0">
|
|
<div className="flex items-center justify-between px-4 py-3 border-b border-default bg-surface-100">
|
|
<h3 className="text-sm text-foreground truncate">{prompt.title}</h3>
|
|
{prompt.docsUrl && (
|
|
<Link href={prompt.docsUrl} className="relative">
|
|
<ArrowUpRight className="w-4 h-4 not-sr-only stroke-1 opacity-80 transition-opacity group-hover:opacity-100" />
|
|
</Link>
|
|
)}
|
|
</div>
|
|
<div className="p-4 relative">
|
|
{prompt.copyable && (
|
|
<Tooltip>
|
|
<FloatingPlate className="absolute top-2 right-2">
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
className="text-foreground-light hover:text-foreground w-7 h-7 p-1 shadow-lg"
|
|
onClick={async () => {
|
|
await navigator.clipboard.writeText(prompt.code)
|
|
updateCopyStatus()
|
|
}}
|
|
>
|
|
{text === 'copy' ? <Copy className="w-3 h-3" /> : <Check className="w-3 h-3" />}
|
|
</Button>
|
|
</TooltipTrigger>
|
|
</FloatingPlate>
|
|
<TooltipContent>Copy to clipboard</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
<pre className="text-xs text-foreground-light whitespace-pre-wrap font-mono leading-relaxed line-clamp-4">
|
|
{prompt.code}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const TwoColumnsSection = ({
|
|
heading,
|
|
subheading,
|
|
docsUrl,
|
|
id,
|
|
className,
|
|
aiPrompts,
|
|
leftFooter,
|
|
headingRight,
|
|
}: TwoColumnsSectionProps) => {
|
|
return (
|
|
<SectionContainer id={id} className={cn('py-16 md:py-24', className)}>
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-12 lg:gap-16">
|
|
<div className="col-left space-y-6 lg:pr-10">
|
|
<h2 className="h2 text-foreground-lighter">{heading}</h2>
|
|
{subheading && <p className="text-foreground-light">{subheading}</p>}
|
|
{leftFooter && leftFooter}
|
|
</div>
|
|
|
|
<div className="col-right space-y-6">
|
|
{headingRight && <h2 className="h2 text-foreground-lighter max-w-sm">{headingRight}</h2>}
|
|
<div className="grid md:grid-cols-2 gap-2">
|
|
{aiPrompts.map((prompt) => (
|
|
<CodeSnippet key={prompt.id} prompt={prompt} />
|
|
))}
|
|
</div>
|
|
|
|
{docsUrl && (
|
|
<div className="pt-2">
|
|
<TextLink url={docsUrl} label="View all prompts" />
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</SectionContainer>
|
|
)
|
|
}
|
|
|
|
export default TwoColumnsSection
|