Improved height for dataSource container & fixed typos.

old
Javi Jimenez Villar 2015-06-27 22:30:21 +07:00
parent b78a7b05a0
commit dd9d3e2598
3 changed files with 32 additions and 30 deletions

View File

@ -24,7 +24,6 @@ module.exports = React.createClass
# -- Events # -- Events
onSelect: (event) -> onSelect: (event) ->
console.log "onSelect", event.target
@setState active: true @setState active: true
onItem: (event) -> onItem: (event) ->
@ -33,17 +32,17 @@ module.exports = React.createClass
# -- Render # -- Render
render: -> render: ->
className = @props.className className = @props.className
className += " active" if @state.active is true if @state.active is true
className += " active"
console.log "render.className", className stylesheet = height: @getDOMNode().offsetHeight * Object.keys(@props.dataSource).length
<div data-component-dropdown={@props.type}
<div data-component-dropdown={@props.type} className={className}> className={className}>
<span onClick={@onSelect}>{@props.dataSource[@state.value]}</span> <span onClick={@onSelect}>{@props.dataSource[@state.value]}</span>
<ul onClick={@onItem}> <ul onClick={@onItem} style={stylesheet}>
{ {
for key, label of @props.dataSource for key, label of @props.dataSource
<li id={key} className={"selected" if key is @state.value}>{label}</li> <li id={key} className={"selected" if key is @state.value}>{label}</li>
} }
</ul> </ul>
</div> </div>

View File

@ -3,36 +3,38 @@
[data-component-dropdown] [data-component-dropdown]
position : relative position : relative
margin-bottom : SPACE margin-bottom : SPACE
width : (4 * UNIT)
height : INPUT_HEIGHT height : INPUT_HEIGHT
width : inherit
color : COLOR color : COLOR
border-bottom : 1px solid lighten(COLOR, 75%) border-bottom : 1px solid lighten(COLOR, 75%)
// -- Class // -- Class
&.active &.active
> span > span
opacity : 0 opacity : 0
transform translateY(25%) transform translateY((INPUT_HEIGHT / 4))
&:after &:after
transform scale(0) transform scale(0)
> ul > ul
z-index : 2
visibility : visible
height : auto
opacity : 1 opacity : 1
transform translateY(0%) transform translateY(0%)
box-shadow ZDEPTH_SHADOW_1 box-shadow ZDEPTH_SHADOW_1
> li
opacity : 1
transition opacity ANIMATION_DURATION ANIMATION_EASE
&:not(.active) > ul
pointer-events :none
// -- Children // -- Children
> * > *
width : 100% width : 100%
transition-property opacity, transform, box-shadow, height
transition-duration ANIMATION_DURATION
transition-timing-function ANIMATION_EASE
> span > span
display : block display : block
// padding : (SPACE / 2) 0
line-height : INPUT_HEIGHT line-height : INPUT_HEIGHT
font-size : FONT_SIZE_NORMAL font-size : FONT_SIZE_NORMAL
transition-property opacity, transform
transition-duration ANIMATION_DURATION
transition-timing-function ANIMATION_EASE
&:after &:after
SIZE = (INPUT_HEIGHT / 7) SIZE = (INPUT_HEIGHT / 7)
position : absolute position : absolute
@ -41,30 +43,33 @@
top : SPACE top : SPACE
width : 0 width : 0
height : 0 height : 0
border-left : SIZE solid transparent border-left : BORDER = SIZE solid transparent
border-right : SIZE solid transparent border-right : BORDER
border-top : SIZE solid lighten(COLOR, 75%) border-top : SIZE solid lighten(COLOR, 75%)
transition transform ANIMATION_DURATION ANIMATION_EASE transition transform ANIMATION_DURATION ANIMATION_EASE
> ul > ul
z-index : -1 z-index : 2
position : absolute position : absolute
overflow : hidden
top : 0 top : 0
left : -(OFFSET = (SPACE / 1.25)) left : -(OFFSET = (SPACE / 1.25))
right : -(OFFSET) right : -(OFFSET)
width : auto width : auto
height : 0 height : 0
max-height : 50vh
list-style : none list-style : none
opacity : 0 opacity : 0
background-color : WHITE background-color : WHITE
border-radius : BORDER_RADIUS border-radius : BORDER_RADIUS
transform translateY(-(INPUT_HEIGHT)) transform translateY(-(INPUT_HEIGHT / 2))
transition-property height, box-shadow, opacity, transform
transition-duration ANIMATION_DURATION
transition-timing-function ANIMATION_EASE
> li > li
padding : (SPACE / 2) OFFSET padding : (SPACE / 2) OFFSET
font-size : FONT_SIZE_SMALL opacity : 0
&:hover &:hover
background-color : BACKGROUND background-color : BACKGROUND
cursor : pointer cursor : pointer
&.selected &.selected
color : THEME color : PRIMARY

View File

@ -14,6 +14,7 @@ module.exports = React.createClass
"TH-th" : "Thailand" "TH-th" : "Thailand"
"EN-gb" : "England" "EN-gb" : "England"
"EN-en" : "USA" "EN-en" : "USA"
"FR-fr" : "France"
# -- Events # -- Events
onAutocompleteValues: (ref, method) -> onAutocompleteValues: (ref, method) ->
@ -28,10 +29,7 @@ module.exports = React.createClass
<section> <section>
<h2>Dropdown</h2> <h2>Dropdown</h2>
<p>lorem ipsum...</p> <p>lorem ipsum...</p>
<Dropdown ref="dropdown" dataSource={@state.countries_obj} /> <Dropdown ref="dropdown" dataSource={@state.countries_obj} />
<Dropdown ref="dropdown" dataSource={@state.countries_obj} <Dropdown ref="dropdown" dataSource={@state.countries_obj}
value={countries_obj_selected} /> value={countries_obj_selected} />
</section> </section>