Skip to content

Commit 962f810

Browse files
committed
wip
1 parent 26789c8 commit 962f810

File tree

3 files changed

+38
-85
lines changed

3 files changed

+38
-85
lines changed

src/app/conf/2025/schedule/_components/filters.tsx

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111

1212
import { Tag } from "@/app/conf/_design-system/tag"
1313
import { Button } from "@/app/conf/_design-system/button"
14+
import { CheckboxIcon } from "@/app/conf/_design-system/checkbox-icon"
1415

1516
import CloseIcon from "@/app/conf/_design-system/pixelarticons/close.svg?svgr"
1617
import CaretDownIcon from "@/app/conf/_design-system/pixelarticons/caret-down.svg?svgr"
@@ -217,41 +218,6 @@ function FiltersCombobox({
217218
)
218219
}
219220

220-
interface CheckboxIconProps extends React.SVGProps<SVGSVGElement> {
221-
checked: boolean
222-
}
223-
function CheckboxIcon({ checked, ...rest }: CheckboxIconProps) {
224-
return (
225-
<svg
226-
xmlns="http://www.w3.org/2000/svg"
227-
width="20"
228-
height="20"
229-
viewBox="0 0 20 20"
230-
fill="currentColor"
231-
{...rest}
232-
>
233-
{!checked ? (
234-
<>
235-
<path
236-
fillRule="evenodd"
237-
clipRule="evenodd"
238-
d="M2.5 2.5H4.16667H15.8333H17.5V17.5H15.8333H4.16667H2.5V2.5ZM15.8333 15.8333V4.16667H4.16667V15.8333H15.8333Z"
239-
/>
240-
</>
241-
) : (
242-
<g className="[&>path]:fill-neu-0">
243-
<rect x="2" y="3" width="15" height="15" />
244-
<path d="M6 10.3333H7.66667V12H6V10.3333Z" />
245-
<path d="M7.66667 12H9.33333V13.6667H7.66667V12Z" />
246-
<path d="M9.33333 10.3333H11V12H9.33333V10.3333Z" />
247-
<path d="M11 8.66667H12.6667V10.3333H11V8.66667Z" />
248-
<path d="M12.6667 7H14.3333V8.66667H12.6667V7Z" />
249-
</g>
250-
)}
251-
</svg>
252-
)
253-
}
254-
255221
function FilterComboboxOption({
256222
active,
257223
selected,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export interface CheckboxIconProps extends React.SVGProps<SVGSVGElement> {
2+
checked: boolean
3+
}
4+
export function CheckboxIcon({ checked, ...rest }: CheckboxIconProps) {
5+
return (
6+
<svg
7+
xmlns="http://www.w3.org/2000/svg"
8+
width="20"
9+
height="20"
10+
viewBox="0 0 20 20"
11+
fill="currentColor"
12+
{...rest}
13+
>
14+
{!checked ? (
15+
<>
16+
<path
17+
fillRule="evenodd"
18+
clipRule="evenodd"
19+
d="M2.5 2.5H4.16667H15.8333H17.5V17.5H15.8333H4.16667H2.5V2.5ZM15.8333 15.8333V4.16667H4.16667V15.8333H15.8333Z"
20+
/>
21+
</>
22+
) : (
23+
<g className="[&>path]:fill-neu-0">
24+
<rect x="2" y="3" width="15" height="15" />
25+
<path d="M6 10.3333H7.66667V12H6V10.3333Z" />
26+
<path d="M7.66667 12H9.33333V13.6667H7.66667V12Z" />
27+
<path d="M9.33333 10.3333H11V12H9.33333V10.3333Z" />
28+
<path d="M11 8.66667H12.6667V10.3333H11V8.66667Z" />
29+
<path d="M12.6667 7H14.3333V8.66667H12.6667V7Z" />
30+
</g>
31+
)}
32+
</svg>
33+
)
34+
}

src/components/checkbox-tree/checkbox-tree.tsx

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { ReactNode } from "react"
2-
import { useEffect, useMemo, useState } from "react"
3-
import { clsx } from "clsx"
4-
5-
import { ChevronLeftIcon } from "@/icons"
2+
import { useMemo } from "react"
63

74
export interface CheckboxTreeItem {
85
id: string
@@ -38,7 +35,7 @@ export function CheckboxTree({
3835
}: CheckboxTreeProps) {
3936
const normalizedSearch = searchQuery?.trim().toLowerCase() ?? ""
4037

41-
const { allParentIds, defaultExpanded, preparedItems } = useMemo(() => {
38+
const { preparedItems } = useMemo(() => {
4239
const parentIds = new Set<string>()
4340
const defaultOpen = new Set<string>()
4441

@@ -70,23 +67,10 @@ export function CheckboxTree({
7067

7168
return {
7269
allParentIds: parentIds,
73-
defaultExpanded: defaultOpen,
7470
preparedItems: enhance(items, 0),
7571
}
7672
}, [items, normalizedSearch])
7773

78-
const [expandedItems, setExpandedItems] = useState(
79-
() => new Set(defaultExpanded),
80-
)
81-
82-
useEffect(() => {
83-
if (!normalizedSearch) {
84-
setExpandedItems(new Set(defaultExpanded))
85-
return
86-
}
87-
setExpandedItems(new Set(allParentIds))
88-
}, [normalizedSearch, allParentIds, defaultExpanded])
89-
9074
const filteredTree = useMemo(() => {
9175
function markVisibility(node: PreparedTree): PreparedTree | null {
9276
const { children } = node
@@ -121,21 +105,8 @@ export function CheckboxTree({
121105
}
122106
}
123107

124-
const toggleExpand = (id: string) => {
125-
setExpandedItems(prev => {
126-
const next = new Set(prev)
127-
if (next.has(id)) {
128-
next.delete(id)
129-
} else {
130-
next.add(id)
131-
}
132-
return next
133-
})
134-
}
135-
136108
const renderTree = (nodes: PreparedTree[]): ReactNode => {
137109
return nodes.map(node => {
138-
const isExpanded = expandedItems.has(node.id)
139110
const isSelectable = Boolean(node.value)
140111
const checkboxId = `checkbox-tree-${node.id}`
141112

@@ -145,24 +116,6 @@ export function CheckboxTree({
145116
className="flex items-start gap-2 py-1"
146117
style={{ paddingInlineStart: node.depth * 16 }}
147118
>
148-
{node.children && node.children.length > 0 ? (
149-
<button
150-
type="button"
151-
aria-expanded={isExpanded}
152-
onClick={() => toggleExpand(node.id)}
153-
className="mt-0.5 flex size-5 items-center justify-center text-neu-500 transition-colors hover:text-pri-base"
154-
>
155-
<ChevronLeftIcon
156-
className={clsx(
157-
"size-4 transition-transform",
158-
isExpanded ? "-rotate-90" : "rotate-180",
159-
)}
160-
/>
161-
</button>
162-
) : (
163-
<span className="mt-0.5 block size-5" aria-hidden />
164-
)}
165-
166119
{isSelectable ? (
167120
<label
168121
htmlFor={checkboxId}
@@ -196,7 +149,7 @@ export function CheckboxTree({
196149
)}
197150
</div>
198151

199-
{node.children && node.children.length > 0 && isExpanded ? (
152+
{node.children && node.children.length > 0 ? (
200153
<div>{renderTree(node.children)}</div>
201154
) : null}
202155
</div>

0 commit comments

Comments
 (0)