From 22afbe6bae1e5dbcce44d1512acfa07ff8d6c1dc Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Fri, 17 Oct 2025 15:59:04 +0200 Subject: [PATCH 1/2] Renamed component names to lowercase --- .../Resources/public/ts/components/badge.ts | 85 +++++++++++++++++++ .../components/input_text/input_text_field.ts | 2 +- .../ts/components/{Label.ts => label.ts} | 0 .../public/ts/partials/base_field.ts | 2 +- 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/bundle/Resources/public/ts/components/badge.ts rename src/bundle/Resources/public/ts/components/{Label.ts => label.ts} (100%) diff --git a/src/bundle/Resources/public/ts/components/badge.ts b/src/bundle/Resources/public/ts/components/badge.ts new file mode 100644 index 00000000..655c9512 --- /dev/null +++ b/src/bundle/Resources/public/ts/components/badge.ts @@ -0,0 +1,85 @@ +import { Base } from '../partials'; + +enum BadgeSize { + Medium = 'medium', + Small = 'small', +} + +const THRESHOLD = { + [BadgeSize.Medium]: 100, + [BadgeSize.Small]: 10, +}; + +export default class Badge extends Base { + private _value = 0; + private _maxBadgeValue: number; + + constructor(container: HTMLDivElement) { + super(container); + + const _maxBadgeValue = this._container.dataset.idsMaxBadgeValue ?? ''; + const parsedMax = parseInt(_maxBadgeValue, 10); + + if (!_maxBadgeValue || isNaN(parsedMax)) { + throw new Error('There is no proper max badge value defined for this badge!'); + } + + this._maxBadgeValue = parsedMax; + + const initialValue = this._parseValue(this._container.textContent); + + if (initialValue === null) { + throw new Error('No value found for this badge!'); + } + + this.setValue(initialValue); + } + + private _parseValue(badgeContent: string | null): number | null { + if (badgeContent === null || badgeContent.trim() === '') { + return null; + } + + const numericValue = parseInt(badgeContent, 10); + + return isNaN(numericValue) ? null : numericValue; + } + + setValue(value: number): void { + this._value = value; + } + + renderContent(): void { + const content = this.getValueRestrictedByMaxValue(); + const size = this.getSize(); + + this._container.textContent = content; + this._container.classList.toggle('ids-badge--stretched', this._value >= THRESHOLD[size]); + } + + getValueRestrictedByMaxValue(): string { + return this._value > this._maxBadgeValue ? `${this._maxBadgeValue.toString()}+` : this._value.toString(); + } + + getValue(): number | null { + return this._value; + } + + getSize(): BadgeSize { + return this._container.classList.contains('.ids-badge--small') ? BadgeSize.Small : BadgeSize.Medium; + } + + setMaxValue(max: number): void { + this._maxBadgeValue = max; + + const currentValue = this.getValue(); + + if (currentValue !== null && currentValue > this._maxBadgeValue) { + this.setValue(currentValue); + } + } + + getMaxValue(): number { + return this._maxBadgeValue; + } +} diff --git a/src/bundle/Resources/public/ts/components/input_text/input_text_field.ts b/src/bundle/Resources/public/ts/components/input_text/input_text_field.ts index c0da1e86..1bb21082 100644 --- a/src/bundle/Resources/public/ts/components/input_text/input_text_field.ts +++ b/src/bundle/Resources/public/ts/components/input_text/input_text_field.ts @@ -1,7 +1,7 @@ import { Base } from '../../partials'; import { HelperText } from '../helper_text'; import { InputTextInput } from './input_text_input'; -import { Label } from '../Label'; +import { Label } from '../label'; import IsEmptyStringValidator from '@ids-core/validators/IsEmptyStringValidator'; import type { TranslatorType } from '@ids-core/types/translator'; diff --git a/src/bundle/Resources/public/ts/components/Label.ts b/src/bundle/Resources/public/ts/components/label.ts similarity index 100% rename from src/bundle/Resources/public/ts/components/Label.ts rename to src/bundle/Resources/public/ts/components/label.ts diff --git a/src/bundle/Resources/public/ts/partials/base_field.ts b/src/bundle/Resources/public/ts/partials/base_field.ts index 3543d33d..92459213 100644 --- a/src/bundle/Resources/public/ts/partials/base_field.ts +++ b/src/bundle/Resources/public/ts/partials/base_field.ts @@ -1,8 +1,8 @@ import { Base } from './base'; import { HelperText } from '../components/helper_text'; -import { Label } from '../components/Label'; import ValidatorManager from '../validators/ValidatorManager'; +import { Label } from '../components/label'; export abstract class BaseField extends Base { protected _labelInstance: Label | null = null; From 0a5f9a8032213afc3cc35a5c88bb732b144a3f21 Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Fri, 17 Oct 2025 16:03:21 +0200 Subject: [PATCH 2/2] Frontend build fix --- .../Resources/public/ts/components/Badge.ts | 85 ------------------- .../public/ts/partials/base_field.ts | 2 +- 2 files changed, 1 insertion(+), 86 deletions(-) delete mode 100644 src/bundle/Resources/public/ts/components/Badge.ts diff --git a/src/bundle/Resources/public/ts/components/Badge.ts b/src/bundle/Resources/public/ts/components/Badge.ts deleted file mode 100644 index 655c9512..00000000 --- a/src/bundle/Resources/public/ts/components/Badge.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { Base } from '../partials'; - -enum BadgeSize { - Medium = 'medium', - Small = 'small', -} - -const THRESHOLD = { - [BadgeSize.Medium]: 100, - [BadgeSize.Small]: 10, -}; - -export default class Badge extends Base { - private _value = 0; - private _maxBadgeValue: number; - - constructor(container: HTMLDivElement) { - super(container); - - const _maxBadgeValue = this._container.dataset.idsMaxBadgeValue ?? ''; - const parsedMax = parseInt(_maxBadgeValue, 10); - - if (!_maxBadgeValue || isNaN(parsedMax)) { - throw new Error('There is no proper max badge value defined for this badge!'); - } - - this._maxBadgeValue = parsedMax; - - const initialValue = this._parseValue(this._container.textContent); - - if (initialValue === null) { - throw new Error('No value found for this badge!'); - } - - this.setValue(initialValue); - } - - private _parseValue(badgeContent: string | null): number | null { - if (badgeContent === null || badgeContent.trim() === '') { - return null; - } - - const numericValue = parseInt(badgeContent, 10); - - return isNaN(numericValue) ? null : numericValue; - } - - setValue(value: number): void { - this._value = value; - } - - renderContent(): void { - const content = this.getValueRestrictedByMaxValue(); - const size = this.getSize(); - - this._container.textContent = content; - this._container.classList.toggle('ids-badge--stretched', this._value >= THRESHOLD[size]); - } - - getValueRestrictedByMaxValue(): string { - return this._value > this._maxBadgeValue ? `${this._maxBadgeValue.toString()}+` : this._value.toString(); - } - - getValue(): number | null { - return this._value; - } - - getSize(): BadgeSize { - return this._container.classList.contains('.ids-badge--small') ? BadgeSize.Small : BadgeSize.Medium; - } - - setMaxValue(max: number): void { - this._maxBadgeValue = max; - - const currentValue = this.getValue(); - - if (currentValue !== null && currentValue > this._maxBadgeValue) { - this.setValue(currentValue); - } - } - - getMaxValue(): number { - return this._maxBadgeValue; - } -} diff --git a/src/bundle/Resources/public/ts/partials/base_field.ts b/src/bundle/Resources/public/ts/partials/base_field.ts index 92459213..cdbbef10 100644 --- a/src/bundle/Resources/public/ts/partials/base_field.ts +++ b/src/bundle/Resources/public/ts/partials/base_field.ts @@ -1,8 +1,8 @@ import { Base } from './base'; import { HelperText } from '../components/helper_text'; +import { Label } from '../components/label'; import ValidatorManager from '../validators/ValidatorManager'; -import { Label } from '../components/label'; export abstract class BaseField extends Base { protected _labelInstance: Label | null = null;