icns-frontend/components/chain-list/all-chains-item.tsx

79 lines
1.9 KiB
TypeScript
Raw Normal View History

import { ChainItemType } from "../../types";
2022-12-17 13:10:38 +00:00
import {
Dispatch,
FunctionComponent,
SetStateAction,
useEffect,
useState,
} from "react";
2022-12-15 10:06:44 +00:00
import { ChainImage } from "./chain-image";
import { Flex1 } from "../../styles/flex-1";
import {
ChainInfoContainer,
ChainItemContainer,
2022-12-15 10:06:44 +00:00
ChainName,
WalletAddress,
} from "./chain-item";
import color from "../../styles/color";
import styled from "styled-components";
import { Checkbox } from "../checkbox";
2022-12-17 13:10:38 +00:00
import AllChainsIcon from "../../public/images/svg/all-chains-icon.svg";
interface Props {
2022-12-17 13:10:38 +00:00
chainList: ChainItemType[];
checkedItems: Set<unknown>;
setCheckedItems: Dispatch<SetStateAction<Set<unknown>>>;
}
export const AllChainsItem: FunctionComponent<Props> = (props) => {
2022-12-17 13:10:38 +00:00
const { chainList, checkedItems, setCheckedItems } = props;
const [checked, setChecked] = useState(false);
const checkHandler = () => {
2022-12-17 13:10:38 +00:00
if (checked) {
setCheckedItems(new Set());
} else if (chainList.length !== checkedItems.size) {
setCheckedItems(new Set(chainList));
}
};
2022-12-17 13:10:38 +00:00
useEffect(() => {
if (chainList.length === checkedItems.size && checkedItems.size !== 0) {
setChecked(true);
} else {
setChecked(false);
}
}, [checkedItems]);
return (
<AllChainsContainer>
<ChainItemContainer
2022-12-17 13:10:38 +00:00
key="all chains"
isLoading={false}
2022-12-17 13:10:38 +00:00
checked={checked}
onClick={checkHandler}
>
2022-12-17 13:10:38 +00:00
<ChainImage src={AllChainsIcon} fill={true} alt={`all chain images`} />
<ChainInfoContainer>
2022-12-17 13:10:38 +00:00
<ChainName>{`.all chains(${chainList.length})`}</ChainName>
<WalletAddress>
{chainList.map((chain) => chain.chainName).join(", ")}
</WalletAddress>
</ChainInfoContainer>
<Flex1 />
2022-12-17 13:10:38 +00:00
<Checkbox checked={checked} />
</ChainItemContainer>
</AllChainsContainer>
);
};
const AllChainsContainer = styled.div`
width: 100%;
2022-12-15 15:43:18 +00:00
background-color: ${color.grey["900"]};
`;