Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
de70553
inputnumber: стилизация, сторисы, обёртка
Apr 16, 2026
3cdc5ea
фикс размера кнопок
Apr 17, 2026
f1f83f9
фикс границ для сторис Buttons
Apr 17, 2026
4706a04
textarea: стилизация
Apr 20, 2026
0f358a7
фикс размеров; добавлена сторис float label
Apr 20, 2026
b3be4c7
удалён пропс variant из TextareaComponent
Apr 21, 2026
eac3d77
добавлен showClear + NgControl для invalid в TextareaComponent
Apr 21, 2026
91907ea
stories Textarea переведены на FormControl + NgControl в компоненте
Apr 21, 2026
4a810b4
textarea: box-shadow при фокусе, исправлен disabled/readonly CSS, inv…
Apr 21, 2026
4664087
padding-right когда активен showClear
Apr 21, 2026
c9c90f4
доабвлены пропсы для FloatLabel
Apr 21, 2026
48ba27a
inputnumber: box-shadow при фокусе, invalid border при focus, NgControl
Apr 21, 2026
4b749f6
inputnumber stories Buttons/Disabled/FloatLabel: formControl, source.…
Apr 21, 2026
bdbe29a
inputnumber story Currency: mode=currency → suffix=' ₽' (баг PrimeNG …
Apr 21, 2026
397206c
inputnumber stories: minFractionDigits/maxFractionDigits в argTypes, …
Apr 21, 2026
d59162d
обновлён .gitignore
Apr 21, 2026
c883830
Merge branch 'feature/styles-debug' into form.inputnumber
Apr 21, 2026
ac38181
Merge pull request #57 from cdek-it/form.TextArea
Tenkoru Apr 21, 2026
2c252c7
Merge branch 'form.inputtext' into form.inputnumber
khaliulin Apr 22, 2026
e15fa7d
inputnumber: регистрация inputnumberCss в map-tokens.ts
Apr 23, 2026
848ba9c
inputnumber: убран левый бордер у increment-button
Apr 23, 2026
12bfd62
inputnumber: z-index для input при фокусе чтобы box-shadow не обрезался
Apr 23, 2026
7f6a591
inputnumber: z-index для floatlabel label чтобы не перекрывался input…
Apr 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
808 changes: 808 additions & 0 deletions docs/superpowers/plans/2026-04-16-inputnumber.md

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions docs/superpowers/specs/2026-04-16-inputnumber-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# InputNumber Component — Design Spec

**Date:** 2026-04-16
**Branch:** `form.inputnumber` (to be created)
**Reference:** [Vue InputNumber](https://github.com/cdek-it/vue-ui-kit/tree/form.InputNumber/src/plugins/prime/stories/Form/InputNumber)

---

## Overview

Angular wrapper component for PrimeNG `InputNumber`, following the same patterns as `InputTextComponent`. Provides a styled numeric input with optional increment/decrement buttons, currency formatting, and min/max/step constraints. Integrates with Angular Forms via `ControlValueAccessor`.

---

## File Structure

```
src/lib/components/inputnumber/
inputnumber.component.ts

src/prime-preset/tokens/components/
inputnumber.ts ← new CSS override file

src/prime-preset/
map-tokens.ts ← add inputnumber CSS

src/stories/components/inputnumber/
inputnumber.stories.ts
examples/
inputnumber-float-label.component.ts
inputnumber-currency.component.ts
inputnumber-minmax.component.ts
```

---

## Component API (`InputNumberComponent`)

**Selector:** `input-number`
**Standalone:** yes
**CVA value type:** `number | null`

### Inputs

| Prop | Type | Default | Description |
|---|---|---|---|
| `size` | `'small' \| 'base' \| 'large' \| 'xlarge'` | `'base'` | Размер поля |
| `placeholder` | `string` | `''` | Подсказка при пустом поле |
| `disabled` | `boolean` | `false` | Отключает взаимодействие |
| `readonly` | `boolean` | `false` | Только для чтения |
| `invalid` | `boolean` | `false` | Невалидное состояние |
| `showButtons` | `boolean` | `true` | Показывать кнопки +/− |
| `buttonLayout` | `'horizontal' \| 'vertical' \| 'stacked'` | `'horizontal'` | Расположение кнопок |
| `mode` | `'decimal' \| 'currency'` | `'decimal'` | Режим отображения |
| `currency` | `string` | `'RUB'` | Код валюты (ISO 4217) при `mode="currency"` |
| `locale` | `string` | `'ru-RU'` | Локаль форматирования |
| `prefix` | `string \| undefined` | `undefined` | Префикс перед значением |
| `suffix` | `string \| undefined` | `undefined` | Суффикс после значения |
| `min` | `number \| undefined` | `undefined` | Минимальное значение |
| `max` | `number \| undefined` | `undefined` | Максимальное значение |
| `step` | `number` | `1` | Шаг изменения |
| `minFractionDigits` | `number` | `0` | Мин. знаков после запятой |
| `maxFractionDigits` | `number` | `20` | Макс. знаков после запятой |
| `fluid` | `boolean` | `false` | Растягивает на всю ширину |

### Size mapping

| `size` | `pSize` (PrimeNG) | CSS class |
|---|---|---|
| `'small'` | `'small'` | — |
| `'base'` | `undefined` | — |
| `'large'` | `'large'` | — |
| `'xlarge'` | `'large'` | `p-inputnumber-xlg` (on host) |

The `p-inputnumber-xlg` class is applied via `[ngClass]` on the `p-inputnumber` element so CSS cascade can target `.p-inputnumber-xlg .p-inputnumber-input`.

### Icons

Increment button: `<i class="ti ti-plus"></i>` via `#incrementicon` ng-template.
Decrement button: `<i class="ti ti-minus"></i>` via `#decrementicon` ng-template.

### CVA

- `writeValue(v: number | null)` — stores to `modelValue`
- `registerOnChange` / `registerOnTouched` — standard
- `setDisabledState` — sets `disabled`
- `onValueChange(v: number | null)` — called on PrimeNG `(onInput)` event, calls `_onChange`

---

## CSS Overrides (`src/prime-preset/tokens/components/inputnumber.ts`)

```typescript
export const inputnumberCss = ({ dt }) => `
.p-inputnumber-button {
border-width: ${dt('inputnumber.extend.borderWidth')};
}

.p-inputnumber-horizontal .p-inputnumber-button {
min-height: ${dt('inputnumber.extend.extButton.height')};
}

.p-inputnumber-horizontal:has(.p-inputnumber-input:disabled) .p-inputnumber-button {
background: ${dt('inputtext.root.disabledBackground')};
color: ${dt('inputtext.root.disabledColor')};
}

.p-inputnumber.p-inputnumber-xlg .p-inputnumber-input {
font-size: ${dt('inputtext.extend.extXlg.fontSize')};
padding: ${dt('inputtext.extend.extXlg.paddingY')} ${dt('inputtext.extend.extXlg.paddingX')};
}
`;
```

---

## map-tokens.ts

Add import and entry:

```typescript
import { inputnumberCss } from './tokens/components/inputnumber';

// in components:
inputnumber: {
...(tokens.components.inputnumber as unknown as ComponentsDesignTokens['inputnumber']),
css: inputnumberCss,
},
```

---

## Stories

### `inputnumber.stories.ts`

- `meta`: `title: 'Components/Form/InputNumber'`, `component: InputNumberComponent`, `tags: ['autodocs']`
- `argTypes`: all props from API table above
- `args`: defaults from API table
- `Default` story: dynamic template built from args (same pattern as InputText Default)
- Re-exports: `FloatLabel`, `Currency`, `MinMax`

### `examples/inputnumber-float-label.component.ts`

Uses native `p-inputnumber` (not the wrapper) as direct child of `p-floatlabel variant="in"`, because PrimeNG FloatLabel CSS relies on sibling selectors that don't work through wrapper components. Shows `showButtons`, `buttonLayout="horizontal"`, Tabler icon templates. `controls: { disable: true }`.

### `examples/inputnumber-currency.component.ts`

Pure `StoryObj` (no `@Component`), `render: (args) => ({ props: { ...args, value: null }, template })`. Args preset: `mode: 'currency'`, `currency: 'RUB'`, `locale: 'ru-RU'`. All other props bound through Controls.

### `examples/inputnumber-minmax.component.ts`

Pure `StoryObj`. Args preset: `min: 0`, `max: 100`, `step: 1`. Shows constraint behaviour.

---

## Constraints

- No `styles: [...]` in Angular `@Component` decorator — use `const styles = ''` (webpack base64 path bug)
- Storybook story layout: Tailwind classes only, no inline `style="..."`
- Float label: always use native `p-inputnumber` directly — never the wrapper component — inside `p-floatlabel`
- Default story must build template dynamically from args so the code snippet updates with Controls
- `source.code` in float-label example should not include the outer `<div class="pt-6">` wrapper
134 changes: 134 additions & 0 deletions src/lib/components/inputnumber/inputnumber.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { Component, Input, Output, EventEmitter, forwardRef, inject, Injector, OnInit } from '@angular/core';
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
import { NgClass } from '@angular/common';
import { InputNumber } from 'primeng/inputnumber';
import { SharedModule } from 'primeng/api';

export type InputNumberSize = 'small' | 'base' | 'large' | 'xlarge';
export type InputNumberButtonLayout = 'stacked' | 'horizontal' | 'vertical';

@Component({
selector: 'input-number',
standalone: true,
imports: [InputNumber, SharedModule, FormsModule, NgClass],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => InputNumberComponent),
multi: true,
},
],
template: `
<p-inputNumber
[ngClass]="sizeClass"
[inputStyleClass]="inputSizeClass"
[showButtons]="showButtons"
[buttonLayout]="buttonLayout"
[mode]="mode"
[currency]="currency"
[locale]="locale"
[placeholder]="placeholder"
[disabled]="disabled"
[invalid]="invalid"
[readonly]="readonly"
[fluid]="fluid"
[min]="min"
[max]="max"
[step]="step"
[prefix]="prefix"
[suffix]="suffix"
[minFractionDigits]="minFractionDigits"
[maxFractionDigits]="maxFractionDigits"
[useGrouping]="useGrouping"
[incrementButtonIcon]="incrementButtonIcon"
[decrementButtonIcon]="decrementButtonIcon"
[ngModel]="modelValue"
(ngModelChange)="onModelChange($event)"
(onBlur)="onTouched()"
>
@if (!incrementButtonIcon) {
<ng-template pTemplate="incrementbuttonicon">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14M5 12h14"/></svg>
</ng-template>
}
@if (!decrementButtonIcon) {
<ng-template pTemplate="decrementbuttonicon">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/></svg>
</ng-template>
}
</p-inputNumber>
`,
})
export class InputNumberComponent implements ControlValueAccessor, OnInit {
private readonly _injector = inject(Injector);
private _ngControl: NgControl | null = null;

ngOnInit(): void {
this._ngControl = this._injector.get(NgControl, null, { self: true, optional: true });
}

@Input() size: InputNumberSize = 'base';
@Input() showButtons = false;
@Input() buttonLayout: InputNumberButtonLayout = 'stacked';
@Input() mode = 'decimal';
@Input() currency: string | undefined;
@Input() locale: string | undefined;
@Input() placeholder = '';
@Input() readonly = false;
@Input() fluid = false;
@Input() min: number | undefined;
@Input() max: number | undefined;
@Input() step = 1;
@Input() prefix: string | undefined;
@Input() suffix: string | undefined;
@Input() minFractionDigits: number | undefined;
@Input() maxFractionDigits: number | undefined;
@Input() useGrouping = true;
@Input() incrementButtonIcon: string | undefined;
@Input() decrementButtonIcon: string | undefined;

disabled = false;

get invalid(): boolean {
return this._ngControl?.invalid ?? false;
}

@Output() onInput = new EventEmitter<{ value: number | null }>();

modelValue: number | null = null;

private _onChange: (value: number | null) => void = () => {};
onTouched: () => void = () => {};

get inputSizeClass(): string {
if (this.size === 'small') return 'p-inputtext-sm';
if (this.size === 'large' || this.size === 'xlarge') return 'p-inputtext-lg';
return '';
}

get sizeClass(): Record<string, boolean> {
return { 'p-inputnumber-xlg': this.size === 'xlarge' };
}

onModelChange(value: number | null): void {
this.modelValue = value;
this._onChange(value);
this.onInput.emit({ value });
}

writeValue(value: number | null): void {
this.modelValue = value ?? null;
}

registerOnChange(fn: (value: number | null) => void): void {
this._onChange = fn;
}

registerOnTouched(fn: () => void): void {
this.onTouched = fn;
}

setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
}
}
Loading
Loading