feat: Refactor TextArea component and styles for improved usability and consistency

- Updated textarea styles to utilize CSS variables for dimensions and padding.
- Enhanced placeholder styling and added disabled state styles.
- Refactored TextArea component to use forwardRef and updated status handling.
- Changed input statuses from 'normal' to 'default' for better clarity.
- Introduced global decimal separator management in CurrencyService.
- Updated tests to cover new decimal separator functionality.
- Cleaned up global CSS for better organization and readability.
- Removed deprecated rc-component dependencies in favor of @rc-component packages.
This commit is contained in:
Firman Ramdhani
2026-01-27 19:47:06 +07:00
parent 0deaff6e18
commit 1e1d46cbb5
18 changed files with 942 additions and 712 deletions
@@ -5,8 +5,9 @@ describe('CurrencyService', () => {
let currency: CurrencyService;
beforeEach(() => {
// Reset global prefix before each test
// Reset global prefix and decimal separator before each test
CurrencyService.setGlobalPrefix('Rp ');
CurrencyService.setGlobalDecimalSeparator(',');
// Mock console to keep tests clean
vi.spyOn(console, 'warn').mockImplementation(() => {});
@@ -38,6 +39,26 @@ describe('CurrencyService', () => {
});
});
describe('Global Decimal Separator', () => {
it('should set and get global decimal separator', () => {
CurrencyService.setGlobalDecimalSeparator('.');
expect(CurrencyService.getGlobalDecimalSeparator()).toBe('.');
});
it('should use global decimal separator if instance separator is not provided', () => {
CurrencyService.setGlobalDecimalSeparator('.');
const c = new CurrencyService();
expect(c.format(1234.56)).toBe('Rp 1,234.56');
expect(c.parse('Rp 1,234.56')).toBe('1234.56');
});
it('should override instance decimal separator', () => {
const c = new CurrencyService({ decimalSeparator: '.' });
expect(c.format(1234.56)).toBe('Rp 1,234.56');
expect(c.parse('Rp 1,234.56')).toBe('1234.56');
});
});
describe('Formatting', () => {
it('should format integer without decimalScale', () => {
expect(currency.format(1234567)).toBe('Rp 1.234.567');
@@ -74,12 +95,6 @@ describe('CurrencyService', () => {
expect(currency.parse('Rp 1.234,5678')).toBe('1234.5678');
});
it('should handle different decimal separators', () => {
const c = new CurrencyService({ decimalSeparator: '.' });
expect(c.format(1234.56)).toBe('Rp 1,234.56');
expect(c.parse('Rp 1,234.56')).toBe('1234.56');
});
it('should return empty string for null or undefined input', () => {
expect(currency.parse(null)).toBe('');
expect(currency.parse(undefined)).toBe('');
@@ -38,11 +38,14 @@ export class CurrencyService {
* ---------------------------------------------------------------- */
private static _globalPrefix: string = 'Rp ';
/** Global default decimal separator shared across all instances */
private static _globalDecimalSeparator: ',' | '.' = ',';
/** Instance prefix, defaults to global prefix */
private readonly prefix: string;
/** Character used as decimal separator for display */
private readonly decimalSeparator: string;
private readonly decimalSeparator: ',' | '.';
/** Optional number of decimal digits for display rounding */
private readonly decimalScale?: number;
@@ -58,7 +61,7 @@ export class CurrencyService {
*/
constructor(options?: CurrencyOptions) {
this.prefix = options?.prefix ?? CurrencyService._globalPrefix;
this.decimalSeparator = options?.decimalSeparator ?? ',';
this.decimalSeparator = options?.decimalSeparator ?? CurrencyService._globalDecimalSeparator;
this.decimalScale = options?.decimalScale;
this.thousandSeparator = this.decimalSeparator === ',' ? '.' : ',';
}
@@ -86,6 +89,18 @@ export class CurrencyService {
return CurrencyService._globalPrefix;
}
/** ------------------------------------------------------------
* Global decimal separator management
* ------------------------------------------------------------ */
static setGlobalDecimalSeparator(separator: ',' | '.') {
CurrencyService._globalDecimalSeparator = separator;
}
static getGlobalDecimalSeparator(): ',' | '.' {
return CurrencyService._globalDecimalSeparator;
}
/** ------------------------------------------------------------
* Formatter (DISPLAY ONLY)
* ------------------------------------------------------------ */