-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathconcepts.jsx
More file actions
59 lines (53 loc) · 1.8 KB
/
concepts.jsx
File metadata and controls
59 lines (53 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { useState } from 'preact/hooks'
import { openUIConceptsByComponent } from '../sources'
import './concepts.css'
import Concept from './concept'
const Concepts = ({ component }) => {
const [showDescriptions, setShowDescriptions] = useState(false)
const [collapseAll, toggleCollapseAll] = useState(true)
const conceptsForComponent = Object.entries(openUIConceptsByComponent[component] || []).sort(
([_a, conceptsA], [_b, conceptsB]) => conceptsA.length - conceptsB.length,
)
return (
<>
<div className="concepts">
<label htmlFor="descriptions">
<input
type="checkbox"
id="descriptions"
checked={showDescriptions}
aria-checked={showDescriptions}
onChange={() => setShowDescriptions((isDescShown) => !isDescShown)}
/>
Show descriptions
</label>
<label htmlFor="collapse">
<input
type="checkbox"
id="collapse"
checked={collapseAll}
aria-checked={collapseAll}
onChange={() => toggleCollapseAll((isCollapsed) => !isCollapsed)}
/>
{collapseAll ? 'Collapse all' : 'Expand all'}
</label>
</div>
{conceptsForComponent.map(([conceptOpenUIName, concepts]) => {
const uniqueNames = Array.from(new Set(concepts.map((concept) => concept.name)))
const hasOtherNames = uniqueNames.length > 1
return (
<Concept
conceptOpenUIName={conceptOpenUIName}
hasOtherNames={hasOtherNames}
component={component}
uniqueNames={uniqueNames}
showDescriptions={showDescriptions}
key={conceptOpenUIName}
initExpand={collapseAll}
/>
)
})}
</>
)
}
export default Concepts