| 1 |
import { PanelBody, PanelRow } from '@wordpress/components' |
| 2 |
import classNames from 'classnames' |
| 3 |
import { useTemplatesStore } from '@library/state/Templates' |
| 4 |
import { getTaxonomyName } from '@library/util/general' |
| 5 |
|
| 6 |
const SingleTaxItem = ({ active, tax, update }) => { |
| 7 |
return ( |
| 8 |
<li className="m-0 w-full" key={tax.slug}> |
| 9 |
<button |
| 10 |
type="button" |
| 11 |
className="group m-0 p-0 flex w-full cursor-pointer text-left text-sm leading-none my-px bg-transparent" |
| 12 |
onClick={update}> |
| 13 |
<span |
| 14 |
className={classNames( |
| 15 |
'w-full group-hover:bg-gray-900 p-2 group-hover:text-gray-50 rounded', |
| 16 |
{ |
| 17 |
'group-hover:bg-design-main': |
| 18 |
window.extendifyData?.partnerLogo, |
| 19 |
'bg-transparent text-gray-900': |
| 20 |
!active && !window.extendifyData?.partnerLogo, |
| 21 |
'bg-gray-900 text-gray-50': |
| 22 |
active && !window.extendifyData?.partnerLogo, |
| 23 |
'bg-design-main text-gray-50': |
| 24 |
active && window.extendifyData?.partnerLogo, |
| 25 |
}, |
| 26 |
)}> |
| 27 |
{tax?.title ?? tax.slug} |
| 28 |
</span> |
| 29 |
</button> |
| 30 |
</li> |
| 31 |
) |
| 32 |
} |
| 33 |
|
| 34 |
export const TaxonomySection = ({ taxType, taxonomies, taxLabel }) => { |
| 35 |
const searchParams = useTemplatesStore((state) => state.searchParams) |
| 36 |
const updateTaxonomies = useTemplatesStore( |
| 37 |
(state) => state.updateTaxonomies, |
| 38 |
) |
| 39 |
if (!taxonomies?.length > 0) return null |
| 40 |
|
| 41 |
return ( |
| 42 |
<PanelBody |
| 43 |
title={getTaxonomyName(taxLabel ?? taxType)} |
| 44 |
className="ext-type-control p-0" |
| 45 |
initialOpen={true}> |
| 46 |
<PanelRow> |
| 47 |
<div className="relative w-full overflow-hidden"> |
| 48 |
<ul id="filter-patterns" className="m-0 w-full px-5 py-1"> |
| 49 |
{taxonomies.map((tax) => { |
| 50 |
const update = () => |
| 51 |
updateTaxonomies({ [taxType]: tax }) |
| 52 |
const isCurrentTax = |
| 53 |
searchParams?.taxonomies[taxType]?.slug === |
| 54 |
tax?.slug |
| 55 |
return ( |
| 56 |
<SingleTaxItem |
| 57 |
key={tax?.slug} |
| 58 |
active={isCurrentTax} |
| 59 |
tax={tax} |
| 60 |
update={update} |
| 61 |
/> |
| 62 |
) |
| 63 |
})} |
| 64 |
</ul> |
| 65 |
</div> |
| 66 |
</PanelRow> |
| 67 |
</PanelBody> |
| 68 |
) |
| 69 |
} |
| 70 |
|