@fox-dls/carousels 1.1.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,12 +2,19 @@
2
2
  /* eslint-disable unused-imports/no-unused-vars */
3
3
  import React, { useRef, useState } from 'react';
4
4
 
5
- import { css } from 'styled-components';
6
5
  import SwiperCore, { Navigation } from 'swiper';
7
6
  // eslint-disable-next-line import/extensions
8
7
  import { SwiperSlide } from 'swiper/react';
9
8
 
10
- import { CarouselSwiper, CarouselPillContainer, CarouselPill } from './styles';
9
+ import {
10
+ CarouselSwiper,
11
+ CarouselPillContainer,
12
+ CarouselPill,
13
+ CarouselPillFlex,
14
+ CarouselPillArrowContainer,
15
+ CarouselPillInlineChild,
16
+ CarouselPillArrowSVG
17
+ } from './styles';
11
18
 
12
19
  SwiperCore.use([Navigation]);
13
20
 
@@ -28,30 +35,10 @@ export const PillsCarousel: React.FC<any> = ({
28
35
  });
29
36
  const [swiper, setSwiper] = useState<any>(null);
30
37
  return (
31
- <div
32
- css={`
33
- display: flex !important;
34
- position: relative !important;
35
- min-width: 0px !important;
36
- `}
37
- >
38
- <div
39
- css={`
40
- position: absolute !important;
41
- left: 0px !important;
42
- z-index: 3 !important;
43
- width: 65px !important;
44
- background: linear-gradient(
45
- to right,
46
- rgb(255, 255, 255) 56.77%,
47
- rgba(255, 255, 255, 0) 94.47%
48
- ) !important;
49
- ${swiperSlides.isBeginning &&
50
- css`
51
- display: none !important;
52
- visibility: hidden !important;
53
- `}
54
- `}
38
+ <CarouselPillFlex>
39
+ <CarouselPillArrowContainer
40
+ start={true}
41
+ hidden={swiperSlides.isBeginning}
55
42
  >
56
43
  {arrows && (
57
44
  <CarouselPillContainer>
@@ -62,36 +49,23 @@ export const PillsCarousel: React.FC<any> = ({
62
49
  type="button"
63
50
  onClick={() => swiper.slidePrev()}
64
51
  >
65
- <span
66
- css={`
67
- position: relative !important;
68
- `}
69
- >
70
- <svg
52
+ <span style={{ position: 'relative' }}>
53
+ <CarouselPillArrowSVG
71
54
  viewBox="0 0 32 32"
72
55
  xmlns="http://www.w3.org/2000/svg"
73
56
  aria-hidden="true"
74
57
  role="presentation"
75
58
  focusable="false"
76
- css={`
77
- display: block;
78
- fill: none;
79
- height: 12px;
80
- width: 12px;
81
- stroke: currentcolor;
82
- stroke-width: 5.33333;
83
- overflow: visible;
84
- `}
85
59
  >
86
60
  <g fill="none">
87
61
  <path d="m20 28-11.29289322-11.2928932c-.39052429-.3905243-.39052429-1.0236893 0-1.4142136l11.29289322-11.2928932" />
88
62
  </g>
89
- </svg>
63
+ </CarouselPillArrowSVG>
90
64
  </span>
91
65
  </CarouselPill>
92
66
  </CarouselPillContainer>
93
67
  )}
94
- </div>
68
+ </CarouselPillArrowContainer>
95
69
 
96
70
  <CarouselSwiper
97
71
  {...props}
@@ -128,42 +102,12 @@ export const PillsCarousel: React.FC<any> = ({
128
102
  >
129
103
  {React.Children.map(children, child => (
130
104
  <SwiperSlide>
131
- <div
132
- css={`
133
- display: inline-block !important;
134
- white-space: nowrap !important;
135
- padding-right: 8px !important;
136
- padding-top: 4px !important;
137
- padding-bottom: 4px !important;
138
- `}
139
- >
140
- {child}
141
- </div>
105
+ <CarouselPillInlineChild>{child}</CarouselPillInlineChild>
142
106
  </SwiperSlide>
143
107
  ))}
144
108
  </CarouselSwiper>
145
109
 
146
- <div
147
- css={`
148
- -webkit-box-pack: end !important;
149
- position: absolute !important;
150
- right: 0px !important;
151
- z-index: 3 !important;
152
- width: 75px !important;
153
- display: flex !important;
154
- justify-content: flex-end !important;
155
- background: linear-gradient(
156
- to left,
157
- rgb(255, 255, 255) 56.77%,
158
- rgba(255, 255, 255, 0) 94.47%
159
- ) !important;
160
- ${swiperSlides.isEnd &&
161
- css`
162
- display: none !important;
163
- visibility: hidden !important;
164
- `}
165
- `}
166
- >
110
+ <CarouselPillArrowContainer hidden={swiperSlides.isEnd} end={true}>
167
111
  {arrows && (
168
112
  <CarouselPillContainer>
169
113
  <CarouselPill
@@ -173,36 +117,23 @@ export const PillsCarousel: React.FC<any> = ({
173
117
  ref={nextRef}
174
118
  onClick={() => swiper.slideNext()}
175
119
  >
176
- <span
177
- css={`
178
- position: relative !important;
179
- `}
180
- >
181
- <svg
120
+ <span style={{ position: 'relative' }}>
121
+ <CarouselPillArrowSVG
182
122
  viewBox="0 0 32 32"
183
123
  xmlns="http://www.w3.org/2000/svg"
184
124
  aria-hidden="true"
185
125
  role="presentation"
186
126
  focusable="false"
187
- css={`
188
- display: block;
189
- fill: none;
190
- height: 12px;
191
- width: 12px;
192
- stroke: currentcolor;
193
- stroke-width: 5.33333;
194
- overflow: visible;
195
- `}
196
127
  >
197
128
  <g fill="none">
198
129
  <path d="m12 4 11.2928932 11.2928932c.3905243.3905243.3905243 1.0236893 0 1.4142136l-11.2928932 11.2928932" />
199
130
  </g>
200
- </svg>
131
+ </CarouselPillArrowSVG>
201
132
  </span>
202
133
  </CarouselPill>
203
134
  </CarouselPillContainer>
204
135
  )}
205
- </div>
206
- </div>
136
+ </CarouselPillArrowContainer>
137
+ </CarouselPillFlex>
207
138
  );
208
139
  };
@@ -1,5 +1,5 @@
1
1
  import ButtonUnstyled from '@mui/core/ButtonUnstyled';
2
- import styled from 'styled-components';
2
+ import styled, { css } from 'styled-components';
3
3
  // eslint-disable-next-line import/extensions
4
4
  import { Swiper } from 'swiper/react';
5
5
 
@@ -56,3 +56,61 @@ export const CarouselPill = styled(ButtonUnstyled)<any>`
56
56
  border: 1px solid rgb(221, 221, 221) !important;
57
57
  }
58
58
  `;
59
+
60
+ export const CarouselPillFlex = styled.div`
61
+ display: flex !important;
62
+ position: relative !important;
63
+ min-width: 0px !important;
64
+ `;
65
+
66
+ export const CarouselPillArrowContainer = styled.div<any>`
67
+ position: absolute !important;
68
+ background: linear-gradient(
69
+ to left,
70
+ rgb(255, 255, 255) 56.77%,
71
+ rgba(255, 255, 255, 0) 94.47%
72
+ ) !important;
73
+ z-index: 3 !important;
74
+
75
+ ${props =>
76
+ props.start &&
77
+ css`
78
+ left: 0px !important;
79
+ width: 65px !important;
80
+ `}
81
+
82
+ ${props =>
83
+ props.end &&
84
+ css`
85
+ -webkit-box-pack: end !important;
86
+ right: 0px !important;
87
+ width: 75px !important;
88
+ display: flex !important;
89
+ justify-content: flex-end !important;
90
+ `}
91
+
92
+ ${props =>
93
+ props.hidden &&
94
+ css`
95
+ display: none !important;
96
+ visibility: hidden !important;
97
+ `}
98
+ `;
99
+
100
+ export const CarouselPillInlineChild = styled.div`
101
+ display: inline-block !important;
102
+ white-space: nowrap !important;
103
+ padding-right: 8px !important;
104
+ padding-top: 4px !important;
105
+ padding-bottom: 4px !important;
106
+ `;
107
+
108
+ export const CarouselPillArrowSVG = styled.svg`
109
+ display: block;
110
+ fill: none;
111
+ height: 12px;
112
+ width: 12px;
113
+ stroke: currentcolor;
114
+ stroke-width: 5.33333;
115
+ overflow: visible;
116
+ `;
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "extends": "../../tsconfig.build.json",
3
- "include": ["src", "types", "../../types"]
3
+ "include": ["src", "types", "../../types", "../styled.d.ts"]
4
4
  }