File tree Expand file tree Collapse file tree 8 files changed +126
-102
lines changed
Expand file tree Collapse file tree 8 files changed +126
-102
lines changed Original file line number Diff line number Diff line change 11import '@storybook/addon-options/register'
2- import '@storybook/addon-actions/register'
Original file line number Diff line number Diff line change 1- import { action } from '@storybook/addon-actions'
2- import Sample from 'or-input'
1+ import { Input } from 'or-input'
32import React , { PureComponent } from 'react'
43
5- const handleClick = action ( 'sample-click' )
6-
74export default class Example extends PureComponent < { } , { } > {
5+ state = {
6+ name : '' ,
7+ age : ''
8+ }
9+
810 render ( ) {
911 return (
1012 < div >
11- < h1 > button type:</ h1 >
12- < div >
13- < Sample type = "primary" onClick = { handleClick } >
14- ADD TO CART
15- </ Sample >
16- < Sample onClick = { handleClick } > SIGN UP</ Sample >
17- < Sample type = "warning" onClick = { handleClick } >
18- DELETE
19- </ Sample >
20- < Sample onClick = { handleClick } > TOO LOOOOOOOOOOOOOOOOOOG</ Sample >
21- </ div >
13+ < Input
14+ placeholder = "name"
15+ value = { this . state . name }
16+ maxlength = { 12 }
17+ onChange = { this . handleChange ( 'name' ) }
18+ />
19+ < Input
20+ numericInput = { true }
21+ placeholder = "age"
22+ value = { this . state . age }
23+ maxlength = { 12 }
24+ onChange = { this . handleChange ( 'age' ) }
25+ />
2226 </ div >
2327 )
2428 }
29+
30+ handleChange = state => {
31+ return value => {
32+ this . setState ( {
33+ [ `${ state } ` ] : value
34+ } )
35+ }
36+ }
2537}
Original file line number Diff line number Diff line change 1- import { action } from '@storybook/addon-actions'
21import { withInfo } from '@storybook/addon-info'
32import { storiesOf } from '@storybook/react'
43import React from 'react'
54
6- import Sample from 'or-input'
75import { previewCode } from './util'
86
97import Example from './example'
108
119import './styles.scss'
1210
13- const handleClick = action ( 'basic-click' )
1411storiesOf ( 'or-sample' , module )
1512 . addDecorator (
1613 withInfo ( {
1714 inline : true ,
18- propTables : [ Sample ] ,
1915 propTablesExclude : [ Example ] ,
2016 styles : {
2117 jsxInfoContent : {
@@ -25,7 +21,6 @@ storiesOf('or-sample', module)
2521 }
2622 } )
2723 )
28- . add ( 'basic' , ( ) => < Sample onClick = { handleClick } > Test</ Sample > )
2924 . add ( 'sample' , ( ) => < Example /> , {
3025 info : {
3126 source : false ,
Original file line number Diff line number Diff line change 1+ import clx from 'classnames'
2+ import React , { PureComponent } from 'react'
3+
4+ interface Props {
5+ /**
6+ * additional classname for input
7+ */
8+ classname ?: string
9+
10+ type ?: 'text' | 'number'
11+
12+ numericInput ?: boolean
13+
14+ placeholder ?: string
15+
16+ value : string
17+
18+ maxlength ?: number
19+
20+ withClearIcon ?: boolean
21+
22+ /**
23+ * callback triggered input's onchange event
24+ **/
25+ onChange ?: ( value ) => void
26+ }
27+
28+ export class Input extends PureComponent < Props , { } > {
29+ render ( ) {
30+ const {
31+ classname,
32+ placeholder,
33+ value,
34+ maxlength,
35+ withClearIcon = true
36+ } = this . props
37+ const inputClass = clx ( classname , 'or-input' )
38+
39+ return (
40+ < div className = { inputClass } >
41+ < input
42+ placeholder = { placeholder }
43+ value = { value }
44+ maxLength = { maxlength }
45+ onChange = { this . handleChange }
46+ />
47+ { withClearIcon && (
48+ < div className = "or-clear-icon" onClick = { this . handleClear } />
49+ ) }
50+ </ div >
51+ )
52+ }
53+
54+ handleChange = ( e : React . FormEvent < HTMLInputElement > ) => {
55+ const { onChange, numericInput = false } = this . props
56+ const { value } = e . currentTarget
57+ if ( numericInput && typeof onChange === 'function' ) {
58+ const reg = / ^ [ 0 - 9 ] + $ /
59+ if ( reg . test ( value ) || value === '' ) {
60+ onChange ( value )
61+ }
62+ } else {
63+ onChange ( value )
64+ }
65+ }
66+
67+ handleClear = ( ) => {
68+ const { onChange } = this . props
69+ if ( typeof onChange === 'function' ) {
70+ onChange ( '' )
71+ }
72+ }
73+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import './styles.scss'
2- export { Sample as default } from './Sample '
2+ export { Input } from './Input '
Original file line number Diff line number Diff line change 11@import " ~or-theme" ;
22
3- .or-btn {
3+ .or-input {
4+ position : relative ;
45 display : inline-block ;
5- min-width : 120px ;
6- padding : $btn-padding-y $btn-padding-x ;
7- background-color : $white ;
8- color : $gray8 ;
9- border-width : 1px ;
10- border-color : $gray8 ;
11- border-style : solid ;
12- font-size : 14px ;
13- border-radius : 1px ;
14- text-align : center ;
15- box-sizing : border-box ;
16- font-family : $font-family ;
17- cursor : pointer ;
186
19- & :hover {
20- background-color : $gray8 ;
21- color : $white ;
7+ input {
8+ outline : none ;
9+ line-height : 38px ;
10+ height : 38px ;
11+ padding : 0 5px ;
12+ font-size : 14px ;
2213 }
23- }
24-
25- .or-btn-primary {
26- background-color : $primary-color ;
27- color : $white ;
28- border-color : $primary-color ;
2914
30- & :hover {
31- background-color : $primary-color0 ;
32- border-color : $primary-color0 ;
33- }
15+ input ::-webkit-outer-spin-button ,
16+ input ::-webkit-inner-spin-button {
17+ /* display: none; <- Crashes Chrome on hover */
18+ -webkit-appearance : none ;
19+ margin : 0 ; /* <-- Apparently some margin are still there even though it's hidden */
3420}
3521
36- .or-btn-warning {
37- background-color : $warning-color ;
38- color : $white ;
39- border-color : $warning-color ;
40-
41- & :hover {
42- background-color : $warning-color0 ;
43- border-color : $warning-color0 ;
22+ .or-clear-icon {
23+ position : absolute ;
24+ top : 50% ;
25+ right : 10px ;
26+ transform : translateY (-50% );
27+ width : 15px ;
28+ height : 15px ;
29+ background-color : #aaa ;
30+ border-radius : 50% ;
31+ cursor : pointer ;
4432 }
4533}
34+
Original file line number Diff line number Diff line change 11{
22 "compilerOptions" : {
3- "target" : " esnext " ,
3+ "target" : " ESNext " ,
44 "module" : " commonjs" ,
55 "baseUrl" : " ./src" ,
66 "declarationDir" : " ./lib" ,
You can’t perform that action at this time.
0 commit comments