Skip to content

Commit 306c488

Browse files
committed
UI(PG): filter card polish & sort select fixes
Refs ENG-83
1 parent 96efc5e commit 306c488

File tree

5 files changed

+26
-42
lines changed

5 files changed

+26
-42
lines changed

client/src/sites/pg/components/PgAlgoliaFacetsActive.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const tagStyle = {
1919
fontSize: "sm",
2020
color: "#908989",
2121
cursor: "pointer",
22-
css: { "&:hover .close-icon": { color: "red" } },
22+
css: { "&:hover .close-icon": { color: "brand.black" } },
2323
} as const;
2424

2525
export type FacetsActiveConfig = {

client/src/sites/pg/components/PgAlgoliaFilterCard.tsx

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Box, Collapsible, Flex, HStack, Icon, Stack } from "@chakra-ui/react";
2-
import React, { useEffect, useRef, type ReactNode, type RefObject } from "react";
2+
import { useEffect, useRef, type ReactNode } from "react";
33
import { LuChevronDown, LuSquareX } from "react-icons/lu";
44
import { useClearRefinements } from "react-instantsearch";
55
import {
@@ -8,42 +8,32 @@ import {
88
} from "@/sites/pg/components/PgAlgoliaFacetsActive";
99
import { useStateValtio } from "@neuronhub/shared/utils/useStateValtio";
1010

11-
export function PgFilterCardWithSplitBg(props: {
12-
children: ReactNode;
13-
isOpenRef: RefObject<boolean>;
14-
}) {
15-
const rootRef = useRef<HTMLDivElement>(null);
11+
export function PgFilterCardWithSplitBg(props: { children: ReactNode }) {
12+
const rootRef = useRef<HTMLDivElement | null>(null);
1613

1714
useEffect(() => {
18-
const rootElement = rootRef.current;
19-
if (!rootElement) {
20-
return;
21-
}
22-
const observer = new ResizeObserver(() => {
23-
if (!props.isOpenRef.current) {
15+
function measureSplitHeight() {
16+
const rootElement = rootRef.current;
17+
if (rootElement) {
2418
rootElement.style.setProperty("--split-bg-h", `${rootElement.offsetHeight / 2}px`);
2519
}
26-
});
27-
observer.observe(rootElement);
28-
return () => observer.disconnect();
20+
}
21+
measureSplitHeight();
22+
window.addEventListener("resize", measureSplitHeight);
23+
return () => window.removeEventListener("resize", measureSplitHeight);
2924
}, []);
3025

3126
return (
32-
<Box
33-
position="relative"
34-
ref={rootRef}
35-
style={{ "--split-bg-h": "50%" } as React.CSSProperties}
36-
>
27+
<Box ref={rootRef} pos="relative">
3728
<Box
38-
position="absolute"
29+
pos="absolute"
3930
top="0"
4031
left="-9999px"
4132
right="-9999px"
4233
h="var(--split-bg-h)"
4334
bg="brand.green"
4435
/>
45-
<Box position="absolute" top="var(--split-bg-h)" left="-9999px" right="-9999px" bg="bg" />
46-
<Box position="relative">{props.children}</Box>
36+
<Box pos="relative">{props.children}</Box>
4737
</Box>
4838
);
4939
}
@@ -75,7 +65,6 @@ export function PgMobileCollapsible(props: {
7565
cta?: ReactNode;
7666
facetsTopbar: ReactNode;
7767
facetsActive: FacetsActiveConfig;
78-
onOpenChange?: (open: boolean) => void;
7968
}) {
8069
const state = useStateValtio({ isOpen: false });
8170

@@ -84,7 +73,6 @@ export function PgMobileCollapsible(props: {
8473
open={state.snap.isOpen}
8574
onOpenChange={details => {
8675
state.mutable.isOpen = details.open;
87-
props.onOpenChange?.(details.open);
8876
}}
8977
>
9078
{!state.snap.isOpen && (

client/src/sites/pg/components/PgAlgoliaList.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Box, Grid, HStack, Stack } from "@chakra-ui/react";
2-
import { useRef, type ReactNode } from "react";
2+
import { type ReactNode } from "react";
33
import { InstantSearch } from "react-instantsearch";
44
import type { ID } from "@/gql-tada";
55
import type { FacetsActiveConfig } from "@/sites/pg/components/PgAlgoliaFacetsActive";
@@ -33,8 +33,6 @@ export function PgAlgoliaList<TItem extends { id: ID }, TData = unknown>(props:
3333
}) {
3434
const algolia = useAlgoliaSearchClient();
3535

36-
const pgFilterCardIsOpenRef = useRef(false);
37-
3836
const indexName = algolia[props.index];
3937

4038
if (algolia.loading || !algolia.client || !indexName) {
@@ -66,7 +64,7 @@ export function PgAlgoliaList<TItem extends { id: ID }, TData = unknown>(props:
6664
{props.children}
6765

6866
<Stack gap="gap.sm" w="full">
69-
<PgFilterCardWithSplitBg isOpenRef={pgFilterCardIsOpenRef}>
67+
<PgFilterCardWithSplitBg>
7068
{/* Mobile */}
7169
<Box
7270
hideFrom="md"
@@ -87,9 +85,6 @@ export function PgAlgoliaList<TItem extends { id: ID }, TData = unknown>(props:
8785
cta={props.ctaMobile ?? props.cta}
8886
facetsTopbar={props.facetsTopbar}
8987
facetsActive={props.facetsActive}
90-
onOpenChange={open => {
91-
pgFilterCardIsOpenRef.current = open;
92-
}}
9388
/>
9489
</Stack>
9590
</Box>
@@ -115,9 +110,9 @@ export function PgAlgoliaList<TItem extends { id: ID }, TData = unknown>(props:
115110

116111
<Box>{props.cta}</Box>
117112

118-
<PgFacetsActive facetsActive={props.facetsActive} />
119-
120113
<Box gridColumn="span 5">{props.facetsTopbar}</Box>
114+
115+
<PgFacetsActive facetsActive={props.facetsActive} />
121116
</Grid>
122117
</Box>
123118
</PgFilterCardWithSplitBg>

client/src/sites/pg/components/PgAlgoliaListSkeleton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PgHitSkeletons } from "@/sites/pg/components/PgAlgoliaInfiniteHits";
66
export function PgAlgoliaListSkeleton() {
77
return (
88
<Stack gap="gap.sm" w="full">
9-
<PgFilterCardWithSplitBg isOpenRef={{ current: false }}>
9+
<PgFilterCardWithSplitBg>
1010
<Box
1111
hideFrom="md"
1212
borderWidth="1px"

client/src/sites/pg/components/PgAlgoliaSortSelect.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ export function PgAlgoliaSortSelect(props: { items: Array<{ value: string; label
1717
<Select.HiddenSelect />
1818
<Select.Control>
1919
<Select.Trigger
20-
ps="0"
21-
fontWeight="500"
22-
fontSize="sm"
2320
bg="bg"
21+
px="0"
2422
color="brand.black"
23+
fontWeight="500"
24+
fontSize="sm"
2525
cursor="pointer"
26-
_hover={{ bg: "bg" }}
26+
_hover={{ bg: "bg", color: "brand.green.light" }}
2727
_focusVisible={{ outline: "none", boxShadow: "none" }}
2828
>
2929
<Select.ValueText />
30-
<Select.Indicator ms="gap.sm" color="brand.black" />
30+
<Select.Indicator ms="gap.sm" color="currentColor" />
3131
</Select.Trigger>
3232
</Select.Control>
3333
<Select.Positioner>
@@ -37,8 +37,9 @@ export function PgAlgoliaSortSelect(props: { items: Array<{ value: string; label
3737
borderWidth="1px"
3838
borderRadius="sm"
3939
p="3"
40-
w="fit-content"
40+
w="var(--select-trigger-width)"
4141
minW="unset"
42+
css={{ "& [role='option']": { paddingInline: "0", justifyContent: "flex-start" } }}
4243
>
4344
{collection.items.map(item => (
4445
<Select.Item

0 commit comments

Comments
 (0)