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

65 lines
1.6 KiB
TypeScript
Raw Normal View History

import React, { useCallback, useRef } from 'react';
import { Platform, TextInput, TextInputProps } from 'react-native';
import styled, { css } from 'styled-components/native';
2022-11-13 11:25:57 +01:00
import useDefaultStyles from './Colors';
2020-06-17 14:58:04 +02:00
2022-11-13 11:25:57 +01:00
export interface InputProps extends TextInputProps {
2022-11-28 22:56:22 +01:00
icon?: React.ReactNode;
2022-11-13 11:25:57 +01:00
}
2023-04-22 21:58:27 +02:00
const Container = styled.Pressable<{ hasIcon?: boolean }>`
position: relative;
2022-11-13 11:25:57 +01:00
margin: 6px 0;
2023-04-22 21:58:27 +02:00
border-radius: 12px;
2022-11-13 11:25:57 +01:00
display: flex;
${Platform.select({
ios: css`padding: 12px;`,
android: css`padding: 4px 12px;`,
})}
2023-04-22 21:58:27 +02:00
${({ hasIcon }) => hasIcon && css`
padding-left: 36px;
`}
`;
const IconWrapper = styled.View`
position: absolute;
left: 0;
top: 0;
bottom: 0;
display: flex;
justify-content: center;
padding-left: 12px;
2022-11-13 11:25:57 +01:00
`;
2022-11-28 22:56:22 +01:00
function Input({ icon = null, style, testID, ...rest }: InputProps) {
2022-11-13 11:25:57 +01:00
const defaultStyles = useDefaultStyles();
const inputRef = useRef<TextInput | null>(null);
const handlePress = useCallback(() => inputRef.current?.focus(), []);
2022-11-13 11:25:57 +01:00
return (
2023-04-22 21:58:27 +02:00
<Container
style={[defaultStyles.input, style]}
onPress={handlePress}
testID={`${testID}-container`}
accessible={false}
hasIcon={!!icon}
>
2022-11-13 11:25:57 +01:00
{icon && (
2023-04-22 21:58:27 +02:00
<IconWrapper>
2022-11-13 11:25:57 +01:00
{icon}
2023-04-22 21:58:27 +02:00
</IconWrapper>
2022-11-13 11:25:57 +01:00
)}
<TextInput
{...rest}
style={[defaultStyles.text, { margin: 0, padding: 0 }]}
ref={inputRef}
testID={`${testID}-textinput`}
/>
2022-11-13 11:25:57 +01:00
</Container>
);
}
2020-06-17 14:58:04 +02:00
export default Input;