PluginProbe
Code Snippets / 3.10.2
Code Snippets v3.10.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / js / components / common / snippets / SnippetCard.tsx

SnippetCard.tsx in Code Snippets 3.10.2, at js/components/common/snippets/SnippetCard.tsx

61 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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