Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Alert component #5

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Alert/demos/Playground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import type { AlertProps } from '@yuntijs/ui';
import { Alert } from '@yuntijs/ui';

export default () => {
const store = useCreateStore();
const control: AlertProps | any = useControls(
{
message: 'YuntiUI',
description:
'The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components, and it is recommended to use antd-style as the default css-in-js styling solution.',
showIcon: true,
type: {
options: ['success', 'info', 'warning', 'error'],
value: 'info',
},
bordered: {
options: ['dashed', 'solid', 'none'],
value: 'dashed',
},
closable: false,
banner: false,
},
{ store }
);
return (
<StoryBook levaStore={store}>
<Alert {...control} />
</StoryBook>
);
};
46 changes: 46 additions & 0 deletions src/Alert/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Alert } from '@yuntijs/ui';
import { Button, Space } from 'antd';

export default () => {
return (
<Space direction="vertical">
<Alert
action={
<Button size="small" type="text">
UNDO
</Button>
}
closable
description="The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components,
and it is recommended to use antd-style as the default css-in-js styling solution."
message="YuntiUI"
showIcon
type="info"
/>
<Alert
message="The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components,
and it is recommended to use antd-style as the default css-in-js styling solution."
showIcon
type="info"
/>
<Alert
message="The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components,
and it is recommended to use antd-style as the default css-in-js styling solution."
showIcon
type="success"
/>
<Alert
message="The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components,
and it is recommended to use antd-style as the default css-in-js styling solution."
showIcon
type="warning"
/>
<Alert
message="The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components,
and it is recommended to use antd-style as the default css-in-js styling solution."
showIcon
type="error"
/>
</Space>
);
};
36 changes: 36 additions & 0 deletions src/Alert/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
nav: Components
group: Feedback
title: Alert
description: Display warning messages that require attention.
---

## Usage

based on antd [Alert](https://ant.design/components/alert-cn/) component.

### Simple usage

```jsx | pure
import { Alert } from '@yuntijs/ui';

export default () => {
return (
<Alert
message="The YuntiUI components are inspired by LobeUI and developed based on Antd components, fully compatible with Antd components, and it is recommended to use antd-style as the default css-in-js styling solution."
showIcon
type="info"
/>
);
};
```

<code src="./demos/index.tsx" center></code>

## Playground

<code src="./demos/Playground.tsx" nopadding></code>

## APIs

<API></API>
25 changes: 25 additions & 0 deletions src/Alert/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Alert as AntdAlert, type AlertProps as AntdAlertProps } from 'antd';
import React from 'react';

import { useStyles } from './style';

export interface CustomAlertProps {
/** border type of Alert */
bordered?: 'dashed' | 'solid' | 'none';
}
export interface AlertProps extends AntdAlertProps, CustomAlertProps {}

type ComposedAlertProps = React.FC<AlertProps> & {
ErrorBoundary: typeof AntdAlert.ErrorBoundary;
};

export const Alert: ComposedAlertProps = props => {
const { bordered = 'dashed', className, ...otherProps } = props;

const { styles, cx } = useStyles({ bordered });

return <AntdAlert {...otherProps} className={cx(styles.custom, className)} />;
};
Alert.ErrorBoundary = AntdAlert.ErrorBoundary;

export default Alert;
14 changes: 14 additions & 0 deletions src/Alert/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createStyles } from 'antd-style';

import { CustomAlertProps } from './index';

export const useStyles = createStyles(
({ css }, { bordered = 'dashed' }: CustomAlertProps) => {
return {
custom: css`
border-style: ${bordered} !important;
`,
};
},
{ hashPriority: 'low' }
);
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,22 @@ export * from './MonacoEditor';
export * from './SliderInput';
export * from './Tree';

// ~ custom antd
export * from './Alert';

// ~ antd
export {
Affix,
type AffixProps,
Anchor,
type AnchorProps,
App,
type AppProps,
AutoComplete,
type AutoCompleteProps,
Avatar,
type AvatarProps,
} from 'antd';

// ~ antd-style
export { useResponsive, useTheme, useThemeMode } from 'antd-style';
Loading