Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facet by Meta Range block UI. #3337

Merged
merged 12 commits into from
Mar 1, 2023
61 changes: 56 additions & 5 deletions assets/css/facets.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
:root {
--ep-range-slider-background-color: #fff;
--ep-range-slider-track-color: #eee;

@media ( min-width: 768px ) {
--ep-range-slider-thumb-size: 1.25em;
--ep-range-slider-track-size: 0.5em;
}
}

.widget_ep-facet,
.wp-block-elasticpress-facet {

Expand Down Expand Up @@ -34,19 +44,19 @@
& .level-1 {
padding-left: 20px;
}

& .level-2 {
padding-left: 40px;
}

& .level-3 {
padding-left: 60px;
}

& .level-4 {
padding-left: 80px;
}

& .level-5 {
padding-left: 100px;
}
Expand All @@ -55,7 +65,7 @@
cursor: pointer;
opacity: 1;
}

& .term a {
align-items: center;
display: flex;
Expand Down Expand Up @@ -95,3 +105,44 @@
.ep-checkbox.checked::after {
display: block;
}

.ep-range-facet {
align-items: center;
display: grid;
grid-template-columns: 1fr max-content;
}

.ep-range-facet__slider {
grid-column: 1 / -1;
}

.ep-range-facet__actions {
justify-content: end;
}

.ep-range-slider {
align-items: center;
display: flex;
margin: 0.5em 0;
min-height: var(--ep-range-slider-thumb-size);
}

.ep-range-slider__track {
background: var(--ep-range-slider-track-color);
border-radius: calc(var(--ep-range-slider-track-size) / 2);
height: var(--ep-range-slider-track-size);
}

.ep-range-slider__track-1 {
background-color: currentcolor; /* stylelint-disable-line scale-unlimited/declaration-strict-value */
}

.ep-range-slider__thumb {
background-color: currentcolor; /* stylelint-disable-line scale-unlimited/declaration-strict-value */
border-radius: calc(var(--ep-range-slider-thumb-size) / 2);
box-shadow:
inset 0 0 0 calc(var(--ep-range-slider-thumb-size) / 10) currentcolor,
inset 0 0 0 calc((var(--ep-range-slider-thumb-size) - var(--ep-range-slider-track-size)) / 2) var(--ep-range-slider-background-color);
height: var(--ep-range-slider-thumb-size);
width: var(--ep-range-slider-thumb-size);
}
13 changes: 11 additions & 2 deletions assets/js/blocks/facets/meta-range/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
"facet": {
"type": "string",
"default": ""
},
"prefix": {
"type": "string",
"default": ""
},
"suffix": {
"type": "string",
"default": ""
}
},
"supports": {
"html": false
},
"editorScript": "ep-facets-meta-range-block-script",
"style": "elasticpress-facets"
}
"style": "elasticpress-facets",
"viewScript": "ep-facets-meta-range-block-view-script"
}
53 changes: 53 additions & 0 deletions assets/js/blocks/facets/meta-range/components/range-facet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* External dependencies.
*/
import ReactSlider from 'react-slider';

/**
* WordPress dependencies.
*/
import { WPElement } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
* Range facet component.
*
* @param {object} props Props.
* @param {number} props.min Minimum value.
* @param {number} props.max Maximum value.
* @param {string} props.prefix Value prefix.
* @param {string} props.suffix Value suffix.
* @param {number[]} props.value Currnet value.
* @returns {WPElement} Component element.
*/
export default ({ min, max, prefix, suffix, value, ...props }) => {
return (
<div className="ep-range-facet">
<div className="ep-range-facet__slider">
<ReactSlider
className="ep-range-slider"
minDistance={1}
thumbActiveClassName="ep-range-slider__thumb--active"
thumbClassName="ep-range-slider__thumb"
trackClassName="ep-range-slider__track"
min={min}
max={max}
value={value}
{...props}
/>
</div>
<div className="ep-range-facet__values">
{prefix}
{value[0]}
{suffix}
{' — '}
{prefix}
{value[1]}
{suffix}
</div>
<div className="ep-range-facet__action">
<button type="submit">{__('Filter', 'elasticpress')}</button>
</div>
</div>
);
};
Loading