-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix/design review #52
Changes from 6 commits
cb7073a
0fca77f
e8f114b
d4757d9
d3f4d5c
9db09ff
96043cf
6159716
3bdb6a4
9ecdb4c
195665c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,95 @@ | ||
import React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import { Button, Screen } from 'smartway-react-native-ui'; | ||
|
||
export const ButtonsPage = () => { | ||
return ( | ||
<Screen style={styles.container}> | ||
<Button mode="text">Text button</Button> | ||
<Button mode="filled">Filled button</Button> | ||
<View style={styles.buttonContainer}> | ||
<Button style={styles.button} mode="filled"> | ||
Filled | ||
</Button> | ||
<Button style={styles.button} status="primary" mode="filled"> | ||
Filled | ||
</Button> | ||
<Button style={styles.button} status="information" mode="filled"> | ||
Filled | ||
</Button> | ||
<Button style={styles.button} status="success" mode="filled"> | ||
Filled | ||
</Button> | ||
<Button style={styles.button} status="warning" mode="filled"> | ||
Filled | ||
</Button> | ||
<Button style={styles.button} status="error" mode="filled"> | ||
Filled | ||
</Button> | ||
<Button style={styles.button} disabled mode="filled"> | ||
Filled | ||
</Button> | ||
</View> | ||
<View style={styles.buttonContainer}> | ||
<Button style={styles.button} mode="text"> | ||
Text | ||
</Button> | ||
<Button style={styles.button} status="primary" mode="text"> | ||
Text | ||
</Button> | ||
<Button style={styles.button} status="information" mode="text"> | ||
Text | ||
</Button> | ||
<Button style={styles.button} status="success" mode="text"> | ||
Text | ||
</Button> | ||
<Button style={styles.button} status="warning" mode="text"> | ||
Text | ||
</Button> | ||
<Button style={styles.button} status="error" mode="text"> | ||
Text | ||
</Button> | ||
<Button style={styles.button} disabled mode="text"> | ||
Text | ||
</Button> | ||
</View> | ||
<View style={styles.buttonContainer}> | ||
<Button style={styles.outlinedButton} mode="outlined"> | ||
Outlined | ||
</Button> | ||
<Button style={styles.outlinedButton} status="primary" mode="outlined"> | ||
Outlined | ||
</Button> | ||
<Button style={styles.outlinedButton} status="information" mode="outlined"> | ||
Outlined | ||
</Button> | ||
<Button style={styles.outlinedButton} status="success" mode="outlined"> | ||
Outlined | ||
</Button> | ||
<Button style={styles.outlinedButton} status="warning" mode="outlined"> | ||
Outlined | ||
</Button> | ||
<Button style={styles.outlinedButton} status="error" mode="outlined"> | ||
Outlined | ||
</Button> | ||
<Button style={styles.outlinedButton} disabled mode="outlined"> | ||
Outlined | ||
</Button> | ||
</View> | ||
</Screen> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flexDirection: 'row', | ||
justifyContent: 'center', | ||
}, | ||
buttonContainer: { | ||
alignItems: 'center', | ||
}, | ||
button: { | ||
margin: 6, | ||
}, | ||
outlinedButton: { | ||
margin: 5, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import type { ReactNode } from 'react'; | ||
import type { TextStyle, ViewStyle } from 'react-native'; | ||
|
||
type ButtonStatus = | ||
| 'default' | ||
| 'primary' | ||
| 'information' | ||
| 'success' | ||
| 'warning' | ||
| 'error' | ||
| 'neutral'; | ||
export interface BaseButtonProps { | ||
children?: ReactNode; | ||
style?: ViewStyle; | ||
labelStyle?: TextStyle; | ||
onClick?: () => void; | ||
testID?: string; | ||
disabled?: boolean; | ||
status?: ButtonStatus; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ import { TextButton } from './TextButton'; | |
import { Button as BaseButton } from 'react-native-paper'; | ||
import { FilledButton } from './FilledButton'; | ||
import type { BaseButtonProps } from './BaseButtonProps'; | ||
import { OutlinedButton } from './OutlinedButton'; | ||
|
||
interface ButtonProps extends BaseButtonProps { | ||
mode?: 'text' | 'filled'; | ||
mode?: 'filled' | 'outlined' | 'text'; | ||
} | ||
|
||
export const Button = ({ | ||
|
@@ -14,23 +15,58 @@ export const Button = ({ | |
style, | ||
labelStyle, | ||
onClick, | ||
status = 'primary', | ||
disabled, | ||
testID, | ||
}: ButtonProps) => { | ||
if (mode === 'text') { | ||
return ( | ||
<TextButton style={style} labelStyle={labelStyle} onClick={onClick} testID={testID}> | ||
<TextButton | ||
status={status} | ||
style={style} | ||
labelStyle={labelStyle} | ||
onClick={onClick} | ||
testID={testID} | ||
disabled={disabled} | ||
> | ||
{children} | ||
</TextButton> | ||
); | ||
} else if (mode === 'filled') { | ||
return ( | ||
<FilledButton style={style} labelStyle={labelStyle} onClick={onClick} testID={testID}> | ||
<FilledButton | ||
status={status} | ||
style={style} | ||
labelStyle={labelStyle} | ||
onClick={onClick} | ||
testID={testID} | ||
disabled={disabled} | ||
> | ||
{children} | ||
</FilledButton> | ||
); | ||
} else if (mode === 'outlined') { | ||
return ( | ||
<OutlinedButton | ||
status={status} | ||
style={style} | ||
labelStyle={labelStyle} | ||
onClick={onClick} | ||
testID={testID} | ||
disabled={disabled} | ||
> | ||
{children} | ||
</OutlinedButton> | ||
); | ||
} else { | ||
return ( | ||
<BaseButton style={style} labelStyle={labelStyle} onPress={onClick} testID={testID}> | ||
<BaseButton | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about it I think it's not a good idea to fallback to the default react-native-paper's Button component if no Would you mind to provide a default value to the |
||
style={style} | ||
disabled={disabled} | ||
labelStyle={labelStyle} | ||
onPress={onClick} | ||
testID={testID} | ||
> | ||
{children} | ||
</BaseButton> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,64 @@ | ||
import React from 'react'; | ||
import type { TextStyle, ViewStyle } from 'react-native'; | ||
import { StyleSheet, ViewStyle } from 'react-native'; | ||
import { Button as BaseButton } from 'react-native-paper'; | ||
import { useTheme } from '../../styles/themes'; | ||
import type { BaseButtonProps } from './BaseButtonProps'; | ||
|
||
export const FilledButton = ({ children, style, labelStyle, onClick, testID }: BaseButtonProps) => { | ||
export const FilledButton = ({ | ||
children, | ||
style, | ||
labelStyle, | ||
onClick, | ||
testID, | ||
disabled, | ||
status, | ||
}: BaseButtonProps) => { | ||
const theme = useTheme(); | ||
const buttonStyle: ViewStyle = { | ||
borderRadius: 8, | ||
backgroundColor: theme.sw.colors.primary[400], | ||
...style, | ||
}; | ||
|
||
const _labelStyle: TextStyle = { | ||
fontFamily: 'PublicSans-Regular', | ||
fontSize: 16, | ||
lineHeight: 19, | ||
color: theme.sw.colors.neutral[50], | ||
paddingVertical: theme.sw.spacing.s, | ||
paddingHorizontal: theme.sw.spacing.l, | ||
// Overrides default margin of Paper component | ||
marginVertical: 0, | ||
marginHorizontal: 0, | ||
...labelStyle, | ||
const getbackgroundColor = (): ViewStyle['backgroundColor'] => { | ||
switch (status) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you move this function in it's own file (like Something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated :) |
||
case 'primary': | ||
return theme.sw.colors.primary[400]; | ||
case 'information': | ||
return theme.sw.colors.information[400]; | ||
case 'success': | ||
return theme.sw.colors.success[400]; | ||
case 'warning': | ||
return theme.sw.colors.warning[400]; | ||
case 'error': | ||
return theme.sw.colors.error[400]; | ||
default: | ||
return theme.sw.colors.neutral[700]; | ||
} | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
button: { | ||
borderRadius: 8, | ||
backgroundColor: disabled ? '#919EAB3D' : getbackgroundColor(), | ||
...style, | ||
}, | ||
label: { | ||
fontFamily: 'PublicSans-Regular', | ||
fontSize: 16, | ||
lineHeight: 26, | ||
color: disabled ? theme.sw.colors.neutral[500] : theme.sw.colors.neutral[50], | ||
paddingVertical: theme.sw.spacing.s, | ||
paddingHorizontal: theme.sw.spacing.l, | ||
fontWeight: 'bold', | ||
marginVertical: 0, | ||
marginHorizontal: 0, | ||
...labelStyle, | ||
}, | ||
}); | ||
|
||
return ( | ||
<BaseButton style={buttonStyle} labelStyle={_labelStyle} onPress={onClick} testID={testID}> | ||
<BaseButton | ||
style={styles.button} | ||
labelStyle={styles.label} | ||
onPress={onClick} | ||
testID={testID} | ||
> | ||
{children} | ||
</BaseButton> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neutral[50]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i tried to use theme there, but it returns an error as i try to use it outside
ThemeProvider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We definitely should use the ThemeProvider then !