Skip to content

Commit

Permalink
feat(experimental): Rating add new component (#5633)
Browse files Browse the repository at this point in the history
Co-authored-by: taiga-family-bot <[email protected]>
  • Loading branch information
waterplea and taiga-family-bot authored Oct 16, 2023
1 parent 9de981e commit 254e68b
Show file tree
Hide file tree
Showing 30 changed files with 582 additions and 8 deletions.
2 changes: 1 addition & 1 deletion projects/cdk/constants/used-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const TUI_USED_ICONS = [
`tuiIconCheckCircle`,
`tuiIconXCircle`,
`tuiIconChevronLeft`,
`tuiIconStarLarge`,
`tuiIconChevronDown`,
`tuiIconChevronDownLarge`,
`tuiIconFileLarge`,
Expand All @@ -61,7 +62,6 @@ export const TUI_USED_ICONS = [
`tuiIconEyeLarge`,
`tuiIconClock`,
`tuiIconClockLarge`,
`tuiIconStarLarge`,
`tuiIconToggleOff`,
`tuiIconToggleOffLarge`,
`tuiIconToggleOn`,
Expand Down
2 changes: 1 addition & 1 deletion projects/core/styles/mixins/mixins.less
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@

.hoverable-with-shadow() {
.shadow();
.transition(all);
.transition();
cursor: pointer;
transition-property: transform, box-shadow;
will-change: transform, box-shadow;
Expand Down
2 changes: 1 addition & 1 deletion projects/core/styles/mixins/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
}

// transition
@mixin transition($param, $speed: var(--tui-duration, 300ms)) {
@mixin transition($param: all, $speed: var(--tui-duration, 300ms)) {
transition-property: $param;
transition-duration: $speed;
transition-timing-function: ease-in-out;
Expand Down
8 changes: 8 additions & 0 deletions projects/demo/src/modules/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ export const ROUTES: Routes = [
title: `Fade`,
},
},
{
path: `experimental/rating`,
loadChildren: async () =>
(await import(`../experimental/rating/rating.module`)).ExampleTuiRatingModule,
data: {
title: `Rating`,
},
},
{
path: `experimental/sensitive`,
loadChildren: async () =>
Expand Down
6 changes: 6 additions & 0 deletions projects/demo/src/modules/app/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,12 @@ export const pages: TuiDocPages = [
keywords: `overflow, ellipsis, gradient, clamp, line`,
route: `/experimental/fade`,
},
{
section: `Experimental`,
title: `Rating `,
keywords: `рейтинг, оценка, звезда, rating, star, rate`,
route: `/experimental/rating`,
},
{
section: `Experimental`,
title: `Sensitive`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<ng-template pageTab>
<ol class="b-demo-steps">
<li>
<p>Import module</p>
<p>Import module:</p>

<tui-doc-code
filename="myComponent.module.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<ng-template pageTab>
<ol class="b-demo-steps">
<li>
<p>Import module</p>
<p>Import module:</p>

<tui-doc-code
filename="my.module.ts"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<label tuiLabel="Rate Taiga UI">
<tui-rating
class="rating"
[(ngModel)]="value"
></tui-rating>
</label>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.rating {
fill: currentColor;
font-size: 0.625rem;
width: 10rem;
}
14 changes: 14 additions & 0 deletions projects/demo/src/modules/experimental/rating/examples/1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-rating-example-1',
templateUrl: './index.html',
styleUrls: ['./index.less'],
changeDetection,
encapsulation,
})
export class TuiRatingExample1 {
value = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<label tuiLabel="Are you satisfied with Taiga UI?">
<tui-rating
class="rating"
[attr.data-value]="value"
[icon]="icon"
[max]="3"
[(ngModel)]="value"
></tui-rating>
<button
*ngIf="value"
appearance="icon"
iconLeft="tuiIconCloseLarge"
size="s"
tuiIconButton
class="button"
(click)="value = 0"
>
Clear
</button>
</label>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.rating,
.button {
display: inline-block;
vertical-align: middle;
}

.rating {
&[data-value='1'] {
color: var(--tui-negative);
}

&[data-value='2'] {
color: var(--tui-warning-fill);
}

&[data-value='3'] {
color: var(--tui-positive);
}

&:hover {
color: var(--tui-info-fill);
}
}
29 changes: 29 additions & 0 deletions projects/demo/src/modules/experimental/rating/examples/2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
import {TuiContextWithImplicit} from '@taiga-ui/cdk';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

@Component({
selector: 'tui-rating-example-2',
templateUrl: 'index.html',
styleUrls: ['index.less'],
changeDetection,
encapsulation,
})
export class TuiRatingExample2 {
value = 0;

readonly icon: PolymorpheusContent<TuiContextWithImplicit<number>> = ({
$implicit,
}) => {
switch ($implicit) {
case 1:
return 'tuiIconFrownLarge';
case 2:
return 'tuiIconMehLarge';
default:
return 'tuiIconSmileLarge';
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<label tuiLabel="Back to the Future">
<tui-rating
[max]="10"
[ngModel]="8.5"
[readOnly]="true"
></tui-rating>
</label>
11 changes: 11 additions & 0 deletions projects/demo/src/modules/experimental/rating/examples/3/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-rating-example-3',
templateUrl: 'index.html',
changeDetection,
encapsulation,
})
export class TuiRatingExample3 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```ts
import {NgModule} from '@angular/core';
import {TuiRatingModule} from '@taiga-ui/experimental';
// ...

@NgModule({
imports: [
// ...
TuiRatingModule,
],
})
export class MyModule {}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```html
<tui-rating [(ngModel)]="value"></tui-rating>
```
33 changes: 33 additions & 0 deletions projects/demo/src/modules/experimental/rating/rating.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiDocExample, TuiRawLoaderContent} from '@taiga-ui/addon-doc';

@Component({
selector: 'example-rating',
templateUrl: './rating.template.html',
changeDetection,
})
export class ExampleTuiRatingComponent {
readonly exampleModule: TuiRawLoaderContent = import(
'./examples/import/import-module.md?raw'
);

readonly exampleHtml: TuiRawLoaderContent = import(
'./examples/import/insert-template.md?raw'
);

readonly example1: TuiDocExample = {
HTML: import('./examples/1/index.html?raw'),
LESS: import('./examples/1/index.less?raw'),
};

readonly example2: TuiDocExample = {
TypeScript: import('./examples/2/index.ts?raw'),
HTML: import('./examples/2/index.html?raw'),
LESS: import('./examples/2/index.less?raw'),
};

readonly example3: TuiDocExample = {
HTML: import('./examples/3/index.html?raw'),
};
}
31 changes: 31 additions & 0 deletions projects/demo/src/modules/experimental/rating/rating.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {tuiGetDocModules} from '@taiga-ui/addon-doc';
import {TuiLabelModule, TuiNotificationModule} from '@taiga-ui/core';
import {TuiButtonModule, TuiRatingModule} from '@taiga-ui/experimental';

import {TuiRatingExample1} from './examples/1';
import {TuiRatingExample2} from './examples/2';
import {TuiRatingExample3} from './examples/3';
import {ExampleTuiRatingComponent} from './rating.component';

@NgModule({
imports: [
CommonModule,
FormsModule,
TuiRatingModule,
TuiNotificationModule,
TuiLabelModule,
tuiGetDocModules(ExampleTuiRatingComponent),
TuiButtonModule,
],
declarations: [
ExampleTuiRatingComponent,
TuiRatingExample1,
TuiRatingExample2,
TuiRatingExample3,
],
exports: [ExampleTuiRatingComponent],
})
export class ExampleTuiRatingModule {}
59 changes: 59 additions & 0 deletions projects/demo/src/modules/experimental/rating/rating.template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<tui-doc-page
header="Rating"
package="EXPERIMENTAL"
type="components"
>
<ng-template pageTab>
<tui-notification status="warning">
This code is
<strong>experimental</strong>
and is a subject to change. Expect final solution to be shipped in the next major version
</tui-notification>

<tui-doc-example
id="basic"
heading="Basic"
[content]="example1"
>
<tui-rating-example-1></tui-rating-example-1>
</tui-doc-example>

<tui-doc-example
id="icons"
heading="Custom icons"
[content]="example2"
>
<tui-rating-example-2></tui-rating-example-2>
</tui-doc-example>

<tui-doc-example
id="readonly"
heading="Readonly"
[content]="example3"
>
<tui-rating-example-3></tui-rating-example-3>
</tui-doc-example>
</ng-template>

<ng-template pageTab="Setup">
<ol class="b-demo-steps">
<li>
<p>Import module:</p>

<tui-doc-code
filename="my.module.ts"
[code]="exampleModule"
></tui-doc-code>
</li>

<li>
<p>Add to the template:</p>

<tui-doc-code
filename="my.component.html"
[code]="exampleHtml"
></tui-doc-code>
</li>
</ol>
</ng-template>
</tui-doc-page>
1 change: 1 addition & 0 deletions projects/experimental/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from '@taiga-ui/experimental/components/badge-alert';
export * from '@taiga-ui/experimental/components/badged-content';
export * from '@taiga-ui/experimental/components/button';
export * from '@taiga-ui/experimental/components/compass';
export * from '@taiga-ui/experimental/components/rating';
3 changes: 3 additions & 0 deletions projects/experimental/components/rating/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './rating.component';
export * from './rating.module';
export * from './rating.options';
8 changes: 8 additions & 0 deletions projects/experimental/components/rating/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"lib": {
"entryFile": "index.ts",
"styleIncludePaths": [
"../../../core/styles"
]
}
}
Loading

0 comments on commit 254e68b

Please sign in to comment.