PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.4.1
Block Animations, Motion & Scroll Effects – Ghost Kit v3.4.1
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / blocks / grid-column / edit.js

edit.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.4.1, at gutenberg/blocks/grid-column/edit.js

291 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import classnames from 'classnames/dedupe';
2
3 import {
4 InnerBlocks,
5 InspectorControls,
6 useBlockProps,
7 useInnerBlocksProps,
8 } from '@wordpress/block-editor';
9 import { PanelBody, SelectControl } from '@wordpress/components';
10 import { useSelect } from '@wordpress/data';
11 import { applyFilters } from '@wordpress/hooks';
12 import { __, sprintf } from '@wordpress/i18n';
13
14 import ApplyFilters from '../../components/apply-filters';
15 import RangeControl from '../../components/range-control';
16 import ResponsiveToggle from '../../components/responsive-toggle';
17 import ToggleGroup from '../../components/toggle-group';
18 import useResponsive from '../../hooks/use-responsive';
19 import getIcon from '../../utils/get-icon';
20 import getColClass from './get-col-class';
21
22 /**
23 * Get array for Select element.
24 *
25 * @return {Array} array for Select.
26 */
27 const getDefaultColumnSizes = function () {
28 const result = [
29 {
30 label: __('Inherit from larger', 'ghostkit'),
31 value: '',
32 },
33 {
34 label: __('Auto', 'ghostkit'),
35 value: 'auto',
36 },
37 {
38 label: __('Grow', 'ghostkit'),
39 value: 'grow',
40 },
41 ];
42
43 for (let k = 1; k <= 12; k += 1) {
44 result.push({
45 // eslint-disable-next-line @wordpress/valid-sprintf
46 label: sprintf(
47 k === 1
48 ? __('%d Column (%s)', 'ghostkit')
49 : __('%d Columns (%s)', 'ghostkit'),
50 k,
51 `${Math.round(((100 * k) / 12) * 100) / 100}%`
52 ),
53 value: k,
54 });
55 }
56 return result;
57 };
58
59 /**
60 * Get array for Select element.
61 *
62 * @param {number} columns - number of available columns.
63 *
64 * @return {Array} array for Select.
65 */
66 const getDefaultColumnOrders = function (columns = 12) {
67 const result = [
68 {
69 label: __('Inherit from larger', 'ghostkit'),
70 value: '',
71 },
72 {
73 label: __('Auto', 'ghostkit'),
74 value: 'auto',
75 },
76 {
77 label: __('First', 'ghostkit'),
78 value: 'first',
79 },
80 ];
81
82 for (let k = 1; k <= columns; k += 1) {
83 result.push({
84 label: k,
85 value: k,
86 });
87 }
88
89 result.push({
90 label: __('Last', 'ghostkit'),
91 value: 'last',
92 });
93
94 return result;
95 };
96
97 /**
98 * Block Edit Class.
99 *
100 * @param props
101 */
102 export default function BlockEdit(props) {
103 const { clientId, attributes, setAttributes } = props;
104
105 const { stickyContent, stickyContentOffset } = attributes;
106
107 const { device } = useResponsive();
108
109 const { hasChildBlocks } = useSelect(
110 (select) => {
111 const blockEditor = select('core/block-editor');
112
113 return {
114 hasChildBlocks: blockEditor
115 ? blockEditor.getBlockOrder(clientId).length > 0
116 : false,
117 };
118 },
119 [clientId]
120 );
121
122 // background
123 const background = applyFilters(
124 'ghostkit.editor.grid-column.background',
125 '',
126 props
127 );
128
129 const blockProps = useBlockProps({
130 className: classnames(props.attributes.className, getColClass(props)),
131 });
132
133 const innerBlocksProps = useInnerBlocksProps(
134 { className: 'ghostkit-col-content' },
135 {
136 templateLock: false,
137 renderAppender: hasChildBlocks
138 ? undefined
139 : InnerBlocks.ButtonBlockAppender,
140 }
141 );
142
143 let sizeName = 'size';
144 let orderName = 'order';
145 let verticalAlignName = 'verticalAlign';
146
147 if (device) {
148 sizeName = `${device}_${sizeName}`;
149 orderName = `${device}_${orderName}`;
150 verticalAlignName = `${device}_${verticalAlignName}`;
151 }
152
153 return (
154 <div {...blockProps}>
155 <InspectorControls>
156 <ApplyFilters
157 name="ghostkit.editor.controls"
158 attribute="columnSettings"
159 props={props}
160 >
161 <PanelBody>
162 <SelectControl
163 label={
164 <>
165 {__('Size', 'ghostkit')}
166 <ResponsiveToggle
167 checkActive={(checkMedia) => {
168 return !!attributes[
169 `${checkMedia}_size`
170 ];
171 }}
172 />
173 </>
174 }
175 value={attributes[sizeName]}
176 onChange={(value) => {
177 setAttributes({
178 [sizeName]: value,
179 });
180 }}
181 options={getDefaultColumnSizes()}
182 __next40pxDefaultSize
183 __nextHasNoMarginBottom
184 />
185 <SelectControl
186 label={
187 <>
188 {__('Order', 'ghostkit')}
189 <ResponsiveToggle
190 checkActive={(checkMedia) => {
191 return !!attributes[
192 `${checkMedia}_order`
193 ];
194 }}
195 />
196 </>
197 }
198 value={attributes[orderName]}
199 onChange={(value) => {
200 setAttributes({
201 [orderName]: value,
202 });
203 }}
204 options={getDefaultColumnOrders()}
205 __next40pxDefaultSize
206 __nextHasNoMarginBottom
207 />
208 <ToggleGroup
209 label={
210 <>
211 {__('Vertical Alignment', 'ghostkit')}
212 <ResponsiveToggle
213 checkActive={(checkMedia) => {
214 return !!attributes[
215 `${checkMedia}_verticalAlign`
216 ];
217 }}
218 />
219 </>
220 }
221 value={attributes[verticalAlignName]}
222 options={[
223 {
224 icon: getIcon('icon-vertical-top'),
225 label: __('Top', 'ghostkit'),
226 value: '',
227 },
228 {
229 icon: getIcon('icon-vertical-center'),
230 label: __('Center', 'ghostkit'),
231 value: 'center',
232 },
233 {
234 icon: getIcon('icon-vertical-bottom'),
235 label: __('Bottom', 'ghostkit'),
236 value: 'end',
237 },
238 ]}
239 onChange={(value) => {
240 setAttributes({ [verticalAlignName]: value });
241 }}
242 isDeselectable
243 />
244 </PanelBody>
245 </ApplyFilters>
246 <PanelBody>
247 <ToggleGroup
248 label={__('Sticky Content', 'ghostkit')}
249 value={stickyContent}
250 options={[
251 {
252 label: __('Top', 'ghostkit'),
253 value: 'top',
254 },
255 {
256 label: __('Bottom', 'ghostkit'),
257 value: 'bottom',
258 },
259 ]}
260 onChange={(value) => {
261 setAttributes({ stickyContent: value });
262 }}
263 isDeselectable
264 />
265 {stickyContent ? (
266 <RangeControl
267 label={__('Sticky Offset', 'ghostkit')}
268 value={stickyContentOffset}
269 onChange={(value) =>
270 setAttributes({ stickyContentOffset: value })
271 }
272 allowCustomMax
273 __next40pxDefaultSize
274 __nextHasNoMarginBottom
275 />
276 ) : null}
277 </PanelBody>
278 <div className="ghostkit-background-controls">
279 <ApplyFilters
280 name="ghostkit.editor.controls"
281 attribute="background"
282 props={props}
283 />
284 </div>
285 </InspectorControls>
286 {background}
287 <div {...innerBlocksProps} />
288 </div>
289 );
290 }
291