Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,49 @@ export const SnippetSelectionTable: React.FC<SnippetSelectionTableProps> = ({
snippets,
selection: { selectedItems, isAllSelected, toggleItem, selectAll }
}) =>
<>
<table className="wp-list-table widefat fixed striped">
<thead>
<tr>
<th scope="col" className="check-column">
<input type="checkbox" checked={isAllSelected} onChange={selectAll} />
<table className="wp-list-table widefat fixed striped">
<thead>
<tr>
<th scope="col" className="check-column">
<label htmlFor="cb-select-all-head">
<span className="screen-reader-text">{__('Select all snippets', 'code-snippets')}</span>
</label>
<input id="cb-select-all-head" type="checkbox" checked={isAllSelected} onChange={selectAll} />
</th>
<th scope="col" className="column-name">{__('Name', 'code-snippets')}</th>
<th scope="col" className="column-type">{__('Type', 'code-snippets')}</th>
<th scope="col" className="column-desc">{__('Description', 'code-snippets')}</th>
<th scope="col" className="column-tags">{__('Tags', 'code-snippets')}</th>
</tr>
</thead>
<tbody>
{snippets.map(snippet =>
<tr key={snippet.table_data.id} className={`${snippet.table_data.type}-snippet`}>
<th scope="row" className="check-column">
<label htmlFor={`cb-select-${snippet.table_data.id}`}>
<span className="screen-reader-text">{__('Select snippet', 'code-snippets')}</span>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe “Select snippet: {title}”?

</label>
<input
id={`cb-select-${snippet.table_data.id}`}
type="checkbox"
checked={selectedItems.has(snippet.table_data.id)}
onChange={() => toggleItem(snippet.table_data.id)}
/>
</th>
<th scope="col" className="column-name">{__('Name', 'code-snippets')}</th>
<th scope="col" className="column-type">{__('Type', 'code-snippets')}</th>
<th scope="col" className="column-desc">{__('Description', 'code-snippets')}</th>
<th scope="col" className="column-tags">{__('Tags', 'code-snippets')}</th>
<td className="column-name">
<strong>{snippet.table_data.title}</strong>
{snippet.source_file && <div>
{sprintf(
// translators: %s: source file name.
_x('from %s', 'import snippet source file', 'code-snippets'),
snippet.source_file
)}
</div>}
</td>
<td className="column-type"><span>{snippet.table_data.type}</span></td>
<td className="column-desc">{truncateDescription(snippet.table_data.description)}</td>
<td className="column-tags">{snippet.table_data.tags || '—'}</td>
</tr>
</thead>
<tbody>
{snippets.map(snippet =>
<tr key={snippet.table_data.id} className={`${snippet.table_data.type}-snippet`}>
<th scope="row" className="check-column">
<input
type="checkbox"
checked={selectedItems.has(snippet.table_data.id)}
onChange={() => toggleItem(snippet.table_data.id)}
/>
</th>
<td className="column-name">
<strong>{snippet.table_data.title}</strong>
{snippet.source_file && <div>
{sprintf(
// translators: %s: source file name.
_x('from %s', 'import snippet source file', 'code-snippets'),
snippet.source_file
)}
</div>}
</td>
<td className="column-type"><span>{snippet.table_data.type}</span></td>
<td className="column-desc">{truncateDescription(snippet.table_data.description)}</td>
<td className="column-tags">{snippet.table_data.tags || '—'}</td>
</tr>
)}
</tbody>
</table>
</>
)}
</tbody>
</table>
5 changes: 5 additions & 0 deletions src/js/components/common/ListTable/TableItems.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import classnames from 'classnames'
import { __ } from '@wordpress/i18n'
import type { Dispatch, Key, SetStateAction } from 'react'
import type { ListTableColumn, ListTableItemsProps } from './ListTable'

Expand All @@ -10,7 +11,11 @@ interface CheckboxCellProps<T, K extends Key> extends Pick<TableItemsProps<T, K>

const CheckboxCell = <T, K extends Key>({ item, setSelected, getKey }: CheckboxCellProps<T, K>) =>
<th scope="row" className="check-column">
<label htmlFor={`cb-select-${getKey(item)}`}>
<span className="screen-reader-text">{__('Select snippet', 'code-snippets')}</span>
</label>
<input
id={`cb-select-${getKey(item)}`}
type="checkbox"
name="checked[]"
onChange={event => {
Expand Down
Loading