Skip to content

Commit

Permalink
refactor: update props to type-based declaration approach (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlmoravek authored Nov 19, 2024
1 parent 37e17f5 commit e3f94b1
Show file tree
Hide file tree
Showing 20 changed files with 650 additions and 895 deletions.
197 changes: 25 additions & 172 deletions packages/oruga/src/components/carousel/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
readonly,
toRaw,
useTemplateRef,
type PropType,
} from "vue";
import OIcon from "../icon/Icon.vue";
Expand All @@ -24,7 +23,8 @@ import {
} from "@/composables";
import type { CarouselComponent } from "./types";
import type { ComponentClass, ClassBind } from "@/types";
import type { ClassBind } from "@/types";
import type { CarouselProps } from "./props";
/**
* A Slideshow for cycling images in confined spaces
Expand All @@ -38,176 +38,29 @@ defineOptions({
configField: "carousel",
});
const props = defineProps({
/** Override existing theme classes completely */
override: { type: Boolean, default: undefined },
/** The index of the current active element */
modelValue: { type: Number, default: 0 },
/** Enable drag mode */
dragable: { type: Boolean, default: true },
/** Timer interval for `autoplay` */
interval: {
type: Number,
default: () => getDefault("carousel.interval", 3500),
},
/** Move item automaticalls after `interval` */
autoplay: { type: Boolean, default: false },
/** Pause autoplay on hover */
pauseHover: { type: Boolean, default: false },
/** Repeat from the beginning after reaching the end */
repeat: { type: Boolean, default: false },
/** Show an overlay */
overlay: { type: Boolean, default: false },
/** Enable indicators */
indicators: { type: Boolean, default: true },
/** Place indicators inside the carousel */
indicatorInside: { type: Boolean, default: false },
/**
* Indicator interaction mode
* @values click, hover
*/
indicatorMode: {
type: String,
default: "click",
validator: (value: string) => ["click", "hover"].indexOf(value) >= 0,
},
/** Position of the indicator - depends on used theme */
indicatorPosition: {
type: String,
default: () => getDefault("carousel.indicatorPosition", "bottom"),
},
/** Style of the indicator - depends on used theme */
indicatorStyle: {
type: String,
default: () => getDefault("carousel.indicatorStyle", "dots"),
},
/** Number of items to show at once*/
itemsToShow: {
type: Number,
default: () => getDefault("carousel.itemsToShow", 1),
},
/** Number of items to switch at once */
itemsToList: {
type: Number,
default: () => getDefault("carousel.itemsToList", 1),
},
/** Show next / prev arrows */
arrows: {
type: Boolean,
default: () => getDefault("carousel.arrows", true),
},
/** Show next / prev arrows only on hover */
arrowsHover: {
type: Boolean,
default: () => getDefault("carousel.arrowsHover", true),
},
/**
* Icon pack to use
* @values mdi, fa, fas and any other custom icon pack
*/
iconPack: {
type: String,
default: () => getDefault("carousel.iconPack"),
},
/**
* Icon size
* @values small, medium, large
*/
iconSize: {
type: String,
default: () => getDefault("carousel.iconSize"),
},
/** Icon name for previous icon */
iconPrev: {
type: String,
default: () => getDefault("carousel.iconPrev", "chevron-left"),
},
/** Icon name for next icon */
iconNext: {
type: String,
default: () => getDefault("carousel.iconNext", "chevron-right"),
},
/** Define these props for different screen sizes */
breakpoints: {
type: Object as PropType<Record<number, any>>,
default: () => ({}),
},
// class props (will not be displayed in the docs)
/** Class of the root element */
rootClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of the root element in overlay */
overlayClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of the wrapper element of carousel items */
wrapperClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of slider items */
itemsClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of slider items on drag */
itemsDraggingClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of arrow elements */
arrowIconClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of prev arrow element */
arrowIconPrevClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of next arrow element */
arrowIconNextClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of indicator link element */
indicatorClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of indicators wrapper element */
indicatorsClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of indicators wrapper element when inside */
indicatorsInsideClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of indicators wrapper element when inside and position */
indicatorsInsidePositionClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of indicator item element */
indicatorItemClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of indicator element when is active */
indicatorItemActiveClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of indicator element to separate different styles */
indicatorItemStyleClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
const props = withDefaults(defineProps<CarouselProps>(), {
override: undefined,
modelValue: 0,
dragable: true,
interval: () => getDefault("carousel.interval", 3500),
autoplay: false,
pauseHover: false,
repeat: false,
overlay: false,
indicators: true,
indicatorInside: false,
indicatorMode: "click",
indicatorPosition: () => getDefault("carousel.indicatorPosition", "bottom"),
indicatorStyle: () => getDefault("carousel.indicatorStyle", "dots"),
itemsToShow: () => getDefault("carousel.itemsToShow", 1),
itemsToList: () => getDefault("carousel.itemsToList", 1),
arrows: () => getDefault("carousel.arrows", true),
arrowsHover: () => getDefault("carousel.arrowsHover", true),
iconPack: () => getDefault("carousel.iconPack"),
iconSize: () => getDefault("carousel.iconSize"),
iconPrev: () => getDefault("carousel.iconPrev", "chevron-left"),
iconNext: () => getDefault("carousel.iconNext", "chevron-right"),
breakpoints: () => ({}),
});
const emits = defineEmits<{
Expand Down
34 changes: 6 additions & 28 deletions packages/oruga/src/components/carousel/CarouselItem.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup lang="ts">
import { computed, type PropType } from "vue";
import { computed } from "vue";
import { getDefault } from "@/utils/config";
import { defineClasses, useProviderChild } from "@/composables";
import type { CarouselComponent } from "./types";
import type { ComponentClass } from "@/types";
import type { CarouselItemProps } from "./props";
/**
* A Slideshow item used by the carousel
Expand All @@ -17,32 +17,10 @@ defineOptions({
configField: "carousel",
});
const props = defineProps({
/** Override existing theme classes completely */
override: { type: Boolean, default: undefined },
/** Make item clickable */
clickable: { type: Boolean, default: false },
/** Role attribute to be passed to the div wrapper for better accessibility */
ariaRole: {
type: String,
default: () => getDefault("carousel.ariaRole", "option"),
},
// class props (will not be displayed in the docs)
/** Class of carousel item */
itemClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of carousel item when is active */
itemActiveClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
/** Class of carousel item when is clickable */
itemClickableClass: {
type: [String, Array, Function] as PropType<ComponentClass>,
default: undefined,
},
const props = withDefaults(defineProps<CarouselItemProps>(), {
override: undefined,
clickable: false,
ariaRole: () => getDefault("carousel.ariaRole", "option"),
});
// Inject functionalities and data from the parent carousel component
Expand Down
109 changes: 109 additions & 0 deletions packages/oruga/src/components/carousel/props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import type { ComponentClass } from "@/types";

export type CarouselProps = {
/** Override existing theme classes completely */
override?: boolean;
/** The index of the current active element */
modelValue?: number;
/** Enable drag mode */
dragable?: boolean;
/** Timer interval for `autoplay` */
interval?: number;
/** Move item automaticalls after `interval` */
autoplay?: boolean;
/** Pause autoplay on hover */
pauseHover?: boolean;
/** Repeat from the beginning after reaching the end */
repeat?: boolean;
/** Show an overlay */
overlay?: boolean;
/** Enable indicators */
indicators?: boolean;
/** Place indicators inside the carousel */
indicatorInside?: boolean;
/**
* Indicator interaction mode
* @values click, hover
*/
indicatorMode?: "click" | "hover";
/** Position of the indicator - depends on used theme */
indicatorPosition?: string;
/** Style of the indicator - depends on used theme */
indicatorStyle?: string;
/** Number of items to show at once*/
itemsToShow?: number;
/** Number of items to switch at once */
itemsToList?: number;
/** Show next / prev arrows */
arrows?: boolean;
/** Show next / prev arrows only on hover */
arrowsHover?: boolean;
/**
* Icon pack to use
* @values mdi, fa, fas and any other custom icon pack
*/
iconPack?: string;
/**
* Icon size
* @values small, medium, large
*/
iconSize?: string;
/** Icon name for previous icon */
iconPrev?: string;
/** Icon name for next icon */
iconNext?: string;
/** Define these props for different screen sizes */
breakpoints?: Record<number, any>;
} & CarouselClasses;

// class props (will not be displayed in the docs)
type CarouselClasses = Partial<{
/** Class of the root element */
rootClass: ComponentClass;
/** Class of the root element in overlay */
overlayClass: ComponentClass;
/** Class of the wrapper element of carousel items */
wrapperClass: ComponentClass;
/** Class of slider items */
itemsClass: ComponentClass;
/** Class of slider items on drag */
itemsDraggingClass: ComponentClass;
/** Class of arrow elements */
arrowIconClass: ComponentClass;
/** Class of prev arrow element */
arrowIconPrevClass: ComponentClass;
/** Class of next arrow element */
arrowIconNextClass: ComponentClass;
/** Class of indicator link element */
indicatorClass: ComponentClass;
/** Class of indicators wrapper element */
indicatorsClass: ComponentClass;
/** Class of indicators wrapper element when inside */
indicatorsInsideClass: ComponentClass;
/** Class of indicators wrapper element when inside and position */
indicatorsInsidePositionClass: ComponentClass;
/** Class of indicator item element */
indicatorItemClass: ComponentClass;
/** Class of indicator element when is active */
indicatorItemActiveClass: ComponentClass;
/** Class of indicator element to separate different styles */
indicatorItemStyleClass: ComponentClass;
}>;

export type CarouselItemProps = {
override?: boolean;
/** Make item clickable */
clickable?: boolean;
/** Role attribute to be passed to the div wrapper for better accessibility */
ariaRole?: string;
} & CarouselItemClasses;

// class props (will not be displayed in the docs)
type CarouselItemClasses = Partial<{
/** Class of carousel item */
itemClass: ComponentClass;
/** Class of carousel item when is active */
itemActiveClass: ComponentClass;
/** Class of carousel item when is clickable */
itemClickableClass: ComponentClass;
}>;
Loading

0 comments on commit e3f94b1

Please sign in to comment.