Skip to content

Commit 28e79d2

Browse files
committed
refactor: reorganize constants and types for improved clarity and maintainability
1 parent 6c749e2 commit 28e79d2

File tree

4 files changed

+69
-64
lines changed

4 files changed

+69
-64
lines changed

src/shared/constants.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { CarouselConfig } from './types'
22

3-
export const SNAP_ALIGN_OPTIONS = [
4-
'center',
5-
'start',
6-
'end',
7-
'center-even',
8-
'center-odd',
9-
] as const
10-
export const SLIDE_EFFECTS = ['slide', 'fade'] as const
113
export const BREAKPOINT_MODE_OPTIONS = ['viewport', 'carousel'] as const
4+
5+
export const DIR_MAP = {
6+
'bottom-to-top': 'btt',
7+
'left-to-right': 'ltr',
8+
'right-to-left': 'rtl',
9+
'top-to-bottom': 'ttb',
10+
} as const
11+
1212
export const DIR_OPTIONS = [
1313
'ltr',
1414
'left-to-right',
@@ -19,47 +19,51 @@ export const DIR_OPTIONS = [
1919
'btt',
2020
'bottom-to-top',
2121
] as const
22+
2223
export const I18N_DEFAULT_CONFIG = {
24+
ariaGallery: 'Gallery',
25+
ariaNavigateToPage: 'Navigate to page {slideNumber}',
26+
ariaNavigateToSlide: 'Navigate to slide {slideNumber}',
2327
ariaNextSlide: 'Navigate to next slide',
2428
ariaPreviousSlide: 'Navigate to previous slide',
25-
ariaNavigateToSlide: 'Navigate to slide {slideNumber}',
26-
ariaNavigateToPage: 'Navigate to page {slideNumber}',
27-
ariaGallery: 'Gallery',
28-
itemXofY: 'Item {currentSlide} of {slidesCount}',
29-
iconArrowUp: 'Arrow pointing upwards',
3029
iconArrowDown: 'Arrow pointing downwards',
31-
iconArrowRight: 'Arrow pointing to the right',
3230
iconArrowLeft: 'Arrow pointing to the left',
33-
} as const
34-
35-
export const DIR_MAP = {
36-
'left-to-right': 'ltr',
37-
'right-to-left': 'rtl',
38-
'top-to-bottom': 'ttb',
39-
'bottom-to-top': 'btt',
31+
iconArrowRight: 'Arrow pointing to the right',
32+
iconArrowUp: 'Arrow pointing upwards',
33+
itemXofY: 'Item {currentSlide} of {slidesCount}',
4034
} as const
4135

4236
export const NORMALIZED_DIR_OPTIONS = Object.values(DIR_MAP)
4337

38+
export const SLIDE_EFFECTS = ['slide', 'fade'] as const
39+
40+
export const SNAP_ALIGN_OPTIONS = [
41+
'center',
42+
'start',
43+
'end',
44+
'center-even',
45+
'center-odd',
46+
] as const
47+
4448
export const DEFAULT_CONFIG: CarouselConfig = {
45-
enabled: true,
46-
itemsToShow: 1,
47-
itemsToScroll: 1,
48-
modelValue: 0,
49-
transition: 300,
5049
autoplay: 0,
51-
gap: 0,
52-
height: 'auto',
53-
wrapAround: false,
54-
pauseAutoplayOnHover: false,
55-
mouseDrag: true,
56-
touchDrag: true,
57-
snapAlign: SNAP_ALIGN_OPTIONS[0],
58-
dir: DIR_OPTIONS[0],
5950
breakpointMode: BREAKPOINT_MODE_OPTIONS[0],
6051
breakpoints: undefined,
52+
dir: DIR_OPTIONS[0],
53+
enabled: true,
54+
gap: 0,
55+
height: 'auto',
6156
i18n: I18N_DEFAULT_CONFIG,
6257
ignoreAnimations: false,
63-
slideEffect: SLIDE_EFFECTS[0],
58+
itemsToScroll: 1,
59+
itemsToShow: 1,
60+
modelValue: 0,
61+
mouseDrag: true,
62+
pauseAutoplayOnHover: false,
6463
preventExcessiveDragging: false,
64+
slideEffect: SLIDE_EFFECTS[0],
65+
snapAlign: SNAP_ALIGN_OPTIONS[0],
66+
touchDrag: true,
67+
transition: 300,
68+
wrapAround: false,
6569
}

src/shared/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './injectSymbols'
21
export * from './constants'
3-
export * from './types'
2+
export * from './injectSymbols'
43
export * from './slideRegistry'
4+
export * from './types'

src/shared/slideRegistry.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ const createSlideRegistry = (emit: EmitFn) => {
1616
}
1717

1818
return {
19+
cleanup: () => {
20+
slides.splice(0, slides.length)
21+
},
22+
23+
getSlides: () => slides,
24+
1925
registerSlide: (slide: ComponentInternalInstance, index?: number) => {
2026
if (!slide) return
2127

@@ -38,12 +44,6 @@ const createSlideRegistry = (emit: EmitFn) => {
3844
slides.splice(slideIndex, 1)
3945
updateSlideIndexes(slideIndex)
4046
},
41-
42-
cleanup: () => {
43-
slides.splice(0, slides.length)
44-
},
45-
46-
getSlides: () => slides,
4747
}
4848
}
4949

src/shared/types.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
11
import {
22
BREAKPOINT_MODE_OPTIONS,
3+
DIR_MAP,
34
DIR_OPTIONS,
4-
SNAP_ALIGN_OPTIONS,
55
I18N_DEFAULT_CONFIG,
66
NORMALIZED_DIR_OPTIONS,
7-
DIR_MAP,
87
SLIDE_EFFECTS,
8+
SNAP_ALIGN_OPTIONS,
99
} from './constants'
1010

11+
export type BreakpointMode = (typeof BREAKPOINT_MODE_OPTIONS)[number]
12+
1113
export type Breakpoints = {
1214
[key: number]: Partial<
1315
Omit<CarouselConfig, 'breakpoints' | 'modelValue' | 'breakpointMode'>
1416
>
1517
}
1618

17-
export type SlideEffect = (typeof SLIDE_EFFECTS)[number]
18-
export type SnapAlign = (typeof SNAP_ALIGN_OPTIONS)[number]
19-
2019
export type Dir = (typeof DIR_OPTIONS)[number]
2120

22-
export type BreakpointMode = (typeof BREAKPOINT_MODE_OPTIONS)[number]
21+
export type I18nKeys = keyof typeof I18N_DEFAULT_CONFIG
22+
23+
export type NonNormalizedDir = keyof typeof DIR_MAP
2324

2425
export type NormalizedDir = (typeof NORMALIZED_DIR_OPTIONS)[number]
2526

26-
export type NonNormalizedDir = keyof typeof DIR_MAP
27+
export type SlideEffect = (typeof SLIDE_EFFECTS)[number]
2728

28-
export type I18nKeys = keyof typeof I18N_DEFAULT_CONFIG
29+
export type SnapAlign = (typeof SNAP_ALIGN_OPTIONS)[number]
2930

3031
export interface CarouselConfig {
31-
enabled: boolean
32-
itemsToShow: number | 'auto'
33-
itemsToScroll: number
34-
modelValue?: number
35-
transition?: number
36-
gap: number
3732
autoplay?: number
38-
snapAlign: SnapAlign
39-
wrapAround?: boolean
40-
pauseAutoplayOnHover?: boolean
41-
mouseDrag?: boolean
42-
touchDrag?: boolean
43-
dir?: Dir
4433
breakpointMode?: BreakpointMode
4534
breakpoints?: Breakpoints
35+
dir?: Dir
36+
enabled: boolean
37+
gap: number
4638
height: string | number
4739
i18n: { [key in I18nKeys]?: string }
4840
ignoreAnimations: boolean | string[] | string
49-
slideEffect: SlideEffect
41+
itemsToScroll: number
42+
itemsToShow: number | 'auto'
43+
modelValue?: number
44+
mouseDrag?: boolean
45+
pauseAutoplayOnHover?: boolean
5046
preventExcessiveDragging: boolean
47+
slideEffect: SlideEffect
48+
snapAlign: SnapAlign
49+
touchDrag?: boolean
50+
transition?: number
51+
wrapAround?: boolean
5152
}
5253

5354
export type VueClass = string | Record<string, boolean> | VueClass[]

0 commit comments

Comments
 (0)