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

48 lines
1.2 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';
import { Gap } from './Utility';
2020-06-17 14:58:04 +02:00
2022-11-13 11:25:57 +01:00
export interface InputProps extends TextInputProps {
icon?: React.ReactNode
}
const Container = styled.Pressable`
2022-11-13 11:25:57 +01:00
margin: 6px 0;
border-radius: 8px;
2022-11-13 11:25:57 +01:00
display: flex;
flex-direction: row;
align-items: center;
${Platform.select({
ios: css`padding: 12px;`,
android: css`padding: 4px 12px;`,
})}
`;
2022-11-13 11:25:57 +01:00
const InputWrapper = styled.TextInput`
margin: 0;
padding: 0;
2020-06-17 14:58:04 +02:00
`;
2022-11-13 11:25:57 +01:00
function Input({ icon = null, style, ...rest }: InputProps) {
const defaultStyles = useDefaultStyles();
const inputRef = useRef<TextInput | null>(null);
const handlePress = useCallback(() => inputRef.current?.focus(), []);
2022-11-13 11:25:57 +01:00
return (
<Container style={[defaultStyles.input, style]} onPress={handlePress}>
2022-11-13 11:25:57 +01:00
{icon && (
<>
{icon}
<Gap size={8} />
</>
)}
<InputWrapper {...rest} ref={inputRef} />
2022-11-13 11:25:57 +01:00
</Container>
);
}
2020-06-17 14:58:04 +02:00
export default Input;