Skip to content

Commit

Permalink
Feature/line value selector (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Canciller authored Apr 6, 2022
1 parent 0cb5716 commit 84239cb
Show file tree
Hide file tree
Showing 15 changed files with 731 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
'no-constant-condition': 'off',
'no-empty': 'off',
'no-unused-vars': 'off',
'object-shorthand': ['warn', 'always'],

// react
'react/prop-types': 'off',
Expand Down
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"react-native-haptic-feedback": "^1.13.1",
"react-native-mask-input": "^1.2.0",
"react-native-reanimated": "2.3.1",
"react-native-redash": "^16.2.3",
"react-native-safe-area-context": "^4.2.2",
"react-native-screens": "^3.13.1",
"react-native-svg": "^12.3.0"
Expand Down
4 changes: 4 additions & 0 deletions example/src/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Switch } from '@nomada-sh/react-native-eyecandy';
import { useTheme as useEyecandyTheme } from '@nomada-sh/react-native-eyecandy-theme';
import { createDrawerNavigator } from '@react-navigation/drawer';

import LineValueSelectors from '../LineValueSelectors';
import TextInputs from '../TextInputs';
import { useTheme } from '../shared/hooks';

Expand All @@ -15,12 +16,15 @@ export default function Drawer() {

return (
<Navigator
initialRouteName="LineValueSelectors"
screenOptions={{
headerTintColor: colors.text.default.normal,
headerRight: () => <Switch value={dark} onValueChange={setDark} />,
swipeEnabled: false,
}}
>
<Screen name="TextInputs" component={TextInputs} />
<Screen name="LineValueSelectors" component={LineValueSelectors} />
</Navigator>
);
}
143 changes: 143 additions & 0 deletions example/src/LineValueSelectors/LineValueSelectors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import React from 'react';
import { View, ScrollView, useWindowDimensions } from 'react-native';

import {
Body,
Button,
TextInputV2,
LineValueSelector,
useLineValueSelector,
} from '@nomada-sh/react-native-eyecandy';

export default function TextInputs() {
const { width } = useWindowDimensions();

const [increment, setIncrement] = React.useState(1);
const [min, setMin] = React.useState(0);
const [max, setMax] = React.useState(230);

const { props, setValue, value } = useLineValueSelector({
initialValue: 140,
max,
min,
increment,
});

const { props: props2, value: value2 } = useLineValueSelector({
initialValue: 30,
max: 100,
min: 15,
increment: 0.1,
});

return (
<ScrollView
contentContainerStyle={{
flex: 1,
justifyContent: 'flex-end',
}}
>
<View>
<TextInputV2
defaultValue={String(min)}
onChangeText={text => {
if (!Number.isNaN(Number(text))) setMin(Number(text));
}}
/>
<TextInputV2
defaultValue={String(max)}
onChangeText={text => {
if (!Number.isNaN(Number(text))) setMax(Number(text));
}}
/>
<TextInputV2
defaultValue={String(increment)}
onChangeText={text => {
if (!Number.isNaN(Number(text))) setIncrement(Number(text));
}}
/>
<Button
text="Increment"
onPress={() => {
const newValue = value + increment;
if (newValue <= max) setValue(newValue);
}}
/>
<Button
text="Decrement"
onPress={() => {
const newValue = value - increment;
if (newValue >= min) setValue(newValue);
}}
/>
<Body
style={{
padding: 40,
fontSize: 48,
textAlign: 'right',
}}
weight="bold"
>
{value.toFixed(2)} cm
</Body>
<Body
style={{
padding: 40,
fontSize: 48,
textAlign: 'right',
}}
weight="bold"
>
{value2.toFixed(2)} kg
</Body>
<View
style={{
backgroundColor: '#3e39ea',
paddingTop: 40,
paddingBottom: 60,
borderTopLeftRadius: 30,
}}
>
<LineValueSelector
width={width}
tickCount={4}
ticksWidth={80}
ticksColor="white"
indicatorColor="#49dbe9"
indicatorTickPosition={2}
{...props}
/>
<LineValueSelector
width={width}
tickCount={4}
ticksWidth={80}
ticksColor="white"
indicatorColor="#49dbe9"
indicatorTickPosition={2}
{...props2}
/>
<View
style={{
marginHorizontal: 40,
marginTop: 20,
}}
>
<Body
size="xlarge"
customColor="white"
weight="bold"
style={{
marginBottom: 20,
}}
>
Lorem ipsum dolor
</Body>
<Body customColor="white">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</Body>
</View>
</View>
</View>
</ScrollView>
);
}
1 change: 1 addition & 0 deletions example/src/LineValueSelectors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './LineValueSelectors';
2 changes: 1 addition & 1 deletion example/src/TextInputs/TextInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function TextInputs() {
padding: 20,
}}
>
<PhoneTextInput {...phoneInputProps} />
<PhoneTextInput placeholder="0000" {...phoneInputProps} />

<TextInputV2 iconLeft={Lock} placeholder="test" error required />
<TextInput
Expand Down
7 changes: 5 additions & 2 deletions packages/react-native-eyecandy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@
"react-native-gesture-handler": "^2.2.0",
"react-native-haptic-feedback": "^1.13.0",
"react-native-image-picker": "^4.4.2",
"react-native-reanimated": "2.3.1"
"react-native-reanimated": "2.3.1",
"react-native-svg": "^12.3.0"
},
"peerDependencies": {
"react": "*",
"react-native": "*",
"react-native-gesture-handler": "^2.2.0",
"react-native-haptic-feedback": "^1.13.0",
"react-native-image-picker": "^4.4.2",
"react-native-reanimated": "^2.3.1"
"react-native-reanimated": "^2.3.1",
"react-native-svg": "^12.3.0"
},
"dependencies": {
"@nomada-sh/react-native-eyecandy-icons": "^1.0.5",
Expand All @@ -87,6 +89,7 @@
"react-native-country-picker-modal": "^2.0.0",
"react-native-mask-input": "^1.2.0",
"react-native-picker-select": "^8.0.4",
"react-native-redash": "^16.2.3",
"react-use": "^17.3.2",
"rn-swipe-button": "^1.3.6"
}
Expand Down
Loading

0 comments on commit 84239cb

Please sign in to comment.