Skip to content

Commit

Permalink
feat: add widget field facets entry
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Oct 4, 2024
1 parent 8d28ced commit 7cde9e2
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ declare module 'vue' {
WidgetDuplicates: typeof import('./src/components/Widget/WidgetDuplicates.vue')['default']
WidgetEmpty: typeof import('./src/components/Widget/WidgetEmpty.vue')['default']
WidgetEntities: typeof import('./src/components/Widget/WidgetEntities.vue')['default']
WidgetFieldFacetEntry: typeof import('./src/components/Widget/WidgetFieldFacetEntry.vue')['default']
WidgetFieldFacets: typeof import('./src/components/Widget/WidgetFieldFacets.vue')['default']
WidgetFieldFacetsEntry: typeof import('./src/components/Widget/WidgetFieldFacetsEntry.vue')['default']
WidgetFileBarometer: typeof import('./src/components/Widget/WidgetFileBarometer.vue')['default']
WidgetListGroup: typeof import('./src/components/Widget/WidgetListGroup.vue')['default']
WidgetNames: typeof import('./src/components/Widget/WidgetNames.vue')['default']
Expand Down
123 changes: 123 additions & 0 deletions src/components/Widget/WidgetFieldFacetsEntry.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<script setup>
import { computed } from 'vue'
import { round } from 'lodash'
import { PhosphorIcon } from '@icij/murmur-next'
import DisplayNumber from '@/components/Display/DisplayNumber'
const {
count = 0,
total = 0,
to = null
} = defineProps({
label: { type: String, required: true },
count: { type: Number },
total: { type: Number },
to: { type: Object }
})
const is = computed(() => {
return to ? 'router-link' : 'span'
})
const totalPercentage = computed(() => {
if (total > 0) {
return round((count / total) * 100, 2) + '%'
}
return '0%'
})
const barStyle = computed(() => {
return { width: totalPercentage.value }
})
</script>

<template>
<component :is="is" class="widget-field-facets-entry" :to="to">
<div class="d-flex align-items-center flex-truncate">
<div class="widget-field-facets-entry__label text-truncate">
<slot>{{ label }}</slot>
</div>
<span class="widget-field-facets-entry__count ms-auto flex-shrink-0">
<phosphor-icon
name="magnifying-glass"
aria-hidden="true"
weight="bold"
class="me-2 flex-shrink-0 widget-field-facets-entry__count__icon"
/>
<slot name="count" v-bind="{ count }">
<display-number :value="count" />
</slot>
</span>
</div>
<div class="widget-field-facets-entry__bar" :style="barStyle"></div>
</component>
</template>

<style lang="scss" scoped>
@keyframes slidingBar {
0% {
max-width: 0;
}
100% {
max-width: 100%;
}
}
.widget-field-facets-entry {
color: var(--bs-body-color);
background: transparent;
padding: $spacer-xs 0 $spacer-sm;
position: relative;
display: block;
&[href] {
color: var(--bs-link-color);
&:hover .widget-field-facets-entry__count {
color: var(--bs-white);
background: var(--bs-action);
border-radius: var(--bs-border-radius);
&__icon {
visibility: visible;
}
}
}
&__count {
display: inline-flex;
font-variant-numeric: tabular-nums;
line-height: 1;
justify-content: space-between;
align-items: center;
padding: $spacer-xxs $spacer-xs;
font-weight: 500;
color: var(--bs-body-color);
&__icon {
color: inherit;
display: inline-flex;
visibility: hidden;
}
}
&__bar {
animation: slidingBar 200ms forwards;
height: 8px;
background: var(--bs-secondary-bg-subtle);
position: absolute;
left: 0;
bottom: 0;
min-width: 1px;
max-width: 0;
border-radius: 0 4px 4px 0;
}
@for $i from 0 through 100 {
&:nth-child(#{$i}) &__bar {
animation-delay: $i * 50ms;
}
}
}
</style>
18 changes: 18 additions & 0 deletions src/stories/components/Widget/WidgetFieldFacetsEntry.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { vueRouter } from 'storybook-vue3-router'

import WidgetFieldFacetsEntry from '@/components/Widget/WidgetFieldFacetsEntry'

export default {
title: 'Components/Widget/WidgetFieldFacetsEntry',
decorators: [vueRouter([{ name: 'search' }])],
component: WidgetFieldFacetsEntry,
tags: ['autodocs'],
args: {
label: 'English',
count: 6781,
total: 1e4,
to: { name: 'search' }
}
}

export const Default = {}

0 comments on commit 7cde9e2

Please sign in to comment.