@cranberry-money/shared-utils 4.15.0 → 5.0.1
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/package.json +1 -1
- package/dist/auth.d.ts +0 -55
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -135
- package/dist/badge-status.d.ts +0 -87
- package/dist/badge-status.d.ts.map +0 -1
- package/dist/badge-status.js +0 -170
- package/dist/badge.d.ts +0 -68
- package/dist/badge.d.ts.map +0 -1
- package/dist/badge.js +0 -71
- package/dist/collections.d.ts +0 -81
- package/dist/collections.d.ts.map +0 -1
- package/dist/collections.js +0 -127
- package/dist/currency.d.ts +0 -99
- package/dist/currency.d.ts.map +0 -1
- package/dist/currency.js +0 -128
- package/dist/date.d.ts +0 -64
- package/dist/date.d.ts.map +0 -1
- package/dist/date.js +0 -91
- package/dist/downloads.d.ts +0 -46
- package/dist/downloads.d.ts.map +0 -1
- package/dist/downloads.js +0 -91
- package/dist/filters.d.ts +0 -121
- package/dist/filters.d.ts.map +0 -1
- package/dist/filters.js +0 -206
- package/dist/formatting.d.ts +0 -59
- package/dist/formatting.d.ts.map +0 -1
- package/dist/formatting.js +0 -81
- package/dist/index.d.ts +0 -28
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -34
- package/dist/instruments.d.ts +0 -118
- package/dist/instruments.d.ts.map +0 -1
- package/dist/instruments.js +0 -135
- package/dist/numbers.d.ts +0 -72
- package/dist/numbers.d.ts.map +0 -1
- package/dist/numbers.js +0 -101
- package/dist/portfolio.d.ts +0 -68
- package/dist/portfolio.d.ts.map +0 -1
- package/dist/portfolio.js +0 -87
- package/dist/text.d.ts +0 -22
- package/dist/text.d.ts.map +0 -1
- package/dist/text.js +0 -25
- package/dist/validation.d.ts +0 -249
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -337
- package/dist/withdrawal.d.ts +0 -97
- package/dist/withdrawal.d.ts.map +0 -1
- package/dist/withdrawal.js +0 -119
package/package.json
CHANGED
package/dist/auth.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authentication and token management utilities
|
|
3
|
-
*/
|
|
4
|
-
import type { DeviceInfo, TokenRefreshResponse, TokenRefreshError, AutoRefreshHandler } from '@cranberry-money/shared-types';
|
|
5
|
-
/**
|
|
6
|
-
* Check if a token has expired based on its expiration timestamp
|
|
7
|
-
* @param expiresAt - The expiration timestamp
|
|
8
|
-
* @returns true if token is expired, false otherwise
|
|
9
|
-
*/
|
|
10
|
-
export declare function isTokenExpired(expiresAt: string): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Check if a token will expire within a specified number of minutes
|
|
13
|
-
* @param expiresAt - The expiration timestamp
|
|
14
|
-
* @param minutesBeforeExpiry - Minutes before expiry to consider as "expiring soon"
|
|
15
|
-
* @returns true if token is expiring soon, false otherwise
|
|
16
|
-
*/
|
|
17
|
-
export declare function isTokenExpiringSoon(expiresAt: string, minutesBeforeExpiry?: number): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Get the remaining time until token expiry in minutes
|
|
20
|
-
* @param expiresAt - The expiration timestamp
|
|
21
|
-
* @returns Number of minutes until expiry
|
|
22
|
-
*/
|
|
23
|
-
export declare function getTimeUntilExpiry(expiresAt: string): number;
|
|
24
|
-
/**
|
|
25
|
-
* Format the time until expiry in a human-readable format
|
|
26
|
-
* @param expiresAt - The expiration timestamp
|
|
27
|
-
* @returns Formatted time string
|
|
28
|
-
*/
|
|
29
|
-
export declare function formatTimeUntilExpiry(expiresAt: string): string;
|
|
30
|
-
/**
|
|
31
|
-
* Parse device information from user agent string
|
|
32
|
-
* @param userAgent - The user agent string
|
|
33
|
-
* @returns Parsed device info
|
|
34
|
-
*/
|
|
35
|
-
export declare function parseDeviceInfo(userAgent: string): DeviceInfo;
|
|
36
|
-
/**
|
|
37
|
-
* Check if token refresh was successful
|
|
38
|
-
* @param response - The refresh response
|
|
39
|
-
* @returns true if refresh was successful, false otherwise
|
|
40
|
-
*/
|
|
41
|
-
export declare function isRefreshSuccess(response: TokenRefreshResponse): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Get error message from token refresh error
|
|
44
|
-
* @param error - The refresh error
|
|
45
|
-
* @returns Error message string
|
|
46
|
-
*/
|
|
47
|
-
export declare function getRefreshErrorMessage(error: TokenRefreshError): string;
|
|
48
|
-
/**
|
|
49
|
-
* Create an auto-refresh handler for tokens
|
|
50
|
-
* @param refreshCallback - Callback function to refresh token
|
|
51
|
-
* @param checkInterval - Interval in milliseconds to check for refresh
|
|
52
|
-
* @returns Auto refresh handler with start/stop methods
|
|
53
|
-
*/
|
|
54
|
-
export declare function createAutoRefreshHandler(refreshCallback: () => Promise<void>, checkInterval?: number): AutoRefreshHandler;
|
|
55
|
-
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAkB7H;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,mBAAmB,GAAE,MAA6C,GACjE,OAAO,CAMT;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAkB/D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAwB7D;AAGD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,OAAO,CAExE;AAGD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAWvE;AAGD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACpC,aAAa,GAAE,MAAc,GAC5B,kBAAkB,CAiBpB"}
|
package/dist/auth.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authentication and token management utilities
|
|
3
|
-
*/
|
|
4
|
-
import { DEFAULT_TOKEN_REFRESH_BUFFER_MINUTES, MILLISECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY, TIME_LABEL_EXPIRED, TIME_LABEL_MINUTE, TIME_LABEL_MINUTES, TIME_LABEL_HOUR, TIME_LABEL_HOURS, TIME_LABEL_DAY, TIME_LABEL_DAYS, DEFAULT_UNKNOWN_VALUE, DEFAULT_ERROR_MESSAGE, } from '@cranberry-money/shared-constants';
|
|
5
|
-
/**
|
|
6
|
-
* Check if a token has expired based on its expiration timestamp
|
|
7
|
-
* @param expiresAt - The expiration timestamp
|
|
8
|
-
* @returns true if token is expired, false otherwise
|
|
9
|
-
*/
|
|
10
|
-
export function isTokenExpired(expiresAt) {
|
|
11
|
-
const expirationTime = new Date(expiresAt).getTime();
|
|
12
|
-
const currentTime = Date.now();
|
|
13
|
-
return currentTime >= expirationTime;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Check if a token will expire within a specified number of minutes
|
|
17
|
-
* @param expiresAt - The expiration timestamp
|
|
18
|
-
* @param minutesBeforeExpiry - Minutes before expiry to consider as "expiring soon"
|
|
19
|
-
* @returns true if token is expiring soon, false otherwise
|
|
20
|
-
*/
|
|
21
|
-
export function isTokenExpiringSoon(expiresAt, minutesBeforeExpiry = DEFAULT_TOKEN_REFRESH_BUFFER_MINUTES) {
|
|
22
|
-
const expirationTime = new Date(expiresAt).getTime();
|
|
23
|
-
const currentTime = Date.now();
|
|
24
|
-
const bufferTime = minutesBeforeExpiry * MILLISECONDS_PER_MINUTE;
|
|
25
|
-
return currentTime + bufferTime >= expirationTime;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Get the remaining time until token expiry in minutes
|
|
29
|
-
* @param expiresAt - The expiration timestamp
|
|
30
|
-
* @returns Number of minutes until expiry
|
|
31
|
-
*/
|
|
32
|
-
export function getTimeUntilExpiry(expiresAt) {
|
|
33
|
-
const expirationTime = new Date(expiresAt).getTime();
|
|
34
|
-
const currentTime = Date.now();
|
|
35
|
-
const remainingTime = expirationTime - currentTime;
|
|
36
|
-
if (remainingTime <= 0) {
|
|
37
|
-
return 0;
|
|
38
|
-
}
|
|
39
|
-
return Math.floor(remainingTime / MILLISECONDS_PER_MINUTE);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Format the time until expiry in a human-readable format
|
|
43
|
-
* @param expiresAt - The expiration timestamp
|
|
44
|
-
* @returns Formatted time string
|
|
45
|
-
*/
|
|
46
|
-
export function formatTimeUntilExpiry(expiresAt) {
|
|
47
|
-
const minutesRemaining = getTimeUntilExpiry(expiresAt);
|
|
48
|
-
if (minutesRemaining <= 0) {
|
|
49
|
-
return TIME_LABEL_EXPIRED;
|
|
50
|
-
}
|
|
51
|
-
if (minutesRemaining < MINUTES_PER_HOUR) {
|
|
52
|
-
return minutesRemaining === 1 ? `1 ${TIME_LABEL_MINUTE}` : `${minutesRemaining} ${TIME_LABEL_MINUTES}`;
|
|
53
|
-
}
|
|
54
|
-
const hoursRemaining = Math.floor(minutesRemaining / MINUTES_PER_HOUR);
|
|
55
|
-
if (hoursRemaining < HOURS_PER_DAY) {
|
|
56
|
-
return hoursRemaining === 1 ? `1 ${TIME_LABEL_HOUR}` : `${hoursRemaining} ${TIME_LABEL_HOURS}`;
|
|
57
|
-
}
|
|
58
|
-
const daysRemaining = Math.floor(hoursRemaining / HOURS_PER_DAY);
|
|
59
|
-
return daysRemaining === 1 ? `1 ${TIME_LABEL_DAY}` : `${daysRemaining} ${TIME_LABEL_DAYS}`;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Parse device information from user agent string
|
|
63
|
-
* @param userAgent - The user agent string
|
|
64
|
-
* @returns Parsed device info
|
|
65
|
-
*/
|
|
66
|
-
export function parseDeviceInfo(userAgent) {
|
|
67
|
-
const browser = userAgent.includes('Chrome')
|
|
68
|
-
? 'Chrome'
|
|
69
|
-
: userAgent.includes('Firefox')
|
|
70
|
-
? 'Firefox'
|
|
71
|
-
: userAgent.includes('Safari')
|
|
72
|
-
? 'Safari'
|
|
73
|
-
: userAgent.includes('Edge')
|
|
74
|
-
? 'Edge'
|
|
75
|
-
: DEFAULT_UNKNOWN_VALUE;
|
|
76
|
-
const os = userAgent.includes('Windows')
|
|
77
|
-
? 'Windows'
|
|
78
|
-
: userAgent.includes('Mac')
|
|
79
|
-
? 'macOS'
|
|
80
|
-
: userAgent.includes('Linux')
|
|
81
|
-
? 'Linux'
|
|
82
|
-
: userAgent.includes('Android')
|
|
83
|
-
? 'Android'
|
|
84
|
-
: userAgent.includes('iOS')
|
|
85
|
-
? 'iOS'
|
|
86
|
-
: DEFAULT_UNKNOWN_VALUE;
|
|
87
|
-
return { browser, os };
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Check if token refresh was successful
|
|
91
|
-
* @param response - The refresh response
|
|
92
|
-
* @returns true if refresh was successful, false otherwise
|
|
93
|
-
*/
|
|
94
|
-
export function isRefreshSuccess(response) {
|
|
95
|
-
return !!(response?.status === 200 && response?.data?.access && response?.data?.refresh);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Get error message from token refresh error
|
|
99
|
-
* @param error - The refresh error
|
|
100
|
-
* @returns Error message string
|
|
101
|
-
*/
|
|
102
|
-
export function getRefreshErrorMessage(error) {
|
|
103
|
-
if (error.response?.data?.detail) {
|
|
104
|
-
return error.response.data.detail;
|
|
105
|
-
}
|
|
106
|
-
if (error.response?.data?.message) {
|
|
107
|
-
return error.response.data.message;
|
|
108
|
-
}
|
|
109
|
-
if (error.message) {
|
|
110
|
-
return error.message;
|
|
111
|
-
}
|
|
112
|
-
return DEFAULT_ERROR_MESSAGE;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Create an auto-refresh handler for tokens
|
|
116
|
-
* @param refreshCallback - Callback function to refresh token
|
|
117
|
-
* @param checkInterval - Interval in milliseconds to check for refresh
|
|
118
|
-
* @returns Auto refresh handler with start/stop methods
|
|
119
|
-
*/
|
|
120
|
-
export function createAutoRefreshHandler(refreshCallback, checkInterval = 60000 // 1 minute
|
|
121
|
-
) {
|
|
122
|
-
let intervalId = null;
|
|
123
|
-
const start = () => {
|
|
124
|
-
if (intervalId)
|
|
125
|
-
return;
|
|
126
|
-
intervalId = setInterval(refreshCallback, checkInterval);
|
|
127
|
-
};
|
|
128
|
-
const stop = () => {
|
|
129
|
-
if (intervalId) {
|
|
130
|
-
clearInterval(intervalId);
|
|
131
|
-
intervalId = null;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
return { start, stop };
|
|
135
|
-
}
|
package/dist/badge-status.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Badge Status Utilities - Status-specific badge functions
|
|
3
|
-
*
|
|
4
|
-
* This module provides pre-configured badge functions for common status types
|
|
5
|
-
* in the MyPortfolio platform. It builds on top of the core badge system.
|
|
6
|
-
*/
|
|
7
|
-
import { TRADE_STATUS_EXECUTED, TRADE_STATUS_SETTLED, TRADE_STATUS_CANCELLED, TRADE_STATUS_FAILED, TARGET_TRADE_STATUS_PENDING, TARGET_TRADE_STATUS_APPROVED, TARGET_TRADE_STATUS_SUBMITTED, TARGET_TRADE_STATUS_CANCELLED, TARGET_TRADE_STATUS_EXPIRED, WITHDRAWAL_STATUS_PENDING_REVIEW, WITHDRAWAL_STATUS_APPROVED, WITHDRAWAL_STATUS_REJECTED, WITHDRAWAL_STATUS_PROCESSING, WITHDRAWAL_STATUS_AWAITING_LIQUIDATION, WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS, WITHDRAWAL_STATUS_COMPLETED, WITHDRAWAL_STATUS_CANCELLED, WITHDRAWAL_STATUS_FAILED, LIQUIDATION_STATUS_PENDING, LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED, LIQUIDATION_STATUS_SETTLED, LIQUIDATION_STATUS_FAILED } from '@cranberry-money/shared-constants';
|
|
8
|
-
import type { BadgeSize, BadgeStyle } from './badge';
|
|
9
|
-
/**
|
|
10
|
-
* Extended badge style with display text for status badges
|
|
11
|
-
*/
|
|
12
|
-
export interface StatusBadgeStyle extends BadgeStyle {
|
|
13
|
-
displayText: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Trade status type encompassing regular and target trades
|
|
17
|
-
*/
|
|
18
|
-
export type TradeStatus = typeof TRADE_STATUS_EXECUTED | typeof TRADE_STATUS_SETTLED | typeof TRADE_STATUS_CANCELLED | typeof TRADE_STATUS_FAILED | typeof TARGET_TRADE_STATUS_PENDING | typeof TARGET_TRADE_STATUS_SUBMITTED | typeof TARGET_TRADE_STATUS_EXPIRED;
|
|
19
|
-
/**
|
|
20
|
-
* Withdrawal status type
|
|
21
|
-
*/
|
|
22
|
-
export type WithdrawalStatus = typeof WITHDRAWAL_STATUS_PENDING_REVIEW | typeof WITHDRAWAL_STATUS_APPROVED | typeof WITHDRAWAL_STATUS_REJECTED | typeof WITHDRAWAL_STATUS_PROCESSING | typeof WITHDRAWAL_STATUS_AWAITING_LIQUIDATION | typeof WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS | typeof WITHDRAWAL_STATUS_COMPLETED | typeof WITHDRAWAL_STATUS_CANCELLED | typeof WITHDRAWAL_STATUS_FAILED;
|
|
23
|
-
/**
|
|
24
|
-
* Liquidation status type
|
|
25
|
-
*/
|
|
26
|
-
export type LiquidationStatus = typeof LIQUIDATION_STATUS_PENDING | typeof LIQUIDATION_STATUS_TRADES_CREATED | typeof LIQUIDATION_STATUS_EXECUTED | typeof LIQUIDATION_STATUS_SETTLED | typeof LIQUIDATION_STATUS_FAILED;
|
|
27
|
-
/**
|
|
28
|
-
* Target trade status type
|
|
29
|
-
*/
|
|
30
|
-
export type TargetTradeStatus = typeof TARGET_TRADE_STATUS_PENDING | typeof TARGET_TRADE_STATUS_APPROVED | typeof TARGET_TRADE_STATUS_SUBMITTED | typeof TARGET_TRADE_STATUS_CANCELLED | typeof TARGET_TRADE_STATUS_EXPIRED;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a badge for trade status
|
|
33
|
-
*
|
|
34
|
-
* @param status - Trade status constant
|
|
35
|
-
* @param size - Badge size (default: 'md')
|
|
36
|
-
* @returns Badge style with display text and accessibility attributes
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const badge = getTradeStatusBadge(TRADE_STATUS_SETTLED);
|
|
41
|
-
* // Returns badge with success variant and "Settled" display text
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function getTradeStatusBadge(status: TradeStatus, size?: BadgeSize): StatusBadgeStyle;
|
|
45
|
-
/**
|
|
46
|
-
* Creates a badge for withdrawal status
|
|
47
|
-
*
|
|
48
|
-
* @param status - Withdrawal status constant
|
|
49
|
-
* @param size - Badge size (default: 'md')
|
|
50
|
-
* @returns Badge style with display text and accessibility attributes
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* const badge = getWithdrawalStatusBadge(WITHDRAWAL_STATUS_APPROVED);
|
|
55
|
-
* // Returns badge with success variant and "Approved" display text
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare function getWithdrawalStatusBadge(status: WithdrawalStatus, size?: BadgeSize): StatusBadgeStyle;
|
|
59
|
-
/**
|
|
60
|
-
* Creates a badge for liquidation status
|
|
61
|
-
*
|
|
62
|
-
* @param status - Liquidation status constant
|
|
63
|
-
* @param size - Badge size (default: 'md')
|
|
64
|
-
* @returns Badge style with display text and accessibility attributes
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* const badge = getLiquidationStatusBadge(LIQUIDATION_STATUS_SETTLED);
|
|
69
|
-
* // Returns badge with success variant and "Settled" display text
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export declare function getLiquidationStatusBadge(status: LiquidationStatus, size?: BadgeSize): StatusBadgeStyle;
|
|
73
|
-
/**
|
|
74
|
-
* Creates a badge for target trade status
|
|
75
|
-
*
|
|
76
|
-
* @param status - Target trade status constant
|
|
77
|
-
* @param size - Badge size (default: 'md')
|
|
78
|
-
* @returns Badge style with display text and accessibility attributes
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* const badge = getTargetTradeStatusBadge(TARGET_TRADE_STATUS_PENDING);
|
|
83
|
-
* // Returns badge with warning variant and "Pending" display text
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
export declare function getTargetTradeStatusBadge(status: TargetTradeStatus, size?: BadgeSize): StatusBadgeStyle;
|
|
87
|
-
//# sourceMappingURL=badge-status.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"badge-status.d.ts","sourceRoot":"","sources":["../src/badge-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EAKnB,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,EAC7B,6BAA6B,EAC7B,2BAA2B,EAM3B,gCAAgC,EAChC,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC5B,sCAAsC,EACtC,yCAAyC,EACzC,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EAUxB,0BAA0B,EAC1B,iCAAiC,EACjC,2BAA2B,EAC3B,0BAA0B,EAC1B,yBAAyB,EAM1B,MAAM,mCAAmC,CAAC;AAE3C,OAAO,KAAK,EAAgB,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGnE;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,OAAO,qBAAqB,GAC5B,OAAO,oBAAoB,GAC3B,OAAO,sBAAsB,GAC7B,OAAO,mBAAmB,GAC1B,OAAO,2BAA2B,GAClC,OAAO,6BAA6B,GACpC,OAAO,2BAA2B,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,OAAO,gCAAgC,GACvC,OAAO,0BAA0B,GACjC,OAAO,0BAA0B,GACjC,OAAO,4BAA4B,GACnC,OAAO,sCAAsC,GAC7C,OAAO,yCAAyC,GAChD,OAAO,2BAA2B,GAClC,OAAO,2BAA2B,GAClC,OAAO,wBAAwB,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,OAAO,0BAA0B,GACjC,OAAO,iCAAiC,GACxC,OAAO,2BAA2B,GAClC,OAAO,0BAA0B,GACjC,OAAO,yBAAyB,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,OAAO,2BAA2B,GAClC,OAAO,4BAA4B,GACnC,OAAO,6BAA6B,GACpC,OAAO,6BAA6B,GACpC,OAAO,2BAA2B,CAAC;AAgFvC;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,GAAE,SAAgB,GAAG,gBAAgB,CAUjG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,GAAE,SAAgB,GAAG,gBAAgB,CAU3G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,GAAE,SAAgB,GAAG,gBAAgB,CAU7G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,GAAE,SAAgB,GAAG,gBAAgB,CAU7G"}
|
package/dist/badge-status.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Badge Status Utilities - Status-specific badge functions
|
|
3
|
-
*
|
|
4
|
-
* This module provides pre-configured badge functions for common status types
|
|
5
|
-
* in the MyPortfolio platform. It builds on top of the core badge system.
|
|
6
|
-
*/
|
|
7
|
-
import { TRADE_STATUS_EXECUTED, TRADE_STATUS_SETTLED, TRADE_STATUS_CANCELLED, TRADE_STATUS_FAILED, TRADE_STATUS_LABEL_EXECUTED, TRADE_STATUS_LABEL_SETTLED, TRADE_STATUS_LABEL_CANCELLED, TRADE_STATUS_LABEL_FAILED, TARGET_TRADE_STATUS_PENDING, TARGET_TRADE_STATUS_APPROVED, TARGET_TRADE_STATUS_SUBMITTED, TARGET_TRADE_STATUS_CANCELLED, TARGET_TRADE_STATUS_EXPIRED, TARGET_TRADE_STATUS_LABEL_PENDING, TARGET_TRADE_STATUS_LABEL_APPROVED, TARGET_TRADE_STATUS_LABEL_SUBMITTED, TARGET_TRADE_STATUS_LABEL_CANCELLED, TARGET_TRADE_STATUS_LABEL_EXPIRED, WITHDRAWAL_STATUS_PENDING_REVIEW, WITHDRAWAL_STATUS_APPROVED, WITHDRAWAL_STATUS_REJECTED, WITHDRAWAL_STATUS_PROCESSING, WITHDRAWAL_STATUS_AWAITING_LIQUIDATION, WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS, WITHDRAWAL_STATUS_COMPLETED, WITHDRAWAL_STATUS_CANCELLED, WITHDRAWAL_STATUS_FAILED, WITHDRAWAL_STATUS_LABEL_PENDING_REVIEW, WITHDRAWAL_STATUS_LABEL_APPROVED, WITHDRAWAL_STATUS_LABEL_REJECTED, WITHDRAWAL_STATUS_LABEL_PROCESSING, WITHDRAWAL_STATUS_LABEL_AWAITING_LIQUIDATION, WITHDRAWAL_STATUS_LABEL_LIQUIDATION_IN_PROGRESS, WITHDRAWAL_STATUS_LABEL_COMPLETED, WITHDRAWAL_STATUS_LABEL_CANCELLED, WITHDRAWAL_STATUS_LABEL_FAILED, LIQUIDATION_STATUS_PENDING, LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED, LIQUIDATION_STATUS_SETTLED, LIQUIDATION_STATUS_FAILED, LIQUIDATION_STATUS_LABEL_PENDING, LIQUIDATION_STATUS_LABEL_TRADES_CREATED, LIQUIDATION_STATUS_LABEL_EXECUTED, LIQUIDATION_STATUS_LABEL_SETTLED, LIQUIDATION_STATUS_LABEL_FAILED, } from '@cranberry-money/shared-constants';
|
|
8
|
-
import { createBadge } from './badge';
|
|
9
|
-
// Status to variant mappings
|
|
10
|
-
const TRADE_STATUS_MAPPING = {
|
|
11
|
-
[TRADE_STATUS_EXECUTED]: 'primary',
|
|
12
|
-
[TRADE_STATUS_SETTLED]: 'success',
|
|
13
|
-
[TRADE_STATUS_CANCELLED]: 'error',
|
|
14
|
-
[TRADE_STATUS_FAILED]: 'error',
|
|
15
|
-
[TARGET_TRADE_STATUS_PENDING]: 'warning',
|
|
16
|
-
[TARGET_TRADE_STATUS_SUBMITTED]: 'primary',
|
|
17
|
-
[TARGET_TRADE_STATUS_EXPIRED]: 'neutral',
|
|
18
|
-
};
|
|
19
|
-
const WITHDRAWAL_STATUS_MAPPING = {
|
|
20
|
-
[WITHDRAWAL_STATUS_PENDING_REVIEW]: 'warning',
|
|
21
|
-
[WITHDRAWAL_STATUS_APPROVED]: 'success',
|
|
22
|
-
[WITHDRAWAL_STATUS_REJECTED]: 'error',
|
|
23
|
-
[WITHDRAWAL_STATUS_PROCESSING]: 'primary',
|
|
24
|
-
[WITHDRAWAL_STATUS_AWAITING_LIQUIDATION]: 'warning',
|
|
25
|
-
[WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS]: 'primary',
|
|
26
|
-
[WITHDRAWAL_STATUS_COMPLETED]: 'success',
|
|
27
|
-
[WITHDRAWAL_STATUS_CANCELLED]: 'neutral',
|
|
28
|
-
[WITHDRAWAL_STATUS_FAILED]: 'error',
|
|
29
|
-
};
|
|
30
|
-
const LIQUIDATION_STATUS_MAPPING = {
|
|
31
|
-
[LIQUIDATION_STATUS_PENDING]: 'warning',
|
|
32
|
-
[LIQUIDATION_STATUS_TRADES_CREATED]: 'primary',
|
|
33
|
-
[LIQUIDATION_STATUS_EXECUTED]: 'primary',
|
|
34
|
-
[LIQUIDATION_STATUS_SETTLED]: 'success',
|
|
35
|
-
[LIQUIDATION_STATUS_FAILED]: 'error',
|
|
36
|
-
};
|
|
37
|
-
const TARGET_TRADE_STATUS_MAPPING = {
|
|
38
|
-
[TARGET_TRADE_STATUS_PENDING]: 'warning',
|
|
39
|
-
[TARGET_TRADE_STATUS_APPROVED]: 'success',
|
|
40
|
-
[TARGET_TRADE_STATUS_SUBMITTED]: 'primary',
|
|
41
|
-
[TARGET_TRADE_STATUS_CANCELLED]: 'error',
|
|
42
|
-
[TARGET_TRADE_STATUS_EXPIRED]: 'neutral',
|
|
43
|
-
};
|
|
44
|
-
// Status to label mappings
|
|
45
|
-
const TRADE_STATUS_LABELS = {
|
|
46
|
-
[TRADE_STATUS_EXECUTED]: TRADE_STATUS_LABEL_EXECUTED,
|
|
47
|
-
[TRADE_STATUS_SETTLED]: TRADE_STATUS_LABEL_SETTLED,
|
|
48
|
-
[TRADE_STATUS_CANCELLED]: TRADE_STATUS_LABEL_CANCELLED,
|
|
49
|
-
[TRADE_STATUS_FAILED]: TRADE_STATUS_LABEL_FAILED,
|
|
50
|
-
[TARGET_TRADE_STATUS_PENDING]: TARGET_TRADE_STATUS_LABEL_PENDING,
|
|
51
|
-
[TARGET_TRADE_STATUS_SUBMITTED]: TARGET_TRADE_STATUS_LABEL_SUBMITTED,
|
|
52
|
-
[TARGET_TRADE_STATUS_EXPIRED]: TARGET_TRADE_STATUS_LABEL_EXPIRED,
|
|
53
|
-
};
|
|
54
|
-
const WITHDRAWAL_STATUS_LABELS = {
|
|
55
|
-
[WITHDRAWAL_STATUS_PENDING_REVIEW]: WITHDRAWAL_STATUS_LABEL_PENDING_REVIEW,
|
|
56
|
-
[WITHDRAWAL_STATUS_APPROVED]: WITHDRAWAL_STATUS_LABEL_APPROVED,
|
|
57
|
-
[WITHDRAWAL_STATUS_REJECTED]: WITHDRAWAL_STATUS_LABEL_REJECTED,
|
|
58
|
-
[WITHDRAWAL_STATUS_PROCESSING]: WITHDRAWAL_STATUS_LABEL_PROCESSING,
|
|
59
|
-
[WITHDRAWAL_STATUS_AWAITING_LIQUIDATION]: WITHDRAWAL_STATUS_LABEL_AWAITING_LIQUIDATION,
|
|
60
|
-
[WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS]: WITHDRAWAL_STATUS_LABEL_LIQUIDATION_IN_PROGRESS,
|
|
61
|
-
[WITHDRAWAL_STATUS_COMPLETED]: WITHDRAWAL_STATUS_LABEL_COMPLETED,
|
|
62
|
-
[WITHDRAWAL_STATUS_CANCELLED]: WITHDRAWAL_STATUS_LABEL_CANCELLED,
|
|
63
|
-
[WITHDRAWAL_STATUS_FAILED]: WITHDRAWAL_STATUS_LABEL_FAILED,
|
|
64
|
-
};
|
|
65
|
-
const LIQUIDATION_STATUS_LABELS = {
|
|
66
|
-
[LIQUIDATION_STATUS_PENDING]: LIQUIDATION_STATUS_LABEL_PENDING,
|
|
67
|
-
[LIQUIDATION_STATUS_TRADES_CREATED]: LIQUIDATION_STATUS_LABEL_TRADES_CREATED,
|
|
68
|
-
[LIQUIDATION_STATUS_EXECUTED]: LIQUIDATION_STATUS_LABEL_EXECUTED,
|
|
69
|
-
[LIQUIDATION_STATUS_SETTLED]: LIQUIDATION_STATUS_LABEL_SETTLED,
|
|
70
|
-
[LIQUIDATION_STATUS_FAILED]: LIQUIDATION_STATUS_LABEL_FAILED,
|
|
71
|
-
};
|
|
72
|
-
const TARGET_TRADE_STATUS_LABELS = {
|
|
73
|
-
[TARGET_TRADE_STATUS_PENDING]: TARGET_TRADE_STATUS_LABEL_PENDING,
|
|
74
|
-
[TARGET_TRADE_STATUS_APPROVED]: TARGET_TRADE_STATUS_LABEL_APPROVED,
|
|
75
|
-
[TARGET_TRADE_STATUS_SUBMITTED]: TARGET_TRADE_STATUS_LABEL_SUBMITTED,
|
|
76
|
-
[TARGET_TRADE_STATUS_CANCELLED]: TARGET_TRADE_STATUS_LABEL_CANCELLED,
|
|
77
|
-
[TARGET_TRADE_STATUS_EXPIRED]: TARGET_TRADE_STATUS_LABEL_EXPIRED,
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Creates a badge for trade status
|
|
81
|
-
*
|
|
82
|
-
* @param status - Trade status constant
|
|
83
|
-
* @param size - Badge size (default: 'md')
|
|
84
|
-
* @returns Badge style with display text and accessibility attributes
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* const badge = getTradeStatusBadge(TRADE_STATUS_SETTLED);
|
|
89
|
-
* // Returns badge with success variant and "Settled" display text
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
export function getTradeStatusBadge(status, size = 'md') {
|
|
93
|
-
const variant = TRADE_STATUS_MAPPING[status] || 'neutral';
|
|
94
|
-
const badge = createBadge({ variant, size });
|
|
95
|
-
const displayText = TRADE_STATUS_LABELS[status] || status.charAt(0) + status.slice(1).toLowerCase();
|
|
96
|
-
return {
|
|
97
|
-
...badge,
|
|
98
|
-
displayText,
|
|
99
|
-
ariaLabel: `Trade status: ${displayText}`,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Creates a badge for withdrawal status
|
|
104
|
-
*
|
|
105
|
-
* @param status - Withdrawal status constant
|
|
106
|
-
* @param size - Badge size (default: 'md')
|
|
107
|
-
* @returns Badge style with display text and accessibility attributes
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```typescript
|
|
111
|
-
* const badge = getWithdrawalStatusBadge(WITHDRAWAL_STATUS_APPROVED);
|
|
112
|
-
* // Returns badge with success variant and "Approved" display text
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
export function getWithdrawalStatusBadge(status, size = 'md') {
|
|
116
|
-
const variant = WITHDRAWAL_STATUS_MAPPING[status] || 'neutral';
|
|
117
|
-
const badge = createBadge({ variant, size });
|
|
118
|
-
const displayText = WITHDRAWAL_STATUS_LABELS[status] || status;
|
|
119
|
-
return {
|
|
120
|
-
...badge,
|
|
121
|
-
displayText,
|
|
122
|
-
ariaLabel: `Withdrawal status: ${displayText}`,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Creates a badge for liquidation status
|
|
127
|
-
*
|
|
128
|
-
* @param status - Liquidation status constant
|
|
129
|
-
* @param size - Badge size (default: 'md')
|
|
130
|
-
* @returns Badge style with display text and accessibility attributes
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* const badge = getLiquidationStatusBadge(LIQUIDATION_STATUS_SETTLED);
|
|
135
|
-
* // Returns badge with success variant and "Settled" display text
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
export function getLiquidationStatusBadge(status, size = 'md') {
|
|
139
|
-
const variant = LIQUIDATION_STATUS_MAPPING[status] || 'neutral';
|
|
140
|
-
const badge = createBadge({ variant, size });
|
|
141
|
-
const displayText = LIQUIDATION_STATUS_LABELS[status] || status;
|
|
142
|
-
return {
|
|
143
|
-
...badge,
|
|
144
|
-
displayText,
|
|
145
|
-
ariaLabel: `Liquidation status: ${displayText}`,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Creates a badge for target trade status
|
|
150
|
-
*
|
|
151
|
-
* @param status - Target trade status constant
|
|
152
|
-
* @param size - Badge size (default: 'md')
|
|
153
|
-
* @returns Badge style with display text and accessibility attributes
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```typescript
|
|
157
|
-
* const badge = getTargetTradeStatusBadge(TARGET_TRADE_STATUS_PENDING);
|
|
158
|
-
* // Returns badge with warning variant and "Pending" display text
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
export function getTargetTradeStatusBadge(status, size = 'md') {
|
|
162
|
-
const variant = TARGET_TRADE_STATUS_MAPPING[status] || 'neutral';
|
|
163
|
-
const badge = createBadge({ variant, size });
|
|
164
|
-
const displayText = TARGET_TRADE_STATUS_LABELS[status] || status;
|
|
165
|
-
return {
|
|
166
|
-
...badge,
|
|
167
|
-
displayText,
|
|
168
|
-
ariaLabel: `Target trade status: ${displayText}`,
|
|
169
|
-
};
|
|
170
|
-
}
|
package/dist/badge.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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
|
package/dist/badge.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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;
|