@epam/ai-dial-ui-kit 0.4.0-rc.27 → 0.4.0-rc.28

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.
@@ -0,0 +1,86 @@
1
+ import { FlexibleActionsDirection } from '../types/flexible-actions';
2
+ interface UseFlexibleActionsOptions<T> {
3
+ actions: T[];
4
+ direction?: FlexibleActionsDirection;
5
+ moreButtonWidth?: number;
6
+ actionsGap?: number;
7
+ containerPadding?: number;
8
+ dependencies?: unknown[];
9
+ }
10
+ /**
11
+ * A responsive layout hook that automatically determines how many action buttons
12
+ * can fit within a container and moves overflowing ones into a hidden list (e.g. a dropdown).
13
+ *
14
+ * It measures each action's width and dynamically recalculates visible and hidden actions
15
+ * whenever the container resizes or dependencies change.
16
+ *
17
+ * This hook is reusable for toolbars or action strips that can have:
18
+ * - a **left fixed section** (e.g., selection info),
19
+ * - a **right fixed section** (e.g., metadata or pagination),
20
+ * - and a **flexible central section** where actions may overflow.
21
+ *
22
+ * @template T - Type of the action item. Each action must have a unique `key` property.
23
+ *
24
+ * @param {Object} options - Hook configuration options.
25
+ * @param {T[]} options.actions - Array of all available actions.
26
+ * @param {FlexibleActionsDirection} [options.direction=FlexibleActionsDirection.Normal] -
27
+ * Defines the fill direction:
28
+ * - `Normal`: Fills actions from left to right.
29
+ * - `Reverse`: Fills actions from right to left (useful when the "More" button is on the right).
30
+ * @param {number} [options.moreButtonWidth=BASE_ICON_SIZE] - Reserved width for the “more” or overflow button.
31
+ * @param {number} [options.actionsGap=8] - Horizontal gap (in pixels) between action buttons.
32
+ * @param {number} [options.containerPadding=8] - Horizontal padding (in pixels) inside the container.
33
+ * @param {unknown[]} [options.dependencies=[]] - Dependency array to trigger recalculation when external layout-affecting
34
+ * values (like screen size or visibility) change.
35
+ *
36
+ * @returns Result object containing the calculated visible and hidden actions and all relevant refs.
37
+ *
38
+ * @property {T[]} visibleActions - Actions that currently fit into the available width.
39
+ * @property {T[]} hiddenActions - Actions that do not fit and should be rendered inside a dropdown.
40
+ *
41
+ * @property {Object} refs - A set of refs used for layout measurement.
42
+ * @property {React.RefObject<HTMLDivElement>} refs.containerRef - Ref for the outer container. Must wrap the entire toolbar area.
43
+ * @property {React.RefObject<HTMLDivElement>} refs.measureRef - Ref for a hidden measurement container (used to measure action widths).
44
+ * @property {React.RefObject<HTMLDivElement>} refs.leftSectionRef - Ref for the left fixed section (optional).
45
+ * @property {React.RefObject<HTMLDivElement>} refs.rightSectionRef - Ref for the right fixed section (optional).
46
+ *
47
+ * @example
48
+ * // Example usage inside a toolbar component:
49
+ * const { visibleActions, hiddenActions, refs } = useFlexibleActions({
50
+ * actions,
51
+ * direction: FlexibleActionsDirection.Reverse,
52
+ * dependencies: [isMobile],
53
+ * });
54
+ *
55
+ * return (
56
+ * <>
57
+ * <div ref={refs.measureRef} className="invisible absolute top-0 left-0 flex gap-2">
58
+ * {actions.map(a => <ActionButton key={a.key} {...a} />)}
59
+ * </div>
60
+ *
61
+ * <div ref={refs.containerRef} className="flex justify-between items-center">
62
+ * <div ref={refs.leftSectionRef}>Left section</div>
63
+ *
64
+ * <div className="flex gap-2 items-center">
65
+ * {hiddenActions.length > 0 && <MoreMenu items={hiddenActions} />}
66
+ * {visibleActions.map(a => <ActionButton key={a.key} {...a} />)}
67
+ * </div>
68
+ *
69
+ * <div ref={refs.rightSectionRef}>Right section</div>
70
+ * </div>
71
+ * </>
72
+ * );
73
+ */
74
+ export declare function useFlexibleActions<T extends {
75
+ key: string;
76
+ }>({ actions, direction, moreButtonWidth, actionsGap, containerPadding, dependencies, }: UseFlexibleActionsOptions<T>): {
77
+ visibleActions: T[];
78
+ hiddenActions: T[];
79
+ refs: {
80
+ containerRef: import('react').RefObject<HTMLDivElement | null>;
81
+ measureRef: import('react').RefObject<HTMLDivElement | null>;
82
+ leftSectionRef: import('react').RefObject<HTMLDivElement | null>;
83
+ rightSectionRef: import('react').RefObject<HTMLDivElement | null>;
84
+ };
85
+ };
86
+ export {};
@@ -63,6 +63,7 @@ export { TabOrientation } from './types/tab';
63
63
  export type { DialBreadcrumbPathItem } from './models/breadcrumb';
64
64
  export { FormItemOrientation } from './types/form-item';
65
65
  export { DialFileManagerTabs, DialFileManagerActions, } from './types/file-manager';
66
+ export { FlexibleActionsDirection } from './types/flexible-actions';
66
67
  export { useDialFileManagerTabs } from './components/FileManager/hooks/use-file-manager-tabs';
67
68
  export { FileManagerProvider } from './components/FileManager/FileManagerProvider';
68
69
  export { useFileManagerContext } from './components/FileManager/hooks/use-file-manager-context';
@@ -0,0 +1,4 @@
1
+ export declare enum FlexibleActionsDirection {
2
+ Normal = "normal",
3
+ Reverse = "reverse"
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epam/ai-dial-ui-kit",
3
- "version": "0.4.0-rc.27",
3
+ "version": "0.4.0-rc.28",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "A modern UI kit for building AI DIAL interfaces with React",