Skip to content

Commit 50ac32e

Browse files
committed
feat(select): add animation for select
fix #54
1 parent 6827435 commit 50ac32e

File tree

6 files changed

+70
-27
lines changed

6 files changed

+70
-27
lines changed

packages/_theme/src/components/option.less

+24-19
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,40 @@
44
@option-prefix-cls: ~"@{pure-prefix}-option";
55

66
.@{option-prefix-cls} {
7-
padding: 6px 10px;
7+
display: flex;
88
overflow: hidden;
99

10+
&:not(:first-child) {
11+
.@{option-prefix-cls}__content {
12+
border-top: solid 1px #f2f2f2;
13+
}
14+
}
15+
1016
&:hover {
11-
background-color: fade(@primary-color,5%);
17+
background-color: #f9f9f9;
1218
}
1319

14-
&--checked {
20+
&.is-checked {
1521
position: relative;
16-
background-color: fade(@primary-color,5%);
22+
background-color: fade(@primary-color,6%);
1723
color: @primary-color;
1824

19-
&::after {
20-
font-family: 'pureicon';
21-
font-style: normal;
22-
-webkit-font-smoothing: antialiased;
23-
-moz-osx-font-smoothing: grayscale;
24-
display: block;
25-
content: '\e63f';
26-
position: absolute;
27-
right: 10px;
28-
top: 50%;
29-
transform: translate3d(0,-50%,0);
30-
color: @primary-color;
31-
font-size: 13px;
32-
}
33-
3425
&:hover {
3526
background-color: fade(@primary-color,10%);
3627
}
3728
}
29+
30+
&__icon {
31+
padding: 8px 4px;
32+
font-size: 13px;
33+
color: @primary-color;
34+
width: 20px;
35+
text-align: center;
36+
}
37+
38+
&__content {
39+
flex: 1;
40+
padding: 8px 10px 8px 0;
41+
font-size: 13px;
42+
}
3843
}

packages/_theme/src/components/select.less

+10-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@
4242
margin-top: 5px;
4343
padding: 5px 0;
4444
background-color: #fff;
45-
border: solid 1px #ddd;
46-
box-shadow: 1px 1px 6px 1px rgba(0,0,0,.1);
45+
border: solid 1px #f2f2f2;
46+
box-shadow: 1px 1px 6px 1px rgba(0,0,0,.03);
4747
z-index: 1;
48+
opacity: 0;
49+
transform: translate3d(0,-20px,0) scale(.9);
50+
transition: all .16s ease;
51+
52+
&.is-transition-fadeup {
53+
opacity: 1;
54+
transform: translate3d(0,0,0) scale(1);
55+
}
4856
}
4957

5058
.@{input-prefix-cls}__wrapper {

packages/option/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"license": "MIT",
1111
"devDependencies": {
1212
"pure-cli": "latest"
13+
},
14+
"dependencies": {
15+
"@pure/icon": "^0.1.0"
1316
}
1417
}

packages/option/src/option.rgl

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
<template>
2-
<div class="pure-option { checked ? 'pure-option--checked' : '' }" ref="option" on-click="{ this.onClick() }">
3-
{#inc this.$body}
2+
<div
3+
class="pure-option { checked ? 'is-checked' : '' }"
4+
ref="option"
5+
on-click="{ this.onCheck() }"
6+
>
7+
<div class="pure-option__icon">
8+
{#if checked}
9+
<Icon type="right"></Icon>
10+
{/if}
11+
</div>
12+
<div class="pure-option__content">
13+
{#inc this.$body}
14+
</div>
415
</div>
516
</template>
617

718
<script>
19+
import Icon from '@pure/icon';
20+
821
export default {
22+
components: {
23+
Icon,
24+
},
925
config() {
1026
this.data.checked = false;
1127

1228
if ( this.$outer && this.$outer.optionPing ) {
1329
this.$outer.optionPing( this );
1430
}
1531
},
16-
onClick() {
32+
onCheck() {
1733
if ( this.$outer && this.$outer.onOptionChange ) {
1834
this.$outer.onOptionChange( this );
1935
}

packages/select/src/select.rgl

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
<Input placeholder="{ placeholder || 'Choose' }" value="{ text }" readonly sm="{ sm }" transparent="{ transparent }" on-click="{ this.onToggleOptions() }"></Input>
44

55
<div class="pure-select__icon" style="{ show ? 'display: block;' : '' }">
6-
<Icon>&#xe60b;</Icon>
6+
<Icon type="down2"></Icon>
77
</div>
88

9-
<div class="pure-select__options" r-hide="{ !show }">
9+
{#if show}
10+
<div
11+
class="pure-select__options"
12+
r-animation="on: enter;class: is-transition-fadeup,3;"
13+
r-animation="on: leave;class: is-transition-fadeup,4;"
14+
>
1015
{#inc this.$body}
1116
</div>
17+
{/if}
1218
</div>
1319
</template>
1420

@@ -44,6 +50,11 @@
4450
},
4551
optionPing( target ) {
4652
this.children.push( target );
53+
if ( this.data.selected === target.data.value ) {
54+
target.data.checked = true;
55+
} else {
56+
target.data.checked = false;
57+
}
4758
},
4859
onOptionChange( target ) {
4960
this.data.show = false;

play/select.play.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Option from '@pure/option';
44
play( Select, module ).name( 'Select' ).component( 'Option', Option ).add(
55
'basic',
66
`
7-
<Select selected="0">
7+
<Select>
88
<Option value="0">Option 0</Option>
99
<Option value="1">Option 1</Option>
1010
<Option value="2">Option 2</Option>

0 commit comments

Comments
 (0)