@befe/brick-comp-tabs 0.2.92
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.
- package/CHANGELOG.md +1155 -0
- package/README.md +3 -0
- package/es/index.css +3391 -0
- package/es/index.js +2 -0
- package/es/style.css +314 -0
- package/es/tab-pane.js +67 -0
- package/es/tabs-context.js +2 -0
- package/es/tabs.js +634 -0
- package/package.json +40 -0
- package/src/index.scss +6 -0
- package/src/index.tsx +2 -0
- package/src/style.scss +360 -0
- package/src/tab-pane.tsx +82 -0
- package/src/tabs-context.tsx +9 -0
- package/src/tabs.tsx +716 -0
- package/types/index.d.ts +2 -0
- package/types/tab-pane.d.ts +42 -0
- package/types/tabs-context.d.ts +6 -0
- package/types/tabs.d.ts +139 -0
package/src/style.scss
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
@use "sass:map";
|
|
2
|
+
@use "sass:math";
|
|
3
|
+
@use "@befe/brick-style/src/themes/base";
|
|
4
|
+
@use "@befe/brick-style/src/themes/tabs";
|
|
5
|
+
@use "@befe/brick-style/src/themes/menu";
|
|
6
|
+
|
|
7
|
+
$tabs-wrap-gap: base.padding(1);
|
|
8
|
+
|
|
9
|
+
.brick-tabs {
|
|
10
|
+
@include base.reset();
|
|
11
|
+
& {
|
|
12
|
+
position: relative;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
&-container {
|
|
16
|
+
display: flex;
|
|
17
|
+
position: relative;
|
|
18
|
+
width: 100%;
|
|
19
|
+
margin-bottom: tabs.$tabs-container-margin-bottom;
|
|
20
|
+
color: tabs.$tabs-tab-color;
|
|
21
|
+
|
|
22
|
+
&::after {
|
|
23
|
+
content: "";
|
|
24
|
+
position: absolute;
|
|
25
|
+
width: 100%;
|
|
26
|
+
pointer-events: none;
|
|
27
|
+
bottom: 0;
|
|
28
|
+
border-bottom: base.border($color: tabs.$tabs-border-color);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&-wrap {
|
|
33
|
+
position: relative;
|
|
34
|
+
overflow: hidden;
|
|
35
|
+
|
|
36
|
+
// 使 focus-ring shadow 露出来
|
|
37
|
+
padding: $tabs-wrap-gap;
|
|
38
|
+
margin: -($tabs-wrap-gap);
|
|
39
|
+
|
|
40
|
+
ul {
|
|
41
|
+
display: inline-block;
|
|
42
|
+
padding: 0;
|
|
43
|
+
margin: 0;
|
|
44
|
+
white-space: nowrap;
|
|
45
|
+
transition: transform 300ms cubic-bezier(0.19, 1, 0.22, 1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&-tab {
|
|
50
|
+
display: inline-block;
|
|
51
|
+
position: relative;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
padding: tabs.$tabs-tab-padding-vertical map.get(tabs.$tabs-tab-padding-horizontal, base.$base-size);
|
|
54
|
+
list-style: none;
|
|
55
|
+
outline: none;
|
|
56
|
+
text-align: center;
|
|
57
|
+
vertical-align: top;
|
|
58
|
+
border: base.border($color: transparent);
|
|
59
|
+
&-invisible {
|
|
60
|
+
visibility: hidden;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&:focus-visible {
|
|
64
|
+
@include base.focus-ring()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&-tab-active:not(.brick-tabs-tab-status-error) {
|
|
69
|
+
color: tabs.$tabs-tab-active-color;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
&-tab-disabled {
|
|
73
|
+
cursor: not-allowed;
|
|
74
|
+
color: tabs.$tabs-tab-color-disabled;
|
|
75
|
+
&:hover,
|
|
76
|
+
&:active {
|
|
77
|
+
color: tabs.$tabs-tab-color-disabled;
|
|
78
|
+
}
|
|
79
|
+
&.brick-tabs-tab-active {
|
|
80
|
+
&, &:hover, &:active {
|
|
81
|
+
cursor: not-allowed;
|
|
82
|
+
color: tabs.$tabs-tab-active-color-disabled;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&-ellipsis {
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
padding: tabs.$tabs-tab-ellipsis-button-padding-vertical tabs.$tabs-tab-ellipsis-button-padding-horizontal;
|
|
91
|
+
.brick-icon {
|
|
92
|
+
font-size: tabs.$tabs-tab-ellipsis-button-size;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
&-add {
|
|
97
|
+
display: inline-block;
|
|
98
|
+
// button 有边框,减掉
|
|
99
|
+
padding-top: map.get(tabs.$tabs-tab-add-button-padding-vertical, base.$base-size);
|
|
100
|
+
padding-left: tabs.$tabs-tab-add-button-padding-horizontal;
|
|
101
|
+
padding-right: tabs.$tabs-tab-add-button-padding-horizontal;
|
|
102
|
+
line-height: 1;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 考虑嵌套情况,只对直属 tabs 进行修饰
|
|
107
|
+
.brick-tabs-type-plain > .brick-tabs-container {
|
|
108
|
+
.brick-tabs-tab:not(.brick-tabs-tab-disabled) {
|
|
109
|
+
&:hover {
|
|
110
|
+
color: tabs.$tabs-tab-color-hover;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
&:active {
|
|
114
|
+
color: tabs.$tabs-tab-color-active;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
// @note safari < 15.4 不支持 :focus-visible,会导致通分组样式一同失效,估须将其单独修饰,以保证其他样式正常
|
|
119
|
+
// 特别注意不能和上面 &:hover 放一起, 否则 post-css 会判定为连续两个一致的修饰,将其"优化"合并成一个分组
|
|
120
|
+
.brick-tabs-tab:not(.brick-tabs-tab-disabled):not(:active):focus-visible {
|
|
121
|
+
color: tabs.$tabs-tab-color-hover;
|
|
122
|
+
}
|
|
123
|
+
.brick-tabs-tab-active {
|
|
124
|
+
border-bottom: tabs.$tabs-tab-active-border-width solid base.$color-primary;
|
|
125
|
+
padding-bottom: tabs.$tabs-tab-padding-vertical - (tabs.$tabs-tab-active-border-width - base.$border-width-base);
|
|
126
|
+
&:focus-visible {
|
|
127
|
+
border-bottom-width: tabs.$tabs-tab-active-border-width;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 考虑嵌套情况,只对直属 tabs 进行修饰
|
|
133
|
+
.brick-tabs-type-card > .brick-tabs-container {
|
|
134
|
+
.brick-tabs-tab,
|
|
135
|
+
.brick-tabs-ellipsis {
|
|
136
|
+
border: base.border($color: tabs.$tabs-border-color);
|
|
137
|
+
background-color: tabs.$tabs-tab-card-bg-color;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.brick-tabs-tab {
|
|
141
|
+
padding-top: tabs.$tabs-tab-padding-vertical;
|
|
142
|
+
|
|
143
|
+
& + .brick-tabs-tab {
|
|
144
|
+
margin-left: -(base.$border-width-base);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
& + &-active {
|
|
148
|
+
position: relative;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
&:hover {
|
|
152
|
+
background-color: tabs.$tabs-tab-card-bg-color-hover;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
&:focus-visible {
|
|
156
|
+
background-color: tabs.$tabs-tab-card-bg-color-hover;
|
|
157
|
+
border-color: base.color-brand();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&:active {
|
|
161
|
+
background-color: tabs.$tabs-tab-card-bg-color-active;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
&:first-child {
|
|
165
|
+
border-top-left-radius: tabs.$tabs-tab-border-radius;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
&:last-child {
|
|
169
|
+
border-top-right-radius: tabs.$tabs-tab-border-radius;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
&-deletable {
|
|
173
|
+
padding-right: 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
&-active {
|
|
177
|
+
border-top: tabs.$tabs-tab-active-border-width solid base.$color-primary;
|
|
178
|
+
padding-top: tabs.$tabs-tab-padding-vertical - (tabs.$tabs-tab-active-border-width - base.$border-width-base);
|
|
179
|
+
background-color: tabs.$tabs-tab-card-active-bg-color;
|
|
180
|
+
border-bottom-color: tabs.$tabs-tab-card-active-bg-color;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
&-delete {
|
|
185
|
+
margin-left: tabs.$tabs-tab-delete-button-margin-text;
|
|
186
|
+
margin-right: tabs.$tabs-tab-delete-button-margin-edge - map.get(tabs.$tabs-tab-padding-horizontal, base.$base-size);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
&-status-icon {
|
|
190
|
+
color: inherit;
|
|
191
|
+
margin-right: tabs.$tabs-tab-card-status-padding-right;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
&-status-error:not(&-disabled) {
|
|
195
|
+
&, &.brick-tab-active {
|
|
196
|
+
color: tabs.$tabs-tab-color-error;
|
|
197
|
+
&:focus-visible {
|
|
198
|
+
border-color: base.$color-error;
|
|
199
|
+
@include base.focus-ring(base.$color-error)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.brick-tabs-tab-status-icon {
|
|
204
|
+
color: currentColor;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
&-disabled {
|
|
209
|
+
background-color: tabs.$tabs-tab-card-bg-color;
|
|
210
|
+
&:hover {
|
|
211
|
+
background-color: tabs.$tabs-tab-card-bg-color;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.brick-tabs-ellipsis {
|
|
217
|
+
border-top-right-radius: tabs.$tabs-tab-border-radius;
|
|
218
|
+
text-align: center;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&.brick-tabs-with-ellipsis {
|
|
222
|
+
.brick-tabs-wrap::after {
|
|
223
|
+
@include base.box-shadow-inset(right);
|
|
224
|
+
& {
|
|
225
|
+
top: $tabs-wrap-gap;
|
|
226
|
+
bottom: $tabs-wrap-gap;
|
|
227
|
+
right: 0;
|
|
228
|
+
left: unset;
|
|
229
|
+
transform: unset;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
.brick-tabs-tab {
|
|
233
|
+
&:last-child {
|
|
234
|
+
border-radius: 0;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.brick-tabs-type-tag > .brick-tabs-container {
|
|
241
|
+
.brick-tabs-tab {
|
|
242
|
+
padding-top: 0;
|
|
243
|
+
padding-bottom: 0;
|
|
244
|
+
&-active {
|
|
245
|
+
background-color: tabs.$tabs-tab-tag-active-bg-color;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.brick-tabs-tab:not(.brick-tabs-tab-disabled) {
|
|
250
|
+
&:hover {
|
|
251
|
+
color: tabs.$tabs-tab-tag-color-hover;
|
|
252
|
+
}
|
|
253
|
+
&:active {
|
|
254
|
+
color: tabs.$tabs-tab-tag-color-active;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// @note safari < 15.4 不支持 :focus-visible,会导致通分组样式一同失效,估须将其单独修饰,以保证其他样式正常
|
|
258
|
+
// 特别注意不能和上面 &:hover 放一起, 否则 post-css 会判定为连续两个一致的修饰,将其"优化"合并成一个分组
|
|
259
|
+
.brick-tabs-tab:not(.brick-tabs-tab-disabled):not(:active):focus-visible {
|
|
260
|
+
color: tabs.$tabs-tab-tag-color-hover;
|
|
261
|
+
}
|
|
262
|
+
.brick-tabs-tab-active {
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.brick-tabs-type-tag,
|
|
267
|
+
.brick-tabs-type-button-group-intensive,
|
|
268
|
+
.brick-tabs-type-button-group-important {
|
|
269
|
+
> .brick-tabs-container::after {
|
|
270
|
+
content: none;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@each $size in tabs.$tabs-size-list {
|
|
275
|
+
.brick-tabs-size-#{$size} {
|
|
276
|
+
@include base.font-size-with-line-height(map.get(tabs.$tabs-font-size, $size));
|
|
277
|
+
.brick-tabs-tab {
|
|
278
|
+
min-width: map.get(tabs.$tabs-tab-min-width, $size);
|
|
279
|
+
padding-left: map.get(tabs.$tabs-tab-padding-horizontal, $size);
|
|
280
|
+
padding-right: map.get(tabs.$tabs-tab-padding-horizontal, $size);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
&.brick-tabs-type-card {
|
|
284
|
+
.brick-tabs-add {
|
|
285
|
+
padding-top: map.get(tabs.$tabs-tab-add-button-padding-vertical, $size);
|
|
286
|
+
}
|
|
287
|
+
.brick-tabs-ellipsis {
|
|
288
|
+
padding: tabs.$tabs-tab-padding-vertical map.get(tabs.$tabs-tab-card-ellipsis-button-padding-horizontal, $size);
|
|
289
|
+
}
|
|
290
|
+
.brick-tabs-tab-delete {
|
|
291
|
+
margin-right: tabs.$tabs-tab-delete-button-margin-edge - map.get(tabs.$tabs-tab-padding-horizontal, $size);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
&.brick-tabs-type-tag {
|
|
296
|
+
$tag-tab-height: map.get(tabs.$tabs-tab-tag-height, $size);
|
|
297
|
+
.brick-tabs-wrap > ul {
|
|
298
|
+
line-height: $tag-tab-height;
|
|
299
|
+
}
|
|
300
|
+
.brick-tabs-tab {
|
|
301
|
+
height: $tag-tab-height;
|
|
302
|
+
min-width: map.get(tabs.$tabs-tab-tag-min-width, $size);
|
|
303
|
+
border-radius: map.get(tabs.$tabs-tab-tag-border-radius, $size);
|
|
304
|
+
font-size: map.get(tabs.$tabs-tab-tag-font-size, $size);
|
|
305
|
+
+ .brick-tabs-tab {
|
|
306
|
+
margin-left: map.get(tabs.$tabs-tab-tag-sibling-margin, $size)
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.brick-tabs-ellipsis-dropdown-popper {
|
|
314
|
+
.brick-menu-item-content-inner .brick-tabs-tab-delete {
|
|
315
|
+
position: absolute;
|
|
316
|
+
display: inline-block;
|
|
317
|
+
top: 50%;
|
|
318
|
+
transform: translateY(-50%);
|
|
319
|
+
right: menu.$menu-popper-item-padding-horizontal;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.brick-tabs-ellipsis-item-status-error {
|
|
323
|
+
&.brick-menu-item:not(.brick-menu-item-selected, .brick-menu-item-disabled) > .brick-menu-item-content-in-cursor,
|
|
324
|
+
.brick-menu-item-content {
|
|
325
|
+
color: tabs.$tabs-tab-color-error;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.brick-tabs-tab-pane {
|
|
331
|
+
&-inactive {
|
|
332
|
+
display: none;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// z-index 管理
|
|
337
|
+
// tab 之间有重叠部分,通过 z-index 确定是重叠取样式
|
|
338
|
+
.brick-tabs {
|
|
339
|
+
// create stacking context
|
|
340
|
+
z-index: 0;
|
|
341
|
+
&-container::after {
|
|
342
|
+
z-index: 0;
|
|
343
|
+
}
|
|
344
|
+
&-wrap {
|
|
345
|
+
z-index: 1;
|
|
346
|
+
}
|
|
347
|
+
&-ellipsis {
|
|
348
|
+
z-index: 2;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
&-tab {
|
|
352
|
+
z-index: 0;
|
|
353
|
+
}
|
|
354
|
+
&-tab-active {
|
|
355
|
+
z-index: 1;
|
|
356
|
+
}
|
|
357
|
+
&-tab:focus-visible {
|
|
358
|
+
z-index: 2;
|
|
359
|
+
}
|
|
360
|
+
}
|
package/src/tab-pane.tsx
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {Component, ContextType, ReactNode} from 'react'
|
|
2
|
+
// import * as PropTypes from 'prop-types'
|
|
3
|
+
import c from 'classnames'
|
|
4
|
+
import {isUndefined} from 'lodash-es'
|
|
5
|
+
import {TabPaneId, TabsContext} from './tabs-context'
|
|
6
|
+
|
|
7
|
+
export interface TabPaneProps {
|
|
8
|
+
/**
|
|
9
|
+
* 自定义 class
|
|
10
|
+
*/
|
|
11
|
+
className?: string
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 唯一标识
|
|
15
|
+
*/
|
|
16
|
+
id: TabPaneId
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 标签页上的内容
|
|
20
|
+
*/
|
|
21
|
+
label: ReactNode
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 是否禁用
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 是否可删除
|
|
30
|
+
*/
|
|
31
|
+
deletable?: boolean
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* tab 标签页的状态
|
|
35
|
+
* - 仅 type card 支持
|
|
36
|
+
* - 暂时只有 'normal' | 'error'
|
|
37
|
+
*/
|
|
38
|
+
status?: 'normal' | 'error'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type TabPanePropsWithDefaults = TabPaneProps & Required<Pick<TabPaneProps, keyof typeof TabPane.defaultProps>>
|
|
42
|
+
|
|
43
|
+
export class TabPane extends Component<TabPaneProps> {
|
|
44
|
+
static displayName = 'TabPane'
|
|
45
|
+
// static propTypes = {}
|
|
46
|
+
static defaultProps = {
|
|
47
|
+
className: '',
|
|
48
|
+
status: 'normal',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static contextType = TabsContext
|
|
52
|
+
|
|
53
|
+
context!: ContextType<typeof TabsContext>
|
|
54
|
+
|
|
55
|
+
get className() {
|
|
56
|
+
const {className, status} = this.props as TabPanePropsWithDefaults
|
|
57
|
+
return c(
|
|
58
|
+
'brick-tabs-tab-pane',
|
|
59
|
+
`brick-tabs-tab-pane-${this.isActive ? 'active' : 'inactive'}`,
|
|
60
|
+
`brick-tabs-tab-pane-status-${status}`,
|
|
61
|
+
className
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get isActive() {
|
|
66
|
+
const {activeId} = this.context
|
|
67
|
+
const {id} = this.props
|
|
68
|
+
if (isUndefined(id) || isUndefined(activeId) || activeId === null) {
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return id === activeId
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
render() {
|
|
76
|
+
return (
|
|
77
|
+
<div className={this.className}>
|
|
78
|
+
{this.props.children}
|
|
79
|
+
</div>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
}
|