Skip to content

Commit

Permalink
Merge pull request #16 from platformbuilders/feat/refactor
Browse files Browse the repository at this point in the history
Feat/refactor
  • Loading branch information
duspada-builders authored Jul 16, 2021
2 parents 1aa396e + 64d3c99 commit 05d1d7f
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platformbuilders/react-native-elements",
"version": "0.2.6",
"version": "0.2.7",
"description": "Platform Builders Shared Components Library For React Native",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
28 changes: 27 additions & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from 'react';
import { ButtonProps } from '../../types';
import { ButtonWrapper, Loading, TextButton, Touchable } from './styles';
import { ButtonWrapper, Icon, Loading, TextButton, Touchable } from './styles';

const Button: FC<ButtonProps> = ({
id,
Expand All @@ -17,6 +17,11 @@ const Button: FC<ButtonProps> = ({
contrast = false,
variant = 'primary',
typographyVariant = 'body',
minWidth,
maxWidth,
rightIconName,
leftIconName,
hasBorder = false,
}) => {
return (
<Touchable
Expand All @@ -29,14 +34,26 @@ const Button: FC<ButtonProps> = ({
rounded={rounded}
>
<ButtonWrapper
hasBorder={hasBorder}
buttonVariant={variant}
style={style}
disabled={disabled}
rounded={rounded}
minWidth={minWidth}
maxWidth={maxWidth}
>
{loading && <Loading contrast={contrast} />}
{!loading && (
<>
{!!leftIconName && (
<Icon
accessibility=""
name={leftIconName as string}
buttonVariant={variant}
style={style}
leftIcon
/>
)}
<TextButton
style={textStyle}
disabled={disabled}
Expand All @@ -45,6 +62,15 @@ const Button: FC<ButtonProps> = ({
>
{children}
</TextButton>
{!!rightIconName && (
<Icon
accessibility=""
name={rightIconName as string}
buttonVariant={variant}
style={style}
rightIcon
/>
)}
</>
)}
</ButtonWrapper>
Expand Down
32 changes: 29 additions & 3 deletions src/components/Button/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { moderateScale } from 'react-native-size-matters';
import styled from 'styled-components/native';
import { ButtonVariants, TypographyVariants } from '../../types';
import { getTheme } from '../../utils/helpers';
import { getTheme, ifStyle } from '../../utils/helpers';
import DefaultIcon from '../Icon';
import LoadingIndicator from '../LoadingIndicator';
import TouchableComponent from '../Touchable';
import TypographyComponent from '../Typography';
Expand All @@ -18,12 +19,18 @@ const accentMain = getTheme('accent.main');
const accentContrast = getTheme('accent.contrast');
const buttonRadius = getTheme('buttonRadius');
const minimumSpacing = getTheme('minimumSpacing');
const smallSpacing = getTheme('smallSpacing');
const isLeftIcon = ifStyle('leftIcon');
const isRightIcon = ifStyle('rightIcon');

type ButtonWrapperProps = {
rounded: boolean;
hasBorder: boolean;
buttonVariant: ButtonVariants;
disabled?: boolean;
style: any;
minWidth?: string | number;
maxWidth?: string | number;
};

const buttonSize = moderateScale(45);
Expand Down Expand Up @@ -88,7 +95,10 @@ export const ButtonWrapper = styled.View<ButtonWrapperProps>`
height: ${buttonSize}px;
flex-direction: row;
align-items: center;
min-width: ${moderateScale(180)}px;
min-width: ${({ minWidth }: ButtonWrapperProps) =>
minWidth || moderateScale(180) + 'px'};
max-width: ${({ maxWidth }: ButtonWrapperProps) => maxWidth || '100%'};
overflow: hidden;
padding: ${(props: ButtonWrapperProps): string =>
props.rounded ? '0' : minimumSpacing(props)};
border-radius: ${(props: ButtonWrapperProps): string =>
Expand All @@ -97,7 +107,9 @@ export const ButtonWrapper = styled.View<ButtonWrapperProps>`
background-color: ${getBackgroundColor};
border-color: ${getTextColor};
border: ${(props: ButtonWrapperProps) =>
props.buttonVariant === 'flat' ? `1px solid ${getTextColor(props)}` : '0'};
props.buttonVariant === 'flat' || props.hasBorder
? `1px solid ${getTextColor(props)}`
: '0'};
`;

export const TextButton = styled(TypographyComponent)<TextButtonProps>`
Expand All @@ -112,3 +124,17 @@ export const Loading = styled(LoadingIndicator).attrs({
align-self: center;
width: ${moderateScale(55)}px;
`;

type IconProps = {
rightIcon?: boolean;
leftIcon?: boolean;
buttonVariant: ButtonVariants;
style: any;
};

export const Icon = styled(DefaultIcon).attrs((props: IconProps) => ({
color: getTextColor(props),
}))<IconProps>`
margin-right: ${isLeftIcon(smallSpacing, 0)};
margin-left: ${isRightIcon(smallSpacing, 0)};
`;
18 changes: 18 additions & 0 deletions src/components/LabelDivider/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { DividerText, Line, OptionsWrapper } from './styles';

type Props = {
marginTop?: number;
marginBottom?: number;
text: string;
};

const LabelDivider: React.FC<Props> = ({ text, marginTop, marginBottom }) => (
<OptionsWrapper marginTop={marginTop} marginBottom={marginBottom}>
<Line />
<DividerText>{text}</DividerText>
<Line />
</OptionsWrapper>
);

export default LabelDivider;
31 changes: 31 additions & 0 deletions src/components/LabelDivider/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import styled from 'styled-components/native';
import { getTheme } from '../../utils/helpers';
import Typography from '../Typography';

const smallerSpacing = getTheme('smallerSpacing');
const disabled = getTheme('texts.dark');

type Props = {
marginTop?: number;
marginBottom?: number;
};

export const OptionsWrapper = styled.View`
margin-top: ${({ marginTop }: Props) => marginTop || 0}px;
margin-bottom: ${({ marginBottom }: Props) => marginBottom || 0}px;
flex-direction: row;
justify-content: center;
align-items: center;
`;

export const Line = styled.View`
width: 33%;
height: 1px;
background-color: ${disabled}90;
`;

export const DividerText = styled(Typography)`
padding: ${smallerSpacing};
color: ${disabled}90;
font-weight: bold;
`;
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export { default as Accordion } from './Accordion';
export { default as RadioButton } from './RadioButton';
export { default as SearchInput } from './SearchInput';
export { default as DisplayVersion } from './DisplayVersion';
export { default as LabelDivider } from './LabelDivider';
5 changes: 5 additions & 0 deletions src/types/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ export type ButtonProps = {
variant?: ButtonVariants;
typographyVariant?: TypographyVariants;
children?: string | ReactNode;
minWidth?: string | number;
maxWidth?: string | number;
leftIconName?: string;
rightIconName?: string;
hasBorder?: boolean;
} & TouchableType;

0 comments on commit 05d1d7f

Please sign in to comment.