@hamsterbase/ui 0.2.0 → 0.3.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/dist/components/Select/Select.d.ts +17 -0
- package/dist/components/Select/layout.d.ts +39 -0
- package/dist/components/Select/styles.d.ts +26 -0
- package/dist/components/Select/useScrollAffordance.d.ts +12 -0
- package/dist/components/Select/useSelectValue.d.ts +15 -0
- package/dist/components/Tooltip/Tooltip.d.ts +10 -0
- package/dist/components/Tooltip/coordinator.d.ts +79 -0
- package/dist/components/Tooltip/layout.d.ts +28 -0
- package/dist/components/Tooltip/styles.d.ts +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +956 -9
- package/dist/styles.css +480 -1
- package/dist/utils/css.d.ts +6 -0
- package/docs/Select.md +20 -0
- package/docs/Tooltip.md +20 -0
- package/docs/index.md +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactNode } from 'react';
|
|
2
|
+
export interface SelectOption {
|
|
3
|
+
readonly value: string;
|
|
4
|
+
readonly label: string;
|
|
5
|
+
readonly icon?: ReactNode;
|
|
6
|
+
readonly disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface SelectProps extends Omit<ComponentPropsWithoutRef<'button'>, 'value' | 'defaultValue' | 'onChange' | 'children' | 'size'> {
|
|
9
|
+
readonly options: readonly SelectOption[];
|
|
10
|
+
readonly value?: string;
|
|
11
|
+
readonly defaultValue?: string;
|
|
12
|
+
readonly onValueChange?: (value: string) => void;
|
|
13
|
+
readonly size?: 'small' | 'default';
|
|
14
|
+
readonly placeholder?: string;
|
|
15
|
+
readonly name?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function Select({ options, value, defaultValue, onValueChange, size, placeholder, name, disabled, className, onKeyDown, onClick, ...props }: SelectProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type MenuPlacement = 'aligned' | 'below' | 'above';
|
|
2
|
+
/** 菜单定位用到的样式 token(px)。 */
|
|
3
|
+
export interface MenuMetrics {
|
|
4
|
+
readonly gutter: number;
|
|
5
|
+
readonly maxHeight: number;
|
|
6
|
+
readonly affordance: number;
|
|
7
|
+
}
|
|
8
|
+
export interface MenuLayoutInput {
|
|
9
|
+
readonly trigger: Pick<DOMRect, 'top' | 'bottom' | 'left' | 'width' | 'height'>;
|
|
10
|
+
readonly viewport: {
|
|
11
|
+
readonly width: number;
|
|
12
|
+
readonly height: number;
|
|
13
|
+
};
|
|
14
|
+
readonly metrics: MenuMetrics;
|
|
15
|
+
/** 菜单按内容撑开时的宽度。 */
|
|
16
|
+
readonly panelWidth: number;
|
|
17
|
+
/** 菜单自身边框占用的高度(菜单高度减去列表高度)。 */
|
|
18
|
+
readonly borderHeight: number;
|
|
19
|
+
/** 列表内容总高度(含内边距)。 */
|
|
20
|
+
readonly contentHeight: number;
|
|
21
|
+
/** 初始高亮行在列表内的位置;没有可用选项时为 undefined。 */
|
|
22
|
+
readonly row?: {
|
|
23
|
+
readonly top: number;
|
|
24
|
+
readonly height: number;
|
|
25
|
+
readonly hasNext: boolean;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface MenuLayout {
|
|
29
|
+
readonly placement: MenuPlacement;
|
|
30
|
+
readonly top: number;
|
|
31
|
+
readonly left: number;
|
|
32
|
+
readonly width: number;
|
|
33
|
+
/** 列表的 max-height。 */
|
|
34
|
+
readonly maxHeight: number;
|
|
35
|
+
readonly scrollTop: number;
|
|
36
|
+
}
|
|
37
|
+
export declare function readMenuMetrics(panel: Element): MenuMetrics;
|
|
38
|
+
/** 根据测量值计算菜单位置:优先让初始行与触发器对齐,贴近视口边缘时改为向下或向上展开。 */
|
|
39
|
+
export declare function computeMenuLayout({ trigger, viewport, metrics, panelWidth, borderHeight, contentHeight, row }: MenuLayoutInput): MenuLayout;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const selectStyles: {
|
|
2
|
+
readonly Root: "inline-flex min-w-0 align-middle";
|
|
3
|
+
readonly Trigger: string;
|
|
4
|
+
readonly Size: {
|
|
5
|
+
readonly small: "h-(--hub-control-height-sm) text-hub-sm";
|
|
6
|
+
readonly default: "h-(--hub-control-height-md) text-hub-md";
|
|
7
|
+
};
|
|
8
|
+
readonly Font: {
|
|
9
|
+
readonly small: "text-hub-sm";
|
|
10
|
+
readonly default: "text-hub-md";
|
|
11
|
+
};
|
|
12
|
+
readonly Row: {
|
|
13
|
+
readonly small: "h-(--hub-control-height-sm)";
|
|
14
|
+
readonly default: "h-(--hub-row-height-md)";
|
|
15
|
+
};
|
|
16
|
+
readonly Label: "min-w-0 flex-1 truncate text-left";
|
|
17
|
+
readonly Icon: "inline-flex shrink-0 items-center justify-center";
|
|
18
|
+
readonly Chevron: "h-2 w-2.5 shrink-0 text-hub-fg-muted";
|
|
19
|
+
readonly Check: "size-4 shrink-0 text-hub-fg-muted";
|
|
20
|
+
readonly Popup: string;
|
|
21
|
+
readonly List: "relative box-border overflow-y-auto overscroll-contain p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden";
|
|
22
|
+
readonly Option: string;
|
|
23
|
+
readonly Scroll: string;
|
|
24
|
+
readonly ScrollTop: "top-0 bg-linear-to-b from-hub-bg-panel via-hub-bg-panel/90 to-hub-bg-panel/50";
|
|
25
|
+
readonly ScrollBottom: "bottom-0 bg-linear-to-t from-hub-bg-panel via-hub-bg-panel/90 to-hub-bg-panel/50";
|
|
26
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
export type ScrollSide = 'top' | 'bottom';
|
|
3
|
+
/** 列表两端的滚动提示:是否还有被裁剪的内容,以及悬停提示时的连续滚动。 */
|
|
4
|
+
export declare function useScrollAffordance(list: RefObject<HTMLElement | null>): {
|
|
5
|
+
edges: {
|
|
6
|
+
top: boolean;
|
|
7
|
+
bottom: boolean;
|
|
8
|
+
};
|
|
9
|
+
update: () => void;
|
|
10
|
+
start: (side: ScrollSide) => void;
|
|
11
|
+
stop: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
interface Options {
|
|
3
|
+
readonly value: string | undefined;
|
|
4
|
+
readonly defaultValue: string | undefined;
|
|
5
|
+
readonly onValueChange: ((value: string) => void) | undefined;
|
|
6
|
+
readonly trigger: RefObject<HTMLButtonElement | null>;
|
|
7
|
+
/** 触发器的 `form` 属性;变化时重新查找所属表单。 */
|
|
8
|
+
readonly form: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
/** 受控 / 非受控的选中值;非受控时随所属表单重置恢复 defaultValue。 */
|
|
11
|
+
export declare function useSelectValue({ value, defaultValue, onValueChange, trigger, form }: Options): {
|
|
12
|
+
current: string;
|
|
13
|
+
commit: (next: string) => void;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
export interface TooltipProps {
|
|
3
|
+
readonly children: ReactElement;
|
|
4
|
+
readonly content: ReactNode;
|
|
5
|
+
readonly shortcut?: readonly string[];
|
|
6
|
+
readonly side?: 'top' | 'right' | 'bottom' | 'left';
|
|
7
|
+
readonly align?: 'start' | 'center' | 'end';
|
|
8
|
+
readonly disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function Tooltip({ children, content, shortcut, side, align, disabled }: TooltipProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** 组件实例提供给协调器的回调。 */
|
|
2
|
+
export interface TooltipHost {
|
|
3
|
+
readonly trigger: () => Element | null;
|
|
4
|
+
readonly onOpenChange: (open: boolean) => void;
|
|
5
|
+
/** 当前按键状态变化;只通知正在显示的实例。 */
|
|
6
|
+
readonly onKeysChange: () => void;
|
|
7
|
+
/** 重新定位;触发器已离开视口时返回 false。 */
|
|
8
|
+
readonly reposition: () => boolean;
|
|
9
|
+
}
|
|
10
|
+
/** 一个 Tooltip 实例在协调器中的状态:显示条件和自身的定时器。 */
|
|
11
|
+
export declare class TooltipHandle {
|
|
12
|
+
private readonly coordinator;
|
|
13
|
+
readonly host: TooltipHost;
|
|
14
|
+
hover: boolean;
|
|
15
|
+
popupHover: boolean;
|
|
16
|
+
focus: boolean;
|
|
17
|
+
shortcut: boolean;
|
|
18
|
+
disabled: boolean;
|
|
19
|
+
openTimer: number | undefined;
|
|
20
|
+
closeTimer: number | undefined;
|
|
21
|
+
constructor(coordinator: TooltipCoordinator, host: TooltipHost);
|
|
22
|
+
get wanted(): boolean;
|
|
23
|
+
delay(name: string): number;
|
|
24
|
+
clearClose(): void;
|
|
25
|
+
enter(): void;
|
|
26
|
+
leave(): void;
|
|
27
|
+
popupEnter(): void;
|
|
28
|
+
popupLeave(): void;
|
|
29
|
+
focusIn(): void;
|
|
30
|
+
focusOut(): void;
|
|
31
|
+
/** 关闭并清除显示条件;之后需要新的进入或聚焦动作才会再次显示。 */
|
|
32
|
+
dismiss(): void;
|
|
33
|
+
setDisabled(disabled: boolean): void;
|
|
34
|
+
setShortcut(shortcut: boolean): void;
|
|
35
|
+
isPressed(label: string): boolean;
|
|
36
|
+
dispose(): void;
|
|
37
|
+
}
|
|
38
|
+
/** 同一文档内所有 Tooltip 共享的开关、免等待和按键状态。 */
|
|
39
|
+
declare class TooltipCoordinator {
|
|
40
|
+
private readonly document;
|
|
41
|
+
private readonly onEmpty;
|
|
42
|
+
private readonly handles;
|
|
43
|
+
private visible;
|
|
44
|
+
private pending;
|
|
45
|
+
/** 免等待截止时间(performance.now 时间戳)。 */
|
|
46
|
+
private skipUntil;
|
|
47
|
+
private shortcuts;
|
|
48
|
+
private modifiers;
|
|
49
|
+
/** 按下的普通键:event.code 到 keydown 时的逻辑键,释放时按 code 找回。 */
|
|
50
|
+
private readonly keys;
|
|
51
|
+
private composing;
|
|
52
|
+
constructor(document: Document, onEmpty: () => void);
|
|
53
|
+
register(host: TooltipHost): TooltipHandle;
|
|
54
|
+
unregister(handle: TooltipHandle): void;
|
|
55
|
+
/** 请求显示:已有提示显示或处于免等待时间内立即切换,否则从头等待。 */
|
|
56
|
+
request(handle: TooltipHandle, immediate: boolean): void;
|
|
57
|
+
/** 某个显示条件消失:全部消失后才关闭;鼠标离开时留出缓冲,便于移到提示内容上。 */
|
|
58
|
+
release(handle: TooltipHandle, buffered: boolean): void;
|
|
59
|
+
dismiss(handle: TooltipHandle): void;
|
|
60
|
+
countShortcut(change: number): void;
|
|
61
|
+
isPressed(label: string): boolean;
|
|
62
|
+
private show;
|
|
63
|
+
private hide;
|
|
64
|
+
private cancelPending;
|
|
65
|
+
private dismissAll;
|
|
66
|
+
private keyState;
|
|
67
|
+
private clearKeys;
|
|
68
|
+
private readonly onKey;
|
|
69
|
+
private readonly onComposition;
|
|
70
|
+
/** 触发器随滚动移动时关闭;由键盘焦点保持的提示改为跟随,否则 Tab 到视口外的触发器会立刻被关掉。 */
|
|
71
|
+
private readonly onScroll;
|
|
72
|
+
private readonly onResize;
|
|
73
|
+
/** 窗口失焦或页面隐藏:之后收不到按键释放和鼠标离开,全部状态归零。 */
|
|
74
|
+
private readonly onInactive;
|
|
75
|
+
private listen;
|
|
76
|
+
}
|
|
77
|
+
/** 在触发器所在文档的协调器中注册一个实例;协调器按需创建,最后一个实例注销后移除。 */
|
|
78
|
+
export declare function registerTooltip(document: Document, host: TooltipHost): TooltipHandle;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type TooltipSide = 'top' | 'right' | 'bottom' | 'left';
|
|
2
|
+
export type TooltipAlign = 'start' | 'center' | 'end';
|
|
3
|
+
export interface TooltipLayoutInput {
|
|
4
|
+
readonly trigger: Pick<DOMRect, 'top' | 'bottom' | 'left' | 'right' | 'width' | 'height'>;
|
|
5
|
+
/** 浮层可见部分的尺寸(不含外边距)。 */
|
|
6
|
+
readonly panel: {
|
|
7
|
+
readonly width: number;
|
|
8
|
+
readonly height: number;
|
|
9
|
+
};
|
|
10
|
+
/** 浮层的外边距:既是与触发器的间距,也是与视口边缘的最小间距。 */
|
|
11
|
+
readonly margin: number;
|
|
12
|
+
readonly viewport: {
|
|
13
|
+
readonly width: number;
|
|
14
|
+
readonly height: number;
|
|
15
|
+
};
|
|
16
|
+
readonly side: TooltipSide;
|
|
17
|
+
readonly align: TooltipAlign;
|
|
18
|
+
readonly rtl: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface TooltipLayout {
|
|
21
|
+
/** 实际显示的方向。 */
|
|
22
|
+
readonly side: TooltipSide;
|
|
23
|
+
/** 浮层外边距盒左上角的位置,直接写入 fixed 定位的 top 和 left。 */
|
|
24
|
+
readonly top: number;
|
|
25
|
+
readonly left: number;
|
|
26
|
+
}
|
|
27
|
+
/** 优先使用 side 和 align;主方向放不下且反方向更宽裕时翻转,最后把位置约束在视口内。 */
|
|
28
|
+
export declare function computeTooltipLayout({ trigger, panel, margin, viewport, side, align, rtl }: TooltipLayoutInput): TooltipLayout;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,3 +14,7 @@ export { Toaster } from './components/Toast/Toaster.js';
|
|
|
14
14
|
export type { ToasterProps } from './components/Toast/Toaster.js';
|
|
15
15
|
export { ToastStore } from './components/Toast/ToastStore.js';
|
|
16
16
|
export type { ToastItem, ToastOptions, ToastStoreOptions } from './components/Toast/ToastStore.js';
|
|
17
|
+
export { Select } from './components/Select/Select.js';
|
|
18
|
+
export type { SelectProps, SelectOption } from './components/Select/Select.js';
|
|
19
|
+
export { Tooltip } from './components/Tooltip/Tooltip.js';
|
|
20
|
+
export type { TooltipProps } from './components/Tooltip/Tooltip.js';
|