@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,219 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+
5
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
+
7
+ _Object$defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+
11
+ exports.default = void 0;
12
+
13
+ var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
14
+
15
+ var _setInterval2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-interval"));
16
+
17
+ var _throttle2 = _interopRequireDefault(require("lodash/throttle"));
18
+
19
+ var _get2 = _interopRequireDefault(require("lodash/get"));
20
+
21
+ var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
22
+
23
+ var _foundation = _interopRequireDefault(require("../base/foundation"));
24
+
25
+ var _constants = require("./constants");
26
+
27
+ class CarouselFoundation extends _foundation.default {
28
+ constructor(adapter) {
29
+ super((0, _assign.default)({}, adapter));
30
+ this._interval = null;
31
+ this.throttleChange = (0, _throttle2.default)(this.onIndicatorChange, this.getSwitchingTime());
32
+ }
33
+
34
+ play(interval) {
35
+ if (this._interval) {
36
+ clearInterval(this._interval);
37
+ }
38
+
39
+ this._interval = (0, _setInterval2.default)(() => {
40
+ this.next();
41
+ }, interval);
42
+ }
43
+
44
+ stop() {
45
+ if (this._interval) {
46
+ clearInterval(this._interval);
47
+ }
48
+ }
49
+
50
+ goTo(activeIndex) {
51
+ const {
52
+ activeIndex: stateActiveIndex
53
+ } = this.getStates();
54
+ const targetIndex = this.getValidIndex(activeIndex);
55
+
56
+ this._adapter.setIsReverse(stateActiveIndex > targetIndex);
57
+
58
+ if (this.getIsControledComponent()) {
59
+ this._notifyChange(targetIndex);
60
+ } else {
61
+ this._notifyChange(targetIndex);
62
+
63
+ this.handleNewActiveIndex(targetIndex);
64
+ }
65
+ }
66
+
67
+ next() {
68
+ const {
69
+ activeIndex: stateActiveIndex
70
+ } = this.getStates();
71
+ const targetIndex = this.getValidIndex(stateActiveIndex + 1);
72
+
73
+ this._adapter.setIsReverse(false);
74
+
75
+ if (this.getIsControledComponent()) {
76
+ this._notifyChange(targetIndex);
77
+ } else {
78
+ this._notifyChange(targetIndex);
79
+
80
+ this.handleNewActiveIndex(targetIndex);
81
+ }
82
+ }
83
+
84
+ prev() {
85
+ const {
86
+ activeIndex: stateActiveIndex
87
+ } = this.getStates();
88
+ const targetIndex = this.getValidIndex(stateActiveIndex - 1);
89
+
90
+ this._adapter.setIsReverse(true);
91
+
92
+ if (this.getIsControledComponent()) {
93
+ this._notifyChange(targetIndex);
94
+ } else {
95
+ this._notifyChange(targetIndex);
96
+
97
+ this.handleNewActiveIndex(targetIndex);
98
+ }
99
+ }
100
+
101
+ destroy() {
102
+ this._unregisterInterval();
103
+ }
104
+
105
+ _unregisterInterval() {
106
+ if (this._interval) {
107
+ clearInterval(this._interval);
108
+ this._interval = null;
109
+ }
110
+ }
111
+
112
+ _notifyChange(activeIndex) {
113
+ const {
114
+ activeIndex: stateActiveIndex,
115
+ isInit
116
+ } = this.getStates();
117
+
118
+ if (isInit) {
119
+ this._adapter.setIsInit(false);
120
+ }
121
+
122
+ if (stateActiveIndex !== activeIndex) {
123
+ this._adapter.setPreActiveIndex(stateActiveIndex);
124
+
125
+ this._adapter.notifyChange(activeIndex, stateActiveIndex);
126
+ }
127
+ }
128
+
129
+ getValidIndex(index) {
130
+ const {
131
+ children
132
+ } = this.getStates();
133
+ return (index + children.length) % children.length;
134
+ }
135
+
136
+ getSwitchingTime() {
137
+ const {
138
+ autoPlay,
139
+ speed
140
+ } = this.getProps();
141
+ const autoPlayType = typeof autoPlay;
142
+
143
+ if (autoPlayType === 'boolean' && autoPlay) {
144
+ return _constants.numbers.DEFAULT_INTERVAL + speed;
145
+ }
146
+
147
+ if ((0, _isObject2.default)(autoPlay)) {
148
+ return (0, _get2.default)(autoPlay, 'interval', _constants.numbers.DEFAULT_INTERVAL) + speed;
149
+ }
150
+
151
+ return speed;
152
+ }
153
+
154
+ getIsControledComponent() {
155
+ return this._isInProps('activeIndex');
156
+ }
157
+
158
+ handleAutoPlay() {
159
+ const {
160
+ autoPlay
161
+ } = this.getProps();
162
+ const autoPlayType = typeof autoPlay;
163
+
164
+ if (autoPlayType === 'boolean' && autoPlay || (0, _isObject2.default)(autoPlay)) {
165
+ this.play(this.getSwitchingTime());
166
+ }
167
+ }
168
+
169
+ handleKeyDown(event) {
170
+ if (event.key === 'ArrowLeft') {
171
+ this.prev();
172
+ }
173
+
174
+ if (event.key === 'ArrowRight') {
175
+ this.next();
176
+ }
177
+ }
178
+
179
+ onIndicatorChange(activeIndex) {
180
+ const {
181
+ activeIndex: stateActiveIndex
182
+ } = this.getStates();
183
+
184
+ this._adapter.setIsReverse(stateActiveIndex > activeIndex);
185
+
186
+ this._notifyChange(activeIndex);
187
+
188
+ if (!this.getIsControledComponent()) {
189
+ this.handleNewActiveIndex(activeIndex);
190
+ }
191
+ }
192
+
193
+ handleNewActiveIndex(activeIndex) {
194
+ const {
195
+ activeIndex: stateActiveIndex
196
+ } = this.getStates();
197
+
198
+ if (stateActiveIndex !== activeIndex) {
199
+ this._adapter.setNewActiveIndex(activeIndex);
200
+ }
201
+ }
202
+
203
+ getDefaultActiveIndex() {
204
+ let activeIndex;
205
+ const props = this.getProps();
206
+
207
+ if ('activeIndex' in props) {
208
+ activeIndex = props.activeIndex;
209
+ } else if ('defaultActiveIndex' in props) {
210
+ activeIndex = props.defaultActiveIndex;
211
+ }
212
+
213
+ return activeIndex;
214
+ }
215
+
216
+ }
217
+
218
+ var _default = CarouselFoundation;
219
+ exports.default = _default;
@@ -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
+ }
@@ -0,0 +1,46 @@
1
+ $color-carousel_indicator_theme_dark-bg-default: rgba(var(--semi-black), .5); // 深色主题指示器背景颜色 - 默认
2
+ $color-carousel_indicator_theme_dark-bg-hover: rgba(var(--semi-black), .7); // 深色主题指示器背景颜色 - 悬浮
3
+ $color-carousel_indicator_theme_dark-bg-active: rgba(var(--semi-black), 1); // 深色主题指示器背景颜色 - 选中
4
+
5
+ $color-carousel_indicator_theme_primary-bg-default: rgba(var(--semi-blue-6), .4); // 主要主题指示器背景颜色 - 默认
6
+ $color-carousel_indicator_theme_primary-bg-hover: rgba(var(--semi-blue-6), .7); // 主要主题指示器背景颜色 - 悬浮
7
+ $color-carousel_indicator_theme_primary-bg-active: rgba(var(--semi-blue-6), 1); // 主要主题指示器背景颜色 - 选中
8
+
9
+ $color-carousel_indicator_theme_light-bg-default: rgba(var(--semi-white), .4); // 浅色主题指示器背景颜色 - 默认
10
+ $color-carousel_indicator_theme_light-bg-hover: rgba(var(--semi-white), .7); // 浅色主题指示器背景颜色 - 悬浮
11
+ $color-carousel_indicator_theme_light-bg-active: rgba(var(--semi-white), 1); // 浅色主题指示器背景颜色 - 选中
12
+
13
+ $color-carousel_arrow_theme_dark-bg-default: rgba(var(--semi-black), .5); // 深色主题箭头背景颜色 - 默认
14
+ $color-carousel_arrow_theme_dark-bg-hover: rgba(var(--semi-black), 1); // 深色主题箭头背景颜色 - 悬浮
15
+
16
+ $color-carousel_arrow_theme_primary-bg-default: rgba(var(--semi-blue-6), .4); // 主要主题箭头背景颜色 - 默认
17
+ $color-carousel_arrow_theme_primary-bg-hover: rgba(var(--semi-blue-6), 1); // 主要主题箭头背景颜色 - 悬浮
18
+
19
+ $color-carousel_arrow_theme_light-bg-default: rgba(var(--semi-white), .4); // 浅色主题箭头背景颜色 - 默认
20
+ $color-carousel_arrow_theme_light-bg-hover: rgba(var(--semi-white), 1); // 浅色主题箭头背景颜色 - 悬浮
21
+
22
+ $width-carousel_indicator_line: 240px; // 条状指示器最大宽度
23
+ $width-carousel_indicator_columnar_small: 4px; // 小尺寸柱状指示器宽度
24
+ $width-carousel_indicator_columnar_medium: 6px; // 中等尺寸柱状指示器宽度
25
+ $width-carousel_indicator_dot_small:8px; // 小尺寸点状指示器宽度
26
+ $width-carousel_indicator_dot_medium: 12px; // 中等尺寸点状指示器宽度
27
+ $width-carousel_arrow: 32px; // 箭头宽度
28
+
29
+ $height-carousel_indicator_columnar_small_default: 12px; // 小尺寸柱状指示器高度 - 默认
30
+ $height-carousel_indicator_columnar_small_active: 20px; // 小尺寸柱状指示器高度 - 选中
31
+ $height-carousel_indicator_columnar_medium_default: 20px; // 中等尺寸柱状指示器高度 - 默认
32
+ $height-carousel_indicator_columnar_medium_active: 28px; // 中等尺寸柱状指示器高度 - 选中
33
+
34
+ $height-carousel_indicator_line_small: 4px; // 小尺寸条状指示器高度
35
+ $height-carousel_indicator_line_medium: 6px; // 中等尺寸条状指示器高度
36
+
37
+ $radius-carousel_indicator_dot: 50%; // 点状指示器圆角
38
+
39
+ $spacing-carousel_indicator-padding: 32px; // 指示器内边距
40
+
41
+ $spacing-carousel_indicator_columnar-marginX: 4px; // 柱状指示器水平外边距
42
+ $spacing-carousel_indicator_line-marginX: 4px; // 条状指示器水平外边距
43
+ $spacing-carousel_indicator_dot-marginX: 8px; // 点状指示器水平外边距
44
+
45
+ $spacing-carousel_arrow-left: 20px; // 左侧箭头绝对定位 - left
46
+ $spacing-carousel_arrow-right: 20px; // 右侧箭头绝对定位 - right
@@ -1,5 +1,6 @@
1
1
  declare const cssClasses: {
2
2
  PREFIX: string;
3
+ FOCUS: string;
3
4
  LARGE: string;
4
5
  SMALL: string;
5
6
  CHECKED: string;
@@ -12,6 +12,7 @@ var _constants = require("../base/constants");
12
12
 
13
13
  const cssClasses = {
14
14
  PREFIX: "".concat(_constants.BASE_CLASS_PREFIX, "-switch"),
15
+ FOCUS: "".concat(_constants.BASE_CLASS_PREFIX, "-switch-focus"),
15
16
  LARGE: "".concat(_constants.BASE_CLASS_PREFIX, "-switch-large"),
16
17
  SMALL: "".concat(_constants.BASE_CLASS_PREFIX, "-switch-small"),
17
18
  CHECKED: "".concat(_constants.BASE_CLASS_PREFIX, "-switch-checked"),
@@ -2,6 +2,7 @@ import BaseFoundation, { DefaultAdapter } from '../base/foundation';
2
2
  export interface SwitchAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
3
3
  setNativeControlChecked: (nativeControlChecked: boolean | undefined) => void;
4
4
  setNativeControlDisabled: (nativeControlDisabled: boolean | undefined) => void;
5
+ setFocusVisible: (focusVisible: boolean) => void;
5
6
  notifyChange: (checked: boolean, e: any) => void;
6
7
  }
7
8
  export default class SwitchFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<SwitchAdapter<P, S>, P, S> {
@@ -10,5 +11,7 @@ export default class SwitchFoundation<P = Record<string, any>, S = Record<string
10
11
  setChecked(checked: boolean | undefined): void;
11
12
  setDisabled(disabled: boolean | undefined): void;
12
13
  handleChange(checked: boolean, e: any): void;
14
+ handleFocusVisible: (event: any) => void;
15
+ handleBlur: () => void;
13
16
  destroy(): void;
14
17
  }
@@ -17,6 +17,24 @@ var _foundation = _interopRequireDefault(require("../base/foundation"));
17
17
  class SwitchFoundation extends _foundation.default {
18
18
  constructor(adapter) {
19
19
  super((0, _assign.default)({}, adapter));
20
+
21
+ this.handleFocusVisible = event => {
22
+ const {
23
+ target
24
+ } = event;
25
+
26
+ try {
27
+ if (target.matches(':focus-visible')) {
28
+ this._adapter.setFocusVisible(true);
29
+ }
30
+ } catch (error) {
31
+ console.warn('The current browser does not support the focus-visible');
32
+ }
33
+ };
34
+
35
+ this.handleBlur = () => {
36
+ this._adapter.setFocusVisible(false);
37
+ };
20
38
  }
21
39
 
22
40
  init() {
@@ -22,6 +22,9 @@
22
22
  .semi-switch:active .semi-switch-knob {
23
23
  width: 24px;
24
24
  }
25
+ .semi-switch-focus {
26
+ outline: 2px solid var(--semi-color-primary-light-active);
27
+ }
25
28
  .semi-switch-checked {
26
29
  background-color: var(--semi-color-success);
27
30
  }
@@ -28,6 +28,10 @@ $module: #{$prefix}-switch;
28
28
  }
29
29
  }
30
30
 
31
+ &-focus {
32
+ outline: $width-switch-outline solid $color-switch_primary-outline-focus;
33
+ }
34
+
31
35
  &-checked {
32
36
  background-color: $color-switch_checked-bg-default;
33
37
 
@@ -37,6 +37,7 @@ $color-switch_unchecked-text-default: var(--semi-color-text-2); // 关闭态开
37
37
  $color-switch_loading_spin-default: var(--semi-color-white); // 加载态开关loading图标颜色
38
38
  $color-switch_spin_checked-bg-default: var(--semi-color-success-hover); // 已开启开关加载态loading背景颜色
39
39
  $color-switch_spin_unchecked-bg-default: var(--semi-color-fill-1); // 已关闭开关加载态loading背景颜色
40
+ $color-switch_primary-outline-focus: var(--semi-color-primary-light-active); // 开关轮廓 - 聚焦
40
41
 
41
42
  // Width/Height
42
43
  $width-switch: 40px; // 开关宽度
@@ -57,6 +58,7 @@ $width-switch_checked_unchecked_text: 26px; // 开关按钮文字宽度
57
58
  $width-switch_spin-small: 10px; // 小尺寸开关加载 spin 宽度
58
59
  $width-switch_spin-default: 18px; // 默认尺寸开关加载 spin 宽度
59
60
  $width-switch_spin-large: 28px; // 大尺寸开关加载 spin 宽度
61
+ $width-switch-outline: 2px; // 开关轮廓宽度
60
62
 
61
63
 
62
64
  // Spacing