- Notifications
You must be signed in to change notification settings - Fork2.5k
feat(card): unified provision of custom prefixCls#6972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
EmilyyyLiu wants to merge1 commit intoant-design:featureChoose a base branch fromEmilyyyLiu:feature-prefix-card
base:feature
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+74 −8
Open
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
18 changes: 10 additions & 8 deletionssrc/components/card/card.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,8 +2,7 @@ import classNames from 'classnames' | ||
| import type { CSSProperties, FC, ReactNode } from 'react' | ||
| import React from 'react' | ||
| import { NativeProps, withNativeProps } from '../../utils/native-props' | ||
EmilyyyLiu marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| import { useConfig } from '../config-provider' | ||
| export type CardProps = { | ||
| title?: ReactNode | ||
| @@ -17,25 +16,28 @@ export type CardProps = { | ||
| onBodyClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void | ||
| onHeaderClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void | ||
| children?: ReactNode | ||
| prefixCls?: string | ||
| } & NativeProps | ||
| export const Card: FC<CardProps> = props => { | ||
| const { getPrefixCls } = useConfig() | ||
| const prefixCls = getPrefixCls('card', props.prefixCls) | ||
| const renderHeader = () => { | ||
| if (!(props.title || props.extra)) { | ||
| return null | ||
| } | ||
| return ( | ||
| <div | ||
| className={classNames(`${prefixCls}-header`, props.headerClassName)} | ||
| style={props.headerStyle} | ||
| onClick={props.onHeaderClick} | ||
| > | ||
| {props.icon && ( | ||
| <div className={`${prefixCls}-header-icon`}>{props.icon}</div> | ||
| )} | ||
| <div className={`${prefixCls}-header-title`}>{props.title}</div> | ||
| {props.extra && ( | ||
| <div className={`${prefixCls}-header-extra`}>{props.extra}</div> | ||
| )} | ||
| </div> | ||
| ) | ||
| @@ -47,7 +49,7 @@ export const Card: FC<CardProps> = props => { | ||
| } | ||
| return ( | ||
| <div | ||
| className={classNames(`${prefixCls}-body`, props.bodyClassName)} | ||
| style={props.bodyStyle} | ||
| onClick={props.onBodyClick} | ||
| > | ||
| @@ -58,7 +60,7 @@ export const Card: FC<CardProps> = props => { | ||
| return withNativeProps( | ||
| props, | ||
| <div className={prefixCls} onClick={props.onClick}> | ||
| {renderHeader()} | ||
| {renderBody()} | ||
| </div> | ||
39 changes: 39 additions & 0 deletionssrc/components/card/tests/__snapshots__/card.test.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
| exports[`should apply prefixCls from ConfigProvider 1`] = ` | ||
| <div> | ||
| <div | ||
| class="config-prefix-card" | ||
| data-testid="test-card-id" | ||
| > | ||
| <div | ||
| class="config-prefix-card-header" | ||
| > | ||
| <div | ||
| class="config-prefix-card-header-title" | ||
| > | ||
| title | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| `; | ||
| exports[`should prioritize component prefixCls over ConfigProvider 1`] = ` | ||
| <div> | ||
| <div | ||
| class="component-prefix" | ||
| data-testid="test-card-id" | ||
| > | ||
| <div | ||
| class="component-prefix-header" | ||
| > | ||
| <div | ||
| class="component-prefix-header-title" | ||
| > | ||
| title | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| `; |
25 changes: 25 additions & 0 deletionssrc/components/card/tests/card.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.