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 / ImportMenu / ImportMenu.tsx

ImportMenu.tsx in Code Snippets 3.10.2, at js/components/ImportMenu/ImportMenu.tsx

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useState } from 'react'
2 import classnames from 'classnames'
3 import { __, sprintf } from '@wordpress/i18n'
4 import { WithRestAPIContext } from '../../hooks/useRestAPI'
5 import { ScreenMetaSlot } from '../common/ScreenMetaSlot'
6 import { SubnavTabs, getTabFromQuery } from '../common/SubnavTabs'
7 import { Toolbar } from '../common/Toolbar'
8 import { UploadForm } from './UploadForm/UploadForm'
9 import { MigrateForm } from './MigrateForm/MigrateForm'
10 import type { SubnavTab} from '../common/SubnavTabs'
11 import type { ReactNode } from 'react'
12
13 const TAB_QUERY_PARAM = 'tab'
14
15 interface ImportMenuTab extends SubnavTab<'upload' | 'migrate'> {
16 content: ReactNode
17 }
18
19 const TABS: ImportMenuTab[] = [
20 {
21 name: 'upload',
22 label: __('Upload snippets', 'code-snippets'),
23 content: <UploadForm />
24 },
25 {
26 name: 'migrate',
27 label: __('Migrate from other plugins', 'code-snippets'),
28 content: <MigrateForm />
29 }
30 ]
31
32 export const ImportMenu: React.FC = () => {
33 const [currentTab, setCurrentTab] = useState<ImportMenuTab>(() => getTabFromQuery(TABS, TAB_QUERY_PARAM))
34
35 return (
36 <>
37 <Toolbar />
38
39 <SubnavTabs
40 className="import-type-nav"
41 ariaLabel={__('Import sources', 'code-snippets')}
42 tabs={TABS}
43 currentTab={currentTab}
44 queryParamName={TAB_QUERY_PARAM}
45 setCurrentTab={setCurrentTab}
46 />
47
48 <ScreenMetaSlot />
49
50 <div className="snippets-page-header">
51 <h1>{// translators: %s: label of the currently selected import tab.
52 sprintf(__('Import: %s', 'code-snippets'), currentTab.label)}</h1>
53 </div>
54
55 <hr className="wp-header-end" />
56
57 <WithRestAPIContext>
58 {TABS.map(tab =>
59 <div
60 key={tab.name}
61 className={classnames('import-snippets-section', { 'active-section': tab.name === currentTab.name })}
62 >
63 {tab.content}
64 </div>)}
65 </WithRestAPIContext>
66 </>
67 )
68 }
69