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

65 lines
1.8 KiB
TypeScript
Raw Normal View History

import React, { useCallback, useState } from 'react';
2023-07-21 13:07:10 +03:00
import { StyleSheet, TouchableOpacityProps, View } from 'react-native';
2023-06-19 23:03:17 +02:00
import ChevronRight from '@/assets/icons/chevron-right.svg';
2022-05-11 23:57:30 +02:00
import styled from 'styled-components/native';
2023-06-19 22:26:41 +02:00
import { THEME_COLOR } from '@/CONSTANTS';
import useDefaultStyles from './Colors';
2023-07-21 13:07:10 +03:00
import { Text } from './Typography';
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 }>`
2022-05-11 23:57:30 +02:00
padding: 14px 16px;
border-radius: 8px;
margin: 4px 8px;
2020-06-21 13:02:23 +02:00
flex-direction: row;
justify-content: space-between;
2022-05-11 23:57:30 +02:00
align-items: center;
`;
const Label = styled.Text<{ active?: boolean }>`
color: ${THEME_COLOR};
font-size: 16px;
2023-07-21 13:07:10 +03:00
display: flex;
2020-06-21 13:02:23 +02:00
`;
2023-07-21 13:07:10 +03:00
function generateListButtonStyles() {
const styles = useDefaultStyles();
return StyleSheet.create({
...styles,
descriptionNote: {
display: 'flex',
flexDirection: 'column'
},
showDescription: {
display: 'flex'
},
hideDescription: {
display: 'none'
}
})
}
2020-06-21 13:02:23 +02:00
const ListButton: React.FC<TouchableOpacityProps> = ({ children, ...props }) => {
2023-07-21 13:07:10 +03:00
const defaultStyles = generateListButtonStyles();
const [isPressed, setPressed] = useState(false);
const handlePressIn = useCallback(() => setPressed(true), []);
const handlePressOut = useCallback(() => setPressed(false), []);
2020-06-21 13:02:23 +02:00
return (
<Container
{...props}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
2022-05-11 23:57:30 +02:00
style={[
defaultStyles.border,
isPressed ? defaultStyles.activeBackground : undefined
]}
>
2022-05-11 23:57:30 +02:00
<Label>{children}</Label>
<ChevronRight width={BUTTON_SIZE} height={BUTTON_SIZE} fill={THEME_COLOR} />
2020-06-21 13:02:23 +02:00
</Container>
);
};
export default ListButton;