|
| 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