@befe/brick-comp-tabs 0.2.127 → 0.2.128

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@befe/brick-comp-tabs",
3
- "version": "0.2.127",
3
+ "version": "0.2.128",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "ssh://git@icode.baidu.com:8235/baidu/be-fe/brick",
@@ -25,21 +25,19 @@
25
25
  "author": "wujun07",
26
26
  "license": "ISC",
27
27
  "dependencies": {
28
- "@befe/brick-comp-button": "^0.2.112",
29
- "@befe/brick-comp-close-x": "^0.2.113",
30
- "@befe/brick-comp-icon": "^0.2.109",
31
- "@befe/brick-comp-menu": "^0.2.127",
32
- "@befe/brick-comp-radio": "^0.2.110",
33
- "@befe/brick-core": "^0.2.68",
34
- "@befe/brick-icon": "^0.2.42",
35
- "@befe/brick-style": "^0.2.80",
36
- "@befe/brick-utils": "^0.2.40"
28
+ "@befe/brick-comp-button": "^0.2.113",
29
+ "@befe/brick-comp-close-x": "^0.2.114",
30
+ "@befe/brick-comp-icon": "^0.2.110",
31
+ "@befe/brick-comp-menu": "^0.2.128",
32
+ "@befe/brick-comp-radio": "^0.2.111",
33
+ "@befe/brick-core": "^0.2.69",
34
+ "@befe/brick-icon": "^0.2.43",
35
+ "@befe/brick-style": "^0.2.81",
36
+ "@befe/brick-utils": "^0.2.41"
37
37
  },
38
38
  "peerDependencies": {
39
- "classnames": "^2.0.0",
40
- "lodash-es": "^4.0.0",
41
39
  "react": "^16.9.0 || ^17.0.0",
42
40
  "react-dom": "^16.9.0 || ^17.0.0"
43
41
  },
44
- "gitHead": "c74f2a8e53380dab632b88a18439c3f84a84799f"
42
+ "gitHead": "8a332023724d1ba1165588df814a164ef56d87e2"
45
43
  }
package/src/style.scss CHANGED
@@ -115,7 +115,7 @@ $tabs-wrap-gap: base.padding(1);
115
115
  }
116
116
 
117
117
  }
118
- // @note safari < 15.4 不支持 :focus-visible,会导致通分组样式一同失效,估须将其单独修饰,以保证其他样式正常
118
+ // safari < 15.4 不支持 :focus-visible,会导致通分组样式一同失效,估须将其单独修饰,以保证其他样式正常
119
119
  // 特别注意不能和上面 &:hover 放一起, 否则 post-css 会判定为连续两个一致的修饰,将其"优化"合并成一个分组
120
120
  .brick-tabs-tab:not(.brick-tabs-tab-disabled):not(:active):focus-visible {
121
121
  color: tabs.$tabs-tab-color-hover;
@@ -254,7 +254,7 @@ $tabs-wrap-gap: base.padding(1);
254
254
  color: tabs.$tabs-tab-tag-color-active;
255
255
  }
256
256
  }
257
- // @note safari < 15.4 不支持 :focus-visible,会导致通分组样式一同失效,估须将其单独修饰,以保证其他样式正常
257
+ // safari < 15.4 不支持 :focus-visible,会导致通分组样式一同失效,估须将其单独修饰,以保证其他样式正常
258
258
  // 特别注意不能和上面 &:hover 放一起, 否则 post-css 会判定为连续两个一致的修饰,将其"优化"合并成一个分组
259
259
  .brick-tabs-tab:not(.brick-tabs-tab-disabled):not(:active):focus-visible {
260
260
  color: tabs.$tabs-tab-tag-color-hover;
package/src/tab-pane.tsx CHANGED
@@ -1,7 +1,5 @@
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'
1
+ import {PropsWithChildren, ReactNode, useContext} from 'react'
2
+ import {cx, isUndefined} from '@befe/brick-utils'
5
3
  import {TabPaneId, TabsContext} from './tabs-context'
6
4
 
7
5
  export interface TabPaneProps {
@@ -34,49 +32,35 @@ export interface TabPaneProps {
34
32
  * tab 标签页的状态
35
33
  * - 仅 type card 支持
36
34
  * - 暂时只有 'normal' | 'error'
35
+ * @default 'normal'
37
36
  */
38
37
  status?: 'normal' | 'error'
39
38
  }
40
39
 
41
- type TabPanePropsWithDefaults = TabPaneProps & Required<Pick<TabPaneProps, keyof typeof TabPane.defaultProps>>
40
+ /**
41
+ * TabPane `status` 默认值;父组件 `Tabs.getTabsAll` 读取 `child.props.status` 时也用它兜底
42
+ * (默认参数不进 element.props,故父子两处共用此常量,避免字面量各写一份而漂移)
43
+ */
44
+ export const TAB_PANE_DEFAULT_STATUS: NonNullable<TabPaneProps['status']> = 'normal'
42
45
 
43
- export class TabPane extends Component<TabPaneProps> {
44
- static displayName = 'TabPane'
45
- // static propTypes = {}
46
- static defaultProps = {
47
- className: '',
48
- status: 'normal',
49
- }
46
+ export function TabPane(props: PropsWithChildren<TabPaneProps>) {
47
+ const {className, id, status = TAB_PANE_DEFAULT_STATUS, children} = props
48
+ const {activeId} = useContext(TabsContext)
50
49
 
51
- static contextType = TabsContext
50
+ const isActive = !isUndefined(id) && !isUndefined(activeId) && activeId !== null && id === activeId
52
51
 
53
- context!: ContextType<typeof TabsContext>
52
+ const paneClassName = cx(
53
+ 'brick-tabs-tab-pane',
54
+ `brick-tabs-tab-pane-${isActive ? 'active' : 'inactive'}`,
55
+ `brick-tabs-tab-pane-status-${status}`,
56
+ className
57
+ )
54
58
 
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
- }
59
+ return (
60
+ <div className={paneClassName}>
61
+ {children}
62
+ </div>
63
+ )
82
64
  }
65
+
66
+ TabPane.displayName = 'TabPane'