Skip to content

Commit

Permalink
feat: add ListingGroup props (#162)
Browse files Browse the repository at this point in the history
* feat: add props

* feat: add isOpen prop
  • Loading branch information
cliu02 authored Jan 3, 2025
1 parent 17f214c commit 1566f8a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/page_components/listing/ListingsGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react"
import React, { useState, useEffect } from "react"
import { Button } from "../../actions/Button"
import { Icon, UniversalIconType } from "../../icons/Icon"
import "./ListingsGroup.scss"
Expand All @@ -11,6 +11,9 @@ export interface ListingsGroupProps {
info?: string
listingsCount: number
showButtonText: string
refKey?: string
observerRef?: React.MutableRefObject<null | IntersectionObserver>
isOpen?: boolean
}

const ListingsGroup = (props: ListingsGroupProps) => {
Expand All @@ -19,6 +22,12 @@ const ListingsGroup = (props: ListingsGroupProps) => {

const listingsCount = ` (${props.listingsCount})`

useEffect(() => {
if (props.isOpen) {
setShowListings(true)
}
}, [props.isOpen])

return (
<div className="listings-group">
<div className="listings-group__header">
Expand All @@ -27,7 +36,17 @@ const ListingsGroup = (props: ListingsGroupProps) => {
<Icon size="xlarge" symbol={props.icon ?? `clock`} />
</div>
<div className="listings-group__header-group">
<h2 className="listings-group__title">{props.header}</h2>
<h2
id={props.refKey ?? props.header}
ref={(el) => {
if (el) {
props.observerRef?.current?.observe(el)
}
}}
className="listings-group__title"
>
{props.header}
</h2>
{props.info && <div className="listings-group__info">{props.info}</div>}
</div>
</div>
Expand Down

0 comments on commit 1566f8a

Please sign in to comment.