forked from mantinedev/mantine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarouselSlide.styles.ts
71 lines (63 loc) · 2.13 KB
/
CarouselSlide.styles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { createStyles, MantineNumberSize, getSortedBreakpoints } from '@mantine/core';
import { CarouselOrientation, CarouselBreakpoint } from '../types';
export interface CarouselSlideStylesParams {
size: string | number;
gap: MantineNumberSize;
orientation: CarouselOrientation;
includeGapInSize: boolean;
breakpoints: CarouselBreakpoint[];
}
export default createStyles(
(
theme,
{ size, gap, orientation, includeGapInSize, breakpoints = [] }: CarouselSlideStylesParams
) => {
const slideBreakpoints = getSortedBreakpoints(theme, breakpoints).reduce((acc, breakpoint) => {
const property = 'maxWidth' in breakpoint ? 'max-width' : 'min-width';
const breakpointSize = theme.fn.size({
size: property === 'max-width' ? breakpoint.maxWidth : breakpoint.minWidth,
sizes: theme.breakpoints,
});
const breakpointGap = typeof breakpoint.slideGap === 'undefined' ? gap : breakpoint.slideGap;
acc[`@media (${property}: ${breakpointSize + (property === 'max-width' ? 0 : 1)}px)`] = {
flex: `0 0 calc(${
typeof breakpoint.slideSize === 'number'
? `${breakpoint.slideSize}px`
: breakpoint.slideSize
} - ${
includeGapInSize
? theme.fn.size({
size: breakpointGap,
sizes: theme.spacing,
}) / 2
: 0
}px)`,
[orientation === 'horizontal' ? 'marginRight' : 'marginBottom']: theme.fn.size({
size: breakpointGap,
sizes: theme.spacing,
}),
};
return acc;
}, {});
return {
slide: {
position: 'relative',
flex: `0 0 calc(${typeof size === 'number' ? `${size}px` : size} - ${
includeGapInSize
? theme.fn.size({
size: gap,
sizes: theme.spacing,
}) / 2
: 0
}px)`,
'&:not(:last-of-type)': {
[orientation === 'horizontal' ? 'marginRight' : 'marginBottom']: theme.fn.size({
size: gap,
sizes: theme.spacing,
}),
},
...slideBreakpoints,
},
};
}
);