balloon
1 week ago
block-manager
2 months ago
block-style-manager
2 months ago
custom-block-style
2 months ago
custom-format
2 months ago
import-export
2 months ago
utils
2 months ago
block-category-position.js
2 months ago
breadcrumb.js
2 months ago
custom-css.js
2 months ago
index.js
2 months ago
license.js
2 months ago
load-separate.js
2 months ago
margin.js
2 months ago
new-faq.js
2 months ago
save-button.js
2 months ago
toc.js
2 months ago
margin.js
229 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | import { __ } from '@wordpress/i18n'; |
| 5 | import { |
| 6 | SelectControl, |
| 7 | __experimentalNumberControl as NumberControl, // eslint-disable-line @wordpress/no-unsafe-wp-apis |
| 8 | TextControl, |
| 9 | } from '@wordpress/components'; |
| 10 | import { useContext } from '@wordpress/element'; |
| 11 | import { hightUnitOptions } from '@vkblocks/utils/unit-options'; |
| 12 | |
| 13 | /** |
| 14 | * Internal dependencies |
| 15 | */ |
| 16 | import { AdminContext } from '@vkblocks/admin/index'; |
| 17 | |
| 18 | const MARGIN_SIZE_ARRAY = [ |
| 19 | { |
| 20 | marginLabel: __('XXS', 'vk-blocks'), |
| 21 | marginValue: 'xxs', |
| 22 | }, |
| 23 | { |
| 24 | marginLabel: __('XS', 'vk-blocks'), |
| 25 | marginValue: 'xs', |
| 26 | }, |
| 27 | { |
| 28 | marginLabel: __('S', 'vk-blocks'), |
| 29 | marginValue: 'sm', |
| 30 | }, |
| 31 | { |
| 32 | marginLabel: __('M', 'vk-blocks'), |
| 33 | marginValue: 'md', |
| 34 | }, |
| 35 | { |
| 36 | marginLabel: __('L', 'vk-blocks'), |
| 37 | marginValue: 'lg', |
| 38 | }, |
| 39 | { |
| 40 | marginLabel: __('XL', 'vk-blocks'), |
| 41 | marginValue: 'xl', |
| 42 | }, |
| 43 | { |
| 44 | marginLabel: __('XXL', 'vk-blocks'), |
| 45 | marginValue: 'xxl', |
| 46 | }, |
| 47 | ]; |
| 48 | |
| 49 | const DEVICE_ARRAY = [ |
| 50 | { |
| 51 | deviceLabel: __('PC', 'vk-blocks'), |
| 52 | deviceValue: 'pc', |
| 53 | }, |
| 54 | { |
| 55 | deviceLabel: __('Tablet', 'vk-blocks'), |
| 56 | deviceValue: 'tablet', |
| 57 | }, |
| 58 | { |
| 59 | deviceLabel: __('Mobile', 'vk-blocks'), |
| 60 | deviceValue: 'mobile', |
| 61 | }, |
| 62 | ]; |
| 63 | |
| 64 | export default function AdminMargin() { |
| 65 | const { vkBlocksOption, setVkBlocksOption, setReloadFlag } = |
| 66 | useContext(AdminContext); |
| 67 | |
| 68 | return ( |
| 69 | <> |
| 70 | <section className="margin-setting"> |
| 71 | <h3 id="margin-setting"> |
| 72 | {__('Common Margin Setting', 'vk-blocks')} |
| 73 | </h3> |
| 74 | <p> |
| 75 | {__( |
| 76 | 'Please specify the size of the common margin used for responsive spacers, etc.', |
| 77 | 'vk-blocks' |
| 78 | )} |
| 79 | </p> |
| 80 | <div className="margin-setting__unit"> |
| 81 | <span>{__('Unit', 'vk-blocks')}</span> |
| 82 | <SelectControl |
| 83 | name="vk_blocks_options[margin_unit]" |
| 84 | className="vk_admin_selectControl unit-select" |
| 85 | value={vkBlocksOption.margin_unit} |
| 86 | onChange={(newValue) => { |
| 87 | setVkBlocksOption({ |
| 88 | ...vkBlocksOption, |
| 89 | margin_unit: newValue, |
| 90 | }); |
| 91 | }} |
| 92 | options={hightUnitOptions} |
| 93 | /> |
| 94 | </div> |
| 95 | <table className="margin-setting__table"> |
| 96 | <thead> |
| 97 | <tr> |
| 98 | <td></td> |
| 99 | {DEVICE_ARRAY.map((device) => { |
| 100 | const { deviceLabel } = device; |
| 101 | return ( |
| 102 | <td |
| 103 | key={deviceLabel} |
| 104 | className="text-center nowrap" |
| 105 | > |
| 106 | {deviceLabel} |
| 107 | </td> |
| 108 | ); |
| 109 | })} |
| 110 | <td> |
| 111 | {__('Custom Value', 'vk-blocks')} |
| 112 | <span className="vk_admin_tooltip"> |
| 113 | <span className="vk_admin_tooltip__trigger"> |
| 114 | ? |
| 115 | </span> |
| 116 | <span className="vk_admin_tooltip__body"> |
| 117 | {__( |
| 118 | 'If you enter a custom value, the values you entered will be used as a priority.', |
| 119 | 'vk-blocks' |
| 120 | )} |
| 121 | <br /> |
| 122 | {__( |
| 123 | 'This item is mainly intended for inputting CSS variables for the margins specified by the theme. Thereby you can apply to the same margin size to the VK Blocks.', |
| 124 | 'vk-blocks' |
| 125 | )} |
| 126 | <br /> |
| 127 | {/* 最後のセミコロンは勝手につくので例の最後のセミコロンは不要*/} |
| 128 | {__('ex)', 'vk-blocks')} |
| 129 | {'var(--wp--custom--spacing--xx-small)'} |
| 130 | </span> |
| 131 | </span> |
| 132 | </td> |
| 133 | </tr> |
| 134 | </thead> |
| 135 | <tbody> |
| 136 | {MARGIN_SIZE_ARRAY.map((size) => { |
| 137 | const { marginLabel, marginValue } = size; |
| 138 | return ( |
| 139 | <tr key={marginLabel}> |
| 140 | <th className="nowrap"> |
| 141 | {__('Margin', 'vk-blocks') + |
| 142 | ` [ ${marginLabel} ] `} |
| 143 | </th> |
| 144 | {DEVICE_ARRAY.map((device) => { |
| 145 | const { deviceLabel, deviceValue } = |
| 146 | device; |
| 147 | { |
| 148 | /* TextControlでは以前の実� |
| 149 | が出来なかったので致し方なく__experimentalNumberControlを利用 */ |
| 150 | } |
| 151 | return ( |
| 152 | <td key={deviceLabel}> |
| 153 | <NumberControl |
| 154 | className="margin_size_input" |
| 155 | name={`vk_blocks_options[margin_size][${marginValue}][${deviceValue}]`} |
| 156 | step="0.05" |
| 157 | value={ |
| 158 | !vkBlocksOption |
| 159 | .margin_size[ |
| 160 | marginValue |
| 161 | ][deviceValue] |
| 162 | ? '' |
| 163 | : vkBlocksOption |
| 164 | .margin_size[ |
| 165 | marginValue |
| 166 | ][deviceValue] |
| 167 | } |
| 168 | onChange={(newValue) => { |
| 169 | setVkBlocksOption({ |
| 170 | ...vkBlocksOption, |
| 171 | margin_size: { |
| 172 | ...vkBlocksOption.margin_size, |
| 173 | [marginValue]: { |
| 174 | ...vkBlocksOption |
| 175 | .margin_size[ |
| 176 | marginValue |
| 177 | ], |
| 178 | [deviceValue]: |
| 179 | newValue, |
| 180 | }, |
| 181 | }, |
| 182 | }); |
| 183 | }} |
| 184 | /> |
| 185 | </td> |
| 186 | ); |
| 187 | })} |
| 188 | <td className="margin-setting__custom"> |
| 189 | <TextControl |
| 190 | className="margin-setting__custom__input" |
| 191 | name={`vk_blocks_options[margin_size][${marginValue}][custom]`} |
| 192 | value={ |
| 193 | !vkBlocksOption.margin_size[ |
| 194 | marginValue |
| 195 | ].custom |
| 196 | ? '' |
| 197 | : vkBlocksOption |
| 198 | .margin_size[ |
| 199 | marginValue |
| 200 | ].custom |
| 201 | } |
| 202 | onChange={(newValue) => { |
| 203 | setVkBlocksOption({ |
| 204 | ...vkBlocksOption, |
| 205 | margin_size: { |
| 206 | ...vkBlocksOption.margin_size, |
| 207 | [marginValue]: { |
| 208 | ...vkBlocksOption |
| 209 | .margin_size[ |
| 210 | marginValue |
| 211 | ], |
| 212 | custom: newValue, |
| 213 | }, |
| 214 | }, |
| 215 | }); |
| 216 | setReloadFlag(true); |
| 217 | }} |
| 218 | /> |
| 219 | </td> |
| 220 | </tr> |
| 221 | ); |
| 222 | })} |
| 223 | </tbody> |
| 224 | </table> |
| 225 | </section> |
| 226 | </> |
| 227 | ); |
| 228 | } |
| 229 |