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

Commit

Permalink
Attribute Filter block: enable global style #4965
Browse files Browse the repository at this point in the history
Attribute Filter block: enable global style #4965
  • Loading branch information
gigitux committed Jan 12, 2022
1 parent c2cab62 commit 6d6b1e7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
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 {Object} 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 @@ -26,6 +26,8 @@ import { getAttributeFromID } from '../../utils/attributes';
import { updateAttributeFilter } from '../../utils/attributes-query';
import { previewAttributeObject, previewOptions } from './preview';
import './style.scss';
import { useBorderProps } from '../../hooks/style-attributes';
import classNames from 'classnames';

/**
* Component displaying an attribute filter.
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
7 changes: 5 additions & 2 deletions assets/js/blocks/attribute-filter/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import HeadingToolbar from '@woocommerce/editor-components/heading-toolbar';
import BlockTitle from '@woocommerce/editor-components/block-title';
import ToggleButtonControl from '@woocommerce/editor-components/toggle-button-control';
import classnames from 'classnames';
import { useBlockProps } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -47,6 +48,8 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak } ) => {
! attributeId && ! isPreview
);

const blockProps = useBlockProps();

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

Expand Down
11 changes: 11 additions & 0 deletions assets/js/blocks/attribute-filter/editor.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.editor-styles-wrapper .wp-block-woocommerce-attribute-filter {
border-style: none !important;
}


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

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

}
23 changes: 21 additions & 2 deletions assets/js/blocks/attribute-filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import { Icon, server } from '@woocommerce/icons';
import { useBlockProps } from '@wordpress/block-editor';
import { isFeaturePluginBuild } from '@woocommerce/block-settings';
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,8 +117,13 @@ registerBlockType( 'woocommerce/attribute-filter', {
}
return (
<div
className={ classNames( 'is-loading', className ) }
{ ...data }
{ ...useBlockProps.save( {
className: classNames( 'is-loading', className ),
style: {
border: 'unset',
},
data,
} ) }
>
<span
aria-hidden
Expand Down
12 changes: 12 additions & 0 deletions assets/js/blocks/attribute-filter/style.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
.wp-block-woocommerce-attribute-filter {
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 +34,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 +45,7 @@

.wc-block-components-dropdown-selector__input-wrapper {
height: 100%;
border-radius: inherit;
border-color: inherit;
}
}

0 comments on commit 6d6b1e7

Please sign in to comment.