Skip to content

Commit aa8fe97

Browse files
author
Ariel Jolo
committed
Adding new blocks
1 parent 149cd29 commit aa8fe97

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"apiVersion": 2,
3+
"name": "custom/about-area",
4+
"title": "About Area",
5+
"description": "A custom block for the about area with tabs.",
6+
"category": "layout",
7+
"icon": "admin-users",
8+
"supports": {
9+
"align": ["wide", "full"]
10+
},
11+
"attributes": {
12+
"title": {
13+
"type": "string",
14+
"default": "What's Open Source AI?"
15+
},
16+
"description": {
17+
"type": "string",
18+
"default": "Following the same idea behind Open Source Software, an Open Source AI is a system made available under terms that grant users the freedoms to:"
19+
},
20+
"tabs": {
21+
"type": "array",
22+
"default": [
23+
{ "label": "Use", "content": "Use the system for any purpose and without having to ask for permission." },
24+
{ "label": "Study", "content": "Study how the system works and understand how its results were created." },
25+
{ "label": "Modify", "content": "Modify the system for any purpose, including to change its output." },
26+
{ "label": "Share", "content": "Share the system for others to use with or without modifications, for any purpose." }
27+
]
28+
}
29+
},
30+
"editorScript": "file:./index.js"
31+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { registerBlockType } from '@wordpress/blocks';
2+
import { useBlockProps, RichText } from '@wordpress/block-editor';
3+
4+
registerBlockType('custom/about-area', {
5+
edit: ({ attributes, setAttributes }) => {
6+
const blockProps = useBlockProps();
7+
const { title, description, tabs } = attributes;
8+
9+
const updateTabContent = (index, content) => {
10+
const updatedTabs = [...tabs];
11+
updatedTabs[index].content = content;
12+
setAttributes({ tabs: updatedTabs });
13+
};
14+
15+
return (
16+
<div {...blockProps} className="rts-about-area rts-section-gap">
17+
<div className="container">
18+
<div className="title-area-left">
19+
<RichText
20+
tagName="h2"
21+
className="title skew-up"
22+
value={title}
23+
onChange={(newTitle) => setAttributes({ title: newTitle })}
24+
/>
25+
<RichText
26+
tagName="p"
27+
value={description}
28+
onChange={(newDesc) => setAttributes({ description: newDesc })}
29+
/>
30+
</div>
31+
<ul className="nav custom-nav-soalr-about nav-pills" id="pills-tab" role="tablist">
32+
{tabs.map((tab, index) => (
33+
<li key={index} className="nav-item" role="presentation">
34+
<button className={`nav-link ${index === 0 ? 'active' : ''}`} data-bs-toggle="pill">
35+
{tab.label}
36+
</button>
37+
</li>
38+
))}
39+
</ul>
40+
<div className="tab-content">
41+
{tabs.map((tab, index) => (
42+
<div key={index} className={`tab-pane fade ${index === 0 ? 'show active' : ''}`}>
43+
<RichText
44+
tagName="p"
45+
className="disc"
46+
value={tab.content}
47+
onChange={(newContent) => updateTabContent(index, newContent)}
48+
/>
49+
</div>
50+
))}
51+
</div>
52+
</div>
53+
</div>
54+
);
55+
},
56+
save: ({ attributes }) => {
57+
const { title, description, tabs } = attributes;
58+
59+
return (
60+
<div className="rts-about-area rts-section-gap">
61+
<div className="container">
62+
<div className="title-area-left">
63+
<h2 className="title skew-up">{title}</h2>
64+
<p>{description}</p>
65+
</div>
66+
<ul className="nav custom-nav-soalr-about nav-pills" id="pills-tab" role="tablist">
67+
{tabs.map((tab, index) => (
68+
<li key={index} className="nav-item" role="presentation">
69+
<button className={`nav-link ${index === 0 ? 'active' : ''}`} data-bs-toggle="pill">
70+
{tab.label}
71+
</button>
72+
</li>
73+
))}
74+
</ul>
75+
<div className="tab-content">
76+
{tabs.map((tab, index) => (
77+
<div key={index} className={`tab-pane fade ${index === 0 ? 'show active' : ''}`}>
78+
<p className="disc">{tab.content}</p>
79+
</div>
80+
))}
81+
</div>
82+
</div>
83+
</div>
84+
);
85+
}
86+
});

0 commit comments

Comments
 (0)