index.jsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React, { useContext, useCallback } from 'react';
  2. import useNotification from '../../useNotification';
  3. import { Button, ConfigProvider } from '../../../index';
  4. import Context from './context';
  5. function App({ children, globalVars }) {
  6. return (
  7. <div data-cy="notice-container">
  8. <Context.Provider value={{ title: '1111', ...globalVars }}>{children}</Context.Provider>
  9. </div>
  10. );
  11. }
  12. export default function Demo() {
  13. const [notice, elements] = useNotification();
  14. const config = {
  15. content: 'Hello World',
  16. position: 'top',
  17. title: <Context.Consumer>{({ title }) => <strong>{title}</strong>}</Context.Consumer>,
  18. duration: 0,
  19. };
  20. const addNotice = () => {
  21. const id1 = notice.info(config);
  22. const id2 = notice.success(config);
  23. const id3 = notice.warning(config);
  24. const id4 = notice.error(config);
  25. const id5 = notice.open(config);
  26. // setTimeout(() => {
  27. // notice.close(id5);
  28. // }, 1000);
  29. };
  30. return (
  31. <div>
  32. <App globalVars={{ title: '2222' }}>{elements}</App>
  33. <div>
  34. <Button onClick={addNotice}>Add Notice</Button>
  35. </div>
  36. </div>
  37. );
  38. }