| 1 |
import { PanelBody, PanelRow } from '@wordpress/components' |
| 2 |
import classNames from 'classnames' |
| 3 |
import { useTemplatesStore } from '../state/Templates' |
| 4 |
import { getTaxonomyName } from '../util/general' |
| 5 |
|
| 6 |
export default function TaxonomySection({ taxType, taxonomies }) { |
| 7 |
const updateTaxonomies = useTemplatesStore( |
| 8 |
(state) => state.updateTaxonomies, |
| 9 |
) |
| 10 |
const searchParams = useTemplatesStore((state) => state.searchParams) |
| 11 |
|
| 12 |
if (!taxonomies?.length > 0) return null |
| 13 |
return ( |
| 14 |
<PanelBody |
| 15 |
title={getTaxonomyName(taxType)} |
| 16 |
className="ext-type-control p-0" |
| 17 |
initialOpen={true}> |
| 18 |
<PanelRow> |
| 19 |
<div className="overflow-hidden w-full relative"> |
| 20 |
<ul className="px-5 py-1 m-0 w-full"> |
| 21 |
{taxonomies.map((tax) => { |
| 22 |
const isCurrentTax = |
| 23 |
searchParams?.taxonomies[taxType]?.slug === |
| 24 |
tax?.slug |
| 25 |
return ( |
| 26 |
<li className="m-0 w-full" key={tax.slug}> |
| 27 |
<button |
| 28 |
type="button" |
| 29 |
className="text-left text-sm cursor-pointer w-full flex justify-between items-center px-0 py-2 m-0 leading-none bg-transparent hover:text-wp-theme-500 transition duration-200 button-focus" |
| 30 |
onClick={() => |
| 31 |
updateTaxonomies({ [taxType]: tax }) |
| 32 |
}> |
| 33 |
<span |
| 34 |
className={classNames({ |
| 35 |
'text-wp-theme-500': |
| 36 |
isCurrentTax, |
| 37 |
})}> |
| 38 |
{tax?.title ?? tax.slug} |
| 39 |
</span> |
| 40 |
</button> |
| 41 |
</li> |
| 42 |
) |
| 43 |
})} |
| 44 |
</ul> |
| 45 |
</div> |
| 46 |
</PanelRow> |
| 47 |
</PanelBody> |
| 48 |
) |
| 49 |
} |
| 50 |
|