icns-frontend/components/chain-list/chain-list.tsx
2022-12-19 00:49:45 +09:00

62 lines
1.6 KiB
TypeScript

import { Dispatch, FunctionComponent, SetStateAction, useEffect } from "react";
import { ChainItemType, DisabledChainItemType } from "../../types";
import color from "../../styles/color";
import styled from "styled-components";
import { ChainItem } from "./chain-item";
interface Props {
chainList: ChainItemType[];
disabledChainList: DisabledChainItemType[];
checkedItems: Set<unknown>;
setCheckedItems: Dispatch<SetStateAction<Set<unknown>>>;
}
export const ChainList: FunctionComponent<Props> = (props) => {
const { chainList, disabledChainList, checkedItems, setCheckedItems } = props;
const checkedItemHandler = (chainItem: ChainItemType, isChecked: boolean) => {
const tempSet = new Set(checkedItems);
if (isChecked) {
tempSet.add(chainItem);
} else if (!isChecked && checkedItems.has(chainItem)) {
tempSet.delete(chainItem);
}
setCheckedItems(tempSet);
};
return (
<ChainContainer color={color.grey["900"]}>
{chainList.map((chainItem) => (
<ChainItem
key={chainItem.chainId}
chainItem={chainItem}
checkedItemHandler={checkedItemHandler}
checkedItems={checkedItems}
/>
))}
{disabledChainList.map((chainItem) => (
<ChainItem
key={chainItem.chainId}
chainItem={chainItem}
checkedItemHandler={checkedItemHandler}
checkedItems={checkedItems}
/>
))}
</ChainContainer>
);
};
export const ChainContainer = styled.div`
display: flex;
flex-direction: column;
width: 100%;
//max-height: 33rem;
overflow-y: scroll;
flex: 1;
background-color: ${(props) => props.color};
`;