PluginProbe
Code Snippets / 3.10.1
Code Snippets v3.10.1
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 / Import / FromFileUpload / components / SnippetSelectionTable.tsx

SnippetSelectionTable.tsx in Code Snippets 3.10.1, at js/components/Import/FromFileUpload/components/SnippetSelectionTable.tsx

91 lines 2.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 { __ } from '@wordpress/i18n'
3 import type { ImportableSnippet } from '../../../../hooks/useFileUploadAPI'
4
5 interface SnippetSelectionTableProps {
6 snippets: ImportableSnippet[]
7 selectedSnippets: Set<number | string>
8 isAllSelected: boolean
9 onSnippetToggle: (snippetId: number | string) => void
10 onSelectAll: () => void
11 }
12
13 export const SnippetSelectionTable: React.FC<SnippetSelectionTableProps> = ({
14 snippets,
15 selectedSnippets,
16 isAllSelected,
17 onSnippetToggle,
18 onSelectAll
19 }) => {
20 const getTypeColor = (type: string): string => {
21 switch (type) {
22 case 'css': return '#9B59B6'
23 case 'js': return '#FFEB3B'
24 case 'html': return '#EF6A36'
25 default: return '#1D97C6'
26 }
27 }
28
29 const truncateDescription = (description: string | undefined): string => {
30 const desc = description || __('No description', 'code-snippets')
31 return desc.length > 50 ? desc.substring(0, 50) + '...' : desc
32 }
33
34 return (
35 <table className="wp-list-table widefat fixed striped" style={{ borderRadius: '5px', tableLayout: 'fixed' }}>
36 <thead>
37 <tr>
38 <th scope="col" className="check-column" style={{ padding: '8px 0', width: '40px' }}>
39 <input
40 type="checkbox"
41 checked={isAllSelected}
42 onChange={onSelectAll}
43 />
44 </th>
45 <th scope="col" style={{ width: '200px' }}>{__('Name', 'code-snippets')}</th>
46 <th scope="col" style={{ width: '90px', textAlign: 'center' }}>{__('Type', 'code-snippets')}</th>
47 <th scope="col" style={{ width: 'auto' }}>{__('Description', 'code-snippets')}</th>
48 <th scope="col" style={{ width: '120px' }}>{__('Tags', 'code-snippets')}</th>
49 </tr>
50 </thead>
51 <tbody>
52 {snippets.map(snippet => (
53 <tr key={snippet.table_data.id}>
54 <th scope="row" className="check-column">
55 <input
56 type="checkbox"
57 checked={selectedSnippets.has(snippet.table_data.id)}
58 onChange={() => onSnippetToggle(snippet.table_data.id)}
59 />
60 </th>
61 <td>
62 <strong>{snippet.table_data.title}</strong>
63 {snippet.source_file && (
64 <div style={{ fontSize: '12px', color: '#666', marginTop: '2px' }}>
65 from {snippet.source_file}
66 </div>
67 )}
68 </td>
69 <td style={{ width: '90px', textAlign: 'center' }}>
70 <span style={{
71 backgroundColor: getTypeColor(snippet.table_data.type),
72 color: 'white',
73 padding: '3px 6px',
74 fontSize: '10px',
75 textTransform: 'uppercase',
76 borderRadius: '3px'
77 }}>
78 {snippet.table_data.type}
79 </span>
80 </td>
81 <td>
82 {truncateDescription(snippet.table_data.description)}
83 </td>
84 <td>{snippet.table_data.tags || '—'}</td>
85 </tr>
86 ))}
87 </tbody>
88 </table>
89 )
90 }
91