Skip to content

Commit

Permalink
WIP Adds title attribute for tab blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
creativecoder committed Jul 17, 2024
1 parent 6a889b9 commit eb97843
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
13 changes: 9 additions & 4 deletions packages/block-library/src/tab/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
"name": "core/tab",
"title": "Tab",
"category": "design",
"description": "Tab container for content (use within the Tabs block).",
"description": "Single tab within a tabs block.",
"textdomain": "default",
"__experimental": true,
"attributes": {},
"attributes": {
"title": {
"type": "string"
}
},
"parent": [ "core/tabs" ],
"supports": {
"align": false,
"html": false
"html": false,
"inserter": false,
"reusable": false
},
"editorScript": "file:./build/index.js",
"style": "file:./build/style.css"
Expand Down
20 changes: 17 additions & 3 deletions packages/block-library/src/tab/edit.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
/**
* WordPress dependencies
*/
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';

export default function Edit( { attributes, setAttributes } ) {
const { title } = attributes;

export default function Edit() {
return (
<div { ...useBlockProps() }>
<InnerBlocks />
<RichText
className="wp-block-tab__title"
tagName="div"
value={ title }
onChange={ ( newTitle ) =>
setAttributes( { title: newTitle } )
}
placeholder={ __( 'Add text…' ) }
/>
<div className="wp-block-tab__content">
<InnerBlocks />
</div>
</div>
);
}
9 changes: 7 additions & 2 deletions packages/block-library/src/tab/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

export default function save() {
export default function save( { attributes } ) {
const { title } = attributes;

return (
<div { ...useBlockProps.save() }>
<InnerBlocks.Content />
<div className="wp-block-tab__title">{ title }</div>
<div className="wp-block-tab__content">
<InnerBlocks.Content />
</div>
</div>
);
}
29 changes: 29 additions & 0 deletions packages/block-library/src/tabs/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.wp-block-tabs {
.wp-block-tabs__tab-buttons {
display: flex;
border-bottom: 1px solid #ccc;
}

.wp-block-tabs__tab-button {
background: none;
border: none;
padding: 10px 15px;
cursor: pointer;

&.is-active {
border-bottom: 2px solid #007cba;
}
}

.wp-block-tabs__content {
padding: 15px 0;
}
}

.wp-block-tab {
display: none;

&.is-active {
display: block;
}
}

0 comments on commit eb97843

Please sign in to comment.