tekivex-ui 2.0.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/LICENSE +21 -0
- package/README.md +201 -0
- package/dist/index.cjs +70 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11002 -0
- package/dist/src/a11y/index.d.ts +24 -0
- package/dist/src/a11y/index.d.ts.map +1 -0
- package/dist/src/components/TkxAccordion.d.ts +32 -0
- package/dist/src/components/TkxAccordion.d.ts.map +1 -0
- package/dist/src/components/TkxAlert.d.ts +14 -0
- package/dist/src/components/TkxAlert.d.ts.map +1 -0
- package/dist/src/components/TkxAvatar.d.ts +14 -0
- package/dist/src/components/TkxAvatar.d.ts.map +1 -0
- package/dist/src/components/TkxBadge.d.ts +12 -0
- package/dist/src/components/TkxBadge.d.ts.map +1 -0
- package/dist/src/components/TkxButton.d.ts +17 -0
- package/dist/src/components/TkxButton.d.ts.map +1 -0
- package/dist/src/components/TkxCard.d.ts +20 -0
- package/dist/src/components/TkxCard.d.ts.map +1 -0
- package/dist/src/components/TkxCarousel.d.ts +32 -0
- package/dist/src/components/TkxCarousel.d.ts.map +1 -0
- package/dist/src/components/TkxChat.d.ts +32 -0
- package/dist/src/components/TkxChat.d.ts.map +1 -0
- package/dist/src/components/TkxCheckbox.d.ts +13 -0
- package/dist/src/components/TkxCheckbox.d.ts.map +1 -0
- package/dist/src/components/TkxClock.d.ts +23 -0
- package/dist/src/components/TkxClock.d.ts.map +1 -0
- package/dist/src/components/TkxColorPicker.d.ts +18 -0
- package/dist/src/components/TkxColorPicker.d.ts.map +1 -0
- package/dist/src/components/TkxCommand.d.ts +34 -0
- package/dist/src/components/TkxCommand.d.ts.map +1 -0
- package/dist/src/components/TkxDatePicker.d.ts +47 -0
- package/dist/src/components/TkxDatePicker.d.ts.map +1 -0
- package/dist/src/components/TkxDivider.d.ts +8 -0
- package/dist/src/components/TkxDivider.d.ts.map +1 -0
- package/dist/src/components/TkxDrawer.d.ts +16 -0
- package/dist/src/components/TkxDrawer.d.ts.map +1 -0
- package/dist/src/components/TkxFileUpload.d.ts +16 -0
- package/dist/src/components/TkxFileUpload.d.ts.map +1 -0
- package/dist/src/components/TkxIcon.d.ts +16 -0
- package/dist/src/components/TkxIcon.d.ts.map +1 -0
- package/dist/src/components/TkxImage.d.ts +16 -0
- package/dist/src/components/TkxImage.d.ts.map +1 -0
- package/dist/src/components/TkxInput.d.ts +13 -0
- package/dist/src/components/TkxInput.d.ts.map +1 -0
- package/dist/src/components/TkxLogo.d.ts +21 -0
- package/dist/src/components/TkxLogo.d.ts.map +1 -0
- package/dist/src/components/TkxMenu.d.ts +64 -0
- package/dist/src/components/TkxMenu.d.ts.map +1 -0
- package/dist/src/components/TkxModal.d.ts +14 -0
- package/dist/src/components/TkxModal.d.ts.map +1 -0
- package/dist/src/components/TkxNumberInput.d.ts +32 -0
- package/dist/src/components/TkxNumberInput.d.ts.map +1 -0
- package/dist/src/components/TkxOTP.d.ts +24 -0
- package/dist/src/components/TkxOTP.d.ts.map +1 -0
- package/dist/src/components/TkxPagination.d.ts +19 -0
- package/dist/src/components/TkxPagination.d.ts.map +1 -0
- package/dist/src/components/TkxProgress.d.ts +13 -0
- package/dist/src/components/TkxProgress.d.ts.map +1 -0
- package/dist/src/components/TkxRadio.d.ts +22 -0
- package/dist/src/components/TkxRadio.d.ts.map +1 -0
- package/dist/src/components/TkxRating.d.ts +18 -0
- package/dist/src/components/TkxRating.d.ts.map +1 -0
- package/dist/src/components/TkxSelect.d.ts +37 -0
- package/dist/src/components/TkxSelect.d.ts.map +1 -0
- package/dist/src/components/TkxSkeleton.d.ts +12 -0
- package/dist/src/components/TkxSkeleton.d.ts.map +1 -0
- package/dist/src/components/TkxSlider.d.ts +33 -0
- package/dist/src/components/TkxSlider.d.ts.map +1 -0
- package/dist/src/components/TkxStepper.d.ts +31 -0
- package/dist/src/components/TkxStepper.d.ts.map +1 -0
- package/dist/src/components/TkxTable.d.ts +23 -0
- package/dist/src/components/TkxTable.d.ts.map +1 -0
- package/dist/src/components/TkxTabs.d.ts +32 -0
- package/dist/src/components/TkxTabs.d.ts.map +1 -0
- package/dist/src/components/TkxTag.d.ts +30 -0
- package/dist/src/components/TkxTag.d.ts.map +1 -0
- package/dist/src/components/TkxTimeline.d.ts +20 -0
- package/dist/src/components/TkxTimeline.d.ts.map +1 -0
- package/dist/src/components/TkxToast.d.ts +23 -0
- package/dist/src/components/TkxToast.d.ts.map +1 -0
- package/dist/src/components/TkxToggle.d.ts +11 -0
- package/dist/src/components/TkxToggle.d.ts.map +1 -0
- package/dist/src/components/TkxTooltip.d.ts +10 -0
- package/dist/src/components/TkxTooltip.d.ts.map +1 -0
- package/dist/src/components/TkxVideoPlayer.d.ts +43 -0
- package/dist/src/components/TkxVideoPlayer.d.ts.map +1 -0
- package/dist/src/components/index.d.ts +41 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/engine/css.d.ts +24 -0
- package/dist/src/engine/css.d.ts.map +1 -0
- package/dist/src/engine/index.d.ts +10 -0
- package/dist/src/engine/index.d.ts.map +1 -0
- package/dist/src/engine/quantum.d.ts +47 -0
- package/dist/src/engine/quantum.d.ts.map +1 -0
- package/dist/src/engine/security.d.ts +54 -0
- package/dist/src/engine/security.d.ts.map +1 -0
- package/dist/src/engine/tkx.d.ts +29 -0
- package/dist/src/engine/tkx.d.ts.map +1 -0
- package/dist/src/engine/wcag.d.ts +34 -0
- package/dist/src/engine/wcag.d.ts.map +1 -0
- package/dist/src/hooks/index.d.ts +8 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/themes/index.d.ts +26 -0
- package/dist/src/themes/index.d.ts.map +1 -0
- package/dist/style.css +1 -0
- package/dist/tests/TkxButton.test.d.ts +2 -0
- package/dist/tests/TkxButton.test.d.ts.map +1 -0
- package/dist/tests/a11y/components.test.d.ts +2 -0
- package/dist/tests/a11y/components.test.d.ts.map +1 -0
- package/dist/tests/quantum.test.d.ts +2 -0
- package/dist/tests/quantum.test.d.ts.map +1 -0
- package/dist/tests/security.test.d.ts +2 -0
- package/dist/tests/security.test.d.ts.map +1 -0
- package/dist/tests/setup.d.ts +2 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/tkx.test.d.ts +2 -0
- package/dist/tests/tkx.test.d.ts.map +1 -0
- package/dist/tests/wcag.test.d.ts +2 -0
- package/dist/tests/wcag.test.d.ts.map +1 -0
- package/package.json +78 -0
- package/src/a11y/index.tsx +87 -0
- package/src/components/TkxAccordion.tsx +588 -0
- package/src/components/TkxAlert.tsx +91 -0
- package/src/components/TkxAvatar.tsx +101 -0
- package/src/components/TkxBadge.tsx +73 -0
- package/src/components/TkxButton.tsx +153 -0
- package/src/components/TkxCard.tsx +92 -0
- package/src/components/TkxCarousel.tsx +552 -0
- package/src/components/TkxChat.tsx +354 -0
- package/src/components/TkxCheckbox.tsx +218 -0
- package/src/components/TkxClock.tsx +601 -0
- package/src/components/TkxColorPicker.tsx +633 -0
- package/src/components/TkxCommand.tsx +644 -0
- package/src/components/TkxDatePicker.tsx +1567 -0
- package/src/components/TkxDivider.tsx +49 -0
- package/src/components/TkxDrawer.tsx +234 -0
- package/src/components/TkxFileUpload.tsx +371 -0
- package/src/components/TkxIcon.tsx +683 -0
- package/src/components/TkxImage.tsx +277 -0
- package/src/components/TkxInput.tsx +101 -0
- package/src/components/TkxLogo.tsx +297 -0
- package/src/components/TkxMenu.tsx +1042 -0
- package/src/components/TkxModal.tsx +119 -0
- package/src/components/TkxNumberInput.tsx +408 -0
- package/src/components/TkxOTP.tsx +295 -0
- package/src/components/TkxPagination.tsx +388 -0
- package/src/components/TkxProgress.tsx +114 -0
- package/src/components/TkxRadio.tsx +284 -0
- package/src/components/TkxRating.tsx +286 -0
- package/src/components/TkxSelect.tsx +923 -0
- package/src/components/TkxSkeleton.tsx +105 -0
- package/src/components/TkxSlider.tsx +492 -0
- package/src/components/TkxStepper.tsx +485 -0
- package/src/components/TkxTable.tsx +148 -0
- package/src/components/TkxTabs.tsx +124 -0
- package/src/components/TkxTag.tsx +319 -0
- package/src/components/TkxTimeline.tsx +303 -0
- package/src/components/TkxToast.tsx +284 -0
- package/src/components/TkxToggle.tsx +93 -0
- package/src/components/TkxTooltip.tsx +69 -0
- package/src/components/TkxVideoPlayer.tsx +1013 -0
- package/src/components/index.ts +40 -0
- package/src/engine/css.ts +126 -0
- package/src/engine/index.ts +10 -0
- package/src/engine/quantum.ts +207 -0
- package/src/engine/security.ts +217 -0
- package/src/engine/tkx.ts +874 -0
- package/src/engine/wcag.ts +275 -0
- package/src/hooks/index.ts +120 -0
- package/src/styles/global.css +167 -0
- package/src/themes/index.ts +111 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { useEffect, useRef, type ReactNode } from 'react';
|
|
2
|
+
import { useTheme } from '../themes';
|
|
3
|
+
import { tkx, cx } from '../engine/tkx';
|
|
4
|
+
import { sanitizeString } from '../engine/security';
|
|
5
|
+
import { useReducedMotion } from '../hooks';
|
|
6
|
+
|
|
7
|
+
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
export type TimelineVariant = 'default' | 'compact' | 'alternating';
|
|
10
|
+
export type TimelineItemStatus = 'completed' | 'active' | 'pending' | 'error';
|
|
11
|
+
|
|
12
|
+
export interface TimelineItem {
|
|
13
|
+
id: string;
|
|
14
|
+
title: ReactNode;
|
|
15
|
+
description?: ReactNode;
|
|
16
|
+
timestamp?: string;
|
|
17
|
+
status?: TimelineItemStatus;
|
|
18
|
+
icon?: ReactNode;
|
|
19
|
+
badge?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface TkxTimelineProps {
|
|
23
|
+
items: TimelineItem[];
|
|
24
|
+
variant?: TimelineVariant;
|
|
25
|
+
orientation?: 'vertical' | 'horizontal';
|
|
26
|
+
connectorStyle?: 'solid' | 'dashed' | 'dotted';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ── Animation injection ───────────────────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
let _timelineStyleInjected = false;
|
|
32
|
+
function injectTimelineStyles() {
|
|
33
|
+
if (_timelineStyleInjected || typeof document === 'undefined') return;
|
|
34
|
+
_timelineStyleInjected = true;
|
|
35
|
+
const style = document.createElement('style');
|
|
36
|
+
style.textContent = `
|
|
37
|
+
@keyframes tkx-pulse-dot { 0%,100% { box-shadow:0 0 0 0 currentColor; opacity:1; } 70% { box-shadow:0 0 0 8px transparent; opacity:0.7; } }
|
|
38
|
+
@keyframes tkx-draw-line { from { transform:scaleY(0); transform-origin:top center; } to { transform:scaleY(1); } }
|
|
39
|
+
@keyframes tkx-draw-line-h { from { transform:scaleX(0); transform-origin:left center; } to { transform:scaleX(1); } }
|
|
40
|
+
.tkx-pulse-dot { animation: tkx-pulse-dot 1.5s ease-in-out infinite; }
|
|
41
|
+
.tkx-draw-v { animation: tkx-draw-line 0.6s ease forwards; }
|
|
42
|
+
.tkx-draw-h { animation: tkx-draw-line-h 0.6s ease forwards; }
|
|
43
|
+
`;
|
|
44
|
+
document.head.appendChild(style);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ── Status color helper ───────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
function useStatusColor(status: TimelineItemStatus = 'pending') {
|
|
50
|
+
const theme = useTheme();
|
|
51
|
+
const map: Record<TimelineItemStatus, string> = {
|
|
52
|
+
completed: theme.success,
|
|
53
|
+
active: theme.primary,
|
|
54
|
+
pending: theme.border,
|
|
55
|
+
error: theme.danger,
|
|
56
|
+
};
|
|
57
|
+
return map[status];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ── Dot component ─────────────────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
function TimelineDot({
|
|
63
|
+
status = 'pending',
|
|
64
|
+
icon,
|
|
65
|
+
size = 28,
|
|
66
|
+
}: {
|
|
67
|
+
status?: TimelineItemStatus;
|
|
68
|
+
icon?: ReactNode;
|
|
69
|
+
size?: number;
|
|
70
|
+
}) {
|
|
71
|
+
const theme = useTheme();
|
|
72
|
+
const reducedMotion = useReducedMotion();
|
|
73
|
+
const color = useStatusColor(status);
|
|
74
|
+
const isActive = status === 'active';
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div
|
|
78
|
+
className={cx(
|
|
79
|
+
tkx('relative flex items-center justify-center rounded-full shrink-0 z-10'),
|
|
80
|
+
isActive && !reducedMotion ? 'tkx-pulse-dot' : '',
|
|
81
|
+
)}
|
|
82
|
+
style={{
|
|
83
|
+
width: size,
|
|
84
|
+
height: size,
|
|
85
|
+
backgroundColor: status === 'pending' ? theme.surface : color,
|
|
86
|
+
border: `2px solid ${color}`,
|
|
87
|
+
color: status === 'pending' ? color : theme.bg,
|
|
88
|
+
}}
|
|
89
|
+
aria-hidden="true"
|
|
90
|
+
>
|
|
91
|
+
{icon ? (
|
|
92
|
+
<span style={{ fontSize: size * 0.45, lineHeight: 1 }}>{icon}</span>
|
|
93
|
+
) : (
|
|
94
|
+
<span
|
|
95
|
+
style={{
|
|
96
|
+
width: size * 0.35,
|
|
97
|
+
height: size * 0.35,
|
|
98
|
+
borderRadius: '50%',
|
|
99
|
+
backgroundColor: status === 'pending' ? color : theme.bg,
|
|
100
|
+
display: 'block',
|
|
101
|
+
}}
|
|
102
|
+
/>
|
|
103
|
+
)}
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ── Connector segment ─────────────────────────────────────────────────────────
|
|
109
|
+
|
|
110
|
+
function VerticalConnector({
|
|
111
|
+
style: lineStyle,
|
|
112
|
+
color,
|
|
113
|
+
animate,
|
|
114
|
+
}: {
|
|
115
|
+
style: 'solid' | 'dashed' | 'dotted';
|
|
116
|
+
color: string;
|
|
117
|
+
animate: boolean;
|
|
118
|
+
}) {
|
|
119
|
+
const theme = useTheme();
|
|
120
|
+
return (
|
|
121
|
+
<div
|
|
122
|
+
className={cx(tkx('w-0.5 flex-1 min-h-[24px]'), animate ? 'tkx-draw-v' : '')}
|
|
123
|
+
style={{
|
|
124
|
+
borderLeft: `2px ${lineStyle} ${color}`,
|
|
125
|
+
backgroundColor: 'transparent',
|
|
126
|
+
alignSelf: 'stretch',
|
|
127
|
+
borderColor: color,
|
|
128
|
+
marginLeft: 1,
|
|
129
|
+
}}
|
|
130
|
+
aria-hidden="true"
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function HorizontalConnector({
|
|
136
|
+
style: lineStyle,
|
|
137
|
+
color,
|
|
138
|
+
animate,
|
|
139
|
+
}: {
|
|
140
|
+
style: 'solid' | 'dashed' | 'dotted';
|
|
141
|
+
color: string;
|
|
142
|
+
animate: boolean;
|
|
143
|
+
}) {
|
|
144
|
+
return (
|
|
145
|
+
<div
|
|
146
|
+
className={cx(tkx('h-0.5 flex-1 min-w-[24px]'), animate ? 'tkx-draw-h' : '')}
|
|
147
|
+
style={{
|
|
148
|
+
borderTop: `2px ${lineStyle} ${color}`,
|
|
149
|
+
borderColor: color,
|
|
150
|
+
}}
|
|
151
|
+
aria-hidden="true"
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ── Item content block ────────────────────────────────────────────────────────
|
|
157
|
+
|
|
158
|
+
function ItemContent({
|
|
159
|
+
item,
|
|
160
|
+
compact,
|
|
161
|
+
}: {
|
|
162
|
+
item: TimelineItem;
|
|
163
|
+
compact: boolean;
|
|
164
|
+
}) {
|
|
165
|
+
const theme = useTheme();
|
|
166
|
+
const safeTimestamp = item.timestamp ? sanitizeString(item.timestamp) : null;
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<div className={tkx('flex flex-col gap-0.5', compact ? 'pb-3' : 'pb-5')}>
|
|
170
|
+
<div className={tkx('flex items-center gap-2 flex-wrap')}>
|
|
171
|
+
<span
|
|
172
|
+
className={tkx('text-sm font-semibold leading-snug')}
|
|
173
|
+
style={{ color: theme.text }}
|
|
174
|
+
>
|
|
175
|
+
{typeof item.title === 'string' ? sanitizeString(item.title) : item.title}
|
|
176
|
+
</span>
|
|
177
|
+
{item.badge && (
|
|
178
|
+
<span>{item.badge}</span>
|
|
179
|
+
)}
|
|
180
|
+
{safeTimestamp && (
|
|
181
|
+
<span className={tkx('text-[11px] ml-auto')} style={{ color: theme.textMuted }}>
|
|
182
|
+
{safeTimestamp}
|
|
183
|
+
</span>
|
|
184
|
+
)}
|
|
185
|
+
</div>
|
|
186
|
+
{item.description && !compact && (
|
|
187
|
+
<div className={tkx('text-xs leading-relaxed mt-0.5')} style={{ color: theme.textMuted }}>
|
|
188
|
+
{typeof item.description === 'string' ? sanitizeString(item.description) : item.description}
|
|
189
|
+
</div>
|
|
190
|
+
)}
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ── Main TkxTimeline ──────────────────────────────────────────────────────────
|
|
196
|
+
|
|
197
|
+
export function TkxTimeline({
|
|
198
|
+
items,
|
|
199
|
+
variant = 'default',
|
|
200
|
+
orientation = 'vertical',
|
|
201
|
+
connectorStyle = 'solid',
|
|
202
|
+
}: TkxTimelineProps) {
|
|
203
|
+
const theme = useTheme();
|
|
204
|
+
const reducedMotion = useReducedMotion();
|
|
205
|
+
const mounted = useRef(false);
|
|
206
|
+
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
injectTimelineStyles();
|
|
209
|
+
mounted.current = true;
|
|
210
|
+
}, []);
|
|
211
|
+
|
|
212
|
+
const animate = !reducedMotion;
|
|
213
|
+
const isCompact = variant === 'compact';
|
|
214
|
+
const isAlternating = variant === 'alternating' && orientation === 'vertical';
|
|
215
|
+
const isHorizontal = orientation === 'horizontal';
|
|
216
|
+
|
|
217
|
+
if (isHorizontal) {
|
|
218
|
+
return (
|
|
219
|
+
<div role="list" aria-label="Timeline" className={tkx('flex items-start w-full overflow-x-auto')}>
|
|
220
|
+
{items.map((item, idx) => {
|
|
221
|
+
const status = item.status ?? 'pending';
|
|
222
|
+
const connColor = status === 'completed' ? theme.success : theme.border;
|
|
223
|
+
const isLast = idx === items.length - 1;
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<div key={item.id} role="listitem" className={tkx('flex items-start flex-1 min-w-0')}>
|
|
227
|
+
<div className={tkx('flex flex-col items-center flex-1 min-w-0')}>
|
|
228
|
+
<div className={tkx('flex items-center w-full')}>
|
|
229
|
+
{idx > 0 && (
|
|
230
|
+
<HorizontalConnector style={connectorStyle} color={connColor} animate={animate} />
|
|
231
|
+
)}
|
|
232
|
+
<TimelineDot status={status} icon={item.icon} size={24} />
|
|
233
|
+
{!isLast && (
|
|
234
|
+
<HorizontalConnector style={connectorStyle} color={connColor} animate={animate} />
|
|
235
|
+
)}
|
|
236
|
+
</div>
|
|
237
|
+
<div className={tkx('mt-2 px-1 text-center min-w-0 w-full')}>
|
|
238
|
+
<div className={tkx('text-xs font-semibold truncate')} style={{ color: theme.text }}>
|
|
239
|
+
{typeof item.title === 'string' ? sanitizeString(item.title) : item.title}
|
|
240
|
+
</div>
|
|
241
|
+
{item.timestamp && (
|
|
242
|
+
<div className={tkx('text-[10px] mt-0.5')} style={{ color: theme.textMuted }}>
|
|
243
|
+
{sanitizeString(item.timestamp)}
|
|
244
|
+
</div>
|
|
245
|
+
)}
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
</div>
|
|
249
|
+
);
|
|
250
|
+
})}
|
|
251
|
+
</div>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Vertical layouts
|
|
256
|
+
return (
|
|
257
|
+
<div role="list" aria-label="Timeline" className={tkx('flex flex-col')}>
|
|
258
|
+
{items.map((item, idx) => {
|
|
259
|
+
const status = item.status ?? 'pending';
|
|
260
|
+
const isLast = idx === items.length - 1;
|
|
261
|
+
const connColor = status === 'completed' ? theme.success : theme.border;
|
|
262
|
+
const isRight = isAlternating && idx % 2 === 0;
|
|
263
|
+
|
|
264
|
+
if (isAlternating) {
|
|
265
|
+
return (
|
|
266
|
+
<div key={item.id} role="listitem" className={tkx('flex items-stretch gap-0')}>
|
|
267
|
+
{/* Left content (even indexes) */}
|
|
268
|
+
<div className={tkx('flex-1 flex flex-col items-end pr-4', !isRight ? 'invisible' : '')}>
|
|
269
|
+
{isRight && <ItemContent item={item} compact={isCompact} />}
|
|
270
|
+
</div>
|
|
271
|
+
{/* Center axis */}
|
|
272
|
+
<div className={tkx('flex flex-col items-center')}>
|
|
273
|
+
<TimelineDot status={status} icon={item.icon} size={28} />
|
|
274
|
+
{!isLast && (
|
|
275
|
+
<VerticalConnector style={connectorStyle} color={connColor} animate={animate} />
|
|
276
|
+
)}
|
|
277
|
+
</div>
|
|
278
|
+
{/* Right content (odd indexes) */}
|
|
279
|
+
<div className={tkx('flex-1 flex flex-col items-start pl-4', isRight ? 'invisible' : '')}>
|
|
280
|
+
{!isRight && <ItemContent item={item} compact={isCompact} />}
|
|
281
|
+
</div>
|
|
282
|
+
</div>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Default / compact — left-side connector
|
|
287
|
+
return (
|
|
288
|
+
<div key={item.id} role="listitem" className={tkx('flex gap-3 items-stretch')}>
|
|
289
|
+
<div className={tkx('flex flex-col items-center')}>
|
|
290
|
+
<TimelineDot status={status} icon={item.icon} size={isCompact ? 22 : 28} />
|
|
291
|
+
{!isLast && (
|
|
292
|
+
<VerticalConnector style={connectorStyle} color={connColor} animate={animate} />
|
|
293
|
+
)}
|
|
294
|
+
</div>
|
|
295
|
+
<div className={tkx('flex-1 min-w-0 pt-0.5')}>
|
|
296
|
+
<ItemContent item={item} compact={isCompact} />
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
);
|
|
300
|
+
})}
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useState,
|
|
3
|
+
useEffect,
|
|
4
|
+
useCallback,
|
|
5
|
+
useRef,
|
|
6
|
+
useId,
|
|
7
|
+
type ReactNode,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { createPortal } from 'react-dom';
|
|
10
|
+
import { useTheme } from '../themes';
|
|
11
|
+
import { sanitizeString } from '../engine/security';
|
|
12
|
+
import { useReducedMotion } from '../hooks';
|
|
13
|
+
import { tkx } from '../engine/tkx';
|
|
14
|
+
|
|
15
|
+
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
export type ToastVariant = 'default' | 'success' | 'danger' | 'warning' | 'info';
|
|
18
|
+
export type ToastPosition = 'top-right' | 'top-left' | 'top-center' | 'bottom-right' | 'bottom-left' | 'bottom-center';
|
|
19
|
+
|
|
20
|
+
export interface ToastItem {
|
|
21
|
+
id: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
variant?: ToastVariant;
|
|
25
|
+
duration?: number;
|
|
26
|
+
action?: { label: string; onClick: () => void };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface TkxToastProps {
|
|
30
|
+
position?: ToastPosition;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ── Module-level store ────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
type Listener = (toasts: ToastItem[]) => void;
|
|
36
|
+
|
|
37
|
+
const MAX_VISIBLE = 5;
|
|
38
|
+
let queue: ToastItem[] = [];
|
|
39
|
+
let visible: ToastItem[] = [];
|
|
40
|
+
const listeners = new Set<Listener>();
|
|
41
|
+
const timers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
42
|
+
|
|
43
|
+
function notify() {
|
|
44
|
+
const snapshot = [...visible];
|
|
45
|
+
listeners.forEach((fn) => fn(snapshot));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function scheduleRemove(id: string, duration: number) {
|
|
49
|
+
if (duration === 0) return;
|
|
50
|
+
timers.set(id, setTimeout(() => removeToast(id), duration));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function removeToast(id: string) {
|
|
54
|
+
clearTimeout(timers.get(id));
|
|
55
|
+
timers.delete(id);
|
|
56
|
+
const wasVisible = visible.some((t) => t.id === id);
|
|
57
|
+
visible = visible.filter((t) => t.id !== id);
|
|
58
|
+
queue = queue.filter((t) => t.id !== id);
|
|
59
|
+
if (wasVisible && queue.length > 0 && visible.length < MAX_VISIBLE) {
|
|
60
|
+
const next = queue.shift()!;
|
|
61
|
+
visible = [...visible, next];
|
|
62
|
+
scheduleRemove(next.id, next.duration ?? 4000);
|
|
63
|
+
}
|
|
64
|
+
notify();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function addToast(item: Omit<ToastItem, 'id'>): string {
|
|
68
|
+
const id = `tkx-toast-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`;
|
|
69
|
+
const toast: ToastItem = { ...item, id, duration: item.duration ?? 4000 };
|
|
70
|
+
if (visible.length < MAX_VISIBLE) {
|
|
71
|
+
visible = [...visible, toast];
|
|
72
|
+
scheduleRemove(id, toast.duration!);
|
|
73
|
+
} else {
|
|
74
|
+
queue = [...queue, toast];
|
|
75
|
+
}
|
|
76
|
+
notify();
|
|
77
|
+
return id;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function dismissAll() {
|
|
81
|
+
timers.forEach((t) => clearTimeout(t));
|
|
82
|
+
timers.clear();
|
|
83
|
+
visible = [];
|
|
84
|
+
queue = [];
|
|
85
|
+
notify();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ── Hook ──────────────────────────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
export function useToast() {
|
|
91
|
+
const toast = useCallback((item: Omit<ToastItem, 'id'>) => addToast(item), []);
|
|
92
|
+
const dismiss = useCallback((id: string) => removeToast(id), []);
|
|
93
|
+
const dismissAllToasts = useCallback(() => dismissAll(), []);
|
|
94
|
+
return { toast, dismiss, dismissAll: dismissAllToasts };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ── Variant config ────────────────────────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
const VARIANT_ICONS: Record<ToastVariant, ReactNode> = {
|
|
100
|
+
default: (
|
|
101
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
102
|
+
<path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z" />
|
|
103
|
+
</svg>
|
|
104
|
+
),
|
|
105
|
+
success: (
|
|
106
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
107
|
+
<path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm-2 14.5l-4-4 1.41-1.41L10 13.67l6.59-6.59L18 8.5l-8 8z" />
|
|
108
|
+
</svg>
|
|
109
|
+
),
|
|
110
|
+
danger: (
|
|
111
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
112
|
+
<path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z" />
|
|
113
|
+
</svg>
|
|
114
|
+
),
|
|
115
|
+
warning: (
|
|
116
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
117
|
+
<path d="M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" />
|
|
118
|
+
</svg>
|
|
119
|
+
),
|
|
120
|
+
info: (
|
|
121
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
122
|
+
<path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z" />
|
|
123
|
+
</svg>
|
|
124
|
+
),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// ── Position styles ───────────────────────────────────────────────────────────
|
|
128
|
+
|
|
129
|
+
const POSITION_STYLES: Record<ToastPosition, React.CSSProperties> = {
|
|
130
|
+
'top-right': { top: 16, right: 16, alignItems: 'flex-end' },
|
|
131
|
+
'top-left': { top: 16, left: 16, alignItems: 'flex-start' },
|
|
132
|
+
'top-center': { top: 16, left: '50%', transform: 'translateX(-50%)', alignItems: 'center' },
|
|
133
|
+
'bottom-right': { bottom: 16, right: 16, alignItems: 'flex-end' },
|
|
134
|
+
'bottom-left': { bottom: 16, left: 16, alignItems: 'flex-start' },
|
|
135
|
+
'bottom-center':{ bottom: 16, left: '50%', transform: 'translateX(-50%)', alignItems: 'center' },
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
function slideInStyle(position: ToastPosition, reduced: boolean): React.CSSProperties {
|
|
139
|
+
if (reduced) return {};
|
|
140
|
+
const isTop = position.startsWith('top');
|
|
141
|
+
return {
|
|
142
|
+
animation: `tkx-toast-slide-${isTop ? 'down' : 'up'} 220ms cubic-bezier(0.16,1,0.3,1) both`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ── Single toast card ─────────────────────────────────────────────────────────
|
|
147
|
+
|
|
148
|
+
interface ToastCardProps {
|
|
149
|
+
toast: ToastItem;
|
|
150
|
+
position: ToastPosition;
|
|
151
|
+
onDismiss: (id: string) => void;
|
|
152
|
+
reduced: boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function ToastCard({ toast, position, onDismiss, reduced }: ToastCardProps) {
|
|
156
|
+
const theme = useTheme();
|
|
157
|
+
const labelId = useId();
|
|
158
|
+
|
|
159
|
+
const variantColorMap: Record<ToastVariant, string> = {
|
|
160
|
+
default: theme.textMuted,
|
|
161
|
+
success: theme.success,
|
|
162
|
+
danger: theme.danger,
|
|
163
|
+
warning: theme.warning,
|
|
164
|
+
info: theme.info,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const variant = toast.variant ?? 'default';
|
|
168
|
+
const accentColor = variantColorMap[variant];
|
|
169
|
+
const isDanger = variant === 'danger';
|
|
170
|
+
const safeTitle = toast.title ? sanitizeString(toast.title) : undefined;
|
|
171
|
+
const safeDesc = toast.description ? sanitizeString(toast.description) : undefined;
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<div
|
|
175
|
+
role={isDanger ? 'alert' : 'status'}
|
|
176
|
+
aria-live={isDanger ? 'assertive' : 'polite'}
|
|
177
|
+
aria-atomic="true"
|
|
178
|
+
aria-labelledby={safeTitle ? labelId : undefined}
|
|
179
|
+
className={tkx('flex items-start gap-3 px-4 py-3 rounded-lg shadow-lg font-sans min-w-[280px] max-w-[380px]')}
|
|
180
|
+
style={{
|
|
181
|
+
backgroundColor: theme.surface,
|
|
182
|
+
border: `1px solid ${accentColor}55`,
|
|
183
|
+
boxShadow: `0 8px 24px ${theme.bg}cc`,
|
|
184
|
+
color: theme.text,
|
|
185
|
+
...slideInStyle(position, reduced),
|
|
186
|
+
}}
|
|
187
|
+
>
|
|
188
|
+
<span className={tkx('shrink-0 mt-[2px]')} style={{ color: accentColor }}>
|
|
189
|
+
{VARIANT_ICONS[variant]}
|
|
190
|
+
</span>
|
|
191
|
+
|
|
192
|
+
<div className={tkx('flex-1 min-w-0')}>
|
|
193
|
+
{safeTitle && (
|
|
194
|
+
<p id={labelId} className={tkx('m-0 font-semibold text-sm leading-snug')}>
|
|
195
|
+
{safeTitle}
|
|
196
|
+
</p>
|
|
197
|
+
)}
|
|
198
|
+
{safeDesc && (
|
|
199
|
+
<p className={tkx('m-0 text-xs mt-[2px] leading-relaxed')} style={{ color: theme.textMuted }}>
|
|
200
|
+
{safeDesc}
|
|
201
|
+
</p>
|
|
202
|
+
)}
|
|
203
|
+
{toast.action && (
|
|
204
|
+
<button
|
|
205
|
+
onClick={() => { toast.action!.onClick(); onDismiss(toast.id); }}
|
|
206
|
+
className={tkx('border-none bg-transparent cursor-pointer p-0 mt-2 text-xs font-semibold focus-visible:focus-ring')}
|
|
207
|
+
style={{ color: accentColor }}
|
|
208
|
+
>
|
|
209
|
+
{sanitizeString(toast.action.label)}
|
|
210
|
+
</button>
|
|
211
|
+
)}
|
|
212
|
+
</div>
|
|
213
|
+
|
|
214
|
+
<button
|
|
215
|
+
aria-label="Dismiss notification"
|
|
216
|
+
onClick={() => onDismiss(toast.id)}
|
|
217
|
+
className={tkx('bg-transparent border-none cursor-pointer rounded p-[2px] shrink-0 flex items-center justify-center focus-visible:focus-ring')}
|
|
218
|
+
style={{ color: theme.textMuted }}
|
|
219
|
+
>
|
|
220
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2.5} aria-hidden="true">
|
|
221
|
+
<line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
|
|
222
|
+
</svg>
|
|
223
|
+
</button>
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ── Provider ──────────────────────────────────────────────────────────────────
|
|
229
|
+
|
|
230
|
+
export function TkxToastProvider({ position = 'top-right' }: TkxToastProps) {
|
|
231
|
+
const [toasts, setToasts] = useState<ToastItem[]>([...visible]);
|
|
232
|
+
const reduced = useReducedMotion();
|
|
233
|
+
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
setToasts([...visible]);
|
|
236
|
+
const handler: Listener = (next) => setToasts([...next]);
|
|
237
|
+
listeners.add(handler);
|
|
238
|
+
return () => { listeners.delete(handler); };
|
|
239
|
+
}, []);
|
|
240
|
+
|
|
241
|
+
const isBottom = position.startsWith('bottom');
|
|
242
|
+
const posStyle = POSITION_STYLES[position];
|
|
243
|
+
|
|
244
|
+
// Inject keyframes once
|
|
245
|
+
const injectedRef = useRef(false);
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
if (injectedRef.current || typeof document === 'undefined') return;
|
|
248
|
+
injectedRef.current = true;
|
|
249
|
+
if (!document.getElementById('tkx-toast-kf')) {
|
|
250
|
+
const style = document.createElement('style');
|
|
251
|
+
style.id = 'tkx-toast-kf';
|
|
252
|
+
style.textContent = `
|
|
253
|
+
@keyframes tkx-toast-slide-down {
|
|
254
|
+
from { opacity: 0; transform: translateY(-16px); }
|
|
255
|
+
to { opacity: 1; transform: translateY(0); }
|
|
256
|
+
}
|
|
257
|
+
@keyframes tkx-toast-slide-up {
|
|
258
|
+
from { opacity: 0; transform: translateY(16px); }
|
|
259
|
+
to { opacity: 1; transform: translateY(0); }
|
|
260
|
+
}
|
|
261
|
+
`;
|
|
262
|
+
document.head.appendChild(style);
|
|
263
|
+
}
|
|
264
|
+
}, []);
|
|
265
|
+
|
|
266
|
+
if (typeof document === 'undefined') return null;
|
|
267
|
+
|
|
268
|
+
const ordered = isBottom ? [...toasts].reverse() : toasts;
|
|
269
|
+
|
|
270
|
+
return createPortal(
|
|
271
|
+
<div
|
|
272
|
+
aria-label="Notifications"
|
|
273
|
+
className={tkx('fixed z-[9999] flex flex-col gap-2 pointer-events-none')}
|
|
274
|
+
style={posStyle}
|
|
275
|
+
>
|
|
276
|
+
{ordered.map((t) => (
|
|
277
|
+
<div key={t.id} className={tkx('pointer-events-auto')}>
|
|
278
|
+
<ToastCard toast={t} position={position} onDismiss={removeToast} reduced={reduced} />
|
|
279
|
+
</div>
|
|
280
|
+
))}
|
|
281
|
+
</div>,
|
|
282
|
+
document.body,
|
|
283
|
+
);
|
|
284
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { forwardRef, useId, type ButtonHTMLAttributes } from 'react';
|
|
2
|
+
import { useTheme } from '../themes';
|
|
3
|
+
import { useReducedMotion } from '../hooks';
|
|
4
|
+
import { validateProps } from '../engine/security';
|
|
5
|
+
import { tkx, cx } from '../engine/tkx';
|
|
6
|
+
|
|
7
|
+
export type ToggleSize = 'sm' | 'md' | 'lg';
|
|
8
|
+
|
|
9
|
+
export interface TkxToggleProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onChange'> {
|
|
10
|
+
checked: boolean;
|
|
11
|
+
onChange: (checked: boolean) => void;
|
|
12
|
+
label: string;
|
|
13
|
+
size?: ToggleSize;
|
|
14
|
+
hideLabel?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const SIZES: Record<ToggleSize, { tw: number; th: number; td: number; gap: number }> = {
|
|
18
|
+
sm: { tw: 28, th: 16, td: 10, gap: 3 },
|
|
19
|
+
md: { tw: 40, th: 22, td: 14, gap: 4 },
|
|
20
|
+
lg: { tw: 52, th: 28, td: 18, gap: 5 },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const TkxToggle = forwardRef<HTMLButtonElement, TkxToggleProps>(
|
|
24
|
+
({ checked, onChange, label, size = 'md', hideLabel, disabled, className, style, ...rest }, ref) => {
|
|
25
|
+
const theme = useTheme();
|
|
26
|
+
const reducedMotion = useReducedMotion();
|
|
27
|
+
const id = useId();
|
|
28
|
+
|
|
29
|
+
validateProps(
|
|
30
|
+
{ label, checked },
|
|
31
|
+
{ label: { type: 'string', required: true }, checked: { type: 'boolean', required: true } },
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const { tw, th, td, gap } = SIZES[size];
|
|
35
|
+
const thumbOffset = checked ? tw - td - gap : gap;
|
|
36
|
+
const trackBg = checked ? theme.primary : theme.border;
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div
|
|
40
|
+
className={cx(tkx('inline-flex items-center gap-2', disabled ? 'opacity-50' : ''), className)}
|
|
41
|
+
style={style}
|
|
42
|
+
>
|
|
43
|
+
{!hideLabel && (
|
|
44
|
+
<label
|
|
45
|
+
htmlFor={id}
|
|
46
|
+
className={tkx('text-sm font-sans', disabled ? 'cursor-not-allowed' : 'cursor-pointer', 'select-none')}
|
|
47
|
+
style={{ color: theme.text }}
|
|
48
|
+
>
|
|
49
|
+
{label}
|
|
50
|
+
</label>
|
|
51
|
+
)}
|
|
52
|
+
<button
|
|
53
|
+
ref={ref}
|
|
54
|
+
id={id}
|
|
55
|
+
role="switch"
|
|
56
|
+
aria-checked={checked}
|
|
57
|
+
aria-label={hideLabel ? label : undefined}
|
|
58
|
+
disabled={disabled}
|
|
59
|
+
onClick={() => !disabled && onChange(!checked)}
|
|
60
|
+
onKeyDown={(e) => {
|
|
61
|
+
if ((e.key === 'Enter' || e.key === ' ') && !disabled) {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
onChange(!checked);
|
|
64
|
+
}
|
|
65
|
+
}}
|
|
66
|
+
className={cx(
|
|
67
|
+
tkx('relative border-none p-0 outline-none shrink-0 focus-visible:focus-ring',
|
|
68
|
+
disabled ? 'cursor-not-allowed' : 'cursor-pointer',
|
|
69
|
+
!reducedMotion && 'transition-colors duration-200',
|
|
70
|
+
),
|
|
71
|
+
)}
|
|
72
|
+
style={{ width: tw, height: th, borderRadius: th, backgroundColor: trackBg }}
|
|
73
|
+
{...rest}
|
|
74
|
+
>
|
|
75
|
+
<span
|
|
76
|
+
aria-hidden="true"
|
|
77
|
+
className={tkx('absolute rounded-full')}
|
|
78
|
+
style={{
|
|
79
|
+
top: '50%', left: thumbOffset,
|
|
80
|
+
width: td, height: td,
|
|
81
|
+
transform: 'translateY(-50%)',
|
|
82
|
+
backgroundColor: '#ffffff',
|
|
83
|
+
boxShadow: '0 1px 3px rgba(0,0,0,0.3)',
|
|
84
|
+
transition: reducedMotion ? 'none' : 'left 200ms ease',
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
</button>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
TkxToggle.displayName = 'TkxToggle';
|