-
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
fcfad34
commit 0e7aed1
Showing
8 changed files
with
268 additions
and
0 deletions.
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,19 @@ | ||
import React from 'react'; | ||
import { Box, SafeAreaBox, Text } from 'react-native-ficus-ui'; | ||
|
||
const SafeAreaBoxComponent = () => { | ||
return ( | ||
<SafeAreaBox bg="blue.100" h="100%"> | ||
<Box px="xl"> | ||
<Text fontSize="4xl">SafeAreaBox component</Text> | ||
<Box flexDirection="row"> | ||
<Box h={40} w={40} mr="sm" bg="green.500" /> | ||
<Box h={40} w={40} mr="sm" bg="teal.500" /> | ||
<Box h={40} w={40} mr="sm" bg="yellow.500" /> | ||
</Box> | ||
</Box> | ||
</SafeAreaBox> | ||
); | ||
}; | ||
|
||
export default SafeAreaBoxComponent; |
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
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,112 @@ | ||
import * as React from 'react'; | ||
import { SafeAreaView } from 'react-native'; | ||
|
||
import { getStyle } from './safeareabox.style'; | ||
import type { SafeAreaBoxProps } from './safeareabox.type'; | ||
import { useTheme } from '../../theme/theme.hook'; | ||
import { useDefaultProps } from '../../utilities/useDefaultProps'; | ||
|
||
const SafeAreaBox: React.FunctionComponent<SafeAreaBoxProps> = ( | ||
incomingProps | ||
) => { | ||
const props = useDefaultProps('SafeAreaBox', incomingProps, { | ||
bg: 'transparent', | ||
flexDirection: 'column', | ||
flexWrap: 'nowrap', | ||
borderRadius: 'none', | ||
shadow: 'none', | ||
position: 'relative', | ||
pointerEvents: 'auto', | ||
borderStyle: 'solid', | ||
}); | ||
|
||
const { | ||
bg, | ||
h, | ||
w, | ||
m, | ||
mt, | ||
mr, | ||
mb, | ||
ml, | ||
ms, | ||
p, | ||
pr, | ||
pt, | ||
pb, | ||
pl, | ||
minH, | ||
minW, | ||
maxW, | ||
maxH, | ||
position, | ||
style, | ||
flexDirection, | ||
direction, | ||
borderRadius, | ||
borderTopRadius, | ||
borderTopLeftRadius, | ||
borderTopRightRadius, | ||
borderBottomLeftRadius, | ||
borderBottomRightRadius, | ||
borderLeftRadius, | ||
borderRightRadius, | ||
borderBottomRadius, | ||
children, | ||
alignItems, | ||
align, | ||
justifyContent, | ||
justify, | ||
borderColor, | ||
borderBottomColor, | ||
borderLeftColor, | ||
borderTopColor, | ||
borderRightColor, | ||
borderWidth, | ||
borderLeftWidth, | ||
borderRightWidth, | ||
borderBottomWidth, | ||
borderTopWidth, | ||
borderEndWidth, | ||
flexWrap, | ||
wrap, | ||
flexGrow, | ||
grow, | ||
flexBasis, | ||
basis, | ||
flexShrink, | ||
shrink, | ||
shadow, | ||
shadowColor, | ||
opacity, | ||
overflow, | ||
top, | ||
left, | ||
right, | ||
bottom, | ||
zIndex, | ||
...rest | ||
} = props; | ||
const { theme } = useTheme(); | ||
const computedStyle = getStyle(theme, props); | ||
|
||
return ( | ||
<SafeAreaView style={computedStyle.box} {...rest}> | ||
{children} | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
// SafeAreaBox.defaultProps = { | ||
// bg: 'transparent', | ||
// flexDirection: 'column', | ||
// flexWrap: 'nowrap', | ||
// borderRadius: 'none', | ||
// shadow: 'none', | ||
// shadowColor: 'gray900', | ||
// position: 'relative', | ||
// pointerEvents: 'auto', | ||
// borderStyle: 'solid', | ||
// }; | ||
|
||
export { SafeAreaBox }; |
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,29 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react-native'; | ||
|
||
import { Text } from '../text/text.component'; | ||
import { SafeAreaBox } from './safeareabox.component'; | ||
import type { SafeAreaBoxProps } from './safeareabox.type'; | ||
import { ThemeProvider } from '../../theme/theme.provider'; | ||
|
||
jest.mock('react-native-toast-message', () => 'Toast'); | ||
|
||
describe('SafeAreaBox component', () => { | ||
const TestSafeAreaBox: React.FC<SafeAreaBoxProps> = (props) => ( | ||
<ThemeProvider> | ||
<SafeAreaBox {...props} /> | ||
</ThemeProvider> | ||
); | ||
|
||
it('should render component passed to children', () => { | ||
render( | ||
<TestSafeAreaBox> | ||
<Text>I love Ficus UI (forked from Magnus UI)</Text> | ||
</TestSafeAreaBox> | ||
); | ||
|
||
expect( | ||
screen.getByText('I love Ficus UI (forked from Magnus UI)') | ||
).toBeTruthy(); | ||
}); | ||
}); |
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,67 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
import { | ||
createShadowStyles, | ||
createPositionStyle, | ||
createSpacingStyles, | ||
createBorderWidthStyles, | ||
createBorderColorStyles, | ||
createBorderRadiusStyles, | ||
getThemeColor, | ||
} from '../../theme/theme.service'; | ||
import type { SafeAreaBoxProps } from './safeareabox.type'; | ||
import type { ThemeType } from '../../theme/type'; | ||
|
||
/** | ||
* computed style | ||
* | ||
* @param theme | ||
* @param props | ||
*/ | ||
export const getStyle = (theme: ThemeType, props: SafeAreaBoxProps) => { | ||
const computedStyle: any = {}; | ||
|
||
computedStyle.box = { | ||
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, | ||
overflow: props.overflow || 'hidden', | ||
zIndex: props.zIndex, | ||
borderStyle: props.borderStyle, | ||
backgroundColor: getThemeColor(theme.colors, props.bg), | ||
flex: props.flex, | ||
...createPositionStyle(props), | ||
...createShadowStyles(props, theme), | ||
...createBorderWidthStyles(props), | ||
...createSpacingStyles(props, theme.spacing), | ||
...createBorderColorStyles(props, theme.colors), | ||
...createBorderRadiusStyles(props, theme.borderRadius), | ||
}; | ||
|
||
computedStyle.image = { | ||
...createBorderRadiusStyles(props, theme.borderRadius), | ||
}; | ||
|
||
// merging custom style props to computed style | ||
if (props.style) { | ||
computedStyle.box = { | ||
...computedStyle.box, | ||
// @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 { | ||
BorderPropsType, | ||
SpacingPropsType, | ||
BorderRadiusPropsType, | ||
ShadowPropsType, | ||
DimensionPropsType, | ||
BackgroundPropsType, | ||
FlexPropsType, | ||
PositionPropsType, | ||
ZIndexPropsType, | ||
OverflowPropsType, | ||
OpacityPropsType, | ||
VariantPropsType, | ||
} from '../../types'; | ||
|
||
export interface SafeAreaBoxProps | ||
extends RNViewProps, | ||
BorderPropsType, | ||
SpacingPropsType, | ||
BorderRadiusPropsType, | ||
ShadowPropsType, | ||
DimensionPropsType, | ||
BackgroundPropsType, | ||
FlexPropsType, | ||
PositionPropsType, | ||
ZIndexPropsType, | ||
OverflowPropsType, | ||
OpacityPropsType, | ||
VariantPropsType {} |
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