From 748cdeb2bb24d6fe24fc4519dc6f7e955448c397 Mon Sep 17 00:00:00 2001 From: patomation Date: Wed, 6 May 2020 17:33:41 +0700 Subject: [PATCH 1/2] feat: textArea and select event --- package.json | 2 +- src/Input/index.tsx | 23 ++------ src/Select/index.tsx | 4 +- src/TextArea/index.test.tsx | 10 ++++ src/TextArea/index.tsx | 109 ++++++++++++++++++++++++++++++++++++ src/TextArea/readme.md | 7 +++ src/TextArea/styles.ts | 42 ++++++++++++++ src/index.ts | 1 + 8 files changed, 176 insertions(+), 22 deletions(-) create mode 100644 src/TextArea/index.test.tsx create mode 100644 src/TextArea/index.tsx create mode 100644 src/TextArea/readme.md create mode 100644 src/TextArea/styles.ts diff --git a/package.json b/package.json index 6fe4a46..c133721 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patomation/ui", - "version": "2.0.0-beta16", + "version": "2.0.0-beta17", "main": "lib/index.js", "types": "lib/index.d.ts", "private": false, diff --git a/src/Input/index.tsx b/src/Input/index.tsx index c41249c..c9bc3a6 100644 --- a/src/Input/index.tsx +++ b/src/Input/index.tsx @@ -6,9 +6,8 @@ import Error from '../Error' import Gutter from '../Gutter' interface Props { - type?: string name?: string - onChange?: InputHTMLAttributes['onChange'] + onChange?: InputHTMLAttributes['onChange'] onFocus?: () => void onBlur?: () => void value?: string | number @@ -29,8 +28,6 @@ interface Props { max?: number step?: number textAlign?: 'center' | 'left' | '-moz-initial' | 'inherit' | 'initial' | 'revert' | 'unset' | 'right' | 'end' | 'justify' | 'match-parent' | 'start' | undefined - cols?: number - rows?: number prefix?: string suffix?: string disabled?: boolean @@ -40,17 +37,14 @@ interface Props { * A standardized input component plus textarea */ const Input: FunctionComponent = ({ - type, name, onChange, onFocus, onBlur, value, defaultValue, error, placeholder, + name, onChange, onFocus, onBlur, value, defaultValue, error, placeholder, className, onClick, background, color, containerStyle, inputStyle, inputErrorStyle, errorStyle, style, textAlign, - rows = 3, cols, label, min, max, step, prefix, suffix, disabled }) => { - const InputType = type === 'textarea' ? 'textarea' : 'input' - return (
= ({ : null } - = ({ ...(prefix ? { paddingLeft: '2rem' } : null), - ...(type === 'textarea' ? { - textAlign: 'left' as 'left', - resize: 'none', - padding: '1rem' - } : null), ...(background ? { background: background } : null), ...(color ? { color: color } : null), textAlign, ...inputStyle, - ...(error ? (inputErrorStyle || styles.errorBorder) : null), - ...(type === 'textarea' ? { height: 'auto' } : null) + ...(error ? (inputErrorStyle || styles.errorBorder) : null) }} disabled={disabled}/> diff --git a/src/Select/index.tsx b/src/Select/index.tsx index 615738c..cadce09 100644 --- a/src/Select/index.tsx +++ b/src/Select/index.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { FunctionComponent, ReactNode } from 'react' +import { FunctionComponent, ReactNode, InputHTMLAttributes } from 'react' import styles from './styles' import concat from '../_utility/concat' @@ -9,7 +9,7 @@ interface Props { children?: [ReactNode] | ReactNode className?: string name?: string - onChange?: React.ChangeEventHandler + onChange?: InputHTMLAttributes['onChange'] onBlur?: () => void value?: string | number error?: string | boolean diff --git a/src/TextArea/index.test.tsx b/src/TextArea/index.test.tsx new file mode 100644 index 0000000..eaad757 --- /dev/null +++ b/src/TextArea/index.test.tsx @@ -0,0 +1,10 @@ +import * as React from 'react' +import { mount } from 'enzyme' + +import TextArea from './index' + +describe('