-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add Header component and theme #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
loc-nguyenthien
wants to merge
4
commits into
develop
Choose a base branch
from
feature/add_header_component
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,16 @@ | ||
| import React from 'react' | ||
| import type {ComponentMeta, ComponentStory} from '@storybook/react' | ||
| import {Header} from 'rn-base-component' | ||
| import {Text} from 'react-native' | ||
|
|
||
| export default { | ||
| title: 'components/Header', | ||
| component: Header, | ||
| } as ComponentMeta<typeof Header> | ||
|
|
||
| export const Basic: ComponentStory<typeof Header> = rest => <Header {...rest} /> | ||
|
|
||
| Basic.args = { | ||
| title: 'Header Title', | ||
| rightComponent: <Text>Right Comp</Text>, | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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,175 @@ | ||
| import React, {ReactNode} from 'react' | ||
| import {StyleSheet, TouchableOpacity} from 'react-native' | ||
| import type {ImageStyle, StyleProp, TextStyle, ViewStyle} from 'react-native' | ||
| import styled from 'styled-components/native' | ||
| import {TextBold} from '../Text/Text' | ||
| import {Images} from '../../theme' | ||
| import {hitSlop, metrics} from '../../helpers' | ||
| import {useTheme} from '../../hooks' | ||
|
|
||
| export interface HeaderProps { | ||
| /** | ||
| * The top padding for the notch of device, usually we will use react-native-safe-area-context to get the inset | ||
| */ | ||
| paddingTop?: number | ||
| /** | ||
| * Height of the header | ||
| */ | ||
| height?: number | ||
| /** | ||
| * Style of Header container | ||
| */ | ||
| containerStyle?: StyleProp<ViewStyle> | ||
| /** | ||
| * Width of Header bottom border | ||
| */ | ||
| borderBottomWidth?: number | ||
| /** | ||
| * Color of Header bottom border | ||
| */ | ||
| borderBottomColor?: string | ||
| /** | ||
| * Title of the header, will be use if no custom CenterComponent is defined | ||
| */ | ||
| title?: string | ||
| /** | ||
| * The color of Header title | ||
| */ | ||
| titleColor?: string | ||
| /** | ||
| * The custom style of Header title | ||
| */ | ||
| titleStyle?: StyleProp<TextStyle> | ||
| /** | ||
| * Background color of the Header | ||
| */ | ||
| backgroundColor?: string | ||
| /** | ||
| * Show the back to previous screen icon, default value is true | ||
| */ | ||
| hasBackButton?: boolean | ||
| /** | ||
| * The color of back to previous screen icon | ||
| */ | ||
| backIconColor?: string | ||
| /** | ||
| * The action for the back to previous screen icon | ||
| */ | ||
| backButtonPress?: () => void | ||
| /** | ||
| * The left component of the Header | ||
| */ | ||
| leftComponent?: ReactNode | ||
| /** | ||
| * The style of left component of the Header | ||
| */ | ||
| leftStyle?: StyleProp<ViewStyle> | ||
| /** | ||
| * The center component of the Header, will replace Title | ||
| */ | ||
| centerComponent?: ReactNode | ||
| /** | ||
| * The style of center component of the Header | ||
| */ | ||
| centerStyle?: StyleProp<ViewStyle> | ||
| /** | ||
| * The right component of the Header | ||
| */ | ||
| rightComponent?: ReactNode | ||
| /** | ||
| * The style of right component of the Header | ||
| */ | ||
| rightStyle?: StyleProp<ViewStyle> | ||
| } | ||
|
|
||
| const Header: React.FC<HeaderProps> = ({ | ||
| paddingTop, | ||
| height, | ||
| containerStyle, | ||
| borderBottomWidth, | ||
| borderBottomColor, | ||
| title, | ||
| titleColor, | ||
| titleStyle, | ||
| backgroundColor, | ||
| hasBackButton = true, | ||
| backIconColor, | ||
| backButtonPress, | ||
| leftComponent, | ||
| leftStyle, | ||
| centerComponent, | ||
| centerStyle, | ||
| rightComponent, | ||
| rightStyle, | ||
| }) => { | ||
| const HeaderTheme = useTheme().components.Header | ||
| return ( | ||
| <Container | ||
| backgroundColor={backgroundColor ?? HeaderTheme.backgroundColor} | ||
| height={(height ?? (HeaderTheme.height as number)) + (paddingTop ?? (HeaderTheme.paddingTop as number))} | ||
| paddingTop={paddingTop ?? HeaderTheme.paddingTop} | ||
baonguyenhsts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| borderBottomWidth={borderBottomWidth ?? HeaderTheme.borderBottomWidth} | ||
| borderBottomColor={borderBottomColor ?? HeaderTheme.borderBottomColor} | ||
| {...StyleSheet.flatten(containerStyle)}> | ||
| <SidesContainer {...StyleSheet.flatten(leftStyle)}> | ||
| {leftComponent | ||
| ? leftComponent | ||
| : hasBackButton && ( | ||
| <TouchableOpacity hitSlop={hitSlop} onPress={() => backButtonPress?.()}> | ||
| <IconBack | ||
| source={Images.chevronLeft} | ||
| resizeMode="contain" | ||
| tintColor={backIconColor ?? HeaderTheme.backIconColor} | ||
| /> | ||
| </TouchableOpacity> | ||
| )} | ||
| </SidesContainer> | ||
|
|
||
| <TitleContainer {...StyleSheet.flatten(centerStyle)}> | ||
| {centerComponent | ||
| ? centerComponent | ||
| : !!title && ( | ||
| <TextBold | ||
| color={titleColor ?? HeaderTheme.titleColor} | ||
| style={titleStyle ?? HeaderTheme.titleStyle} | ||
| numberOfLines={1}> | ||
| {title} | ||
| </TextBold> | ||
| )} | ||
| </TitleContainer> | ||
|
|
||
| <SidesContainer {...StyleSheet.flatten(rightStyle)}> | ||
| {!!rightComponent && rightComponent} | ||
| </SidesContainer> | ||
| </Container> | ||
| ) | ||
| } | ||
|
|
||
| const Container = styled.View((style: ViewStyle) => ({ | ||
| flexDirection: 'row', | ||
| justifyContent: 'space-between', | ||
| alignItems: 'center', | ||
| paddingHorizontal: metrics.small, | ||
| ...style, | ||
| })) | ||
|
|
||
| const SidesContainer = styled.View((style: ViewStyle) => ({ | ||
| flex: 1, | ||
| justifyContent: 'center', | ||
| ...style, | ||
| })) | ||
|
|
||
| const TitleContainer = styled.View((style: ViewStyle) => ({ | ||
| flex: 4, | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| ...style, | ||
| })) | ||
|
|
||
| const IconBack = styled.Image(({tintColor}: ImageStyle) => ({ | ||
| height: metrics.large, | ||
| aspectRatio: 1, | ||
| tintColor, | ||
| })) | ||
|
|
||
| export default Header | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
| import {metrics, responsiveHeight} from '../../helpers' | ||
| import type {HeaderProps} from '../../components/Header/Header' | ||
| import base from '../base' | ||
|
|
||
| export type HeaderThemeProps = Pick< | ||
| HeaderProps, | ||
| | 'paddingTop' | ||
| | 'height' | ||
| | 'borderBottomWidth' | ||
| | 'borderBottomColor' | ||
| | 'titleColor' | ||
| | 'titleStyle' | ||
| | 'backgroundColor' | ||
| | 'backIconColor' | ||
| > | ||
|
|
||
| export const HeaderTheme: HeaderThemeProps = { | ||
| paddingTop: metrics.xxl, | ||
| height: metrics.huge, | ||
| borderBottomWidth: responsiveHeight(1), | ||
| borderBottomColor: base.colors.backgroundSecondary, | ||
| titleColor: base.colors.textColor, | ||
| titleStyle: { | ||
| fontSize: base.fontSizes.sm, | ||
| }, | ||
| backgroundColor: base.colors.white, | ||
| backIconColor: base.colors.black, | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| const Images = { | ||
| check: require('../assets/images/check.png'), | ||
| } | ||
| chevronLeft: require('../assets/images/chevron-left.png'), | ||
| } as const | ||
|
|
||
| export {Images} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.