@phoenix-cg/v-tabs 0.1.0 → 0.1.1-5.beta-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@phoenix-cg/v-tabs",
3
- "version": "0.1.0",
3
+ "version": "0.1.15.beta-0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
7
- "build": "vue-cli-service build",
7
+ "build": "vue-cli-service build --target lib --name v-tabs src/export.js",
8
8
  "test:unit": "vue-cli-service test:unit",
9
- "lint": "vue-cli-service lint",
10
- "build-lib": "vue-cli-service build --target lib --name v-tabs src/export.js"
9
+ "lint": "vue-cli-service lint"
11
10
  },
12
11
  "dependencies": {
13
12
  "core-js": "^3.6.5",
@@ -19,13 +18,11 @@
19
18
  "@vue/cli-plugin-eslint": "~4.5.0",
20
19
  "@vue/cli-plugin-unit-jest": "~4.5.0",
21
20
  "@vue/cli-service": "~4.5.0",
22
- "@vue/eslint-config-prettier": "^6.0.0",
23
21
  "@vue/test-utils": "^1.0.3",
24
22
  "babel-eslint": "^10.1.0",
25
23
  "eslint": "^6.7.2",
26
24
  "eslint-plugin-prettier": "^3.1.3",
27
25
  "eslint-plugin-vue": "^6.2.2",
28
- "prettier": "^1.19.1",
29
26
  "vue-template-compiler": "^2.6.11"
30
27
  },
31
28
  "description": "## Project setup ``` npm install ```",
@@ -1,100 +1,152 @@
1
- <template>
2
- <div class="v-tabs" :class="[`__${direction}`]">
3
- <div
4
- v-for="tab in list"
5
- :key="tab[trackBy]"
6
- @click="handleTabSelect(tab, event)"
7
- ref="tabs"
8
- class="v-tabs_tab"
9
- :class="{ __active: value && value[trackBy] === tab[trackBy] }"
10
- >
11
- <slot name="single-tab" v-bind:tab="tab">
12
- {{ tab.title || '' }}
13
- </slot>
14
- </div>
15
- <div v-if="withSlider" :style="sliderStyle" class="v-tabs_slider"></div>
16
- </div>
17
- </template>
18
-
19
- <script>
20
- export default {
21
- props: {
22
- direction: {
23
- type: String,
24
- default: 'horizontal'
25
- },
26
- trackBy: {
27
- type: String,
28
- default: 'id'
29
- },
30
- list: {
31
- type: Array,
32
- required: true
33
- },
34
- value: {
35
- type: Object
36
- },
37
- selectFirst: {
38
- type: Boolean,
39
- default: true
40
- },
41
- withSlider: {
42
- type: Boolean,
43
- default: false
44
- }
45
- },
46
- data () {
47
- return {
48
- sliderStyle: {}
49
- }
50
- },
51
- mounted () {
52
- if (this.selectFirst && this.list.length && !this.value) {
53
- this.handleTabSelect(this.list[0])
54
- }
55
- },
56
- methods: {
57
- async handleTabSelect (tab) {
58
- this.$emit('input', tab)
59
- if (this.withSlider) {
60
- await this.$nextTick
61
- const { left: tabsLeft } = this.$el.getBoundingClientRect()
62
- const [currentTabEl] = this.$el.getElementsByClassName('__active')
63
- const {
64
- left: currentTabLeft,
65
- width
66
- } = currentTabEl.getBoundingClientRect();
67
- const leftPoisiton = currentTabLeft - tabsLeft
68
- this.sliderStyle = {
69
- transform: `translateX(${leftPoisiton}px)`,
70
- width: `${width}px`
71
- }
72
- }
73
- }
74
- }
75
- }
76
- </script>
77
-
78
- <style>
79
- .v-tabs {
80
- display: flex;
81
- position: relative;
82
- }
83
- .v-tabs_tab {
84
- padding: 10px 20px;
85
- background: #ddd;
86
- cursor: pointer;
87
- user-select: none;
88
- }
89
- .v-tabs_tab.__active {
90
- background: rgb(182, 181, 181);
91
- }
92
- .v-tabs_slider {
93
- position: absolute;
94
- height: 2px;
95
- background: #000;
96
- left: 0;
97
- bottom: 0;
98
- transition: all .2s ease-in-out;
99
- }
100
- </style>
1
+ <template>
2
+ <div class="v-tabs" :class="[`__${direction}`]">
3
+ <div class="v-tabs_inner">
4
+ <div
5
+ v-for="tab in list"
6
+ :key="tab[trackBy]"
7
+ ref="tabs"
8
+ class="v-tabs_tab"
9
+ :data-id="tab[trackBy]"
10
+ :class="{
11
+ __active: value && value[trackBy] === tab[trackBy],
12
+ _disabled: tab && tab._disabled
13
+ }"
14
+ @click="handleTabSelect(tab, $event)"
15
+ >
16
+ <slot name="single-tab" :tab="tab">
17
+ <template v-if="wrapTitle">
18
+ <div class="v-tabs_tab_title">
19
+ {{ tab[label] || "" }}
20
+ </div>
21
+ </template>
22
+ <template v-else>
23
+ {{ tab[label] || "" }}
24
+ </template>
25
+ </slot>
26
+ </div>
27
+ </div>
28
+ <div v-if="withSlider" :style="sliderStyle" class="v-tabs_slider" />
29
+ </div>
30
+ </template>
31
+
32
+ <script>
33
+ export default {
34
+ props: {
35
+ direction: {
36
+ type: String,
37
+ default: 'horizontal'
38
+ },
39
+ trackBy: {
40
+ type: String,
41
+ default: 'id'
42
+ },
43
+ label: {
44
+ type: String,
45
+ default: 'title'
46
+ },
47
+ list: {
48
+ type: Array,
49
+ required: true
50
+ },
51
+ value: {
52
+ type: Object
53
+ },
54
+ selectFirst: {
55
+ type: Boolean,
56
+ default: true
57
+ },
58
+ withSlider: {
59
+ type: Boolean,
60
+ default: false
61
+ },
62
+ initialTab: {
63
+ type: [Number, String],
64
+ default: null
65
+ },
66
+ wrapTitle: {
67
+ type: Boolean,
68
+ default: false
69
+ }
70
+ },
71
+ data () {
72
+ return {
73
+ sliderStyle: {}
74
+ }
75
+ },
76
+ mounted () {
77
+ if (this.selectFirst && this.list.length && !this.value) {
78
+ this.handleTabSelect(this.list[0])
79
+ }
80
+ if (this.initialTab && this.list.length && !this.value) {
81
+ const tab = this.list.find(tab => tab[this.trackBy] === this.initialTab)
82
+ tab && this.handleTabSelect(tab)
83
+ }
84
+ },
85
+ watch: {
86
+ value () {
87
+ this.withSlider && this.calcSlider()
88
+ }
89
+ },
90
+ methods: {
91
+ handleTabSelect (tab) {
92
+ this.$emit('input', tab)
93
+ this.calcSlider()
94
+ },
95
+ async calcSlider () {
96
+ if (!this.withSlider) {
97
+ return
98
+ }
99
+ await this.$nextTick()
100
+ const { left: tabsLeft } = this.$el.getBoundingClientRect()
101
+ const [currentTabEl] = this.$el.getElementsByClassName('__active')
102
+ const {
103
+ left: currentTabLeft,
104
+ width
105
+ } = currentTabEl.getBoundingClientRect()
106
+ const widthTabs = this.$el.scrollWidth
107
+ const screenWidth = window.innerWidth
108
+ const tabsLeftScroll = this.$el.scrollLeft
109
+ let leftPoisiton = null
110
+ if (widthTabs > screenWidth) {
111
+ leftPoisiton = currentTabLeft - tabsLeftScroll - tabsLeft
112
+ } else {
113
+ leftPoisiton = currentTabLeft - tabsLeft
114
+ }
115
+ this.sliderStyle = {
116
+ transform: `translateX(${leftPoisiton}px)`,
117
+ width: `${width}px`
118
+ }
119
+ }
120
+ }
121
+ }
122
+ </script>
123
+
124
+ <style>
125
+ .v-tabs {
126
+ position: relative;
127
+ }
128
+ .v-tabs_inner {
129
+ display: flex;
130
+ }
131
+ .v-tabs_tab {
132
+ padding: 10px 20px;
133
+ background: #ddd;
134
+ cursor: pointer;
135
+ user-select: none;
136
+ }
137
+ .v-tabs_tab.__active {
138
+ background: rgb(182, 181, 181);
139
+ }
140
+ .v-tabs.__disabled {
141
+ pointer-events: none;
142
+ opacity: 0.5;
143
+ }
144
+ .v-tabs_slider {
145
+ position: absolute;
146
+ height: 2px;
147
+ background: #000;
148
+ left: 0;
149
+ bottom: 0;
150
+ transition: all 0.2s ease-in-out;
151
+ }
152
+ </style>
package/src/export.js CHANGED
@@ -1,3 +1,3 @@
1
- import VTabs from './components/VTabs'
2
-
1
+ import VTabs from './components/VTabs'
2
+
3
3
  export default VTabs