app-safe-header.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view class="app-safe-header" :style="headerStyle">
  3. <view class="app-safe-header__safe" />
  4. <view class="app-safe-header__nav">
  5. <view class="app-safe-header__left">
  6. <slot name="left" />
  7. </view>
  8. <view class="app-safe-header__title-wrap">
  9. <slot>
  10. <text class="app-safe-header__title">{{ title }}</text>
  11. </slot>
  12. </view>
  13. <view class="app-safe-header__right" />
  14. </view>
  15. </view>
  16. </template>
  17. <script setup>
  18. import { computed } from 'vue'
  19. import { getGlobalSafeArea, buildSafeAreaCssVarsStyle } from '@/utils/safeArea'
  20. const props = defineProps({
  21. title: {
  22. type: String,
  23. default: '',
  24. },
  25. background: {
  26. type: String,
  27. default: 'transparent',
  28. },
  29. })
  30. const headerStyle = computed(() => ({
  31. ...buildSafeAreaCssVarsStyle(getGlobalSafeArea()),
  32. '--sq-header-background': props.background,
  33. }))
  34. </script>
  35. <style scoped lang="scss">
  36. .app-safe-header {
  37. background: var(--sq-header-background);
  38. }
  39. .app-safe-header__safe {
  40. height: var(--sq-safe-top, 20px);
  41. }
  42. .app-safe-header__nav {
  43. height: var(--sq-nav-height, 44px);
  44. display: grid;
  45. grid-template-columns: auto minmax(0, 1fr) var(--sq-capsule-right-safe, 96px);
  46. align-items: center;
  47. box-sizing: border-box;
  48. }
  49. .app-safe-header__left {
  50. min-width: 0;
  51. }
  52. .app-safe-header__title-wrap {
  53. min-width: 0;
  54. }
  55. .app-safe-header__title {
  56. display: block;
  57. overflow: hidden;
  58. text-overflow: ellipsis;
  59. white-space: nowrap;
  60. }
  61. </style>