1- import React , { isValidElement , useRef } from 'react'
2- import type { FC , ReactNode , ReactElement } from 'react'
3- import classNames from 'classnames'
41import { animated } from '@react-spring/web'
2+ import classNames from 'classnames'
3+ import type { FC , ReactElement , ReactNode } from 'react'
4+ import React , { isValidElement , useRef } from 'react'
55import { NativeProps , withNativeProps } from '../../utils/native-props'
6+ import { ShouldRender } from '../../utils/should-render'
7+ import { traverseReactNode } from '../../utils/traverse-react-node'
68import { usePropsValue } from '../../utils/use-props-value'
79import { useResizeEffect } from '../../utils/use-resize-effect'
810import { useTabListScroll } from '../../utils/use-tab-list-scroll'
11+ import { useConfig } from '../config-provider'
912import ScrollMask from '../scroll-mask'
10- import { ShouldRender } from '../../utils/should-render'
11- import { traverseReactNode } from '../../utils/traverse-react-node'
12-
13- const classPrefix = `adm-capsule-tabs`
1413
1514export type CapsuleTabProps = {
1615 title : ReactNode
@@ -27,14 +26,16 @@ export type CapsuleTabsProps = {
2726 defaultActiveKey ?: string | null
2827 onChange ?: ( key : string ) => void
2928 children ?: ReactNode
29+ prefixCls ?: string
3030} & NativeProps
3131
3232export const CapsuleTabs : FC < CapsuleTabsProps > = props => {
3333 const tabListContainerRef = useRef < HTMLDivElement > ( null )
3434 const rootRef = useRef < HTMLDivElement > ( null )
3535 const keyToIndexRecord : Record < string , number > = { }
3636 let firstActiveKey : string | null = null
37-
37+ const { getPrefixCls } = useConfig ( )
38+ const prefixCls = getPrefixCls ( 'capsule-tabs' , props . prefixCls )
3839 const panes : ReactElement < CapsuleTabProps > [ ] = [ ]
3940
4041 traverseReactNode ( props . children , ( child , index ) => {
@@ -68,18 +69,18 @@ export const CapsuleTabs: FC<CapsuleTabsProps> = props => {
6869
6970 return withNativeProps (
7071 props ,
71- < div className = { classPrefix } ref = { rootRef } >
72- < div className = { `${ classPrefix } -header` } >
72+ < div className = { prefixCls } ref = { rootRef } >
73+ < div className = { `${ prefixCls } -header` } >
7374 < ScrollMask scrollTrackRef = { tabListContainerRef } />
7475 < animated . div
75- className = { `${ classPrefix } -tab-list` }
76+ className = { `${ prefixCls } -tab-list` }
7677 ref = { tabListContainerRef }
7778 scrollLeft = { scrollLeft }
7879 >
7980 { panes . map ( pane =>
8081 withNativeProps (
8182 pane . props ,
82- < div key = { pane . key } className = { `${ classPrefix } -tab-wrapper` } >
83+ < div key = { pane . key } className = { `${ prefixCls } -tab-wrapper` } >
8384 < div
8485 onClick = { ( ) => {
8586 const { key } = pane
@@ -89,9 +90,9 @@ export const CapsuleTabs: FC<CapsuleTabsProps> = props => {
8990 }
9091 setActiveKey ( key . toString ( ) )
9192 } }
92- className = { classNames ( `${ classPrefix } -tab` , {
93- [ `${ classPrefix } -tab-active` ] : pane . key === activeKey ,
94- [ `${ classPrefix } -tab-disabled` ] : pane . props . disabled ,
93+ className = { classNames ( `${ prefixCls } -tab` , {
94+ [ `${ prefixCls } -tab-active` ] : pane . key === activeKey ,
95+ [ `${ prefixCls } -tab-disabled` ] : pane . props . disabled ,
9596 } ) }
9697 >
9798 { pane . props . title }
@@ -114,7 +115,7 @@ export const CapsuleTabs: FC<CapsuleTabsProps> = props => {
114115 destroyOnClose = { pane . props . destroyOnClose }
115116 >
116117 < div
117- className = { `${ classPrefix } -content` }
118+ className = { `${ prefixCls } -content` }
118119 style = { { display : active ? 'block' : 'none' } }
119120 >
120121 { pane . props . children }
0 commit comments