Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Simplify Filter Sidebar component and improve scrollbar styles (#432)

Olga Bulatbadc9b6c5e33
diff --git a/src/components/Filters/FiltersList.vue b/src/components/Filters/FiltersList.vue
deleted file mode 100644
index 4f38f6da8..000000000
--- a/src/components/Filters/FiltersList.vue
+++ /dev/null
@@ -1,87 +0,0 @@
-<template>
- <div class="p-4">
- <div class="flex items-center justify-between mt-4 mb-8">
- <h4 class="text-2xl">
- {{ $t('filter-list.filter-by') }}
- </h4>
- <button
- id="hide-filters-button"
- type="button"
- class="text-sm font-medium my-auto"
- @click="onToggleSearchGridFilter"
- >
- <span class="text-trans-blue hidden lg:block text-sm lowercase">{{
- $t('filter-list.hide')
- }}</span>
- <span class="me-4 text-lg lg:hidden">
- <i class="icon cross" />
- </span>
- </button>
- </div>
- <form class="filters-form">
- <FilterChecklist
- v-for="filterType in filterTypes"
- :key="filterType"
- :options="filters[filterType]"
- :title="filterTypeTitle(filterType)"
- :filter-type="filterType"
- @filterChanged="onUpdateFilter"
- />
- </form>
- <footer v-if="isAnyFilterApplied" class="flex justify-between">
- <button
- id="clear-filter-button"
- class="text-sm py-2 px-4 lowercase rounded color-dark-blue border border-dark-blue hover:text-white hover:bg-dark-gray hover:border-dark-gray"
- @click="onClearFilters"
- >
- {{ $t('filter-list.clear') }}
- </button>
- <button
- class="text-sm py-4 px-6 lowercase rounded bg-trans-blue text-white lg:hidden hover:bg-trans-blue-action"
- @click="onToggleSearchGridFilter"
- >
- {{ $t('filter-list.show') }}
- </button>
- </footer>
- </div>
-</template>
-
-<script>
-import { mapGetters } from 'vuex'
-import { kebabize } from '~/utils/format-strings'
-import { SEARCH } from '~/constants/store-modules'
-import FilterChecklist from './FilterChecklist'
-
-export default {
- name: 'FiltersList',
- components: {
- FilterChecklist,
- },
- computed: {
- ...mapGetters(SEARCH, ['mediaFiltersForDisplay', 'isAnyFilterApplied']),
- filters() {
- return this.mediaFiltersForDisplay || {}
- },
- filterTypes() {
- return Object.keys(this.filters)
- },
- },
- methods: {
- filterTypeTitle(filterType) {
- if (filterType === 'searchBy') {
- return ''
- }
- return this.$t(`filters.${kebabize(filterType)}.title`)
- },
- onUpdateFilter({ code, filterType }) {
- this.$emit('onUpdateFilter', { code, filterType })
- },
- onToggleSearchGridFilter() {
- this.$emit('onToggleSearchGridFilter')
- },
- onClearFilters() {
- this.$emit('onClearFilters')
- },
- },
-}
-</script>
diff --git a/src/components/Filters/SearchGridFilter.vue b/src/components/Filters/SearchGridFilter.vue
index 761834aef..4a63e9f0b 100644
--- a/src/components/Filters/SearchGridFilter.vue
+++ b/src/components/Filters/SearchGridFilter.vue
@@ -1,26 +1,84 @@
<template>
- <FiltersList
- class="search-filters h-auto max-h-full overflow-y-scroll"
+ <div
+ class="p-4 search-filters h-auto max-h-full overflow-y-scroll"
:class="[isFilterVisible ? 'block' : 'hidden']"
data-testid="filters-list"
@onUpdateFilter="onUpdateFilter"
@onToggleSearchGridFilter="onToggleSearchGridFilter"
@onClearFilters="onClearFilters"
- />
+ >
+ <div class="flex items-center justify-between mt-4 mb-8">
+ <h4 class="text-2xl">
+ {{ $t('filter-list.filter-by') }}
+ </h4>
+ <button
+ id="hide-filters-button"
+ type="button"
+ class="text-sm font-medium my-auto"
+ @click="onToggleSearchGridFilter"
+ >
+ <span class="text-trans-blue hidden lg:block text-sm lowercase">{{
+ $t('filter-list.hide')
+ }}</span>
+ <span class="me-4 text-lg lg:hidden">
+ <CloseIcon class="w-4 h-4" />
+ </span>
+ </button>
+ </div>
+ <form class="filters-form">
+ <FilterChecklist
+ v-for="filterType in filterTypes"
+ :key="filterType"
+ :options="filters[filterType]"
+ :title="filterTypeTitle(filterType)"
+ :filter-type="filterType"
+ @filterChanged="onUpdateFilter"
+ />
+ </form>
+ <footer v-if="isAnyFilterApplied" class="flex justify-between">
+ <button
+ id="clear-filter-button"
+ type="button"
+ class="text-sm py-2 px-4 lowercase rounded color-dark-blue border border-dark-blue hover:text-white hover:bg-dark-gray hover:border-dark-gray"
+ @click="onClearFilters"
+ >
+ {{ $t('filter-list.clear') }}
+ </button>
+ <button
+ class="text-sm py-4 px-6 lowercase rounded bg-trans-blue text-white lg:hidden hover:bg-trans-blue-action"
+ type="button"
+ @click="onToggleSearchGridFilter"
+ >
+ {{ $t('filter-list.show') }}
+ </button>
+ </footer>
+ </div>
</template>
<script>
-import { mapActions, mapMutations, mapState } from 'vuex'
+import { mapActions, mapGetters, mapMutations, mapState } from 'vuex'
import { SET_FILTER_IS_VISIBLE } from '~/constants/mutation-types'
import { CLEAR_FILTERS, TOGGLE_FILTER } from '~/constants/action-types'
import { SEARCH } from '~/constants/store-modules'
-import FiltersList from '~/components/Filters/FiltersList'
+import { kebabize } from '~/utils/format-strings'
+import FilterChecklist from '~/components/Filters/FilterChecklist'
+import CloseIcon from '~/assets/icons/close.svg?inline'
export default {
name: 'SearchGridFilter',
- components: { FiltersList },
+ components: {
+ CloseIcon,
+ FilterChecklist,
+ },
computed: {
- ...mapState(SEARCH, ['filters', 'isFilterVisible']),
+ ...mapState(SEARCH, ['isFilterVisible']),
+ ...mapGetters(SEARCH, ['mediaFiltersForDisplay', 'isAnyFilterApplied']),
+ filters() {
+ return this.mediaFiltersForDisplay || {}
+ },
+ filterTypes() {
+ return Object.keys(this.filters)
+ },
},
methods: {
...mapActions(SEARCH, {
@@ -30,6 +88,12 @@ export default {
...mapMutations(SEARCH, {
setFilterVisible: SET_FILTER_IS_VISIBLE,
}),
+ filterTypeTitle(filterType) {
+ if (filterType === 'searchBy') {
+ return ''
+ }
+ return this.$t(`filters.${kebabize(filterType)}.title`)
+ },
onUpdateFilter({ code, filterType }) {
this.toggleFilter({ code, filterType })
},
@@ -47,6 +111,20 @@ export default {
<style lang="scss" scoped>
.search-filters {
+ /* Works on Firefox */
+ scrollbar-color: transparent transparent;
+ scrollbar-width: thin;
+ /* Works on Chrome, Edge, and Safari */
+ &::-webkit-scrollbar {
+ width: 12px;
+ }
+ &::-webkit-scrollbar-track {
+ background: transparent;
+ }
+ &::-webkit-scrollbar-thumb {
+ background-color: transparent;
+ border-radius: 20px;
+ }
@include touch {
width: 21.875rem;
max-width: 100%;
diff --git a/src/components/VCheckbox.vue b/src/components/VCheckbox.vue
index 68eede1ba..12a208ac9 100644
--- a/src/components/VCheckbox.vue
+++ b/src/components/VCheckbox.vue
@@ -70,8 +70,6 @@ const VCheckbox = defineComponent({
},
/**
* Sets disabled property of the input and changes label opacity if set to true.
- *
- * @default false
*/
disabled: {
type: Boolean,
diff --git a/tailwind.config.js b/tailwind.config.js
index 933a9ba87..ed33b19db 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -195,7 +195,7 @@ module.exports = {
borderColor: ['checked', 'disabled'],
margin: ['last'],
opacity: ['disabled'],
- ringColor: ['focus-visible'],
+ ringColor: ['focus', 'focus-visible'],
ringOffsetWidth: ['focus-visible'],
ringWidth: ['focus-visible'],
borderWidth: ['focus', 'focus-within'],