@apptimate/ui 1.3.0 → 1.5.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/package.json
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Modal } from './Modal';
|
|
5
|
+
|
|
6
|
+
export interface ActionModalProps {
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
title?: string | React.ReactNode;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
onConfirm?: () => void;
|
|
12
|
+
confirmLabel?: string;
|
|
13
|
+
cancelLabel?: string;
|
|
14
|
+
isLoading?: boolean;
|
|
15
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full';
|
|
16
|
+
/** Variant controls the confirm button colour */
|
|
17
|
+
variant?: 'primary' | 'danger';
|
|
18
|
+
className?: string;
|
|
19
|
+
/** Override z-index layer (default 50). Increase for nested modals. */
|
|
20
|
+
zIndex?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ActionModal — a convenience wrapper around `Modal` that renders a
|
|
25
|
+
* standard Cancel / Confirm footer. Use this for quick confirm-style
|
|
26
|
+
* dialogs (deposits, withdrawals, delete confirmations, etc.).
|
|
27
|
+
*/
|
|
28
|
+
export const ActionModal = ({
|
|
29
|
+
isOpen,
|
|
30
|
+
onClose,
|
|
31
|
+
title,
|
|
32
|
+
children,
|
|
33
|
+
onConfirm,
|
|
34
|
+
confirmLabel = "Confirm",
|
|
35
|
+
cancelLabel = "Cancel",
|
|
36
|
+
isLoading = false,
|
|
37
|
+
size = 'sm',
|
|
38
|
+
variant = 'primary',
|
|
39
|
+
className,
|
|
40
|
+
zIndex,
|
|
41
|
+
}: ActionModalProps) => {
|
|
42
|
+
const confirmBtnClass =
|
|
43
|
+
variant === 'danger'
|
|
44
|
+
? "px-4 py-2 rounded-lg text-sm font-bold bg-red-600 text-white hover:bg-red-700 disabled:opacity-50 transition-colors"
|
|
45
|
+
: "px-4 py-2 rounded-lg text-sm font-bold bg-[#2D3142] text-white hover:bg-[#3d4156] disabled:opacity-50 transition-colors";
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Modal
|
|
49
|
+
isOpen={isOpen}
|
|
50
|
+
onClose={onClose}
|
|
51
|
+
title={title}
|
|
52
|
+
size={size}
|
|
53
|
+
className={className}
|
|
54
|
+
zIndex={zIndex}
|
|
55
|
+
footer={
|
|
56
|
+
<>
|
|
57
|
+
<button
|
|
58
|
+
onClick={onClose}
|
|
59
|
+
className="px-4 py-2 rounded-lg text-sm font-bold text-gray-600 bg-gray-100 hover:bg-gray-200 transition-colors"
|
|
60
|
+
disabled={isLoading}
|
|
61
|
+
>
|
|
62
|
+
{cancelLabel}
|
|
63
|
+
</button>
|
|
64
|
+
{onConfirm && (
|
|
65
|
+
<button
|
|
66
|
+
onClick={onConfirm}
|
|
67
|
+
className={confirmBtnClass}
|
|
68
|
+
disabled={isLoading}
|
|
69
|
+
>
|
|
70
|
+
{isLoading ? (
|
|
71
|
+
<span className="inline-flex items-center gap-2">
|
|
72
|
+
<span className="w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin" />
|
|
73
|
+
{confirmLabel}
|
|
74
|
+
</span>
|
|
75
|
+
) : (
|
|
76
|
+
confirmLabel
|
|
77
|
+
)}
|
|
78
|
+
</button>
|
|
79
|
+
)}
|
|
80
|
+
</>
|
|
81
|
+
}
|
|
82
|
+
>
|
|
83
|
+
{children}
|
|
84
|
+
</Modal>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { cn } from '@apptimate/core-lib';
|
|
5
|
+
import { Label } from './Label';
|
|
6
|
+
|
|
7
|
+
// ── Types ────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
export type AmountDisplayMode = 'label' | 'input';
|
|
10
|
+
|
|
11
|
+
export interface AmountComponentProps {
|
|
12
|
+
/** The numeric amount value */
|
|
13
|
+
value: number | string;
|
|
14
|
+
/** Display mode: 'label' (read-only text) or 'input' (editable field). Default: 'label' */
|
|
15
|
+
mode?: AmountDisplayMode;
|
|
16
|
+
/** Currency symbol. Default: 'Rs.' */
|
|
17
|
+
currency?: string;
|
|
18
|
+
/** Text color class (e.g. 'text-green-600', 'text-red-500'). Applied to the rendered amount. */
|
|
19
|
+
color?: string;
|
|
20
|
+
/** Label text shown above the amount (only when mode='label'). */
|
|
21
|
+
label?: string;
|
|
22
|
+
/** If true, shows the required asterisk on the label */
|
|
23
|
+
isRequired?: boolean;
|
|
24
|
+
/** Font size class override. Default: 'text-sm' for label, 'text-[13.5px]' for input */
|
|
25
|
+
fontSize?: string;
|
|
26
|
+
/** Font weight class override. Default: 'font-semibold' */
|
|
27
|
+
fontWeight?: string;
|
|
28
|
+
/** Additional className for the root wrapper */
|
|
29
|
+
className?: string;
|
|
30
|
+
/** Number of decimal places. Default: 2 */
|
|
31
|
+
decimals?: number;
|
|
32
|
+
|
|
33
|
+
// ── Input mode props ──────────────────────────────────────────────────
|
|
34
|
+
/** Callback when value changes (input mode only) */
|
|
35
|
+
onChange?: (value: number) => void;
|
|
36
|
+
/** Placeholder text (input mode only). Default: '0.00' */
|
|
37
|
+
placeholder?: string;
|
|
38
|
+
/** Disable the input (input mode only) */
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
/** Error message (input mode only) */
|
|
41
|
+
error?: string;
|
|
42
|
+
/** Min value (input mode only) */
|
|
43
|
+
min?: number;
|
|
44
|
+
/** Max value (input mode only) */
|
|
45
|
+
max?: number;
|
|
46
|
+
/** Step value (input mode only). Default: '0.01' */
|
|
47
|
+
step?: string;
|
|
48
|
+
/** Name attribute (input mode only) */
|
|
49
|
+
name?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ── Helpers ──────────────────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
function formatAmount(value: number | string, decimals: number): string {
|
|
55
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
56
|
+
if (isNaN(num)) return '0.' + '0'.repeat(decimals);
|
|
57
|
+
return num.toLocaleString('en-US', {
|
|
58
|
+
minimumFractionDigits: decimals,
|
|
59
|
+
maximumFractionDigits: decimals,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ── Component ────────────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
export const AmountComponent = React.forwardRef<HTMLInputElement, AmountComponentProps>(
|
|
66
|
+
(
|
|
67
|
+
{
|
|
68
|
+
value,
|
|
69
|
+
mode = 'label',
|
|
70
|
+
currency = 'Rs.',
|
|
71
|
+
color,
|
|
72
|
+
label,
|
|
73
|
+
isRequired,
|
|
74
|
+
fontSize,
|
|
75
|
+
fontWeight = 'font-semibold',
|
|
76
|
+
className,
|
|
77
|
+
decimals = 2,
|
|
78
|
+
// Input mode props
|
|
79
|
+
onChange,
|
|
80
|
+
placeholder = '0.00',
|
|
81
|
+
disabled = false,
|
|
82
|
+
error,
|
|
83
|
+
min,
|
|
84
|
+
max,
|
|
85
|
+
step = '0.01',
|
|
86
|
+
name,
|
|
87
|
+
},
|
|
88
|
+
ref
|
|
89
|
+
) => {
|
|
90
|
+
// ── Label Mode ────────────────────────────────────────────────────────
|
|
91
|
+
if (mode === 'label') {
|
|
92
|
+
const resolvedFontSize = fontSize || 'text-sm';
|
|
93
|
+
const resolvedColor = color || 'text-foreground-1';
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div className={cn('flex flex-col gap-1', className)}>
|
|
97
|
+
{label && (
|
|
98
|
+
<Label isRequired={isRequired}>{label}</Label>
|
|
99
|
+
)}
|
|
100
|
+
<span className={cn(resolvedFontSize, fontWeight, resolvedColor)}>
|
|
101
|
+
{currency} {formatAmount(value, decimals)}
|
|
102
|
+
</span>
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ── Input Mode ────────────────────────────────────────────────────────
|
|
108
|
+
const resolvedFontSize = fontSize || 'text-[13.5px]';
|
|
109
|
+
const resolvedColor = color || 'text-foreground-1';
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<div className={cn('flex flex-col gap-1.5 w-full', className)}>
|
|
113
|
+
{label && (
|
|
114
|
+
<Label isRequired={isRequired}>{label}</Label>
|
|
115
|
+
)}
|
|
116
|
+
<div className="relative group">
|
|
117
|
+
{/* Currency prefix */}
|
|
118
|
+
<span
|
|
119
|
+
className={cn(
|
|
120
|
+
'absolute left-3 top-1/2 -translate-y-1/2 text-[12px] font-medium text-gray-400 pointer-events-none select-none'
|
|
121
|
+
)}
|
|
122
|
+
>
|
|
123
|
+
{currency}
|
|
124
|
+
</span>
|
|
125
|
+
<input
|
|
126
|
+
ref={ref}
|
|
127
|
+
type="number"
|
|
128
|
+
name={name}
|
|
129
|
+
value={value}
|
|
130
|
+
onChange={(e) => onChange?.(parseFloat(e.target.value) || 0)}
|
|
131
|
+
disabled={disabled}
|
|
132
|
+
min={min}
|
|
133
|
+
max={max}
|
|
134
|
+
step={step}
|
|
135
|
+
placeholder={placeholder}
|
|
136
|
+
className={cn(
|
|
137
|
+
'w-full bg-surface-0 border-[1.5px] border-border-subtle rounded-[10px] pl-10 pr-3.5 py-2.5 text-right outline-none transition-all',
|
|
138
|
+
'hover:border-gray-300 focus:border-gray-300 focus:bg-surface-1',
|
|
139
|
+
'placeholder:text-foreground-disabled',
|
|
140
|
+
'[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none',
|
|
141
|
+
resolvedFontSize,
|
|
142
|
+
fontWeight,
|
|
143
|
+
resolvedColor,
|
|
144
|
+
disabled && 'opacity-60 cursor-not-allowed',
|
|
145
|
+
error && 'border-danger-alt focus:border-danger-alt hover:border-danger-alt'
|
|
146
|
+
)}
|
|
147
|
+
/>
|
|
148
|
+
</div>
|
|
149
|
+
{error && (
|
|
150
|
+
<span className="text-[11px] text-danger-alt font-medium">{error}</span>
|
|
151
|
+
)}
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
AmountComponent.displayName = 'AmountComponent';
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
export * from './base-components/Accordion';
|
|
4
|
+
export * from './base-components/AmountComponent';
|
|
4
5
|
export * from './base-components/Badge';
|
|
5
6
|
export * from './base-components/Button';
|
|
6
7
|
export * from './base-components/ButtonGroup';
|
|
@@ -20,6 +21,7 @@ export * from './base-components/DesktopFilterPopover';
|
|
|
20
21
|
export * from './base-components/Input';
|
|
21
22
|
export * from './base-components/Label';
|
|
22
23
|
export * from './base-components/Modal';
|
|
24
|
+
export * from './base-components/ActionModal';
|
|
23
25
|
export * from './base-components/Pagination';
|
|
24
26
|
export * from './base-components/PopConfirm';
|
|
25
27
|
export * from './base-components/SearchableSelect';
|