-
Notifications
You must be signed in to change notification settings - Fork 179
/
textPane.js
143 lines (133 loc) · 3.46 KB
/
textPane.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
/**
* External dependencies
*/
import styled from 'styled-components';
/**
* Internal dependencies
*/
import { PAGE_WIDTH } from '../../../../constants';
import { dataFontEm } from '../../../../units';
import { Section, MainButton, SearchInput } from '../../common';
import { FontPreview } from '../../text';
import useLibrary from '../../useLibrary';
import { Pane } from '../shared';
import paneId from './paneId';
// By default, the element should be 50% of the page.
const DEFAULT_ELEMENT_WIDTH = PAGE_WIDTH / 2;
const PRESETS = [
{
id: 'heading',
title: __('Heading', 'web-stories'),
content: `<span style="font-weight: 700">${__(
'Heading',
'web-stories'
)}</span>`,
fontSize: dataFontEm(2),
font: {
family: 'Open Sans',
service: 'fonts.google.com',
},
},
{
id: 'subheading',
title: __('Subheading', 'web-stories'),
content: `<span style="font-weight: 600">${__(
'Subheading',
'web-stories'
)}</span>`,
fontSize: dataFontEm(1.5),
font: {
family: 'Open Sans',
service: 'fonts.google.com',
},
},
{
id: 'body-text',
title: __('Body text', 'web-stories'),
content: __(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'web-stories'
),
fontSize: dataFontEm(1.1),
font: {
family: 'Roboto',
service: 'fonts.google.com',
},
},
];
function getPresetById(id) {
for (let i = 0; i < PRESETS.length; i++) {
if (PRESETS[i].id === id) {
return PRESETS[i];
}
}
return null;
}
const SectionContent = styled.p``;
function TextPane(props) {
const {
actions: { insertElement },
} = useLibrary();
return (
<Pane id={paneId} {...props}>
<SearchInput
value={''}
placeholder={__('Search', 'web-stories')}
onChange={() => {}}
disabled
/>
<Section
title={__('Presets', 'web-stories')}
titleTools={
<MainButton
onClick={() =>
insertElement('text', {
...getPresetById('subheading'),
content: __('Fill in some text', 'web-stories'),
width: DEFAULT_ELEMENT_WIDTH,
})
}
>
{__('Add new text', 'web-stories')}
</MainButton>
}
>
{PRESETS.map((preset) => (
<FontPreview
key={`preset-${preset.id}`}
{...preset}
onClick={() =>
insertElement('text', {
...preset,
width: DEFAULT_ELEMENT_WIDTH,
})
}
/>
))}
</Section>
<Section title={__('Text Sets', 'web-stories')}>
<SectionContent>{__('Coming soon.', 'web-stories')}</SectionContent>
</Section>
</Pane>
);
}
export default TextPane;