PluginProbe
Code Snippets / 4.0.0-beta.1
Code Snippets v4.0.0-beta.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 / ImportMenu / MigrateForm / SimpleSnippetTable.tsx

SimpleSnippetTable.tsx in Code Snippets 4.0.0-beta.1, at js/components/ImportMenu/MigrateForm/SimpleSnippetTable.tsx

96 lines 2.9 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 { __, sprintf } from '@wordpress/i18n'
3 import { Button } from '../../common/Button'
4 import { ImportCard } from '../common/ImportCard'
5 import type { UseSelection } from '../../../hooks/useSelection'
6 import type { ImportableSnippet } from './WithMigrationData'
7
8 interface TableNavProps extends SimpleSnippetTableProps {
9 which: 'top' | 'bottom'
10 }
11
12 const TableNav: React.FC<TableNavProps> = ({ which, onImport, isImporting, selection }) =>
13 <div className={`tablenav ${which}`}>
14 <Button onClick={selection.selectAll}>
15 {selection.isAllSelected
16 ? __('Deselect All', 'code-snippets')
17 : __('Select All', 'code-snippets')}
18 </Button>
19
20 <Button
21 primary
22 onClick={onImport}
23 disabled={0 === selection.selectedItems.size || isImporting}
24 >
25 {isImporting
26 ? __('Importing…', 'code-snippets')
27 : sprintf(
28 // translators: %d: number of selected snippets.
29 __('Import Selected (%d)', 'code-snippets'),
30 selection.selectedItems.size
31 )}
32 </Button>
33 </div>
34
35 export interface SimpleSnippetTableProps {
36 selection: UseSelection<ImportableSnippet, number>
37 onImport: VoidFunction
38 isImporting: boolean
39 }
40
41 export const SimpleSnippetTable: React.FC<SimpleSnippetTableProps> = props => {
42 const { selection: { availableItems, selectedItems, selectAll, isAllSelected, toggleItem } } = props
43
44 return (
45 <ImportCard className="migrate-snippets-table-card snippets-table-card">
46 <header>
47 <h3>{sprintf(
48 // translators: %d: number of available snippets.
49 __('Available snippets (%d)', 'code-snippets'),
50 availableItems.length
51 )}</h3>
52 <p>{__('We found the following snippets:', 'code-snippets')}</p>
53 </header>
54
55 <TableNav which="top" {...props} />
56
57 <table className="wp-list-table widefat fixed striped">
58 <thead>
59 <tr>
60 <th scope="col" className="check-column">
61 <input
62 type="checkbox"
63 checked={isAllSelected}
64 onChange={selectAll}
65 aria-label={__('Select all snippets', 'code-snippets')}
66 />
67 </th>
68 <th scope="col" className="column-name">{__('Snippet name', 'code-snippets')}</th>
69 <th scope="col" className="column-id">{__('ID', 'code-snippets')}</th>
70 </tr>
71 </thead>
72 <tbody>
73 {availableItems.map(snippet =>
74 <tr key={snippet.table_data.id}>
75 <th scope="row" className="check-column">
76 <input
77 type="checkbox"
78 checked={selectedItems.has(snippet.table_data.id)}
79 onChange={() => toggleItem(snippet.table_data.id)}
80 aria-label={sprintf(
81 // translators: %s: snippet name.
82 __('Select %s', 'code-snippets'),
83 snippet.table_data.title
84 )}
85 />
86 </th>
87 <td className="column-name">{snippet.table_data.title}</td>
88 <td className="column-id">{snippet.table_data.id}</td>
89 </tr>)}
90 </tbody>
91 </table>
92 <TableNav which="bottom" {...props} />
93 </ImportCard>
94 )
95 }
96