PluginProbe
Extendify / 0.9.2
Extendify v0.9.2
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Library / components / TaxonomySection.js

TaxonomySection.js in Extendify 0.9.2, at src/Library/components/TaxonomySection.js

64 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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