-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathedit.js
More file actions
168 lines (150 loc) · 4.02 KB
/
edit.js
File metadata and controls
168 lines (150 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* External dependencies
*/
import classnames from 'classnames'
import { version as VERSION, i18n } from 'stackable'
import { InspectorTabs, useBlockCssGenerator } from '~stackable/components'
import {
getTypographyClasses,
BlockDiv,
Advanced,
CustomCSS,
Responsive,
Button,
Typography,
BlockStyle,
CustomAttributes,
EffectsAnimations,
ConditionalDisplay,
Transform,
getAlignmentClasses,
} from '~stackable/block-components'
import { useBlockStyle } from '~stackable/hooks'
import {
withBlockAttributeContext,
withBlockWrapper,
withQueryLoopContext,
} from '~stackable/higher-order'
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n'
import { compose } from '@wordpress/compose'
import { AlignmentToolbar, BlockControls } from '@wordpress/block-editor'
import { memo } from '@wordpress/element'
/**
* Internal dependencies
*/
import buttonStyles from './style'
import { blockStyles } from './block-styles'
const Edit = props => {
const {
className,
onReplace,
attributes,
setAttributes,
} = props
const typographyInnerClasses = getTypographyClasses( props.attributes )
const customAttributes = CustomAttributes.getCustomAttributes( props.attributes )
const blockAlignmentClass = getAlignmentClasses( props.attributes )
const blockStyle = useBlockStyle( blockStyles )
const blockClassNames = classnames( [
className,
'stk-block-button',
blockAlignmentClass,
// We need to add the blockStyle here to append the class alongside `.stk-block`
// Only in the editor.
{
[ `is-style-${ blockStyle }` ]: blockStyle,
},
] )
const typographyInnerClassNames = classnames( [
typographyInnerClasses,
'stk-button__inner-text',
] )
// Generate the CSS styles for the block.
const blockCss = useBlockCssGenerator( {
attributes: props.attributes,
blockStyles: buttonStyles,
clientId: props.clientId,
context: props.context,
setAttributes: props.setAttributes,
blockState: props.blockState,
version: VERSION,
} )
return (
<>
<InspectorControls
contentAlign={ attributes.contentAlign }
setAttributes={ setAttributes }
blockState={ props.blockState }
/>
{ blockCss && <style key="block-css">{ blockCss }</style> }
<CustomCSS mainBlockClass="stk-block-button" />
<BlockDiv
blockHoverClass={ props.blockHoverClass }
clientId={ props.clientId }
attributes={ props.attributes }
className={ blockClassNames }
applyCustomAttributes={ false }
blockTag={ blockStyle === 'link' ? 'p' : null }
>
<Button
buttonProps={ {
tagName: props.attributes.linkTag,
id: props.attributes.anchorId || undefined,
...customAttributes,
} }
>
<Typography
tagName="span"
className={ typographyInnerClassNames }
placeholder={ __( 'Button text', i18n ) }
withoutInteractiveFormatting={ true }
onReplace={ onReplace }
/>
</Button>
</BlockDiv>
</>
)
}
const InspectorControls = memo( props => {
return (
<>
<BlockControls>
<AlignmentToolbar
value={ props.contentAlign }
onChange={ contentAlign => props.setAttributes( { contentAlign } ) }
/>
</BlockControls>
<InspectorTabs hasLayoutPanel={ false } />
<BlockStyle.InspectorControls styles={ blockStyles }>
<Button.InspectorControls.HoverEffects />
</BlockStyle.InspectorControls>
<Button.InspectorControls
blockState={ props.blockState }
borderSelector=".stk-button"
hasFullWidth={ true }
/>
<Typography.InspectorControls
{ ...props }
hasTextTag={ false }
initialOpen={ false }
hasColor={ false }
/>
<BlockDiv.InspectorControls initialOpen="spacing" />
<Advanced.InspectorControls />
<Transform.InspectorControls />
<EffectsAnimations.InspectorControls />
<CustomAttributes.InspectorControls />
<CustomCSS.InspectorControls mainBlockClass="stk-block-button" />
<Responsive.InspectorControls />
<ConditionalDisplay.InspectorControls />
</>
)
} )
export default compose(
withBlockWrapper,
withQueryLoopContext,
withBlockAttributeContext,
)( Edit )