@befe/brick-comp-tabs 0.2.92

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,42 @@
1
+ import { Component, ContextType, ReactNode } from 'react';
2
+ import { TabPaneId, TabsContext } from './tabs-context';
3
+ export interface TabPaneProps {
4
+ /**
5
+ * 自定义 class
6
+ */
7
+ className?: string;
8
+ /**
9
+ * 唯一标识
10
+ */
11
+ id: TabPaneId;
12
+ /**
13
+ * 标签页上的内容
14
+ */
15
+ label: ReactNode;
16
+ /**
17
+ * 是否禁用
18
+ */
19
+ disabled?: boolean;
20
+ /**
21
+ * 是否可删除
22
+ */
23
+ deletable?: boolean;
24
+ /**
25
+ * tab 标签页的状态
26
+ * - 仅 type card 支持
27
+ * - 暂时只有 'normal' | 'error'
28
+ */
29
+ status?: 'normal' | 'error';
30
+ }
31
+ export declare class TabPane extends Component<TabPaneProps> {
32
+ static displayName: string;
33
+ static defaultProps: {
34
+ className: string;
35
+ status: string;
36
+ };
37
+ static contextType: import("react").Context<import("./tabs-context").TabsContextValue>;
38
+ context: ContextType<typeof TabsContext>;
39
+ get className(): string;
40
+ get isActive(): boolean;
41
+ render(): JSX.Element;
42
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export type TabPaneId = string | number | boolean;
3
+ export interface TabsContextValue {
4
+ activeId?: TabPaneId | null;
5
+ }
6
+ export declare const TabsContext: import("react").Context<TabsContextValue>;
@@ -0,0 +1,139 @@
1
+ import { Component, ContextType, ReactNode, MouseEvent, ReactComponentElement } from 'react';
2
+ import { EventListenerHandler } from '@befe/brick-utils';
3
+ import { ConfigContext } from '@befe/brick-core';
4
+ import { MenuPopperProps } from '@befe/brick-comp-menu';
5
+ import { RadioGroupProps } from '@befe/brick-comp-radio';
6
+ import { TabPane, TabPaneProps } from './tab-pane';
7
+ import { TabPaneId, TabsContextValue } from './tabs-context';
8
+ type ButtonGroupProps = Pick<RadioGroupProps, 'value' | 'options'>;
9
+ interface TabItem extends TabPaneProps {
10
+ /**
11
+ * tab 页内容
12
+ */
13
+ content?: ReactNode;
14
+ }
15
+ export interface TabsProps {
16
+ /**
17
+ * 自定义 class
18
+ */
19
+ className?: string;
20
+ /**
21
+ * 尺寸
22
+ * use config context `baseSize` as default
23
+ */
24
+ size?: 'sm' | 'md';
25
+ /**
26
+ * 标签卡样式类型
27
+ */
28
+ type?: 'plain' | 'card' | 'tag' | 'button-group-intensive' | 'button-group-important';
29
+ /**
30
+ * 标签页
31
+ */
32
+ panes?: TabItem[];
33
+ /**
34
+ * 激活 tab id 的 控制值
35
+ */
36
+ activeId?: TabPaneId;
37
+ /**
38
+ * 激活 tab id 的 默认值
39
+ */
40
+ defaultActiveId?: TabPaneId | null;
41
+ /**
42
+ * activeId 变化时的回调
43
+ */
44
+ onChange?: (activeId: TabPaneId) => void;
45
+ /**
46
+ * 点击 tab 的回调
47
+ *
48
+ * type `button-group-intensive` 和 `button-group-important` 无效,因 RadioGroup 没有 onClick 事件
49
+ */
50
+ onClickTab?: (e: MouseEvent, id: TabPaneId) => void;
51
+ /**
52
+ * 下拉列表触发方式
53
+ */
54
+ triggerType?: MenuPopperProps['type'];
55
+ /**
56
+ * 是否干掉非当前激活的 pane dom
57
+ */
58
+ shouldDestroyInactivePane?: boolean;
59
+ /**
60
+ * 添加按钮点击回调
61
+ *
62
+ * 提供回调则显示添加按钮,仅 type 'card' 支持
63
+ */
64
+ onClickAdd?: (e: MouseEvent) => void | TabPaneId;
65
+ /**
66
+ * delete 删除tab回调
67
+ */
68
+ onTabDelete?: (activeId: TabPaneId) => void;
69
+ /**
70
+ * @private 暂不公布,以便于收集需要使用 "非 bottom-end" 场景的普遍率
71
+ * 收起到等多下拉 popper 位置
72
+ */
73
+ ellipsisDropdownPlacement?: MenuPopperProps['placement'];
74
+ }
75
+ interface TabsState {
76
+ activeId?: TabPaneId | null;
77
+ visibleFrom: number;
78
+ visibleTo: number;
79
+ isEllipsisPopperVisible: boolean;
80
+ }
81
+ export declare class Tabs extends Component<TabsProps, TabsState> {
82
+ static displayName: string;
83
+ static defaultProps: {
84
+ className: string;
85
+ type: string;
86
+ defaultActiveId: null;
87
+ shouldDestroyInactivePane: boolean;
88
+ ellipsisDropdownPlacement: string;
89
+ };
90
+ static contextType: import("react").Context<import("@befe/brick-core").ConfigContextValue>;
91
+ context: ContextType<typeof ConfigContext>;
92
+ windowResizeHandler: EventListenerHandler | null;
93
+ tabsWheelHandler: EventListenerHandler | null;
94
+ static getDerivedStateFromProps(nextProps: TabsProps): Partial<TabsProps> | null;
95
+ state: TabsState;
96
+ refTabsWrap: import("react").RefObject<HTMLDivElement>;
97
+ refTabs: import("react").RefObject<HTMLUListElement>;
98
+ tabsWrapWidth: number;
99
+ tabsWidth: number[];
100
+ tabsWrapMaxScrollLeft: number;
101
+ tabsWrapScrollLeft: number;
102
+ get className(): string;
103
+ get size(): "sm" | "md";
104
+ get contextValue(): TabsContextValue;
105
+ get validChildren(): ReactComponentElement<typeof TabPane, Pick<TabPaneProps, keyof TabPaneProps>>[] | null;
106
+ get tabsAll(): TabItem[];
107
+ get tabsEllipsis(): TabItem[];
108
+ get canEllipsis(): boolean;
109
+ get withEllipsis(): boolean;
110
+ isTabPaneDisabled(id: TabPaneId): boolean;
111
+ updateWidth(): void;
112
+ updateEllipsis(): void;
113
+ changeActive(id: TabPaneId): void;
114
+ deleteTab(id: TabPaneId): void;
115
+ scrollTabsWrap(scrollLeftTo?: number): void;
116
+ scrollTabsWrapToTab(id: TabPaneId, force?: boolean): void;
117
+ scrollTabsWrapToActive(force?: boolean): void;
118
+ handleClickAdd: (e: MouseEvent) => void;
119
+ handleClickTab: (e: MouseEvent, id: TabPaneId) => void;
120
+ handleChangeRadioGroup: (value: ButtonGroupProps['value']) => void;
121
+ handleMenuPopperChange: (status: boolean) => void;
122
+ handleWheelTabsWrap: (e: WheelEvent) => void;
123
+ renderTabDelete(tab: TabItem): JSX.Element | null;
124
+ renderTabStatus(tab: TabItem): false | JSX.Element | null;
125
+ renderTab: (tab: TabItem) => JSX.Element;
126
+ renderTabs(): JSX.Element;
127
+ renderTabsEllipsisMenu(): JSX.Element;
128
+ renderTabsEllipsis(): JSX.Element | null;
129
+ renderAddButton(): JSX.Element | null;
130
+ renderButtonGroupTabs(): JSX.Element;
131
+ renderTabsContainer(): JSX.Element;
132
+ renderTabPanes(): JSX.Element[] | null;
133
+ renderTabPanesContainer(): JSX.Element | null;
134
+ componentDidMount(): void;
135
+ componentWillUnmount(): void;
136
+ componentDidUpdate(prevProps: Readonly<TabsProps>, prevState: Readonly<TabsState>): void;
137
+ render(): JSX.Element;
138
+ }
139
+ export {};