header.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const html = require('choo/html');
  2. const Component = require('choo/component');
  3. const Account = require('./account');
  4. const assets = require('../../common/assets');
  5. const { platform } = require('../utils');
  6. class Header extends Component {
  7. constructor(name, state, emit) {
  8. super(name);
  9. this.state = state;
  10. this.emit = emit;
  11. this.account = state.cache(Account, 'account');
  12. }
  13. update() {
  14. this.account.render();
  15. return false;
  16. }
  17. createElement() {
  18. let assetMap = {};
  19. if (this.state.ui !== undefined) assetMap = this.state.ui.assets;
  20. else
  21. assetMap = {
  22. icon:
  23. this.state.WEB_UI.CUSTOM_ASSETS.icon !== ''
  24. ? this.state.WEB_UI.CUSTOM_ASSETS.icon
  25. : assets.get('icon.svg'),
  26. wordmark:
  27. this.state.WEB_UI.CUSTOM_ASSETS.wordmark !== ''
  28. ? this.state.WEB_UI.CUSTOM_ASSETS.wordmark
  29. : assets.get('wordmark.svg') + '#logo'
  30. };
  31. const title =
  32. platform() === 'android'
  33. ? html`
  34. <a class="flex flex-row items-center">
  35. <img src="${assetMap.icon}" />
  36. <svg class="w-48">
  37. <use xlink:href="${assetMap.wordmark}" />
  38. </svg>
  39. </a>
  40. `
  41. : html`
  42. <a class="flex flex-row items-center" href="/">
  43. <img
  44. alt="${this.state.translate('title')}"
  45. src="${assetMap.icon}"
  46. />
  47. <svg viewBox="66 0 340 64" class="w-48 md:w-64">
  48. <use xlink:href="${assetMap.wordmark}" />
  49. </svg>
  50. </a>
  51. `;
  52. return html`
  53. <header
  54. class="main-header relative flex-none flex flex-row items-center justify-between w-full px-6 md:px-8 h-16 md:h-24 z-20 bg-transparent"
  55. >
  56. ${title} ${this.account.render()}
  57. </header>
  58. `;
  59. }
  60. }
  61. module.exports = Header;