Skip to content

Instantly share code, notes, and snippets.

@trooperandz
Last active November 15, 2021 02:07
Show Gist options
  • Select an option

  • Save trooperandz/ff4f50243736b805cdc2790266f65c06 to your computer and use it in GitHub Desktop.

Select an option

Save trooperandz/ff4f50243736b805cdc2790266f65c06 to your computer and use it in GitHub Desktop.

Revisions

  1. trooperandz renamed this gist Nov 15, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Button.js → index.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // storybook/Button/index.js
    import React from 'react';
    import {
    ActivityIndicator,
  2. trooperandz created this gist Nov 14, 2021.
    99 changes: 99 additions & 0 deletions Button.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    import React from 'react';
    import {
    ActivityIndicator,
    StyleSheet,
    Text,
    TouchableOpacity,
    View,
    } from 'react-native';

    import SearchIcon from 'assets/icon-search.svg';

    export const Button = props => {
    const {
    containerStyle,
    iconType,
    isLoading,
    onPress,
    text,
    textStyle,
    type,
    } = props;

    const fontSize = 18;
    let containerThemeStyle;
    let icon;
    let contentColor;

    switch (type) {
    case 'primary':
    containerThemeStyle = {
    backgroundColor: '#30BE76',
    borderColor: '#30BE76',
    };
    contentColor = '#fff';
    break;
    case 'secondary':
    containerThemeStyle = {
    backgroundColor: '#fff',
    borderColor: '#30BE76',
    };
    contentColor = '#30BE76';
    break;
    case 'tertiary':
    containerThemeStyle = {
    backgroundColor: 'rgba(0, 0, 0, 0.0)',
    borderColor: 'rgba(0, 0, 0, 0.0)',
    };
    contentColor = '#30BE76';
    break;
    }

    switch (iconType) {
    case 'search':
    icon = <SearchIcon fill={contentColor} />;
    break;
    default:
    icon = undefined;
    break;
    }

    return (
    <TouchableOpacity
    onPress={onPress}
    style={[styles.container, containerThemeStyle, containerStyle]}>
    {isLoading ? (
    <ActivityIndicator color={contentColor} size="small" />
    ) : (
    <View style={styles.wrapper}>
    {icon ? <View style={styles.icon}>{icon}</View> : null}
    <Text
    style={[styles.text, { color: contentColor, fontSize }, textStyle]}>
    {text}
    </Text>
    </View>
    )}
    </TouchableOpacity>
    );
    };

    const styles = StyleSheet.create({
    container: {
    alignItems: 'center',
    borderRadius: 32,
    borderWidth: 1,
    justifyContent: 'center',
    minHeight: 54,
    paddingHorizontal: 24,
    paddingVertical: 14,
    width: '100%',
    },
    icon: {
    marginRight: 10,
    },
    wrapper: {
    alignItems: 'center',
    flexDirection: 'row',
    justifyContent: 'center',
    },
    });