|
| 1 | +import cn from "classnames" |
1 | 2 | import { useIntl } from "react-intl" |
2 | 3 | import useTrends from "../../../hooks/useTrends" |
3 | 4 | import useOptions from "../../../hooks/useOptions" |
| 5 | +import { useTrendsContext } from "../../../context" |
| 6 | +import { useState } from "react" |
| 7 | +import { TextInput } from "@dataesr/dsfr-plus" |
4 | 8 |
|
5 | 9 | export default function TrendsTableHeader() { |
6 | 10 | const intl = useIntl() |
| 11 | + const [openSearch, setOpenSearch] = useState(false) |
| 12 | + const { includes, setIncludes } = useTrendsContext() |
7 | 13 | const { trendsYears } = useTrends() |
8 | 14 | const { currentModel } = useOptions() |
9 | 15 |
|
| 16 | + const handleOpenSearchChange = () => { |
| 17 | + if (openSearch === true) setIncludes("") // reset includes if closing |
| 18 | + setOpenSearch(!openSearch) |
| 19 | + } |
| 20 | + |
10 | 21 | return ( |
11 | 22 | <thead> |
12 | 23 | <tr> |
13 | | - <th>Rank</th> |
14 | | - <th>{intl.formatMessage({ id: `trends.ranking.header.domains` })}</th> |
| 24 | + <th className={cn("action", openSearch ? "open" : "")} onClick={handleOpenSearchChange}> |
| 25 | + {<span className="fr-icon-search-line" />} |
| 26 | + </th> |
| 27 | + <th> |
| 28 | + {openSearch ? ( |
| 29 | + <TextInput value={includes} placeholder="Search topics" onChange={(event) => setIncludes(event.target.value)} /> |
| 30 | + ) : ( |
| 31 | + intl.formatMessage({ id: `trends.ranking.header.domains` }) |
| 32 | + )} |
| 33 | + </th> |
15 | 34 | <th>{intl.formatMessage({ id: `trends.ranking.header.count` }, { max: trendsYears.max })}</th> |
16 | 35 | <th title={`The variation between the volume in ${trendsYears.max} and the previous years average volume`}> |
17 | 36 | {intl.formatMessage({ id: `trends.ranking.header.variation` })} |
|
0 commit comments