-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move components to src (#1354)
BREAKING CHANGE: change the importing path of components. Using DesignContext for global configuration.
- Loading branch information
Showing
588 changed files
with
8,467 additions
and
7,160 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,65 @@ | ||
import React, { useState } from 'react'; | ||
import classnames from 'classnames'; | ||
import { usePrefixCls, useSize } from '@gio-design/utils'; | ||
|
||
import _ from 'lodash'; | ||
import { | ||
CheckCircleFilled, | ||
WarningCircleFilled, | ||
InfoCircleFilled, | ||
CloseCircleFilled, | ||
CloseOutlined, | ||
} from '@gio-design/icons'; | ||
import { PaletteGreen7, PaletteYellow7, PaletteRed5, PaletteBlue6 } from '@gio-design/tokens'; | ||
import { AlertProps } from './interfaces'; | ||
|
||
export const Alert: React.FC<AlertProps> = (props: AlertProps) => { | ||
const prefixCls = usePrefixCls('alert'); | ||
const [alertStatus, setAlertStatus] = useState(true); | ||
const { message, description, closeable, showIcon = false, onClose, icon, type, size: customizeSize, style } = props; | ||
|
||
const size = useSize(); | ||
const mergedSize = customizeSize ?? size; | ||
const getIcon = () => { | ||
switch (type) { | ||
case 'success': | ||
return <CheckCircleFilled color={PaletteGreen7} />; | ||
case 'warning': | ||
return <WarningCircleFilled color={PaletteYellow7} />; | ||
case 'error': | ||
return <CloseCircleFilled color={PaletteRed5} />; | ||
case 'info': | ||
return <InfoCircleFilled color={PaletteBlue6} />; | ||
default: | ||
return icon || <InfoCircleFilled color={PaletteBlue6} />; | ||
} | ||
}; | ||
|
||
const closeAlert = () => { | ||
setAlertStatus(false); | ||
onClose?.(); | ||
}; | ||
|
||
return alertStatus ? ( | ||
<div style={style} className={classnames(prefixCls, `${prefixCls}-${mergedSize}`, `${prefixCls}-${type}`)}> | ||
{showIcon && <div className={classnames(`${prefixCls}-icon`)}>{getIcon()}</div>} | ||
<div className={classnames(`${prefixCls}-content`)}> | ||
{message && <div className={classnames(`${prefixCls}-content-title`)}>{message}</div>} | ||
{description && <div className={classnames(`${prefixCls}-content-description`)}>{description}</div>} | ||
</div> | ||
{closeable && ( | ||
<div | ||
className={classnames(`${prefixCls}-closeIcon`)} | ||
onClick={closeAlert} | ||
role="button" | ||
tabIndex={0} | ||
onKeyPress={_.noop} | ||
> | ||
<CloseOutlined /> | ||
</div> | ||
)} | ||
</div> | ||
) : null; | ||
}; | ||
|
||
export default Alert; |
This file contains 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,42 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { Default } from '../demos/Alert.stories'; | ||
import Alert from '../Alert'; | ||
|
||
const props = { | ||
showIcon: true, | ||
closeable: true, | ||
message: '标题', | ||
description: '提示正文', | ||
}; | ||
describe('Testing Alert', () => { | ||
it('basic', () => { | ||
render(<Default {...Default.args} />); | ||
}); | ||
|
||
it('no description', () => { | ||
render(<Alert />); | ||
}); | ||
|
||
it('show icon', () => { | ||
render(<Alert {...props} type="info" />); | ||
expect(screen.getByText('提示正文')).toBeTruthy(); | ||
}); | ||
|
||
it('showIcon', () => { | ||
render(<Alert showIcon closeable />); | ||
fireEvent.click(screen.getByRole('button')); | ||
}); | ||
|
||
it('showIcon', () => { | ||
render(<Alert showIcon closeable icon={11} />); | ||
fireEvent.click(screen.getByRole('button')); | ||
}); | ||
|
||
it('can be close', () => { | ||
const mockClick = jest.fn(); | ||
render(<Alert {...props} onClose={mockClick} />); | ||
fireEvent.click(screen.getByRole('button')); | ||
expect(mockClick).toBeCalled(); | ||
}); | ||
}); |
This file contains 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,65 @@ | ||
import React from 'react'; | ||
import { Story, Meta } from '@storybook/react/types-6-0'; | ||
import { action } from '@storybook/addon-actions'; | ||
import Docs from './AlertPage'; | ||
import Alert from '../index'; | ||
import { AlertProps } from '../interfaces'; | ||
import '../style'; | ||
|
||
export default { | ||
title: 'Feedback/Alert', | ||
component: Alert, | ||
parameters: { | ||
docs: { | ||
page: Docs, | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
const Template: Story<AlertProps> = (args) => ( | ||
<div style={{ width: 320 }}> | ||
<Alert {...args} type="info" size="small" /> | ||
<br /> | ||
<Alert {...args} type="warning" size="small" /> | ||
<br /> | ||
<Alert {...args} type="success" size="small" /> | ||
<br /> | ||
<Alert {...args} type="error" size="small" onClose={action('我被关闭了')} /> | ||
</div> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
showIcon: true, | ||
closeable: true, | ||
message: '标题', | ||
description: '提示正文', | ||
}; | ||
|
||
export const NoDescription = Template.bind({}); | ||
NoDescription.args = { | ||
showIcon: true, | ||
closeable: true, | ||
message: '标题', | ||
}; | ||
|
||
export const NoTitle = Template.bind({}); | ||
NoTitle.args = { | ||
showIcon: true, | ||
closeable: true, | ||
description: '提示正文', | ||
}; | ||
|
||
export const NoIcon = Template.bind({}); | ||
NoIcon.args = { | ||
closeable: true, | ||
message: '标题', | ||
description: '提示正文', | ||
}; | ||
|
||
export const NoClose = Template.bind({}); | ||
NoClose.args = { | ||
showIcon: true, | ||
message: '标题', | ||
description: '提示正文', | ||
}; |
This file contains 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,48 @@ | ||
import React from 'react'; | ||
import { Canvas, Title, Heading, Story, Subheading, ArgsTable } from '@storybook/addon-docs'; | ||
import { useIntl } from 'react-intl'; | ||
import Alert from '../Alert'; | ||
|
||
export default function ListPage() { | ||
const { formatMessage } = useIntl(); | ||
|
||
return ( | ||
<> | ||
<Title>{formatMessage({ defaultMessage: 'Alert 警告信息' })}</Title> | ||
<p> | ||
{formatMessage({ | ||
defaultMessage: | ||
'当某个页面需要向用户显示警告、提示的信息时使用,这部分信息是用户必须了解的,例如未对公众号进行授权则影响某些功能的使用。通常为页面级提示信息,提示重要性高,通常位置在页面或弹窗顶部。Alert宽度根据不同使用场景,可以设置为固定宽度,内容超长时,换行展示。', | ||
})} | ||
</p> | ||
<Heading>{formatMessage({ defaultMessage: '代码演示' })}</Heading> | ||
<Subheading>{formatMessage({ defaultMessage: 'Icon、标题、正文、关闭按钮' })}</Subheading> | ||
<Canvas> | ||
<Story id="feedback-alert--default" /> | ||
</Canvas> | ||
|
||
<Subheading>{formatMessage({ defaultMessage: 'Icon & 标题 & 关闭' })}</Subheading> | ||
<Canvas> | ||
<Story id="feedback-alert--no-description" /> | ||
</Canvas> | ||
|
||
<Subheading>{formatMessage({ defaultMessage: 'Icon & 正文 & 关闭' })}</Subheading> | ||
<Canvas> | ||
<Story id="feedback-alert--no-title" /> | ||
</Canvas> | ||
|
||
<Subheading>{formatMessage({ defaultMessage: '标题 & 正文 & 关闭' })}</Subheading> | ||
<Canvas> | ||
<Story id="feedback-alert--no-icon" /> | ||
</Canvas> | ||
|
||
<Subheading>{formatMessage({ defaultMessage: 'Icon & 标题 & 正文 ' })}</Subheading> | ||
<Canvas> | ||
<Story id="feedback-alert--no-close" /> | ||
</Canvas> | ||
|
||
<Heading>{formatMessage({ defaultMessage: '参数说明' })}</Heading> | ||
<ArgsTable of={Alert} /> | ||
</> | ||
); | ||
} |
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Alert from './alert'; | ||
import Alert from './Alert'; | ||
|
||
export { AlertProps } from './interfaces'; | ||
export default Alert; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/components/alert/style/index.less → src/alert/style/index.less
This file contains 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
File renamed without changes.
This file contains 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
2 changes: 1 addition & 1 deletion
2
src/components/avatar/AvatarGroup.tsx → src/avatar/AvatarGroup.tsx
This file contains 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
This file contains 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
10 changes: 5 additions & 5 deletions
10
src/components/avatar/Avatar.stories.tsx → src/avatar/demos/Avatar.stories.tsx
This file contains 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.
b90e301
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: