Skip to content

Commit

Permalink
feat: add Notification component
Browse files Browse the repository at this point in the history
  • Loading branch information
Jandiasnow committed Apr 11, 2024
1 parent 395fc9d commit 1e5a0cf
Show file tree
Hide file tree
Showing 7 changed files with 486 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/App/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { App as AntdApp, type AppProps as AntdAppProps } from 'antd';
import React from 'react';

import { NotificationGlobalStyle } from '../notification';

export type AppProps = AntdAppProps;

export const App: React.FC<AppProps> & {
useApp: typeof AntdApp.useApp;
} = props => {
const { children, ...otherProps } = props;
return (
<AntdApp {...otherProps}>
<NotificationGlobalStyle />
{children}
</AntdApp>
);
};

App.useApp = AntdApp.useApp;
export default App;
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ export * from './Tree';

// ~ custom antd
export * from './Alert';
export * from './App';
export * from './Card';
export * from './Descriptions';
export * from './Divider';
export * from './Drawer';
export * from './Modal';
export * from './notification';

// ~ antd
export {
Affix,
type AffixProps,
Anchor,
type AnchorProps,
App,
type AppProps,
AutoComplete,
type AutoCompleteProps,
Avatar,
Expand Down
41 changes: 41 additions & 0 deletions src/notification/demos/Playground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { App, Button, NotificationArgsProps, notification } from '@yuntijs/ui';

export default () => {
const store = useCreateStore();
const control: NotificationArgsProps | any = useControls(
{
message: 'YuntiUI nitification',
description: 'Prompt notification message globally.',
duration: 4.5,
key: 'notification',
placement: {
options: ['top', 'topLeft', 'topRight', 'bottom', 'bottomLeft', 'bottomRight'],
value: 'topRight',
},
},
{ store }
);
return (
<StoryBook levaStore={store}>
<App>
<Button
onClick={() => {
notification.warnings({
...control,
errors: [
{
name: 'YuntiUI',
message:
'The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components, and it is recommended to use antd-style as the default css-in-js styling solution.',
},
],
});
}}
>
Open
</Button>
</App>
</StoryBook>
);
};
94 changes: 94 additions & 0 deletions src/notification/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { App, Button, Space, notification } from '@yuntijs/ui';

export default () => {
return (
<App>
<Space>
<Button
onClick={() => {
notification.success({
message: 'YuntiUI notification success',
description: 'Prompt notification message globally.',
});
}}
>
success
</Button>
<Button
onClick={() => {
notification.info({
message: 'YuntiUI notification info',
description: 'Prompt notification message globally.',
});
}}
>
info
</Button>
<Button
onClick={() => {
notification.warning({
message: 'YuntiUI notification warning',
description: 'Prompt notification message globally.',
});
}}
>
warning
</Button>
<Button
onClick={() => {
notification.warn({
message: 'YuntiUI notification warn',
description: 'Prompt notification message globally.',
});
}}
>
warn
</Button>
<Button
onClick={() => {
notification.error({
message: 'YuntiUI notification error',
description: 'Prompt notification message globally.',
});
}}
>
error
</Button>
<Button
onClick={() => {
notification.warnings({
message: 'YuntiUI notification warnings',
description: 'Prompt notification message globally.',
errors: [
{
name: 'YuntiUI',
message:
'The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components, and it is recommended to use antd-style as the default css-in-js styling solution.',
},
],
});
}}
>
warnings
</Button>
<Button
onClick={() => {
notification.warns({
message: 'YuntiUI notification warns',
description: 'Prompt notification message globally.',
errors: [
{
name: 'YuntiUI',
message:
'The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components, and it is recommended to use antd-style as the default css-in-js styling solution.',
},
],
});
}}
>
warns
</Button>
</Space>
</App>
);
};
52 changes: 52 additions & 0 deletions src/notification/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
nav: Components
group: Feedback
title: Notification
description: Prompt notification message globally.
---

## Usage

based on antd [Notification](https://ant.design/components/notification-cn/) component.

### Simple usage

**Note: Pages that use notification need to be wrapped by the app component, otherwise the notification style may be problematic**

```jsx | pure
import { App, Button, notification } from '@yuntijs/ui';

export default () => {
return (
<App>
<Button
onClick={() => {
notification.warnings({
message: 'YuntiUI nitification',
description: 'Prompt notification message globally.',
errors: [
{
name: 'YuntiUI',
message:
'The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components, and it is recommended to use antd-style as the default css-in-js styling solution.',
},
],
});
}}
>
Open
</Button>
</App>
);
};
```

<code src="./demos/index.tsx" center></code>

## Playground

<code src="./demos/Playground.tsx" nopadding></code>

## APIs

<API></API>
Loading

0 comments on commit 1e5a0cf

Please sign in to comment.