Skip to content

Commit

Permalink
给日历组件增加了disable功能
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchaofan committed Mar 6, 2018
1 parent 73eda62 commit b1ac937
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
14 changes: 12 additions & 2 deletions example/DatePicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<template>
<div>
<div class="date-picker-demo-row">
<san-date-picker value="{=date=}" />
<san-date-picker value="{=date=}" isDisabled="{{isDisabled}}"/>
</div>
<div class="date-picker-demo-row">
<san-date-picker value="{=date=}" disabled />
Expand All @@ -18,13 +18,23 @@
<script>
import DatePicker from '../src/DatePicker';
import '../src/DatePicker/DatePicker.styl';
import moment from 'moment';
export default {
components: {
'san-date-picker': DatePicker
},
initData() {
return {
date: ''
date: '',
isDisabled(date) {
let startTime = moment('20180301', 'YYYYMMDD').unix();
let endTime = moment('20180306', 'YYYYMMDD').unix();
if (date > startTime && date < endTime) {
console.log(123);
return true;
}
return false;
}
};
}
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "san-mui",
"version": "1.0.11",
"version": "1.0.12",
"description": "A Set of SAN Components that Implement Google's Material Design",
"author": "ecomfe",
"main": "./lib/index.js",
Expand Down
9 changes: 6 additions & 3 deletions src/DatePicker/Date.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ export default san.defineComponent({
let active = this.data.get('active');
let today = this.data.get('today');
let part = this.data.get('part');
let disabled = this.data.get('disabled');
return cx(this)
.addVariants(part)
.addStates({
weekend,
active,
today
today,
disabled
}).build();
}
},

click() {
this.fire('pick');
if (!this.data.get('disabled')) {
this.fire('pick');
}
}

});
8 changes: 8 additions & 0 deletions src/DatePicker/Date.styl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
.sm-ripple
background-color: rgb(0, 159, 147)

&.state-disabled
opacity: 0.4
&.state-disabled &-cell
&:hover
color: rgba(0, 0, 0, .8)
background-color: #fff


&.state-active &-cell
color: #fff
background-color: rgb(0, 159, 147)
3 changes: 2 additions & 1 deletion src/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class DatePicker extends Component {
on-open="toggleYearPanel" />
<san-month-carousel date="{=visualDate=}"/>
<san-week />
<san-month date="{=visualDate=}" value="{=pickedDate=}" />
<san-month date="{=visualDate=}" value="{=pickedDate=}" isDisabled="{{isDisabled}}"/>
<san-year
san-if="{{yearPanelOpen}}"
date="{=pickedDate=}"
Expand Down Expand Up @@ -166,6 +166,7 @@ export default class DatePicker extends Component {

}

attached() {}

openDialog() {
this.data.set('open', true);
Expand Down
11 changes: 10 additions & 1 deletion src/DatePicker/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {CenterRipple} from '../Ripple';

const FORMAT = 'YYYY-MM-DD';

let empty = function () {
return false;
};

export default class Month extends Component {

static template = `
Expand All @@ -22,6 +26,7 @@ export default class Month extends Component {
active="{{date.active}}"
today="{{date.today}}"
part="{{date.part}}"
disabled="{{date.disabled}}"
on-pick="{{setDate(date.value)}}"/>
</div>
`;
Expand All @@ -41,12 +46,13 @@ export default class Month extends Component {
let monthEnd = moment(date).endOf('month');
let begin = moment(monthBegin).startOf('week');
let end = moment(monthEnd).endOf('week');

let isDisabled = this.data.get('isDisabled') || empty;
let dates = [];

while (begin.isBefore(end)) {

dates.push({
disabled: isDisabled(begin.unix()),
value: begin.date(),
weekend: begin.weekday() > 4,
active: begin.isSame(value, 'd'),
Expand All @@ -71,6 +77,9 @@ export default class Month extends Component {
};
}

attached() {
}

setDate(date) {
this.data.set(
'value',
Expand Down

0 comments on commit b1ac937

Please sign in to comment.