| 1 |
import React from 'react' |
| 2 |
import classnames from 'classnames' |
| 3 |
import { __ } from '@wordpress/i18n' |
| 4 |
import { CardViewIcon } from './icons/CardViewIcon' |
| 5 |
import { TableViewIcon } from './icons/TableViewIcon' |
| 6 |
import type { SnippetView } from '../../types/SnippetView' |
| 7 |
|
| 8 |
export interface SnippetViewToggleProps { |
| 9 |
snippetView: SnippetView |
| 10 |
setSnippetView: (view: SnippetView) => void |
| 11 |
className?: string |
| 12 |
} |
| 13 |
|
| 14 |
export const SnippetViewToggle: React.FC<SnippetViewToggleProps> = ({ snippetView, setSnippetView, className }) => |
| 15 |
<div |
| 16 |
className={classnames('snippet-view-toggle', className)} |
| 17 |
role="group" |
| 18 |
aria-label={__('Snippet view', 'code-snippets')} |
| 19 |
> |
| 20 |
<button |
| 21 |
type="button" |
| 22 |
className={classnames('snippet-view-toggle-option', { 'active-view': 'card' === snippetView })} |
| 23 |
aria-pressed={'card' === snippetView} |
| 24 |
title={__('Switch to card view', 'code-snippets')} |
| 25 |
onClick={() => setSnippetView('card')} |
| 26 |
> |
| 27 |
<CardViewIcon aria-hidden="true" /> |
| 28 |
<span className="screen-reader-text">{__('Card view', 'code-snippets')}</span> |
| 29 |
</button> |
| 30 |
|
| 31 |
<button |
| 32 |
type="button" |
| 33 |
className={classnames('snippet-view-toggle-option', { 'active-view': 'table' === snippetView })} |
| 34 |
aria-pressed={'table' === snippetView} |
| 35 |
title={__('Switch to table view', 'code-snippets')} |
| 36 |
onClick={() => setSnippetView('table')} |
| 37 |
> |
| 38 |
<TableViewIcon aria-hidden="true" /> |
| 39 |
<span className="screen-reader-text">{__('Table view', 'code-snippets')}</span> |
| 40 |
</button> |
| 41 |
</div> |
| 42 |
|