Skip to content

Commit

Permalink
Merge pull request #114 from frappe/tabs-component-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik authored Nov 20, 2023
2 parents 958942a + e68e4e1 commit f5186c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
21 changes: 21 additions & 0 deletions src/components/Tabs.story.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Props

### Tabs

It is an array of objects which contains the following attributes:

1. `label` is the name of the tab, it is required.
2. `icon` is the icon to be shown in the tab, it accept component and it is
optional.
3. You can add more attributes which can be used for custom rendering in the tab
header or content.

### Options

Currently, it has only one option `indicatorLeft` which is used to set the left
position of the indicator in case of custom rendering. It is optional and
default value is `20`.

## v-model

It is used to set the active tab or change the active tab. It is required.
18 changes: 9 additions & 9 deletions src/components/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
</Tab>
<div
ref="indicator"
class="absolute -bottom-px h-px bg-gray-900"
:style="{ left: `${indicatorLeftValue}px` }"
class="absolute -bottom-px h-px bg-gray-900 transition-all duration-300 ease-in-out"
:style="{ left: `${indicatorLeft}px` }"
/>
</TabList>
<TabPanels class="flex flex-1 overflow-hidden">
Expand All @@ -45,7 +45,6 @@

<script setup>
import { TabGroup, TabList, Tab, TabPanels, TabPanel } from '@headlessui/vue'
import { TransitionPresets, useTransition } from '@vueuse/core'
import { ref, watch, computed, onMounted, nextTick } from 'vue'
const props = defineProps({
Expand All @@ -57,6 +56,12 @@ const props = defineProps({
type: Number,
default: 0,
},
options: {
type: Object,
default: () => ({
indicatorLeft: 20,
}),
},
})
const emit = defineEmits(['update:modelValue'])
Expand All @@ -70,12 +75,7 @@ const tabRef = ref([])
const indicator = ref(null)
const tabsLength = ref(props.tabs?.length)
let indicatorLeft = ref(0)
const indicatorLeftValue = useTransition(indicatorLeft, {
duration: 250,
ease: TransitionPresets.easeOutCubic,
})
const indicatorLeft = ref(props.options?.indicatorLeft)
function moveIndicator(index) {
if (index >= tabsLength.value) {
Expand Down

0 comments on commit f5186c4

Please sign in to comment.