deprecated
4 years ago
block.json
4 years ago
edit.js
4 years ago
icon.svg
5 years ago
index.js
4 years ago
index.php
4 years ago
save.js
4 years ago
style.scss
4 years ago
edit.js
375 lines
| 1 | /** |
| 2 | * External dependencies |
| 3 | */ |
| 4 | import classnames from 'classnames'; |
| 5 | |
| 6 | /** |
| 7 | * WordPress dependencies |
| 8 | */ |
| 9 | import { __ } from '@wordpress/i18n'; |
| 10 | import { |
| 11 | TextControl, |
| 12 | PanelBody, |
| 13 | RadioControl, |
| 14 | BaseControl, |
| 15 | SelectControl, |
| 16 | Button, |
| 17 | } from '@wordpress/components'; |
| 18 | import { |
| 19 | InspectorControls, |
| 20 | useBlockProps, |
| 21 | RichText, |
| 22 | MediaUpload, |
| 23 | } from '@wordpress/block-editor'; |
| 24 | import { isHexColor } from '@vkblocks/utils/is-hex-color'; |
| 25 | import { AdvancedColorPalette } from '@vkblocks/components/advanced-color-palette'; |
| 26 | |
| 27 | export default function StaffEdit(props) { |
| 28 | const { attributes, setAttributes, className, clientId } = props; |
| 29 | // id生成 |
| 30 | const vkStaffNameColorId = `vk_staff_name-color-${clientId}`; |
| 31 | const vkStaffCaptionColorId = `vk_staff_caption-color-${clientId}`; |
| 32 | const vkStaffPositionColorId = `vk_staff_position-color-${clientId}`; |
| 33 | const vkStaffProfileTitleColorId = `vk_staff_profileTitle-color-${clientId}`; |
| 34 | const vkStaffProfileTextColorId = `vk_staff_profileText-color-${clientId}`; |
| 35 | const { |
| 36 | vk_staff_layout, // eslint-disable-line camelcase |
| 37 | vk_staff_nameColor, // eslint-disable-line camelcase |
| 38 | vk_staff_captionColor, // eslint-disable-line camelcase |
| 39 | vk_staff_positionColor, // eslint-disable-line camelcase |
| 40 | vk_staff_profileTitleColor, // eslint-disable-line camelcase |
| 41 | vk_staff_profileTextColor, // eslint-disable-line camelcase |
| 42 | vk_staff_photo_image_alt, // eslint-disable-line camelcase |
| 43 | vk_staff_photoBorder, // eslint-disable-line camelcase |
| 44 | vk_staff_text_name, // eslint-disable-line camelcase |
| 45 | vk_staff_text_caption, // eslint-disable-line camelcase |
| 46 | vk_staff_text_role, // eslint-disable-line camelcase |
| 47 | vk_staff_text_profileTitle, // eslint-disable-line camelcase |
| 48 | vk_staff_text_profileText, // eslint-disable-line camelcase |
| 49 | vk_staff_photo_image, // eslint-disable-line camelcase |
| 50 | vk_staff_fontFamily, |
| 51 | } = attributes; |
| 52 | |
| 53 | const classes = classnames('vk_staff', { |
| 54 | [className]: !!className, |
| 55 | [`vk_staff-layout-${vk_staff_layout}`]: !!vk_staff_layout, // eslint-disable-line camelcase |
| 56 | }); |
| 57 | |
| 58 | const blockProps = useBlockProps({ |
| 59 | className: classes, |
| 60 | }); |
| 61 | |
| 62 | // 画像の線のクラスとimgタグの親タグのクラス名を生成. |
| 63 | const imgBorderClassName = classnames('vk_staff_photo', { |
| 64 | [`vk_staff_photo-border-${vk_staff_photoBorder}`]: |
| 65 | !!vk_staff_photoBorder, // eslint-disable-line camelcase |
| 66 | }); |
| 67 | |
| 68 | let staffTextClassName = classnames; |
| 69 | if (vk_staff_fontFamily === '1') { |
| 70 | staffTextClassName = classnames( |
| 71 | 'vk_staff_text', |
| 72 | staffTextClassName, |
| 73 | 'vk_staff-headingFont-serif' |
| 74 | ); |
| 75 | } else { |
| 76 | staffTextClassName = classnames('vk_staff_text', staffTextClassName); |
| 77 | } |
| 78 | |
| 79 | let staffNameColorInlineStyle = {}; |
| 80 | let staffTextNameClassName = ''; |
| 81 | if (vk_staff_nameColor !== undefined) { |
| 82 | staffTextNameClassName += ` has-text-color`; |
| 83 | if (isHexColor(vk_staff_nameColor)) { |
| 84 | staffNameColorInlineStyle = { color: `${vk_staff_nameColor}` }; |
| 85 | } else { |
| 86 | staffTextNameClassName += ` has-${vk_staff_nameColor}-color`; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | let staffCaptionColorInlineStyle = {}; |
| 91 | let staffCaptionClassName = ''; |
| 92 | if (vk_staff_captionColor !== undefined) { |
| 93 | staffCaptionClassName += ` has-text-color`; |
| 94 | if (isHexColor(vk_staff_captionColor)) { |
| 95 | staffCaptionColorInlineStyle = { |
| 96 | color: `${vk_staff_captionColor}`, |
| 97 | }; |
| 98 | } else { |
| 99 | staffCaptionClassName += ` has-${vk_staff_captionColor}-color`; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | let staffPositionColorInlineStyle = {}; |
| 104 | let staffPositionClassName = ''; |
| 105 | if (vk_staff_positionColor !== undefined) { |
| 106 | staffPositionClassName += ` has-text-color`; |
| 107 | if (isHexColor(vk_staff_positionColor)) { |
| 108 | staffPositionColorInlineStyle = { |
| 109 | color: `${vk_staff_positionColor}`, |
| 110 | }; |
| 111 | } else { |
| 112 | staffPositionClassName += ` has-${vk_staff_positionColor}-color`; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | let staffProfileTitleColorInlineStyle = {}; |
| 117 | let staffProfileTitleClassName = ''; |
| 118 | if (vk_staff_profileTitleColor !== undefined) { |
| 119 | staffProfileTitleClassName += ` has-text-color`; |
| 120 | if (isHexColor(vk_staff_profileTitleColor)) { |
| 121 | staffProfileTitleColorInlineStyle = { |
| 122 | color: `${vk_staff_profileTitleColor}`, |
| 123 | }; |
| 124 | } else { |
| 125 | staffProfileTitleClassName += ` has-${vk_staff_profileTitleColor}-color`; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | let staffProfileTextColorInlineStyle = {}; |
| 130 | let staffProfileTextClassName = ''; |
| 131 | if (vk_staff_profileTextColor !== undefined) { |
| 132 | staffProfileTextClassName += ` has-text-color`; |
| 133 | if (isHexColor(vk_staff_profileTextColor)) { |
| 134 | staffProfileTextColorInlineStyle = { |
| 135 | color: `${vk_staff_profileTextColor}`, |
| 136 | }; |
| 137 | } else { |
| 138 | staffProfileTextClassName += ` has-${vk_staff_profileTextColor}-color`; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return ( |
| 143 | <> |
| 144 | <InspectorControls> |
| 145 | <PanelBody title={__('Layout', 'vk-blocks')}> |
| 146 | <SelectControl |
| 147 | value={vk_staff_layout} // eslint-disable-line camelcase |
| 148 | onChange={ |
| 149 | (value) => setAttributes({ vk_staff_layout: value }) // eslint-disable-line camelcase |
| 150 | } |
| 151 | options={[ |
| 152 | { |
| 153 | value: 'default', |
| 154 | label: __('Default', 'vk-blocks'), |
| 155 | }, |
| 156 | { |
| 157 | value: 'imageLeft', |
| 158 | label: __('Image left', 'vk-blocks'), |
| 159 | }, |
| 160 | ]} |
| 161 | /> |
| 162 | </PanelBody> |
| 163 | <PanelBody title={__('Image border', 'vk-blocks')}> |
| 164 | <SelectControl |
| 165 | value={vk_staff_photoBorder} // eslint-disable-line camelcase |
| 166 | onChange={ |
| 167 | (value) => |
| 168 | setAttributes({ vk_staff_photoBorder: value }) // eslint-disable-line camelcase |
| 169 | } |
| 170 | options={[ |
| 171 | { |
| 172 | value: 'default', |
| 173 | label: __('Default', 'vk-blocks'), |
| 174 | }, |
| 175 | { |
| 176 | value: 'none', |
| 177 | label: __('None', 'vk-blocks'), |
| 178 | }, |
| 179 | ]} |
| 180 | /> |
| 181 | </PanelBody> |
| 182 | <PanelBody title={__('Alt text', 'vk-blocks')}> |
| 183 | <BaseControl |
| 184 | help={__( |
| 185 | 'Set the alt text for profile image', |
| 186 | 'vk-blocks' |
| 187 | )} |
| 188 | > |
| 189 | <TextControl |
| 190 | value={vk_staff_photo_image_alt} // eslint-disable-line camelcase |
| 191 | onChange={(value) => |
| 192 | setAttributes({ |
| 193 | vk_staff_photo_image_alt: value, // eslint-disable-line camelcase |
| 194 | }) |
| 195 | } |
| 196 | /> |
| 197 | </BaseControl> |
| 198 | </PanelBody> |
| 199 | <PanelBody title={__('Color', 'vk-blocks')}> |
| 200 | <BaseControl |
| 201 | id={vkStaffNameColorId} |
| 202 | label={__('Staff name', 'vk-blocks')} |
| 203 | > |
| 204 | <AdvancedColorPalette |
| 205 | id={vkStaffNameColorId} |
| 206 | schema={'vk_staff_nameColor'} |
| 207 | {...props} |
| 208 | /> |
| 209 | </BaseControl> |
| 210 | <BaseControl |
| 211 | id={vkStaffCaptionColorId} |
| 212 | label={__('Name caption', 'vk-blocks')} |
| 213 | > |
| 214 | <AdvancedColorPalette |
| 215 | id={vkStaffCaptionColorId} |
| 216 | schema={'vk_staff_captionColor'} |
| 217 | {...props} |
| 218 | /> |
| 219 | </BaseControl> |
| 220 | <BaseControl |
| 221 | id={vkStaffPositionColorId} |
| 222 | label={__('Role position', 'vk-blocks')} |
| 223 | > |
| 224 | <AdvancedColorPalette |
| 225 | id={vkStaffPositionColorId} |
| 226 | schema={'vk_staff_positionColor'} |
| 227 | {...props} |
| 228 | /> |
| 229 | </BaseControl> |
| 230 | <BaseControl |
| 231 | id={vkStaffProfileTitleColorId} |
| 232 | label={__('Profile title', 'vk-blocks')} |
| 233 | > |
| 234 | <AdvancedColorPalette |
| 235 | id={vkStaffProfileTitleColorId} |
| 236 | schema={'vk_staff_profileTitleColor'} |
| 237 | {...props} |
| 238 | /> |
| 239 | </BaseControl> |
| 240 | <BaseControl |
| 241 | id={vkStaffProfileTextColorId} |
| 242 | label={__('Profile text', 'vk-blocks')} |
| 243 | > |
| 244 | <AdvancedColorPalette |
| 245 | id={vkStaffProfileTextColorId} |
| 246 | schema={'vk_staff_profileTextColor'} |
| 247 | {...props} |
| 248 | /> |
| 249 | </BaseControl> |
| 250 | </PanelBody> |
| 251 | <PanelBody title={__('Heading Font', 'vk-blocks')}> |
| 252 | <RadioControl |
| 253 | label={__('Font', 'vk-blocks')} |
| 254 | selected={vk_staff_fontFamily} |
| 255 | options={[ |
| 256 | { |
| 257 | label: __('Unspecified', 'vk-blocks'), |
| 258 | value: '0', |
| 259 | }, |
| 260 | { |
| 261 | label: __('minchoBody', 'vk-blocks'), |
| 262 | value: '1', |
| 263 | }, |
| 264 | ]} |
| 265 | onChange={(value) => |
| 266 | setAttributes({ vk_staff_fontFamily: value }) |
| 267 | } |
| 268 | /> |
| 269 | </PanelBody> |
| 270 | </InspectorControls> |
| 271 | |
| 272 | <div {...blockProps}> |
| 273 | <div className={staffTextClassName}> |
| 274 | <RichText |
| 275 | tagName="h3" |
| 276 | className={ |
| 277 | `vk_staff_text_name` + staffTextNameClassName |
| 278 | } |
| 279 | style={staffNameColorInlineStyle} |
| 280 | onChange={(value) => |
| 281 | setAttributes({ vk_staff_text_name: value }) |
| 282 | } |
| 283 | value={vk_staff_text_name} // eslint-disable-line camelcase |
| 284 | placeholder={__('Your Name', 'vk-blocks')} |
| 285 | /> |
| 286 | <RichText |
| 287 | tagName="p" |
| 288 | className={ |
| 289 | `vk_staff_text_caption` + staffCaptionClassName |
| 290 | } |
| 291 | style={staffCaptionColorInlineStyle} |
| 292 | onChange={(value) => |
| 293 | setAttributes({ vk_staff_text_caption: value }) |
| 294 | } |
| 295 | value={vk_staff_text_caption} // eslint-disable-line camelcase |
| 296 | placeholder={__('Caption', 'vk-blocks')} |
| 297 | /> |
| 298 | <RichText |
| 299 | tagName="p" |
| 300 | className={ |
| 301 | `vk_staff_text_role` + staffPositionClassName |
| 302 | } |
| 303 | style={staffPositionColorInlineStyle} |
| 304 | onChange={(value) => |
| 305 | setAttributes({ vk_staff_text_role: value }) |
| 306 | } |
| 307 | value={vk_staff_text_role} // eslint-disable-line camelcase |
| 308 | placeholder={__('Role position', 'vk-blocks')} |
| 309 | /> |
| 310 | <RichText |
| 311 | tagName="h4" |
| 312 | className={ |
| 313 | `vk_staff_text_profileTitle` + |
| 314 | staffProfileTitleClassName |
| 315 | } |
| 316 | style={staffProfileTitleColorInlineStyle} |
| 317 | onChange={(value) => |
| 318 | setAttributes({ vk_staff_text_profileTitle: value }) |
| 319 | } |
| 320 | value={vk_staff_text_profileTitle} // eslint-disable-line camelcase |
| 321 | placeholder={__('Profile title', 'vk-blocks')} |
| 322 | /> |
| 323 | <RichText |
| 324 | tagName="p" |
| 325 | className={ |
| 326 | `vk_staff_text_profileText` + |
| 327 | staffProfileTextClassName |
| 328 | } |
| 329 | style={staffProfileTextColorInlineStyle} |
| 330 | onChange={ |
| 331 | (value) => |
| 332 | setAttributes({ |
| 333 | vk_staff_text_profileText: value, |
| 334 | }) // eslint-disable-line camelcase |
| 335 | } |
| 336 | value={vk_staff_text_profileText} // eslint-disable-line camelcase |
| 337 | placeholder={__('Profile text', 'vk-blocks')} |
| 338 | /> |
| 339 | </div> |
| 340 | <div className={imgBorderClassName}> |
| 341 | <MediaUpload |
| 342 | onSelect={(value) => |
| 343 | setAttributes({ |
| 344 | vk_staff_photo_image: value.sizes.full.url, |
| 345 | }) |
| 346 | } |
| 347 | type="image" |
| 348 | value={vk_staff_photo_image} // eslint-disable-line camelcase |
| 349 | render={({ open }) => ( |
| 350 | <Button |
| 351 | onClick={open} |
| 352 | className={ |
| 353 | vk_staff_photo_image // eslint-disable-line camelcase |
| 354 | ? 'image-button' |
| 355 | : 'button button-large' |
| 356 | } |
| 357 | > |
| 358 | {!vk_staff_photo_image ? ( // eslint-disable-line camelcase |
| 359 | __('Select image', 'vk-blocks') |
| 360 | ) : ( |
| 361 | <img |
| 362 | className={`vk_staff_photo_image`} |
| 363 | src={vk_staff_photo_image} // eslint-disable-line camelcase |
| 364 | alt={vk_staff_photo_image_alt} // eslint-disable-line camelcase |
| 365 | /> |
| 366 | )} |
| 367 | </Button> |
| 368 | )} |
| 369 | /> |
| 370 | </div> |
| 371 | </div> |
| 372 | </> |
| 373 | ); |
| 374 | } |
| 375 |