Skip to content

Commit

Permalink
feat(notification): 支持自定义 notification 配置 (XiaoMi#2832)
Browse files Browse the repository at this point in the history
* feat(notification): 支持指定portal挂载(XiaoMi#2831)

* chore(notification): 生成变更记录文件

* chore: 修改container类型

* feat(notification): 重写自定义portal和zIndex功能(XiaoMi#2831)

* feat(notification): 重写自定义属性示例(XiaoMi#2831)

* feat(notification): 删除toast修改部分

---------

Co-authored-by: xiamiao <[email protected]>
  • Loading branch information
2 people authored and yangxuexue committed Jun 28, 2024
1 parent ba60d8c commit 8dc9afe
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/soft-eggs-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/notification": minor
---

feat: 支持自定义 notification 配置
5 changes: 5 additions & 0 deletions .changeset/thick-taxis-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

feat(notification): 支持自定义 notification 配置
6 changes: 5 additions & 1 deletion packages/ui/notification/src/NotificationAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export interface NotificationAPIOptions extends ToastAPIOptions {}

export interface NotificationOptions extends Omit<NotificationProps, 'destroy' | 'visible'> {}

export const notification = new NotificationAPI({ component: NotificationComponent })
export const createNotification = (options?: Omit<NotificationAPIOptions, 'component'>) => {
return new NotificationAPI({ component: NotificationComponent, ...options })
}

export const notification = createNotification({})
54 changes: 54 additions & 0 deletions packages/ui/notification/stories/custom.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useState, useMemo } from 'react'
import { createNotification } from '../src'
import Button from '@hi-ui/button'

/**
* @title notification 属性自定义
*/
export const Custom = () => {
const [container, setContainer] = useState<HTMLElement | undefined>()

const notification = useMemo(
() =>
createNotification({
container: container,
zIndex: 2000,
}),
[container]
)

return (
<>
<h1>Custom</h1>
<div
ref={(e) => {
setContainer(e)
}}
id="ddd"
style={{
width: 400,
height: 300,
background: 'rgb(245, 247, 250)',

// Need add it
position: 'relative',
overflow: 'hidden',
}}
></div>

<div className="notification-custom__wrap">
<Button
onClick={() => {
notification.open({
title: '数据备份通知',
content:
'各位同学请注意,将于2019.08.10 00:00:00 -08:00:00 期间进行系统服务器升级维护,请做好数据备份工作,以防丢失。带来不便,敬请谅解!',
})
}}
>
Notice
</Button>
</div>
</>
)
}
1 change: 1 addition & 0 deletions packages/ui/notification/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './title.stories'
export * from './auto-close.stories'
export * from './action.stories'
export * from './size.stories'
export * from './custom.stories'

export default {
title: 'FeedBack/Notification',
Expand Down

0 comments on commit 8dc9afe

Please sign in to comment.