-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add PreviewCard component #663
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
Open
rohanchkrabrty
wants to merge
2
commits into
main
Choose a base branch
from
feat-preview-card
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
apps/www/src/components/playground/preview-card-examples.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| 'use client'; | ||
|
|
||
| import { Flex, PreviewCard, Text } from '@raystack/apsara'; | ||
| import PlaygroundLayout from './playground-layout'; | ||
|
|
||
| const placeholderStyle = { | ||
| width: 200, | ||
| height: 120, | ||
| borderRadius: 'var(--rs-radius-2)', | ||
| backgroundColor: 'var(--rs-color-background-base-secondary)' | ||
| }; | ||
|
|
||
| export function PreviewCardExamples() { | ||
| return ( | ||
| <PlaygroundLayout title='PreviewCard'> | ||
| <Flex gap='medium' wrap='wrap'> | ||
| <PreviewCard> | ||
| <PreviewCard.Trigger href='#'> | ||
| Hover to preview (bottom) | ||
| </PreviewCard.Trigger> | ||
| <PreviewCard.Content side='bottom'> | ||
| <Flex direction='column' gap='small'> | ||
| <div style={placeholderStyle} /> | ||
| <Text size='2'>Content appears below the trigger</Text> | ||
| </Flex> | ||
| </PreviewCard.Content> | ||
| </PreviewCard> | ||
| <PreviewCard> | ||
| <PreviewCard.Trigger href='#'> | ||
| Hover to preview (top) | ||
| </PreviewCard.Trigger> | ||
| <PreviewCard.Content side='top'> | ||
| <Flex direction='column' gap='small'> | ||
| <div style={placeholderStyle} /> | ||
| <Text size='2'>Content appears above the trigger</Text> | ||
| </Flex> | ||
| </PreviewCard.Content> | ||
| </PreviewCard> | ||
| <PreviewCard> | ||
| <PreviewCard.Trigger href='#'>Hover with arrow</PreviewCard.Trigger> | ||
| <PreviewCard.Content showArrow> | ||
| <Flex direction='column' gap='small'> | ||
| <div style={placeholderStyle} /> | ||
| <Text size='2'>Preview content with an arrow indicator</Text> | ||
| </Flex> | ||
| </PreviewCard.Content> | ||
| </PreviewCard> | ||
| </Flex> | ||
| </PlaygroundLayout> | ||
| ); | ||
| } |
170 changes: 170 additions & 0 deletions
170
apps/www/src/content/docs/components/preview-card/demo.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| 'use client'; | ||
|
|
||
| import { getPropsString } from '@/lib/utils'; | ||
|
|
||
| const PLACEHOLDER = `<div style={{ width: 200, height: 120, borderRadius: "var(--rs-radius-2)", backgroundColor: "var(--rs-color-background-accent-primary)" }} />`; | ||
|
|
||
| export const getCode = (props: any) => { | ||
| const { children, ...rest } = props; | ||
| return ` | ||
| <PreviewCard> | ||
| <PreviewCard.Trigger href="#">Hover to preview</PreviewCard.Trigger> | ||
| <PreviewCard.Content${getPropsString(rest)}> | ||
| <Flex direction="column" gap="small"> | ||
| ${PLACEHOLDER} | ||
| <Text size="2">${children}</Text> | ||
| </Flex> | ||
| </PreviewCard.Content> | ||
| </PreviewCard>`; | ||
| }; | ||
|
|
||
| export const playground = { | ||
| type: 'playground', | ||
| controls: { | ||
| align: { | ||
| type: 'select', | ||
| options: ['start', 'center', 'end'], | ||
| defaultValue: 'center' | ||
| }, | ||
| side: { | ||
| type: 'select', | ||
| options: ['top', 'right', 'bottom', 'left'], | ||
| defaultValue: 'bottom' | ||
| }, | ||
| sideOffset: { type: 'number', min: 0, defaultValue: 4 }, | ||
| showArrow: { type: 'checkbox', defaultValue: false }, | ||
| children: { | ||
| type: 'text', | ||
| initialValue: 'This is the preview card content.' | ||
| } | ||
| }, | ||
| getCode | ||
| }; | ||
|
|
||
| export const arrowDemo = { | ||
| type: 'code', | ||
| code: ` | ||
| <PreviewCard> | ||
| <PreviewCard.Trigger href="#">Hover to preview</PreviewCard.Trigger> | ||
| <PreviewCard.Content showArrow> | ||
| <Flex direction="column" gap="small"> | ||
| ${PLACEHOLDER} | ||
| <Text size="2">Preview content with an arrow indicator</Text> | ||
| </Flex> | ||
| </PreviewCard.Content> | ||
| </PreviewCard>` | ||
| }; | ||
|
|
||
| export const contentTransitionsDemo = { | ||
| type: 'code', | ||
| code: `function ContentTransitionsExample() { | ||
| const handle = PreviewCard.createHandle(); | ||
| const pages = { | ||
| "page-a": { | ||
| color: "var(--rs-color-background-accent-primary)", | ||
| title: "Getting Started", | ||
| description: "Learn the basics of the design system.", | ||
| }, | ||
| "page-b": { | ||
| color: "var(--rs-color-background-success-primary)", | ||
| title: "Components", | ||
| description: "Explore the full component library with interactive examples and detailed API documentation.", | ||
| }, | ||
| "page-c": { | ||
| color: "var(--rs-color-background-attention-primary)", | ||
| title: "Theming", | ||
| description: "Customize colors, typography, and spacing to match your brand. Includes dark mode support and CSS variable overrides.", | ||
| }, | ||
| }; | ||
|
|
||
| return ( | ||
| <Flex gap="medium"> | ||
| <PreviewCard.Trigger handle={handle} payload="page-a" href="#"> | ||
| Page A | ||
| </PreviewCard.Trigger> | ||
| <PreviewCard.Trigger handle={handle} payload="page-b" href="#"> | ||
| Page B | ||
| </PreviewCard.Trigger> | ||
| <PreviewCard.Trigger handle={handle} payload="page-c" href="#"> | ||
| Page C | ||
| </PreviewCard.Trigger> | ||
|
|
||
| <PreviewCard handle={handle}> | ||
| {({payload}) => { | ||
| const page = pages[payload]; | ||
| if (!page) return null; | ||
| return ( | ||
| <PreviewCard.Content style={{ maxWidth: 240 }}> | ||
| <PreviewCard.Viewport> | ||
| <Flex direction="column" gap="small"> | ||
| <div style={{ width: "100%", height: 120, borderRadius: "var(--rs-radius-2)", backgroundColor: page.color, padding: "var(--rs-space-4)" }} /> | ||
| <Text size="2" weight="medium">{page.title}</Text> | ||
| <Text size="1">{page.description}</Text> | ||
| </Flex> | ||
| </PreviewCard.Viewport> | ||
| </PreviewCard.Content> | ||
| ); | ||
| }} | ||
| </PreviewCard> | ||
| </Flex> | ||
| ); | ||
| }` | ||
| }; | ||
|
|
||
| export const positionDemo = { | ||
| type: 'code', | ||
| tabs: [ | ||
| { | ||
| name: 'Top', | ||
| code: ` | ||
| <PreviewCard> | ||
| <PreviewCard.Trigger href="#">Hover me</PreviewCard.Trigger> | ||
| <PreviewCard.Content side="top"> | ||
| <Flex direction="column" gap="small"> | ||
| ${PLACEHOLDER} | ||
| <Text size="2">Content appears above the trigger</Text> | ||
| </Flex> | ||
| </PreviewCard.Content> | ||
| </PreviewCard>` | ||
| }, | ||
| { | ||
| name: 'Right', | ||
| code: ` | ||
| <PreviewCard> | ||
| <PreviewCard.Trigger href="#">Hover me</PreviewCard.Trigger> | ||
| <PreviewCard.Content side="right"> | ||
| <Flex direction="column" gap="small"> | ||
| ${PLACEHOLDER} | ||
| <Text size="2">Content appears to the right</Text> | ||
| </Flex> | ||
| </PreviewCard.Content> | ||
| </PreviewCard>` | ||
| }, | ||
| { | ||
| name: 'Bottom', | ||
| code: ` | ||
| <PreviewCard> | ||
| <PreviewCard.Trigger href="#">Hover me</PreviewCard.Trigger> | ||
| <PreviewCard.Content side="bottom"> | ||
| <Flex direction="column" gap="small"> | ||
| ${PLACEHOLDER} | ||
| <Text size="2">Content appears below the trigger</Text> | ||
| </Flex> | ||
| </PreviewCard.Content> | ||
| </PreviewCard>` | ||
| }, | ||
| { | ||
| name: 'Left', | ||
| code: ` | ||
| <PreviewCard> | ||
| <PreviewCard.Trigger href="#">Hover me</PreviewCard.Trigger> | ||
| <PreviewCard.Content side="left"> | ||
| <Flex direction="column" gap="small"> | ||
| ${PLACEHOLDER} | ||
| <Text size="2">Content appears to the left</Text> | ||
| </Flex> | ||
| </PreviewCard.Content> | ||
| </PreviewCard>` | ||
| } | ||
| ] | ||
| }; |
78 changes: 78 additions & 0 deletions
78
apps/www/src/content/docs/components/preview-card/index.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| --- | ||
| title: PreviewCard | ||
| description: A popup that appears when a link is hovered, showing a preview for sighted users. | ||
| source: packages/raystack/components/preview-card | ||
| tag: new | ||
| --- | ||
|
|
||
| import { playground, arrowDemo, positionDemo, contentTransitionsDemo } from "./demo.ts"; | ||
|
|
||
| <Demo data={playground} /> | ||
|
|
||
| ## Anatomy | ||
|
|
||
| Import and assemble the component: | ||
|
|
||
| ```tsx | ||
| import { PreviewCard } from "@raystack/apsara"; | ||
|
|
||
| <PreviewCard> | ||
| <PreviewCard.Trigger href="/some-url">Hover me</PreviewCard.Trigger> | ||
| <PreviewCard.Content> | ||
| Preview content here | ||
| </PreviewCard.Content> | ||
| </PreviewCard> | ||
| ``` | ||
|
|
||
| ## API Reference | ||
|
|
||
| ### Root | ||
|
|
||
| Groups all parts of the preview card. | ||
|
|
||
| <auto-type-table path="./props.ts" name="PreviewCardRootProps" /> | ||
|
|
||
| ### Trigger | ||
|
|
||
| A link element that opens the preview card on hover. Renders an `<a>` tag. | ||
|
|
||
| <auto-type-table path="./props.ts" name="PreviewCardTriggerProps" /> | ||
|
|
||
| ### Content | ||
|
|
||
| Renders the preview card content panel, wrapping Portal, Positioner, and Popup internally. | ||
|
|
||
| <auto-type-table path="./props.ts" name="PreviewCardContentProps" /> | ||
|
|
||
| ### Viewport | ||
|
|
||
| Optional wrapper for animating content transitions when multiple triggers share one card via `createHandle`. Provides direction-aware slide animations. | ||
|
|
||
| <auto-type-table path="./props.ts" name="PreviewCardViewportProps" /> | ||
|
|
||
| ## Examples | ||
|
|
||
| ### With Arrow | ||
|
|
||
| Display an arrow pointing to the trigger element. | ||
|
|
||
| <Demo data={arrowDemo} /> | ||
|
|
||
| ### Content Transitions | ||
|
|
||
| When multiple triggers share one card via `createHandle`, wrap content in `Viewport` to animate transitions between them. Content slides in from the direction of the newly hovered trigger. | ||
|
|
||
| <Demo data={contentTransitionsDemo} /> | ||
|
|
||
| ### Positioning | ||
|
|
||
| Control the position of the preview card relative to its trigger. | ||
|
|
||
| <Demo data={positionDemo} /> | ||
|
|
||
| ## Accessibility | ||
|
|
||
| - Opens on hover with configurable delay (default 600ms) | ||
| - Closes when the pointer leaves the trigger or content area | ||
| - Content is accessible to screen readers when open | ||
| - Trigger renders as a semantic `<a>` element |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: raystack/apsara
Length of output: 1524
🏁 Script executed:
Repository: raystack/apsara
Length of output: 7843
🏁 Script executed:
Repository: raystack/apsara
Length of output: 334
🏁 Script executed:
Repository: raystack/apsara
Length of output: 2513
Routing bug in Content component template: merged Popup props are incorrectly spread into Positioner.
Lines 118–176 merge Positioner and Popup props at the interface level but fail to route them correctly. The template destructures only
className,style,renderexplicitly and spreads all remaining props via...positionerPropsintoPositioner. This means any additional Popup-specific props (likeinitialFocus,finalFocus, or others) either get dropped or incorrectly routed toPositioner.Real implementations (popover.tsx, tooltip-content.tsx, preview-card.tsx) follow this pattern. popover.tsx works around it by explicitly destructuring Popup-specific props, but tooltip-content.tsx and preview-card.tsx silently drop unhandled Popup props. The guidance should separate prop concerns:
🤖 Prompt for AI Agents