Skip to content

Commit

Permalink
[新增] 增加Rate组件,可用于评分, fixes #258
Browse files Browse the repository at this point in the history
  • Loading branch information
rdkmaster committed Jan 14, 2019
1 parent 3ec6642 commit 314bb75
Show file tree
Hide file tree
Showing 14 changed files with 384 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app/demo-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {routerConfig as paginationConfig} from "./demo/pagination/demo-set.modul
import {routerConfig as popupConfig} from "./demo/popup/demo-set.module";
import {routerConfig as radioConfig} from "./demo/radio-group/demo-set.module";
import {routerConfig as radioLiteConfig} from "./demo/radio-lite/demo-set.module";
import {routerConfig as rateConfig} from "./demo/rate/demo-set.module";
import {routerConfig as rangeTimeConfig} from "./demo/range-time/demo-set.module";
import {routerConfig as scrollbarConfig} from "./demo/scrollbar/demo-set.module";
import {routerConfig as selectConfig} from "./demo/select/demo-set.module";
Expand Down Expand Up @@ -126,6 +127,7 @@ export class DemoListManager {
this._addRouterConfig(routerConfig, 'popup', popupConfig);
this._addRouterConfig(routerConfig, 'radio-group', radioConfig);
this._addRouterConfig(routerConfig, 'radio-lite', radioLiteConfig);
this._addRouterConfig(routerConfig, 'rate', rateConfig);
this._addRouterConfig(routerConfig, 'range-time', rangeTimeConfig);
this._addRouterConfig(routerConfig, 'scrollbar', scrollbarConfig);
this._addRouterConfig(routerConfig, 'select', selectConfig);
Expand Down
19 changes: 19 additions & 0 deletions src/app/demo/rate/demo-set.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {NgModule} from "@angular/core";
import {RouterModule} from "@angular/router";
import {RateFullModule} from "./full/demo.module";
import {RateFullComponent} from "./full/demo.component";

export const routerConfig = [
{
path: 'full', component: RateFullComponent
},
];

@NgModule({
imports: [
RouterModule.forChild(routerConfig),
RateFullModule
]
})
export class RateDemoModule {
}
3 changes: 3 additions & 0 deletions src/app/demo/rate/full/demo.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.rate-font-size{
font-size: 20px;
}
28 changes: 28 additions & 0 deletions src/app/demo/rate/full/demo.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- ignore the following lines, they are not important to this demo -->
<jigsaw-demo-description [summary]="summary" [content]="description">
</jigsaw-demo-description>


<!-- start to learn the demo from here -->
<div class="live-demo-wrap">
<h2>Rate</h2>
<div class="clearfix">
<div class="demo-1 live-demo live-demo-block">
<h3>基本</h3>
<p class="comment">基本用法</p>
<jigsaw-rate class="rate-font-size" max="5" icon="fa fa-paper-plane" [(value)]="selectedValue" (valueChange)="selectChange($event)"></jigsaw-rate>
</div>

<div class="demo-2 live-demo live-demo-block">
<h3>半星</h3>
<p class="comment">支持选中半星</p>
<jigsaw-rate class="rate-font-size" max="5" [allowHalf]="true" [(value)]="selectedHalfValue" (valueChange)="selectChange($event)"></jigsaw-rate>
</div>

<div class="demo-2 live-demo live-demo-block">
<h3>只读</h3>
<p class="comment">支持标签和属性两种写法</p>
<jigsaw-rate class="rate-font-size" max="5" [disabled]="true" [(value)]="selectedValue"></jigsaw-rate>
</div>
</div>
</div>
22 changes: 22 additions & 0 deletions src/app/demo/rate/full/demo.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Component} from "@angular/core";

@Component({
templateUrl: './demo.component.html',
styleUrls: ['./demo.component.css']
})
export class RateFullComponent {

selectedValue = 3;
selectedHalfValue = 2.5;

selectChange(value: any) {
console.log(value);
}

// ====================================================================
// ignore the following lines, they are not important to this demo
// ====================================================================
summary: string = '演示了Rate组件的多种用法';
description: string = '';
}

14 changes: 14 additions & 0 deletions src/app/demo/rate/full/demo.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {NgModule} from "@angular/core";
import {JigsawDemoDescriptionModule} from "app/demo-description/demo-description";
import {JigsawRateModule} from "jigsaw/component/rate";
import {RateFullComponent} from "./demo.component";
import {CommonModule} from "@angular/common";

@NgModule({
declarations: [RateFullComponent],
exports: [RateFullComponent],
imports: [JigsawRateModule, JigsawDemoDescriptionModule,CommonModule]
})
export class RateFullModule {

}
4 changes: 4 additions & 0 deletions src/app/router-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export const routerConfig = [
path: "range-time",
loadChildren: "./demo/range-time/demo-set.module#RangeTimeDemoModule",
},
{
path: "rate",
loadChildren: "./demo/rate/demo-set.module#RateDemoModule",
},
{
path: "scrollbar",
loadChildren: "./demo/scrollbar/demo-set.module#ScrollbarDemoModule",
Expand Down
13 changes: 13 additions & 0 deletions src/jigsaw/component/rate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { JigsawRateComponent } from './rate';

@NgModule({
imports: [
CommonModule
],
declarations: [JigsawRateComponent],
exports: [JigsawRateComponent]
})
export class JigsawRateModule { }
13 changes: 13 additions & 0 deletions src/jigsaw/component/rate/rate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ul [ngClass]="_$classMap" (mouseleave)="_$leaveRate($event)">
<li *ngFor="let i of _$stars" [ngClass]="_$setClasses(i)"
(mouseover)="_$hoverRate($event, i, true)"
(click)="_$clickRate($event, i, true)">
<div class="jigsaw-rate-star-first" (mouseover)="_$hoverRate($event, i)" (click)="_$clickRate($event, i)">
<i [ngClass]="icon"></i>
</div>
<div class="jigsaw-rate-star-second" (mouseover)="_$hoverRate($event, i, true)"
(click)="_$clickRate($event, i, true)">
<i [ngClass]="icon"></i>
</div>
</li>
</ul>
60 changes: 60 additions & 0 deletions src/jigsaw/component/rate/rate.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@import "../../assets/scss/core/base";

.#{$jigsaw-prefix}-rate {
margin: 0;
padding: 0;
list-style: none;
display: inline-block;
vertical-align: middle;
&-disabled &-star {
cursor: not-allowed;
&:hover {
transform: scale(1);
}
}
&-star {
padding: 0;
display: inline-block;
margin: 0 8px 0 0;
position: relative;
transition: all .3s;
color: #e9e9e9;
cursor: pointer;

&-first,
&-second {
user-select: none;
transition: all .3s;
}

&:hover {
transform: scale(1.1);
}

&-first {
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
opacity: 0;
}

&-half &-first,
&-half &-second {
opacity: 1;
}

&-half &-first,
&-full &-second {
color: #f5a623;
}

&-half:hover &-first,
&-full:hover &-second {
color: #f5a623;
}
}
}

Loading

0 comments on commit 314bb75

Please sign in to comment.