Make logic in List with HOVER and ONCLICK events
This commit is contained in:
parent
ce4db33072
commit
91b25d953b
|
@ -1,16 +1,35 @@
|
||||||
import { XStack, YStack } from 'tamagui'
|
import { useState } from 'react';
|
||||||
import { Avatar, Checkbox, Text } from '@status-im/components'
|
import { XStack, YStack } from 'tamagui';
|
||||||
import { VerifiedIcon, ContactIcon } from '@status-im/icons'
|
import { Avatar, Checkbox, Text } from '@status-im/components';
|
||||||
|
import { VerifiedIcon, ContactIcon } from '@status-im/icons';
|
||||||
|
|
||||||
|
type ValidatorListItemProps = {
|
||||||
|
name: string;
|
||||||
|
avatarKey: string;
|
||||||
|
selected?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ValidatorListItem = ({ name, avatarKey, selected }: ValidatorListItemProps) => {
|
||||||
|
const [hovered, setHovered] = useState(false);
|
||||||
|
const [isSelected, setIsSelected] = useState(selected);
|
||||||
|
|
||||||
|
const handleMouseEnter = () => setHovered(true);
|
||||||
|
const handleMouseLeave = () => setHovered(false);
|
||||||
|
const handleClick = () => setIsSelected(!isSelected);
|
||||||
|
|
||||||
|
const backgroundColor = isSelected || hovered ? 'rgba(42, 74, 245, 0.05)' : 'transparent';
|
||||||
|
|
||||||
const ValidatorListItem = () => {
|
|
||||||
return (
|
return (
|
||||||
<XStack
|
<XStack
|
||||||
|
onMouseEnter={handleMouseEnter}
|
||||||
|
onMouseLeave={handleMouseLeave}
|
||||||
|
onClick={handleClick}
|
||||||
justifyContent="space-between"
|
justifyContent="space-between"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
style={{
|
style={{
|
||||||
padding: '6px 8px',
|
padding: '6px 8px',
|
||||||
borderRadius: '12px',
|
borderRadius: '12px',
|
||||||
backgroundColor: 'rgba(42, 74, 245, 0.05);',
|
backgroundColor: backgroundColor,
|
||||||
}}
|
}}
|
||||||
width="90%"
|
width="90%"
|
||||||
>
|
>
|
||||||
|
@ -31,15 +50,17 @@ const ValidatorListItem = () => {
|
||||||
/>
|
/>
|
||||||
<YStack pl="8px">
|
<YStack pl="8px">
|
||||||
<Text size={13} weight={'semibold'}>
|
<Text size={13} weight={'semibold'}>
|
||||||
Validator 1
|
{name}
|
||||||
<VerifiedIcon size={20} /> <ContactIcon size={20} />
|
<VerifiedIcon size={20} /> <ContactIcon size={20} />
|
||||||
</Text>
|
</Text>
|
||||||
<Text size={13}>Validator 1</Text>
|
<Text size={13}>{avatarKey}</Text>
|
||||||
</YStack>
|
</YStack>
|
||||||
</XStack>
|
</XStack>
|
||||||
<Checkbox id="" variant="outline" size={20} selected />
|
{isSelected &&
|
||||||
|
<Checkbox id="" variant="outline" size={20} selected={isSelected} />
|
||||||
|
}
|
||||||
</XStack>
|
</XStack>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ValidatorListItem
|
export default ValidatorListItem;
|
||||||
|
|
Loading…
Reference in New Issue