mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
Update variable name
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
import styled, { css } from 'styled-components';
|
import styled, { css } from 'styled-components';
|
||||||
|
|
||||||
const StyledFilter = styled.div`
|
const StyledOrder = styled.div`
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
@@ -9,11 +9,11 @@ const StyledFilter = styled.div`
|
|||||||
gap: 10px;
|
gap: 10px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
interface IFilterBtn {
|
interface IOrderBtn {
|
||||||
active: boolean;
|
active: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FilterButton = styled.button<IFilterBtn>`
|
const OrderButton = styled.button<IOrderBtn>`
|
||||||
border: none;
|
border: none;
|
||||||
|
|
||||||
${(props) =>
|
${(props) =>
|
||||||
@@ -34,18 +34,18 @@ const FilterButton = styled.button<IFilterBtn>`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
interface IFilterProps {
|
interface IOrderProps {
|
||||||
options: {
|
options: {
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const OrderBy = ({ options }: IFilterProps) => {
|
const OrderBy = ({ options }: IOrderProps) => {
|
||||||
const field = 'orderBy';
|
const field = 'orderBy';
|
||||||
|
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
const currentFilter = searchParams.get(field) || options[0].value;
|
const currentOrder = searchParams.get(field) || options[0].value;
|
||||||
|
|
||||||
const handleClick = (value: string) => {
|
const handleClick = (value: string) => {
|
||||||
searchParams.set(field, value);
|
searchParams.set(field, value);
|
||||||
@@ -54,18 +54,18 @@ const OrderBy = ({ options }: IFilterProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledFilter>
|
<StyledOrder>
|
||||||
{options.map((option) => (
|
{options.map((option) => (
|
||||||
<FilterButton
|
<OrderButton
|
||||||
key={option.value}
|
key={option.value}
|
||||||
onClick={() => handleClick(option.value)}
|
onClick={() => handleClick(option.value)}
|
||||||
active={option.value === currentFilter}
|
active={option.value === currentOrder}
|
||||||
disabled={option.value === currentFilter}
|
disabled={option.value === currentOrder}
|
||||||
>
|
>
|
||||||
{option.label}
|
{option.label}
|
||||||
</FilterButton>
|
</OrderButton>
|
||||||
))}
|
))}
|
||||||
</StyledFilter>
|
</StyledOrder>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user