Files
jellyfin-audio-player/src/components/ListButton.tsx

51 lines
1.6 KiB
TypeScript
Raw Normal View History

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';
import styled, { css } from 'styled-components/native';
2020-07-10 15:25:32 +02:00
import { THEME_COLOR } from 'CONSTANTS';
import useDefaultStyles from './Colors';
2020-06-21 13:02:23 +02:00
2020-07-07 13:21:03 +02:00
const BUTTON_SIZE = 14;
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;
${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 }) => {
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
<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;