Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Add Checkbox component (#406)
Olga Bulata46f83adbbd7
diff --git a/jest.config.js b/jest.config.jsindex 054e834be..aef39d1b4 100644--- a/jest.config.js+++ b/jest.config.js@@ -7,6 +7,7 @@ module.exports = {moduleFileExtensions: ['js', 'vue', 'json'],moduleNameMapper: {'^@/(.*)$': '<rootDir>/src/$1',+ '^~/(.*.svg)\\?inline$': '<rootDir>/src/$1','^~/(.*)$': '<rootDir>/src/$1','^vue$': 'vue/dist/vue.common.js','(.*svg)(\\?inline)$': '<rootDir>/test/unit/test-utils/svgTransform.js',diff --git a/src/assets/icons/checkmark.svg b/src/assets/icons/checkmark.svgnew file mode 100644index 000000000..04691f386--- /dev/null+++ b/src/assets/icons/checkmark.svg@@ -0,0 +1,3 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">+ <path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z" fill="currentColor"/>+</svg>diff --git a/src/components/Filters/FilterChecklist.vue b/src/components/Filters/FilterChecklist.vueindex 011076cee..8c11cd2e1 100644--- a/src/components/Filters/FilterChecklist.vue+++ b/src/components/Filters/FilterChecklist.vue@@ -1,147 +1,101 @@<template>- <div- :class="{ ['filters']: true, ['single']: isSingleFilter, 'mb-8': true }"- @click="hideLicenseExplanationVisibility()"- @keyup.enter="hideLicenseExplanationVisibility()"- >+ <fieldset class="mb-8" @click.stop="hideLicenseExplanationVisibility">+ <legend v-if="title" class="text-2xl font-semibold mb-2">+ {{ title }}+ </legend><div- v-if="title"- class="filters-title"- @click.prevent="toggleFilterVisibility"- @keyup.enter="toggleFilterVisibility"+ v-for="(item, index) in options"+ :key="index"+ class="flex justify-between items-center mt-3">- <h4 class="filter-heading">{{ title }}</h4>+ <VCheckbox+ :id="item.code"+ :key="index"+ :checked="item.checked"+ :name="itemName"+ :value="item.code"+ :disabled="isDisabled(item)"+ @change="onValueChange"+ >+ <VLicense v-if="filterType === 'licenses'" :license="item.code" />+ <template v-else>{{ itemLabel(item) }}</template>+ </VCheckbox><button- v-if="!filtersExpandedByDefault"- :aria-label="$t('filter-list.category-aria', { categoryName: title })"- class="filter-visibility-toggle is-white py-2"+ v-if="filterType === 'licenses'"+ :ref="`${item.code}licenseIcon`"+ :aria-label="$t('browse-page.aria.license-explanation')"+ class="appearance-none"+ type="button"+ @click.stop="toggleLicenseExplanationVisibility(item.code)">- <i- v-if="areFiltersExpanded"- class="icon angle-up rotImg text-lg text-light-gray"- title="toggle filters visibility"- />- <i- v-else- class="icon angle-down text-lg text-light-gray"- title="toggle filters visibility"- />+ <svg+ aria-hidden="true"+ width="24"+ height="24"+ viewBox="0 0 24 24"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ class="pe-1"+ >+ <circle cx="12" cy="10" r="8" stroke="#1E1E1E" stroke-width="1.5" />+ <path+ d="M9.75 8.25C9.75 7.00736 10.7574 6 12 6C13.2426 6 14.25 7.00736 14.25 8.25C14.25 9.40828 13.3748 10.3621 12.2496 10.4863C12.1124 10.5015 12 10.6119 12 10.75V12"+ stroke="#1E1E1E"+ stroke-width="1.5"+ />+ <path d="M12 13V14.5" stroke="#1E1E1E" stroke-width="1.5" />+ </svg></button></div>- <template v-if="areFiltersExpanded">- <div- v-for="(item, index) in options"- :key="index"- class="filter-checkbox-wrapper"- >- <!--eslint-disable vuejs-accessibility/label-has-for -->- <label class="checkbox" :disabled="isDisabled(item)">- <input- :key="index"- :name="item.code"- type="checkbox"- class="filter-checkbox me-2"- :checked="item.checked"- :disabled="isDisabled(item)"- @change="onValueChange"- />- <LicenseIcons v-if="filterType === 'licenses'" :license="item.code" />- {{ itemLabel(item) }}- </label>- <button class="appearance-none" type="button">- <svg- v-if="filterType === 'licenses'"- :ref="`${index}licenseIcon`"- width="24"- height="20"- viewBox="0 0 24 20"- fill="none"- xmlns="http://www.w3.org/2000/svg"- :aria-label="$t('browse-page.aria.license-explanation')"- tabindex="0"- alt="help"- class="license-help pe-1"- @click.stop="toggleLicenseExplanationVisibility(item.code)"- @keyup.enter="toggleLicenseExplanationVisibility(item.code)"- >- <circle cx="12" cy="10" r="8" stroke="#1E1E1E" stroke-width="1.5" />- <path- d="M9.75 8.25C9.75 7.00736 10.7574 6 12 6C13.2426 6 14.25 7.00736 14.25 8.25C14.25 9.40828 13.3748 10.3621 12.2496 10.4863C12.1124 10.5015 12 10.6119 12 10.75V12"- stroke="#1E1E1E"- stroke-width="1.5"- />- <path d="M12 13V14.5" stroke="#1E1E1E" stroke-width="1.5" />- </svg>- </button>-- <LicenseExplanationTooltip- v-if="- shouldRenderLicenseExplanationTooltip(item.code) &&- !isDisabled(item)- "- :license="licenseExplanationCode"- :icon-dom-node="$refs[`${index}licenseIcon`][0]"- />- </div>- </template>- </div>+ <LicenseExplanationTooltip+ v-if="licenseExplanationVisible"+ :license="licenseExplanationCode"+ :icon-dom-node="$refs[`${licenseExplanationCode}licenseIcon`][0]"+ />+ </fieldset></template><script>-import LicenseIcons from '~/components/LicenseIcons'import LicenseExplanationTooltip from '~/components/Filters/LicenseExplanationTooltip'+import VLicense from '~/components/License/VLicense'export default {name: 'FilterCheckList',components: {- LicenseIcons,+ VLicense,LicenseExplanationTooltip,},- props: ['options', 'title', 'filterType', 'disabled'],+ props: {+ options: { type: Array, required: false },+ title: { type: String },+ filterType: { type: String, required: true },+ disabled: { type: Boolean, default: false },+ },data() {return {- filtersVisible: false,licenseExplanationVisible: false,- licenseExplanationCode: '',+ licenseExplanationCode: null,}},computed: {- /**- * Show filters expanded by default- * @todo: The A/B test is over and we're going with the expanded view. Can remove a lot of this old test logic- */- filtersExpandedByDefault() {- return true- },- areFiltersExpanded() {- return this.filtersExpandedByDefault || this.filtersVisible- },- isSingleFilter() {- return this.$props.filterType === 'searchBy'+ itemName() {+ return this.filterType === 'searchBy'+ ? this.$t('filters.searchBy.title')+ : this.title},},methods: {itemLabel(item) {- return ['audioProviders', 'imageProviders'].includes(- this.$props.filterType- )+ return ['audioProviders', 'imageProviders'].includes(this.filterType)? item.name: this.$t(item.name)},- onValueChange(e) {+ onValueChange({ value }) {this.$emit('filterChanged', {- code: e.target.name,- filterType: this.$props.filterType,+ code: value,+ filterType: this.filterType,})},- /**- * This function is used to hide sub items in filters- * It was decided not to use them after a/b tests- * TODO: either remove or use if necessary when implementing new designs- */- toggleFilterVisibility() {- this.filtersVisible = !this.filtersVisible- },toggleLicenseExplanationVisibility(licenseCode) {this.licenseExplanationVisible = !this.licenseExplanationVisiblethis.licenseExplanationCode = licenseCode@@ -155,29 +109,29 @@ export default {)},isDisabled(item) {- if (this.$props.filterType === 'licenseTypes') {+ if (this.filterType === 'licenseTypes') {const nc = this.getFilterTypeValue('licenses', 'nc')const nd = this.getFilterTypeValue('licenses', 'nd')return ((item.code === 'commercial' && nc.some((li) => li.checked)) ||(item.code === 'modification' && nd.some((li) => li.checked)))- }- if (this.$props.filterType === 'licenses') {+ } else if (this.filterType === 'licenses') {const commercial = this.getFilterTypeValue('licenseTypes', 'commercial')const modification = this.getFilterTypeValue('licenseTypes','modification')return (- (commercial.checked && item.code.includes('nc')) ||- (modification.checked && item.code.includes('nd'))+ (commercial[0].checked && item.code.includes('nc')) ||+ (modification[0].checked && item.code.includes('nd')))}- return this.$props.disabled+ return this.disabled},shouldRenderLicenseExplanationTooltip(licenseCode) {return (+ !this.isDisabled({ code: licenseCode }) &&this.licenseExplanationVisible &&this.licenseExplanationCode === licenseCode)@@ -185,60 +139,3 @@ export default {},}</script>--<style lang="scss" scoped>-.filters-title {- font-size: 1.25em;- font-weight: 600;- font-stretch: normal;- font-style: normal;- line-height: 1.5;- letter-spacing: normal;- cursor: pointer;- margin-bottom: 0.5rem;-}--.filter-heading {- font-size: 1rem;- font-weight: 600;- margin-bottom: 1rem;-}--.filter-visibility-toggle {- float: right;- cursor: pointer;- background: none;- border: none;-}--label {- color: #333333;-}--.license-help {- cursor: pointer;- padding: 0;-}--.filter-checkbox-wrapper {- display: flex;- justify-content: space-between;- align-items: center;- margin-top: 0.8rem;-}--.checkbox {- display: flex;- align-items: center;- font-size: 0.875rem;- font-weight: 500;-}-.checkbox input {- min-width: 1.25rem;- height: 1.25rem;-}--.single .checkbox {- font-size: 0.875rem;-}-</style>diff --git a/src/components/Filters/FiltersList.vue b/src/components/Filters/FiltersList.vueindex 352986044..4f38f6da8 100644--- a/src/components/Filters/FiltersList.vue+++ b/src/components/Filters/FiltersList.vue@@ -1,15 +1,14 @@<template><div class="p-4">- <div class="filterlist-header mt-4 mb-8">- <h4 class="filter-heading">+ <div class="flex items-center justify-between mt-4 mb-8">+ <h4 class="text-2xl">{{ $t('filter-list.filter-by') }}</h4>-<buttonid="hide-filters-button"type="button"- @click="onToggleSearchGridFilter()"- @keyup.enter="onToggleSearchGridFilter()"+ class="text-sm font-medium my-auto"+ @click="onToggleSearchGridFilter"><span class="text-trans-blue hidden lg:block text-sm lowercase">{{$t('filter-list.hide')@@ -19,11 +18,10 @@</span></button></div>- <form class="filters-form" role="list">+ <form class="filters-form"><FilterChecklistv-for="filterType in filterTypes":key="filterType"- role="listitem":options="filters[filterType]":title="filterTypeTitle(filterType)":filter-type="filterType"@@ -33,14 +31,14 @@<footer v-if="isAnyFilterApplied" class="flex justify-between"><buttonid="clear-filter-button"- class="text-sm py-4 px-6 lowercase rounded"+ 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"- @click="onToggleSearchGridFilter()"+ 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>@@ -87,33 +85,3 @@ export default {},}</script>--<style lang="scss" scoped>-.filterlist-header {- display: flex;- align-items: center;- justify-content: space-between;-}--.filter-heading {- font-size: 1rem;-}--#hide-filters-button {- font-size: 0.813rem;- font-weight: 500;- margin-top: auto;- margin-bottom: auto;-}--#clear-filter-button {- color: #23282d;- border: solid #23282d33 1px;-}-#clear-filter-button:hover {- color: white;- // @todo: Remove hardcoded colors- background-color: #919496;- border-color: #919496;-}-</style>diff --git a/src/components/Filters/LicenseExplanationTooltip.vue b/src/components/Filters/LicenseExplanationTooltip.vueindex 3e8395d28..833e15b21 100644--- a/src/components/Filters/LicenseExplanationTooltip.vue+++ b/src/components/Filters/LicenseExplanationTooltip.vue@@ -48,7 +48,6 @@ export default {required: true,},iconDomNode: {- type: Object,required: true,},},diff --git a/src/components/Filters/SearchGridFilter.vue b/src/components/Filters/SearchGridFilter.vueindex ecdebca76..761834aef 100644--- a/src/components/Filters/SearchGridFilter.vue+++ b/src/components/Filters/SearchGridFilter.vue@@ -11,11 +11,8 @@<script>import { mapActions, mapMutations, mapState } from 'vuex'-import {- SET_FILTER_IS_VISIBLE,- CLEAR_FILTERS,-} from '~/constants/mutation-types'-import { TOGGLE_FILTER } from '~/constants/action-types'+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'diff --git a/src/components/HeroSection.vue b/src/components/HeroSection.vueindex f670384ea..3014cea7e 100644--- a/src/components/HeroSection.vue+++ b/src/components/HeroSection.vue@@ -55,7 +55,7 @@</template></i18n></div>- <HomeLicenseFilter @toggle="toggleFilter" />+ <HomeLicenseFilter :filters="filters" @toggle="toggleFilter" /></form></div><img@@ -105,16 +105,16 @@ export default {getMediaType() {return this.form.searchType},- toggleFilter({ code }) {- this.filters[code] = !this.filters[code]+ toggleFilter({ code, checked }) {+ this.filters[code] = checked},onSubmit() {const newQuery = { q: this.form.searchTerm }- const checkedFilters = Object.keys(this.filters).filter(- (filterName) => !!this.filters[filterName]- )- checkedFilters.forEach((f) => {- this.checkFilter({ filterType: 'licenseTypes', code: f })++ Object.entries(this.filters).forEach(([filterCode, isChecked]) => {+ if (isChecked) {+ this.checkFilter({ filterType: 'licenseTypes', code: filterCode })+ }})if (process.env.enableAudio) {diff --git a/src/components/HomeLicenseFilter.vue b/src/components/HomeLicenseFilter.vueindex 01c4533af..0ff926e5d 100644--- a/src/components/HomeLicenseFilter.vue+++ b/src/components/HomeLicenseFilter.vue@@ -1,44 +1,37 @@<template>- <fieldset class="home-license-filter mt-16">- <legend class="w-full text-center">+ <fieldset class="home-license-filter mt-16 flex justify-center">+ <legend class="flex justify-center w-full mb-2">{{ $t('hero.license-filter.label') }}</legend>- <template v-for="(licenseType, index) in filters">- <label :key="index" class="checkbox mx-3" :for="licenseType.code">- <input- :id="licenseType.code"- v-model="licenseType.checked"- type="checkbox"- name="lt"- :value="licenseType.code"- @change="onFilterChanged(licenseType.code)"- />- {{ $t(licenseType.name) }}- </label>- </template>+ <VCheckbox+ v-for="[licenseType, isChecked] in Object.entries(filters)"+ :id="licenseType"+ :key="licenseType"+ class="me-6 last:me-0"+ :checked="isChecked"+ name="licenseType"+ @change="onFilterChanged"+ >+ {{ $t(`filters.license-types.${licenseType}`) }}+ </VCheckbox></fieldset></template><script>+import VCheckbox from '~/components/VCheckbox'+export default {- name: 'LicenseFilter',- data: () => ({- filters: [- {- code: 'commercial',- name: 'filters.license-types.commercial',- checked: false,- },- {- code: 'modification',- name: 'filters.license-types.modification',- checked: false,- },- ],- }),+ name: 'HomeLicenseFilter',+ components: { VCheckbox },+ props: {+ filters: {+ type: Object,+ required: true,+ },+ },methods: {- onFilterChanged(code) {- this.$emit('toggle', { code })+ onFilterChanged({ value, checked }) {+ this.$emit('toggle', { code: value, checked })},},}diff --git a/src/components/License/VLicense.vue b/src/components/License/VLicense.vueindex 682ed6605..6670df49b 100644--- a/src/components/License/VLicense.vue+++ b/src/components/License/VLicense.vue@@ -1,16 +1,11 @@<template><div class="license flex flex-row items-center gap-2"><div class="flex gap-1">- <VIcon- v-if="isCC"- class="icon"- view-box="0 0 30 30"- :icon-path="ccLogo"- />+ <VIcon v-if="isCC" :size="4" view-box="0 0 30 30" :icon-path="ccLogo" /><VIconv-for="(name, index) in icons":key="index"- class="icon"+ :size="4"view-box="0 0 30 30":icon-path="svgs[name]"/>@@ -83,10 +78,3 @@ export default {},}</script>--<style scoped>-.icon {- height: 1.1667em;- width: 1.1667em;-}-</style>diff --git a/src/components/VCheckbox.vue b/src/components/VCheckbox.vuenew file mode 100644index 000000000..25cd65611--- /dev/null+++ b/src/components/VCheckbox.vue@@ -0,0 +1,140 @@+<template>+ <label :for="id" class="checkbox-label" :class="labelClasses">+ <input+ :id="id"+ type="checkbox"+ class="checkbox"+ v-bind="inputAttrs"+ @change="onChange"+ />+ <Checkmark+ v-show="localCheckedState"+ class="checkmark"+ focusable="false"+ width="20"+ height="20"+ role="img"+ />+ <!-- @slot The checkbox label --><slot />+ </label>+</template>++<script>+import Checkmark from '~/assets/icons/checkmark.svg?inline'+import { computed, defineComponent, ref, watch } from '@nuxtjs/composition-api'++const VCheckbox = defineComponent({+ name: 'VCheckbox',+ components: { Checkmark },+ props: {+ /**+ * Checkbox `id` is used for the input id property, connecting the label to+ * the checkbox. id is also used in the `change` event payload as the `name`+ * and `value` parameters if they are not set.+ */+ id: {+ type: String,+ required: true,+ },+ /**+ * Whether the checkbox is checked or not. No indeterminate state is allowed.+ *+ * @default false+ */+ checked: {+ type: Boolean,+ default: false,+ },+ /**+ * The name and value parameters are used when sending the form data to the server+ * using HTML on form submit: if a checkbox is checked, `name=value` pair in+ * the POST request body.+ * In a Vue app, this is used as the name parameter in the emitted event's payload.+ * It is usually the category that this checkbox belongs to, eg. licenseType for a+ * 'by-nc-nd' checkbox.+ * If not set, the value of `id` prop is used instead.+ */+ name: {+ type: String,+ required: false,+ },+ /**+ * The value parameter in `name=value` pair sent in the POST request body, here+ * emitted in the event's payload. Usually the code as 'by-nc-nd'.+ *+ * If not set, the value of `id` prop is used.+ */+ value: {+ type: String,+ required: false,+ },+ /**+ * Sets disabled property of the input and changes label opacity if set to true.+ *+ * @default false+ */+ disabled: {+ type: Boolean,+ default: false,+ },+ },+ setup(props, { emit }) {+ const localCheckedState = ref(props.checked || false)+ const labelClasses = computed(() =>+ props.disabled ? 'text-dark-charcoal-70' : 'text-dark-charcoal'+ )+ const inputAttrs = computed(() => {+ const attrs = {+ name: props.name || props.id,+ value: props.value || props.id,+ }+ if (props.disabled) {+ attrs.disabled = 'disabled'+ }+ if (localCheckedState.value) {+ attrs.checked = 'checked'+ }+ return attrs+ })++ watch(+ () => props.checked,+ (checked) => {+ if (checked !== localCheckedState.value) {+ localCheckedState.value = checked+ }+ }+ )++ const onChange = () => {+ localCheckedState.value = !localCheckedState.value+ emit('change', {+ name: inputAttrs.value.name,+ value: inputAttrs.value.value,+ checked: localCheckedState.value,+ })+ }+ return {+ localCheckedState,+ labelClasses,+ inputAttrs,+ onChange,+ }+ },+})+export default VCheckbox+</script>+<style scoped>+.checkbox-label {+ @apply relative flex text-base leading-5;+}+.checkbox {+ @apply appearance-none w-5 h-5 border-dark-charcoal border rounded-sm me-3 flex-shrink-0 relative;+ @apply focus:outline-none focus:ring focus:ring-offset-2 focus:ring-primary;+ @apply transition-colors disabled:bg-dark-charcoal-10 disabled:border-dark-charcoal-40;+ @apply checked:bg-dark-charcoal;+}+.checkmark {+ @apply absolute left-0 w-5 h-5 text-white;+}+</style>diff --git a/src/components/VIcon/VIcon.vue b/src/components/VIcon/VIcon.vueindex 1c5298ec6..2680a9f1e 100644--- a/src/components/VIcon/VIcon.vue+++ b/src/components/VIcon/VIcon.vue@@ -1,6 +1,7 @@<template><svg- class="v-icon h-6 w-6"+ class="v-icon"+ :class="`w-${size} h-${size}`"xmlns="http://www.w3.org/2000/svg":viewBox="viewBox"aria-hidden="true"@@ -40,6 +41,10 @@ export default {type: String,default: 'icon',},+ size: {+ type: Number,+ default: 6,+ },},}</script>diff --git a/src/components/meta/VCheckbox.stories.js b/src/components/meta/VCheckbox.stories.jsnew file mode 100644index 000000000..aa07690c8--- /dev/null+++ b/src/components/meta/VCheckbox.stories.js@@ -0,0 +1,75 @@+import VCheckbox from '~/components/VCheckbox'+import VLicense from '~/components/License/VLicense'++export default {+ title: 'Components/VCheckbox',+ component: VCheckbox,+}++const SimpleCheckboxStory = (args, { argTypes }) => {+ return {+ template: `<div class="flex flex-col">+ <VCheckbox v-bind="$props" @change="handleChange" class="mb-4">Code is Poetry</VCheckbox>+ <p>Checkbox is {{isChecked ? '' : 'NOT ' }}checked.</p>+ <p>\`@change\` event payload: </p><pre class="ps-0">{{ payload }}</pre>+ </div>`,+ components: { VCheckbox },+ data: () => ({+ isChecked: args.checked,+ payload: null,+ }),+ props: Object.keys(argTypes),+ methods: {+ handleChange(params) {+ this.isChecked = params.checked+ this.payload = params+ },+ },+ }+}++const DisabledCheckboxStory = (args, { argTypes }) => ({+ template: `<fieldset><legend>Use</legend><VCheckbox v-bind="$props">Use commercially</VCheckbox></fieldset>`,+ components: { VCheckbox },+ props: Object.keys(argTypes),+})++const LicenseCheckboxStory = (args, { argTypes }) => ({+ template: `<VCheckbox v-bind="$props" @change="onChange">+ <VLicense license="by-nc" class="me-4"/>+ <span >Checked: {{ isChecked }}</span>+ </VCheckbox>`,+ components: { VCheckbox, VLicense },+ data: () => ({+ isChecked: args.checked,+ }),+ props: Object.keys(argTypes),+ methods: {+ onChange(params) {+ window.alert('License checkbox checked! ' + JSON.stringify(params))+ this.isChecked = params.checked+ },+ },+})++export const Default = SimpleCheckboxStory.bind({})+Default.args = {+ id: 'simple',+ checked: true,+ name: 'checkboxes',+}++export const DisabledCheckbox = DisabledCheckboxStory.bind({})+DisabledCheckbox.args = {+ id: 'disabled',+ checked: false,+ name: 'use',+ disabled: true,+}++export const LicenseCheckbox = LicenseCheckboxStory.bind({})+LicenseCheckbox.args = {+ id: 'license',+ checked: false,+ name: 'checkboxes',+}diff --git a/src/constants/action-types.js b/src/constants/action-types.jsindex ccbf8be69..8de822bb7 100644--- a/src/constants/action-types.js+++ b/src/constants/action-types.js@@ -16,3 +16,4 @@ export const UPDATE_QUERY = 'UPDATE_QUERY'export const UPDATE_QUERY_FROM_FILTERS = 'UPDATE_QUERY_FROM_FILTERS'export const SET_SEARCH_STATE_FROM_URL = 'SET_SEARCH_STATE_FROM_URL'export const SET_MEDIA_TYPE = 'SET_MEDIA_TYPE'+export const CLEAR_FILTERS = 'CLEAR_FILTERS'diff --git a/src/constants/mutation-types.js b/src/constants/mutation-types.jsindex 456229588..1555cd2bb 100644--- a/src/constants/mutation-types.js+++ b/src/constants/mutation-types.js@@ -6,7 +6,6 @@ export const FETCH_MEDIA_ERROR = 'FETCH_MEDIA_ERROR'export const MEDIA_NOT_FOUND = 'MEDIA_NOT_FOUND'export const FETCH_START_MEDIA = 'FETCH_START_MEDIA'export const SET_FILTER = 'SET_FILTER'-export const CLEAR_FILTERS = 'CLEAR_FILTERS'export const SET_FILTER_IS_VISIBLE = 'SET_FILTER_IS_VISIBLE'export const SET_AUDIO = 'SET_AUDIO'export const SET_IMAGE = 'SET_IMAGE'diff --git a/src/pages/index.vue b/src/pages/index.vueindex fb00be534..bff1c7498 100644--- a/src/pages/index.vue+++ b/src/pages/index.vue@@ -4,7 +4,7 @@<script>import { SEARCH } from '~/constants/store-modules'-import { CLEAR_FILTERS } from '~/constants/mutation-types'+import { CLEAR_FILTERS } from '~/constants/action-types'const HomePage = {name: 'home-page',diff --git a/src/store/index.js b/src/store/index.jsindex 9199ed6bf..ad837e167 100644--- a/src/store/index.js+++ b/src/store/index.js@@ -6,7 +6,7 @@ export const actions = {try {await dispatch(`${PROVIDER}/${FETCH_MEDIA_PROVIDERS}`)} catch (error) {- console.error("Couldn't fetch media providers")+ console.warn("Couldn't fetch media providers")}},}diff --git a/src/store/media.js b/src/store/media.jsindex 7103b3ab3..5dc1e385b 100644--- a/src/store/media.js+++ b/src/store/media.js@@ -204,6 +204,7 @@ export const createActions = (services) => ({[HANDLE_NO_MEDIA]({ commit }, { mediaCount, mediaType }) {if (!mediaCount) {commit(FETCH_MEDIA_ERROR, {+ mediaType,errorMessage: `No ${mediaType} found for this query`,})}diff --git a/src/store/provider.js b/src/store/provider.jsindex d3500350e..f94d3daf1 100644--- a/src/store/provider.js+++ b/src/store/provider.js@@ -60,7 +60,7 @@ export const createActions = (services) => ({sortedProviders = sortProviders(data)}).catch((error) => {- console.error(+ console.warn(`Error getting ${mediaType} providers: ${error}. Will use saved provider data instead `)sortedProviders = existingProviders[mediaType]diff --git a/src/store/search.js b/src/store/search.jsindex 2feff6c2e..5c1ff07fa 100644--- a/src/store/search.js+++ b/src/store/search.js@@ -21,11 +21,11 @@ import {TOGGLE_FILTER,UPDATE_QUERY_FROM_FILTERS,UPDATE_SEARCH_TYPE,+ CLEAR_FILTERS,} from '~/constants/action-types'import {SET_FILTER,SET_PROVIDERS_FILTERS,- CLEAR_FILTERS,SET_FILTER_IS_VISIBLE,CLEAR_OTHER_MEDIA_TYPE_FILTERS,REPLACE_FILTERS,diff --git a/src/styles/base/generic.sass b/src/styles/base/generic.sassindex f6c2da480..47d217fa5 100644--- a/src/styles/base/generic.sass+++ b/src/styles/base/generic.sass@@ -106,7 +106,6 @@ imgheight: automax-width: 100%-input[type="checkbox"],input[type="radio"]vertical-align: baselinediff --git a/src/styles/form/_all.sass b/src/styles/form/_all.sassindex 4b5eda590..f5404d234 100644--- a/src/styles/form/_all.sass+++ b/src/styles/form/_all.sass@@ -8,5 +8,5 @@ $input-size-large: 1.75rem@import "shared"@import "tools"@import "input-textarea"-@import "checkbox-radio"+@import "radio"@import "select"diff --git a/src/styles/form/checkbox-radio.sass b/src/styles/form/radio.sasssimilarity index 80%rename from src/styles/form/checkbox-radio.sassrename to src/styles/form/radio.sassindex 83f889909..ad838599d 100644--- a/src/styles/form/checkbox-radio.sass+++ b/src/styles/form/radio.sass@@ -1,4 +1,4 @@-%checkbox-radio+%radiocursor: pointerdisplay: inline-blockline-height: 1.25@@ -13,10 +13,7 @@color: $input-disabled-colorcursor: not-allowed-.checkbox- @extend %checkbox-radio-.radio- @extend %checkbox-radio+ @extend %radio& + .radio+ltr-property("margin", 0.5em, false)diff --git a/tailwind.config.js b/tailwind.config.jsindex d9391c73c..c462fe279 100644--- a/tailwind.config.js+++ b/tailwind.config.js@@ -16,7 +16,7 @@ module.exports = {yellow: '#ffe033','dark-charcoal': '#30272e',pink: '#c52b9b',-+ primary: '#3e58e1', // will change to pink after redesign launch// Active'dark-pink': '#7c2264',@@ -176,6 +176,9 @@ module.exports = {},variants: {extend: {+ backgroundColor: ['checked', 'disabled'],+ borderColor: ['checked', 'disabled'],+ margin: ['last'],opacity: ['disabled'],ringColor: ['focus-visible'],ringOffsetWidth: ['focus-visible'],diff --git a/test/e2e/homepage.spec.js b/test/e2e/homepage.spec.jsindex 5b224aeb5..6889d4d68 100644--- a/test/e2e/homepage.spec.js+++ b/test/e2e/homepage.spec.js@@ -9,7 +9,7 @@ test('can change type and search for audio/modification from homepage', async ({// Click text=Audioawait page.click('text=Audio')// Check text=Modify or adapt >> input[name="lt"]- await page.check('text=Modify or adapt >> input[name="lt"]')+ await page.check('text=Modify or adapt >> input[name="licenseType"]')// Click [placeholder="Search all content"]await page.click('[placeholder="Search all content"]')// Fill [placeholder="Search all content"]diff --git a/test/e2e/search-query-server.spec.js b/test/e2e/search-query-server.spec.jsindex f17c91c1b..ced6aa2ed 100644--- a/test/e2e/search-query-server.spec.js+++ b/test/e2e/search-query-server.spec.js@@ -71,15 +71,17 @@ test('url query to filter, all tab, one parameter per filter type', async ({// Have to specify `aside` because there are technically two filter lists on the page:// aside for desktop, and a modal for mobile view.- const cc0 = page.locator('aside [type="checkbox"][name="cc0"]')+ const cc0 = page.locator('aside input[type="checkbox"][value="cc0"]')await expect(cc0).toBeChecked()- const commercial = page.locator('aside [type="checkbox"][name="commercial"]')+ const commercial = page.locator(+ 'aside input[type="checkbox"][value="commercial"]'+ )await expect(commercial).toBeChecked()// TODO (obulat): Check that this checkbox has a clear a11y nameconst searchByCreator = page.locator(- 'aside [type="checkbox"][name="creator"]'+ 'aside input[type="checkbox"][value="creator"]')await expect(searchByCreator).toBeChecked()})@@ -91,16 +93,16 @@ test('url query to filter, image tab, several filters for one filter type select'/search/image?q=cat&searchBy=creator&extension=jpg,png,gif,svg')- const cc0 = page.locator('aside [type="checkbox"][name="jpg"]')- await expect(cc0).toBeChecked()+ const jpg = page.locator('aside input[type="checkbox"][value="jpg"]')+ await expect(jpg).toBeChecked()- const png = page.locator('aside [type="checkbox"][name="png"]')+ const png = page.locator('aside input[type="checkbox"][value="png"]')await expect(png).toBeChecked()- const gif = page.locator('aside [type="checkbox"][name="gif"]')+ const gif = page.locator('aside input[type="checkbox"][value="gif"]')await expect(gif).toBeChecked()- const svg = page.locator('aside [type="checkbox"][name="svg"]')+ const svg = page.locator('aside input[type="checkbox"][value="svg"]')await expect(svg).toBeChecked()})diff --git a/test/unit/specs/components/filter-checklist.spec.js b/test/unit/specs/components/filter-checklist.spec.jsindex 9dd43a28b..cae034fd2 100644--- a/test/unit/specs/components/filter-checklist.spec.js+++ b/test/unit/specs/components/filter-checklist.spec.js@@ -1,11 +1,16 @@import FilterChecklist from '~/components/Filters/FilterChecklist'-import render from '../../test-utils/render'+import VCheckbox from '~/components/VCheckbox'+import { createLocalVue } from '@vue/test-utils'+import { fireEvent, render, screen } from '@testing-library/vue'describe('FilterChecklist', () => {let options = {}let props = null+ let localVue = nullbeforeEach(() => {+ localVue = createLocalVue()+ localVue.component('VCheckbox', VCheckbox)props = {options: [{ code: 'foo', name: 'bar', checked: false }],title: 'Foo',@@ -13,32 +18,21 @@ describe('FilterChecklist', () => {disabled: false,}options = {+ localVue,propsData: props,- mocks: {- $store: { state: { filters: { licenses: {}, licenseTypes: {} } } },- },}})- it('should render correct contents', () => {- const wrapper = render(FilterChecklist, options)- expect(wrapper.find('.filters').vm).toBeDefined()- })-- xit('should render filter visibility toggle button', () => {- const wrapper = render(FilterChecklist, options)- expect(wrapper.find('.filter-visibility-toggle').element).toBeDefined()- })-- xit('visibility toggle button should be in collapsed state by default', () => {- const wrapper = render(FilterChecklist, options)- expect(wrapper.find('.angle-down').element).toBeDefined()- })+ it('should render correct contents', async () => {+ const { container } = render(FilterChecklist, options)+ const checkbox = screen.getByRole('checkbox', {+ checked: false,+ label: /bar/i,+ })+ expect(checkbox).toBeTruthy()+ expect(container.querySelector('svg')).not.toBeVisible()- xit('hides checklist when visibility toggle button pressed twice', async () => {- const wrapper = render(FilterChecklist, options)- await wrapper.find('.filter-visibility-toggle').trigger('click') // should open- await wrapper.find('.filter-visibility-toggle').trigger('click') // should close- expect(wrapper.find('.angle-down').element).toBeDefined()+ await fireEvent.click(checkbox)+ expect(container.querySelector('svg')).toBeVisible()})})diff --git a/test/unit/specs/components/hero-section.spec.js b/test/unit/specs/components/hero-section.spec.jsindex cea521655..0b7d97284 100644--- a/test/unit/specs/components/hero-section.spec.js+++ b/test/unit/specs/components/hero-section.spec.js@@ -1,13 +1,13 @@-import Vuex from 'vuex'-import HeroSection from '~/components/HeroSection'import { fireEvent, render, screen } from '@testing-library/vue'-import searchStore, { filterData } from '~/store/search'-import mediaStore from '~/store/media'import { createLocalVue } from '@vue/test-utils'+import Vuex from 'vuex'import clonedeep from 'lodash.clonedeep'import VueI18n from 'vue-i18n'import messages from '~/locales/en.json'+import searchStore, { filterData } from '~/store/search'import { IMAGE } from '~/constants/media'+import HeroSection from '~/components/HeroSection'+import VCheckbox from '~/components/VCheckbox'const i18n = new VueI18n({locale: 'en',@@ -26,12 +26,12 @@ describe('HeroSection', () => {localVue = createLocalVue()localVue.use(VueI18n)localVue.use(Vuex)+ localVue.component('VCheckbox', VCheckbox)filters = clonedeep(filterData)storeMock = new Vuex.Store({modules: {search: {namespaced: true,- ...mediaStore,...searchStore,state: {query: {diff --git a/test/unit/specs/components/home-license-filter.spec.js b/test/unit/specs/components/home-license-filter.spec.jsindex 661f8a926..1884a23b1 100644--- a/test/unit/specs/components/home-license-filter.spec.js+++ b/test/unit/specs/components/home-license-filter.spec.js@@ -1,48 +1,29 @@-import HomeLicenseFilter from '~/components/HomeLicenseFilter'+import Vuex from 'vuex'import { render, screen } from '@testing-library/vue'-import { TOGGLE_FILTER } from '~/constants/action-types'import { createLocalVue } from '@vue/test-utils'-import Vuex from 'vuex'+import HomeLicenseFilter from '~/components/HomeLicenseFilter'+import VCheckbox from '~/components/VCheckbox'describe('HomeLicenseFilter', () => {let options = {}let localVue = null- let dispatchMock = null- let toggleMock = null- let storeMock = null+ let propsData = nullbeforeEach(() => {- dispatchMock = jest.fn()- toggleMock = jest.fn()-localVue = createLocalVue()localVue.use(Vuex)- storeMock = new Vuex.Store({- modules: {- search: {- namespaced: true,- actions: {- // Without this action, we get '[vuex] unknown local action type' error- [TOGGLE_FILTER]: toggleMock,- },- state: {- filters: {- licenseTypes: [- { code: 'commercial', name: 'Commercial usage' },- { code: 'modification', name: 'Allows modification' },- ],- },- },- },- },- })+ localVue.component('VCheckbox', VCheckbox)+ propsData = {+ filters: { commercial: false, modification: false },+ }options = {- store: storeMock,+ localVue,+ props: propsData,}})- it('renders checkboxes', () => {- render(HomeLicenseFilter, options)+ it('renders checkboxes', async () => {+ await render(HomeLicenseFilter, options)const checkboxes = screen.queryAllByRole('checkbox')expect(checkboxes.length).toEqual(2)@@ -53,8 +34,7 @@ describe('HomeLicenseFilter', () => {expect(modificationCheckbox).toBeTruthy()})- it('dispatches `TOGGLE_FILTER` when checkboxes selected', async () => {- storeMock.dispatch = dispatchMock+ it('toggles checkboxes', async () => {render(HomeLicenseFilter, options)const commercialCheckbox = screen.queryByLabelText(/commercial/i)await commercialCheckbox.click()diff --git a/test/unit/specs/components/search-grid-filter.spec.js b/test/unit/specs/components/search-grid-filter.spec.jsindex 1656e6de7..f311d4025 100644--- a/test/unit/specs/components/search-grid-filter.spec.js+++ b/test/unit/specs/components/search-grid-filter.spec.js@@ -1,10 +1,11 @@-import clonedeep from 'lodash.clonedeep'import Vuex from 'vuex'import { fireEvent, render, screen } from '@testing-library/vue'import { createLocalVue } from '@vue/test-utils'import { IMAGE } from '~/constants/media'import store from '~/store/search'+import clonedeep from 'lodash.clonedeep'import SearchGridFilter from '~/components/Filters/SearchGridFilter'+import VCheckbox from '~/components/VCheckbox'const initialFilters = {licenseTypes: [@@ -13,6 +14,11 @@ const initialFilters = {name: 'Commercial usage',checked: false,},+ {+ code: 'modification',+ name: 'Modify or adapt',+ checked: false,+ },],licenses: [{ code: 'by', name: 'CC-BY', checked: false }],imageCategories: [{ code: 'photo', name: 'Photographs', checked: false }],@@ -35,6 +41,7 @@ describe('SearchGridFilter', () => {beforeEach(() => {localVue = createLocalVue()localVue.use(Vuex)+ localVue.component('VCheckbox', VCheckbox)filters = clonedeep(initialFilters)storeMock = new Vuex.Store({modules: {@@ -63,10 +70,12 @@ describe('SearchGridFilter', () => {})options = {+ localVue,propsData: props,mocks: {$store: storeMock,},+ stubs: { VIcon: true },}})diff --git a/test/unit/specs/components/v-checkbox.spec.js b/test/unit/specs/components/v-checkbox.spec.jsnew file mode 100644index 000000000..40bfe4f99--- /dev/null+++ b/test/unit/specs/components/v-checkbox.spec.js@@ -0,0 +1,98 @@+import Vue from 'vue'+import { fireEvent, render, screen } from '@testing-library/vue'+import VCheckbox from '~/components/VCheckbox'+import VLicense from '~/components/License/VLicense'++const TestWrapperStringLabel = ({+ id = 'simple',+ value = 'simple',+ checked = false,+ defaultSlot = 'JPGs',+ disabled = false,+} = {}) => {+ // eslint-disable-next-line vue/one-component-per-file+ return Vue.component('TestWrapper', {+ components: { VCheckbox },+ data() {+ return { checked, status: '' }+ },+ computed: {+ attrs() {+ return {+ id: id,+ value: value,+ checked: this.checked,+ defaultSlot: defaultSlot,+ disabled: disabled,+ }+ },+ },+ methods: {+ updateStatus(params) {+ this.status = Object.values(params).join(',')+ },+ },+ template: `<div><span>{{status}}</span><VCheckbox v-bind="attrs" @change="updateStatus">${defaultSlot}</VCheckbox></div>`,+ })+}++// eslint-disable-next-line vue/one-component-per-file+const TestWrapperLicenseLabel = Vue.component('TestWrapperLicenseLabel', {+ // This still raises an error `Unknown custom element: <Licence>`+ components: { VCheckbox, VLicense },+ template: `<VCheckbox id="license" name="licenseType">+ <VLicence class="license" license="by-sa" /></VCheckbox>`,+})++describe('VCheckbox', () => {+ it('should render a checkbox with a string label', async () => {+ const wrapper = TestWrapperStringLabel()+ const { container } = render(wrapper)+ // Finding a checked input doesn't work using { checked: false/true }+ // does not change the result, the checkbox is still returned.+ // toHaveAttribute('checked', 'true') also doesn't work, screen.debug()+ // returns an element without `checked` attribute, although the attribute+ // exists in the app/Storybook.+ const checkboxes = screen.queryAllByLabelText(/jpgs/i, { role: 'checkbox' })++ // The checkmark svg should not be visible+ expect(container.querySelector('svg')).not.toBeVisible()+ expect(checkboxes).toHaveLength(1)+ })++ it('should render a checked checkbox if `checked` is true', async () => {+ const wrapper = TestWrapperStringLabel({ checked: true })+ const { container } = render(wrapper)+ const checkboxes = screen.queryAllByLabelText(/jpgs/i, { role: 'checkbox' })++ // The checkmark svg should be visible+ expect(container.querySelector('svg')).toBeVisible()+ expect(checkboxes).toHaveLength(1)+ })++ it('should emit event on change', async () => {+ const wrapper = TestWrapperStringLabel()+ const { container } = render(wrapper)+ await fireEvent.click(screen.queryByRole('checkbox'))++ // Testing the method that handles the emitted data instead of testing emitted event+ expect(container.querySelector('span').textContent).toEqual(+ 'simple,simple,true'+ )+ })++ it('should render a disabled checkbox if `disabled` is true', async () => {+ const wrapper = TestWrapperStringLabel({ disabled: true })+ render(wrapper)+ const checkboxes = screen.queryAllByLabelText(/jpgs/i, { role: 'checkbox' })++ expect(checkboxes).toHaveLength(1)+ expect(checkboxes[0]).toHaveAttribute('disabled', 'disabled')+ })++ it('should render another component in the default slot', async () => {+ const { container } = render(TestWrapperLicenseLabel)++ expect(container.querySelectorAll('.license')).toHaveLength(1)+ })+})diff --git a/test/unit/specs/pages/browse-page.spec.js b/test/unit/specs/pages/browse-page.spec.jsindex 980dace82..5104849cd 100644--- a/test/unit/specs/pages/browse-page.spec.js+++ b/test/unit/specs/pages/browse-page.spec.js@@ -18,6 +18,9 @@ describe('Search Grid Wrapper', () => {query: { q: 'foo' },isFilterVisible: false,},+ getters: {+ isAnyFilterApplied: () => false,+ },mutations: {SET_FILTER_IS_VISIBLE: jest.fn(),},diff --git a/test/unit/specs/store/media-store.spec.js b/test/unit/specs/store/media-store.spec.jsindex 3a2abe59f..a2a0ba15a 100644--- a/test/unit/specs/store/media-store.spec.js+++ b/test/unit/specs/store/media-store.spec.js@@ -501,6 +501,7 @@ describe('Search Store', () => {const action = createActions(services)[HANDLE_NO_MEDIA]await action(context, { mediaCount: 0, mediaType: IMAGE })expect(context.commit).toHaveBeenLastCalledWith(FETCH_MEDIA_ERROR, {+ mediaType: IMAGE,errorMessage: 'No image found for this query',})})diff --git a/test/unit/specs/store/search-store.spec.js b/test/unit/specs/store/search-store.spec.jsindex 638ff0699..6c1fabbc2 100644--- a/test/unit/specs/store/search-store.spec.js+++ b/test/unit/specs/store/search-store.spec.js@@ -1,5 +1,6 @@import store, { filterData } from '~/store/search'import {+ CLEAR_FILTERS,SET_SEARCH_STATE_FROM_URL,TOGGLE_FILTER,UPDATE_QUERY_FROM_FILTERS,@@ -8,7 +9,6 @@ import {import {SET_FILTER,SET_PROVIDERS_FILTERS,- CLEAR_FILTERS,SET_FILTER_IS_VISIBLE,REPLACE_FILTERS,SET_SEARCH_TYPE,