@cranberry-money/shared-utils 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/badge.d.ts +68 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +71 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +5 -2
package/dist/badge.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Badge System Core - Type definitions and factory function
|
|
3
|
+
*
|
|
4
|
+
* This module provides a standardized way to create and style badges.
|
|
5
|
+
* It ensures consistency in colors, typography, and semantic meaning
|
|
6
|
+
* while maintaining accessibility standards.
|
|
7
|
+
*
|
|
8
|
+
* Note: The actual style classes are designed to work with Tailwind CSS
|
|
9
|
+
* and assume a specific color system is in place.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Badge variant types representing different semantic states
|
|
13
|
+
*/
|
|
14
|
+
export type BadgeVariant = 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info' | 'neutral';
|
|
15
|
+
/**
|
|
16
|
+
* Badge size options
|
|
17
|
+
*/
|
|
18
|
+
export type BadgeSize = 'sm' | 'md' | 'lg';
|
|
19
|
+
/**
|
|
20
|
+
* Configuration options for creating a badge
|
|
21
|
+
*/
|
|
22
|
+
export interface BadgeConfig {
|
|
23
|
+
/** The semantic variant of the badge */
|
|
24
|
+
variant: BadgeVariant;
|
|
25
|
+
/** Size of the badge (default: 'md') */
|
|
26
|
+
size?: BadgeSize;
|
|
27
|
+
/** Additional CSS classes to apply */
|
|
28
|
+
className?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Badge style output with generated classes and accessibility attributes
|
|
32
|
+
*/
|
|
33
|
+
export interface BadgeStyle {
|
|
34
|
+
/** Combined CSS classes for the badge */
|
|
35
|
+
className: string;
|
|
36
|
+
/** Accessibility label for screen readers */
|
|
37
|
+
ariaLabel?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a badge style configuration with appropriate CSS classes
|
|
41
|
+
*
|
|
42
|
+
* @param config - Badge configuration options
|
|
43
|
+
* @param variantStyles - Optional custom variant styles (defaults to DEFAULT_BADGE_VARIANTS)
|
|
44
|
+
* @param sizeStyles - Optional custom size styles (defaults to DEFAULT_BADGE_SIZES)
|
|
45
|
+
* @returns Badge style object with className and accessibility attributes
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Create a success badge
|
|
50
|
+
* const successBadge = createBadge({ variant: 'success' });
|
|
51
|
+
* // Returns: { className: 'inline-flex items-center rounded-md font-medium whitespace-nowrap transition-colors bg-success-900/80 text-success-300 text-xs px-2 py-1', ariaLabel: 'success status' }
|
|
52
|
+
*
|
|
53
|
+
* // Create a large warning badge with custom class
|
|
54
|
+
* const warningBadge = createBadge({ variant: 'warning', size: 'lg', className: 'ml-2' });
|
|
55
|
+
*
|
|
56
|
+
* // Use custom variant styles
|
|
57
|
+
* const customVariants = { primary: 'bg-blue-500 text-white', ... };
|
|
58
|
+
* const customBadge = createBadge({ variant: 'primary' }, customVariants);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function createBadge({ variant, size, className }: BadgeConfig, variantStyles?: Record<BadgeVariant, string>, sizeStyles?: Record<BadgeSize, string>): BadgeStyle;
|
|
62
|
+
/**
|
|
63
|
+
* Export the default style mappings for consumers who want to use them directly
|
|
64
|
+
* or extend them with their own styles
|
|
65
|
+
*/
|
|
66
|
+
export declare const BADGE_VARIANTS: Record<BadgeVariant, string>;
|
|
67
|
+
export declare const BADGE_SIZES: Record<BadgeSize, string>;
|
|
68
|
+
//# sourceMappingURL=badge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badge.d.ts","sourceRoot":"","sources":["../src/badge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1G;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,OAAO,EAAE,YAAY,CAAC;IACtB,wCAAwC;IACxC,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA8BD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CACzB,EAAE,OAAO,EAAE,IAAW,EAAE,SAAc,EAAE,EAAE,WAAW,EACrD,aAAa,GAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAA0B,EACpE,UAAU,GAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAuB,GAC1D,UAAU,CAQZ;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,8BAAyB,CAAC;AACrD,eAAO,MAAM,WAAW,2BAAsB,CAAC"}
|
package/dist/badge.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Badge System Core - Type definitions and factory function
|
|
3
|
+
*
|
|
4
|
+
* This module provides a standardized way to create and style badges.
|
|
5
|
+
* It ensures consistency in colors, typography, and semantic meaning
|
|
6
|
+
* while maintaining accessibility standards.
|
|
7
|
+
*
|
|
8
|
+
* Note: The actual style classes are designed to work with Tailwind CSS
|
|
9
|
+
* and assume a specific color system is in place.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Default variant styles using Tailwind CSS classes
|
|
13
|
+
* These assume a specific color system with surface and semantic colors
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_BADGE_VARIANTS = {
|
|
16
|
+
primary: 'bg-surface-tertiary text-content-secondary',
|
|
17
|
+
secondary: 'bg-surface-secondary text-content-body',
|
|
18
|
+
success: 'bg-success-900/80 text-success-300',
|
|
19
|
+
warning: 'bg-warning-900/80 text-warning-300',
|
|
20
|
+
error: 'bg-error-900/80 text-error-300',
|
|
21
|
+
info: 'bg-surface-tertiary text-content-body',
|
|
22
|
+
neutral: 'bg-surface-secondary text-content-muted',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Default size styles for badges
|
|
26
|
+
*/
|
|
27
|
+
const DEFAULT_BADGE_SIZES = {
|
|
28
|
+
sm: 'text-xs px-1.5 py-0.5',
|
|
29
|
+
md: 'text-xs px-2 py-1',
|
|
30
|
+
lg: 'text-sm px-3 py-1.5',
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Base badge styles that apply to all badges
|
|
34
|
+
*/
|
|
35
|
+
const BASE_BADGE_STYLES = 'inline-flex items-center rounded-md font-medium whitespace-nowrap transition-colors';
|
|
36
|
+
/**
|
|
37
|
+
* Creates a badge style configuration with appropriate CSS classes
|
|
38
|
+
*
|
|
39
|
+
* @param config - Badge configuration options
|
|
40
|
+
* @param variantStyles - Optional custom variant styles (defaults to DEFAULT_BADGE_VARIANTS)
|
|
41
|
+
* @param sizeStyles - Optional custom size styles (defaults to DEFAULT_BADGE_SIZES)
|
|
42
|
+
* @returns Badge style object with className and accessibility attributes
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Create a success badge
|
|
47
|
+
* const successBadge = createBadge({ variant: 'success' });
|
|
48
|
+
* // Returns: { className: 'inline-flex items-center rounded-md font-medium whitespace-nowrap transition-colors bg-success-900/80 text-success-300 text-xs px-2 py-1', ariaLabel: 'success status' }
|
|
49
|
+
*
|
|
50
|
+
* // Create a large warning badge with custom class
|
|
51
|
+
* const warningBadge = createBadge({ variant: 'warning', size: 'lg', className: 'ml-2' });
|
|
52
|
+
*
|
|
53
|
+
* // Use custom variant styles
|
|
54
|
+
* const customVariants = { primary: 'bg-blue-500 text-white', ... };
|
|
55
|
+
* const customBadge = createBadge({ variant: 'primary' }, customVariants);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function createBadge({ variant, size = 'md', className = '' }, variantStyles = DEFAULT_BADGE_VARIANTS, sizeStyles = DEFAULT_BADGE_SIZES) {
|
|
59
|
+
const variantClasses = variantStyles[variant] || variantStyles.neutral;
|
|
60
|
+
const sizeClasses = sizeStyles[size];
|
|
61
|
+
return {
|
|
62
|
+
className: `${BASE_BADGE_STYLES} ${variantClasses} ${sizeClasses} ${className}`.trim(),
|
|
63
|
+
ariaLabel: `${variant} status`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Export the default style mappings for consumers who want to use them directly
|
|
68
|
+
* or extend them with their own styles
|
|
69
|
+
*/
|
|
70
|
+
export const BADGE_VARIANTS = DEFAULT_BADGE_VARIANTS;
|
|
71
|
+
export const BADGE_SIZES = DEFAULT_BADGE_SIZES;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,6 @@
|
|
|
7
7
|
export { truncateText } from './text';
|
|
8
8
|
export { formatDate, formatShortDate, formatTime, formatDateTime } from './date';
|
|
9
9
|
export { NUMBER_FORMAT_OPTIONS_CURRENCY, NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED, formatCurrency, parseCurrencyInput, formatCurrencyWithCode, formatDefaultCurrency, formatShares, } from './currency';
|
|
10
|
+
export type { BadgeVariant, BadgeSize, BadgeConfig, BadgeStyle } from './badge';
|
|
11
|
+
export { createBadge, BADGE_VARIANTS, BADGE_SIZES } from './badge';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGjF,OAAO,EACL,8BAA8B,EAC9B,qCAAqC,EACrC,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,GACb,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGjF,OAAO,EACL,8BAA8B,EAC9B,qCAAqC,EACrC,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,3 +10,4 @@ export { truncateText } from './text';
|
|
|
10
10
|
export { formatDate, formatShortDate, formatTime, formatDateTime } from './date';
|
|
11
11
|
// Currency formatting utilities
|
|
12
12
|
export { NUMBER_FORMAT_OPTIONS_CURRENCY, NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED, formatCurrency, parseCurrencyInput, formatCurrencyWithCode, formatDefaultCurrency, formatShares, } from './currency';
|
|
13
|
+
export { createBadge, BADGE_VARIANTS, BADGE_SIZES } from './badge';
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cranberry-money/shared-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Shared utility functions for MyPortfolio platform",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"exports": {
|
|
@@ -18,7 +19,9 @@
|
|
|
18
19
|
"build": "tsc",
|
|
19
20
|
"clean": "rm -rf dist",
|
|
20
21
|
"typecheck": "tsc --noEmit",
|
|
21
|
-
"dev": "tsc --watch"
|
|
22
|
+
"dev": "tsc --watch",
|
|
23
|
+
"lint": "eslint src",
|
|
24
|
+
"lint:fix": "eslint src --fix"
|
|
22
25
|
},
|
|
23
26
|
"dependencies": {
|
|
24
27
|
"@cranberry-money/shared-constants": "^4.0.0",
|