| 1 |
import React from 'react' |
| 2 |
import classnames from 'classnames' |
| 3 |
import type { ReactNode } from 'react' |
| 4 |
|
| 5 |
export interface SnippetCardProps { |
| 6 |
className?: string |
| 7 |
isSelected?: boolean |
| 8 |
onSelectedChange?: (isSelected: boolean) => void |
| 9 |
selectionLabel?: string |
| 10 |
footer?: ReactNode |
| 11 |
footerStatus?: ReactNode |
| 12 |
children: ReactNode |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Shared card chrome for displaying a snippet in a card grid: border, inner |
| 17 |
* padding, footer strip, and a top corner holding a selection checkbox for |
| 18 |
* bulk actions. |
| 19 |
* The footer is split into a status region at the inline start and an actions |
| 20 |
* region at the inline end; the status region is always rendered so actions |
| 21 |
* stay end-aligned even when no status is provided. Both cloud search results |
| 22 |
* and local snippet cards render inside this shell so the two views stay |
| 23 |
* visually consistent. |
| 24 |
*/ |
| 25 |
export const SnippetCard: React.FC<SnippetCardProps> = ({ |
| 26 |
className, |
| 27 |
isSelected = false, |
| 28 |
onSelectedChange, |
| 29 |
selectionLabel, |
| 30 |
footer, |
| 31 |
footerStatus, |
| 32 |
children |
| 33 |
}) => |
| 34 |
<li |
| 35 |
className={classnames('code-snippets-card', className, { |
| 36 |
'is-selectable': undefined !== onSelectedChange, |
| 37 |
'is-selected': undefined !== onSelectedChange && isSelected |
| 38 |
})} |
| 39 |
> |
| 40 |
{undefined !== onSelectedChange |
| 41 |
? <div className="snippet-card-corner"> |
| 42 |
<input |
| 43 |
type="checkbox" |
| 44 |
className="snippet-card-select" |
| 45 |
checked={isSelected} |
| 46 |
aria-label={selectionLabel} |
| 47 |
onChange={event => onSelectedChange(event.target.checked)} |
| 48 |
/> |
| 49 |
</div> |
| 50 |
: null} |
| 51 |
|
| 52 |
{children} |
| 53 |
|
| 54 |
{undefined !== footer || undefined !== footerStatus |
| 55 |
? <footer> |
| 56 |
<div className="snippet-card-footer-status">{footerStatus}</div> |
| 57 |
<div className="snippet-card-footer-actions">{footer}</div> |
| 58 |
</footer> |
| 59 |
: null} |
| 60 |
</li> |
| 61 |
|