@akinon/ui-badge 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,5 +1,5 @@
1
- import type { BadgeProps as AntBadgeProps } from 'antd';
2
1
  import * as React from 'react';
3
- export type BadgeProps = AntBadgeProps;
4
- export declare const Badge: ({ ...restBadgeProps }: BadgeProps) => React.JSX.Element;
2
+ import type { BadgeProps } from './types';
3
+ export type { BadgeProps } from './types';
4
+ export declare const Badge: ({ children, ...restBadgeProps }: BadgeProps) => React.JSX.Element;
5
5
  //# 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;AAG/B,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC;AAEvC,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,eAAO,MAAM,KAAK,oCAAqC,UAAU,sBA8BhE,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -12,10 +12,30 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.Badge = 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
19
  const Badge = (_a) => {
18
- var restBadgeProps = __rest(_a, []);
19
- return React.createElement(antd_1.Badge, Object.assign({}, restBadgeProps));
20
+ var { children } = _a, restBadgeProps = __rest(_a, ["children"]);
21
+ const { getPrefixCls, theme } = React.useContext(antd_1.ConfigProvider.ConfigContext);
22
+ const { token, hashId } = (0, ui_theme_1.useToken)();
23
+ const badgeToken = token.Badge;
24
+ const useStyle = (0, cssinjs_1.useStyleRegister)({
25
+ token: token,
26
+ path: ['Badge'],
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ theme: theme
29
+ }, () => {
30
+ const prefixCls = `:where(.${hashId}).${getPrefixCls()}-badge`;
31
+ const prefixClsWithoutHash = `.${getPrefixCls()}-badge`;
32
+ return {
33
+ [prefixCls]: {},
34
+ [`${prefixClsWithoutHash}-count.akinon-scroll-number`]: {
35
+ color: badgeToken.colorText
36
+ }
37
+ };
38
+ });
39
+ return useStyle(React.createElement(antd_1.Badge, Object.assign({}, restBadgeProps), children));
20
40
  };
21
41
  exports.Badge = Badge;
@@ -0,0 +1,65 @@
1
+ export type BadgeProps = Omit<
2
+ AntBadgeProps,
3
+ 'prefixCls' | 'style' | 'styles' | 'status'
4
+ >;
5
+
6
+ export interface AntBadgeProps {
7
+ /** Number to show in badge */
8
+ count?: React.ReactNode;
9
+ /**
10
+ * Whether to show badge when count is zero
11
+ */
12
+ showZero?: boolean;
13
+ /** Max count to show */
14
+ overflowCount?: number;
15
+ /** Whether to show red dot without number */
16
+ dot?: boolean;
17
+ style?: React.CSSProperties;
18
+ prefixCls?: string;
19
+ scrollNumberPrefixCls?: string;
20
+ className?: string;
21
+ /**
22
+ * Set Badge as a status dot
23
+ */
24
+ status?: PresetStatusColorType;
25
+ rootClassName?: string;
26
+ /**
27
+ * Customize Badge dot color
28
+ */
29
+ color?: string;
30
+ /**
31
+ * Text sets the display text of the status dot
32
+ */
33
+ text?: React.ReactNode;
34
+ /**
35
+ * If count is set, size sets the size of badge
36
+ */
37
+ size?: 'default' | 'small';
38
+ /**
39
+ * Set offset of the badge dot
40
+ */
41
+ offset?: [number | string, number | string];
42
+ /**
43
+ * Text to show when hovering over the badge
44
+ */
45
+ title?: string;
46
+ children?: React.ReactNode;
47
+ classNames?: {
48
+ root?: string;
49
+ indicator?: string;
50
+ };
51
+ styles?: {
52
+ root?: React.CSSProperties;
53
+ indicator?: React.CSSProperties;
54
+ };
55
+ }
56
+
57
+ type PresetStatusColorType = (typeof PresetStatusColorTypes)[number];
58
+
59
+ declare const PresetStatusColorTypes: readonly [
60
+ 'success',
61
+ 'processing',
62
+ 'error',
63
+ 'default',
64
+ 'warning'
65
+ ];
@@ -1,5 +1,5 @@
1
- import type { BadgeProps as AntBadgeProps } from 'antd';
2
1
  import * as React from 'react';
3
- export type BadgeProps = AntBadgeProps;
4
- export declare const Badge: ({ ...restBadgeProps }: BadgeProps) => React.JSX.Element;
2
+ import type { BadgeProps } from './types';
3
+ export type { BadgeProps } from './types';
4
+ export declare const Badge: ({ children, ...restBadgeProps }: BadgeProps) => React.JSX.Element;
5
5
  //# 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;AAG/B,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC;AAEvC,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,eAAO,MAAM,KAAK,oCAAqC,UAAU,sBA8BhE,CAAC"}
package/dist/esm/index.js CHANGED
@@ -9,9 +9,29 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { Badge as AntBadge } from 'antd';
12
+ import { useToken } from '@akinon/ui-theme';
13
+ import { useStyleRegister } from '@ant-design/cssinjs';
14
+ import { Badge as AntBadge, ConfigProvider } from 'antd';
13
15
  import * as React from 'react';
14
16
  export const Badge = (_a) => {
15
- var restBadgeProps = __rest(_a, []);
16
- return React.createElement(AntBadge, Object.assign({}, restBadgeProps));
17
+ var { children } = _a, restBadgeProps = __rest(_a, ["children"]);
18
+ const { getPrefixCls, theme } = React.useContext(ConfigProvider.ConfigContext);
19
+ const { token, hashId } = useToken();
20
+ const badgeToken = token.Badge;
21
+ const useStyle = useStyleRegister({
22
+ token: token,
23
+ path: ['Badge'],
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ theme: theme
26
+ }, () => {
27
+ const prefixCls = `:where(.${hashId}).${getPrefixCls()}-badge`;
28
+ const prefixClsWithoutHash = `.${getPrefixCls()}-badge`;
29
+ return {
30
+ [prefixCls]: {},
31
+ [`${prefixClsWithoutHash}-count.akinon-scroll-number`]: {
32
+ color: badgeToken.colorText
33
+ }
34
+ };
35
+ });
36
+ return useStyle(React.createElement(AntBadge, Object.assign({}, restBadgeProps), children));
17
37
  };
@@ -0,0 +1,65 @@
1
+ export type BadgeProps = Omit<
2
+ AntBadgeProps,
3
+ 'prefixCls' | 'style' | 'styles' | 'status'
4
+ >;
5
+
6
+ export interface AntBadgeProps {
7
+ /** Number to show in badge */
8
+ count?: React.ReactNode;
9
+ /**
10
+ * Whether to show badge when count is zero
11
+ */
12
+ showZero?: boolean;
13
+ /** Max count to show */
14
+ overflowCount?: number;
15
+ /** Whether to show red dot without number */
16
+ dot?: boolean;
17
+ style?: React.CSSProperties;
18
+ prefixCls?: string;
19
+ scrollNumberPrefixCls?: string;
20
+ className?: string;
21
+ /**
22
+ * Set Badge as a status dot
23
+ */
24
+ status?: PresetStatusColorType;
25
+ rootClassName?: string;
26
+ /**
27
+ * Customize Badge dot color
28
+ */
29
+ color?: string;
30
+ /**
31
+ * Text sets the display text of the status dot
32
+ */
33
+ text?: React.ReactNode;
34
+ /**
35
+ * If count is set, size sets the size of badge
36
+ */
37
+ size?: 'default' | 'small';
38
+ /**
39
+ * Set offset of the badge dot
40
+ */
41
+ offset?: [number | string, number | string];
42
+ /**
43
+ * Text to show when hovering over the badge
44
+ */
45
+ title?: string;
46
+ children?: React.ReactNode;
47
+ classNames?: {
48
+ root?: string;
49
+ indicator?: string;
50
+ };
51
+ styles?: {
52
+ root?: React.CSSProperties;
53
+ indicator?: React.CSSProperties;
54
+ };
55
+ }
56
+
57
+ type PresetStatusColorType = (typeof PresetStatusColorTypes)[number];
58
+
59
+ declare const PresetStatusColorTypes: readonly [
60
+ 'success',
61
+ 'processing',
62
+ 'error',
63
+ 'default',
64
+ 'warning'
65
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/ui-badge",
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,12 +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
- "test": "vitest run",
45
- "test:ui": "vitest --ui",
46
- "test:watch": "vitest watch",
47
42
  "typecheck": "tsc --noEmit"
48
43
  }
49
44
  }