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

93 lines
2.1 KiB
TypeScript
Raw Normal View History

import { ChainItemType } from "../../types";
import {
ChangeEvent,
Dispatch,
FunctionComponent,
SetStateAction,
useEffect,
useState,
} from "react";
2022-12-09 11:59:52 +00:00
import {
ChainImageContainer,
ChainInfoContainer,
ChainItemContainer,
} from "./chain-list";
import color from "../../styles/color";
2022-12-12 06:51:25 +00:00
import { Flex1 } from "../../styles/flex-1";
2022-12-09 11:59:52 +00:00
import styled from "styled-components";
import { ChainImage } from "./chain-image";
2022-12-09 11:59:52 +00:00
interface Props {
chainItem: ChainItemType;
checkedItemHandler: (chainItem: ChainItemType, isChecked: boolean) => void;
checkedItems: Set<unknown>;
2022-12-09 11:59:52 +00:00
}
export const ChainItem: FunctionComponent<Props> = (props) => {
const { chainItem, checkedItemHandler, checkedItems } = props;
const [checked, setChecked] = useState(false);
const checkHandler = () => {
setChecked(!checked);
checkedItemHandler(chainItem, !checked);
};
useEffect(() => {
setChecked(checkedItems.has(chainItem));
}, [checkedItems]);
2022-12-09 11:59:52 +00:00
return (
<ChainItemContainer
key={chainItem.prefix}
isLoading={false}
onClick={checkHandler}
>
2022-12-09 11:59:52 +00:00
<ChainImageContainer width="3rem" height="3rem">
<ChainImage
src={chainItem.chainImageUrl}
2022-12-09 11:59:52 +00:00
fill={true}
alt={`${chainItem.prefix} chain image`}
2022-12-09 11:59:52 +00:00
/>
</ChainImageContainer>
<ChainInfoContainer>
<ChainName>{`.${chainItem.prefix}`}</ChainName>
<WalletAddress>{chainItem.address}</WalletAddress>
2022-12-09 11:59:52 +00:00
</ChainInfoContainer>
<Flex1 />
<ChainCheckBox checked={checked} />
2022-12-09 11:59:52 +00:00
</ChainItemContainer>
);
};
export const ChainName = styled.div`
2022-12-09 11:59:52 +00:00
font-weight: 600;
font-size: 0.8rem;
line-height: 1rem;
color: ${color.white};
2022-12-09 11:59:52 +00:00
`;
export const WalletAddress = styled.div`
2022-12-09 11:59:52 +00:00
font-weight: 500;
font-size: 0.8rem;
line-height: 1rem;
max-height: 2rem;
max-width: 27rem;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
2022-12-09 11:59:52 +00:00
color: ${color.grey["400"]};
`;
export const ChainCheckBox = styled.input.attrs({ type: "checkbox" })`
2022-12-09 11:59:52 +00:00
width: 1.5rem;
height: 1.5rem;
`;