| 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 |
'bg-transparent text-gray-900': !active, |
| 18 |
'bg-gray-900 text-gray-50': active, |
| 19 |
}, |
| 20 |
)}> |
| 21 |
{tax?.title ?? tax.slug} |
| 22 |
</span> |
| 23 |
</button> |
| 24 |
</li> |
| 25 |
) |
| 26 |
} |
| 27 |
|
| 28 |
export const TaxonomySection = ({ taxType, taxonomies, taxLabel }) => { |
| 29 |
const searchParams = useTemplatesStore((state) => state.searchParams) |
| 30 |
const updateTaxonomies = useTemplatesStore( |
| 31 |
(state) => state.updateTaxonomies, |
| 32 |
) |
| 33 |
if (!taxonomies?.length > 0) return null |
| 34 |
|
| 35 |
return ( |
| 36 |
<PanelBody |
| 37 |
title={getTaxonomyName(taxLabel ?? taxType)} |
| 38 |
className="ext-type-control p-0" |
| 39 |
initialOpen={true}> |
| 40 |
<PanelRow> |
| 41 |
<div className="relative w-full overflow-hidden"> |
| 42 |
<ul className="m-0 w-full px-5 py-1"> |
| 43 |
{taxonomies.map((tax) => { |
| 44 |
const update = () => |
| 45 |
updateTaxonomies({ [taxType]: tax }) |
| 46 |
const isCurrentTax = |
| 47 |
searchParams?.taxonomies[taxType]?.slug === |
| 48 |
tax?.slug |
| 49 |
return ( |
| 50 |
<SingleTaxItem |
| 51 |
key={tax?.slug} |
| 52 |
active={isCurrentTax} |
| 53 |
tax={tax} |
| 54 |
update={update} |
| 55 |
/> |
| 56 |
) |
| 57 |
})} |
| 58 |
</ul> |
| 59 |
</div> |
| 60 |
</PanelRow> |
| 61 |
</PanelBody> |
| 62 |
) |
| 63 |
} |
| 64 |
|