2021-02-11 23:43:21 +01:00
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
|
import { TouchableOpacityProps } from 'react-native';
|
2020-07-07 13:21:03 +02:00
|
|
|
import ChevronRight from 'assets/chevron-right.svg';
|
2021-02-11 23:43:21 +01:00
|
|
|
import styled, { css } from 'styled-components/native';
|
2020-07-10 15:25:32 +02:00
|
|
|
import { THEME_COLOR } from 'CONSTANTS';
|
2021-02-11 23:43:21 +01:00
|
|
|
import useDefaultStyles from './Colors';
|
2020-06-21 13:02:23 +02:00
|
|
|
|
2020-07-07 13:21:03 +02:00
|
|
|
const BUTTON_SIZE = 14;
|
|
|
|
|
|
2021-02-11 23:43:21 +01:00
|
|
|
const Container = styled.Pressable<{ active?: boolean }>`
|
|
|
|
|
padding: 18px 20px;
|
2020-06-21 13:02:23 +02:00
|
|
|
border-bottom-width: 1px;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
justify-content: space-between;
|
2021-02-11 23:43:21 +01:00
|
|
|
|
|
|
|
|
${props => props.active && css`
|
|
|
|
|
background-color: ${THEME_COLOR};
|
|
|
|
|
`}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Label = styled.Text<{ active?: boolean }>`
|
|
|
|
|
color: ${THEME_COLOR};
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
|
|
|
|
${props => props.active && css`
|
|
|
|
|
color: white;
|
|
|
|
|
`}
|
2020-06-21 13:02:23 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const ListButton: React.FC<TouchableOpacityProps> = ({ children, ...props }) => {
|
2021-02-11 23:43:21 +01:00
|
|
|
const defaultStyles = useDefaultStyles();
|
|
|
|
|
const [isPressed, setPressed] = useState(false);
|
|
|
|
|
const handlePressIn = useCallback(() => setPressed(true), []);
|
|
|
|
|
const handlePressOut = useCallback(() => setPressed(false), []);
|
|
|
|
|
|
2020-06-21 13:02:23 +02:00
|
|
|
return (
|
2022-01-02 19:29:20 +01:00
|
|
|
// @ts-expect-error styled-components has outdated react-native typings
|
2021-02-11 23:43:21 +01:00
|
|
|
<Container
|
|
|
|
|
{...props}
|
|
|
|
|
onPressIn={handlePressIn}
|
|
|
|
|
onPressOut={handlePressOut}
|
|
|
|
|
style={defaultStyles.border}
|
|
|
|
|
active={isPressed}
|
|
|
|
|
>
|
|
|
|
|
<Label active={isPressed}>{children}</Label>
|
|
|
|
|
<ChevronRight width={BUTTON_SIZE} height={BUTTON_SIZE} fill={isPressed ? '#fff' : THEME_COLOR} />
|
2020-06-21 13:02:23 +02:00
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ListButton;
|