@akinon/ui-alert 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,12 @@
1
- import type { AlertProps as AntAlertProps } from 'antd';
2
1
  import * as React from 'react';
3
- export type AlertProps = AntAlertProps;
4
- /**
5
- * A component that renders an Ant Design Alert component with the given props.
6
- *
7
- * @param {AlertProps} restAlertProps - The props for the Alert component
8
- * @return {JSX.Element} The rendered Ant Alert component
9
- */
10
- export declare const Alert: ({ ...restAlertProps }: AlertProps) => React.JSX.Element;
2
+ import type { AlertProps } from './types';
3
+ export type { AlertProps } from './types';
4
+ export declare enum AlertStatus {
5
+ Success = "success",
6
+ Info1 = "info-1",
7
+ Info2 = "info-2",
8
+ Info3 = "info-3",
9
+ Error = "error"
10
+ }
11
+ export declare const Alert: ({ status, ...restAlertProps }: AlertProps) => React.JSX.Element;
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,MAAM,CAAC;AAExD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,0BAA2B,UAAU,sBAEtD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,oBAAY,WAAW;IACrB,OAAO,YAAY;IACnB,KAAK,WAAW;IAChB,KAAK,WAAW;IAChB,KAAK,WAAW;IAChB,KAAK,UAAU;CAChB;AAED,eAAO,MAAM,KAAK,kCAAmC,UAAU,sBAwE9D,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -11,17 +11,76 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.Alert = void 0;
14
+ exports.Alert = exports.AlertStatus = void 0;
15
+ const ui_theme_1 = require("@akinon/ui-theme");
16
+ const cssinjs_1 = require("@ant-design/cssinjs");
15
17
  const antd_1 = require("antd");
16
18
  const React = require("react");
17
- /**
18
- * A component that renders an Ant Design Alert component with the given props.
19
- *
20
- * @param {AlertProps} restAlertProps - The props for the Alert component
21
- * @return {JSX.Element} The rendered Ant Alert component
22
- */
19
+ var AlertStatus;
20
+ (function (AlertStatus) {
21
+ AlertStatus["Success"] = "success";
22
+ AlertStatus["Info1"] = "info-1";
23
+ AlertStatus["Info2"] = "info-2";
24
+ AlertStatus["Info3"] = "info-3";
25
+ AlertStatus["Error"] = "error";
26
+ })(AlertStatus || (exports.AlertStatus = AlertStatus = {}));
23
27
  const Alert = (_a) => {
24
- var restAlertProps = __rest(_a, []);
25
- return React.createElement(antd_1.Alert, Object.assign({}, restAlertProps));
28
+ var { status } = _a, restAlertProps = __rest(_a, ["status"]);
29
+ const { getPrefixCls, theme } = React.useContext(antd_1.ConfigProvider.ConfigContext);
30
+ const { token, hashId } = (0, ui_theme_1.useToken)();
31
+ const alertToken = token.Alert;
32
+ const useStyle = (0, cssinjs_1.useStyleRegister)({
33
+ token: token,
34
+ path: ['Alert'],
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ theme: theme
37
+ }, () => {
38
+ const prefixCls = `:where(.${hashId}).${getPrefixCls()}-alert`;
39
+ const prefixClsWithoutHash = `.${getPrefixCls()}-alert`;
40
+ return {
41
+ [`${prefixCls}-${AlertStatus.Success}`]: {
42
+ color: alertToken.defaultColorSuccess,
43
+ borderColor: alertToken.defaultBorderColorSuccess,
44
+ backgroundColor: alertToken.defaultBgSuccess,
45
+ ['.anticon.anticon-close']: {
46
+ color: alertToken.defaultBorderColorSuccess
47
+ }
48
+ },
49
+ [`${prefixCls}-${AlertStatus.Info1}`]: {
50
+ color: alertToken.defaultColorWaiting1,
51
+ borderColor: alertToken.defaultBorderColorWaiting1,
52
+ backgroundColor: alertToken.defaultBgWaiting1,
53
+ ['.anticon.anticon-close']: {
54
+ color: alertToken.defaultBorderColorWaiting1
55
+ }
56
+ },
57
+ [`${prefixCls}-${AlertStatus.Info2}`]: {
58
+ color: alertToken.defaultColorWaiting2,
59
+ borderColor: alertToken.defaultBorderColorWaiting2,
60
+ backgroundColor: alertToken.defaultBgWaiting2,
61
+ ['.anticon.anticon-close']: {
62
+ color: alertToken.defaultBorderColorWaiting2
63
+ }
64
+ },
65
+ [`${prefixCls}-${AlertStatus.Info3}`]: {
66
+ color: alertToken.defaultColorWaiting3,
67
+ borderColor: alertToken.defaultBorderColorWaiting3,
68
+ backgroundColor: alertToken.defaultBgWaiting3,
69
+ ['.anticon.anticon-close']: {
70
+ color: alertToken.defaultBorderColorWaiting3
71
+ }
72
+ },
73
+ [`${prefixCls}-${AlertStatus.Error}`]: {
74
+ color: alertToken.defaultColorFailed,
75
+ borderColor: alertToken.defaultBorderColorFailed,
76
+ backgroundColor: alertToken.defaultBgFailed,
77
+ ['.anticon.anticon-close']: {
78
+ color: alertToken.defaultBorderColorFailed
79
+ }
80
+ },
81
+ [prefixClsWithoutHash]: {}
82
+ };
83
+ });
84
+ return useStyle(React.createElement(antd_1.Alert, Object.assign({ className: status && `akinon-alert-${status}` }, restAlertProps)));
26
85
  };
27
86
  exports.Alert = Alert;
@@ -0,0 +1,109 @@
1
+ import { AlertStatus } from './';
2
+
3
+ export type AlertProps = Omit<
4
+ AntAlertProps,
5
+ | 'prefixCls'
6
+ | 'style'
7
+ | 'styles'
8
+ | 'closeIcon'
9
+ | 'onMouseEnter'
10
+ | 'onMouseLeave'
11
+ | 'onClick'
12
+ | 'id'
13
+ | 'role'
14
+ > & {
15
+ /**
16
+ * The status of the alert.
17
+ */
18
+ status?: AlertStatus;
19
+ };
20
+
21
+ interface AntAlertProps {
22
+ /** Type of Alert styles */
23
+ type?: 'success' | 'info' | 'warning' | 'error';
24
+ /** Whether Alert can be closed */
25
+ closable?: ClosableType;
26
+ /** Content of Alert */
27
+ message?: React.ReactNode;
28
+ /** Additional content of Alert */
29
+ description?: React.ReactNode;
30
+ /** Callback when close Alert */
31
+ onClose?: React.MouseEventHandler<HTMLButtonElement>;
32
+ /** Trigger when animation ending of Alert */
33
+ afterClose?: () => void;
34
+ /** Whether to show icon */
35
+ showIcon?: boolean;
36
+ /** https://www.w3.org/TR/2014/REC-html5-20141028/dom.html#aria-role-attribute */
37
+ role?: string;
38
+ style?: React.CSSProperties;
39
+ prefixCls?: string;
40
+ /**
41
+ * The additional css class
42
+ */
43
+ className?: string;
44
+ /**
45
+ * ClassName on the root element
46
+ */
47
+ rootClassName?: string;
48
+ /**
49
+ * Whether to show as banner
50
+ */
51
+ banner?: boolean;
52
+ /**
53
+ * Custom icon, effective when showIcon is true
54
+ */
55
+ icon?: React.ReactNode;
56
+ /**
57
+ * Custom close icon
58
+ */
59
+ closeIcon?: React.ReactNode;
60
+ /**
61
+ * The action of Alert
62
+ */
63
+ action?: React.ReactNode;
64
+ onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
65
+ onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
66
+ onClick?: React.MouseEventHandler<HTMLDivElement>;
67
+ id?: string;
68
+ }
69
+
70
+ type BaseClosableType = {
71
+ closeIcon?: React.ReactNode;
72
+ } & React.AriaAttributes;
73
+
74
+ type ClosableType = boolean | BaseClosableType;
75
+
76
+ interface ErrorBoundaryProps {
77
+ message?: React.ReactNode;
78
+ description?: React.ReactNode;
79
+ children?: React.ReactNode;
80
+ id?: string;
81
+ }
82
+
83
+ interface ErrorBoundaryStates {
84
+ error?: Error | null;
85
+ info?: {
86
+ componentStack?: string;
87
+ };
88
+ }
89
+
90
+ declare class ErrorBoundary extends React.Component<
91
+ ErrorBoundaryProps,
92
+ ErrorBoundaryStates
93
+ > {
94
+ state: {
95
+ error: undefined;
96
+ info: {
97
+ componentStack: string;
98
+ };
99
+ };
100
+ componentDidCatch(error: Error | null, info: object): void;
101
+ render():
102
+ | string
103
+ | number
104
+ | boolean
105
+ | Iterable<React.ReactNode>
106
+ | React.JSX.Element
107
+ | null
108
+ | undefined;
109
+ }
@@ -1,11 +1,12 @@
1
- import type { AlertProps as AntAlertProps } from 'antd';
2
1
  import * as React from 'react';
3
- export type AlertProps = AntAlertProps;
4
- /**
5
- * A component that renders an Ant Design Alert component with the given props.
6
- *
7
- * @param {AlertProps} restAlertProps - The props for the Alert component
8
- * @return {JSX.Element} The rendered Ant Alert component
9
- */
10
- export declare const Alert: ({ ...restAlertProps }: AlertProps) => React.JSX.Element;
2
+ import type { AlertProps } from './types';
3
+ export type { AlertProps } from './types';
4
+ export declare enum AlertStatus {
5
+ Success = "success",
6
+ Info1 = "info-1",
7
+ Info2 = "info-2",
8
+ Info3 = "info-3",
9
+ Error = "error"
10
+ }
11
+ export declare const Alert: ({ status, ...restAlertProps }: AlertProps) => React.JSX.Element;
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,MAAM,CAAC;AAExD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,0BAA2B,UAAU,sBAEtD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,oBAAY,WAAW;IACrB,OAAO,YAAY;IACnB,KAAK,WAAW;IAChB,KAAK,WAAW;IAChB,KAAK,WAAW;IAChB,KAAK,UAAU;CAChB;AAED,eAAO,MAAM,KAAK,kCAAmC,UAAU,sBAwE9D,CAAC"}
package/dist/esm/index.js CHANGED
@@ -9,15 +9,74 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { Alert as AntAlert } from 'antd';
12
+ import { useToken } from '@akinon/ui-theme';
13
+ import { useStyleRegister } from '@ant-design/cssinjs';
14
+ import { Alert as AntAlert, ConfigProvider } from 'antd';
13
15
  import * as React from 'react';
14
- /**
15
- * A component that renders an Ant Design Alert component with the given props.
16
- *
17
- * @param {AlertProps} restAlertProps - The props for the Alert component
18
- * @return {JSX.Element} The rendered Ant Alert component
19
- */
16
+ export var AlertStatus;
17
+ (function (AlertStatus) {
18
+ AlertStatus["Success"] = "success";
19
+ AlertStatus["Info1"] = "info-1";
20
+ AlertStatus["Info2"] = "info-2";
21
+ AlertStatus["Info3"] = "info-3";
22
+ AlertStatus["Error"] = "error";
23
+ })(AlertStatus || (AlertStatus = {}));
20
24
  export const Alert = (_a) => {
21
- var restAlertProps = __rest(_a, []);
22
- return React.createElement(AntAlert, Object.assign({}, restAlertProps));
25
+ var { status } = _a, restAlertProps = __rest(_a, ["status"]);
26
+ const { getPrefixCls, theme } = React.useContext(ConfigProvider.ConfigContext);
27
+ const { token, hashId } = useToken();
28
+ const alertToken = token.Alert;
29
+ const useStyle = useStyleRegister({
30
+ token: token,
31
+ path: ['Alert'],
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ theme: theme
34
+ }, () => {
35
+ const prefixCls = `:where(.${hashId}).${getPrefixCls()}-alert`;
36
+ const prefixClsWithoutHash = `.${getPrefixCls()}-alert`;
37
+ return {
38
+ [`${prefixCls}-${AlertStatus.Success}`]: {
39
+ color: alertToken.defaultColorSuccess,
40
+ borderColor: alertToken.defaultBorderColorSuccess,
41
+ backgroundColor: alertToken.defaultBgSuccess,
42
+ ['.anticon.anticon-close']: {
43
+ color: alertToken.defaultBorderColorSuccess
44
+ }
45
+ },
46
+ [`${prefixCls}-${AlertStatus.Info1}`]: {
47
+ color: alertToken.defaultColorWaiting1,
48
+ borderColor: alertToken.defaultBorderColorWaiting1,
49
+ backgroundColor: alertToken.defaultBgWaiting1,
50
+ ['.anticon.anticon-close']: {
51
+ color: alertToken.defaultBorderColorWaiting1
52
+ }
53
+ },
54
+ [`${prefixCls}-${AlertStatus.Info2}`]: {
55
+ color: alertToken.defaultColorWaiting2,
56
+ borderColor: alertToken.defaultBorderColorWaiting2,
57
+ backgroundColor: alertToken.defaultBgWaiting2,
58
+ ['.anticon.anticon-close']: {
59
+ color: alertToken.defaultBorderColorWaiting2
60
+ }
61
+ },
62
+ [`${prefixCls}-${AlertStatus.Info3}`]: {
63
+ color: alertToken.defaultColorWaiting3,
64
+ borderColor: alertToken.defaultBorderColorWaiting3,
65
+ backgroundColor: alertToken.defaultBgWaiting3,
66
+ ['.anticon.anticon-close']: {
67
+ color: alertToken.defaultBorderColorWaiting3
68
+ }
69
+ },
70
+ [`${prefixCls}-${AlertStatus.Error}`]: {
71
+ color: alertToken.defaultColorFailed,
72
+ borderColor: alertToken.defaultBorderColorFailed,
73
+ backgroundColor: alertToken.defaultBgFailed,
74
+ ['.anticon.anticon-close']: {
75
+ color: alertToken.defaultBorderColorFailed
76
+ }
77
+ },
78
+ [prefixClsWithoutHash]: {}
79
+ };
80
+ });
81
+ return useStyle(React.createElement(AntAlert, Object.assign({ className: status && `akinon-alert-${status}` }, restAlertProps)));
23
82
  };
@@ -0,0 +1,109 @@
1
+ import { AlertStatus } from './';
2
+
3
+ export type AlertProps = Omit<
4
+ AntAlertProps,
5
+ | 'prefixCls'
6
+ | 'style'
7
+ | 'styles'
8
+ | 'closeIcon'
9
+ | 'onMouseEnter'
10
+ | 'onMouseLeave'
11
+ | 'onClick'
12
+ | 'id'
13
+ | 'role'
14
+ > & {
15
+ /**
16
+ * The status of the alert.
17
+ */
18
+ status?: AlertStatus;
19
+ };
20
+
21
+ interface AntAlertProps {
22
+ /** Type of Alert styles */
23
+ type?: 'success' | 'info' | 'warning' | 'error';
24
+ /** Whether Alert can be closed */
25
+ closable?: ClosableType;
26
+ /** Content of Alert */
27
+ message?: React.ReactNode;
28
+ /** Additional content of Alert */
29
+ description?: React.ReactNode;
30
+ /** Callback when close Alert */
31
+ onClose?: React.MouseEventHandler<HTMLButtonElement>;
32
+ /** Trigger when animation ending of Alert */
33
+ afterClose?: () => void;
34
+ /** Whether to show icon */
35
+ showIcon?: boolean;
36
+ /** https://www.w3.org/TR/2014/REC-html5-20141028/dom.html#aria-role-attribute */
37
+ role?: string;
38
+ style?: React.CSSProperties;
39
+ prefixCls?: string;
40
+ /**
41
+ * The additional css class
42
+ */
43
+ className?: string;
44
+ /**
45
+ * ClassName on the root element
46
+ */
47
+ rootClassName?: string;
48
+ /**
49
+ * Whether to show as banner
50
+ */
51
+ banner?: boolean;
52
+ /**
53
+ * Custom icon, effective when showIcon is true
54
+ */
55
+ icon?: React.ReactNode;
56
+ /**
57
+ * Custom close icon
58
+ */
59
+ closeIcon?: React.ReactNode;
60
+ /**
61
+ * The action of Alert
62
+ */
63
+ action?: React.ReactNode;
64
+ onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
65
+ onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
66
+ onClick?: React.MouseEventHandler<HTMLDivElement>;
67
+ id?: string;
68
+ }
69
+
70
+ type BaseClosableType = {
71
+ closeIcon?: React.ReactNode;
72
+ } & React.AriaAttributes;
73
+
74
+ type ClosableType = boolean | BaseClosableType;
75
+
76
+ interface ErrorBoundaryProps {
77
+ message?: React.ReactNode;
78
+ description?: React.ReactNode;
79
+ children?: React.ReactNode;
80
+ id?: string;
81
+ }
82
+
83
+ interface ErrorBoundaryStates {
84
+ error?: Error | null;
85
+ info?: {
86
+ componentStack?: string;
87
+ };
88
+ }
89
+
90
+ declare class ErrorBoundary extends React.Component<
91
+ ErrorBoundaryProps,
92
+ ErrorBoundaryStates
93
+ > {
94
+ state: {
95
+ error: undefined;
96
+ info: {
97
+ componentStack: string;
98
+ };
99
+ };
100
+ componentDidCatch(error: Error | null, info: object): void;
101
+ render():
102
+ | string
103
+ | number
104
+ | boolean
105
+ | Iterable<React.ReactNode>
106
+ | React.JSX.Element
107
+ | null
108
+ | undefined;
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/ui-alert",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/esm/index.js",
@@ -9,16 +9,15 @@
9
9
  "dist"
10
10
  ],
11
11
  "dependencies": {
12
- "antd": "5.17.0"
12
+ "antd": "5.17.0",
13
+ "@akinon/ui-theme": "0.7.0"
13
14
  },
14
15
  "devDependencies": {
15
16
  "clean-package": "2.2.0",
16
17
  "copyfiles": "^2.4.1",
17
18
  "rimraf": "^5.0.5",
18
19
  "typescript": "^5.2.2",
19
- "@akinon/vite-config": "0.4.0",
20
- "@akinon/typescript-config": "0.2.0",
21
- "@akinon/eslint-config": "0.1.0"
20
+ "@akinon/typescript-config": "0.4.0"
22
21
  },
23
22
  "peerDependencies": {
24
23
  "react": ">=18",
@@ -38,9 +37,8 @@
38
37
  "build": "pnpm run build:esm && pnpm run build:commonjs && pnpm run copy:files",
39
38
  "build:esm": "tsc --outDir dist/esm",
40
39
  "build:commonjs": "tsc --module commonjs --outDir dist/cjs",
41
- "copy:files": "copyfiles -u 1 src/**/*.css dist/esm && copyfiles -u 1 src/**/*.css dist/cjs",
40
+ "copy:files": "copyfiles -u 1 \"src/**/*.!(ts|tsx)\" dist/esm && copyfiles -u 1 \"src/**/*.!(ts|tsx)\" dist/cjs",
42
41
  "clean": "rimraf dist/",
43
- "lint": "eslint *.ts*",
44
42
  "typecheck": "tsc --noEmit"
45
43
  }
46
44
  }