icns-frontend/components/chain-list/chain-list.tsx

62 lines
1.6 KiB
TypeScript
Raw Normal View History

import { Dispatch, FunctionComponent, SetStateAction, useEffect } from "react";
import { ChainItemType, DisabledChainItemType } from "../../types";
2022-12-09 11:59:52 +00:00
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>>>;
2022-12-09 11:59:52 +00:00
}
export const ChainList: FunctionComponent<Props> = (props) => {
2022-12-17 13:10:38 +00:00
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);
};
2022-12-09 11:59:52 +00:00
return (
2022-12-15 15:43:18 +00:00
<ChainContainer color={color.grey["900"]}>
{chainList.map((chainItem) => (
<ChainItem
2022-12-18 12:09:34 +00:00
key={chainItem.chainId}
chainItem={chainItem}
checkedItemHandler={checkedItemHandler}
checkedItems={checkedItems}
/>
2022-12-09 11:59:52 +00:00
))}
2022-12-15 10:06:44 +00:00
{disabledChainList.map((chainItem) => (
<ChainItem
2022-12-18 12:09:34 +00:00
key={chainItem.chainId}
2022-12-15 10:06:44 +00:00
chainItem={chainItem}
checkedItemHandler={checkedItemHandler}
checkedItems={checkedItems}
/>
))}
2022-12-09 11:59:52 +00:00
</ChainContainer>
);
};
export const ChainContainer = styled.div`
display: flex;
flex-direction: column;
width: 100%;
2022-12-15 15:43:18 +00:00
//max-height: 33rem;
2022-12-18 15:49:45 +00:00
overflow-y: scroll;
2022-12-09 11:59:52 +00:00
2022-12-15 15:43:18 +00:00
flex: 1;
2022-12-09 11:59:52 +00:00
background-color: ${(props) => props.color};
`;