-
Notifications
You must be signed in to change notification settings - Fork 530
/
Highlighter.vue
72 lines (69 loc) · 1.43 KB
/
Highlighter.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<template>
<span :class="suit()">
<component
v-for="({ value, isHighlighted }, index) in parsedHighlights"
:class="[isHighlighted && suit('highlighted')]"
:key="index"
:is="isHighlighted ? highlightedTagName : TextNode"
>{{ value }}</component
>
</span>
</template>
<script>
import { parseAlgoliaHit } from '../util/parseAlgoliaHit';
import { getDefaultSlot, renderCompat, isVue3 } from '../util/vue-compat';
const TextNode = isVue3
? (props, context) => context.slots.default()
: {
render: renderCompat(function () {
return getDefaultSlot(this);
}),
};
export default {
name: 'AisHighlighter',
props: {
hit: {
type: Object,
required: true,
},
attribute: {
type: String,
required: true,
},
highlightedTagName: {
type: String,
default: 'mark',
},
suit: {
type: Function,
required: true,
},
highlightProperty: {
type: String,
required: true,
},
preTag: {
type: String,
required: true,
},
postTag: {
type: String,
required: true,
},
},
data() {
return { TextNode };
},
computed: {
parsedHighlights() {
return parseAlgoliaHit({
attribute: this.attribute,
hit: this.hit,
highlightProperty: this.highlightProperty,
preTag: this.preTag,
postTag: this.postTag,
});
},
},
};
</script>