@fe-free/core 2.2.12 → 2.2.13

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 2.2.13
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: tabs
8
+ - @fe-free/tool@2.2.13
9
+
3
10
  ## 2.2.12
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "2.2.12",
3
+ "version": "2.2.13",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -41,7 +41,7 @@
41
41
  "remark-gfm": "^4.0.1",
42
42
  "vanilla-jsoneditor": "^0.23.1",
43
43
  "zustand": "^4.5.4",
44
- "@fe-free/tool": "2.2.12"
44
+ "@fe-free/tool": "2.2.13"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
package/src/index.ts CHANGED
@@ -37,6 +37,8 @@ export { PageLayout } from './page_layout';
37
37
  export { routeTool } from './route';
38
38
  export { Table } from './table';
39
39
  export type { TableProps } from './table';
40
+ export { Tabs } from './tabs';
41
+ export type { TabsProps } from './tabs';
40
42
  export { Tree, flatToTreeData } from './tree';
41
43
  export type { TreeProps } from './tree';
42
44
  export { useLocalforageState } from './use_localforage_state';
@@ -8,22 +8,22 @@ const meta: Meta<typeof PageLayout> = {
8
8
  };
9
9
 
10
10
  export default meta;
11
- type Story = StoryObj<typeof meta>;
11
+ type Story = StoryObj<typeof PageLayout>;
12
12
 
13
13
  export const Default: Story = {
14
14
  args: {
15
- start: <div className="bg-red-500 w-[100px] h-[100px]">start</div>,
16
- children: <div className="bg-blue-500 h-[100px]">children</div>,
17
- end: <div className="bg-green-500 w-[100px] h-[100px]">end</div>,
15
+ start: <div className="h-[100px] w-[100px] bg-red-500">start</div>,
16
+ children: <div className="h-[100px] bg-blue-500">children</div>,
17
+ end: <div className="h-[100px] w-[100px] bg-green-500">end</div>,
18
18
  },
19
19
  };
20
20
 
21
21
  export const DirectionVertical: Story = {
22
22
  args: {
23
23
  direction: 'vertical',
24
- start: <div className="bg-red-500 h-[100px]">start</div>,
25
- children: <div className="bg-blue-500 h-[100px]">children</div>,
26
- end: <div className="bg-green-500 h-[100px]">end</div>,
24
+ start: <div className="h-[100px] bg-red-500">start</div>,
25
+ children: <div className="h-[100px] bg-blue-500">children</div>,
26
+ end: <div className="h-[100px] bg-green-500">end</div>,
27
27
  },
28
28
  };
29
29
 
@@ -33,8 +33,8 @@ export const ClassName: Story = {
33
33
  startClassName: 'p-4 bg-red-200',
34
34
  childrenClassName: 'p-4 bg-blue-200',
35
35
  endClassName: 'p-4 bg-green-200',
36
- start: <div className="bg-red-500 w-[100px] h-full">start</div>,
37
- children: <div className="bg-blue-500 h-full">children</div>,
38
- end: <div className="bg-green-500 w-[100px] h-full">end</div>,
36
+ start: <div className="h-full w-[100px] bg-red-500">start</div>,
37
+ children: <div className="h-full bg-blue-500">children</div>,
38
+ end: <div className="h-full w-[100px] bg-green-500">end</div>,
39
39
  },
40
40
  };
@@ -0,0 +1,42 @@
1
+ import type { TabsProps as AntdTabsProps } from 'antd';
2
+ import { Tabs as AntdTabs } from 'antd';
3
+ import { useEffect } from 'react';
4
+ import { useSearchParams } from 'react-router-dom';
5
+
6
+ interface TabsProps extends AntdTabsProps {
7
+ /** 自动时设置和同步 searchParams tab */
8
+ withSearchParams?: boolean;
9
+ }
10
+
11
+ function Tabs(props: TabsProps) {
12
+ const { withSearchParams, activeKey, onChange, ...rest } = props;
13
+ const [searchParams, setSearchParams] = useSearchParams();
14
+ const tab = searchParams.get('tab') || undefined;
15
+
16
+ useEffect(() => {
17
+ if (withSearchParams) {
18
+ if (!tab && props.items?.[0]?.key) {
19
+ setSearchParams({ tab: props.items?.[0]?.key });
20
+ }
21
+ }
22
+ // tab 清空的时候要重新设置第一个
23
+ }, [tab]);
24
+
25
+ return (
26
+ <AntdTabs
27
+ {...rest}
28
+ activeKey={withSearchParams ? tab : activeKey}
29
+ onChange={(key) => {
30
+ onChange?.(key);
31
+ if (props.withSearchParams) {
32
+ searchParams.set('tab', key);
33
+
34
+ setSearchParams({ tab: key });
35
+ }
36
+ }}
37
+ />
38
+ );
39
+ }
40
+
41
+ export { Tabs };
42
+ export type { TabsProps };
@@ -0,0 +1,26 @@
1
+ import { Tabs } from '@fe-free/core';
2
+ import type { Meta, StoryObj } from '@storybook/react-vite';
3
+
4
+ const meta: Meta<typeof Tabs> = {
5
+ title: '@fe-free/core/Tabs',
6
+ component: Tabs,
7
+ tags: ['autodocs'],
8
+ parameters: {
9
+ docs: {
10
+ description: {
11
+ component:
12
+ '基于 antd Tabs 封装的 Tabs,设置 withSearchParams 则自动根据 ?tab= 设置 activeKey',
13
+ },
14
+ },
15
+ },
16
+ };
17
+
18
+ export default meta;
19
+ type Story = StoryObj<typeof Tabs>;
20
+
21
+ // 基础用法
22
+ export const Basic: Story = {
23
+ render: () => {
24
+ return <div>依赖 react-router-dom 的 Route 组件,暂不提供 demo</div>;
25
+ },
26
+ };