1- import {
2- WebCellProps,
3- component,
4- mixin,
5- attribute,
6- watch,
7- createCell
8- } from 'web-cell';
9-
10- import { Status } from '../../utility/constant';
11- import style from './index.less';
1+ import { computed, observable } from 'mobx';
2+ import { WebCell, attribute, component, observer } from 'web-cell';
3+
4+ import { Status } from './type';
125
136interface TimeUnit {
147 scale: number;
@@ -22,24 +15,24 @@ interface TimeSection {
2215
2316const colors = Object.keys(Status).slice(0, 4);
2417
25- export interface CountDownProps extends WebCellProps {
18+ export interface CountDownProps {
2619 endTime?: string | Date | number;
2720}
2821
29- @component({
30- tagName: 'count-down',
31- renderTarget : 'children'
32- })
33- export class CountDown extends mixin <CountDownProps>() {
22+ export interface CountDown extends WebCell<CountDownProps> {}
23+
24+ @component({ tagName : 'count-down' })
25+ @observer
26+ export class CountDown extends HTMLElement implements WebCell <CountDownProps> {
3427 @attribute
35- @watch
36- endTime: CountDownProps['endTime'] = Date.now();
28+ @observable
29+ accessor endTime: CountDownProps['endTime'] = Date.now();
3730
38- @watch
39- rest = 0;
31+ @observable
32+ accessor rest = 0;
4033
41- @watch
42- units: TimeUnit[] = [
34+ @observable
35+ accessor units: TimeUnit[] = [
4336 {
4437 scale: 24,
4538 label: 'D'
@@ -58,6 +51,7 @@ export class CountDown extends mixin<CountDownProps>() {
5851 }
5952 ];
6053
54+ @computed
6155 get timeSections() {
6256 var { rest } = this;
6357
@@ -105,7 +99,9 @@ export class CountDown extends mixin<CountDownProps>() {
10599 <ol className="list-inline text-white">
106100 {this.timeSections.map(({ value, label }, index) => (
107101 <li
108- className={`list-inline-item display-4 bg-${colors[index]} ${style.section}`}
102+ key={value}
103+ className={`list-inline-item display-4 bg-${colors[index]} d-inline-flex align-items-center justify-content-center rounded-5`}
104+ style={{ width: '5.5rem', height: '5.5rem' }}
109105 >
110106 <small>
111107 {(value + '').padStart(2, '0')}
0 commit comments