Page.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import './page.css';
  2. import { createHeader } from './Header';
  3. export const createPage = () => {
  4. const article = document.createElement('article');
  5. let user = null;
  6. let header = null;
  7. const rerenderHeader = () => {
  8. const wrapper = document.getElementsByTagName('article')[0];
  9. wrapper.replaceChild(createHeaderElement(), wrapper.firstChild);
  10. };
  11. const onLogin = () => {
  12. user = { name: 'Jane Doe' };
  13. rerenderHeader();
  14. };
  15. const onLogout = () => {
  16. user = null;
  17. rerenderHeader();
  18. };
  19. const onCreateAccount = () => {
  20. user = { name: 'Jane Doe' };
  21. rerenderHeader();
  22. };
  23. const createHeaderElement = () => {
  24. return createHeader({ onLogin, onLogout, onCreateAccount, user });
  25. };
  26. header = createHeaderElement();
  27. article.appendChild(header);
  28. const section = `
  29. <section>
  30. <h2>Pages in Storybook</h2>
  31. <p>
  32. We recommend building UIs with a
  33. <a
  34. href="https://blog.hichroma.com/component-driven-development-ce1109d56c8e"
  35. target="_blank"
  36. rel="noopener noreferrer">
  37. <strong>component-driven</strong>
  38. </a>
  39. process starting with atomic components and ending with pages.
  40. </p>
  41. <p>
  42. Render pages with mock data. This makes it easy to build and review page states without
  43. needing to navigate to them in your app. Here are some handy patterns for managing page data
  44. in Storybook:
  45. </p>
  46. <ul>
  47. <li>
  48. Use a higher-level connected component. Storybook helps you compose such data from the
  49. "args" of child component stories
  50. </li>
  51. <li>
  52. Assemble data in the page component from your services. You can mock these services out
  53. using Storybook.
  54. </li>
  55. </ul>
  56. <p>
  57. Get a guided tutorial on component-driven development at
  58. <a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
  59. Storybook tutorials
  60. </a>
  61. . Read more in the
  62. <a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
  63. .
  64. </p>
  65. <div class="tip-wrapper">
  66. <span class="tip">Tip</span>
  67. Adjust the width of the canvas with the
  68. <svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
  69. <g fill="none" fillRule="evenodd">
  70. <path
  71. d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0
  72. 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0
  73. 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
  74. id="a"
  75. fill="#999" />
  76. </g>
  77. </svg>
  78. Viewports addon in the toolbar
  79. </div>
  80. </section>
  81. `;
  82. article.insertAdjacentHTML('beforeend', section);
  83. return article;
  84. };