Skip to content

Commit

Permalink
fix(animation-prop): decommission old animation-prop.ts and generaliz…
Browse files Browse the repository at this point in the history
…e the new one (#1660)
  • Loading branch information
joseacabaneros authored Nov 21, 2024
1 parent c61339f commit 493b6bd
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
4 changes: 2 additions & 2 deletions packages/x-components/src/components/items-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { computed, defineComponent, PropType } from 'vue';
import { ListItem } from '../utils/types';
import { toKebabCase } from '../utils/string';
import { animationProp } from '../utils/options-api';
import { AnimationProp } from '../types';
/**
* It renders a list of {@link ListItem} providing a slot for each `slotName` which depends on
Expand All @@ -39,7 +39,7 @@
props: {
/** Animation component that will be used to animate the list. */
animation: {
type: animationProp,
type: AnimationProp,
default: 'ul'
},
/** List of items. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

<script lang="ts">
import { Result } from '@empathyco/x-types';
import { computed, DefineComponent, defineComponent, PropType, Ref, ref, watch } from 'vue';
import { animationProp } from '../../utils/options-api';
import { computed, defineComponent, PropType, Ref, ref, watch } from 'vue';
import { NoAnimation } from '../animations';
import { AnimationProp } from '../../types';
/**
* Component to be reused that renders an `<img>`.
Expand All @@ -63,12 +63,12 @@
* image fallback.
*/
loadAnimation: {
type: animationProp,
type: AnimationProp,
default: () => NoAnimation
},
/** Animation to use when switching between the loaded image and the hover image. */
hoverAnimation: {
type: animationProp
type: AnimationProp
},
/**
* Indicates if the next valid image should be displayed on hover.
Expand Down Expand Up @@ -150,7 +150,7 @@
*
* @internal
*/
const animation = computed<DefineComponent | string>(() => {
const animation = computed(() => {
return userHasHoveredImage
? props.hoverAnimation ?? props.loadAnimation
: props.loadAnimation;
Expand All @@ -163,7 +163,7 @@
*
* @internal
*/
const imageSrc = computed<string>(() => {
const imageSrc = computed(() => {
return loadedImages.value[
!props.showNextImageOnHover || !isHovering.value ? 0 : loadedImages.value.length - 1
];
Expand All @@ -176,7 +176,7 @@
*
* @internal
*/
const shouldLoadNextImage = computed<boolean>(() => {
const shouldLoadNextImage = computed(() => {
const numImagesToLoad = props.showNextImageOnHover && userHasHoveredImage ? 2 : 1;
return !!pendingImages.value.length && loadedImages.value.length < numImagesToLoad;
});
Expand All @@ -186,7 +186,7 @@
*
* @internal
*/
const flagImageAsFailed = (): void => {
const flagImageAsFailed = () => {
pendingImages.value.shift();
};
Expand All @@ -195,7 +195,7 @@
*
* @internal
*/
const flagImageLoaded = (): void => {
const flagImageLoaded = () => {
const image = pendingImages.value.shift();
if (image) {
loadedImages.value.push(image);
Expand Down
12 changes: 6 additions & 6 deletions packages/x-components/src/types/animation-prop.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DefineComponent, PropType } from 'vue';

/**
* Type for animations props.
*
* @remarks
* String for 'ul'
* Object for `DefineComponent` type
* Function for `() => NoElement`
*
* @public
*/
export const AnimationProp = [String, Object, Function] as PropType<
// eslint-disable-next-line @typescript-eslint/ban-types
DefineComponent<{}, {}, any> | string
>;
export const AnimationProp = [String, Object, Function];
3 changes: 0 additions & 3 deletions packages/x-components/src/utils/options-api.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
import { Dictionary, map, objectFilter } from '@empathyco/x-utils';
import { computed, ComputedRef, defineComponent, PropType } from 'vue';
import { useGetter } from '../../../../composables/use-getter';
import { animationProp } from '../../../../utils/options-api';
import { toKebabCase } from '../../../../utils/string';
import { useFacets } from '../../composables/use-facets';
import { facetsXModule } from '../../x-module';
import { AnimationProp } from '../../../../types';
/**
* Custom interface to provide a slot name to a Facet.
Expand Down Expand Up @@ -93,7 +93,7 @@
alwaysVisible: Boolean,
/** Animation component that will be used to animate the facets. */
animation: {
type: animationProp,
type: AnimationProp,
default: 'ul'
},
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
<script lang="ts">
import { Facet, Filter, isFacetFilter } from '@empathyco/x-types';
import { defineComponent, PropType } from 'vue';
import { animationProp } from '../../../../utils/options-api';
import { toKebabCase } from '../../../../utils/string';
import { useFacets } from '../../composables/use-facets';
import { facetsXModule } from '../../x-module';
import { AnimationProp } from '../../../../types';
import SelectedFilters from './selected-filters.vue';
/**
Expand Down Expand Up @@ -78,7 +78,7 @@
alwaysVisible: Boolean,
/** Animation component that will be used to animate the selected filters list. */
animation: {
type: animationProp,
type: AnimationProp,
default: 'ul'
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
} from '../../../components/decorators/injection.consts';
import ItemsList from '../../../components/items-list.vue';
import { RequestStatus } from '../../../store/utils/status-store.utils';
import { animationProp } from '../../../utils/options-api';
import { useState } from '../../../composables/use-state';
import { searchXModule } from '../x-module';
import { AnimationProp } from '../../../types';
/**
* It renders a {@link ItemsList} list with the results from {@link SearchState.results} by
Expand All @@ -29,7 +29,7 @@
props: {
/** Animation component that will be used to animate the results. */
animation: {
type: animationProp,
type: AnimationProp,
default: 'ul'
}
},
Expand Down

0 comments on commit 493b6bd

Please sign in to comment.