Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

layout

v1.1.32arrow_drop_down
v1.1.32
STATUS
Passing
DOWNLOADS
3
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
6 months ago
SIZE
1 KB
1 contributor
Install layout as a package?
Copied
npm i @bit/myliang.fish-ui.layout
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Files
Layout.vue
56 Lines(56 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<template>
  <div :class="['fish layout has-sider', {'responsive': responsive}]"  v-if="sider === 'tl' || sider === 'tr'">
    <div class="toggle" :style="{'top': `${siderToggleTop}px`}" ref="siderToggle" @click="toggleHandler" v-if="responsive"><i class="fa fa-align-justify"></i></div>
    <div class="sider" v-if="sider === 'tl'"><slot name="sider"></slot></div>
    <div class="fish layout">
      <div class="header" ref="header"><slot name="header"></slot></div>
      <div class="content"><slot name="content"></slot></div>
      <div class="footer" v-if="$slots.footer"><slot name="footer"></slot></div>
    </div>
    <div class="sider" v-if="sider === 'tr'"><slot name="sider"></slot></div>
  </div>
  <div :class="['fish layout']" v-else>
    <div class="header" ref="header"><slot name="header"></slot></div>
    <div :class="['fish layout has-sider', {'responsive': responsive}]" v-if="sider">
      <div class="toggle" :style="{'top': `${siderToggleTop}px`}" ref="siderToggle" @click="toggleHandler" v-if="responsive"><i class="fa fa-align-justify"></i></div>
      <div class="sider" v-if="sider === 'l'" ref="sider"><slot name="sider"></slot></div>
      <div class="content"><slot name="content"></slot></div>
      <div class="sider" v-if="sider === 'r'"><slot name="sider"></slot></div>
    </div>
    <div class="content" v-else><slot name="content"></slot></div>
    <div class="footer" v-if="$slots.footer"><slot name="footer"></slot></div>
  </div>
</template>
<script>
  export default {
    name: 'fish-layout',
    props: {
      sider: { type: String },
      responsive: { type: Boolean, default: false }
    },
    data () {
      return {
        siderToggleTop: 0
      }
    },
    mounted () {
      if (this.responsive) {
        const headerHeight = this.$refs.header.offsetHeight
        const siderToggleHeight = this.$refs.siderToggle.offsetHeight
        this.siderToggleTop = headerHeight - siderToggleHeight / 2
      }
    },
    methods: {
      toggleHandler () {
        let sider = this.$refs.sider
        if (sider.style.display === 'block') {
          sider.style.display = 'none'
          this.$refs.siderToggle.style.left = '0px'
        } else {
          sider.style.display = 'block'
          this.$refs.siderToggle.style.left = `${sider.offsetWidth}px`
        }
      }
    }
  }
</script>