Added theme components. Reorganized them. Prepping for Tech Tracker Rewrite
This commit is contained in:
62
components/theme/inputs/ThemedSearchBar.tsx
Normal file
62
components/theme/inputs/ThemedSearchBar.tsx
Normal file
@ -0,0 +1,62 @@
|
||||
import React from 'react';
|
||||
import { StyleSheet, ViewProps, View, DimensionValue } from 'react-native';
|
||||
import { Ionicons } from '@expo/vector-icons';
|
||||
import { ThemedTextInput } from '@/components/theme';
|
||||
import { Colors } from '@/constants/Colors';
|
||||
import { useColorScheme } from '@/hooks/useColorScheme';
|
||||
|
||||
type ThemedSearchBarProps = ViewProps & {
|
||||
placeholder?: string;
|
||||
value: string;
|
||||
onChangeText: (text: string) => void;
|
||||
width?: DimensionValue;
|
||||
height?: number;
|
||||
};
|
||||
|
||||
const ThemedSearchBar: React.FC<ThemedSearchBarProps> = ({
|
||||
placeholder = 'Search',
|
||||
value,
|
||||
onChangeText,
|
||||
width = '100%',
|
||||
height = 40,
|
||||
style,
|
||||
...restProps
|
||||
}) => {
|
||||
const scheme = useColorScheme() ?? 'dark';
|
||||
|
||||
return (
|
||||
<View style={[styles.container, { width }, style]} {...restProps}>
|
||||
<Ionicons
|
||||
name="search"
|
||||
size={20}
|
||||
color={Colors[scheme].text}
|
||||
style={styles.icon}
|
||||
/>
|
||||
<ThemedTextInput
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
onChangeText={onChangeText}
|
||||
height={height}
|
||||
width={width}
|
||||
style={styles.input}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
},
|
||||
icon: {
|
||||
position: 'absolute',
|
||||
zIndex: 1,
|
||||
left: 15,
|
||||
},
|
||||
input: {
|
||||
paddingLeft: 45,
|
||||
},
|
||||
});
|
||||
|
||||
export default ThemedSearchBar;
|
26
components/theme/inputs/ThemedSwitch.tsx
Normal file
26
components/theme/inputs/ThemedSwitch.tsx
Normal file
@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import { Switch, SwitchProps } from 'react-native';
|
||||
import { Colors } from '@/constants/Colors';
|
||||
import { useColorScheme } from '@/hooks/useColorScheme';
|
||||
|
||||
type ThemedSwitchProps = SwitchProps;
|
||||
|
||||
const ThemedSwitch: React.FC<ThemedSwitchProps> = ({
|
||||
...props
|
||||
}) => {
|
||||
const scheme = useColorScheme() ?? 'dark';
|
||||
|
||||
return (
|
||||
<Switch
|
||||
trackColor={{
|
||||
false: Colors[scheme].border,
|
||||
true: Colors[scheme].tint + '80'
|
||||
}}
|
||||
thumbColor={props.value ? Colors[scheme].tint : Colors[scheme].card}
|
||||
ios_backgroundColor={Colors[scheme].border}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default ThemedSwitch;
|
63
components/theme/inputs/ThemedTextInput.tsx
Normal file
63
components/theme/inputs/ThemedTextInput.tsx
Normal file
@ -0,0 +1,63 @@
|
||||
import React from 'react';
|
||||
import { StyleSheet, TextInput, TextInputProps, DimensionValue } from 'react-native';
|
||||
import { ThemedView } from '@/components/theme';
|
||||
import { Colors } from '@/constants/Colors';
|
||||
import { useColorScheme } from '@/hooks/useColorScheme';
|
||||
|
||||
const DEFAULT_WIDTH = 320;
|
||||
const DEFAULT_HEIGHT = 50;
|
||||
|
||||
type ThemedTextInputProps = TextInputProps & {
|
||||
width?: DimensionValue;
|
||||
height?: DimensionValue
|
||||
containerStyle?: object;
|
||||
};
|
||||
|
||||
const ThemedTextInput: React.FC<ThemedTextInputProps> = ({
|
||||
width = DEFAULT_WIDTH,
|
||||
height = DEFAULT_HEIGHT,
|
||||
containerStyle,
|
||||
style,
|
||||
...restProps
|
||||
}) => {
|
||||
const scheme = useColorScheme() ?? 'dark';
|
||||
|
||||
return (
|
||||
<ThemedView
|
||||
style={[
|
||||
styles.inputContainer,
|
||||
{ width, height },
|
||||
containerStyle,
|
||||
]}
|
||||
>
|
||||
<TextInput
|
||||
style={[
|
||||
styles.input,
|
||||
{
|
||||
color: Colors[scheme].text,
|
||||
backgroundColor: Colors[scheme].background,
|
||||
},
|
||||
style,
|
||||
]}
|
||||
placeholderTextColor={Colors[scheme].text + '80'} // 50% opacity
|
||||
{...restProps}
|
||||
/>
|
||||
</ThemedView>
|
||||
);
|
||||
};
|
||||
|
||||
export default ThemedTextInput;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
inputContainer: {
|
||||
padding: 3,
|
||||
borderRadius: 10,
|
||||
},
|
||||
input: {
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
borderRadius: 8,
|
||||
paddingHorizontal: 15,
|
||||
fontSize: 16,
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user