← All changes
|
js/components/EditMenu/SnippetForm/fields/SnippetLocationInput.tsx
+3
-33
3.10.2
→
4.0.0-beta.2
View file →
| @@ -2,42 +2,12 @@ | ||
| 2 | 2 | import React, { useId } from 'react' |
| 3 | 3 | import Select from 'react-select' |
| 4 | 4 | import { useSnippetForm } from '../WithSnippetFormContext' |
| 5 | 5 | import { SNIPPET_TYPE_SCOPES } from '../../../../types/Snippet' |
| 6 | -import { getSnippetType, isCondition } from '../../../../utils/snippets/snippets' | |
| 6 | +import { SNIPPET_SCOPE_DESCRIPTIONS, SNIPPET_SCOPE_ICONS, getSnippetType, isCondition } from '../../../../utils/snippets/snippets' | |
| 7 | 7 | import type { SnippetCodeScope } from '../../../../types/Snippet' |
| 8 | 8 | import type { SelectOption } from '../../../../types/SelectOption' |
| 9 | 9 | |
| 10 | -const SCOPE_ICONS: Record<SnippetCodeScope, string> = { | |
| 11 | - 'global': 'admin-site', | |
| 12 | - 'admin': 'admin-tools', | |
| 13 | - 'front-end': 'admin-appearance', | |
| 14 | - 'single-use': 'clock', | |
| 15 | - 'content': 'shortcode', | |
| 16 | - 'head-content': 'editor-code', | |
| 17 | - 'body-content': 'editor-code', | |
| 18 | - 'footer-content': 'editor-code', | |
| 19 | - 'admin-css': 'dashboard', | |
| 20 | - 'site-css': 'admin-customizer', | |
| 21 | - 'site-head-js': 'media-code', | |
| 22 | - 'site-footer-js': 'media-code' | |
| 23 | -} | |
| 24 | - | |
| 25 | -const SCOPE_DESCRIPTIONS: Record<SnippetCodeScope, string> = { | |
| 26 | - 'global': __('Run everywhere', 'code-snippets'), | |
| 27 | - 'admin': __('Only run in administration area', 'code-snippets'), | |
| 28 | - 'front-end': __('Only run on site front-end', 'code-snippets'), | |
| 29 | - 'single-use': __('Only run once', 'code-snippets'), | |
| 30 | - 'content': __('Where inserted in editor', 'code-snippets'), | |
| 31 | - 'head-content': __('In site header (<head> section)', 'code-snippets'), | |
| 32 | - 'body-content': __('In site content (start of <body>)', 'code-snippets'), | |
| 33 | - 'footer-content': __('In site footer (end of <body>)', 'code-snippets'), | |
| 34 | - 'site-css': __('Site front-end', 'code-snippets'), | |
| 35 | - 'admin-css': __('Administration area', 'code-snippets'), | |
| 36 | - 'site-head-js': __('In site header (<head> section)', 'code-snippets'), | |
| 37 | - 'site-footer-js': __('In site footer (end of <body>)', 'code-snippets') | |
| 38 | -} | |
| 39 | - | |
| 40 | 10 | export const SnippetLocationInput: React.FC = () => { |
| 41 | 11 | const { snippet, setSnippet, isReadOnly } = useSnippetForm() |
| 42 | 12 | const locationId = useId() |
| 43 | 13 | |
| @@ -45,9 +15,9 @@ | ||
| 45 | 15 | .filter(scope => 'condition' !== scope) |
| 46 | 16 | .map(scope => ({ |
| 47 | 17 | key: scope, |
| 48 | 18 | value: scope, |
| 49 | - label: SCOPE_DESCRIPTIONS[scope] | |
| 19 | + label: SNIPPET_SCOPE_DESCRIPTIONS[scope] | |
| 50 | 20 | })) |
| 51 | 21 | |
| 52 | 22 | return isCondition(snippet) |
| 53 | 23 | ? null |
| @@ -68,9 +38,9 @@ | ||
| 68 | 38 | }} |
| 69 | 39 | value={options.find(option => option.value === snippet.scope)} |
| 70 | 40 | formatOptionLabel={({ label, value }) => |
| 71 | 41 | <> |
| 72 | - <span className={`dashicons dashicons-${SCOPE_ICONS[value]}`} aria-hidden="true"></span>{` ${label}`} | |
| 42 | + <span className={`dashicons dashicons-${SNIPPET_SCOPE_ICONS[value]}`} aria-hidden="true"></span>{` ${label}`} | |
| 73 | 43 | </> |
| 74 | 44 | } |
| 75 | 45 | onChange={option => |
| 76 | 46 | option?.value && setSnippet(previous => ({ ...previous, scope: option.value }))} |