PluginProbe ʕ •ᴥ•ʔ
VK Blocks / 1.119.2
VK Blocks v1.119.2
1.126.4 1.126.3 1.126.1 1.126.2 1.126.0 1.125.0 1.124.0 1.123.0 1.122.0 1.121.0 1.120.0 1.119.2 1.119.1 1.119.0 1.118.7 1.82.0.0 1.82.0.1 1.83.0.0 1.83.0.1 1.84.0.0 1.84.0.1 1.85.0.2 1.85.0.3 1.85.1.0 1.85.1.1 1.86.0.0 1.86.0.1 1.86.1.0 1.87.0.0 1.87.0.1 1.88.0.1 1.88.0.2 1.89.0.0 1.9.2 1.90.0.0 1.90.0.1 1.90.1.1 1.91.0.0 1.91.1.1 1.92.0.0 1.92.0.1 1.92.1.0 1.92.1.1 1.93.0.0 trunk 1.93.0.1 0.1.1 1.93.1.0 0.10.3 1.93.1.1 0.11.0 1.94.0.0 0.12.6 1.94.0.1 0.15.1 1.94.1.0 0.16.2 1.94.2.1 0.17.6 1.94.2.2 0.2.2 1.95.0.3 0.22.4 1.95.0.4 0.26.7 1.96.2.0 0.3.2 1.96.2.1 0.31.0 1.97.0.1 0.35.5 1.97.0.2 0.37.5 1.99.0.0 0.38.8 1.99.0.1 0.39.4 0.4.7 0.41.0 0.42.0 0.44.13 0.45.2 0.46.1 0.47.0 0.48.0 0.49.8 0.5.2 0.50.3 0.51.0 0.52.2 0.53.2 0.54.0 0.55.0 0.56.2 0.56.3 0.57.6 0.58.10 0.59.0 0.6.0 0.60.1 0.61.2 0.7.1 0.8.2 1.0.16 1.10.0 1.100.0.0 1.100.0.1 1.102.0.0 1.102.0.1 1.103.0.0 1.104.0.0 1.104.0.1 1.105.1.0 1.105.1.1 1.106.0.0 1.106.0.1 1.107.0.0 1.107.0.1 1.107.0.2 1.108.0.0 1.108.0.1 1.109.0.0 1.109.0.1 1.11.4 1.110.0.0 1.110.0.1 1.111.0.0 1.111.0.1 1.111.0.2 1.112.0.0 1.112.0.1 1.113.0.0 1.113.0.1 1.114.0.0 1.114.0.1 1.114.2.0 1.114.2.1 1.115.0.0 1.115.0.1 1.115.1.0 1.115.1.1 1.115.2.0 1.115.2.1 1.116.0.0 1.116.0.1 1.116.1.0 1.116.1.1 1.116.2.0 1.117.0.0 1.117.0.1 1.117.1.0 1.118.2 1.118.5 1.12.0 1.13.2 1.14.1 1.15.1 1.16.11 1.17.0 1.18.6 1.19.0 1.19.1 1.2.3 1.20.7 1.21.0 1.22.4 1.23.0 1.24.5 1.25.1 1.26.2 1.27.7.2 1.28.0.1 1.29.2.0 1.3.9 1.30.0.1 1.31.0.1 1.32.0.2 1.33.2.1 1.36.1.5 1.37.0.0 1.39.2.1 1.4.6 1.40.0.1 1.40.1.0 1.40.1.1 1.41.0.0 1.41.0.1 1.41.2.2 1.41.2.3 1.43.0.0 1.43.0.1 1.43.0.2 1.44.0.0 1.44.0.1 1.45.0.0 1.45.0.1 1.46.0.0 1.46.0.1 1.47.0.0 1.47.0.1 1.47.1.0 1.48.0.0 1.48.0.1 1.48.0.2 1.48.1.0 1.48.1.1 1.5.0 1.50.0.0 1.50.0.1 1.51.0.0 1.51.0.1 1.52.0.0 1.52.0.1 1.53.0.0 1.53.0.1 1.54.0.0 1.54.0.1 1.55.0.0 1.55.0.1 1.56.0.0 1.56.0.1 1.57.0.0 1.57.0.2 1.57.0.3 1.57.0.4 1.57.0.5 1.57.1.0 1.57.1.1 1.57.1.2 1.58.0.0 1.58.0.1 1.59.0.0 1.59.0.1 1.6.0 1.60.0.0 1.60.0.1 1.63.0.0 1.63.0.1 1.64.0.0 1.64.0.1 1.64.1.0 1.64.1.2 1.67.0.0 1.67.0.1 1.68.0.0 1.68.0.1 1.69.0.0 1.69.0.1 1.69.1.1 1.69.1.2 1.7.1 1.70.0.0 1.70.0.1 1.71.0.0 1.71.0.1 1.72.0.0 1.72.1.0 1.72.1.1 1.73.0.0 1.73.0.1 1.74.0.0 1.74.0.1 1.75.0.0 1.75.1.0 1.75.1.1 1.76.0.0 1.76.0.1 1.76.1.0 1.76.1.1 1.76.2.0 1.76.2.1 1.77.0.0 1.77.0.1 1.78.0.0 1.78.0.1 1.79.0.0 1.79.0.1 1.79.0.2 1.79.0.3 1.79.1.0 1.79.1.1 1.8.2 1.80.1.0 1.80.1.1 1.80.1.2 1.81.0.1 1.81.0.2
vk-blocks / src / blocks / button / component.js
vk-blocks / src / blocks / button Last commit date
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
component.js
177 lines
1 import { Component } from '@wordpress/element';
2 import parse from 'html-react-parser';
3 import { isHexColor } from '@vkblocks/utils/is-hex-color';
4 import { sanitizeSlug } from '@vkblocks/utils/sanitizeSlug';
5 import { fixBrokenUnicode } from '@vkblocks/utils/fixBrokenUnicode';
6
7 export class VKBButton extends Component {
8 render() {
9 const buttonTextColorCustom = this.props.lbTextColorCustom;
10 const buttonColorCustom = this.props.lbColorCustom;
11 const buttonColor = this.props.lbColor;
12 const buttonType = this.props.lbType;
13 const buttonAlign = this.props.lbAlign;
14 const buttonSize = this.props.lbSize;
15 const buttonUrl = this.props.lbUrl;
16 const buttonTarget = this.props.lbTarget;
17 const relAttribute = this.props.lbRelAttribute;
18 const linkToPost = this.props.lbLinkToPost;
19 let fontAwesomeIconBefore = this.props.lbFontAwesomeIconBefore;
20 let fontAwesomeIconAfter = this.props.lbFontAwesomeIconAfter;
21 if (fontAwesomeIconBefore) {
22 fontAwesomeIconBefore = fixBrokenUnicode(fontAwesomeIconBefore);
23 }
24 if (fontAwesomeIconAfter) {
25 fontAwesomeIconAfter = fixBrokenUnicode(fontAwesomeIconAfter);
26 }
27 const iconSizeBefore = this.props.lbIconSizeBefore;
28 const iconSizeAfter = this.props.lbIconSizeAfter;
29 const richText = this.props.lbRichtext;
30 const subCaption = this.props.lbsubCaption;
31 const inlineStyle = this.props.inlineStyle;
32 const borderRadius = this.props.borderRadius;
33 let aClass = '';
34 let iconBefore = '';
35 let iconAfter = '';
36
37 aClass = `vk_button_link`;
38
39 // 塗り
40 if (buttonType === '0' || buttonType === null) {
41 // 規定カラーの場合
42 if (buttonColor !== 'custom' && buttonColorCustom === undefined) {
43 aClass += ` btn has-background has-vk-color-${buttonColor}-background-color`;
44 } else {
45 aClass += ` btn has-background`;
46 // カスタムパレットカラーの場合
47 if (!isHexColor(buttonColorCustom)) {
48 aClass += ` has-${sanitizeSlug(buttonColorCustom)}-background-color`;
49 }
50 }
51
52 // 文字色
53 if (
54 buttonColor === 'custom' &&
55 buttonTextColorCustom !== undefined
56 ) {
57 aClass += ` btn has-text-color`;
58 // カスタムパレットカラーの場合
59 if (!isHexColor(buttonTextColorCustom)) {
60 aClass += ` has-${sanitizeSlug(buttonTextColorCustom)}-color`;
61 }
62 }
63 // 塗りなし
64 } else if (buttonType === '1') {
65 // 規定カラーの場合
66 if (buttonColor !== 'custom' && buttonColorCustom === undefined) {
67 aClass += ` btn has-text-color is-style-outline has-vk-color-${buttonColor}-color`;
68 } else {
69 aClass += ` btn has-text-color is-style-outline`;
70 // カスタムパレットカラーの場合
71 if (!isHexColor(buttonColorCustom)) {
72 aClass += ` has-${sanitizeSlug(buttonColorCustom)}-color`;
73 }
74 }
75 // テキストのみ
76 } else if (buttonType === '2') {
77 // 規定カラーの場合
78 if (buttonColor !== 'custom' && buttonColorCustom === undefined) {
79 aClass += ` has-text-color vk_button_link-type-text has-vk-color-${buttonColor}-color`;
80 } else {
81 aClass += ` has-text-color vk_button_link-type-text`;
82 // カスタムパレットカラーの場合
83 if (!isHexColor(buttonColorCustom)) {
84 aClass += ` has-${sanitizeSlug(buttonColorCustom)}-color`;
85 }
86 }
87 }
88
89 // 文字色がカスタムカラーの場合
90 /*
91 if (
92 buttonTextColorCustom !== undefined &&
93 isHexColor(buttonTextColorCustom) &&
94 isSelected
95 ) {
96 aStyle = {
97 // 編集画面対策
98 color: `${buttonTextColorCustom}`,
99 };
100 }
101 */
102
103 aClass = `${aClass} btn-${buttonSize}`;
104
105 if (buttonAlign === 'block') {
106 aClass = `${aClass} btn-block`;
107 }
108
109 //過去バージョンをリカバリーした時にiconを正常に表示する
110 if (fontAwesomeIconBefore && !fontAwesomeIconBefore.match(/<i/)) {
111 fontAwesomeIconBefore = `<i class="${fontAwesomeIconBefore}"></i>`;
112 }
113 if (fontAwesomeIconAfter && !fontAwesomeIconAfter.match(/<i/)) {
114 fontAwesomeIconAfter = `<i class="${fontAwesomeIconAfter}"></i>`;
115 }
116
117 if (fontAwesomeIconBefore) {
118 let fontAwesomeIconBeforeClassName =
119 fontAwesomeIconBefore.match(/class="(.*?)"/)[1];
120 fontAwesomeIconBeforeClassName += ` vk_button_link_before`;
121 const styleBefore = iconSizeBefore
122 ? ` style='font-size: ${iconSizeBefore}'`
123 : '';
124 iconBefore = `<i class="${fontAwesomeIconBeforeClassName}"${styleBefore}></i>`;
125 }
126 if (fontAwesomeIconAfter) {
127 let fontAwesomeIconAfterClassName =
128 fontAwesomeIconAfter.match(/class="(.*?)"/)[1];
129 fontAwesomeIconAfterClassName += ` vk_button_link_after`;
130 const styleAfter = iconSizeAfter
131 ? ` style='font-size: ${iconSizeAfter}'`
132 : '';
133 iconAfter = `<i class="${fontAwesomeIconAfterClassName}"${styleAfter}></i>`;
134 }
135
136 // inlineStyleからborderRadiusを含む新しいスタイルオブジェクトを構築
137 const btnInlineStyle = { ...inlineStyle };
138 if (borderRadius) {
139 btnInlineStyle.borderRadius = borderRadius;
140 }
141
142 // rel属性の設定
143 let relValue = 'noopener';
144 if (relAttribute) {
145 relValue = relAttribute.includes('noopener')
146 ? relAttribute
147 : `${relAttribute} noopener`;
148 }
149
150 return (
151 /* eslint react/jsx-no-target-blank: 0 */
152 /* eslint-disable-next-line jsx-a11y/anchor-is-valid -- linkToPost: href replaced server-side with permalink */
153 <a
154 href={linkToPost ? '#' : buttonUrl}
155 style={btnInlineStyle}
156 className={aClass}
157 role={'button'}
158 aria-pressed={true}
159 target={buttonTarget ? '_blank' : null}
160 rel={relValue}
161 {...(linkToPost ? { 'data-vk-link-to-post': '1' } : {})}
162 >
163 <div className={'vk_button_link_caption'}>
164 {parse(iconBefore)}
165 {richText}
166 {parse(iconAfter)}
167 </div>
168 {/*サブキャプションが�
169 �力された時のみ表示*/}
170 {subCaption && (
171 <p className={'vk_button_link_subCaption'}>{subCaption}</p>
172 )}
173 </a>
174 );
175 }
176 }
177