Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Attribute Filter block: Enable global style #5557

Merged
merged 16 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/js/base/components/dropdown-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import './style.scss';
* @param {Object} props Incoming props for the component.
* @param {string} props.attributeLabel Label for the attributes.
* @param {string} props.className CSS class used.
* @param {import('react').CSSProperties} props.style CSS style object used.
* @param {Array} props.checked Which items are checked.
* @param {string} props.inputLabel Label used for the input.
* @param {boolean} props.isDisabled Whether the input is disabled or not.
Expand All @@ -34,6 +35,7 @@ import './style.scss';
const DropdownSelector = ( {
attributeLabel = '',
className,
style = {},
checked = [],
inputLabel = '',
isDisabled = false,
Expand Down Expand Up @@ -105,6 +107,7 @@ const DropdownSelector = ( {
'has-checked': checked.length > 0,
'is-open': isOpen,
} ) }
style={ style }
>
{ /* eslint-disable-next-line jsx-a11y/label-has-for */ }
<label
Expand Down
10 changes: 9 additions & 1 deletion assets/js/blocks/attribute-filter/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import FilterSubmitButton from '@woocommerce/base-components/filter-submit-butto
import isShallowEqual from '@wordpress/is-shallow-equal';
import { decodeEntities } from '@wordpress/html-entities';
import { Notice } from '@wordpress/components';
import classNames from 'classnames';

/**
* Internal dependencies
*/
import { getAttributeFromID } from '../../utils/attributes';
import { updateAttributeFilter } from '../../utils/attributes-query';
import { previewAttributeObject, previewOptions } from './preview';
import { useBorderProps } from '../../hooks/style-attributes';
import './style.scss';

/**
Expand All @@ -50,6 +52,8 @@ const AttributeFilterBlock = ( {
: []
);

const borderProps = useBorderProps( blockAttributes );

const [ queryState ] = useQueryStateByContext();
const [
productAttributesQuery,
Expand Down Expand Up @@ -381,7 +385,11 @@ const AttributeFilterBlock = ( {
<DropdownSelector
attributeLabel={ attributeObject.label }
checked={ checked }
className={ 'wc-block-attribute-filter-dropdown' }
className={ classNames(
'wc-block-attribute-filter-dropdown',
borderProps.className
) }
style={ { ...borderProps.style, borderStyle: 'none' } }
inputLabel={ blockAttributes.heading }
isLoading={ isLoading }
multiple={ multiple }
Expand Down
12 changes: 9 additions & 3 deletions assets/js/blocks/attribute-filter/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
*/
import { __, sprintf, _n } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { InspectorControls, BlockControls } from '@wordpress/block-editor';
import {
InspectorControls,
BlockControls,
useBlockProps,
} from '@wordpress/block-editor';
import {
Placeholder,
Disabled,
Expand Down Expand Up @@ -47,6 +51,8 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak } ) => {
! attributeId && ! isPreview
);

const blockProps = useBlockProps();

const getBlockControls = () => {
return (
<BlockControls>
Expand Down Expand Up @@ -379,7 +385,7 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak } ) => {
return Object.keys( ATTRIBUTES ).length === 0 ? (
noAttributesPlaceholder()
) : (
<>
<div { ...blockProps }>
{ getBlockControls() }
{ getInspectorControls() }
{ isEditing ? (
Expand All @@ -404,7 +410,7 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak } ) => {
</Disabled>
</div>
) }
</>
</div>
);
};

Expand Down
13 changes: 13 additions & 0 deletions assets/js/blocks/attribute-filter/editor.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.editor-styles-wrapper .wp-block-woocommerce-attribute-filter {
// We need to override it because by default the global styles applied the border-style: solid;
// Our goal is not to have a border on main wrapper DOM element
border-style: none !important;
}


.wc-block-attribute-filter {
.components-placeholder__instructions {
border-bottom: 1px solid #e0e2e6;
Expand Down Expand Up @@ -33,4 +40,10 @@
display: block;
margin-bottom: 1em;
}

.components-disabled {
border-radius: inherit;
border-color: inherit;
}

}
18 changes: 17 additions & 1 deletion assets/js/blocks/attribute-filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import { useBlockProps } from '@wordpress/block-editor';
import { isFeaturePluginBuild } from '@woocommerce/block-settings';
import { Icon, category } from '@wordpress/icons';
import classNames from 'classnames';

Expand All @@ -12,6 +14,7 @@ import classNames from 'classnames';
import edit from './edit.js';

registerBlockType( 'woocommerce/attribute-filter', {
apiVersion: 2,
title: __( 'Filter Products by Attribute', 'woo-gutenberg-products-block' ),
icon: {
src: (
Expand All @@ -29,6 +32,17 @@ registerBlockType( 'woocommerce/attribute-filter', {
),
supports: {
html: false,
color: {
text: true,
background: false,
},
...( isFeaturePluginBuild() && {
__experimentalBorder: {
radius: true,
color: true,
width: false,
},
} ),
},
example: {
attributes: {
Expand Down Expand Up @@ -103,7 +117,9 @@ registerBlockType( 'woocommerce/attribute-filter', {
}
return (
<div
className={ classNames( 'is-loading', className ) }
{ ...useBlockProps.save( {
className: classNames( 'is-loading', className ),
} ) }
{ ...data }
>
<span
Expand Down
14 changes: 14 additions & 0 deletions assets/js/blocks/attribute-filter/style.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
.wp-block-woocommerce-attribute-filter {
// We need to override it because by default the global styles applied the border-style: solid;
// Our goal is not to have a border on main wrapper DOM element
border-style: none !important;
}

.wc-block-attribute-filter {
margin-bottom: $gap-large;
border-radius: inherit;
border-color: inherit;

&.style-dropdown {
display: flex;
gap: $gap;
border-radius: inherit;
border-color: inherit;
}

.wc-block-attribute-filter-list {
Expand All @@ -26,6 +36,8 @@
flex-grow: 1;
max-width: unset;
width: 0;
border-radius: inherit;
border-color: inherit;
}

.is-single .wc-block-attribute-filter-list-count,
Expand All @@ -35,5 +47,7 @@

.wc-block-components-dropdown-selector__input-wrapper {
height: 100%;
border-radius: inherit;
border-color: inherit;
}
}
1 change: 1 addition & 0 deletions assets/js/blocks/featured-category/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
bottom: 0;
right: 0;
background-color: inherit;
border-radius: inherit;
opacity: 0.5;
z-index: 1;
}
Expand Down