forked from Automattic/_s
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
153 lines (136 loc) · 3.24 KB
/
index.js
File metadata and controls
153 lines (136 loc) · 3.24 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
/* global wp */
/* global lodash */
/**
* BLOCK: card
*
* Shows a card
* @author: Brando Meniconi <b.meniconi@silverbackstudio.it>
*/
import edit from './edit';
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
const { __ } = wp.i18n; // Import __() from wp.i18n
const {
InnerBlocks,
RichText,
} = wp.blockEditor;
/**
* Register: Gutenberg Block.
*
* Registers a new block provided a unique name and an object defining its
* behavior. Once registered, the block is made editor as an option to any
* editor interface where blocks are implemented.
*
* @param {string} name Block name.
* @param {Object} settings Block settings.
* @return {?WPBlock} The block, if it has been successfully
* registered; otherwise `undefined`.
*/
/**
* Internal dependencies
*/
export const name = 'svbk/collapse';
export const settings = {
title: __( 'Collapse', '_svbk' ),
icon: 'feedback',
category: 'common',
keywords: [
__( 'collapse', '_svbk' ),
__( 'accordion', '_svbk' ),
],
styles: [
// Mark style as default.
{
name: 'default',
label: __( 'Default', '_svbk' ),
isDefault: true
},
{
name: 'accordion',
label: __( 'Accordion', '_svbk' ),
},
{
name: 'faq',
label: __( 'FAQ', '_svbk' ),
},
{
name: 'button',
label: __( 'Button', '_svbk' ),
},
],
attributes: {
defaultOpen: {
type: 'boolean',
default: false,
},
title: {
type: 'string',
source: 'html',
selector: '.wp-block-svbk-collapse__title',
},
buttonOpen: {
type: 'string',
source: 'text',
selector: '.wp-block-svbk-collapse__label--open',
},
buttonClose: {
type: 'string',
source: 'text',
selector: '.wp-block-svbk-collapse__label--close',
},
},
edit,
save: function( { attributes, className } ) {
const {
title,
defaultOpen,
buttonOpen,
buttonClose,
} = attributes;
const classNames = classnames( className, {
'wp-block-svbk-collapse--open' : defaultOpen
});
const buttonClassNames = classnames(
[
'wp-block-svbk-collapse__button',
'wp-block-svbk-collapse__trigger'
],
{
'wp-block-svbk-collapse__button--has-open': buttonOpen,
'wp-block-svbk-collapse__button--has-close': buttonClose,
}
);
const style = {
display: defaultOpen ? undefined : 'none',
};
return (
<div className={ classNames } >
{ title && (
<RichText.Content
tagName={ 'h3' }
value={ title }
className={ 'wp-block-svbk-collapse__title wp-block-svbk-collapse__trigger' }
/>
) }
<div className={ 'wp-block-svbk-collapse__content' } style={ style } >
<InnerBlocks.Content />
</div>
{ (buttonOpen || buttonClose) && (
<button className={ buttonClassNames }>
{ buttonOpen && (
<span className={ 'wp-block-svbk-collapse__label wp-block-svbk-collapse__label--open' }>{ buttonOpen }</span>
) }
{ buttonClose && (
<span className={ 'wp-block-svbk-collapse__label wp-block-svbk-collapse__label--close' }>{ buttonClose }</span>
) }
</button>
) }
</div>
);
},
};