notification.stories.jsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import React from 'react';
  2. import { IconWifi, IconToutiaoLogo } from '@douyinfe/semi-icons';
  3. import Notification from '../index';
  4. import Button from '@douyinfe/semi-ui/button/index';
  5. import UseNotificationDemo from './useNotification';
  6. export default {
  7. title: 'Notification',
  8. parameters: {
  9. chromatic: { disableSnapshot: true },
  10. },
  11. }
  12. let noticeIds = [];
  13. const fnc = () => {
  14. let id = Notification.info({ content: '0', duration: 0 });
  15. noticeIds.push(id);
  16. };
  17. const remove = () => {
  18. let id = noticeIds[0];
  19. console.log(noticeIds);
  20. Notification.close(id);
  21. noticeIds = noticeIds.filter(key => id !== key);
  22. };
  23. let pos = ['topRight', 'topLeft', 'bottomRight', 'bottomLeft'];
  24. let opts = {
  25. title: 'Title ies',
  26. content:
  27. 'Hi,Bytedance dance dance dance dance dance dance dance dance dance dance dance dance dance dance dance',
  28. duration: 3,
  29. };
  30. function randomPos() {
  31. return pos[Math.floor(Math.random() * pos.length)];
  32. }
  33. export const _Notification = () => (
  34. <div>
  35. <Button
  36. type="primary"
  37. onClick={() =>
  38. Notification.info({ ...opts, content: '我三秒后会被关闭', position: randomPos() })
  39. }
  40. >
  41. After 3s
  42. </Button>
  43. <Button
  44. type="primary"
  45. onClick={() => Notification.open({ ...opts, duration: 2, position: 'topRight' })}
  46. >
  47. After 2s
  48. </Button>
  49. </div>
  50. );
  51. _Notification.story = {
  52. name: 'notification',
  53. };
  54. export const ManaulOpenClose = () => (
  55. <div>
  56. <Button type="primary" onClick={fnc}>
  57. Duration:0
  58. </Button>
  59. <Button type="primary" onClick={remove}>
  60. remove duration:
  61. </Button>
  62. </div>
  63. );
  64. ManaulOpenClose.story = {
  65. name: 'manaul open & close',
  66. };
  67. export const Position = () => {
  68. let opts = {
  69. duration: 0,
  70. position: 'topRight',
  71. content: 'semi-ui-notification',
  72. title: 'Hi bytedance',
  73. };
  74. return (
  75. <>
  76. <Button onClick={() => Notification.info({ ...opts, position: 'top' })}>top</Button>
  77. <Button onClick={() => Notification.info({ ...opts, position: 'topLeft' })}>topLeft</Button>
  78. <Button onClick={() => Notification.info(opts)}>topRight</Button>
  79. <Button onClick={() => Notification.info({ ...opts, position: 'bottom' })}>bottom</Button>
  80. <Button onClick={() => Notification.info({ ...opts, position: 'bottomRight' })}>
  81. bottomRight
  82. </Button>
  83. <Button onClick={() => Notification.info({ ...opts, position: 'bottomLeft' })}>
  84. bottomLeft
  85. </Button>
  86. </>
  87. );
  88. };
  89. export const CustomIcon = () => {
  90. let opts = {
  91. duration: 0,
  92. position: 'topRight',
  93. content: 'semi-ui-notification',
  94. title: 'Hi bytedance',
  95. };
  96. return (
  97. <>
  98. <Button onClick={() => Notification.info({ ...opts, position: 'top' })}>info</Button>
  99. <Button onClick={() => Notification.warning({ ...opts, position: 'top' })}>warning</Button>
  100. <Button
  101. onClick={() =>
  102. Notification.info({
  103. ...opts,
  104. position: 'top',
  105. icon: <IconWifi style={{ color: 'green' }} />,
  106. })
  107. }
  108. >
  109. wifi
  110. </Button>
  111. <Button
  112. onClick={() =>
  113. Notification.info({
  114. ...opts,
  115. position: 'bottomLeft',
  116. icon: <IconToutiaoLogo style={{ color: 'red' }} />,
  117. })
  118. }
  119. >
  120. toutiao
  121. </Button>
  122. </>
  123. );
  124. };
  125. export const EventDemo = () => {
  126. let opts = {
  127. duration: 0,
  128. position: 'topRight',
  129. content: 'semi-ui-notification',
  130. title: 'Hi bytedance',
  131. onClick: e => console.log('clicking'),
  132. onClose: e => console.log('closing da da da...'),
  133. onCloseClick: e => console.log('you closed me'),
  134. };
  135. return (
  136. <>
  137. <Button onClick={() => Notification.info({ ...opts, position: 'top' })}>info</Button>
  138. <Button onClick={() => Notification.warning({ ...opts, position: 'top' })}>warning</Button>
  139. <Button
  140. onClick={() =>
  141. Notification.info({
  142. ...opts,
  143. position: 'top',
  144. icon: <IconWifi style={{ color: 'green' }} />,
  145. })
  146. }
  147. >
  148. wifi
  149. </Button>
  150. <Button
  151. onClick={() =>
  152. Notification.info({
  153. ...opts,
  154. position: 'bottomLeft',
  155. icon: <IconToutiaoLogo style={{ color: 'red' }} />,
  156. })
  157. }
  158. >
  159. toutiao
  160. </Button>
  161. </>
  162. );
  163. };
  164. class Demo extends React.Component {
  165. constructor() {
  166. super();
  167. this.state = { test: 0 };
  168. this.onClick = this.onClick.bind(this);
  169. }
  170. componentDidMount() {
  171. this.onClick();
  172. }
  173. onClick() {
  174. this.setState(
  175. {
  176. test: 1,
  177. },
  178. () => {
  179. this.setState(
  180. {
  181. test: 2,
  182. },
  183. () => {
  184. this.id = Notification.success({
  185. title: 'success',
  186. duration: 3,
  187. });
  188. }
  189. );
  190. }
  191. );
  192. }
  193. render() {
  194. return <Button>test</Button>;
  195. }
  196. }
  197. export const _UseNotificationDemo = () => <UseNotificationDemo />;
  198. _UseNotificationDemo.story = {
  199. name: 'useNotification demo',
  200. };
  201. export const AsyncCallback = () => <Demo />;
  202. AsyncCallback.story = {
  203. name: '二次异步回调'
  204. }