@flikk/ui 1.0.0-beta.15 → 1.0.0-beta.17
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/README.md +52 -0
- package/dist/bg/1.jpg +0 -0
- package/dist/bg/10.jpg +0 -0
- package/dist/bg/11.jpg +0 -0
- package/dist/bg/14.jpg +0 -0
- package/dist/bg/15.jpg +0 -0
- package/dist/bg/16.jpg +0 -0
- package/dist/bg/17.jpg +0 -0
- package/dist/bg/18.jpg +0 -0
- package/dist/bg/19.jpg +0 -0
- package/dist/bg/2.jpg +0 -0
- package/dist/bg/20.jpg +0 -0
- package/dist/bg/21.jpg +0 -0
- package/dist/bg/22.jpg +0 -0
- package/dist/bg/23.jpg +0 -0
- package/dist/bg/24.jpg +0 -0
- package/dist/bg/3.jpg +0 -0
- package/dist/bg/4.jpg +0 -0
- package/dist/bg/5.jpg +0 -0
- package/dist/bg/6.jpg +0 -0
- package/dist/bg/7.jpg +0 -0
- package/dist/bg/8.jpg +0 -0
- package/dist/bg/9.jpg +0 -0
- package/dist/bg/bg/1.jpg +0 -0
- package/dist/bg/bg/10.jpg +0 -0
- package/dist/bg/bg/11.jpg +0 -0
- package/dist/bg/bg/14.jpg +0 -0
- package/dist/bg/bg/15.jpg +0 -0
- package/dist/bg/bg/16.jpg +0 -0
- package/dist/bg/bg/17.jpg +0 -0
- package/dist/bg/bg/18.jpg +0 -0
- package/dist/bg/bg/19.jpg +0 -0
- package/dist/bg/bg/2.jpg +0 -0
- package/dist/bg/bg/20.jpg +0 -0
- package/dist/bg/bg/21.jpg +0 -0
- package/dist/bg/bg/22.jpg +0 -0
- package/dist/bg/bg/23.jpg +0 -0
- package/dist/bg/bg/24.jpg +0 -0
- package/dist/bg/bg/3.jpg +0 -0
- package/dist/bg/bg/4.jpg +0 -0
- package/dist/bg/bg/5.jpg +0 -0
- package/dist/bg/bg/6.jpg +0 -0
- package/dist/bg/bg/7.jpg +0 -0
- package/dist/bg/bg/8.jpg +0 -0
- package/dist/bg/bg/9.jpg +0 -0
- package/dist/components/ai/StreamingResponse/AnimatedText.js +3 -3
- package/dist/components/ai/StreamingResponse/MarkdownRenderer.js +22 -22
- package/dist/components/ai/StreamingResponse/StreamingCursor.js +1 -1
- package/dist/components/ai/StreamingResponse/StreamingResponse.animations.js +10 -10
- package/dist/components/ai/StreamingResponse/StreamingResponse.js +3 -3
- package/dist/components/ai/StreamingResponse/WordAnimationContext.d.ts +1 -1
- package/dist/components/ai/StreamingResponse/WordAnimationContext.js +11 -11
- package/dist/components/ai/index.d.ts +0 -2
- package/dist/components/ai/index.js +0 -2
- package/dist/components/core/Button/Button.js +1 -1
- package/dist/components/core/Calendar/Calendar.js +2 -2
- package/dist/components/core/Calendar/Calendar.types.d.ts +1 -1
- package/dist/components/core/Card/Card.theme.js +2 -2
- package/dist/components/core/Progress/Progress.theme.js +2 -2
- package/dist/components/effects/GlassSurface/GlassSurface.js +7 -7
- package/dist/components/effects/GlassSurface/GlassSurface.types.d.ts +6 -0
- package/dist/components/effects/Neumorphic/InsetCircleButton.d.ts +2 -1
- package/dist/components/effects/Neumorphic/InsetCircleButton.js +2 -2
- package/dist/components/effects/Neumorphic/InsetPill.d.ts +2 -1
- package/dist/components/effects/Neumorphic/InsetPill.js +2 -2
- package/dist/components/effects/index.d.ts +2 -2
- package/dist/components/effects/index.js +1 -1
- package/dist/components/forms/Slider/Slider.js +10 -3
- package/dist/components/forms/Slider/Slider.theme.js +3 -3
- package/dist/components/forms/Switch/Switch.js +10 -2
- package/dist/components/forms/Switch/Switch.theme.js +2 -2
- package/dist/components/forms/index.d.ts +0 -3
- package/dist/components/forms/index.js +0 -2
- package/dist/index.js +1 -3
- package/dist/styles.css +1 -1
- package/package.json +5 -3
- package/dist/components/ai/ThinkingIndicator/ThinkingIndicator.animations.d.ts +0 -10
- package/dist/components/ai/ThinkingIndicator/ThinkingIndicator.animations.js +0 -47
- package/dist/components/ai/ThinkingIndicator/ThinkingIndicator.d.ts +0 -20
- package/dist/components/ai/ThinkingIndicator/ThinkingIndicator.js +0 -44
- package/dist/components/ai/ThinkingIndicator/ThinkingIndicator.theme.d.ts +0 -2
- package/dist/components/ai/ThinkingIndicator/ThinkingIndicator.theme.js +0 -20
- package/dist/components/ai/ThinkingIndicator/ThinkingIndicator.types.d.ts +0 -67
- package/dist/components/ai/ThinkingIndicator/index.d.ts +0 -3
- package/dist/components/forms/TransferList/TransferList.animations.d.ts +0 -10
- package/dist/components/forms/TransferList/TransferList.animations.js +0 -32
- package/dist/components/forms/TransferList/TransferList.d.ts +0 -28
- package/dist/components/forms/TransferList/TransferList.js +0 -199
- package/dist/components/forms/TransferList/TransferList.theme.d.ts +0 -6
- package/dist/components/forms/TransferList/TransferList.theme.js +0 -60
- package/dist/components/forms/TransferList/TransferList.types.d.ts +0 -101
- package/dist/components/forms/TransferList/index.d.ts +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flikk/ui",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.17",
|
|
4
4
|
"description": "A modern React component library built with TypeScript, Tailwind CSS v4, and Framer Motion. Follows the shadcn philosophy with complete className override support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
},
|
|
57
57
|
"./tailwind.preset.cjs": "./tailwind.preset.cjs",
|
|
58
58
|
"./shadcn-compat.css": "./src/shadcn-compat.css",
|
|
59
|
-
"./theme.css": "./src/theme-plugin.css"
|
|
59
|
+
"./theme.css": "./src/theme-plugin.css",
|
|
60
|
+
"./bg/*": "./dist/bg/*"
|
|
60
61
|
},
|
|
61
62
|
"files": [
|
|
62
63
|
"dist",
|
|
@@ -69,7 +70,8 @@
|
|
|
69
70
|
],
|
|
70
71
|
"scripts": {
|
|
71
72
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
72
|
-
"build": "rollup -c && npm run build:css",
|
|
73
|
+
"build": "rollup -c && npm run build:css && npm run build:assets",
|
|
74
|
+
"build:assets": "cp -r public/bg dist/bg",
|
|
73
75
|
"build:css": "tailwindcss -m -i ./src/tailwind-config.css -o ./dist/styles.css",
|
|
74
76
|
"analyze": "ANALYZE=true rollup -c && open stats.html",
|
|
75
77
|
"watch": "rollup -c -w",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Variants } from "motion/react";
|
|
2
|
-
/**
|
|
3
|
-
* Staggered bounce animation for dots
|
|
4
|
-
* Each dot animates with a slight delay creating a wave effect
|
|
5
|
-
*/
|
|
6
|
-
export declare const dotVariants: Variants;
|
|
7
|
-
/**
|
|
8
|
-
* Container fade in/out animation
|
|
9
|
-
*/
|
|
10
|
-
export declare const containerVariants: Variants;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Staggered bounce animation for dots
|
|
3
|
-
* Each dot animates with a slight delay creating a wave effect
|
|
4
|
-
*/
|
|
5
|
-
const dotVariants = {
|
|
6
|
-
initial: {
|
|
7
|
-
y: 0,
|
|
8
|
-
opacity: 0.5,
|
|
9
|
-
},
|
|
10
|
-
animate: (index) => ({
|
|
11
|
-
y: [0, -2, 0],
|
|
12
|
-
opacity: [0.5, 1, 0.5],
|
|
13
|
-
transition: {
|
|
14
|
-
duration: 0.6,
|
|
15
|
-
repeat: Infinity,
|
|
16
|
-
ease: "easeInOut",
|
|
17
|
-
delay: index * 0.15,
|
|
18
|
-
},
|
|
19
|
-
}),
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Container fade in/out animation
|
|
23
|
-
*/
|
|
24
|
-
const containerVariants = {
|
|
25
|
-
hidden: {
|
|
26
|
-
opacity: 0,
|
|
27
|
-
scale: 0.95,
|
|
28
|
-
},
|
|
29
|
-
visible: {
|
|
30
|
-
opacity: 1,
|
|
31
|
-
scale: 1,
|
|
32
|
-
transition: {
|
|
33
|
-
duration: 0.2,
|
|
34
|
-
ease: "easeOut",
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
exit: {
|
|
38
|
-
opacity: 0,
|
|
39
|
-
scale: 0.95,
|
|
40
|
-
transition: {
|
|
41
|
-
duration: 0.15,
|
|
42
|
-
ease: "easeIn",
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export { containerVariants, dotVariants };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { ThinkingIndicatorProps } from "./ThinkingIndicator.types";
|
|
3
|
-
/**
|
|
4
|
-
* ThinkingIndicator - Animated "AI is thinking..." state indicator
|
|
5
|
-
*
|
|
6
|
-
* Shows a 3-dot pulse animation to indicate the AI is processing.
|
|
7
|
-
* Respects prefers-reduced-motion for accessibility.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* <ThinkingIndicator visible={isLoading} />
|
|
12
|
-
*
|
|
13
|
-
* <ThinkingIndicator
|
|
14
|
-
* visible={isLoading}
|
|
15
|
-
* label="Claude is thinking"
|
|
16
|
-
* size="lg"
|
|
17
|
-
* />
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare const ThinkingIndicator: React.ForwardRefExoticComponent<ThinkingIndicatorProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import React__default from 'react';
|
|
3
|
-
import { useReducedMotion, AnimatePresence, motion } from 'motion/react';
|
|
4
|
-
import { thinkingIndicatorTheme } from './ThinkingIndicator.theme.js';
|
|
5
|
-
import { containerVariants, dotVariants } from './ThinkingIndicator.animations.js';
|
|
6
|
-
import { cn } from '../../../utils/cn.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* ThinkingIndicator - Animated "AI is thinking..." state indicator
|
|
10
|
-
*
|
|
11
|
-
* Shows a 3-dot pulse animation to indicate the AI is processing.
|
|
12
|
-
* Respects prefers-reduced-motion for accessibility.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```tsx
|
|
16
|
-
* <ThinkingIndicator visible={isLoading} />
|
|
17
|
-
*
|
|
18
|
-
* <ThinkingIndicator
|
|
19
|
-
* visible={isLoading}
|
|
20
|
-
* label="Claude is thinking"
|
|
21
|
-
* size="lg"
|
|
22
|
-
* />
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
const ThinkingIndicator = React__default.forwardRef(({ visible = true, label = "AI is thinking", showLabel = true, size = "md", icon, className, theme: customTheme = {}, ...props }, ref) => {
|
|
26
|
-
var _a;
|
|
27
|
-
const shouldReduceMotion = useReducedMotion();
|
|
28
|
-
// Merge theme
|
|
29
|
-
const sizeConfig = {
|
|
30
|
-
...thinkingIndicatorTheme.sizes[size],
|
|
31
|
-
...(_a = customTheme.sizes) === null || _a === void 0 ? void 0 : _a[size],
|
|
32
|
-
};
|
|
33
|
-
const baseStyle = customTheme.baseStyle || thinkingIndicatorTheme.baseStyle;
|
|
34
|
-
const labelStyle = customTheme.labelStyle || thinkingIndicatorTheme.labelStyle;
|
|
35
|
-
const dotsContainerStyle = customTheme.dotsContainerStyle ||
|
|
36
|
-
thinkingIndicatorTheme.dotsContainerStyle;
|
|
37
|
-
const dotStyle = customTheme.dotStyle || thinkingIndicatorTheme.dotStyle;
|
|
38
|
-
// Extract conflicting DOM props for motion.div compatibility
|
|
39
|
-
const { onAnimationStart, onAnimationEnd, onDrag, onDragStart, onDragEnd, ...motionSafeProps } = props;
|
|
40
|
-
return (jsx(AnimatePresence, { mode: "wait", children: visible && (jsxs(motion.div, { ref: ref, className: cn(baseStyle, sizeConfig.container, className), variants: shouldReduceMotion ? undefined : containerVariants, initial: shouldReduceMotion ? { opacity: 0 } : "hidden", animate: shouldReduceMotion ? { opacity: 1 } : "visible", exit: shouldReduceMotion ? { opacity: 0 } : "exit", ...motionSafeProps, children: [icon ? (jsx("span", { className: dotsContainerStyle, children: icon })) : (jsx("span", { className: dotsContainerStyle, children: [0, 1, 2].map((index) => (jsx(motion.span, { className: cn(dotStyle, sizeConfig.dot), variants: shouldReduceMotion ? undefined : dotVariants, initial: "initial", animate: "animate", custom: index, style: shouldReduceMotion ? { opacity: 0.7 } : undefined }, index))) })), showLabel && (jsx("span", { className: cn(labelStyle, sizeConfig.label), children: label }))] })) }));
|
|
41
|
-
});
|
|
42
|
-
ThinkingIndicator.displayName = "ThinkingIndicator";
|
|
43
|
-
|
|
44
|
-
export { ThinkingIndicator };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const thinkingIndicatorTheme = {
|
|
2
|
-
baseStyle: "inline-flex items-center gap-2",
|
|
3
|
-
labelStyle: "text-[var(--color-text-muted)] font-medium",
|
|
4
|
-
dotsContainerStyle: "inline-flex items-center gap-1",
|
|
5
|
-
dotStyle: "rounded-full bg-[var(--color-text-muted)]",
|
|
6
|
-
sizes: {
|
|
7
|
-
sm: {
|
|
8
|
-
container: "py-1",
|
|
9
|
-
dot: "size-1",
|
|
10
|
-
label: "text-sm",
|
|
11
|
-
},
|
|
12
|
-
md: {
|
|
13
|
-
container: "py-1",
|
|
14
|
-
dot: "size-1.5",
|
|
15
|
-
label: "text-base",
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { thinkingIndicatorTheme };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* ThinkingIndicator component props
|
|
4
|
-
*/
|
|
5
|
-
export interface ThinkingIndicatorProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
6
|
-
/**
|
|
7
|
-
* Whether the indicator is visible
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
visible?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Custom label text
|
|
13
|
-
* @default "AI is thinking"
|
|
14
|
-
*/
|
|
15
|
-
label?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Whether to show the label text
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
showLabel?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Size variant
|
|
23
|
-
* @default "md"
|
|
24
|
-
*/
|
|
25
|
-
size?: ThinkingIndicatorSize;
|
|
26
|
-
/**
|
|
27
|
-
* Custom icon to display instead of dots
|
|
28
|
-
*/
|
|
29
|
-
icon?: ReactNode;
|
|
30
|
-
/**
|
|
31
|
-
* Additional className for the container
|
|
32
|
-
*/
|
|
33
|
-
className?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Theme overrides
|
|
36
|
-
*/
|
|
37
|
-
theme?: ThinkingIndicatorThemeOverrides;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Size variants
|
|
41
|
-
*/
|
|
42
|
-
export type ThinkingIndicatorSize = "sm" | "md";
|
|
43
|
-
/**
|
|
44
|
-
* Theme configuration
|
|
45
|
-
*/
|
|
46
|
-
export interface ThinkingIndicatorTheme {
|
|
47
|
-
baseStyle: string;
|
|
48
|
-
labelStyle: string;
|
|
49
|
-
dotsContainerStyle: string;
|
|
50
|
-
dotStyle: string;
|
|
51
|
-
sizes: Record<ThinkingIndicatorSize, ThinkingIndicatorSizeConfig>;
|
|
52
|
-
}
|
|
53
|
-
export interface ThinkingIndicatorSizeConfig {
|
|
54
|
-
container: string;
|
|
55
|
-
dot: string;
|
|
56
|
-
label: string;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Theme overrides
|
|
60
|
-
*/
|
|
61
|
-
export interface ThinkingIndicatorThemeOverrides {
|
|
62
|
-
baseStyle?: string;
|
|
63
|
-
labelStyle?: string;
|
|
64
|
-
dotsContainerStyle?: string;
|
|
65
|
-
dotStyle?: string;
|
|
66
|
-
sizes?: Partial<Record<ThinkingIndicatorSize, Partial<ThinkingIndicatorSizeConfig>>>;
|
|
67
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { ThinkingIndicator } from "./ThinkingIndicator";
|
|
2
|
-
export { thinkingIndicatorTheme } from "./ThinkingIndicator.theme";
|
|
3
|
-
export type { ThinkingIndicatorProps, ThinkingIndicatorSize, ThinkingIndicatorTheme, ThinkingIndicatorThemeOverrides, ThinkingIndicatorSizeConfig, } from "./ThinkingIndicator.types";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Variants } from "motion/react";
|
|
2
|
-
/**
|
|
3
|
-
* Get animation variants for items entering/exiting lists.
|
|
4
|
-
* Items slide and fade in from the transfer direction.
|
|
5
|
-
*/
|
|
6
|
-
export declare const getItemVariants: (shouldReduceMotion: boolean | null) => Variants | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Get staggered list animation variants for initial render
|
|
9
|
-
*/
|
|
10
|
-
export declare const getListVariants: (shouldReduceMotion: boolean | null) => Variants | undefined;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get animation variants for items entering/exiting lists.
|
|
3
|
-
* Items slide and fade in from the transfer direction.
|
|
4
|
-
*/
|
|
5
|
-
const getItemVariants = (shouldReduceMotion) => (shouldReduceMotion !== null && shouldReduceMotion !== void 0 ? shouldReduceMotion : false)
|
|
6
|
-
? undefined
|
|
7
|
-
: {
|
|
8
|
-
initial: {
|
|
9
|
-
opacity: 0,
|
|
10
|
-
x: 0,
|
|
11
|
-
height: 0,
|
|
12
|
-
},
|
|
13
|
-
animate: {
|
|
14
|
-
opacity: 1,
|
|
15
|
-
x: 0,
|
|
16
|
-
height: "auto",
|
|
17
|
-
transition: {
|
|
18
|
-
duration: 0.2,
|
|
19
|
-
ease: "easeOut",
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
exit: {
|
|
23
|
-
opacity: 0,
|
|
24
|
-
height: 0,
|
|
25
|
-
transition: {
|
|
26
|
-
duration: 0.15,
|
|
27
|
-
ease: "easeIn",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { getItemVariants };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { TransferListProps } from "./TransferList.types";
|
|
3
|
-
/**
|
|
4
|
-
* TransferList is a dual-list picker for moving items between a source
|
|
5
|
-
* (available) list and a target (selected) list. Commonly used in
|
|
6
|
-
* admin/permissions interfaces for assigning roles, features, or users.
|
|
7
|
-
*
|
|
8
|
-
* Supports controlled (value + onChange) and uncontrolled (defaultValue)
|
|
9
|
-
* patterns, optional search filtering, multi-select with checkboxes,
|
|
10
|
-
* custom item renderers, disabled items, and animated transitions.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* <TransferList
|
|
15
|
-
* items={[
|
|
16
|
-
* { id: '1', label: 'Read' },
|
|
17
|
-
* { id: '2', label: 'Write' },
|
|
18
|
-
* { id: '3', label: 'Delete' },
|
|
19
|
-
* ]}
|
|
20
|
-
* value={selectedPermissions}
|
|
21
|
-
* onChange={setSelectedPermissions}
|
|
22
|
-
* sourceTitle="Available Permissions"
|
|
23
|
-
* targetTitle="Assigned Permissions"
|
|
24
|
-
* searchable
|
|
25
|
-
* />
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare const TransferList: React.ForwardRefExoticComponent<TransferListProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import React__default, { useState, useMemo, useCallback } from 'react';
|
|
3
|
-
import { useReducedMotion, AnimatePresence, motion } from 'motion/react';
|
|
4
|
-
import { ChevronDoubleRightIcon, ChevronRightIcon, ChevronLeftIcon, ChevronDoubleLeftIcon, MagnifyingGlassIcon } from '@heroicons/react/24/outline';
|
|
5
|
-
import { cn } from '../../../utils/cn.js';
|
|
6
|
-
import { transferListTheme } from './TransferList.theme.js';
|
|
7
|
-
import { getItemVariants } from './TransferList.animations.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* TransferList is a dual-list picker for moving items between a source
|
|
11
|
-
* (available) list and a target (selected) list. Commonly used in
|
|
12
|
-
* admin/permissions interfaces for assigning roles, features, or users.
|
|
13
|
-
*
|
|
14
|
-
* Supports controlled (value + onChange) and uncontrolled (defaultValue)
|
|
15
|
-
* patterns, optional search filtering, multi-select with checkboxes,
|
|
16
|
-
* custom item renderers, disabled items, and animated transitions.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* <TransferList
|
|
21
|
-
* items={[
|
|
22
|
-
* { id: '1', label: 'Read' },
|
|
23
|
-
* { id: '2', label: 'Write' },
|
|
24
|
-
* { id: '3', label: 'Delete' },
|
|
25
|
-
* ]}
|
|
26
|
-
* value={selectedPermissions}
|
|
27
|
-
* onChange={setSelectedPermissions}
|
|
28
|
-
* sourceTitle="Available Permissions"
|
|
29
|
-
* targetTitle="Assigned Permissions"
|
|
30
|
-
* searchable
|
|
31
|
-
* />
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
const TransferList = React__default.forwardRef(({ items, value: controlledValue, defaultValue = [], onChange, sourceTitle = "Available", targetTitle = "Selected", searchable = false, size = "md", renderItem, className, ...restProps }, ref) => {
|
|
35
|
-
const shouldReduceMotion = useReducedMotion();
|
|
36
|
-
const itemVariants = getItemVariants(shouldReduceMotion);
|
|
37
|
-
// Controlled vs uncontrolled state for target IDs
|
|
38
|
-
const isControlled = controlledValue !== undefined;
|
|
39
|
-
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
40
|
-
const targetIds = isControlled ? controlledValue : internalValue;
|
|
41
|
-
// Selection state for checkboxes in each list
|
|
42
|
-
const [sourceSelected, setSourceSelected] = useState(new Set());
|
|
43
|
-
const [targetSelected, setTargetSelected] = useState(new Set());
|
|
44
|
-
// Search/filter state
|
|
45
|
-
const [sourceSearch, setSourceSearch] = useState("");
|
|
46
|
-
const [targetSearch, setTargetSearch] = useState("");
|
|
47
|
-
const theme = transferListTheme;
|
|
48
|
-
const sizeStyles = theme.sizes[size];
|
|
49
|
-
// Build a lookup map for items by ID
|
|
50
|
-
const itemMap = useMemo(() => {
|
|
51
|
-
const map = new Map();
|
|
52
|
-
for (const item of items) {
|
|
53
|
-
map.set(item.id, item);
|
|
54
|
-
}
|
|
55
|
-
return map;
|
|
56
|
-
}, [items]);
|
|
57
|
-
// Derive target IDs set for fast lookup
|
|
58
|
-
const targetIdSet = useMemo(() => new Set(targetIds), [targetIds]);
|
|
59
|
-
// Split items into source and target lists
|
|
60
|
-
const sourceItems = useMemo(() => items.filter((item) => !targetIdSet.has(item.id)), [items, targetIdSet]);
|
|
61
|
-
const targetItems = useMemo(() => targetIds
|
|
62
|
-
.map((id) => itemMap.get(id))
|
|
63
|
-
.filter((item) => item !== undefined), [targetIds, itemMap]);
|
|
64
|
-
// Filter items by search query
|
|
65
|
-
const filteredSourceItems = useMemo(() => {
|
|
66
|
-
if (!sourceSearch.trim())
|
|
67
|
-
return sourceItems;
|
|
68
|
-
const query = sourceSearch.toLowerCase();
|
|
69
|
-
return sourceItems.filter((item) => item.label.toLowerCase().includes(query));
|
|
70
|
-
}, [sourceItems, sourceSearch]);
|
|
71
|
-
const filteredTargetItems = useMemo(() => {
|
|
72
|
-
if (!targetSearch.trim())
|
|
73
|
-
return targetItems;
|
|
74
|
-
const query = targetSearch.toLowerCase();
|
|
75
|
-
return targetItems.filter((item) => item.label.toLowerCase().includes(query));
|
|
76
|
-
}, [targetItems, targetSearch]);
|
|
77
|
-
// Update the target list value
|
|
78
|
-
const updateValue = useCallback((newTargetIds) => {
|
|
79
|
-
if (!isControlled) {
|
|
80
|
-
setInternalValue(newTargetIds);
|
|
81
|
-
}
|
|
82
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(newTargetIds);
|
|
83
|
-
}, [isControlled, onChange]);
|
|
84
|
-
// Transfer selected source items to target
|
|
85
|
-
const handleMoveToTarget = useCallback(() => {
|
|
86
|
-
const idsToMove = Array.from(sourceSelected).filter((id) => {
|
|
87
|
-
const item = itemMap.get(id);
|
|
88
|
-
return item && !item.disabled;
|
|
89
|
-
});
|
|
90
|
-
if (idsToMove.length === 0)
|
|
91
|
-
return;
|
|
92
|
-
const newTargetIds = [...targetIds, ...idsToMove];
|
|
93
|
-
updateValue(newTargetIds);
|
|
94
|
-
setSourceSelected(new Set());
|
|
95
|
-
}, [sourceSelected, targetIds, updateValue, itemMap]);
|
|
96
|
-
// Transfer selected target items back to source
|
|
97
|
-
const handleMoveToSource = useCallback(() => {
|
|
98
|
-
const idsToMove = new Set(Array.from(targetSelected).filter((id) => {
|
|
99
|
-
const item = itemMap.get(id);
|
|
100
|
-
return item && !item.disabled;
|
|
101
|
-
}));
|
|
102
|
-
if (idsToMove.size === 0)
|
|
103
|
-
return;
|
|
104
|
-
const newTargetIds = targetIds.filter((id) => !idsToMove.has(id));
|
|
105
|
-
updateValue(newTargetIds);
|
|
106
|
-
setTargetSelected(new Set());
|
|
107
|
-
}, [targetSelected, targetIds, updateValue, itemMap]);
|
|
108
|
-
// Move all non-disabled source items to target
|
|
109
|
-
const handleMoveAllToTarget = useCallback(() => {
|
|
110
|
-
const nonDisabledSourceIds = sourceItems
|
|
111
|
-
.filter((item) => !item.disabled)
|
|
112
|
-
.map((item) => item.id);
|
|
113
|
-
if (nonDisabledSourceIds.length === 0)
|
|
114
|
-
return;
|
|
115
|
-
const newTargetIds = [...targetIds, ...nonDisabledSourceIds];
|
|
116
|
-
updateValue(newTargetIds);
|
|
117
|
-
setSourceSelected(new Set());
|
|
118
|
-
}, [sourceItems, targetIds, updateValue]);
|
|
119
|
-
// Move all non-disabled target items back to source
|
|
120
|
-
const handleMoveAllToSource = useCallback(() => {
|
|
121
|
-
const disabledTargetIds = targetItems
|
|
122
|
-
.filter((item) => item.disabled)
|
|
123
|
-
.map((item) => item.id);
|
|
124
|
-
updateValue(disabledTargetIds);
|
|
125
|
-
setTargetSelected(new Set());
|
|
126
|
-
}, [targetItems, updateValue]);
|
|
127
|
-
// Toggle an individual item's selection
|
|
128
|
-
const toggleSelection = useCallback((id, selected, setSelected) => {
|
|
129
|
-
const item = itemMap.get(id);
|
|
130
|
-
if (item === null || item === void 0 ? void 0 : item.disabled)
|
|
131
|
-
return;
|
|
132
|
-
const next = new Set(selected);
|
|
133
|
-
if (next.has(id)) {
|
|
134
|
-
next.delete(id);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
next.add(id);
|
|
138
|
-
}
|
|
139
|
-
setSelected(next);
|
|
140
|
-
}, [itemMap]);
|
|
141
|
-
// Toggle select-all for a given list
|
|
142
|
-
const toggleSelectAll = useCallback((listItems, selected, setSelected) => {
|
|
143
|
-
const selectableItems = listItems.filter((item) => !item.disabled);
|
|
144
|
-
const allSelected = selectableItems.every((item) => selected.has(item.id));
|
|
145
|
-
if (allSelected) {
|
|
146
|
-
setSelected(new Set());
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
setSelected(new Set(selectableItems.map((item) => item.id)));
|
|
150
|
-
}
|
|
151
|
-
}, []);
|
|
152
|
-
// Compute select-all checkbox states
|
|
153
|
-
const sourceSelectableItems = filteredSourceItems.filter((i) => !i.disabled);
|
|
154
|
-
const targetSelectableItems = filteredTargetItems.filter((i) => !i.disabled);
|
|
155
|
-
const sourceAllSelected = sourceSelectableItems.length > 0 &&
|
|
156
|
-
sourceSelectableItems.every((item) => sourceSelected.has(item.id));
|
|
157
|
-
const sourceIndeterminate = !sourceAllSelected &&
|
|
158
|
-
sourceSelectableItems.some((item) => sourceSelected.has(item.id));
|
|
159
|
-
const targetAllSelected = targetSelectableItems.length > 0 &&
|
|
160
|
-
targetSelectableItems.every((item) => targetSelected.has(item.id));
|
|
161
|
-
const targetIndeterminate = !targetAllSelected &&
|
|
162
|
-
targetSelectableItems.some((item) => targetSelected.has(item.id));
|
|
163
|
-
// Icon size classes per size variant
|
|
164
|
-
const iconSize = size === "sm" ? "w-3.5 h-3.5" : size === "lg" ? "w-5 h-5" : "w-4 h-4";
|
|
165
|
-
const searchIconSize = size === "sm" ? "w-3.5 h-3.5" : size === "lg" ? "w-5 h-5" : "w-4 h-4";
|
|
166
|
-
const searchIconPosition = size === "sm" ? "left-2" : size === "lg" ? "left-3" : "left-2.5";
|
|
167
|
-
// Checkbox size
|
|
168
|
-
const checkboxSize = size === "sm" ? "w-3.5 h-3.5" : size === "lg" ? "w-5 h-5" : "w-4 h-4";
|
|
169
|
-
// Render a single list panel
|
|
170
|
-
const renderPanel = (title, listItems, filteredItems, selected, setSelected, search, setSearch, allSelected, indeterminate, panelAriaLabel) => {
|
|
171
|
-
const selectableCount = filteredItems.filter((i) => !i.disabled).length;
|
|
172
|
-
const selectedCount = Array.from(selected).filter((id) => filteredItems.some((item) => item.id === id)).length;
|
|
173
|
-
return (jsxs("div", { className: cn(theme.panelStyle, sizeStyles.panel), role: "listbox", "aria-label": panelAriaLabel, "aria-multiselectable": "true", children: [jsxs("div", { className: theme.headerStyle, children: [jsxs("div", { className: "flex items-center gap-2", children: [jsx("input", { type: "checkbox", checked: allSelected, ref: (el) => {
|
|
174
|
-
if (el)
|
|
175
|
-
el.indeterminate = indeterminate;
|
|
176
|
-
}, onChange: () => toggleSelectAll(filteredItems, selected, setSelected), disabled: selectableCount === 0, className: cn(checkboxSize, "rounded-[calc(var(--radius-base)*0.5)] border-2 border-[var(--color-border)] accent-[var(--color-primary)] cursor-pointer disabled:cursor-not-allowed disabled:opacity-50"), "aria-label": `Select all ${title}` }), jsx("span", { className: cn(theme.titleStyle, size === "sm" ? "text-sm" : "text-base"), children: title })] }), jsxs("span", { className: cn(theme.countStyle, size === "sm" ? "text-sm" : "text-sm"), children: [selectedCount > 0 ? `${selectedCount}/` : "", listItems.length] })] }), searchable && (jsxs("div", { className: theme.searchWrapperStyle, children: [jsx(MagnifyingGlassIcon, { className: cn(searchIconSize, "absolute text-[var(--color-text-placeholder)] pointer-events-none", searchIconPosition) }), jsx("input", { type: "text", value: search, onChange: (e) => setSearch(e.target.value), placeholder: "Search...", className: cn(theme.searchInputStyle, sizeStyles.searchInput), "aria-label": `Search ${title}` })] })), jsxs("div", { className: theme.listStyle, children: [jsx(AnimatePresence, { mode: "popLayout", initial: false, children: filteredItems.map((item) => {
|
|
177
|
-
const isSelected = selected.has(item.id);
|
|
178
|
-
const isDisabled = item.disabled === true;
|
|
179
|
-
const itemContent = (jsxs(Fragment, { children: [jsx("input", { type: "checkbox", checked: isSelected, onChange: () => toggleSelection(item.id, selected, setSelected), disabled: isDisabled, className: cn(checkboxSize, "rounded-[calc(var(--radius-base)*0.5)] border-2 border-[var(--color-border)] accent-[var(--color-primary)] cursor-pointer flex-shrink-0", isDisabled && "cursor-not-allowed"), tabIndex: -1, "aria-hidden": "true" }), jsx("span", { className: "truncate flex-1", children: renderItem ? renderItem(item) : item.label })] }));
|
|
180
|
-
const itemProps = {
|
|
181
|
-
key: item.id,
|
|
182
|
-
role: "option",
|
|
183
|
-
"aria-selected": isSelected,
|
|
184
|
-
"aria-disabled": isDisabled,
|
|
185
|
-
"data-selected": isSelected ? "true" : "false",
|
|
186
|
-
onClick: () => toggleSelection(item.id, selected, setSelected),
|
|
187
|
-
className: cn(theme.itemStyle, sizeStyles.item, isDisabled && theme.itemDisabledStyle),
|
|
188
|
-
};
|
|
189
|
-
if (itemVariants) {
|
|
190
|
-
return (jsx(motion.div, { ...itemProps, layout: true, variants: itemVariants, initial: "initial", animate: "animate", exit: "exit", children: itemContent }));
|
|
191
|
-
}
|
|
192
|
-
return jsx("div", { ...itemProps, children: itemContent });
|
|
193
|
-
}) }), filteredItems.length === 0 && (jsx("div", { className: cn("flex items-center justify-center text-[var(--color-text-muted)]", size === "sm" ? "py-4 text-sm" : size === "lg" ? "py-8 text-base" : "py-6 text-sm"), children: search.trim() ? "No matches found" : "No items" }))] })] }));
|
|
194
|
-
};
|
|
195
|
-
return (jsxs("div", { ref: ref, className: cn(theme.baseStyle, className), ...restProps, children: [renderPanel(sourceTitle, sourceItems, filteredSourceItems, sourceSelected, setSourceSelected, sourceSearch, setSourceSearch, sourceAllSelected, sourceIndeterminate, sourceTitle), jsxs("div", { className: theme.actionsStyle, children: [jsx("button", { type: "button", onClick: handleMoveAllToTarget, disabled: sourceItems.filter((i) => !i.disabled).length === 0, className: cn(theme.buttonStyle, sizeStyles.button), "aria-label": "Move all to target", children: jsx(ChevronDoubleRightIcon, { className: iconSize }) }), jsx("button", { type: "button", onClick: handleMoveToTarget, disabled: sourceSelected.size === 0, className: cn(theme.buttonStyle, sizeStyles.button), "aria-label": "Move selected to target", children: jsx(ChevronRightIcon, { className: iconSize }) }), jsx("button", { type: "button", onClick: handleMoveToSource, disabled: targetSelected.size === 0, className: cn(theme.buttonStyle, sizeStyles.button), "aria-label": "Move selected to source", children: jsx(ChevronLeftIcon, { className: iconSize }) }), jsx("button", { type: "button", onClick: handleMoveAllToSource, disabled: targetItems.filter((i) => !i.disabled).length === 0, className: cn(theme.buttonStyle, sizeStyles.button), "aria-label": "Move all to source", children: jsx(ChevronDoubleLeftIcon, { className: iconSize }) })] }), renderPanel(targetTitle, targetItems, filteredTargetItems, targetSelected, setTargetSelected, targetSearch, setTargetSearch, targetAllSelected, targetIndeterminate, targetTitle)] }));
|
|
196
|
-
});
|
|
197
|
-
TransferList.displayName = "TransferList";
|
|
198
|
-
|
|
199
|
-
export { TransferList };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default theme configuration for the TransferList component.
|
|
3
|
-
* Uses CSS variables from global.scss for consistent theming.
|
|
4
|
-
*/
|
|
5
|
-
const transferListTheme = {
|
|
6
|
-
// Root container - horizontal layout with centered actions
|
|
7
|
-
baseStyle: "flex items-stretch gap-0",
|
|
8
|
-
// Individual list panel
|
|
9
|
-
panelStyle: "flex flex-col border border-[var(--color-border)] rounded-[var(--form-radius)] bg-[var(--color-surface)] overflow-hidden",
|
|
10
|
-
// Panel header with title and count
|
|
11
|
-
headerStyle: "flex items-center justify-between px-3 py-2 border-b border-[var(--color-border)] bg-[var(--color-background-secondary)]",
|
|
12
|
-
// Title text
|
|
13
|
-
titleStyle: "font-medium text-[var(--color-text-primary)]",
|
|
14
|
-
// Item count badge
|
|
15
|
-
countStyle: "text-[var(--color-text-muted)] tabular-nums",
|
|
16
|
-
// Search input wrapper
|
|
17
|
-
searchWrapperStyle: "relative flex items-center border-b border-[var(--color-border)]",
|
|
18
|
-
// Search input
|
|
19
|
-
searchInputStyle: "w-full bg-transparent text-[var(--color-text-primary)] placeholder:text-[var(--color-text-placeholder)] focus:outline-none",
|
|
20
|
-
// Scrollable list container
|
|
21
|
-
listStyle: "flex-1 overflow-y-auto",
|
|
22
|
-
// Individual item row
|
|
23
|
-
itemStyle: "flex items-center gap-2 cursor-pointer transition-colors duration-150 " +
|
|
24
|
-
"hover:bg-[var(--color-background-secondary)] " +
|
|
25
|
-
"data-[selected=true]:bg-[var(--color-primary-50)]",
|
|
26
|
-
// Disabled item overlay
|
|
27
|
-
itemDisabledStyle: "opacity-50 cursor-not-allowed hover:bg-transparent",
|
|
28
|
-
// Actions column with transfer buttons
|
|
29
|
-
actionsStyle: "flex flex-col items-center justify-center gap-1 px-2",
|
|
30
|
-
// Transfer button
|
|
31
|
-
buttonStyle: "inline-flex items-center justify-center rounded-[var(--form-radius)] border border-[var(--color-border)] " +
|
|
32
|
-
"bg-[var(--color-surface)] text-[var(--color-text-secondary)] " +
|
|
33
|
-
"transition-all duration-150 " +
|
|
34
|
-
"hover:bg-[var(--color-background-secondary)] hover:text-[var(--color-text-primary)] hover:border-[var(--color-border-secondary)] " +
|
|
35
|
-
"focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-primary)] focus-visible:ring-offset-1 " +
|
|
36
|
-
"disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-[var(--color-surface)] disabled:hover:text-[var(--color-text-secondary)] disabled:hover:border-[var(--color-border)]",
|
|
37
|
-
// Size variants
|
|
38
|
-
sizes: {
|
|
39
|
-
sm: {
|
|
40
|
-
panel: "w-56 h-64",
|
|
41
|
-
item: "px-2 py-1 text-sm gap-1.5",
|
|
42
|
-
button: "p-1",
|
|
43
|
-
searchInput: "px-2 py-1.5 text-sm pl-7",
|
|
44
|
-
},
|
|
45
|
-
md: {
|
|
46
|
-
panel: "w-72 h-80",
|
|
47
|
-
item: "px-3 py-1.5 text-base gap-2",
|
|
48
|
-
button: "p-1.5",
|
|
49
|
-
searchInput: "px-3 py-2 text-base pl-8",
|
|
50
|
-
},
|
|
51
|
-
lg: {
|
|
52
|
-
panel: "w-80 h-96",
|
|
53
|
-
item: "px-3 py-2 text-lg gap-2.5",
|
|
54
|
-
button: "p-2",
|
|
55
|
-
searchInput: "px-3 py-2.5 text-lg pl-9",
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export { transferListTheme };
|