Skip to content

Commit

Permalink
add variables to Navigation Block
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidHalkin committed Jul 18, 2024
1 parent 26c3a26 commit 17dd542
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions blocks/Navigation/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Block dependencies
*/
import metadata from '../block.json';

import variables from '../../../assets/build/variables.json';
/**
* Internal block libraries
*/
Expand All @@ -12,6 +12,22 @@ const {PanelBody, SelectControl, Spinner} = wp.components;
const {serverSideRender: ServerSideRender} = wp;
const {useState, useEffect} = wp.element;

const getExpandOptions = (breakpoints) => {
const options = [
{label: 'No responsive', value: 'navbar-expand'},
{label: 'Always expand', value: ''}
];

Object.keys(breakpoints).forEach(key => {
if (key !== 'xs') {
options.push({label: `${key.toUpperCase()} and under`, value: `navbar-expand-${key}`});
}
});

return options;
};
const expandOptions = getExpandOptions(variables['grid-breakpoints']);

registerBlockType(
metadata,
{
Expand Down Expand Up @@ -92,15 +108,7 @@ registerBlockType(
<SelectControl
label={`Expand menu:`}
value={attributes.expand}
options={[
{label: 'No responsive', value: 'navbar-expand'},
{label: 'SM and under', value: 'navbar-expand-sm'},
{label: 'MD and under', value: 'navbar-expand-md'},
{label: 'LG and under', value: 'navbar-expand-lg'},
{label: 'XL and under', value: 'navbar-expand-xl'},
{label: 'XXL and under', value: 'navbar-expand-xxl'},
{label: 'Always expand', value: ''},
]}
options={expandOptions}
onChange={(expand) => setAttributes({expand})}
/>
</PanelBody>
Expand Down

0 comments on commit 17dd542

Please sign in to comment.