Skip to content

Commit

Permalink
feat: add position options to tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Sep 5, 2024
1 parent cabfe5e commit 7ba0e5e
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 58 deletions.
20 changes: 12 additions & 8 deletions src/components/Select/WSelect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ describe('WSelect', () => {
label: 'English',
icon: null
},
options: [{
options: [
{
key: 'en',
label: 'English',
icon: null
},{
},
{
key: 'es',
label: 'Español',
icon: null,
icon: null
}
]
},
}
})

expect(wrapper.element).toMatchSnapshot()
Expand All @@ -39,17 +41,19 @@ describe('WSelect', () => {
label: 'English',
icon: Icon
},
options: [{
options: [
{
key: 'en',
label: 'English',
icon: Icon
},{
},
{
key: 'es',
label: 'Español',
icon: Icon,
icon: Icon
}
]
},
}
})

expect(wrapper.element).toMatchSnapshot()
Expand Down
55 changes: 31 additions & 24 deletions src/components/Select/WSelect.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ const meta: any = {
component: WSelect,
tags: ['autodocs'],
argTypes: {
dropdownPosition: { control: 'select', options: dropdownPostions },
dropdownPosition: { control: 'select', options: dropdownPostions }
},
args: {
options: [{
key: 'en',
label: 'English',
icon: null,
},{
key: 'es',
label: 'Español',
icon: null,
}]}
options: [
{
key: 'en',
label: 'English',
icon: null
},
{
key: 'es',
label: 'Español',
icon: null
}
]
}
} satisfies Meta<typeof WSelect>

export default meta
Expand All @@ -34,26 +38,29 @@ export const Default: Story = {
const model = ref({
key: 'en',
label: 'English',
icon: null,
});
icon: null
})

function update($event: any) {
model.value = $event
}
return { args, model, update };

return { args, model, update }
},
template: `<WSelect v-bind="args" v-model="model" @update:model-value="update" />`,
args: {
options: [{
key: 'en',
label: 'English',
icon: null,
},{
key: 'es',
label: 'Español',
icon: Icon,
}]
options: [
{
key: 'en',
label: 'English',
icon: null
},
{
key: 'es',
label: 'Español',
icon: Icon
}
]
}
})
}
}
4 changes: 2 additions & 2 deletions src/components/Select/WSelect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type Option = {key: string, label: string, icon: string | null}
export type Option = { key: string; label: string; icon: string | null }
export enum DropdownPosition {
Top = 'top',
Bottom = 'bottom'
}
export const dropdownPostions = Object.values(DropdownPosition)
export const dropdownPostions = Object.values(DropdownPosition)
26 changes: 13 additions & 13 deletions src/components/Select/WSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<script setup lang="ts">
import vSelect from 'vue-select'
import 'vue-select/dist/vue-select.css'
import { dropdownPostions, DropdownPosition} from './WSelect'
import { dropdownPostions, DropdownPosition } from './WSelect'
import { PropType, computed, DefineComponent, SVGAttributes } from 'vue'
type Option = { key: string; label: string; icon: DefineComponent<SVGAttributes> | null }
Expand All @@ -44,7 +44,7 @@ const model = defineModel()
const props = defineProps({
options: {
type: Array as PropType<Array<Option>>,
required: true,
required: true
},
dropdownPosition: {
type: String as PropType<DropdownPosition>,
Expand All @@ -63,11 +63,12 @@ const props = defineProps({
}
})
const position = computed(() => props.dropdownPosition === DropdownPosition.Top ? '-210%' : '110%')
const position = computed(() =>
props.dropdownPosition === DropdownPosition.Top ? '-210%' : '110%'
)
</script>

<style lang="scss">
.dropdown-enter {
transform: translateY(-8px);
}
Expand All @@ -81,7 +82,7 @@ const position = computed(() => props.dropdownPosition === DropdownPosition.Top
}
.dropdown-leave {
transform: translateY(0px);
transform: translateY(0px);
}
.dropdown-leave-to {
Expand All @@ -90,17 +91,17 @@ const position = computed(() => props.dropdownPosition === DropdownPosition.Top
}
.dropdown-leave-from {
transform: translateY(0);
transform: translateY(0);
}
.dropdown-leave-active {
transition: all .2s cubic-bezier(.42,0,.58,1);
transition-delay: .5s;
transition: all 0.2s cubic-bezier(0.42, 0, 0.58, 1);
transition-delay: 0.5s;
}
.dropdown-enter-active {
transition: all .2s cubic-bezier(.42,0,.58,1);
transition-delay: .5s;
transition: all 0.2s cubic-bezier(0.42, 0, 0.58, 1);
transition-delay: 0.5s;
}
.vs--open {
.vs__open-indicator {
Expand Down Expand Up @@ -145,13 +146,13 @@ const position = computed(() => props.dropdownPosition === DropdownPosition.Top
.vs__dropdown-option {
font-family: 'NeueMachina-Regular', sans-serif;
color: v-bind(hexPrimaryColor)
color: v-bind(hexPrimaryColor);
}
.vs__dropdown-option--highlight {
z-index: 10;
color: v-bind(hexSecondaryColor);
background: v-bind(hexPrimaryColor)
background: v-bind(hexPrimaryColor);
}
.vs__clear,
Expand Down Expand Up @@ -206,4 +207,3 @@ const position = computed(() => props.dropdownPosition === DropdownPosition.Top
// }
// }
</style>

2 changes: 1 addition & 1 deletion src/components/Tooltip/WTooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('WTooltip', () => {
it('renders properly', () => {
const wrapper = mount(WTooltip, {
props: {
bgColor: '#000',
bgColor: '#000'
},
slots: {
main: `<p>Text</p>`,
Expand Down
14 changes: 9 additions & 5 deletions src/components/Tooltip/WTooltip.stories.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type { Meta, StoryObj } from '@storybook/vue3'
import WTooltip from './WTooltip.vue'
import { TooltipPosition, tooltipPostions } from './WTooltip'

const meta: any = {
title: 'Example/WTooltip',
component: WTooltip,
tags: ['autodocs'],
argTypes: {},
argTypes: {
position: { control: 'select', options: tooltipPostions }
},
args: {
bgColor: '#000',
},
position: TooltipPosition.CenterTop
}
} satisfies Meta<typeof WTooltip>

export default meta
Expand All @@ -20,11 +24,11 @@ export const Default: Story = {
setup() {
return { args }
},
template: `<WTooltip v-bind="args"><template #tooltip><p class="text-white-50 w-[200px]">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></template><template #main>
template: `<div class="h-[200px] w-auto flex justify-center items-center"><WTooltip v-bind="args"><template #tooltip><p class="text-white-50 w-[200px]">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></template><template #main>
<span class="text-xs ml-xs">ⓘ</span>
</template></WTooltip>`,
</template></WTooltip></div>`,
args: {
bgColor: 'black-950',
bgColor: 'black-950'
}
})
}
9 changes: 9 additions & 0 deletions src/components/Tooltip/WTooltip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum TooltipPosition {
CenterTop = 'center-top',
RightTop = 'right-top',
LeftTop = 'left-top',
CenterBottom = 'center-bottom',
RightBottom = 'right-bottom',
LeftBottom = 'left-bottom'
}
export const tooltipPostions = Object.values(TooltipPosition)
32 changes: 27 additions & 5 deletions src/components/Tooltip/WTooltip.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
<template>
<div class="group inline relative p-[4px] -p-[4px]">
<div class="group inline relative p-sm -m-sm">
<slot name="main"></slot>
<div
class="tooltip-container hidden min-w-max py-md px-md rounded-lg group-hover:inline hover:inline transition-opacity text-sm rounded-md absolute bottom-md -translate-x-[50%] mb-sm"
:class="tooltipPosition"
class="tooltip-container hidden min-w-max py-md px-md rounded-lg group-hover:inline group-hover:opacity-100 text-sm rounded-md absolute"
>
<slot name="tooltip"></slot>
</div>
</div>
</template>

<script setup>
defineProps({
<script setup lang="ts">
import { TooltipPosition, tooltipPostions } from './WTooltip'
import { PropType, computed } from 'vue'
const props = defineProps({
bgColor: {
type: String,
required: true,
required: true
},
position: {
type: String as PropType<TooltipPosition>,
default: TooltipPosition.CenterTop,
validation(value: TooltipPosition) {
tooltipPostions.includes(value)
}
}
})
const tooltipStypePositions: Record<TooltipPosition, string> = {
[TooltipPosition.CenterTop]: 'bottom-lg -translate-x-[50%]',
[TooltipPosition.CenterBottom]: 'top-lg -translate-x-[50%]',
[TooltipPosition.RightTop]: 'bottom-lg translate-x-[0%]',
[TooltipPosition.RightBottom]: 'top-lg translate-x-[0%]',
[TooltipPosition.LeftTop]: 'bottom-lg -translate-x-[100%]',
[TooltipPosition.LeftBottom]: 'top-lg -translate-x-[100%]'
}
const tooltipPosition = computed(() => {
return tooltipStypePositions[props.position]
})
</script>

Expand Down

0 comments on commit 7ba0e5e

Please sign in to comment.