Skip to content

Commit dbaa316

Browse files
committed
Move snippet type input next to name control.
1 parent a3b29f2 commit dbaa316

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

src/css/edit.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@
8282
}
8383
}
8484

85+
.snippet-name-wrapper {
86+
display: flex;
87+
gap: 0.5em;
88+
89+
> :first-child {
90+
flex: 1;
91+
}
92+
}
93+
8594
form.condition-snippet .snippet-code-container {
8695
display: none;
8796
}

src/css/edit/_form.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $sidebar-gap: 30px;
1414
align-items: center;
1515
justify-content: space-between;
1616
flex-flow: row;
17+
gap: 2em;
1718

1819
.small-badge {
1920
margin-inline-start: 0.5em;

src/js/components/EditorSidebar/EditorSidebar.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export const EditorSidebar: React.FC<EditorSidebarProps> = ({ setIsUpgradeDialog
2727

2828
return (
2929
<div className="snippet-editor-sidebar">
30-
<SnippetTypeInput setIsUpgradeDialogOpen={setIsUpgradeDialogOpen} />
31-
3230
<div className="box">
3331
{snippet.id && !isCondition(snippet) ? <ActivationSwitch /> : null}
3432

src/js/components/SnippetForm/SnippetForm.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ConfirmDialog } from '../common/ConfirmDialog'
1212
import { UpsellDialog } from '../common/UpsellDialog'
1313
import { EditorSidebar } from '../EditorSidebar'
1414
import { UpsellBanner } from '../common/UpsellBanner'
15+
import { SnippetTypeInput } from './fields/SnippetTypeInput'
1516
import { TagsEditor } from './fields/TagsEditor'
1617
import { CodeEditor } from './fields/CodeEditor'
1718
import { DescriptionEditor } from './fields/DescriptionEditor'
@@ -158,7 +159,11 @@ const EditFormWrap: React.FC = () => {
158159

159160
<EditForm className={editFormClassName({ snippet, isReadOnly, isExpanded })}>
160161
<main className="snippet-form-upper">
161-
<NameInput />
162+
<div className="snippet-name-wrapper">
163+
<NameInput />
164+
<SnippetTypeInput setIsUpgradeDialogOpen={setIsUpgradeDialogOpen} />
165+
</div>
166+
162167
<CodeEditor {...{ isExpanded, setIsExpanded }} />
163168
<ConditionsEditor />
164169
</main>

src/js/components/SnippetForm/fields/SnippetTypeInput.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect } from 'react'
22
import classnames from 'classnames'
33
import { __, _x } from '@wordpress/i18n'
44
import Select from 'react-select'
5+
import type { FormatOptionLabelContext } from 'react-select'
56
import { useSnippetForm } from '../../../hooks/useSnippetForm'
67
import { SNIPPET_TYPE_SCOPES } from '../../../types/Snippet'
78
import { isLicensed } from '../../../utils/screen'
@@ -31,14 +32,21 @@ const OPTIONS: SelectOption<SnippetType>[] = [
3132
{ value: 'cond', label: __('Conditions', 'code-snippets') }
3233
]
3334

34-
const SnippetTypeOption: React.FC<SelectOption<SnippetType>> = ({ label, value }) =>
35+
interface SnippetTypeOptionProps {
36+
option: SelectOption<SnippetType>
37+
context: FormatOptionLabelContext
38+
}
39+
40+
const SnippetTypeOption: React.FC<SnippetTypeOptionProps> = ({ option: { value, label }, context }) =>
3541
<div className={classnames('snippet-type-option', { 'inverted-badges': isProType(value) && !isLicensed() })}>
36-
<div>
37-
{label}
38-
{isProType(value) && !isLicensed()
39-
? <span className="badge pro-badge small-badge">{_x('Pro', 'Upgrade to Pro', 'code-snippets')}</span>
40-
: null}
41-
</div>
42+
{'menu' === context
43+
? <div>
44+
{label}
45+
{isProType(value) && !isLicensed()
46+
? <Badge name="pro" small>{_x('Pro', 'Upgrade to Pro', 'code-snippets')}</Badge>
47+
: null}
48+
</div>
49+
: null}
4250
<Badge name={value} />
4351
</div>
4452

@@ -69,12 +77,19 @@ export const SnippetTypeInput: React.FC<SnippetTypeInputProps> = ({ setIsUpgrade
6977
className="code-snippets-select"
7078
isDisabled={isReadOnly}
7179
options={0 === snippet.id ? OPTIONS : OPTIONS.filter(option => 'cond' !== option.value)}
80+
menuPlacement="bottom"
7281
styles={{
73-
menu: provided => ({ ...provided, zIndex: 9999 }),
82+
menu: provided => ({
83+
...provided,
84+
zIndex: 9999,
85+
width: 'max-content',
86+
minWidth: '100%'
87+
}),
7488
input: provided => ({ ...provided, boxShadow: 'none' })
7589
}}
7690
value={OPTIONS.find(option => option.value === snippetType)}
77-
formatOptionLabel={SnippetTypeOption}
91+
formatOptionLabel={(data, meta) =>
92+
<SnippetTypeOption option={data} context={meta.context} />}
7893
onChange={option => {
7994
if (option && isProType(option.value) && !isLicensed()) {
8095
setIsUpgradeDialogOpen(true)

0 commit comments

Comments
 (0)