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 / index.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
index.js
202 lines
1 /**
2 * Button block type
3 *
4 */
5 import { ReactComponent as Icon } from './icon.svg';
6 import { title, iconName, url, iconUser } from '@vkblocks/utils/example-data';
7 import edit from './edit';
8 import metadata from './block.json';
9 import save from './save';
10 import { deprecated } from './deprecated/save/';
11 import deprecatedHooks from './deprecated/hooks';
12 import transforms from './transforms';
13 import { addFilter } from '@wordpress/hooks';
14 import { createHigherOrderComponent } from '@wordpress/compose';
15 import { isHexColor } from '@vkblocks/utils/is-hex-color';
16
17 const { name } = metadata;
18
19 export { metadata, name };
20
21 export const settings = {
22 icon: <Icon />,
23 example: {
24 attributes: {
25 content: iconName,
26 subCaption: title,
27 buttonUrl: url,
28 buttonTarget: false,
29 buttonSize: 'md',
30 buttonType: '0',
31 buttonEffect: '',
32 buttonColor: 'primary',
33 buttonTextColorCustom: 'undefined',
34 buttonColorCustom: 'undefined',
35 buttonAlign: 'left',
36 buttonWidthMobile: 0,
37 buttonWidthTablet: 0,
38 outerGap: null,
39 buttonWidth: 0,
40 fontAwesomeIconBefore: iconUser,
41 fontAwesomeIconAfter: iconUser,
42 iconSizeBefore: null,
43 iconSizeAfter: null,
44 },
45 },
46 edit,
47 save,
48 deprecated,
49 transforms,
50 };
51
52 const generateInlineCss = (attributes) => {
53 const { buttonTextColorCustom, buttonColorCustom, buttonType, blockId } =
54 attributes;
55 let inlineCss = '';
56
57 // カスタムカラーの場合
58 if (buttonColorCustom !== undefined && isHexColor(buttonColorCustom)) {
59 // 塗り
60 if (buttonType === '0' || buttonType === null) {
61 inlineCss += `.vk_button-${blockId} .has-background {
62 background-color: ${buttonColorCustom};
63 border: 1px solid ${buttonColorCustom};
64 }`;
65 }
66 // アウトライン
67 if (buttonType === '1') {
68 inlineCss += `.vk_button-${blockId} .has-text-color.is-style-outline {
69 background-color: transparent;
70 border: 1px solid ${buttonColorCustom};
71 color: ${buttonColorCustom};
72 }
73 .vk_button-${blockId} .has-text-color.is-style-outline:hover {
74 background-color: ${buttonColorCustom};
75 border: 1px solid ${buttonColorCustom};
76 color: #fff;
77 }`;
78 }
79 // テキストのみ
80 if (buttonType === '2') {
81 inlineCss = `.vk_button-${blockId} .has-text-color.vk_button_link-type-text {
82 color: ${buttonColorCustom};
83 }`;
84 }
85 }
86
87 // 文字色がカスタムカラーの場合
88 if (
89 buttonTextColorCustom !== undefined &&
90 isHexColor(buttonTextColorCustom)
91 ) {
92 if (buttonType === '0' || buttonType === null) {
93 inlineCss += ` .vk_button-${blockId} .has-text-color {
94 color: ${buttonTextColorCustom};
95 }`;
96 }
97 }
98
99 return inlineCss;
100 };
101
102 const generateInlineGapCss = (attributes, isSave) => {
103 const {
104 buttonWidthMobile,
105 buttonWidthTablet,
106 buttonWidth,
107 outerGap,
108 blockId,
109 } = attributes;
110 let inlineCss = '';
111 const propaty = isSave
112 ? '.vk_button'
113 : '.vk_buttons .vk_buttons_col .block-editor-block-list__layout .vk_button';
114
115 // 親ブロックのギャップを反映
116 if (outerGap) {
117 if (buttonWidthMobile) {
118 inlineCss += `@media (max-width: 575.98px) {
119 ${propaty}.vk_button-${blockId} {
120 width: calc(${buttonWidthMobile}% - calc(${outerGap} - calc(${outerGap} / (100 / ${buttonWidthMobile}))) - 1px);
121 }
122 }`;
123 }
124 if (buttonWidthTablet) {
125 inlineCss += `@media(min-width: 576px) and (max-width: 991.98px) {
126 ${propaty}.vk_button-${blockId} {
127 width: calc(${buttonWidthTablet}% - calc(${outerGap} - calc(${outerGap} / (100 / ${buttonWidthTablet}))) - 1px);
128 }
129 }`;
130 }
131 if (buttonWidth) {
132 inlineCss += `@media (min-width: 992px) {
133 ${propaty}.vk_button-${blockId} {
134 width: calc(${buttonWidth}% - calc(${outerGap} - calc(${outerGap} / (100 / ${buttonWidth}))) - 1px );
135 }
136 }`;
137 }
138 }
139
140 return inlineCss;
141 };
142
143 const VKButtonInlineEditorCss = createHigherOrderComponent((BlockEdit) => {
144 return (props) => {
145 const { attributes } = props;
146
147 if ('vk-blocks/button' === props.name) {
148 const cssTag = generateInlineCss(attributes);
149 const cssEditor = generateInlineGapCss(attributes, false);
150 if (cssTag !== '' || cssEditor !== '') {
151 return (
152 <>
153 <BlockEdit {...props} />
154 <style type="text/css">
155 {cssTag} {cssEditor}
156 </style>
157 </>
158 );
159 }
160 return <BlockEdit {...props} />;
161 }
162 return <BlockEdit {...props} />;
163 };
164 }, 'VKButtonInlineEditorCss');
165 addFilter('editor.BlockEdit', 'vk-blocks/button', VKButtonInlineEditorCss);
166
167 const VKButtonInlineCss = (el, type, attributes) => {
168 if ('vk-blocks/button' === type.name) {
169 //現在実行されている deprecated�
170 save関数のindexを取得
171 const deprecatedFuncIndex = deprecated.findIndex(
172 (item) => item.save === type.save
173 );
174
175 // 最新版
176 if (-1 === deprecatedFuncIndex) {
177 // NOTE: useBlockProps + style要素を挿�
178 �する場合、useBlockPropsを使った要素が最初(上)にこないと、
179 // カスタムクラスを追加する処理が失敗する[
180 const cssTag = generateInlineCss(attributes);
181 const cssEditor = generateInlineGapCss(attributes, true);
182 if (cssTag !== '' || cssEditor !== '') {
183 return (
184 <>
185 {el}
186 <style type="text/css">
187 {cssTag} {cssEditor}
188 </style>
189 </>
190 );
191 }
192 return el;
193
194 //後方互換
195 }
196 const DeprecatedHook = deprecatedHooks[deprecatedFuncIndex];
197 return <DeprecatedHook el={el} attributes={attributes} />;
198 }
199 return el;
200 };
201 addFilter('blocks.getSaveElement', 'vk-blocks/button', VKButtonInlineCss, 11);
202