Skip to content

Commit 4a1df3a

Browse files
HardeepAsraniselul
andauthored
feat: add Style Book to Neve's Customizer (#4448)
* feat: add Style Book to Neve's Customizer * Update aria-label for close button in style book * chore: use wp_get_theme to get desc * chore: skip focusing on customizer if clicked inside input fields * feat: take stylebook controls to specific controls * Update class verification for form group in tests * Change locator from page to iframe for form group * Remove clickable class verification from style book tests Removed verification for form clickable class in style book tests. --------- Co-authored-by: Marius Cristea <marius.cristea@vertistudio.com>
1 parent 8cd27f3 commit 4a1df3a

10 files changed

Lines changed: 1122 additions & 7 deletions

File tree

assets/apps/components/src/Controls/ColorControl.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import classnames from 'classnames';
1919
const ColorPickerFix = lazy(() => import('../Common/ColorPickerFix'));
2020

2121
const ColorControl = ({
22+
slug = null,
2223
label,
2324
selectedColor,
2425
onChange,
@@ -52,7 +53,8 @@ const ColorControl = ({
5253
};
5354

5455
const isGlobal = selectedColor && selectedColor.indexOf('var') > -1;
55-
const defaultGradient = 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)';
56+
const defaultGradient =
57+
'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)';
5658

5759
const handleClear = () => {
5860
onChange(defaultValue || '');
@@ -63,7 +65,10 @@ const ColorControl = ({
6365
const wrapClasses = classnames([
6466
'neve-control-header',
6567
'neve-color-component',
66-
{ 'allows-global': !disableGlobal },
68+
{
69+
'allows-global': !disableGlobal,
70+
[`neve-color-slug-${slug}`]: !!slug,
71+
},
6772
]);
6873

6974
const [gradient, setGradient] = useState(selectedColor);
@@ -159,7 +164,9 @@ const ColorControl = ({
159164
<div
160165
className="current-color-gradient"
161166
style={{
162-
background: selectedColor || defaultGradient,
167+
background:
168+
selectedColor ||
169+
defaultGradient,
163170
height: '177px',
164171
border: '1px solid #eee',
165172
minWidth: '215px',

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) {
@@ -355,6 +408,7 @@ window.wp.customize.bind('ready', () => {
355408
initBlogPageFocus();
356409
initSearchCustomizer();
357410
initLocalGoogleFonts();
411+
initStyleBookButton();
358412
previewScrollToTopChanges();
359413
});
360414

assets/apps/customizer-controls/src/global-colors/PaletteColors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const PaletteColors = ({ values, defaults, save }) => {
5252
<ColorControl
5353
disableGlobal
5454
key={slug}
55+
slug={slug}
5556
label={group[slug]}
5657
selectedColor={colors[slug]}
5758
defaultValue={

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

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

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

Lines changed: 211 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)