@citizenplane/pimp 10.0.5 → 10.0.6
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/dist/pimp.es.js +150 -150
- package/dist/pimp.umd.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/CpTabs.vue +24 -12
- package/src/stories/CpTabs.stories.ts +1 -1
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
</template>
|
|
26
26
|
|
|
27
27
|
<script setup lang="ts">
|
|
28
|
-
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
28
|
+
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
29
29
|
|
|
30
30
|
type EmitType = {
|
|
31
31
|
(e: 'onTabClick', index: number): void
|
|
@@ -41,9 +41,7 @@ interface Props {
|
|
|
41
41
|
}[]
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
45
|
-
defaultActiveIndex: 0,
|
|
46
|
-
})
|
|
44
|
+
const props = withDefaults(defineProps<Props>(), { defaultActiveIndex: 0 })
|
|
47
45
|
|
|
48
46
|
const emit = defineEmits<EmitType>()
|
|
49
47
|
|
|
@@ -88,15 +86,16 @@ const getUnderlineElement = () => {
|
|
|
88
86
|
const setUnderlineStyle = () => {
|
|
89
87
|
const activeTabElement = getActiveTabElement()
|
|
90
88
|
const underlineElement = getUnderlineElement()
|
|
89
|
+
const containerElement = cpTabsElement.value
|
|
91
90
|
|
|
92
|
-
if (!activeTabElement) return
|
|
91
|
+
if (!activeTabElement || !underlineElement || !containerElement) return
|
|
93
92
|
|
|
94
|
-
const
|
|
93
|
+
const tabRect = activeTabElement.getBoundingClientRect()
|
|
94
|
+
const containerRect = containerElement.getBoundingClientRect()
|
|
95
|
+
const left = tabRect.left - containerRect.left + containerElement.scrollLeft
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
underlineElement.style.width = `${clientWidth}px`
|
|
99
|
-
underlineElement.style.transform = `translate3d(${offsetLeft}px, 0, 0)`
|
|
97
|
+
underlineElement.style.width = `${tabRect.width}px`
|
|
98
|
+
underlineElement.style.transform = `translate3d(${left}px, 0, 0)`
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
const scrollToActiveElement = () => {
|
|
@@ -111,11 +110,12 @@ onBeforeUnmount(() => window.removeEventListener('resize', setUnderlineStyle))
|
|
|
111
110
|
onMounted(() => {
|
|
112
111
|
window.addEventListener('resize', setUnderlineStyle)
|
|
113
112
|
|
|
114
|
-
setUnderlineStyle()
|
|
115
113
|
activeTabIndex.value = props.defaultActiveIndex
|
|
114
|
+
|
|
115
|
+
nextTick(setUnderlineStyle)
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
-
watch(activeTabIndex, () => setUnderlineStyle
|
|
118
|
+
watch(activeTabIndex, () => nextTick(setUnderlineStyle))
|
|
119
119
|
|
|
120
120
|
watch(
|
|
121
121
|
() => props.defaultActiveIndex,
|
|
@@ -222,4 +222,16 @@ watch(
|
|
|
222
222
|
border-radius: fn.px-to-rem(4);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
+
|
|
226
|
+
@include mx.media-query-max(768px) {
|
|
227
|
+
.cpTabs {
|
|
228
|
+
&__activeUnderline {
|
|
229
|
+
top: auto;
|
|
230
|
+
bottom: auto;
|
|
231
|
+
height: 100%;
|
|
232
|
+
border-radius: var(--pimp-radius-md);
|
|
233
|
+
opacity: 0.14;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
225
237
|
</style>
|
|
@@ -40,7 +40,7 @@ export const Default: Story = {
|
|
|
40
40
|
args: {
|
|
41
41
|
defaultActiveIndex: 0,
|
|
42
42
|
isLoading: false,
|
|
43
|
-
tabs: [{ title: 'Tab 1' }, { title: 'Tab 2' }, { title: 'Tab 3' }],
|
|
43
|
+
tabs: [{ title: 'Tab 1' }, { title: 'Tab 2' }, { title: 'Tab 3' }, { title: 'Tab 4' }],
|
|
44
44
|
onOnTabClick: action('tab-clicked'),
|
|
45
45
|
},
|
|
46
46
|
render: defaultRender,
|