Skip to content

Commit

Permalink
fix #389
Browse files Browse the repository at this point in the history
  • Loading branch information
inc2734 committed Oct 7, 2024
1 parent 7c1d98e commit 5edf24c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"node": "20.11.1"
},
"devDependencies": {
"@inc2734/unitone-css": "^0.60.9",
"@inc2734/unitone-css": "^0.61.0",
"@wordpress/env": "^10.9.0",
"@wordpress/icons": "^10.9.0",
"@wordpress/interface": "^6.9.0",
Expand Down
7 changes: 6 additions & 1 deletion src/blocks/switcher/block.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"version": "10.9.0",
"version": "14.1.0",
"textdomain": "unitone",
"name": "unitone/switcher",
"title": "Switcher",
"description": "This block switches the direction of contents flow depending on its contents.",
"attributes": {
"revert": {
"type": "boolean",
"default": false
},
"threshold": {
"type": "string",
"default": "var(--wp--style--global--content-size)"
Expand Down Expand Up @@ -41,6 +45,7 @@
}
},
"unitone": {
"alignItems": true,
"gap": {
"splitOnAxis": true
},
Expand Down
33 changes: 31 additions & 2 deletions src/blocks/switcher/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {

import {
TextControl,
ToggleControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
Expand All @@ -20,7 +21,7 @@ import { __, sprintf } from '@wordpress/i18n';
import metadata from './block.json';

export default function ( { attributes, setAttributes, clientId } ) {
const { threshold, templateLock } = attributes;
const { revert, threshold, templateLock } = attributes;

const hasInnerBlocks = useSelect(
( select ) =>
Expand All @@ -36,7 +37,10 @@ export default function ( { attributes, setAttributes, clientId } ) {
} );
blockProps[ 'data-unitone-layout' ] = clsx(
'switcher',
blockProps[ 'data-unitone-layout' ]
blockProps[ 'data-unitone-layout' ],
{
'-revert': revert,
}
);

const innerBlocksProps = useInnerBlocksProps( blockProps, {
Expand Down Expand Up @@ -95,6 +99,31 @@ export default function ( { attributes, setAttributes, clientId } ) {
} }
/>
</ToolsPanelItem>

<ToolsPanelItem
hasValue={ () =>
revert !== metadata.attributes.revert.default
}
isShownByDefault
label={ __( 'Revert', 'unitone' ) }
onDeselect={ () =>
setAttributes( {
revert: metadata.attributes.revert.default,
} )
}
>
<ToggleControl
label={ __( 'Revert', 'unitone' ) }
help={ __(
'In single-column display, by default, the elements on the left side of the two-column display are displayed on top, but when enabled, the elements on the right side of the two-column display are displayed on top.',
'unitone'
) }
checked={ revert }
onChange={ ( newAttribute ) => {
setAttributes( { revert: newAttribute } );
} }
/>
</ToolsPanelItem>
</ToolsPanel>
</InspectorControls>

Expand Down
8 changes: 6 additions & 2 deletions src/blocks/switcher/save.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import clsx from 'clsx';

import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';

export default function ( { attributes } ) {
const { threshold } = attributes;
const { revert, threshold } = attributes;

return (
<div
{ ...useInnerBlocksProps.save(
useBlockProps.save( {
'data-unitone-layout': 'switcher',
'data-unitone-layout': clsx( 'switcher', {
'-revert': revert,
} ),
style: {
'--unitone--threshold': threshold || undefined,
},
Expand Down

0 comments on commit 5edf24c

Please sign in to comment.