PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.1
JetFormBuilder — Dynamic Blocks Form Builder v3.1.1
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / assets / src / package / blocks / components / ToggleGroupVariations.js
jetformbuilder / assets / src / package / blocks / components Last commit date
AdvancedFields.js 2 years ago AttributeHelp.js 2 years ago BlockAddPrevButton.js 2 years ago BlockAdvancedValue.js 2 years ago BlockClassName.js 2 years ago BlockDefaultValue.js 2 years ago BlockDescription.js 2 years ago BlockLabel.js 2 years ago BlockName.js 2 years ago BlockPlaceholder.js 2 years ago BlockPrevButtonLabel.js 2 years ago BlockRequired.js 2 years ago BlockVisibility.js 2 years ago FieldControl.js 2 years ago FieldSettingsWrapper.js 2 years ago FieldWrapper.js 2 years ago GeneralFields.js 2 years ago SelectVariations.js 2 years ago ToggleGroupVariations.js 2 years ago ToolBarDefault.js 2 years ago ToolBarFields.js 2 years ago
ToggleGroupVariations.js
107 lines
1 import useBlockAttributes from '../hooks/useBlockAttributes';
2
3 const {
4 Children,
5 cloneElement,
6 useContext,
7 } = wp.element;
8
9 const {
10 useSelect,
11 } = wp.data;
12
13 const {
14 useBlockEditContext,
15 } = wp.blockEditor;
16
17 let {
18 __experimentalToggleGroupControl,
19 __experimentalToggleGroupControlOptionIcon,
20 __experimentalToolbarContext,
21 ToggleGroupControl,
22 ToggleGroupControlOptionIcon,
23 ToolbarItem,
24 ToolbarGroup,
25 ToolbarContext,
26 } = wp.components;
27
28 ToggleGroupControl = (
29 ToggleGroupControl || __experimentalToggleGroupControl
30 );
31 ToggleGroupControlOptionIcon = (
32 ToggleGroupControlOptionIcon || __experimentalToggleGroupControlOptionIcon
33 );
34 ToolbarContext = (
35 ToolbarContext || __experimentalToolbarContext
36 );
37
38 function ToggleGroupVariationsBase( { value } ) {
39 const { name } = useBlockEditContext();
40 const toolbarState = useContext( ToolbarContext );
41
42 const [ , setAttributes ] = useBlockAttributes();
43
44 const { variations, components } = useSelect(
45 ( select ) => {
46 const {
47 getBlockVariations,
48 } = select( 'core/blocks' );
49
50 const items = getBlockVariations( name, 'block' );
51
52 return {
53 variations: items,
54 components: items.map(
55 current => (
56 toolbarState?.currentId ??
57 toolbarState?.baseId
58 )
59 ? <ToolbarItem
60 as={ ToggleGroupControlOptionIcon }
61 value={ current.name }
62 label={ current.title }
63 icon={ current.icon }
64 /> : <ToggleGroupControlOptionIcon
65 value={ current.name }
66 label={ current.title }
67 icon={ current.icon }
68 /> ),
69 };
70 },
71 [],
72 );
73
74 if ( !variations.length ) {
75 return null;
76 }
77
78 return <ToggleGroupControl
79 hideLabelFromVision
80 onChange={ varName => setAttributes( {
81 ...variations.find(
82 ( { name } ) => name === varName,
83 ).attributes,
84 } ) }
85 value={ value }
86 isBlock
87 >
88 { Children.map(
89 components,
90 cloneElement,
91 ) }
92 </ToggleGroupControl>;
93 }
94
95 function ToggleGroupVariations( props ) {
96 const toolbarState = useContext( ToolbarContext );
97
98 if ( !toolbarState?.currentId ) {
99 return <ToggleGroupVariationsBase { ...props }/>;
100 }
101
102 return <ToolbarGroup className={ 'jet-fb toggle-toolbar-group' }>
103 <ToggleGroupVariationsBase { ...props }/>
104 </ToolbarGroup>;
105 }
106
107 export default ToggleGroupVariations;