@douyinfe/semi-foundation 2.9.1 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/carousel/carousel.scss +425 -0
  2. package/carousel/constants.ts +32 -0
  3. package/carousel/foundation.ts +164 -0
  4. package/carousel/rtl.scss +47 -0
  5. package/carousel/variables.scss +46 -0
  6. package/cascader/foundation.ts +6 -6
  7. package/checkbox/checkboxGroupFoundation.ts +2 -2
  8. package/datePicker/_utils/getDefaultPickerDate.ts +3 -3
  9. package/datePicker/_utils/parser.ts +1 -1
  10. package/datePicker/foundation.ts +4 -4
  11. package/datePicker/monthsGridFoundation.ts +11 -11
  12. package/datePicker/yearAndMonthFoundation.ts +1 -1
  13. package/form/foundation.ts +9 -5
  14. package/form/interface.ts +1 -0
  15. package/input/textareaFoundation.ts +5 -5
  16. package/inputNumber/foundation.ts +25 -9
  17. package/lib/cjs/carousel/carousel.css +341 -0
  18. package/lib/cjs/carousel/carousel.scss +425 -0
  19. package/lib/cjs/carousel/constants.d.ts +27 -0
  20. package/lib/cjs/carousel/constants.js +41 -0
  21. package/lib/cjs/carousel/foundation.d.ts +29 -0
  22. package/lib/cjs/carousel/foundation.js +216 -0
  23. package/lib/cjs/carousel/rtl.scss +47 -0
  24. package/lib/cjs/carousel/variables.scss +46 -0
  25. package/lib/cjs/cascader/foundation.d.ts +2 -2
  26. package/lib/cjs/cascader/foundation.js +6 -6
  27. package/lib/cjs/checkbox/checkboxGroupFoundation.d.ts +1 -1
  28. package/lib/cjs/checkbox/checkboxGroupFoundation.js +2 -2
  29. package/lib/cjs/datePicker/_utils/getDefaultPickerDate.js +2 -2
  30. package/lib/cjs/datePicker/_utils/parser.d.ts +1 -1
  31. package/lib/cjs/datePicker/_utils/parser.js +2 -2
  32. package/lib/cjs/datePicker/foundation.js +3 -3
  33. package/lib/cjs/datePicker/monthsGridFoundation.js +9 -9
  34. package/lib/cjs/datePicker/yearAndMonthFoundation.d.ts +1 -1
  35. package/lib/cjs/datePicker/yearAndMonthFoundation.js +2 -2
  36. package/lib/cjs/form/foundation.d.ts +1 -0
  37. package/lib/cjs/form/foundation.js +9 -5
  38. package/lib/cjs/form/interface.d.ts +1 -0
  39. package/lib/cjs/input/textareaFoundation.d.ts +5 -5
  40. package/lib/cjs/inputNumber/foundation.d.ts +8 -0
  41. package/lib/cjs/inputNumber/foundation.js +20 -8
  42. package/lib/cjs/navigation/foundation.d.ts +3 -3
  43. package/lib/cjs/navigation/foundation.js +13 -13
  44. package/lib/cjs/switch/constants.d.ts +1 -0
  45. package/lib/cjs/switch/constants.js +1 -0
  46. package/lib/cjs/switch/foundation.d.ts +3 -0
  47. package/lib/cjs/switch/foundation.js +18 -0
  48. package/lib/cjs/switch/switch.css +3 -0
  49. package/lib/cjs/switch/switch.scss +4 -0
  50. package/lib/cjs/switch/variables.scss +2 -0
  51. package/lib/cjs/tabs/foundation.js +2 -2
  52. package/lib/cjs/timePicker/ComboxFoundation.js +1 -1
  53. package/lib/cjs/timePicker/constants.d.ts +1 -1
  54. package/lib/cjs/timePicker/constants.js +1 -1
  55. package/lib/cjs/timePicker/foundation.js +1 -1
  56. package/lib/cjs/transfer/foundation.js +3 -3
  57. package/lib/cjs/transfer/{transferUtlls.d.ts → transferUtils.d.ts} +0 -0
  58. package/lib/cjs/transfer/{transferUtlls.js → transferUtils.js} +0 -0
  59. package/lib/cjs/tree/foundation.d.ts +2 -2
  60. package/lib/cjs/tree/foundation.js +4 -4
  61. package/lib/cjs/tree/treeUtil.js +11 -11
  62. package/lib/cjs/treeSelect/constants.d.ts +1 -1
  63. package/lib/cjs/treeSelect/constants.js +1 -1
  64. package/lib/cjs/treeSelect/foundation.d.ts +2 -2
  65. package/lib/cjs/treeSelect/foundation.js +4 -4
  66. package/lib/cjs/upload/foundation.js +8 -8
  67. package/lib/cjs/upload/utils.js +1 -1
  68. package/lib/cjs/utils/isNullOrUndefined.d.ts +1 -1
  69. package/lib/cjs/utils/isNullOrUndefined.js +1 -1
  70. package/lib/cjs/utils/object.d.ts +6 -6
  71. package/lib/cjs/utils/object.js +2 -2
  72. package/lib/es/carousel/carousel.css +341 -0
  73. package/lib/es/carousel/carousel.scss +425 -0
  74. package/lib/es/carousel/constants.d.ts +27 -0
  75. package/lib/es/carousel/constants.js +28 -0
  76. package/lib/es/carousel/foundation.d.ts +29 -0
  77. package/lib/es/carousel/foundation.js +198 -0
  78. package/lib/es/carousel/rtl.scss +47 -0
  79. package/lib/es/carousel/variables.scss +46 -0
  80. package/lib/es/cascader/foundation.d.ts +2 -2
  81. package/lib/es/cascader/foundation.js +6 -6
  82. package/lib/es/checkbox/checkboxGroupFoundation.d.ts +1 -1
  83. package/lib/es/checkbox/checkboxGroupFoundation.js +2 -2
  84. package/lib/es/datePicker/_utils/getDefaultPickerDate.js +3 -3
  85. package/lib/es/datePicker/_utils/parser.d.ts +1 -1
  86. package/lib/es/datePicker/_utils/parser.js +1 -1
  87. package/lib/es/datePicker/foundation.js +4 -4
  88. package/lib/es/datePicker/monthsGridFoundation.js +10 -10
  89. package/lib/es/datePicker/yearAndMonthFoundation.d.ts +1 -1
  90. package/lib/es/datePicker/yearAndMonthFoundation.js +1 -1
  91. package/lib/es/form/foundation.d.ts +1 -0
  92. package/lib/es/form/foundation.js +9 -5
  93. package/lib/es/form/interface.d.ts +1 -0
  94. package/lib/es/input/textareaFoundation.d.ts +5 -5
  95. package/lib/es/inputNumber/foundation.d.ts +8 -0
  96. package/lib/es/inputNumber/foundation.js +18 -8
  97. package/lib/es/navigation/foundation.d.ts +3 -3
  98. package/lib/es/navigation/foundation.js +13 -13
  99. package/lib/es/switch/constants.d.ts +1 -0
  100. package/lib/es/switch/constants.js +1 -0
  101. package/lib/es/switch/foundation.d.ts +3 -0
  102. package/lib/es/switch/foundation.js +18 -0
  103. package/lib/es/switch/switch.css +3 -0
  104. package/lib/es/switch/switch.scss +4 -0
  105. package/lib/es/switch/variables.scss +2 -0
  106. package/lib/es/tabs/foundation.js +2 -2
  107. package/lib/es/timePicker/ComboxFoundation.js +1 -1
  108. package/lib/es/timePicker/constants.d.ts +1 -1
  109. package/lib/es/timePicker/constants.js +1 -1
  110. package/lib/es/timePicker/foundation.js +1 -1
  111. package/lib/es/transfer/foundation.js +1 -1
  112. package/lib/es/transfer/{transferUtlls.d.ts → transferUtils.d.ts} +0 -0
  113. package/lib/es/transfer/{transferUtlls.js → transferUtils.js} +0 -0
  114. package/lib/es/tree/foundation.d.ts +2 -2
  115. package/lib/es/tree/foundation.js +4 -4
  116. package/lib/es/tree/treeUtil.js +11 -11
  117. package/lib/es/treeSelect/constants.d.ts +1 -1
  118. package/lib/es/treeSelect/constants.js +1 -1
  119. package/lib/es/treeSelect/foundation.d.ts +2 -2
  120. package/lib/es/treeSelect/foundation.js +4 -4
  121. package/lib/es/upload/foundation.js +8 -8
  122. package/lib/es/upload/utils.js +1 -1
  123. package/lib/es/utils/isNullOrUndefined.d.ts +1 -1
  124. package/lib/es/utils/isNullOrUndefined.js +1 -1
  125. package/lib/es/utils/object.d.ts +6 -6
  126. package/lib/es/utils/object.js +2 -2
  127. package/navigation/foundation.ts +12 -12
  128. package/package.json +3 -3
  129. package/switch/constants.ts +1 -0
  130. package/switch/foundation.ts +16 -0
  131. package/switch/switch.scss +4 -0
  132. package/switch/variables.scss +2 -0
  133. package/tabs/foundation.ts +2 -2
  134. package/timePicker/ComboxFoundation.ts +1 -1
  135. package/timePicker/constants.ts +1 -1
  136. package/timePicker/foundation.ts +1 -1
  137. package/transfer/foundation.ts +1 -1
  138. package/transfer/{transferUtlls.ts → transferUtils.ts} +0 -0
  139. package/tree/foundation.ts +4 -4
  140. package/tree/treeUtil.ts +11 -11
  141. package/treeSelect/constants.ts +1 -1
  142. package/treeSelect/foundation.ts +4 -4
  143. package/upload/foundation.ts +8 -8
  144. package/upload/utils.ts +1 -1
  145. package/utils/isNullOrUndefined.ts +1 -1
  146. package/utils/object.ts +10 -10
@@ -0,0 +1,425 @@
1
+ @import "./variables.scss";
2
+
3
+ $module: #{$prefix}-carousel;
4
+
5
+ .#{$module} {
6
+ position: relative;
7
+ overflow: hidden;
8
+
9
+ &-content {
10
+ width: 100%;
11
+ height: 100%;
12
+ overflow: hidden;
13
+ position: relative;
14
+
15
+ &-item {
16
+ position: absolute;
17
+ left: 0;
18
+ top: 0;
19
+ width: 100%;
20
+ height: 100%;
21
+ overflow: hidden;
22
+
23
+ &-current {
24
+ z-index: 1;
25
+ }
26
+
27
+ }
28
+
29
+ &-fade {
30
+
31
+ > * {
32
+ opacity: 0;
33
+ }
34
+
35
+ .#{$module}-content-item-current {
36
+ opacity: 1;
37
+ }
38
+ }
39
+
40
+ &-slide {
41
+ &>*:not(.#{$module}-content-item-current) {
42
+ visibility: hidden;
43
+ }
44
+
45
+ .#{$module}-content-item-slide-out {
46
+ display: block;
47
+ animation: #{$module}-content-item-keyframe-slide-out;
48
+ }
49
+
50
+ .#{$module}-content-item-slide-in {
51
+ display: block;
52
+ animation: #{$module}-content-item-keyframe-slide-in;
53
+ }
54
+
55
+ }
56
+
57
+ &-reverse {
58
+ .#{$module}-content-item-slide-out {
59
+ animation: #{$module}-content-item-keyframe-slide-out-reverse ;
60
+ }
61
+
62
+ .#{$module}-content-item-slide-in {
63
+ animation: #{$module}-content-item-keyframe-slide-in-reverse ;
64
+ }
65
+ }
66
+ }
67
+
68
+ &-indicator {
69
+ display: flex;
70
+ align-items: flex-end;
71
+ z-index: 2;
72
+
73
+ &-left {
74
+ position: absolute;
75
+ left: $spacing-carousel_indicator-padding;
76
+ bottom: $spacing-carousel_indicator-padding;
77
+ }
78
+
79
+ &-center {
80
+ position: absolute;
81
+ left: 50%;
82
+ bottom: $spacing-carousel_indicator-padding;
83
+ transform: translate(-50%);
84
+ }
85
+
86
+ &-right {
87
+ position: absolute;
88
+ right: $spacing-carousel_indicator-padding;
89
+ bottom: $spacing-carousel_indicator-padding;
90
+ }
91
+
92
+
93
+ &-dot {
94
+ .#{$module}-indicator-item {
95
+ border-radius: $radius-carousel_indicator_dot;
96
+ cursor: pointer;
97
+
98
+ &:not(:last-child) {
99
+ margin-right: $spacing-carousel_indicator_dot-marginX;
100
+ }
101
+
102
+ &-small {
103
+ width: $width-carousel_indicator_dot_small;
104
+ height: $width-carousel_indicator_dot_small;
105
+
106
+ }
107
+
108
+ &-medium {
109
+ width: $width-carousel_indicator_dot_medium;
110
+ height: $width-carousel_indicator_dot_medium;
111
+ }
112
+
113
+ &-primary {
114
+ background-color: $color-carousel_indicator_theme_primary-bg-default;
115
+
116
+ &.#{$module}-indicator-item-active {
117
+ background: $color-carousel_indicator_theme_primary-bg-active;
118
+ }
119
+
120
+ &:hover {
121
+ background-color: $color-carousel_indicator_theme_primary-bg-hover;
122
+ }
123
+
124
+ &:active {
125
+ background: $color-carousel_indicator_theme_primary-bg-active;
126
+ }
127
+ }
128
+
129
+ &-light {
130
+
131
+ background-color: $color-carousel_indicator_theme_light-bg-default;
132
+
133
+ &.#{$module}-indicator-item-active {
134
+ background: $color-carousel_indicator_theme_light-bg-active;
135
+ }
136
+
137
+ &:hover {
138
+ background-color: $color-carousel_indicator_theme_light-bg-hover;
139
+ }
140
+
141
+ &:active {
142
+ background: $color-carousel_indicator_theme_light-bg-active;
143
+ }
144
+ }
145
+
146
+ &-dark {
147
+ background-color: $color-carousel_indicator_theme_dark-bg-default;
148
+
149
+ &.#{$module}-indicator-item-active {
150
+ background-color: $color-carousel_indicator_theme_dark-bg-active;
151
+ }
152
+
153
+ &:hover {
154
+ background-color: $color-carousel_indicator_theme_dark-bg-hover;
155
+ }
156
+
157
+ &:active {
158
+ background: $color-carousel_indicator_theme_dark-bg-active;
159
+ }
160
+ }
161
+ }
162
+
163
+ }
164
+
165
+ &-line {
166
+ width: $width-carousel_indicator_line;
167
+
168
+ .#{$module}-indicator-item {
169
+ flex: 1;
170
+ cursor: pointer;
171
+
172
+ &:not(:last-child) {
173
+ margin-right: $spacing-carousel_indicator_line-marginX;
174
+ }
175
+
176
+ &-small {
177
+ height: $height-carousel_indicator_line_small;
178
+
179
+ }
180
+
181
+ &-medium {
182
+ height: $height-carousel_indicator_line_medium;
183
+ }
184
+
185
+ &-primary {
186
+ background-color: $color-carousel_indicator_theme_primary-bg-default;
187
+
188
+ &.#{$module}-indicator-item-active {
189
+ background: $color-carousel_indicator_theme_primary-bg-active;
190
+ }
191
+
192
+ &:hover {
193
+ background-color: $color-carousel_indicator_theme_primary-bg-hover;
194
+ }
195
+
196
+ &:active {
197
+ background: $color-carousel_indicator_theme_primary-bg-active;
198
+ }
199
+ }
200
+
201
+ &-light {
202
+
203
+ background-color: $color-carousel_indicator_theme_light-bg-default;
204
+
205
+ &.#{$module}-indicator-item-active {
206
+ background: $color-carousel_indicator_theme_light-bg-active;
207
+ }
208
+
209
+ &:hover {
210
+ background-color: $color-carousel_indicator_theme_light-bg-hover;
211
+ }
212
+
213
+ &:active {
214
+ background: $color-carousel_indicator_theme_light-bg-active;
215
+ }
216
+ }
217
+
218
+ &-dark {
219
+
220
+ background-color: $color-carousel_indicator_theme_dark-bg-default;
221
+
222
+ &.#{$module}-indicator-item-active {
223
+ background: $color-carousel_indicator_theme_dark-bg-active;
224
+ }
225
+
226
+ &:hover {
227
+ background-color: $color-carousel_indicator_theme_dark-bg-hover;
228
+ }
229
+
230
+ &:active {
231
+ background: $color-carousel_indicator_theme_dark-bg-active;
232
+ }
233
+ }
234
+
235
+ }
236
+
237
+ }
238
+
239
+ &-columnar {
240
+ .#{$module}-indicator-item {
241
+ cursor: pointer;
242
+
243
+ &:not(:last-child) {
244
+ margin-right: $spacing-carousel_indicator_columnar-marginX;
245
+ }
246
+
247
+ &-small {
248
+ width: $width-carousel_indicator_columnar_small;
249
+ height: $height-carousel_indicator_columnar_small_default;
250
+
251
+ &.#{$module}-indicator-item-active {
252
+ height: $height-carousel_indicator_columnar_small_active;
253
+ }
254
+ }
255
+
256
+ &-medium {
257
+ width: $width-carousel_indicator_columnar_medium;
258
+ height: $height-carousel_indicator_columnar_medium_default;
259
+
260
+ &.#{$module}-indicator-item-active {
261
+ height: $height-carousel_indicator_columnar_medium_active;
262
+ }
263
+ }
264
+
265
+
266
+ &-primary {
267
+ background-color: $color-carousel_indicator_theme_primary-bg-default;
268
+
269
+
270
+ &.#{$module}-indicator-item-active {
271
+ background: $color-carousel_indicator_theme_primary-bg-active;
272
+ }
273
+
274
+ &:hover {
275
+ background-color: $color-carousel_indicator_theme_primary-bg-hover;
276
+ }
277
+
278
+ &:active {
279
+ background: $color-carousel_indicator_theme_primary-bg-active;
280
+ }
281
+ }
282
+
283
+ &-light {
284
+ background-color: $color-carousel_indicator_theme_light-bg-default;
285
+
286
+ &.#{$module}-indicator-item-active {
287
+ background: $color-carousel_indicator_theme_light-bg-active;
288
+ }
289
+
290
+ &:hover {
291
+ background-color: $color-carousel_indicator_theme_light-bg-hover;
292
+ }
293
+
294
+ &:active {
295
+ background: $color-carousel_indicator_theme_light-bg-active;
296
+ }
297
+ }
298
+
299
+ &-dark {
300
+ background-color: $color-carousel_indicator_theme_dark-bg-default;
301
+
302
+ &.#{$module}-indicator-item-active {
303
+ background: $color-carousel_indicator_theme_dark-bg-active;
304
+ }
305
+
306
+ &:hover {
307
+ background-color: $color-carousel_indicator_theme_dark-bg-hover;
308
+ }
309
+
310
+ &:active {
311
+ background: $color-carousel_indicator_theme_dark-bg-active;
312
+ }
313
+ }
314
+
315
+ }
316
+
317
+ }
318
+ }
319
+
320
+ &-arrow {
321
+ display: flex;
322
+ font-size: $width-carousel_arrow;
323
+ cursor: pointer;
324
+
325
+ &-prev {
326
+ position: absolute;
327
+ top: 50%;
328
+ left: $spacing-carousel_arrow-left;
329
+ transform: translateY(-50%);
330
+ z-index: 2;
331
+ }
332
+
333
+ &-next {
334
+ position: absolute;
335
+ top: 50%;
336
+ right: $spacing-carousel_arrow-right;
337
+ transform: translateY(-50%);
338
+ z-index: 2;
339
+ }
340
+
341
+ &-light {
342
+ color: $color-carousel_arrow_theme_light-bg-default;
343
+
344
+ &:hover {
345
+ color: $color-carousel_arrow_theme_light-bg-hover;
346
+ }
347
+ }
348
+
349
+
350
+ &-primary {
351
+ color: $color-carousel_arrow_theme_primary-bg-default;
352
+
353
+ &:hover {
354
+ color: $color-carousel_arrow_theme_primary-bg-hover;
355
+ }
356
+ }
357
+
358
+ &-dark {
359
+ color: $color-carousel_arrow_theme_dark-bg-default;
360
+
361
+ &:hover {
362
+ color: $color-carousel_arrow_theme_dark-bg-hover;
363
+ }
364
+ }
365
+
366
+ }
367
+
368
+ &-arrow-hover div {
369
+ z-index: 2;
370
+ opacity: 0;
371
+ transition: all .3s;
372
+ }
373
+
374
+ &:hover {
375
+ .#{$module}-arrow-hover div {
376
+ opacity: 1;
377
+ }
378
+ }
379
+ }
380
+
381
+ @keyframes #{$module}-content-item-keyframe-slide-in {
382
+
383
+ from {
384
+ transform: translateX(100%);
385
+ }
386
+
387
+ to {
388
+ transform: translateX(0);
389
+ }
390
+ }
391
+
392
+ @keyframes #{$module}-content-item-keyframe-slide-out {
393
+
394
+ from {
395
+ transform: translateX(0);
396
+ }
397
+
398
+ to {
399
+ transform: translateX(-100%);
400
+ }
401
+ }
402
+
403
+ @keyframes #{$module}-content-item-keyframe-slide-in-reverse {
404
+
405
+ from {
406
+ transform: translateX(-100%);
407
+ }
408
+
409
+ to {
410
+ transform: translateX(0);
411
+ }
412
+ }
413
+
414
+ @keyframes #{$module}-content-item-keyframe-slide-out-reverse {
415
+
416
+ from {
417
+ transform: translateX(0);
418
+ }
419
+
420
+ to {
421
+ transform: translateX(100%);
422
+ }
423
+ }
424
+
425
+ @import "./rtl.scss";
@@ -0,0 +1,32 @@
1
+ import { BASE_CLASS_PREFIX } from '../base/constants';
2
+
3
+ const cssClasses = {
4
+ CAROUSEL: `${BASE_CLASS_PREFIX}-carousel`,
5
+ CAROUSEL_INDICATOR: `${BASE_CLASS_PREFIX}-carousel-indicator`,
6
+ CAROUSEL_INDICATOR_LINE: `${BASE_CLASS_PREFIX}-carousel-indicator-line`,
7
+ CAROUSEL_INDICATOR_DOT: `${BASE_CLASS_PREFIX}-carousel-indicator-dot`,
8
+ CAROUSEL_INDICATOR_COLUMNAR: `${BASE_CLASS_PREFIX}-carousel-indicator-columnar`,
9
+ CAROUSEL_INDICATOR_INACTIVE: `${BASE_CLASS_PREFIX}-carousel-indicator-inactive`,
10
+ CAROUSEL_INDICATOR_ACTIVE: `${BASE_CLASS_PREFIX}-carousel-indicator-active`,
11
+ CAROUSEL_CONTENT: `${BASE_CLASS_PREFIX}-carousel-content`,
12
+ CAROUSEL_ARROW: `${BASE_CLASS_PREFIX}-carousel-arrow`,
13
+ };
14
+
15
+ const numbers = {
16
+ DEFAULT_ACTIVE_INDEX: 0,
17
+ DEFAULT_INTERVAL: 2000,
18
+ DEFAULT_SPEED: 300,
19
+ };
20
+
21
+ const strings = {
22
+ ANIMATION_MAP: ['slide', 'fade'],
23
+ DIRECTION: ['left', 'right'],
24
+ TYPE_MAP: ['columnar', 'line', 'dot'],
25
+ THEME_MAP: ['dark', 'primary', 'light'],
26
+ POSITION_MAP: ['left', 'center', 'right'],
27
+ ARROW_MAP: ['always', 'hover'],
28
+ SIZE: ['small', 'medium'],
29
+ TRIGGER: ['click', 'hover'],
30
+ } as const;
31
+
32
+ export { cssClasses, numbers, strings };
@@ -0,0 +1,164 @@
1
+ import { isObject, get } from 'lodash';
2
+ import BaseFoundation, { DefaultAdapter } from '../base/foundation';
3
+ import { numbers } from './constants';
4
+ import { throttle } from 'lodash';
5
+
6
+ export interface CarouselAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
7
+ notifyChange: (activeIndex: number, preIndex: number) => void;
8
+ setNewActiveIndex: (activeIndex: number) => void;
9
+ setPreActiveIndex: (activeIndex: number) => void;
10
+ setIsReverse: (isReverse: boolean) => void;
11
+ setIsInit: (isInit: boolean) => void;
12
+ }
13
+
14
+ class CarouselFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<CarouselAdapter<P, S>, P, S> {
15
+
16
+ constructor(adapter: CarouselAdapter<P, S>) {
17
+ super({ ...adapter });
18
+ }
19
+
20
+ _interval = null;
21
+
22
+ play(interval: number): void {
23
+ if (this._interval) {
24
+ clearInterval(this._interval);
25
+ }
26
+ this._interval = setInterval(() => {
27
+ this.next();
28
+ }, interval);
29
+ }
30
+
31
+ stop(): void {
32
+ if (this._interval){
33
+ clearInterval(this._interval);
34
+ }
35
+ }
36
+
37
+ goTo(activeIndex: number): void {
38
+ const { activeIndex: stateActiveIndex } = this.getStates();
39
+ const targetIndex = this.getValidIndex(activeIndex);
40
+ this._adapter.setIsReverse(stateActiveIndex > targetIndex);
41
+ if (this.getIsControledComponent()) {
42
+ this._notifyChange(targetIndex);
43
+ } else {
44
+ this._notifyChange(targetIndex);
45
+ this.handleNewActiveIndex(targetIndex);
46
+ }
47
+ }
48
+
49
+ next(): void {
50
+ const { activeIndex: stateActiveIndex } = this.getStates();
51
+ const targetIndex = this.getValidIndex(stateActiveIndex + 1);
52
+ this._adapter.setIsReverse(false);
53
+ if (this.getIsControledComponent()) {
54
+ this._notifyChange(targetIndex);
55
+ } else {
56
+ this._notifyChange(targetIndex);
57
+ this.handleNewActiveIndex(targetIndex);
58
+ }
59
+ }
60
+
61
+ prev(): void {
62
+ const { activeIndex: stateActiveIndex } = this.getStates();
63
+ const targetIndex = this.getValidIndex(stateActiveIndex - 1);
64
+ this._adapter.setIsReverse(true);
65
+ if (this.getIsControledComponent()) {
66
+ this._notifyChange(targetIndex);
67
+ } else {
68
+ this._notifyChange(targetIndex);
69
+ this.handleNewActiveIndex(targetIndex);
70
+ }
71
+ }
72
+
73
+ destroy(): void {
74
+ this._unregisterInterval();
75
+ }
76
+
77
+ _unregisterInterval() {
78
+ if (this._interval) {
79
+ clearInterval(this._interval);
80
+ this._interval = null;
81
+ }
82
+ }
83
+
84
+
85
+ _notifyChange(activeIndex: number): void {
86
+ const { activeIndex: stateActiveIndex, isInit } = this.getStates();
87
+ if (isInit){
88
+ this._adapter.setIsInit(false);
89
+ }
90
+ if (stateActiveIndex !== activeIndex) {
91
+ this._adapter.setPreActiveIndex(stateActiveIndex);
92
+ this._adapter.notifyChange(activeIndex, stateActiveIndex);
93
+ }
94
+ }
95
+
96
+ getValidIndex(index: number): number {
97
+ const { children } = this.getStates();
98
+ return (index + children.length) % children.length;
99
+ }
100
+
101
+ getSwitchingTime(): number {
102
+ const { autoPlay, speed } = this.getProps();
103
+ const autoPlayType = typeof autoPlay;
104
+ if (autoPlayType === 'boolean' && autoPlay){
105
+ return numbers.DEFAULT_INTERVAL + speed;
106
+ }
107
+ if (isObject(autoPlay)){
108
+ return get(autoPlay, 'interval', numbers.DEFAULT_INTERVAL) + speed;
109
+ }
110
+ return speed;
111
+ }
112
+
113
+ getIsControledComponent(): boolean {
114
+ return this._isInProps('activeIndex');
115
+ }
116
+
117
+ handleAutoPlay(): void {
118
+ const { autoPlay } = this.getProps();
119
+ const autoPlayType = typeof autoPlay;
120
+ if ((autoPlayType === 'boolean' && autoPlay) || isObject(autoPlay)){
121
+ this.play(this.getSwitchingTime());
122
+ }
123
+ }
124
+
125
+ handleKeyDown(event: any): void{
126
+ if (event.key === 'ArrowLeft') {
127
+ this.prev();
128
+ }
129
+ if (event.key === 'ArrowRight') {
130
+ this.next();
131
+ }
132
+ }
133
+
134
+ onIndicatorChange(activeIndex: number): void {
135
+ const { activeIndex: stateActiveIndex } = this.getStates();
136
+ this._adapter.setIsReverse(stateActiveIndex > activeIndex);
137
+ this._notifyChange(activeIndex);
138
+ if (!this.getIsControledComponent()) {
139
+ this.handleNewActiveIndex(activeIndex);
140
+ }
141
+ }
142
+
143
+
144
+ handleNewActiveIndex(activeIndex: number): void {
145
+ const { activeIndex: stateActiveIndex } = this.getStates();
146
+ if (stateActiveIndex !== activeIndex) {
147
+ this._adapter.setNewActiveIndex(activeIndex);
148
+ }
149
+ }
150
+
151
+ getDefaultActiveIndex(): number {
152
+ let activeIndex;
153
+ const props = this.getProps();
154
+ if ('activeIndex' in props) {
155
+ activeIndex = props.activeIndex;
156
+ } else if ('defaultActiveIndex' in props) {
157
+ activeIndex = props.defaultActiveIndex;
158
+ }
159
+ return activeIndex;
160
+ }
161
+
162
+ }
163
+
164
+ export default CarouselFoundation;
@@ -0,0 +1,47 @@
1
+ $module: #{$prefix}-carousel;
2
+ .#{$prefix}-rtl,
3
+ .#{$prefix}-portal-rtl {
4
+ .#{$module} {
5
+ direction: rtl;
6
+
7
+ &-indicator {
8
+ display: flex;
9
+
10
+ &-dot {
11
+ .#{$module}-indicator-item {
12
+ &:not(:last-child) {
13
+ margin-right: 0;
14
+ margin-left: $spacing-carousel_indicator_dot-marginX;
15
+ }
16
+ }
17
+ }
18
+
19
+ &-columnar {
20
+ .#{$module}-indicator-item {
21
+ &:not(:last-child) {
22
+ margin-right: 0;
23
+ margin-left: $spacing-carousel_indicator_columnar-marginX;
24
+ }
25
+ }
26
+ }
27
+ }
28
+
29
+ &-arrow {
30
+ flex-direction: row-reverse;
31
+
32
+ &-prev {
33
+ left: auto;
34
+ right: $spacing-carousel_arrow-right;
35
+ transform: scaleX(-1) translateY(-50%);
36
+ z-index: 2;
37
+ }
38
+
39
+ &-next {
40
+ left: $spacing-carousel_arrow-left;
41
+ transform: scaleX(-1) translateY(-50%);
42
+ right: auto;
43
+ z-index: 2;
44
+ }
45
+ }
46
+ }
47
+ }