-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a526c60
commit 413fec6
Showing
47 changed files
with
738 additions
and
564 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
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 |
---|---|---|
@@ -1,58 +1,58 @@ | ||
import React from "react"; | ||
import { TouchableOpacity, StyleProp, ViewStyle } from "react-native"; | ||
import { Ionicons } from "@expo/vector-icons"; | ||
|
||
import { Font } from "style"; | ||
import { Colors } from "style"; | ||
|
||
import Text from "../Text"; | ||
import styles from "./Button.styles"; | ||
import mainStyle from "./styles"; | ||
|
||
const PADDING_VERTICAL = 12; | ||
|
||
type ButtonType = "Primary" | "Secondary"; | ||
type ButtonType = "Primary" | "Secondary" | "Danger"; | ||
|
||
type Props = { | ||
style?: StyleProp<ViewStyle>; | ||
children: React.ReactNode; | ||
fullWidth?: boolean; | ||
textType: ButtonType; | ||
black?: boolean; | ||
red?: boolean; | ||
onPress: () => void; | ||
text: string; | ||
icon?: string; | ||
}; | ||
|
||
interface ButtonFactory { | ||
(type: ButtonType): React.FC<Props>; | ||
} | ||
|
||
const buttonFactory: ButtonFactory = (type) => (props) => { | ||
const customStyle = [mainStyle.default, styles[type].default, props.style]; | ||
const { fullWidth, children, textType, black, red, onPress } = props; | ||
const style = [mainStyle.default, styles[type].default, props.style]; | ||
const { fullWidth, onPress, text, icon } = props; | ||
let iconItem = null; | ||
|
||
if (fullWidth) { | ||
customStyle.push(mainStyle.fullWidth); | ||
style.push(mainStyle.fullWidth); | ||
} | ||
|
||
if (black) { | ||
customStyle.push(mainStyle.black); | ||
} | ||
|
||
if (red) { | ||
customStyle.push(mainStyle.red); | ||
if (icon) { | ||
iconItem = <Ionicons name={icon} size={24} style={mainStyle.mainIcon} color={Colors.white} />; | ||
} | ||
|
||
const additionalStyle = { | ||
paddingVertical: PADDING_VERTICAL, | ||
borderRadius: PADDING_VERTICAL * 2 + Font.FontSize[textType], | ||
borderRadius: PADDING_VERTICAL * 2, | ||
}; | ||
|
||
return ( | ||
<TouchableOpacity onPress={onPress} {...props} style={[customStyle, additionalStyle]}> | ||
{children} | ||
<TouchableOpacity onPress={onPress} {...props} style={[style, additionalStyle]}> | ||
<Text.Primary bold center white> | ||
{text} | ||
</Text.Primary> | ||
{iconItem} | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
const Primary = buttonFactory("Primary"); | ||
const Secondary = buttonFactory("Secondary"); | ||
const Danger = buttonFactory("Danger"); | ||
|
||
export default { Primary, Secondary }; | ||
export default { Primary, Secondary, Danger }; |
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
Oops, something went wrong.