Skip to content

Commit 704a527

Browse files
committed
Basic input using material design
1 parent 5aacd7c commit 704a527

File tree

4 files changed

+99
-36
lines changed

4 files changed

+99
-36
lines changed

source/components/input.cjsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
###
2+
@todo
3+
###
4+
5+
module.exports = React.createClass
6+
7+
# -- States & Properties
8+
propTypes:
9+
label : React.PropTypes.string
10+
value : React.PropTypes.string
11+
type : React.PropTypes.string
12+
disabled : React.PropTypes.boolean
13+
onChange : React.PropTypes.function
14+
15+
getDefaultProps: ->
16+
type : "text"
17+
disabled : false
18+
19+
# -- Events
20+
onChange: (event) ->
21+
console.log "onChange"
22+
23+
# -- Render
24+
render: ->
25+
<div data-component="input">
26+
<input
27+
type={@props.type}
28+
value={@props.value}
29+
placeholder={@props.hint
30+
disabled={@props.disabled}
31+
required={@props.required} />
32+
<span className="bar"></span>
33+
{ <label>{@props.label}</label> if @props.label }
34+
{ <span className="error">{@props.error}</span> if @props.error }
35+
</div>

source/styles/__constants.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ THEME = #00bcd4
77

88
WHITE = #ffffff
99
PRIMARY = rgb(255, 64, 129)
10+
CANCEL = #f44336
1011

1112
// -- Fonts
1213
FONT_FAMILY = "Roboto", "Helvetica Neue", "Helvetica", "sans-serif"

source/styles/components/input.styl

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,65 @@
1-
input[type="email"], input[type="search"], input[type="text"], input[type="tel"],
2-
input[type="url"], input[type="password"], textarea, select
3-
width : 100%
4-
padding : (SPACE / 2)
5-
font-size : FONT_SIZE_NORMAL
6-
border : none
7-
border-bottom : solid (SPACE / 10)
8-
box-shadow : none
9-
box-sizing : border-box
10-
transition all ANIMATION_DURATION ANIMATION_EASE
11-
& :focus
12-
outline : 0
1+
[data-component="input"]
2+
position : relative
3+
margin-bottom : SPACE
134

14-
-webkit-appearance : none
15-
-moz-appearance : none
16-
appearance : none
17-
outline : none
18-
-webkit-tap-highlight-color : rgba(255, 255, 255, 0)
19-
-webkit-touch-callout : none
5+
input, label
6+
font-size : FONT_SIZE_NORMAL
7+
font-weight : FONT_WEIGHT_NORMAL
208

21-
// -- class ------------------------------------------------------------------
22-
&.transparent
23-
font-size : FONT_SIZE_BIG
24-
font-weight : FONT_WEIGHT_BOLD
25-
background-color : transparent
26-
color : WHITE
27-
border-bottom-color : alpha(WHITE, 50%)
28-
&:hover, &:focus, &:active
29-
border-bottom-color : WHITE
30-
&::-webkit-input-placeholder
31-
color : alpha(WHITE, 50%)
9+
input
10+
display : block
11+
padding : (SPACE / 2) 0
12+
width : 100%
13+
color : COLOR
14+
border : none
15+
border-bottom : 1px solid lighten(COLOR, 75%)
16+
// -- Attributes
17+
&:focus
18+
outline : none
19+
~ .bar:before, ~ .bar:after
20+
width : 50%
21+
&:focus ~ label, &:valid ~ label
22+
top : -(SPACE / 2)
23+
font-size : FONT_SIZE_TINY
24+
color : THEME
25+
&:disabled
26+
border-bottom-style : dotted
27+
&:invalid
28+
border-bottom-color : CANCEL
29+
~ .bar:before, ~ .bar:after
30+
background-color : CANCEL
3231

33-
&.white
34-
border-bottom-color : alpha(BACKGROUND, 25%)
35-
opacity : 0.75
36-
&:hover, &:focus, &:active
37-
border-bottom-color : THEME
38-
opacity : 1
32+
label
33+
position : absolute
34+
left : 0
35+
top : (SPACE / 2)
36+
color : lighten(COLOR, 75%)
37+
pointer-events : none
38+
transition-property top, font-size, color
39+
transition-duration ANIMATION_DURATION
40+
transition-timing-function ANIMATION_EASE
41+
42+
.bar
43+
position : relative
44+
display : block
45+
width : 100%
46+
&:before, &:after
47+
content : ''
48+
position : absolute
49+
height : 2px
50+
width : 0
51+
bottom : 0
52+
background-color : THEME
53+
transition-property width, background-color
54+
transition-duration ANIMATION_DURATION
55+
transition-timing-function ANIMATION_EASE
56+
&:before
57+
left : 50%
58+
&:after
59+
right : 50%
60+
61+
.error
62+
position : absolute
63+
bottom : -(SPACE)
64+
font-size : FONT_SIZE_TINY
65+
color : CANCEL

source/styles/normalize.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ a,abbr,address,article,aside,audio,b,blockquote,body,caption,cite,code,dd,del,df
159159
*, *:before, *:after
160160
margin: 0
161161
padding: 0
162-
box-sizing(border-box)
162+
box-sizing: border-box
163163

164164
html
165165
position: absolute

0 commit comments

Comments
 (0)