-
Notifications
You must be signed in to change notification settings - Fork 0
toggleswitch: стилизация, сторисы, обёртки #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
khaliulin
wants to merge
5
commits into
feature/styles-debug
Choose a base branch
from
form.inputswitch
base: feature/styles-debug
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
432fe10
toggleswitch: стилизация, сторисы, обёртки
5ce2873
редактирование группы компонента
4f9e718
Merge branch 'feature/styles-debug' into form.inputswitch
khaliulin bfb2994
toggleswitch: убрать @Input invalid/disabled, читать из NgControl
413a903
toggleswitch: stories переведены на FormControl и Validators
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,62 @@ | ||
| import { Component, EventEmitter, Input, Output, forwardRef } from '@angular/core'; | ||
| import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms'; | ||
| import { ToggleSwitch } from 'primeng/toggleswitch'; | ||
|
|
||
| @Component({ | ||
| selector: 'toggleswitch', | ||
| standalone: true, | ||
| imports: [ToggleSwitch, FormsModule], | ||
| providers: [ | ||
| { | ||
| provide: NG_VALUE_ACCESSOR, | ||
| useExisting: forwardRef(() => ToggleSwitchComponent), | ||
| multi: true, | ||
| }, | ||
| ], | ||
| template: ` | ||
| <p-toggleswitch | ||
| [ngModel]="modelValue" | ||
| (ngModelChange)="handleChange($event)" | ||
| [invalid]="invalid" | ||
| [disabled]="disabled" | ||
| (onChange)="onChange.emit($event)" | ||
| (onFocus)="onFocus.emit($event)" | ||
| (onBlur)="onBlur.emit($event)" | ||
| ></p-toggleswitch> | ||
| `, | ||
| }) | ||
| export class ToggleSwitchComponent implements ControlValueAccessor { | ||
| @Input() invalid = false; | ||
| @Input() disabled = false; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. invalid и disabled должны считытваться через FormControl все через формы, не прокидывая пропсы
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| @Output() onChange = new EventEmitter<any>(); | ||
| @Output() onFocus = new EventEmitter<FocusEvent>(); | ||
| @Output() onBlur = new EventEmitter<FocusEvent>(); | ||
|
|
||
| modelValue = false; | ||
|
|
||
| private _onChange: (value: boolean) => void = () => {}; | ||
| private _onTouched: () => void = () => {}; | ||
|
|
||
| handleChange(value: boolean): void { | ||
| this.modelValue = value; | ||
| this._onChange(value); | ||
| this._onTouched(); | ||
| } | ||
|
|
||
| writeValue(value: boolean): void { | ||
| this.modelValue = value ?? false; | ||
| } | ||
|
|
||
| registerOnChange(fn: (value: boolean) => void): void { | ||
| this._onChange = fn; | ||
| } | ||
|
|
||
| registerOnTouched(fn: () => void): void { | ||
| this._onTouched = fn; | ||
| } | ||
|
|
||
| setDisabledState(isDisabled: boolean): void { | ||
| this.disabled = isDisabled; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,11 @@ | ||
| export const toggleswitchCss = ({ dt }: { dt: (token: string) => string }): string => ` | ||
| /* Focus ring для валидных состояний */ | ||
| .p-toggleswitch:not(.p-disabled):not(.p-invalid):has(.p-toggleswitch-input:focus-visible) .p-toggleswitch-slider { | ||
| box-shadow: 0 0 0 ${dt('toggleswitch.root.focusRing.width')} ${dt('focusRing.extend.success')}; | ||
| } | ||
|
|
||
| /* Focus ring для состояния ошибки */ | ||
| .p-toggleswitch.p-invalid:not(.p-disabled):has(.p-toggleswitch-input:focus-visible) .p-toggleswitch-slider { | ||
| box-shadow: 0 0 0 ${dt('focusRing.width')} ${dt('focusRing.extend.invalid')}; | ||
| } | ||
| `; |
49 changes: 49 additions & 0 deletions
49
src/stories/components/toggleswitch/examples/toggleswitch-checked.component.ts
This file contains hidden or 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,49 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { FormsModule } from '@angular/forms'; | ||
| import { StoryObj } from '@storybook/angular'; | ||
| import { ToggleSwitchComponent } from '../../../../lib/components/toggleswitch/toggleswitch.component'; | ||
|
|
||
| const template = ` | ||
| <toggleswitch [(ngModel)]="value"></toggleswitch> | ||
| `; | ||
|
|
||
| @Component({ | ||
| selector: 'app-toggleswitch-checked', | ||
| standalone: true, | ||
| imports: [ToggleSwitchComponent, FormsModule], | ||
| template, | ||
| }) | ||
| export class ToggleSwitchCheckedComponent { | ||
| value = true; | ||
| } | ||
|
|
||
| export const Checked: StoryObj = { | ||
| render: () => ({ | ||
| template: `<app-toggleswitch-checked></app-toggleswitch-checked>`, | ||
| }), | ||
| parameters: { | ||
| docs: { | ||
| description: { story: 'Переключатель во включённом состоянии.' }, | ||
| source: { | ||
| language: 'ts', | ||
| code: ` | ||
| import { Component } from '@angular/core'; | ||
| import { ToggleSwitchComponent } from '@cdek-it/angular-ui-kit'; | ||
| import { FormsModule } from '@angular/forms'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-toggleswitch-checked', | ||
| standalone: true, | ||
| imports: [ToggleSwitchComponent, FormsModule], | ||
| template: \` | ||
| <toggleswitch [(ngModel)]="value"></toggleswitch> | ||
| \`, | ||
| }) | ||
| export class ToggleSwitchCheckedComponent { | ||
| value = true; | ||
| } | ||
| `, | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
49 changes: 49 additions & 0 deletions
49
src/stories/components/toggleswitch/examples/toggleswitch-disabled.component.ts
This file contains hidden or 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,49 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { FormsModule } from '@angular/forms'; | ||
| import { StoryObj } from '@storybook/angular'; | ||
| import { ToggleSwitchComponent } from '../../../../lib/components/toggleswitch/toggleswitch.component'; | ||
|
|
||
| const template = ` | ||
| <toggleswitch [(ngModel)]="value" [disabled]="true"></toggleswitch> | ||
| `; | ||
|
|
||
| @Component({ | ||
| selector: 'app-toggleswitch-disabled', | ||
| standalone: true, | ||
| imports: [ToggleSwitchComponent, FormsModule], | ||
| template, | ||
| }) | ||
| export class ToggleSwitchDisabledComponent { | ||
| value = false; | ||
| } | ||
|
|
||
| export const Disabled: StoryObj = { | ||
| render: () => ({ | ||
| template: `<app-toggleswitch-disabled></app-toggleswitch-disabled>`, | ||
| }), | ||
| parameters: { | ||
| docs: { | ||
| description: { story: 'Заблокированное состояние переключателя.' }, | ||
| source: { | ||
| language: 'ts', | ||
| code: ` | ||
| import { Component } from '@angular/core'; | ||
| import { ToggleSwitchComponent } from '@cdek-it/angular-ui-kit'; | ||
| import { FormsModule } from '@angular/forms'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-toggleswitch-disabled', | ||
| standalone: true, | ||
| imports: [ToggleSwitchComponent, FormsModule], | ||
| template: \` | ||
| <toggleswitch [(ngModel)]="value" [disabled]="true"></toggleswitch> | ||
| \`, | ||
| }) | ||
| export class ToggleSwitchDisabledComponent { | ||
| value = false; | ||
| } | ||
| `, | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
49 changes: 49 additions & 0 deletions
49
src/stories/components/toggleswitch/examples/toggleswitch-invalid.component.ts
This file contains hidden or 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,49 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { FormsModule } from '@angular/forms'; | ||
| import { StoryObj } from '@storybook/angular'; | ||
| import { ToggleSwitchComponent } from '../../../../lib/components/toggleswitch/toggleswitch.component'; | ||
|
|
||
| const template = ` | ||
| <toggleswitch [(ngModel)]="value" [invalid]="true"></toggleswitch> | ||
| `; | ||
|
|
||
| @Component({ | ||
| selector: 'app-toggleswitch-invalid', | ||
| standalone: true, | ||
| imports: [ToggleSwitchComponent, FormsModule], | ||
| template, | ||
| }) | ||
| export class ToggleSwitchInvalidComponent { | ||
| value = false; | ||
| } | ||
|
|
||
| export const Invalid: StoryObj = { | ||
| render: () => ({ | ||
| template: `<app-toggleswitch-invalid></app-toggleswitch-invalid>`, | ||
| }), | ||
| parameters: { | ||
| docs: { | ||
| description: { story: 'Невалидное состояние переключателя.' }, | ||
| source: { | ||
| language: 'ts', | ||
| code: ` | ||
| import { Component } from '@angular/core'; | ||
| import { ToggleSwitchComponent } from '@cdek-it/angular-ui-kit'; | ||
| import { FormsModule } from '@angular/forms'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-toggleswitch-invalid', | ||
| standalone: true, | ||
| imports: [ToggleSwitchComponent, FormsModule], | ||
| template: \` | ||
| <toggleswitch [(ngModel)]="value" [invalid]="true"></toggleswitch> | ||
| \`, | ||
| }) | ||
| export class ToggleSwitchInvalidComponent { | ||
| value = false; | ||
| } | ||
| `, | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужны еще Form Validators, на случай если необходимы валидации формы
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ichiesov stories переведены на FormControl и Validators в 413a903