deprecated
2 months ago
block.json
1 month ago
edit.js
2 weeks ago
icon.svg
2 months ago
index.js
2 months ago
index.php
2 months ago
save.js
2 months ago
style.scss
2 months ago
edit.js
374 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 { sanitizeSlug } from '@vkblocks/utils/sanitizeSlug'; |
| 26 | import { AdvancedColorPalette } from '@vkblocks/components/advanced-color-palette'; |
| 27 | |
| 28 | export default function StaffEdit(props) { |
| 29 | const { attributes, setAttributes, className, clientId } = props; |
| 30 | // id生成 |
| 31 | const vkStaffNameColorId = `vk_staff_name-color-${clientId}`; |
| 32 | const vkStaffCaptionColorId = `vk_staff_caption-color-${clientId}`; |
| 33 | const vkStaffPositionColorId = `vk_staff_position-color-${clientId}`; |
| 34 | const vkStaffProfileTitleColorId = `vk_staff_profileTitle-color-${clientId}`; |
| 35 | const vkStaffProfileTextColorId = `vk_staff_profileText-color-${clientId}`; |
| 36 | const { |
| 37 | vk_staff_layout, |
| 38 | vk_staff_nameColor, |
| 39 | vk_staff_captionColor, |
| 40 | vk_staff_positionColor, |
| 41 | vk_staff_profileTitleColor, |
| 42 | vk_staff_profileTextColor, |
| 43 | vk_staff_photo_image_alt, |
| 44 | vk_staff_photoBorder, |
| 45 | vk_staff_text_name, |
| 46 | vk_staff_text_caption, |
| 47 | vk_staff_text_role, |
| 48 | vk_staff_text_profileTitle, |
| 49 | vk_staff_text_profileText, |
| 50 | vk_staff_photo_image, |
| 51 | vk_staff_fontFamily, |
| 52 | } = attributes; |
| 53 | |
| 54 | const classes = classnames('vk_staff', { |
| 55 | [className]: !!className, |
| 56 | [`vk_staff-layout-${vk_staff_layout}`]: !!vk_staff_layout, |
| 57 | }); |
| 58 | |
| 59 | const blockProps = useBlockProps({ |
| 60 | className: classes, |
| 61 | }); |
| 62 | |
| 63 | // 画像の線のクラスとimgタグの親タグのクラス名を生成. |
| 64 | const imgBorderClassName = classnames('vk_staff_photo', { |
| 65 | [`vk_staff_photo-border-${vk_staff_photoBorder}`]: |
| 66 | !!vk_staff_photoBorder, |
| 67 | }); |
| 68 | |
| 69 | let staffTextClassName = classnames; |
| 70 | if (vk_staff_fontFamily === '1') { |
| 71 | staffTextClassName = classnames( |
| 72 | 'vk_staff_text', |
| 73 | staffTextClassName, |
| 74 | 'vk_staff-headingFont-serif' |
| 75 | ); |
| 76 | } else { |
| 77 | staffTextClassName = classnames('vk_staff_text', staffTextClassName); |
| 78 | } |
| 79 | |
| 80 | let staffNameColorInlineStyle = {}; |
| 81 | let staffTextNameClassName = ''; |
| 82 | if (vk_staff_nameColor !== undefined) { |
| 83 | staffTextNameClassName += ` has-text-color`; |
| 84 | if (isHexColor(vk_staff_nameColor)) { |
| 85 | staffNameColorInlineStyle = { color: `${vk_staff_nameColor}` }; |
| 86 | } else { |
| 87 | staffTextNameClassName += ` has-${sanitizeSlug(vk_staff_nameColor)}-color`; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | let staffCaptionColorInlineStyle = {}; |
| 92 | let staffCaptionClassName = ''; |
| 93 | if (vk_staff_captionColor !== undefined) { |
| 94 | staffCaptionClassName += ` has-text-color`; |
| 95 | if (isHexColor(vk_staff_captionColor)) { |
| 96 | staffCaptionColorInlineStyle = { |
| 97 | color: `${vk_staff_captionColor}`, |
| 98 | }; |
| 99 | } else { |
| 100 | staffCaptionClassName += ` has-${sanitizeSlug(vk_staff_captionColor)}-color`; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | let staffPositionColorInlineStyle = {}; |
| 105 | let staffPositionClassName = ''; |
| 106 | if (vk_staff_positionColor !== undefined) { |
| 107 | staffPositionClassName += ` has-text-color`; |
| 108 | if (isHexColor(vk_staff_positionColor)) { |
| 109 | staffPositionColorInlineStyle = { |
| 110 | color: `${vk_staff_positionColor}`, |
| 111 | }; |
| 112 | } else { |
| 113 | staffPositionClassName += ` has-${sanitizeSlug(vk_staff_positionColor)}-color`; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | let staffProfileTitleColorInlineStyle = {}; |
| 118 | let staffProfileTitleClassName = ''; |
| 119 | if (vk_staff_profileTitleColor !== undefined) { |
| 120 | staffProfileTitleClassName += ` has-text-color`; |
| 121 | if (isHexColor(vk_staff_profileTitleColor)) { |
| 122 | staffProfileTitleColorInlineStyle = { |
| 123 | color: `${vk_staff_profileTitleColor}`, |
| 124 | }; |
| 125 | } else { |
| 126 | staffProfileTitleClassName += ` has-${sanitizeSlug(vk_staff_profileTitleColor)}-color`; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | let staffProfileTextColorInlineStyle = {}; |
| 131 | let staffProfileTextClassName = ''; |
| 132 | if (vk_staff_profileTextColor !== undefined) { |
| 133 | staffProfileTextClassName += ` has-text-color`; |
| 134 | if (isHexColor(vk_staff_profileTextColor)) { |
| 135 | staffProfileTextColorInlineStyle = { |
| 136 | color: `${vk_staff_profileTextColor}`, |
| 137 | }; |
| 138 | } else { |
| 139 | staffProfileTextClassName += ` has-${sanitizeSlug(vk_staff_profileTextColor)}-color`; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return ( |
| 144 | <> |
| 145 | <InspectorControls> |
| 146 | <PanelBody title={__('Layout', 'vk-blocks')}> |
| 147 | <SelectControl |
| 148 | value={vk_staff_layout} |
| 149 | onChange={(value) => |
| 150 | setAttributes({ vk_staff_layout: value }) |
| 151 | } |
| 152 | options={[ |
| 153 | { |
| 154 | value: 'default', |
| 155 | label: __('Default', 'vk-blocks'), |
| 156 | }, |
| 157 | { |
| 158 | value: 'imageLeft', |
| 159 | label: __('Image left', 'vk-blocks'), |
| 160 | }, |
| 161 | ]} |
| 162 | /> |
| 163 | </PanelBody> |
| 164 | <PanelBody title={__('Image border', 'vk-blocks')}> |
| 165 | <SelectControl |
| 166 | value={vk_staff_photoBorder} |
| 167 | onChange={(value) => |
| 168 | setAttributes({ vk_staff_photoBorder: value }) |
| 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} |
| 191 | onChange={(value) => |
| 192 | setAttributes({ |
| 193 | vk_staff_photo_image_alt: value, |
| 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} |
| 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} |
| 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} |
| 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} |
| 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={(value) => |
| 331 | setAttributes({ |
| 332 | vk_staff_text_profileText: value, |
| 333 | }) |
| 334 | } |
| 335 | value={vk_staff_text_profileText} |
| 336 | placeholder={__('Profile text', 'vk-blocks')} |
| 337 | /> |
| 338 | </div> |
| 339 | <div className={imgBorderClassName}> |
| 340 | <MediaUpload |
| 341 | onSelect={(value) => |
| 342 | setAttributes({ |
| 343 | vk_staff_photo_image: value.sizes.full.url, |
| 344 | }) |
| 345 | } |
| 346 | type="image" |
| 347 | value={vk_staff_photo_image} |
| 348 | render={({ open }) => ( |
| 349 | <Button |
| 350 | onClick={open} |
| 351 | className={ |
| 352 | vk_staff_photo_image |
| 353 | ? 'image-button' |
| 354 | : 'button button-large' |
| 355 | } |
| 356 | > |
| 357 | {!vk_staff_photo_image ? ( |
| 358 | __('Select image', 'vk-blocks') |
| 359 | ) : ( |
| 360 | <img |
| 361 | className={`vk_staff_photo_image`} |
| 362 | src={vk_staff_photo_image} |
| 363 | alt={vk_staff_photo_image_alt} |
| 364 | /> |
| 365 | )} |
| 366 | </Button> |
| 367 | )} |
| 368 | /> |
| 369 | </div> |
| 370 | </div> |
| 371 | </> |
| 372 | ); |
| 373 | } |
| 374 |