Header.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import './header.css';
  2. import { createButton } from './Button';
  3. export const createHeader = ({ user, onLogout, onLogin, onCreateAccount }) => {
  4. const header = document.createElement('header');
  5. const wrapper = document.createElement('div');
  6. wrapper.className = 'wrapper';
  7. const logo = `<div>
  8. <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
  9. <g fill="none" fillRule="evenodd">
  10. <path
  11. d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
  12. fill="#FFF" />
  13. <path
  14. d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
  15. fill="#555AB9" />
  16. <path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
  17. </g>
  18. </svg>
  19. <h1>Acme</h1>
  20. </div>`;
  21. wrapper.insertAdjacentHTML('afterbegin', logo);
  22. const account = document.createElement('div');
  23. if (user) {
  24. const welcomeMessage = `<span class="welcome">Welcome, <b>${user.name}</b>!</span>`;
  25. account.innerHTML = welcomeMessage;
  26. account.appendChild(createButton({ size: 'small', label: 'Log out', onClick: onLogout }));
  27. } else {
  28. account.appendChild(createButton({ size: 'small', label: 'Log in', onClick: onLogin }));
  29. account.appendChild(
  30. createButton({
  31. size: 'small',
  32. label: 'Sign up',
  33. onClick: onCreateAccount,
  34. primary: true,
  35. })
  36. );
  37. }
  38. wrapper.appendChild(account);
  39. header.appendChild(wrapper);
  40. return header;
  41. };