-
Notifications
You must be signed in to change notification settings - Fork 0
togglebutton: стилизация, сторисы, обёртка #49
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
7
commits into
feature/styles-debug
Choose a base branch
from
form.togglebutton
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
90afbed
togglebutton: стилизация, сторисы, обёртка
439b93c
фикс стилей текста для размеров lg, xlg
7434238
добавление пропсов в сторисы
fb8b7e6
modified .gitignore
f7ac940
togglebutton: change detection = OnPush
bf6a74f
Merge branch 'feature/styles-debug' into form.togglebutton
khaliulin 5e14a9a
стилизация размеров; formControl
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -58,4 +58,4 @@ src/assets/components/themes | |
|
|
||
| .claude/* | ||
|
|
||
| .playwright-mcp/* | ||
| .playwright-mcp/* | ||
134 changes: 134 additions & 0 deletions
134
docs/superpowers/specs/2026-04-16-togglebutton-design.md
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,134 @@ | ||
| # ToggleButton — Дизайн-документ | ||
|
|
||
| **Дата:** 2026-04-16 | ||
| **Ветка:** `form.togglebutton` | ||
|
|
||
| ## Цель | ||
|
|
||
| Добавить компонент `ToggleButton` в Angular UI Kit: обёртку над PrimeNG `p-togglebutton` с кастомной стилизацией и Storybook-историями по образцу [Vue-референса](https://github.com/cdek-it/vue-ui-kit/tree/togglebutton). | ||
|
|
||
| --- | ||
|
|
||
| ## Файлы | ||
|
|
||
| | Файл | Назначение | | ||
| |---|---| | ||
| | `src/lib/components/togglebutton/togglebutton.component.ts` | Компонент-обёртка | | ||
| | `src/prime-preset/tokens/components/togglebutton.ts` | CSS через `dt()` | | ||
| | `src/prime-preset/map-tokens.ts` | Подключение CSS (изменить) | | ||
| | `src/stories/components/togglebutton/togglebutton.stories.ts` | Default + ре-экспорты | | ||
| | `src/stories/components/togglebutton/examples/togglebutton-sizes.component.ts` | Сетка размеров | | ||
| | `src/stories/components/togglebutton/examples/togglebutton-icons.component.ts` | С иконками | | ||
| | `src/stories/components/togglebutton/examples/togglebutton-icon-only.component.ts` | Icon-only | | ||
| | `src/stories/components/togglebutton/examples/togglebutton-disabled.component.ts` | Disabled | | ||
|
|
||
| --- | ||
|
|
||
| ## Компонент | ||
|
|
||
| **Селектор:** `toggle-button` | ||
| **Паттерн:** `NG_VALUE_ACCESSOR` (аналог `CheckboxComponent`) | ||
|
|
||
| ### Типы | ||
|
|
||
| ```typescript | ||
| export type ToggleButtonSize = 'sm' | 'base' | 'lg' | 'xlg'; | ||
| ``` | ||
|
|
||
| ### Inputs | ||
|
|
||
| | Prop | Тип | Default | Описание | | ||
| |---|---|---|---| | ||
| | `onLabel` | `string` | `'Вкл'` | Текст в активном состоянии | | ||
| | `offLabel` | `string` | `'Выкл'` | Текст в неактивном состоянии | | ||
| | `onIcon` | `string \| undefined` | `undefined` | Иконка в активном состоянии | | ||
| | `offIcon` | `string \| undefined` | `undefined` | Иконка в неактивном состоянии | | ||
| | `iconPos` | `'left' \| 'right'` | `'left'` | Позиция иконки | | ||
| | `size` | `ToggleButtonSize` | `'base'` | Размер кнопки | | ||
| | `disabled` | `boolean` | `false` | Отключённое состояние | | ||
| | `iconOnly` | `boolean` | `false` | Скрывает label, делает кнопку квадратной | | ||
| | `allowEmpty` | `boolean \| undefined` | `undefined` | Разрешить снять выбор | | ||
| | `fluid` | `boolean` | `false` | Растянуть на всю ширину | | ||
| | `ariaLabel` | `string \| undefined` | `undefined` | Aria-label | | ||
| | `ariaLabelledBy` | `string \| undefined` | `undefined` | Aria-labelledby | | ||
| | `inputId` | `string \| undefined` | `undefined` | ID input-элемента | | ||
| | `tabindex` | `number \| undefined` | `undefined` | Tab index | | ||
| | `autofocus` | `boolean \| undefined` | `undefined` | Автофокус | | ||
|
|
||
| ### Outputs | ||
|
|
||
| | Event | Тип | Описание | | ||
| |---|---|---| | ||
| | `onChange` | `EventEmitter<ToggleButtonChangeEvent>` | Изменение значения | | ||
|
|
||
| ### Маппинг размеров в PrimeNG | ||
|
|
||
| | Наш `size` | PrimeNG `size` | Дополнительный класс | | ||
| |---|---|---| | ||
| | `'sm'` | `'small'` | — | | ||
| | `'base'` | `undefined` | — | | ||
| | `'lg'` | `'large'` | — | | ||
| | `'xlg'` | `'large'` | `p-togglebutton-xlg` | | ||
|
|
||
| - `iconOnly=true` → добавляет класс `p-togglebutton-icon-only` через `[ngClass]` | ||
| - Все дополнительные классы применяются через `[ngClass]` на `<p-togglebutton>` | ||
|
|
||
| --- | ||
|
|
||
| ## CSS-стилизация (`togglebutton.ts`) | ||
|
|
||
| Переносим Vue-референс (`togglebutton.ts`) с адаптацией синтаксиса на Angular: | ||
|
|
||
| 1. **Типографика:** `fonts.fontFamily.heading`, `fonts.fontWeight.demibold`, `fonts.lineHeight.50` | ||
| 2. **Hover unchecked:** `togglebutton.extend.hoverBorderColor` | ||
| 3. **Hover checked:** `togglebutton.extend.checkedHoverBackground/BorderColor/Color` | ||
| 4. **Размер sm:** `line-height.30`, icon `iconSize.sm` | ||
| 5. **Размер base:** icon `iconSize.md` | ||
| 6. **Размер lg:** `line-height.55`, gap, icon `iconSize.lg` | ||
| 7. **Размер xlg:** кастомный padding, font-size, align-items, icon `iconSize.lg` | ||
| 8. **Icon-only base:** `iconOnlyWidth` px width/height, `border-radius`, скрытый label | ||
| 9. **Icon-only sm/lg/xlg:** отдельные `iconOnlyWidth` из `extSm`/`extLg`/`extXlg` | ||
|
|
||
| Все токены уже присутствуют в `tokens.json` → доработки JSON не требуются. | ||
|
|
||
| --- | ||
|
|
||
| ## Stories | ||
|
|
||
| ### Default | ||
|
|
||
| Динамический template из `args`. Controls: | ||
|
|
||
| | Control | Тип | | ||
| |---|---| | ||
| | `size` | select: `'sm' \| 'base' \| 'lg' \| 'xlg'` | | ||
| | `onLabel` / `offLabel` | text | | ||
| | `onIcon` / `offIcon` | text | | ||
| | `iconPos` | select: `'left' \| 'right'` | | ||
| | `disabled` | boolean | | ||
| | `iconOnly` | boolean | | ||
| | `fluid` | boolean | | ||
|
|
||
| ### Sizes | ||
|
|
||
| CSS Grid (4 строки × 3 колонки). Строки = sm, base, lg, xlg. Колонки = unchecked, checked, disabled. Используются несколько `<toggle-button>` с `[(ngModel)]` и `[disabled]`. | ||
|
|
||
| ### Icons | ||
|
|
||
| Примеры: `onIcon`/`offIcon` с разными иконками, `iconPos="right"`. | ||
|
|
||
| ### IconOnly | ||
|
|
||
| Сетка из 4 размеров, icon-only, unchecked/checked. | ||
|
|
||
| ### Disabled | ||
|
|
||
| Отдельный компонент с `[disabled]="true"` и `[disabled]="true"` + `modelValue=true`. | ||
|
|
||
| --- | ||
|
|
||
| ## Ограничения | ||
|
|
||
| - `styleClass` на `p-togglebutton` задепрекейчен в PrimeNG v20 → используем `[ngClass]` | ||
| - Класс `p-togglebutton-xlg` не нативный PrimeNG — только наш кастомный CSS | ||
| - В stories нет `styles: [...]` — используем `const styles = ''` согласно CLAUDE.md |
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
100 changes: 100 additions & 0 deletions
100
src/lib/components/togglebutton/togglebutton.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,100 @@ | ||
| import { ChangeDetectionStrategy, Component, Input, Output, EventEmitter, forwardRef } from '@angular/core'; | ||
| import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms'; | ||
| import { NgClass } from '@angular/common'; | ||
| import { ToggleButton, ToggleButtonChangeEvent } from 'primeng/togglebutton'; | ||
|
|
||
| export type ToggleButtonSize = 'sm' | 'base' | 'lg' | 'xlg'; | ||
|
|
||
| @Component({ | ||
| selector: 'toggle-button', | ||
| standalone: true, | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| imports: [ToggleButton, NgClass, FormsModule], | ||
| providers: [ | ||
| { | ||
| provide: NG_VALUE_ACCESSOR, | ||
| useExisting: forwardRef(() => ToggleButtonComponent), | ||
| multi: true, | ||
| }, | ||
| ], | ||
| template: ` | ||
| <p-togglebutton | ||
| [ngClass]="extraClasses" | ||
| [onLabel]="onLabel" | ||
| [offLabel]="offLabel" | ||
| [onIcon]="onIcon" | ||
| [offIcon]="offIcon" | ||
| [iconPos]="iconPos" | ||
| [size]="primeSize!" | ||
| [disabled]="disabled" | ||
| [allowEmpty]="allowEmpty" | ||
| [fluid]="fluid" | ||
| [ariaLabel]="ariaLabel" | ||
| [ariaLabelledBy]="ariaLabelledBy" | ||
| [inputId]="inputId" | ||
| [tabindex]="tabindex" | ||
| [autofocus]="autofocus" | ||
| [(ngModel)]="modelValue" | ||
| (onChange)="onChangeHandler($event)" | ||
| ></p-togglebutton> | ||
| `, | ||
| }) | ||
| export class ToggleButtonComponent implements ControlValueAccessor { | ||
| @Input() onLabel = 'Вкл'; | ||
| @Input() offLabel = 'Выкл'; | ||
| @Input() onIcon: string | undefined = undefined; | ||
| @Input() offIcon: string | undefined = undefined; | ||
| @Input() iconPos: 'left' | 'right' = 'left'; | ||
| @Input() size: ToggleButtonSize = 'base'; | ||
| @Input() disabled = false; | ||
| @Input() iconOnly = false; | ||
| @Input() allowEmpty: boolean | undefined = undefined; | ||
| @Input() fluid = false; | ||
| @Input() ariaLabel: string | undefined = undefined; | ||
| @Input() ariaLabelledBy: string | undefined = undefined; | ||
| @Input() inputId: string | undefined = undefined; | ||
| @Input() tabindex: number | undefined = undefined; | ||
| @Input() autofocus: boolean | undefined = undefined; | ||
|
|
||
| @Output() onChange = new EventEmitter<ToggleButtonChangeEvent>(); | ||
|
|
||
| modelValue = false; | ||
|
|
||
| private _onChange: (value: any) => void = () => {}; | ||
| private _onTouched: () => void = () => {}; | ||
|
|
||
| get primeSize(): 'small' | 'large' | undefined { | ||
| if (this.size === 'sm') return 'small'; | ||
| if (this.size === 'lg' || this.size === 'xlg') return 'large'; | ||
| return undefined; | ||
| } | ||
|
|
||
| get extraClasses(): Record<string, boolean> { | ||
| return { | ||
| 'p-togglebutton-xlg': this.size === 'xlg', | ||
| 'p-togglebutton-icon-only': this.iconOnly, | ||
| }; | ||
| } | ||
|
|
||
| onChangeHandler(event: ToggleButtonChangeEvent): void { | ||
| this._onChange(event.checked); | ||
| this._onTouched(); | ||
| this.onChange.emit(event); | ||
| } | ||
|
|
||
| writeValue(value: any): void { | ||
| this.modelValue = value; | ||
| } | ||
|
|
||
| registerOnChange(fn: (value: any) => 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,95 @@ | ||
| export const togglebuttonCss = ({ dt }: { dt: (token: string) => string }): string => ` | ||
|
|
||
| /* ─── Типографика ─── */ | ||
| .p-togglebutton.p-component { | ||
| font-family: ${dt('fonts.fontFamily.heading')}; | ||
| font-weight: ${dt('fonts.fontWeight.demibold')}; | ||
| line-height: ${dt('fonts.lineHeight.500')}; | ||
| } | ||
|
|
||
| /* ─── Hover unchecked ─── */ | ||
| .p-togglebutton:not(:disabled):not(.p-togglebutton-checked):hover { | ||
| border-color: ${dt('togglebutton.extend.hoverBorderColor')}; | ||
| } | ||
|
|
||
| /* ─── Hover checked ─── */ | ||
| .p-togglebutton.p-togglebutton-checked:hover { | ||
| background: ${dt('togglebutton.extend.checkedHoverBackground')}; | ||
| border-color: ${dt('togglebutton.extend.checkedHoverBorderColor')}; | ||
| color: ${dt('togglebutton.extend.checkedHoverColor')}; | ||
| } | ||
|
|
||
| /* ─── Small ─── */ | ||
| .p-togglebutton.p-togglebutton.p-component.p-togglebutton-sm { | ||
| line-height: ${dt('fonts.lineHeight.300')}; | ||
| } | ||
| .p-togglebutton.p-togglebutton.p-component.p-togglebutton-sm .p-togglebutton-label { | ||
| line-height: ${dt('fonts.lineHeight.250')}; | ||
| } | ||
| .p-togglebutton.p-togglebutton.p-component.p-togglebutton-sm .p-togglebutton-icon { | ||
| font-size: ${dt('togglebutton.extend.iconSize.sm')}; | ||
| } | ||
|
|
||
| /* ─── Base (default) ─── */ | ||
| .p-togglebutton.p-component:not(.p-togglebutton-sm):not(.p-togglebutton-lg):not(.p-togglebutton-xlg) .p-togglebutton-icon { | ||
| font-size: ${dt('togglebutton.extend.iconSize.md')}; | ||
| } | ||
|
|
||
| /* ─── Large ─── */ | ||
| .p-togglebutton.p-togglebutton.p-component.p-togglebutton-lg { | ||
| line-height: ${dt('fonts.lineHeight.550')}; | ||
| gap: ${dt('togglebutton.root.gap')}; | ||
| } | ||
| .p-togglebutton.p-togglebutton.p-component.p-togglebutton-lg .p-togglebutton-content { | ||
| gap: ${dt('togglebutton.extend.ext.gap')}; | ||
| } | ||
| .p-togglebutton.p-togglebutton.p-component.p-togglebutton-lg .p-togglebutton-icon { | ||
| font-size: ${dt('togglebutton.extend.iconSize.lg')}; | ||
| } | ||
|
|
||
| /* ─── Extra Large ─── */ | ||
| .p-togglebutton.p-togglebutton.p-component.p-togglebutton-xlg { | ||
| padding: ${dt('togglebutton.extend.extXlg.padding')}; | ||
| font-size: ${dt('fonts.fontSize.500')}; | ||
| line-height: ${dt('fonts.lineHeight.550')}; | ||
| display: inline-flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| gap: ${dt('togglebutton.root.gap')}; | ||
| } | ||
| .p-togglebutton.p-togglebutton.p-component.p-togglebutton-xlg .p-togglebutton-content { | ||
| gap: ${dt('togglebutton.extend.ext.gap')}; | ||
| } | ||
| .p-togglebutton.p-togglebutton.p-component.p-togglebutton-xlg .p-togglebutton-icon { | ||
| font-size: ${dt('togglebutton.extend.iconSize.lg')}; | ||
| } | ||
|
|
||
| /* ─── Icon-only base ─── */ | ||
| .p-togglebutton.p-togglebutton-icon-only { | ||
| padding: 0; | ||
| width: ${dt('togglebutton.extend.iconOnlyWidth')}; | ||
| height: ${dt('togglebutton.extend.iconOnlyWidth')}; | ||
| border-radius: ${dt('togglebutton.root.borderRadius')}; | ||
| } | ||
| .p-togglebutton.p-togglebutton-icon-only .p-togglebutton-label { | ||
| display: none; | ||
| } | ||
|
|
||
| /* ─── Icon-only sm ─── */ | ||
| .p-togglebutton.p-togglebutton-sm.p-togglebutton-icon-only { | ||
| width: ${dt('togglebutton.extend.extSm.iconOnlyWidth')}; | ||
| height: ${dt('togglebutton.extend.extSm.iconOnlyWidth')}; | ||
| } | ||
|
|
||
| /* ─── Icon-only lg ─── */ | ||
| .p-togglebutton.p-togglebutton-lg.p-togglebutton-icon-only { | ||
| width: ${dt('togglebutton.extend.extLg.iconOnlyWidth')}; | ||
| height: ${dt('togglebutton.extend.extLg.iconOnlyWidth')}; | ||
| } | ||
|
|
||
| /* ─── Icon-only xlg ─── */ | ||
| .p-togglebutton.p-togglebutton-xlg.p-togglebutton-icon-only { | ||
| width: ${dt('togglebutton.extend.extXlg.iconOnlyWidth')}; | ||
| height: ${dt('togglebutton.extend.extXlg.iconOnlyWidth')}; | ||
| } | ||
| `; |
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
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.
change detection: OnPush
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.
Готово — f7ac940