@douyinfe/semi-foundation 2.9.1 → 2.10.0-beta.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 (40) hide show
  1. package/carousel/carousel.scss +425 -0
  2. package/carousel/constants.ts +32 -0
  3. package/carousel/foundation.ts +166 -0
  4. package/carousel/rtl.scss +47 -0
  5. package/carousel/variables.scss +46 -0
  6. package/lib/cjs/carousel/carousel.css +341 -0
  7. package/lib/cjs/carousel/carousel.scss +425 -0
  8. package/lib/cjs/carousel/constants.d.ts +27 -0
  9. package/lib/cjs/carousel/constants.js +41 -0
  10. package/lib/cjs/carousel/foundation.d.ts +30 -0
  11. package/lib/cjs/carousel/foundation.js +219 -0
  12. package/lib/cjs/carousel/rtl.scss +47 -0
  13. package/lib/cjs/carousel/variables.scss +46 -0
  14. package/lib/cjs/switch/constants.d.ts +1 -0
  15. package/lib/cjs/switch/constants.js +1 -0
  16. package/lib/cjs/switch/foundation.d.ts +3 -0
  17. package/lib/cjs/switch/foundation.js +18 -0
  18. package/lib/cjs/switch/switch.css +3 -0
  19. package/lib/cjs/switch/switch.scss +4 -0
  20. package/lib/cjs/switch/variables.scss +2 -0
  21. package/lib/es/carousel/carousel.css +341 -0
  22. package/lib/es/carousel/carousel.scss +425 -0
  23. package/lib/es/carousel/constants.d.ts +27 -0
  24. package/lib/es/carousel/constants.js +28 -0
  25. package/lib/es/carousel/foundation.d.ts +30 -0
  26. package/lib/es/carousel/foundation.js +200 -0
  27. package/lib/es/carousel/rtl.scss +47 -0
  28. package/lib/es/carousel/variables.scss +46 -0
  29. package/lib/es/switch/constants.d.ts +1 -0
  30. package/lib/es/switch/constants.js +1 -0
  31. package/lib/es/switch/foundation.d.ts +3 -0
  32. package/lib/es/switch/foundation.js +18 -0
  33. package/lib/es/switch/switch.css +3 -0
  34. package/lib/es/switch/switch.scss +4 -0
  35. package/lib/es/switch/variables.scss +2 -0
  36. package/package.json +3 -3
  37. package/switch/constants.ts +1 -0
  38. package/switch/foundation.ts +16 -0
  39. package/switch/switch.scss +4 -0
  40. package/switch/variables.scss +2 -0
@@ -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,166 @@
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
+ throttleChange: any;
16
+
17
+ constructor(adapter: CarouselAdapter<P, S>) {
18
+ super({ ...adapter });
19
+ this.throttleChange = throttle(this.onIndicatorChange, this.getSwitchingTime());
20
+ }
21
+
22
+ _interval = null;
23
+
24
+ play(interval: number): void {
25
+ if (this._interval) {
26
+ clearInterval(this._interval);
27
+ }
28
+ this._interval = setInterval(() => {
29
+ this.next();
30
+ }, interval);
31
+ }
32
+
33
+ stop(): void {
34
+ if (this._interval){
35
+ clearInterval(this._interval);
36
+ }
37
+ }
38
+
39
+ goTo(activeIndex: number): void {
40
+ const { activeIndex: stateActiveIndex } = this.getStates();
41
+ const targetIndex = this.getValidIndex(activeIndex);
42
+ this._adapter.setIsReverse(stateActiveIndex > targetIndex);
43
+ if (this.getIsControledComponent()) {
44
+ this._notifyChange(targetIndex);
45
+ } else {
46
+ this._notifyChange(targetIndex);
47
+ this.handleNewActiveIndex(targetIndex);
48
+ }
49
+ }
50
+
51
+ next(): void {
52
+ const { activeIndex: stateActiveIndex } = this.getStates();
53
+ const targetIndex = this.getValidIndex(stateActiveIndex + 1);
54
+ this._adapter.setIsReverse(false);
55
+ if (this.getIsControledComponent()) {
56
+ this._notifyChange(targetIndex);
57
+ } else {
58
+ this._notifyChange(targetIndex);
59
+ this.handleNewActiveIndex(targetIndex);
60
+ }
61
+ }
62
+
63
+ prev(): void {
64
+ const { activeIndex: stateActiveIndex } = this.getStates();
65
+ const targetIndex = this.getValidIndex(stateActiveIndex - 1);
66
+ this._adapter.setIsReverse(true);
67
+ if (this.getIsControledComponent()) {
68
+ this._notifyChange(targetIndex);
69
+ } else {
70
+ this._notifyChange(targetIndex);
71
+ this.handleNewActiveIndex(targetIndex);
72
+ }
73
+ }
74
+
75
+ destroy(): void {
76
+ this._unregisterInterval();
77
+ }
78
+
79
+ _unregisterInterval() {
80
+ if (this._interval) {
81
+ clearInterval(this._interval);
82
+ this._interval = null;
83
+ }
84
+ }
85
+
86
+
87
+ _notifyChange(activeIndex: number): void {
88
+ const { activeIndex: stateActiveIndex, isInit } = this.getStates();
89
+ if (isInit){
90
+ this._adapter.setIsInit(false);
91
+ }
92
+ if (stateActiveIndex !== activeIndex) {
93
+ this._adapter.setPreActiveIndex(stateActiveIndex);
94
+ this._adapter.notifyChange(activeIndex, stateActiveIndex);
95
+ }
96
+ }
97
+
98
+ getValidIndex(index: number): number {
99
+ const { children } = this.getStates();
100
+ return (index + children.length) % children.length;
101
+ }
102
+
103
+ getSwitchingTime(): number {
104
+ const { autoPlay, speed } = this.getProps();
105
+ const autoPlayType = typeof autoPlay;
106
+ if (autoPlayType === 'boolean' && autoPlay){
107
+ return numbers.DEFAULT_INTERVAL + speed;
108
+ }
109
+ if (isObject(autoPlay)){
110
+ return get(autoPlay, 'interval', numbers.DEFAULT_INTERVAL) + speed;
111
+ }
112
+ return speed;
113
+ }
114
+
115
+ getIsControledComponent(): boolean {
116
+ return this._isInProps('activeIndex');
117
+ }
118
+
119
+ handleAutoPlay(): void {
120
+ const { autoPlay } = this.getProps();
121
+ const autoPlayType = typeof autoPlay;
122
+ if ((autoPlayType === 'boolean' && autoPlay) || isObject(autoPlay)){
123
+ this.play(this.getSwitchingTime());
124
+ }
125
+ }
126
+
127
+ handleKeyDown(event: any): void{
128
+ if (event.key === 'ArrowLeft') {
129
+ this.prev();
130
+ }
131
+ if (event.key === 'ArrowRight') {
132
+ this.next();
133
+ }
134
+ }
135
+
136
+ onIndicatorChange(activeIndex: number): void {
137
+ const { activeIndex: stateActiveIndex } = this.getStates();
138
+ this._adapter.setIsReverse(stateActiveIndex > activeIndex);
139
+ this._notifyChange(activeIndex);
140
+ if (!this.getIsControledComponent()) {
141
+ this.handleNewActiveIndex(activeIndex);
142
+ }
143
+ }
144
+
145
+
146
+ handleNewActiveIndex(activeIndex: number): void {
147
+ const { activeIndex: stateActiveIndex } = this.getStates();
148
+ if (stateActiveIndex !== activeIndex) {
149
+ this._adapter.setNewActiveIndex(activeIndex);
150
+ }
151
+ }
152
+
153
+ getDefaultActiveIndex(): number {
154
+ let activeIndex;
155
+ const props = this.getProps();
156
+ if ('activeIndex' in props) {
157
+ activeIndex = props.activeIndex;
158
+ } else if ('defaultActiveIndex' in props) {
159
+ activeIndex = props.defaultActiveIndex;
160
+ }
161
+ return activeIndex;
162
+ }
163
+
164
+ }
165
+
166
+ 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
+ }