Skip to content

Commit 9e9ac4c

Browse files
committed
feat: add Style Book to Neve's Customizer
1 parent 1b521a8 commit 9e9ac4c

File tree

8 files changed

+1025
-4
lines changed

8 files changed

+1025
-4
lines changed

assets/apps/customizer-controls/src/controls.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,59 @@ const initSearchCustomizer = () => {
168168
);
169169
};
170170

171+
const initStyleBookButton = () => {
172+
const headerContainer = document.getElementById('customize-header-actions');
173+
174+
if (!headerContainer) {
175+
return;
176+
}
177+
178+
// Initialize the Style Book state if it doesn't exist
179+
if (!wp.customize.state.has('neveStyleBookOpen')) {
180+
wp.customize.state.create('neveStyleBookOpen', false);
181+
}
182+
183+
// Create the Style Book button
184+
const button = document.createElement('button');
185+
button.name = 'neve-style-book';
186+
button.id = 'neve-style-book';
187+
button.className = 'button-secondary button';
188+
button.title = __('Style Book', 'neve');
189+
button.innerHTML = `
190+
<i class="dashicons dashicons-admin-appearance"></i>
191+
<span class="screen-reader-text">${__('Style Book', 'neve')}</span>
192+
`;
193+
194+
// Add click handler
195+
button.addEventListener('click', (e) => {
196+
e.preventDefault();
197+
198+
// Toggle the state in customizer
199+
const currentState = wp.customize.state('neveStyleBookOpen').get();
200+
const newState = !currentState;
201+
wp.customize.state('neveStyleBookOpen').set(newState);
202+
203+
// Send message to preview
204+
wp.customize.previewer.send('neve-toggle-style-book', newState);
205+
});
206+
207+
// Append to header container
208+
headerContainer.appendChild(button);
209+
210+
// Restore state when preview is ready
211+
wp.customize.previewer.bind('ready', () => {
212+
const currentState = wp.customize.state('neveStyleBookOpen').get();
213+
if (currentState) {
214+
wp.customize.previewer.send('neve-restore-style-book-state', true);
215+
}
216+
});
217+
218+
// Listen for state changes from preview
219+
wp.customize.previewer.bind('neve-style-book-state-changed', (newState) => {
220+
wp.customize.state('neveStyleBookOpen').set(newState);
221+
});
222+
};
223+
171224
const initCustomPagesFocus = () => {
172225
const { sectionsFocus } = window.NeveReactCustomize;
173226
if (sectionsFocus !== undefined) {
@@ -311,6 +364,7 @@ window.wp.customize.bind('ready', () => {
311364
initBlogPageFocus();
312365
initSearchCustomizer();
313366
initLocalGoogleFonts();
367+
initStyleBookButton();
314368
});
315369

316370
window.HFG = {

assets/apps/customizer-controls/src/scss/_general.scss

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,42 @@
157157
width: 100%;
158158
}
159159
}
160+
161+
// Style Book button styles
162+
#customize-header-actions {
163+
#neve-style-book {
164+
display: block;
165+
position: absolute;
166+
top: 0;
167+
bottom: 0;
168+
left: 48px;
169+
width: 45px;
170+
margin-top: 0 !important;
171+
padding: 0;
172+
background: #f0f0f1;
173+
border: none;
174+
border-radius: 0;
175+
border-top: 4px solid #f0f0f1;
176+
border-right: 1px solid #dcdcde;
177+
color: #3c434a;
178+
fill: #3c434a;
179+
stroke: #3c434a;
180+
text-align: center;
181+
cursor: pointer;
182+
transition: color 0.15s ease-in-out, border-color 0.15s ease-in-out, background 0.15s ease-in-out;
183+
184+
.dashicons {
185+
font-size: 22px;
186+
line-height: 1.2;
187+
width: 22px;
188+
height: 22px;
189+
}
190+
191+
&:hover,
192+
&:focus {
193+
color: #0073aa;
194+
border-top-color: #0073aa;
195+
background: #fff;
196+
}
197+
}
198+
}

assets/js/src/customizer-preview/app.js

Lines changed: 122 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)