@@ -2,8 +2,7 @@ import classNames from 'classnames'
22import type { CSSProperties , FC , ReactNode } from 'react'
33import React from 'react'
44import { NativeProps , withNativeProps } from '../../utils/native-props'
5-
6- const classPrefix = `adm-card`
5+ import { useConfig } from '../config-provider'
76
87export type CardProps = {
98 title ?: ReactNode
@@ -17,25 +16,28 @@ export type CardProps = {
1716 onBodyClick ?: ( event : React . MouseEvent < HTMLDivElement , MouseEvent > ) => void
1817 onHeaderClick ?: ( event : React . MouseEvent < HTMLDivElement , MouseEvent > ) => void
1918 children ?: ReactNode
19+ prefixCls ?: string
2020} & NativeProps
2121
2222export const Card : FC < CardProps > = props => {
23+ const { getPrefixCls } = useConfig ( )
24+ const prefixCls = getPrefixCls ( 'card' , props . prefixCls )
2325 const renderHeader = ( ) => {
2426 if ( ! ( props . title || props . extra ) ) {
2527 return null
2628 }
2729 return (
2830 < div
29- className = { classNames ( `${ classPrefix } -header` , props . headerClassName ) }
31+ className = { classNames ( `${ prefixCls } -header` , props . headerClassName ) }
3032 style = { props . headerStyle }
3133 onClick = { props . onHeaderClick }
3234 >
3335 { props . icon && (
34- < div className = { `${ classPrefix } -header-icon` } > { props . icon } </ div >
36+ < div className = { `${ prefixCls } -header-icon` } > { props . icon } </ div >
3537 ) }
36- < div className = { `${ classPrefix } -header-title` } > { props . title } </ div >
38+ < div className = { `${ prefixCls } -header-title` } > { props . title } </ div >
3739 { props . extra && (
38- < div className = { `${ classPrefix } -header-extra` } > { props . extra } </ div >
40+ < div className = { `${ prefixCls } -header-extra` } > { props . extra } </ div >
3941 ) }
4042 </ div >
4143 )
@@ -47,7 +49,7 @@ export const Card: FC<CardProps> = props => {
4749 }
4850 return (
4951 < div
50- className = { classNames ( `${ classPrefix } -body` , props . bodyClassName ) }
52+ className = { classNames ( `${ prefixCls } -body` , props . bodyClassName ) }
5153 style = { props . bodyStyle }
5254 onClick = { props . onBodyClick }
5355 >
@@ -58,7 +60,7 @@ export const Card: FC<CardProps> = props => {
5860
5961 return withNativeProps (
6062 props ,
61- < div className = { classPrefix } onClick = { props . onClick } >
63+ < div className = { prefixCls } onClick = { props . onClick } >
6264 { renderHeader ( ) }
6365 { renderBody ( ) }
6466 </ div >
0 commit comments