Skip to content

Commit

Permalink
refactor: text input (#86)
Browse files Browse the repository at this point in the history
* refactor: text input

* feat: update package version

* refactor: change property background color name

Co-authored-by: glauberbrack <[email protected]>
  • Loading branch information
glauber-brack and glauberbrack authored Jun 1, 2021
1 parent 1de4b7a commit 1a450a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 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-elements",
"version": "0.1.12",
"version": "0.1.13",
"description": "Platform Builders Shared Components Library For React Web and Native",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
11 changes: 6 additions & 5 deletions src/native/components/TextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ const TextInput: FC<TextInputType> = ({
rightIconName = 'magnify',
iconColor,
inputPadding,
borderedBackgroundColor,
borderedHeight,
borderedColor,
borderedRadius,
fixedLabelVariant = 'caption1',
iconType = 'material',
fixedLabelVariant = 'caption2',
...rest
// eslint-disable-next-line sonarjs/cognitive-complexity
}) => {
Expand Down Expand Up @@ -179,6 +181,7 @@ const TextInput: FC<TextInputType> = ({

const renderIcon = (iconProp: string, isRightIcon: boolean) => (
<Icon
type={iconType}
id={`id_${iconProp}`}
accessibility={`icon_${accessibility}`}
size={iconSize}
Expand All @@ -204,6 +207,7 @@ const TextInput: FC<TextInputType> = ({
large={large}
>
<BorderedWrapper
borderedBackgroundColor={borderedBackgroundColor}
borderedHeight={borderedHeight}
borderedColor={borderedColor}
borderedRadius={borderedRadius}
Expand Down Expand Up @@ -255,10 +259,7 @@ const TextInput: FC<TextInputType> = ({
renderIcon(icon || '', true)}
</InputAreaWrapper>
)}

{(withBottomline || !!borderedHeight) && (
<BottomLine status={status} contrast={contrast} />
)}
{withBottomline && <BottomLine status={status} contrast={contrast} />}
</BorderedWrapper>
</FormError>
</Wrapper>
Expand Down
13 changes: 8 additions & 5 deletions src/native/components/TextInput/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type InputAreaWrapperProps = {
};

type BorderedWrapperProps = {
borderedBackgroundColor: string;
borderedHeight?: number;
borderedColor?: string;
borderedRadius?: number;
Expand Down Expand Up @@ -97,6 +98,7 @@ export const Wrapper = styled.View<WrapperProps>`

export const BorderedWrapper = styled.View<BorderedWrapperProps>`
${({
borderedBackgroundColor,
borderedColor,
borderedHeight,
borderedRadius,
Expand All @@ -108,6 +110,7 @@ export const BorderedWrapper = styled.View<BorderedWrapperProps>`
border: 1px solid ${
error ? failure(rest) : borderedColor || primaryMain(rest)
};
background-color: ${borderedBackgroundColor || 'transparent'};
height: ${borderedHeight}px;
border-radius: ${borderedRadius}px;
padding: ${smallSpacing(rest)};
Expand All @@ -130,21 +133,21 @@ export const InputBorderedColumnWrapper = styled.View<
InputBorderedColumnWrapperProps
>`
flex-direction: column;
padding: 0 ${minimumSpacing};
width: ${({ hasLeftIcon }: InputBorderedColumnWrapperProps) =>
hasLeftIcon ? '90%' : '96%'};
margin-left: -${smallSpacing};
hasLeftIcon ? '86%' : '92%'};
margin-left: ${({ hasLeftIcon }: InputBorderedColumnWrapperProps) =>
hasLeftIcon ? minimumSpacing : `-${largeSpacing}`};
`;

export const FixedLabel = styled(Typography)<FixedLabelProps>`
color: ${primaryMain};
margin-bottom: ${minimumSpacing};
margin-left: ${({ hasLeftIcon }: FixedLabelProps) =>
hasLeftIcon ? '0' : `-${largeSpacing}`};
`;

export const InputAreaWrapper = styled.View<InputAreaWrapperProps>`
padding-top: ${({ padding }: InputAreaWrapperProps) =>
(!!padding && `${padding}px`) || smallSpacing};
(!!padding && `${padding}px`) || minimumSpacing};
flex-direction: row;
align-items: center;
justify-content: center;
Expand Down
3 changes: 3 additions & 0 deletions src/native/types/TextInputType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TextInputMaskTypeProp } from '@platformbuilders/react-native-masked-tex

import { HitSlopType } from './Common';
import { TypographyVariants } from './Variants';
import { FontType } from './IconType';

export type TextInputType = {
id: string;
Expand Down Expand Up @@ -41,13 +42,15 @@ export type TextInputType = {
leftIcon?: boolean;
iconColor?: string;
inputPadding?: number;
borderedBackgroundColor?: string;
borderedHeight?: number;
borderedColor?: string;
borderedRadius?: number;
iconNameBordered?: string;
fixedLabelVariant?: TypographyVariants;
rightIcon?: boolean;
rightIconName?: string;
iconType?: FontType;
} & TextInputProps;

export interface MaskedTextInputType extends TextInputType {
Expand Down

0 comments on commit 1a450a3

Please sign in to comment.