-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!:
Rating
replace with experimental component, add migration (
#7134) Co-authored-by: taiga-family-bot <[email protected]>
- Loading branch information
1 parent
d85944c
commit 66aeb22
Showing
56 changed files
with
410 additions
and
1,365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
projects/cdk/schematics/ng-update/v4/steps/migrate-styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {getActiveProject} from 'ng-morph'; | ||
|
||
export const TUI_RATING_WARNING = | ||
'// TODO: (Taiga UI migration): use css to customize rating gap and size. See https://taiga-ui.dev/components/rating#basic'; | ||
|
||
export function migrateStyles(): void { | ||
getActiveProject() | ||
?.getSourceFiles('**/**.{less,sass,scss,css}') | ||
.forEach(sourceFile => { | ||
let fullText = sourceFile.getFullText(); | ||
|
||
fullText = fullText | ||
// eslint-disable-next-line | ||
.replace(/^(.*--tui-rating-size.*)$/gm, `${TUI_RATING_WARNING}\n$1`) | ||
// eslint-disable-next-line | ||
.replace(/^(.*--tui-rating-gap.*)$/gm, `${TUI_RATING_WARNING}\n$1`); | ||
|
||
sourceFile.replaceWithText(fullText); | ||
}); | ||
} |
70 changes: 70 additions & 0 deletions
70
projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-styles.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {join} from 'node:path'; | ||
|
||
import {HostTree} from '@angular-devkit/schematics'; | ||
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; | ||
import type {TuiSchema} from '@taiga-ui/cdk/schematics/ng-add/schema'; | ||
import { | ||
createProject, | ||
createSourceFile, | ||
resetActiveProject, | ||
saveActiveProject, | ||
setActiveProject, | ||
} from 'ng-morph'; | ||
|
||
const collectionPath = join(__dirname, '../../../migration.json'); | ||
|
||
const STYLES_BEFORE = ` | ||
:host { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
--tui-rating-size: 1.5rem; | ||
--tui-rating-gap: 0.5rem; | ||
} | ||
`; | ||
|
||
const STYLES_AFTER = ` | ||
:host { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
// TODO: (Taiga UI migration): use css to customize rating gap and size. See https://taiga-ui.dev/components/rating#basic | ||
--tui-rating-size: 1.5rem; | ||
// TODO: (Taiga UI migration): use css to customize rating gap and size. See https://taiga-ui.dev/components/rating#basic | ||
--tui-rating-gap: 0.5rem; | ||
} | ||
`; | ||
|
||
describe('ng-update', () => { | ||
let host: UnitTestTree; | ||
let runner: SchematicTestRunner; | ||
|
||
beforeEach(() => { | ||
host = new UnitTestTree(new HostTree()); | ||
runner = new SchematicTestRunner('schematics', collectionPath); | ||
|
||
setActiveProject(createProject(host)); | ||
|
||
createMainFiles(); | ||
|
||
saveActiveProject(); | ||
}); | ||
|
||
it('should migrate styles', async () => { | ||
const tree = await runner.runSchematic( | ||
'updateToV4', | ||
{'skip-logs': process.env['TUI_CI'] === 'true'} as Partial<TuiSchema>, | ||
host, | ||
); | ||
|
||
expect(tree.readContent('test/styles.less')).toEqual(STYLES_AFTER); | ||
}); | ||
|
||
afterEach(() => resetActiveProject()); | ||
}); | ||
|
||
function createMainFiles(): void { | ||
createSourceFile('test/styles.less', STYLES_BEFORE); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 3 additions & 48 deletions
51
projects/demo/src/modules/components/rating/examples/1/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,6 @@ | ||
<div class="example"> | ||
<h2>Template Driven</h2> | ||
|
||
<p> | ||
<b>value = {{ rateValue }}</b> | ||
</p> | ||
<label tuiLabel="Rate Taiga UI"> | ||
<tui-rating | ||
class="rating" | ||
[(ngModel)]="rateValue" | ||
[(ngModel)]="value" | ||
/> | ||
|
||
<p> | ||
<b>Read only</b> | ||
</p> | ||
<tui-rating | ||
class="rating" | ||
[readOnly]="true" | ||
[(ngModel)]="rateValue" | ||
/> | ||
|
||
<p> | ||
<b>Disabled</b> | ||
</p> | ||
<tui-rating | ||
class="rating" | ||
[disabled]="true" | ||
[(ngModel)]="rateValue" | ||
/> | ||
</div> | ||
|
||
<div class="example"> | ||
<h2>Reactive Forms / Disabled</h2> | ||
|
||
<p> | ||
<b>value = {{ rateControl.value }}</b> | ||
</p> | ||
<tui-rating | ||
class="rating" | ||
[formControl]="rateControl" | ||
/> | ||
</div> | ||
|
||
<button | ||
size="xs" | ||
tuiButton | ||
type="button" | ||
class="example" | ||
(click)="enableOrDisable()" | ||
> | ||
{{ rateControl.disabled ? 'enable' : 'disable' }} form control | ||
</button> | ||
</label> |
10 changes: 3 additions & 7 deletions
10
projects/demo/src/modules/components/rating/examples/1/index.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
@import '@taiga-ui/core/styles/taiga-ui-local'; | ||
|
||
.example { | ||
.tui-space(bottom, 2); | ||
} | ||
|
||
.rating { | ||
color: var(--tui-accent); | ||
fill: currentColor; | ||
font-size: 0.625rem; | ||
width: 10rem; | ||
} |
22 changes: 9 additions & 13 deletions
22
projects/demo/src/modules/components/rating/examples/1/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
import {FormsModule} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {TuiLabelModule} from '@taiga-ui/core'; | ||
import {TuiRatingComponent} from '@taiga-ui/kit'; | ||
|
||
@Component({ | ||
selector: 'tui-rating-example-1', | ||
standalone: true, | ||
imports: [TuiRatingComponent, TuiLabelModule, FormsModule], | ||
templateUrl: './index.html', | ||
styleUrls: ['./index.less'], | ||
encapsulation, | ||
changeDetection, | ||
}) | ||
export class TuiRatingExample1 { | ||
protected rateControl = new FormControl(2); | ||
protected rateValue = 2; | ||
|
||
protected enableOrDisable(): void { | ||
if (this.rateControl.disabled) { | ||
this.rateControl.enable(); | ||
} else { | ||
this.rateControl.disable(); | ||
} | ||
} | ||
export default class ExampleComponent { | ||
protected value = 0; | ||
} |
50 changes: 18 additions & 32 deletions
50
projects/demo/src/modules/components/rating/examples/2/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,20 @@ | ||
<div class="example"> | ||
<h2>Custom colors</h2> | ||
|
||
<p> | ||
<b>Yellow / value = {{ firstRate }}</b> | ||
</p> | ||
<label tuiLabel="Are you satisfied with Taiga UI?"> | ||
<tui-rating | ||
class="yellow" | ||
[(ngModel)]="firstRate" | ||
class="rating" | ||
[attr.data-value]="value" | ||
[icon]="icon" | ||
[max]="3" | ||
[(ngModel)]="value" | ||
/> | ||
|
||
<p> | ||
<b>10 stars / value = {{ secondRate }}</b> | ||
</p> | ||
<tui-rating | ||
class="pink" | ||
[max]="10" | ||
[(ngModel)]="secondRate" | ||
/> | ||
</div> | ||
|
||
<div class="example"> | ||
<h2>Custom icons</h2> | ||
|
||
<p> | ||
<b>Controlled / value = {{ thirdRate }}</b> | ||
</p> | ||
<tui-rating | ||
iconFilled="tuiIconHeartLarge" | ||
iconNormal="tuiIconHeart" | ||
class="red" | ||
[(ngModel)]="thirdRate" | ||
/> | ||
</div> | ||
<button | ||
*ngIf="value" | ||
appearance="icon" | ||
iconLeft="tuiIconCloseLarge" | ||
size="s" | ||
tuiIconButton | ||
class="button" | ||
(click)="value = 0" | ||
> | ||
Clear | ||
</button> | ||
</label> |
Oops, something went wrong.