deprecated
4 months ago
block.json
4 months ago
component.js
4 months ago
edit.js
4 months ago
icon.svg
4 months ago
index.js
4 months ago
index.php
4 months ago
save.js
4 months ago
style.scss
4 months ago
transforms.js
4 months ago
save.js
110 lines
| 1 | import { VKBButton } from './component'; |
| 2 | import { RichText, useBlockProps } from '@wordpress/block-editor'; |
| 3 | import { isHexColor } from '@vkblocks/utils/is-hex-color'; |
| 4 | |
| 5 | export default function save(props) { |
| 6 | const { attributes } = props; |
| 7 | const { |
| 8 | content, |
| 9 | subCaption, |
| 10 | buttonUrl, |
| 11 | buttonTarget, |
| 12 | relAttribute, |
| 13 | linkToPost, |
| 14 | buttonSize, |
| 15 | buttonType, |
| 16 | buttonEffect, |
| 17 | buttonColor, |
| 18 | buttonTextColorCustom, |
| 19 | buttonColorCustom, |
| 20 | buttonAlign, |
| 21 | buttonWidthMobile, |
| 22 | buttonWidthTablet, |
| 23 | buttonWidth, |
| 24 | outerGap, |
| 25 | fontAwesomeIconBefore, |
| 26 | fontAwesomeIconAfter, |
| 27 | iconSizeBefore, |
| 28 | iconSizeAfter, |
| 29 | inlineStyle, |
| 30 | borderRadius, |
| 31 | blockId, |
| 32 | } = attributes; |
| 33 | |
| 34 | const effectiveUrl = linkToPost ? '' : buttonUrl; |
| 35 | |
| 36 | let containerClass = ''; |
| 37 | // カスタムカラーの場合 またはアウターにギャップが指定されれいる場合 |
| 38 | if ( |
| 39 | (buttonColorCustom !== undefined && isHexColor(buttonColorCustom)) || |
| 40 | (buttonTextColorCustom !== undefined && |
| 41 | isHexColor(buttonTextColorCustom)) || |
| 42 | outerGap |
| 43 | ) { |
| 44 | containerClass = `vk_button vk_button-color-custom vk_button-${blockId}`; |
| 45 | } else { |
| 46 | containerClass = `vk_button vk_button-color-custom`; |
| 47 | } |
| 48 | |
| 49 | if (buttonWidthMobile || buttonWidthTablet || buttonWidth) { |
| 50 | // 横並びボタンで� |
| 51 | が指定されている |
| 52 | if (buttonWidthMobile) { |
| 53 | containerClass += ` vk_button-width-mobile-${buttonWidthMobile}`; |
| 54 | } |
| 55 | if (buttonWidthTablet) { |
| 56 | containerClass += ` vk_button-width-tablet-${buttonWidthTablet}`; |
| 57 | } |
| 58 | if (buttonWidth) { |
| 59 | containerClass += ` vk_button-width-${buttonWidth}`; |
| 60 | } |
| 61 | } else { |
| 62 | containerClass += ` vk_button-align-${buttonAlign}`; |
| 63 | } |
| 64 | |
| 65 | // エフェクト |
| 66 | if (buttonEffect !== '') { |
| 67 | containerClass += ` is-style-${buttonEffect}`; |
| 68 | } |
| 69 | |
| 70 | const blockProps = useBlockProps.save({ |
| 71 | className: containerClass, |
| 72 | }); |
| 73 | |
| 74 | // inlineStyleからborderRadiusを含む新しいスタイルオブジェクトを構築 |
| 75 | const btnInlineStyle = { ...inlineStyle }; |
| 76 | if (borderRadius) { |
| 77 | btnInlineStyle.borderRadius = borderRadius; |
| 78 | } |
| 79 | |
| 80 | return ( |
| 81 | <div {...blockProps}> |
| 82 | <VKBButton |
| 83 | lbTextColorCustom={buttonTextColorCustom} |
| 84 | lbColorCustom={buttonColorCustom} |
| 85 | lbColor={buttonColor} |
| 86 | lbType={buttonType} |
| 87 | lbAlign={buttonAlign} |
| 88 | lbSize={buttonSize} |
| 89 | lbUrl={effectiveUrl} |
| 90 | lbTarget={buttonTarget} |
| 91 | lbLinkToPost={linkToPost} |
| 92 | lbRelAttribute={relAttribute} |
| 93 | lbFontAwesomeIconBefore={fontAwesomeIconBefore} |
| 94 | lbFontAwesomeIconAfter={fontAwesomeIconAfter} |
| 95 | lbIconSizeBefore={iconSizeBefore} |
| 96 | lbIconSizeAfter={iconSizeAfter} |
| 97 | lbsubCaption={subCaption} |
| 98 | inlineStyle={btnInlineStyle} |
| 99 | lbRichtext={ |
| 100 | <RichText.Content |
| 101 | tagName={'span'} |
| 102 | className={'vk_button_link_txt'} |
| 103 | value={content} |
| 104 | /> |
| 105 | } |
| 106 | /> |
| 107 | </div> |
| 108 | ); |
| 109 | } |
| 110 |