-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e85226
commit edae8f8
Showing
11 changed files
with
237 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { useState } from 'react'; | ||
import { SafeAreaView } from 'react-native'; | ||
import { Slider, Text } from 'react-native-ficus-ui'; | ||
import ExampleSection from '@/src/ExampleSection'; | ||
|
||
const SliderComponent = () => { | ||
const [value, setValue] = useState(0.2); | ||
|
||
return ( | ||
<SafeAreaView> | ||
<Text mx="xl" fontSize="4xl"> | ||
Slider | ||
</Text> | ||
<ExampleSection name="Slider"> | ||
<Slider /> | ||
<Slider colorScheme="green" defaultValue={0.2} /> | ||
<Slider colorScheme="red" defaultValue={0.3} /> | ||
<Slider colorScheme="orange" defaultValue={0.5} /> | ||
<Slider colorScheme="pink" filledTrackColor="pink.100" /> | ||
</ExampleSection> | ||
|
||
<ExampleSection name="Slider value"> | ||
<Text>Slider value : {Math.round(value * 100) / 100}</Text> | ||
<Slider colorScheme="teal" value={value} onValueChange={setValue} /> | ||
</ExampleSection> | ||
|
||
<ExampleSection name="Slider custom step"> | ||
<Slider colorScheme="orange" step={0.2} /> | ||
</ExampleSection> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
export default SliderComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as React from 'react'; | ||
import RNSlider from '@react-native-community/slider'; | ||
|
||
import { getStyle } from './slider.style'; | ||
import type { SliderProps } from './slider.type'; | ||
import { useTheme } from '../../theme/theme.hook'; | ||
import { useDefaultProps } from '../../utilities/useDefaultProps'; | ||
import { handleResponsiveProps } from '../../types'; | ||
import { getThemeColor } from '../../theme/theme.service'; | ||
|
||
const Slider: React.FunctionComponent<SliderProps> = (incomingProps) => { | ||
const { theme, windowWidth } = useTheme(); | ||
const props = useDefaultProps( | ||
'Slider', | ||
handleResponsiveProps(incomingProps, theme, windowWidth), | ||
{ | ||
flexDirection: 'column', | ||
flexWrap: 'nowrap', | ||
min: 0, | ||
max: 1, | ||
filledTrackColor: 'gray.200', | ||
colorScheme: 'blue', | ||
} | ||
); | ||
|
||
const { | ||
bg, | ||
h, | ||
w, | ||
m, | ||
mt, | ||
mr, | ||
mb, | ||
ml, | ||
ms, | ||
p, | ||
pr, | ||
pt, | ||
pb, | ||
pl, | ||
minH, | ||
minW, | ||
maxW, | ||
maxH, | ||
position, | ||
style, | ||
flexDirection, | ||
direction, | ||
children, | ||
bgImg, | ||
bgMode, | ||
alignItems, | ||
align, | ||
justifyContent, | ||
justify, | ||
flexWrap, | ||
wrap, | ||
flexGrow, | ||
grow, | ||
flexBasis, | ||
basis, | ||
flexShrink, | ||
shrink, | ||
opacity, | ||
top, | ||
left, | ||
right, | ||
bottom, | ||
zIndex, | ||
min, | ||
max, | ||
colorScheme, | ||
filledTrackColor, | ||
defaultValue, | ||
...rest | ||
} = props; | ||
const computedStyle = getStyle(theme, props); | ||
|
||
return ( | ||
<RNSlider | ||
minimumValue={min} | ||
maximumValue={max} | ||
value={defaultValue} | ||
minimumTrackTintColor={getThemeColor(theme.colors, `${colorScheme}.500`)} | ||
maximumTrackTintColor={getThemeColor(theme.colors, filledTrackColor)} | ||
style={computedStyle.slider} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
export { Slider }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
import { | ||
createPositionStyle, | ||
createSpacingStyles, | ||
getThemeColor, | ||
} from '../../theme/theme.service'; | ||
import type { SliderProps } from './slider.type'; | ||
import type { ThemeType } from '../../theme/type'; | ||
|
||
/** | ||
* computed style | ||
* | ||
* @param theme | ||
* @param props | ||
*/ | ||
export const getStyle = (theme: ThemeType, props: SliderProps) => { | ||
const computedStyle: any = {}; | ||
|
||
computedStyle.slider = { | ||
flexDirection: props.direction ? props.direction : props.flexDirection, | ||
flexWrap: props.wrap ? props.wrap : props.flexWrap, | ||
alignItems: props.align ? props.align : props.alignItems, | ||
justifyContent: props.justify ? props.justify : props.justifyContent, | ||
flexBasis: props.basis ? props.basis : props.flexBasis, | ||
flexGrow: props.grow ? props.grow : props.flexGrow, | ||
flexShrink: props.shrink ? props.shrink : props.flexShrink, | ||
height: props.h, | ||
width: props.w, | ||
minWidth: props.minW, | ||
minHeight: props.minH, | ||
alignSelf: props.alignSelf, | ||
maxWidth: props.maxW, | ||
maxHeight: props.maxH, | ||
opacity: props.opacity, | ||
zIndex: props.zIndex, | ||
backgroundColor: getThemeColor(theme.colors, props.bg as string), | ||
flex: props.flex, | ||
...createPositionStyle(props), | ||
...createSpacingStyles(props, theme.spacing), | ||
}; | ||
|
||
// merging custom style props to computed style | ||
if (props.style) { | ||
computedStyle.slider = { | ||
...computedStyle.slider, | ||
// @ts-ignore | ||
...props.style, | ||
}; | ||
} | ||
|
||
return StyleSheet.create(computedStyle); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { ViewProps as RNViewProps } from 'react-native'; | ||
import type { SliderProps as RNSliderProps } from '@react-native-community/slider'; | ||
|
||
import type { | ||
SpacingPropsType, | ||
DimensionPropsType, | ||
BackgroundPropsType, | ||
FlexPropsType, | ||
PositionPropsType, | ||
ZIndexPropsType, | ||
OpacityPropsType, | ||
VariantPropsType, | ||
} from '../../types'; | ||
|
||
export interface SliderProps | ||
extends RNViewProps, | ||
RNSliderProps, | ||
SpacingPropsType, | ||
DimensionPropsType, | ||
BackgroundPropsType, | ||
FlexPropsType, | ||
PositionPropsType, | ||
ZIndexPropsType, | ||
OpacityPropsType, | ||
VariantPropsType { | ||
min?: number; | ||
max?: number; | ||
defaultValue?: number; | ||
filledTrackColor?: string; | ||
colorScheme?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters