Skip to content

Commit

Permalink
feat: use fixed occurrences width
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Jul 23, 2024
1 parent 735461a commit 3dbec4e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const disabledNext = computed(() => props.activeIndex === props.occurrences || p
@next="$emit('update:activeIndex', activeIndex + 1)"
/>
<document-local-search-occurrences
v-if="modelValue"
:hidden="!modelValue"
:active-index="activeIndex"
:occurrences="occurrences"
class="ms-2 align-self-center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const props = defineProps({
},
occurrences: {
type: Number,
default: null
default: 0
},
hidden: {
type: Boolean
},
maxWidth: {
type: String,
Expand All @@ -26,25 +29,27 @@ const label = computed(() => {
return t('documentLocalSearchOccurrences.label', { activeIndex, occurrences })
})
const show = computed(() => {
return props.occurrences !== null
})
const style = computed(() => {
return { maxWidth: props.maxWidth }
})
const key = computed(() => {
return `${props.activeIndex}-${props.occurrences}`
})
const classList = computed(() => {
return {
'document-local-search-occurrences--hidden': props.hidden
}
})
</script>

<template>
<div
v-if="show"
:key="key"
v-ellipsis-tooltip="{ title: label }"
class="document-local-search-occurrences"
:class="classList"
:style="style"
>
{{ label }}
Expand All @@ -56,5 +61,10 @@ const key = computed(() => {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
&--hidden {
visibility: hidden;
}
}
</style>
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import DocumentLocalSearch from '@/components/Document/DocumentLocalSearch/DocumentLocalSearch'

export default {
title: 'Components/Document/DocumentLocalSearch/DocumentLocalSearch',
title: 'Components/Document/DocumentLocalSearch/DocumentLocalSearchOccurences',
component: DocumentLocalSearch,
tags: ['autodocs'],
args: {
modelValue: '',
activeIndex: 0,
occurrences: 1478
activeIndex: 0
},
render: (args) => ({
components: {
Expand All @@ -17,9 +16,15 @@ export default {
template: `
<document-local-search
v-bind="args"
:occurrences="occurrences"
@update:activeIndex="($event) => args.activeIndex = $event"
/>
`
`,
computed: {
occurrences() {
return Math.max(0, 16e4 - String(this.args.modelValue).length * 1e4)
}
}
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import DocumentLocalSearchOccurrences from '@/components/Document/DocumentLocalSearch/DocumentLocalSearchOccurrences'

export default {
title: 'Components/Document/DocumentLocalSearch/DocumentLocalSearchOccurrences',
component: DocumentLocalSearchOccurrences,
tags: ['autodocs'],
args: {
activeIndex: 0,
occurrences: 1478
}
}

export const Default = {}

0 comments on commit 3dbec4e

Please sign in to comment.