From 5e426c9f9d0e6ab9aa8d166c29ac8fb2fd95a414 Mon Sep 17 00:00:00 2001 From: zhouyun Date: Wed, 25 Dec 2024 17:39:13 +0800 Subject: [PATCH] =?UTF-8?q?chore(provider):=20=E4=BC=98=E5=8C=96=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=20(#3072)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/strong-dodos-provide.md | 6 + packages/ui/locale-context/src/index.ts | 2 + .../ui/provider/stories/basic.stories.tsx | 85 ++++++++++++- .../ui/provider/stories/index.stories.tsx | 1 + .../ui/provider/stories/portal.stories.tsx | 112 ++++++++++++++++++ 5 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 .changeset/strong-dodos-provide.md create mode 100644 packages/ui/provider/stories/portal.stories.tsx diff --git a/.changeset/strong-dodos-provide.md b/.changeset/strong-dodos-provide.md new file mode 100644 index 000000000..82d27caff --- /dev/null +++ b/.changeset/strong-dodos-provide.md @@ -0,0 +1,6 @@ +--- +"@hi-ui/locale-context": patch +"@hi-ui/hiui": patch +--- + +chore(locale-context): 对外暴露类型定义 diff --git a/packages/ui/locale-context/src/index.ts b/packages/ui/locale-context/src/index.ts index ad0013432..445bb3c90 100644 --- a/packages/ui/locale-context/src/index.ts +++ b/packages/ui/locale-context/src/index.ts @@ -2,3 +2,5 @@ export * from './LocaleContext' export * from './LocaleProvider' export { LocaleProvider as default } from './LocaleProvider' + +export * from './types' diff --git a/packages/ui/provider/stories/basic.stories.tsx b/packages/ui/provider/stories/basic.stories.tsx index b6e92b085..b9f327e7b 100644 --- a/packages/ui/provider/stories/basic.stories.tsx +++ b/packages/ui/provider/stories/basic.stories.tsx @@ -1,17 +1,96 @@ import React from 'react' -import Provider from '../src' +import Provider, { DesignSystemAccentColorEnum } from '../src' +import { LocaleEnum } from '@hi-ui/locale-context' +import Pagination from '@hi-ui/pagination' +import Select from '@hi-ui/select' +import { Row, Col } from '@hi-ui/grid' import Alert from '@hi-ui/alert' /** * @title 基础用法 */ export const Basic = () => { + const [locale, setLocale] = React.useState() + const [accentColor, setAccentColor] = React.useState() + return ( <> -

使用须知

+

基础用法

- + + + + setAccentColor(val as DesignSystemAccentColorEnum)} + /> + + + +
) diff --git a/packages/ui/provider/stories/index.stories.tsx b/packages/ui/provider/stories/index.stories.tsx index 2e2a92c23..e374642e2 100644 --- a/packages/ui/provider/stories/index.stories.tsx +++ b/packages/ui/provider/stories/index.stories.tsx @@ -1,6 +1,7 @@ import React from 'react' export * from './basic.stories' +export * from './portal.stories' export default { title: 'Provider', diff --git a/packages/ui/provider/stories/portal.stories.tsx b/packages/ui/provider/stories/portal.stories.tsx new file mode 100644 index 000000000..2fa300edc --- /dev/null +++ b/packages/ui/provider/stories/portal.stories.tsx @@ -0,0 +1,112 @@ +import React from 'react' +import Provider from '../src' +import Button from '@hi-ui/button' +import Drawer from '@hi-ui/drawer' +import Modal from '@hi-ui/modal' +import Space from '@hi-ui/space' +import { createMessage } from '@hi-ui/message' +import { createNotification } from '@hi-ui/notification' + +// 声明为全局变量 +let message = createMessage() +let notification = createNotification() + +/** + * @title 设置 portal + * @desc 通过 Provider 设置 portal,可以将 Drawer、Modal 等组件的弹出层渲染在特定的 DOM 节点下 + */ +export const Portal = () => { + const [drawerVisible, setDrawerVisible] = React.useState(false) + const [modalVisible, setModalVisible] = React.useState(false) + const [container, setContainer] = React.useState(null) + + React.useEffect(() => { + if (!container) return + + // message 和 notification 可通过这种方式挂载到指定容器上 + message = createMessage({ container }) + notification = createNotification({ container }) + }, [container]) + + return ( + <> +

设置 Portal

+
+ + + + + + + + {/* 必须设置一个拥有定位的父元素,组件显示在该元素内 */} +
+ setDrawerVisible(false)} + > + 我是一段文字,也可以是表单、表格、步骤条等等 + + setModalVisible(false)} + > + 我是挂载指定容器的模态框内容 + +
+
+
+ + ) +}