Skip to content

Commit 9b97e47

Browse files
committed
Move dropdowns from above snippet editor to sidebar.
1 parent bad9c8c commit 9b97e47

File tree

14 files changed

+124
-121
lines changed

14 files changed

+124
-121
lines changed

src/css/common/_upsell.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
padding: 12px;
99
gap: 10px;
1010
background: #fff;
11-
border: 1px solid #c3c4c7;
11+
border: 1px solid #ccc;
1212
border-radius: 5px;
1313

1414
p {

src/css/edit.scss

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,27 @@
4848
}
4949
}
5050

51+
#titlediv,
52+
.snippet-type-container {
53+
margin-block-end: 24px;
54+
}
55+
5156
.above-snippet-code {
57+
margin-block: 0 15px;
5258
display: flex;
5359
align-items: center;
54-
margin-block: 25px 15px;
5560
margin-inline: 0;
5661
gap: 8px;
5762

5863
h2 {
5964
margin: 0;
60-
margin-inline-end: auto;
6165
}
6266

6367
.expand-editor-button {
6468
display: flex;
6569
gap: 5px;
6670
align-items: center;
71+
margin-inline-end: auto;
6772

6873
.dashicons {
6974
inline-size: 18px;

src/css/edit/_form.scss

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
@use '../common/theme';
22

3-
$sidebar-width: 280px;
3+
$sidebar-width: 321px;
44
$sidebar-gap: 30px;
55

6+
.snippet-form #titlediv #title,
7+
.snippet-type-container {
8+
border-color: #ccc;
9+
block-size: 45px
10+
}
11+
612
.snippet-type-option {
713
display: flex;
814
align-items: center;
@@ -19,52 +25,39 @@ $sidebar-gap: 30px;
1925
}
2026

2127

22-
.conditions-editor-open .button.button-large {
23-
font-weight: bold;
24-
block-size: 100%;
25-
display: flex;
26-
align-items: center;
27-
min-block-size: 45px;
28-
gap: 5px;
29-
overflow: hidden;
30-
31-
&.no-condition {
28+
.conditions-editor-open {
29+
.button.button-large {
30+
block-size: 100%;
31+
display: flex;
32+
align-items: center;
33+
gap: 8px;
34+
overflow: hidden;
3235
border-color: #ccc;
33-
background-color: #fff;;
34-
}
36+
padding-block: 6px;
37+
padding-inline: 12px;
3538

36-
.badge {
37-
margin-block: 3px;
38-
margin-inline: 0;
39-
}
40-
41-
.beta-badge {
42-
margin-inline-start: auto;
43-
border: 1px solid currentcolor;
39+
.pro-badge {
40+
margin-inline-start: auto;
41+
}
4442
}
4543

46-
.pro-badge {
47-
color: currentcolor;
48-
border: 1px solid currentcolor;
44+
&.no-condition .cond-badge {
4945
background: transparent;
50-
51-
@media screen and (width >= 1080px) and (width <= 1250px) {
52-
display: none;
53-
}
46+
color: inherit;
47+
border: 1px solid currentcolor;
5448
}
5549
}
5650

5751
.snippet-form {
5852
margin-block-start: 10px;
59-
max-inline-size: 1440px;
6053
display: grid;
6154
gap: $sidebar-gap;
6255
grid-template-columns: 1fr $sidebar-width;
63-
grid-template-areas: "upper sidebar" "lower sidebar";
56+
grid-template-areas: 'upper sidebar' 'lower sidebar';
6457
transition: all 700ms;
6558

6659
&.snippet-form-expanded {
67-
grid-template-areas: "upper upper" "lower sidebar";
60+
grid-template-areas: 'upper upper' 'lower sidebar';
6861
}
6962

7063
.snippet-form-upper {
@@ -76,18 +69,14 @@ $sidebar-gap: 30px;
7669
}
7770

7871
.snippet-editor-sidebar {
79-
grid-area: sidebar;
72+
grid-area: span 3 / sidebar;
8073
max-inline-size: $sidebar-width;
8174
}
8275

8376
@media (width <= 1024px) {
8477
grid-template-columns: 1fr;
8578
}
8679

87-
#titlediv #title {
88-
block-size: 45px
89-
}
90-
9180
h2, h3 {
9281
margin-block: 25px 15px;
9382
margin-inline: 0;
@@ -102,16 +91,3 @@ $sidebar-gap: 30px;
10291
}
10392
}
10493
}
105-
106-
.above-editor-container {
107-
display: flex;
108-
flex-flow: row wrap;
109-
gap: 1em;
110-
111-
> * {
112-
flex: 1;
113-
display: flex;
114-
flex-flow: column;
115-
min-inline-size: 180px;
116-
}
117-
}

src/css/edit/_sidebar.scss

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use '../common/theme';
2+
13
.snippet-editor-sidebar {
24
.button-large {
35
block-size: 48px;
@@ -44,7 +46,7 @@
4446
margin-inline: 0;
4547
}
4648

47-
> div {
49+
.inline-form-field {
4850
display: flex;
4951
flex-flow: row wrap;
5052
align-items: center;
@@ -54,6 +56,29 @@
5456
margin-inline-start: auto;
5557
}
5658
}
59+
60+
.block-form-field {
61+
display: flex;
62+
flex-flow: column;
63+
gap: 4px;
64+
65+
h4 {
66+
margin-block-end: 0;
67+
}
68+
}
69+
}
70+
71+
h4 .badge {
72+
float: inline-end;
73+
74+
+ .badge {
75+
margin-inline-end: 5px;
76+
}
77+
}
78+
79+
.beta-badge {
80+
color: theme.$accent;
81+
border: 1px solid currentcolor;
5782
}
5883

5984
.components-form-token-field {

src/js/components/ConditionModal/ConditionModalButton.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import classnames from 'classnames'
33
import { __ } from '@wordpress/i18n'
44
import { isLicensed } from '../../utils/screen'
55
import { isCondition } from '../../utils/snippets/snippets'
6+
import { Badge } from '../common/Badge'
67
import { Button } from '../common/Button'
78
import { useSnippetForm } from '../../hooks/useSnippetForm'
89
import type { Dispatch, SetStateAction } from 'react'
@@ -17,24 +18,20 @@ export const ConditionModalButton: React.FC<ConditionModalButtonProps> = ({ setI
1718
const hasCondition = 0 !== snippet.conditionId
1819

1920
return (
20-
<div className={classnames('conditions-editor-open', hasCondition ? 'has-condition' : 'no-condition')}>
21+
<div className={classnames('conditions-editor-open block-form-field', hasCondition ? 'has-condition' : 'no-condition')}>
2122
{isCondition(snippet) ? null
2223
: <>
23-
<h3>{__('Conditions', 'code-snippets')}</h3>
24+
<h4>
25+
{__('Conditions', 'code-snippets')}
26+
<Badge name="beta" small>{__('beta', 'code-snippets')}</Badge>
27+
{!isLicensed() && <Badge name="pro" small>{__('Pro', 'code-snippets')}</Badge>}
28+
</h4>
2429

25-
<Button
26-
large
27-
primary={hasCondition}
28-
disabled={isReadOnly}
29-
onClick={() => setIsDialogOpen(true)}
30-
>
31-
<span className="dashicons dashicons-randomize"></span>
30+
<Button large disabled={isReadOnly} onClick={() => setIsDialogOpen(true)}>
31+
<Badge name="cond" small />
3232
{hasCondition
33-
? __('Conditions', 'code-snippets')
34-
: __('Set Conditions', 'code-snippets')}
35-
36-
<span className="badge beta-badge small-badge">{__('beta', 'code-snippets')}</span>
37-
{!isLicensed() && <span className="badge pro-badge small-badge">{__('Pro', 'code-snippets')}</span>}
33+
? __('Edit Conditions', 'code-snippets')
34+
: __('Add Conditions', 'code-snippets')}
3835
</Button>
3936
</>}
4037
</div>

src/js/components/EditorSidebar/EditorSidebar.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import React from 'react'
1+
import React, { Dispatch, SetStateAction } from 'react'
22
import { Spinner } from '@wordpress/components'
33
import { isRTL } from '@wordpress/i18n'
44
import { useSnippetForm } from '../../hooks/useSnippetForm'
55
import { isNetworkAdmin } from '../../utils/screen'
66
import { getSnippetType, isCondition } from '../../utils/snippets/snippets'
7+
import { ConditionModalButton } from '../ConditionModal/ConditionModalButton'
8+
import { SnippetLocationInput } from '../SnippetForm/fields/SnippetLocationInput'
9+
import { SnippetTypeInput } from '../SnippetForm/fields/SnippetTypeInput'
710
import { Notices } from '../SnippetForm/page/Notices'
811
import { ShortcodeInfo } from './actions/ShortcodeInfo'
912
import { MultisiteSharingSettings } from './controls/MultisiteSharingSettings'
@@ -15,24 +18,32 @@ import { PriorityInput } from './controls/PriorityInput'
1518
import { RTLControl } from './controls/RTLControl'
1619
import { TagsInput } from './controls/TagsInput'
1720

18-
export const EditorSidebar = () => {
21+
export interface EditorSidebarProps {
22+
setIsUpgradeDialogOpen: Dispatch<SetStateAction<boolean>>
23+
}
24+
25+
export const EditorSidebar: React.FC<EditorSidebarProps> = ({ setIsUpgradeDialogOpen }) => {
1926
const { snippet, isWorking } = useSnippetForm()
2027

2128
return (
2229
<div className="snippet-editor-sidebar">
30+
<SnippetTypeInput setIsUpgradeDialogOpen={setIsUpgradeDialogOpen} />
31+
2332
<div className="box">
2433
{snippet.id && !isCondition(snippet) ? <ActivationSwitch /> : null}
2534

2635
{isNetworkAdmin() ? <MultisiteSharingSettings /> : null}
2736

2837
{isRTL() ? <RTLControl /> : null}
2938

39+
<ConditionModalButton setIsDialogOpen={setIsUpgradeDialogOpen} />
40+
<SnippetLocationInput />
3041
<PriorityInput />
3142

3243
{window.CODE_SNIPPETS_EDIT?.tagOptions.enabled ? <TagsInput /> : null}
3344

3445
{snippet.id
35-
? <div className="row-actions visible">
46+
? <div className="row-actions visible inline-form-field">
3647
<ExportButtons />
3748
<DeleteButton />
3849
</div> : null}

src/js/components/EditorSidebar/controls/ActivationSwitch.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ export const ActivationSwitch = () => {
99
const { submitSnippet } = useSubmitSnippet()
1010

1111
return (
12-
<div>
12+
<div className="inline-form-field">
1313
<h4>
1414
<label htmlFor="activation-switch">
15-
{__('Is Active', 'code-snippets')}
15+
{snippet.active
16+
? __('Deactivate snippet', 'code-snippets')
17+
: __('Activate snippet', 'code-snippets')}
1618
</label>
1719
</h4>
1820

src/js/components/EditorSidebar/controls/PriorityInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const PriorityInput = () => {
77
const { snippet, isReadOnly, setSnippet } = useSnippetForm()
88

99
return (
10-
<div className="snippet-priority">
10+
<div className="snippet-priority inline-form-field">
1111
<h4>
1212
<label htmlFor="snippet-priority">
1313
{__('Priority', 'code-snippets')}

src/js/components/EditorSidebar/controls/TagsInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const TagsInput: React.FC = () => {
1010

1111
return options?.enabled
1212
? <div className="snippet-tags-container">
13-
<h4><label>{__('Tags', 'code-snippets')}</label></h4>
13+
<h4><label htmlFor="components-form-token-input-0">{__('Tags', 'code-snippets')}</label></h4>
1414

1515
<FormTokenField
1616
label=""

src/js/components/SnippetForm/SnippetForm.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ import { createSnippetObject, getSnippetType, isCondition, validateSnippet } fro
1010
import { WithSnippetFormContext, useSnippetForm } from '../../hooks/useSnippetForm'
1111
import { ConfirmDialog } from '../common/ConfirmDialog'
1212
import { UpsellDialog } from '../common/UpsellDialog'
13-
import { ConditionModalButton } from '../ConditionModal/ConditionModalButton'
1413
import { EditorSidebar } from '../EditorSidebar'
1514
import { UpsellBanner } from '../common/UpsellBanner'
1615
import { CodeEditor } from './fields/CodeEditor'
17-
import { SnippetLocationInput } from './fields/SnippetLocationInput'
18-
import { SnippetTypeInput } from './fields/SnippetTypeInput'
1916
import { DescriptionEditor } from './fields/DescriptionEditor'
2017
import { NameInput } from './fields/NameInput'
2118
import { PageHeading } from './page/PageHeading'
@@ -161,15 +158,6 @@ const EditFormWrap: React.FC = () => {
161158
<EditForm className={editFormClassName({ snippet, isReadOnly, isExpanded })}>
162159
<main className="snippet-form-upper">
163160
<NameInput />
164-
165-
{!isCondition(snippet) || 0 === snippet.id
166-
? <div className="above-editor-container">
167-
<SnippetTypeInput setIsUpgradeDialogOpen={setIsUpgradeDialogOpen} />
168-
<SnippetLocationInput />
169-
<ConditionModalButton setIsDialogOpen={setIsUpgradeDialogOpen} />
170-
</div>
171-
: null}
172-
173161
<CodeEditor {...{ isExpanded, setIsExpanded }} />
174162
<ConditionsEditor />
175163
</main>
@@ -179,7 +167,7 @@ const EditFormWrap: React.FC = () => {
179167
<DescriptionEditor />
180168
</div>
181169

182-
<EditorSidebar />
170+
<EditorSidebar setIsUpgradeDialogOpen={setIsUpgradeDialogOpen} />
183171
</EditForm>
184172

185173
<UpsellDialog isOpen={isUpgradeDialogOpen} setIsOpen={setIsUpgradeDialogOpen} />

0 commit comments

Comments
 (0)