Skip to content

Commit

Permalink
feat: info tooltip in BuiInput & BuiSelect, on hover as default (#39)
Browse files Browse the repository at this point in the history
* feat: info tooltip in BuiInput & BuiSelect, on hover as default (refs #DH-1089)

* refactoring: removed unused import
  • Loading branch information
victoriakaropva authored Feb 1, 2024
1 parent a57c454 commit 306aa1a
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/components/BuiInput/BuiInput.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,27 @@ const modelForDisabling = ref(false)
/>
</div>
</Variant>
<Variant title="Tooltip on hover">
<div class="p-2">
<BuiInput
label="Default"
v-model="model"
info-tooltip-event="hover"
info-tooltip="My tooltip info <a href='https://stsoft.ru'>ST Soft </a>"
/>
</div>
</Variant>
<Variant title="Tooltip on click for required">
<div class="p-2">
<BuiInput
label="Kubernetes Api Endpoint Port"
placeholder="1-65535"
:required="true"
info-tooltip-event="click"
info-tooltip="e.g. 6440"
v-model="model"
/>
</div>
</Variant>
</Story>
</template>
12 changes: 11 additions & 1 deletion src/components/BuiInput/BuiInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<div class="flex flex-col justify-center gap-1">
<label v-if="label" :class="labelClasses">
{{ label }}
<BuiTooltip
v-if="infoTooltip"
:event="infoTooltipEvent"
variant="info"
:content="infoTooltip"
/>
<RequiredIcon v-if="required && !disabled" />
</label>
<div class="flex relative">
Expand Down Expand Up @@ -38,6 +44,7 @@
import { computed, ref, watch } from 'vue'
import { twMerge } from 'tailwind-merge'
import RequiredIcon from '../CommonElements/RequiredIcon.vue'
import BuiTooltip from '../BuiTooltip/BuiTooltip.vue'
type ValidationStatus = 'success' | 'error'
interface InputProps {
Expand All @@ -48,6 +55,8 @@ interface InputProps {
validationStatus?: ValidationStatus | null
placeholder?: string | undefined
hasForcedValidation?: boolean
infoTooltip?: string
infoTooltipEvent?: 'hover' | 'click'
}
const props = withDefaults(defineProps<InputProps>(), {
Expand All @@ -56,7 +65,8 @@ const props = withDefaults(defineProps<InputProps>(), {
value: '',
required: false,
validationStatus: null,
placeholder: ''
placeholder: '',
infoTooltipEvent: 'hover'
})
const emit = defineEmits(['focus', 'blur', 'input'])
Expand Down
19 changes: 19 additions & 0 deletions src/components/BuiSelect/BuiSelect.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,24 @@ const options = [
<template #validationMessage> Do not select 'One'</template>
</BuiSelect>
</Variant>
<Variant title="Info tooltip on hover">
<BuiSelect
label="Select option"
:options="options"
v-model="model"
info-tooltip="My tooltip"
info-tooltip-event="hover"
/>
</Variant>
<Variant title="Required with info tooltip on click">
<BuiSelect
label="Select right option (2)"
:options="options"
v-model="model"
info-tooltip-event="click"
info-tooltip="My tooltip"
:required="true"
/>
</Variant>
</Story>
</template>
12 changes: 11 additions & 1 deletion src/components/BuiSelect/BuiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<label class="relative">
<span v-if="label" :class="labelClasses">
{{ label }}
<BuiTooltip
v-if="infoTooltip"
:event="infoTooltipEvent"
variant="info"
:content="infoTooltip"
/>
<RequiredIcon v-if="required && !disabled" />
</span>

Expand Down Expand Up @@ -33,6 +39,7 @@
import { computed, ref, watch } from 'vue'
import { twMerge } from 'tailwind-merge'
import RequiredIcon from '@/components/CommonElements/RequiredIcon.vue'
import BuiTooltip from '../BuiTooltip/BuiTooltip.vue'
type ValidationStatus = 'success' | 'error'
type OptionsType = {
Expand All @@ -48,6 +55,8 @@ interface InputProps {
required?: boolean
hasForcedValidation?: boolean
validationStatus?: ValidationStatus | null
infoTooltip?: string
infoTooltipEvent?: 'hover' | 'click'
}
const props = withDefaults(defineProps<InputProps>(), {
value: '',
Expand All @@ -57,7 +66,8 @@ const props = withDefaults(defineProps<InputProps>(), {
disabled: false,
required: false,
hasForcedValidation: false,
validationStatus: null
validationStatus: null,
infoTooltipEvent: 'hover'
})
const emit = defineEmits(['input', 'blur'])
Expand Down
18 changes: 15 additions & 3 deletions src/components/BuiTooltip/BuiTooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@ import { onMounted } from 'vue'
import InfoIcon from '@/components/CommonElements/InfoIcon.vue'
import { nanoid } from 'nanoid'
const props = defineProps<{ content: string; variant: 'info' | 'id' | 'slot'; id?: string }>()
const props = withDefaults(
defineProps<{
content: string
variant: 'info' | 'id' | 'slot'
event: 'click' | 'hover'
id?: string
}>(),
{
content: '',
variant: 'info',
event: 'hover'
}
)
const componentId = nanoid()
onMounted(() => {
const selector = props.variant === 'id' && props.id ? `#${props.id}` : `#${componentId}`
tippy(selector, {
trigger: 'click',
trigger: props.event === 'hover' ? undefined : 'click',
interactive: true,
allowHTML: true,
arrow: false,
Expand All @@ -24,7 +36,7 @@ onMounted(() => {
</script>

<template>
<div class="relative">
<div>
<div
v-if="variant === 'info' || (variant === 'id' && !id)"
class="w-fit relative text-primary-500 hover:text-primary-550 py-1 cursor-pointer"
Expand Down
3 changes: 2 additions & 1 deletion src/components/BuiTooltip/BuiTooltips.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import BuiTooltip from '@/components/BuiTooltip/BuiTooltip.vue'

<template>
<Story title="BuiTooltip" autoPropsDisabled :layout="{ type: 'grid', width: '100%' }">
<Variant title="variant 'info'">
<Variant title="variant 'info' on hover">
<br /><br />
<br /><br />
<BuiTooltip
variant="info"
event="hover"
content="My tooltip info <a href='https://stsoft.ru'>ST Soft</a>"
/>
<br />
Expand Down

0 comments on commit 306aa1a

Please sign in to comment.