react-public-components 1.2.4 → 1.2.6
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.
- package/README.md +5 -2
- package/dist/AnnouncementBar/index.cjs +3 -2
- package/dist/AnnouncementBar/index.css +102 -11
- package/dist/AnnouncementBar/index.css.map +1 -1
- package/dist/AnnouncementBar/index.d.ts +22 -3
- package/dist/AnnouncementBar/index.js +2 -1
- package/dist/CeilingBox/index.cjs +9 -0
- package/dist/CeilingBox/index.cjs.map +1 -0
- package/dist/CeilingBox/index.css +25 -0
- package/dist/CeilingBox/index.css.map +1 -0
- package/dist/CeilingBox/index.d.ts +28 -0
- package/dist/CeilingBox/index.js +3 -0
- package/dist/CeilingBox/index.js.map +1 -0
- package/dist/LazyLoadBox/index.cjs +18 -0
- package/dist/LazyLoadBox/index.cjs.map +1 -0
- package/dist/LazyLoadBox/index.css +57 -0
- package/dist/LazyLoadBox/index.css.map +1 -0
- package/dist/LazyLoadBox/index.d.ts +104 -0
- package/dist/LazyLoadBox/index.js +3 -0
- package/dist/LazyLoadBox/index.js.map +1 -0
- package/dist/PeriodSelect/index.cjs +22 -0
- package/dist/PeriodSelect/index.cjs.map +1 -0
- package/dist/PeriodSelect/index.css +88 -0
- package/dist/PeriodSelect/index.css.map +1 -0
- package/dist/PeriodSelect/index.d.ts +36 -0
- package/dist/PeriodSelect/index.js +3 -0
- package/dist/PeriodSelect/index.js.map +1 -0
- package/dist/chunk-5Q7THN6M.js +115 -0
- package/dist/chunk-5Q7THN6M.js.map +1 -0
- package/dist/chunk-O4EABET3.js +89 -0
- package/dist/chunk-O4EABET3.js.map +1 -0
- package/dist/chunk-QU33CY3M.cjs +83 -0
- package/dist/chunk-QU33CY3M.cjs.map +1 -0
- package/dist/chunk-RFTYEXKU.js +79 -0
- package/dist/chunk-RFTYEXKU.js.map +1 -0
- package/dist/chunk-UIU6VCEQ.cjs +117 -0
- package/dist/chunk-UIU6VCEQ.cjs.map +1 -0
- package/dist/chunk-V55FEQYU.cjs +196 -0
- package/dist/chunk-V55FEQYU.cjs.map +1 -0
- package/dist/chunk-VYPIRVL4.js +193 -0
- package/dist/chunk-VYPIRVL4.js.map +1 -0
- package/dist/chunk-ZXMFWVE4.cjs +91 -0
- package/dist/chunk-ZXMFWVE4.cjs.map +1 -0
- package/dist/index.cjs +91 -72
- package/dist/index.css +272 -11
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -15
- package/dist/src/index.d.ts +7 -1
- package/package.json +3 -2
- package/dist/chunk-5YQVSOHK.js +0 -44
- package/dist/chunk-5YQVSOHK.js.map +0 -1
- package/dist/chunk-B3HZIYQQ.cjs +0 -46
- package/dist/chunk-B3HZIYQQ.cjs.map +0 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import './index.less';
|
|
3
|
+
export interface PeriodSelectOption<T = string | number> {
|
|
4
|
+
/** 选项展示内容 */
|
|
5
|
+
label: ReactNode;
|
|
6
|
+
/** 选项值 */
|
|
7
|
+
value: T;
|
|
8
|
+
/** 是否禁用当前选项 */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type PeriodSelectSize = 'small' | 'middle' | 'large';
|
|
12
|
+
export interface PeriodSelectProps<T = string | number> {
|
|
13
|
+
/** 选项列表,默认提供【周度、月度、季度、年度】 */
|
|
14
|
+
options?: PeriodSelectOption<T>[];
|
|
15
|
+
/** 当前选中值(受控模式) */
|
|
16
|
+
value?: T;
|
|
17
|
+
/** 默认选中值(非受控模式) */
|
|
18
|
+
defaultValue?: T;
|
|
19
|
+
/** 切换选项时的回调函数 */
|
|
20
|
+
onChange?: (value: T, option: PeriodSelectOption<T>) => void;
|
|
21
|
+
/** 尺寸大小,默认为 'middle' */
|
|
22
|
+
size?: PeriodSelectSize;
|
|
23
|
+
/** 自定义高亮激活颜色(文字与高亮竖线) */
|
|
24
|
+
activeColor?: string;
|
|
25
|
+
/** 是否整体禁用 */
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/** 是否等宽撑满父容器 */
|
|
28
|
+
block?: boolean;
|
|
29
|
+
/** 自定义容器类名 */
|
|
30
|
+
className?: string;
|
|
31
|
+
/** 自定义容器样式 */
|
|
32
|
+
style?: CSSProperties;
|
|
33
|
+
}
|
|
34
|
+
export declare const DEFAULT_PERIOD_OPTIONS: PeriodSelectOption<string>[];
|
|
35
|
+
export declare function PeriodSelect<T = string | number>({ options, value: controlledValue, defaultValue, onChange, size, activeColor, disabled, block, className, style, }: PeriodSelectProps<T>): React.JSX.Element;
|
|
36
|
+
export default PeriodSelect;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// CeilingBox/index.tsx
|
|
5
|
+
var CeilingBox = ({
|
|
6
|
+
children,
|
|
7
|
+
offsetTop = 0,
|
|
8
|
+
offsetBottom,
|
|
9
|
+
target,
|
|
10
|
+
onChange,
|
|
11
|
+
blur = true,
|
|
12
|
+
zIndex = 1e3,
|
|
13
|
+
className = "",
|
|
14
|
+
style,
|
|
15
|
+
affixedClassName = "",
|
|
16
|
+
affixedStyle
|
|
17
|
+
}) => {
|
|
18
|
+
const [isAffixed, setIsAffixed] = useState(false);
|
|
19
|
+
const [boxRect, setBoxRect] = useState({ width: 0, height: 0 });
|
|
20
|
+
const placeholderRef = useRef(null);
|
|
21
|
+
const contentRef = useRef(null);
|
|
22
|
+
const isAffixedRef = useRef(false);
|
|
23
|
+
isAffixedRef.current = isAffixed;
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const getTargetElement = () => {
|
|
26
|
+
if (target) {
|
|
27
|
+
const el = target();
|
|
28
|
+
if (el) return el;
|
|
29
|
+
}
|
|
30
|
+
return window;
|
|
31
|
+
};
|
|
32
|
+
const handleScroll = () => {
|
|
33
|
+
if (!placeholderRef.current) return;
|
|
34
|
+
const targetEl = getTargetElement();
|
|
35
|
+
const placeholderRect = placeholderRef.current.getBoundingClientRect();
|
|
36
|
+
let targetTop = 0;
|
|
37
|
+
let targetBottom = window.innerHeight;
|
|
38
|
+
if (targetEl !== window && targetEl instanceof HTMLElement) {
|
|
39
|
+
const containerRect = targetEl.getBoundingClientRect();
|
|
40
|
+
targetTop = containerRect.top;
|
|
41
|
+
targetBottom = containerRect.bottom;
|
|
42
|
+
}
|
|
43
|
+
let shouldAffix = false;
|
|
44
|
+
if (offsetBottom !== void 0) {
|
|
45
|
+
shouldAffix = placeholderRect.bottom >= targetBottom - offsetBottom;
|
|
46
|
+
} else {
|
|
47
|
+
shouldAffix = placeholderRect.top <= targetTop + offsetTop;
|
|
48
|
+
}
|
|
49
|
+
if (shouldAffix !== isAffixedRef.current) {
|
|
50
|
+
if (shouldAffix && contentRef.current) {
|
|
51
|
+
const rect = contentRef.current.getBoundingClientRect();
|
|
52
|
+
setBoxRect({ width: rect.width, height: rect.height });
|
|
53
|
+
}
|
|
54
|
+
setIsAffixed(shouldAffix);
|
|
55
|
+
onChange == null ? void 0 : onChange(shouldAffix);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const targetNode = getTargetElement();
|
|
59
|
+
targetNode.addEventListener("scroll", handleScroll, { passive: true });
|
|
60
|
+
window.addEventListener("resize", handleScroll, { passive: true });
|
|
61
|
+
handleScroll();
|
|
62
|
+
return () => {
|
|
63
|
+
targetNode.removeEventListener("scroll", handleScroll);
|
|
64
|
+
window.removeEventListener("resize", handleScroll);
|
|
65
|
+
};
|
|
66
|
+
}, [offsetTop, offsetBottom, target, onChange]);
|
|
67
|
+
const computeFixedStyle = () => {
|
|
68
|
+
if (!isAffixed) return {};
|
|
69
|
+
const fixedStyle = {
|
|
70
|
+
position: "fixed",
|
|
71
|
+
zIndex,
|
|
72
|
+
width: boxRect.width ? `${boxRect.width}px` : "100%",
|
|
73
|
+
boxSizing: "border-box"
|
|
74
|
+
};
|
|
75
|
+
if (offsetBottom !== void 0) {
|
|
76
|
+
fixedStyle.bottom = `${offsetBottom}px`;
|
|
77
|
+
} else {
|
|
78
|
+
fixedStyle.top = `${offsetTop}px`;
|
|
79
|
+
}
|
|
80
|
+
if (placeholderRef.current) {
|
|
81
|
+
const rect = placeholderRef.current.getBoundingClientRect();
|
|
82
|
+
fixedStyle.left = `${rect.left}px`;
|
|
83
|
+
}
|
|
84
|
+
return fixedStyle;
|
|
85
|
+
};
|
|
86
|
+
const renderedContent = typeof children === "function" ? children(isAffixed) : children;
|
|
87
|
+
return /* @__PURE__ */ jsx(
|
|
88
|
+
"div",
|
|
89
|
+
{
|
|
90
|
+
ref: placeholderRef,
|
|
91
|
+
className: `rpc_ceiling_box_wrapper ${className}`,
|
|
92
|
+
style: {
|
|
93
|
+
...style,
|
|
94
|
+
height: isAffixed && boxRect.height ? `${boxRect.height}px` : void 0
|
|
95
|
+
},
|
|
96
|
+
children: /* @__PURE__ */ jsx(
|
|
97
|
+
"div",
|
|
98
|
+
{
|
|
99
|
+
ref: contentRef,
|
|
100
|
+
className: `rpc_ceiling_box ${isAffixed ? "rpc_ceiling_box_affixed" : ""} ${isAffixed && blur ? "rpc_ceiling_box_blur" : ""} ${isAffixed ? affixedClassName : ""}`,
|
|
101
|
+
style: {
|
|
102
|
+
...computeFixedStyle(),
|
|
103
|
+
...isAffixed ? affixedStyle : {}
|
|
104
|
+
},
|
|
105
|
+
children: renderedContent
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
var CeilingBox_default = CeilingBox;
|
|
112
|
+
|
|
113
|
+
export { CeilingBox_default };
|
|
114
|
+
//# sourceMappingURL=chunk-5Q7THN6M.js.map
|
|
115
|
+
//# sourceMappingURL=chunk-5Q7THN6M.js.map
|
|
@@ -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AAA,EAAA,CAAA,GAAO;AAAA,OAC/D;AAAA,MAEA,QAAA,kBAAA,GAAA;AAAA,QAAC,KAAA;AAAA,QAAA;AAAA,UACA,GAAA,EAAK,UAAA;AAAA,UACL,SAAA,EAAW,CAAA,gBAAA,EACV,SAAA,GAAY,yBAAA,GAA4B,EACzC,CAAA,CAAA,EAAI,SAAA,IAAa,IAAA,GAAO,sBAAA,GAAyB,EAAE,CAAA,CAAA,EAClD,SAAA,GAAY,mBAAmB,EAChC,CAAA,CAAA;AAAA,UACA,KAAA,EAAO;AAAA,YACN,GAAG,iBAAA,EAAkB;AAAA,YACrB,GAAI,SAAA,GAAY,YAAA,GAAe;AAAC,WACjC;AAAA,UAEC,QAAA,EAAA;AAAA;AAAA;AACF;AAAA,GACD;AAEF,CAAA;AAEA,IAAO,kBAAA,GAAQ","file":"chunk-5Q7THN6M.js","sourcesContent":["import React, {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tReactNode,\n\tCSSProperties,\n} from 'react';\nimport './index.less';\n\nexport interface CeilingBoxProps {\n\t/** 子元素内容,支持普通 ReactNode 或 Render Props 函数接收 isAffixed 状态 */\n\tchildren: ReactNode | ((isAffixed: boolean) => ReactNode);\n\t/** 距离视口/容器顶部的吸顶偏移距离(像素),默认为 0 */\n\toffsetTop?: number;\n\t/** 距离视口/容器底部的吸底偏移距离(像素,传值时开启吸底模式) */\n\toffsetBottom?: number;\n\t/** 监听滚动的目标 DOM 容器,不传时默认监听 window 全局滚动 */\n\ttarget?: () => HTMLElement | Window | null;\n\t/** 吸顶/吸底状态改变时的回调函数 */\n\tonChange?: (isAffixed: boolean) => void;\n\t/** 吸顶时是否自动启用毛玻璃磨砂与精致阴影滤镜,默认为 true */\n\tblur?: boolean;\n\t/** 吸顶/吸底状态下的图层层级 z-index,默认为 1000 */\n\tzIndex?: number;\n\t/** 自定义类名 */\n\tclassName?: string;\n\t/** 自定义行内样式 */\n\tstyle?: CSSProperties;\n\t/** 吸顶激活状态下追加的自定义类名 */\n\taffixedClassName?: string;\n\t/** 吸顶激活状态下追加的自定义行内样式 */\n\taffixedStyle?: CSSProperties;\n}\n\nconst CeilingBox: React.FC<CeilingBoxProps> = ({\n\tchildren,\n\toffsetTop = 0,\n\toffsetBottom,\n\ttarget,\n\tonChange,\n\tblur = true,\n\tzIndex = 1000,\n\tclassName = '',\n\tstyle,\n\taffixedClassName = '',\n\taffixedStyle,\n}) => {\n\tconst [isAffixed, setIsAffixed] = useState<boolean>(false);\n\tconst [boxRect, setBoxRect] = useState<{ width: number; height: number }>({ width: 0, height: 0 });\n\n\tconst placeholderRef = useRef<HTMLDivElement>(null);\n\tconst contentRef = useRef<HTMLDivElement>(null);\n\tconst isAffixedRef = useRef<boolean>(false);\n\n\tisAffixedRef.current = isAffixed;\n\n\tuseEffect(() => {\n\t\tconst getTargetElement = (): HTMLElement | Window => {\n\t\t\tif (target) {\n\t\t\t\tconst el = target();\n\t\t\t\tif (el) return el;\n\t\t\t}\n\t\t\treturn window;\n\t\t};\n\n\t\tconst handleScroll = () => {\n\t\t\tif (!placeholderRef.current) return;\n\n\t\t\tconst targetEl = getTargetElement();\n\t\t\tconst placeholderRect = placeholderRef.current.getBoundingClientRect();\n\n\t\t\tlet targetTop = 0;\n\t\t\tlet targetBottom = window.innerHeight;\n\n\t\t\tif (targetEl !== window && targetEl instanceof HTMLElement) {\n\t\t\t\tconst containerRect = targetEl.getBoundingClientRect();\n\t\t\t\ttargetTop = containerRect.top;\n\t\t\t\ttargetBottom = containerRect.bottom;\n\t\t\t}\n\n\t\t\tlet shouldAffix = false;\n\n\t\t\tif (offsetBottom !== undefined) {\n\t\t\t\t// 吸底模式\n\t\t\t\tshouldAffix = placeholderRect.bottom >= targetBottom - offsetBottom;\n\t\t\t} else {\n\t\t\t\t// 吸顶模式 (默认)\n\t\t\t\tshouldAffix = placeholderRect.top <= targetTop + offsetTop;\n\t\t\t}\n\n\t\t\tif (shouldAffix !== isAffixedRef.current) {\n\t\t\t\t// 触发吸顶切换前记录原本的宽高\n\t\t\t\tif (shouldAffix && contentRef.current) {\n\t\t\t\t\tconst rect = contentRef.current.getBoundingClientRect();\n\t\t\t\t\tsetBoxRect({ width: rect.width, height: rect.height });\n\t\t\t\t}\n\n\t\t\t\tsetIsAffixed(shouldAffix);\n\t\t\t\tonChange?.(shouldAffix);\n\t\t\t}\n\t\t};\n\n\t\tconst targetNode = getTargetElement();\n\t\ttargetNode.addEventListener('scroll', handleScroll, { passive: true });\n\t\twindow.addEventListener('resize', handleScroll, { passive: true });\n\n\t\t// 初始检查一次\n\t\thandleScroll();\n\n\t\treturn () => {\n\t\t\ttargetNode.removeEventListener('scroll', handleScroll);\n\t\t\twindow.removeEventListener('resize', handleScroll);\n\t\t};\n\t}, [offsetTop, offsetBottom, target, onChange]);\n\n\t// 计算吸顶定位样式\n\tconst computeFixedStyle = (): CSSProperties => {\n\t\tif (!isAffixed) return {};\n\n\t\tconst fixedStyle: CSSProperties = {\n\t\t\tposition: 'fixed',\n\t\t\tzIndex,\n\t\t\twidth: boxRect.width ? `${boxRect.width}px` : '100%',\n\t\t\tboxSizing: 'border-box',\n\t\t};\n\n\t\tif (offsetBottom !== undefined) {\n\t\t\tfixedStyle.bottom = `${offsetBottom}px`;\n\t\t} else {\n\t\t\tfixedStyle.top = `${offsetTop}px`;\n\t\t}\n\n\t\tif (placeholderRef.current) {\n\t\t\tconst rect = placeholderRef.current.getBoundingClientRect();\n\t\t\tfixedStyle.left = `${rect.left}px`;\n\t\t}\n\n\t\treturn fixedStyle;\n\t};\n\n\tconst renderedContent =\n\t\ttypeof children === 'function' ? children(isAffixed) : children;\n\n\treturn (\n\t\t<div\n\t\t\tref={placeholderRef}\n\t\t\tclassName={`rpc_ceiling_box_wrapper ${className}`}\n\t\t\tstyle={{\n\t\t\t\t...style,\n\t\t\t\theight: isAffixed && boxRect.height ? `${boxRect.height}px` : undefined,\n\t\t\t}}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={contentRef}\n\t\t\t\tclassName={`rpc_ceiling_box ${\n\t\t\t\t\tisAffixed ? 'rpc_ceiling_box_affixed' : ''\n\t\t\t\t} ${isAffixed && blur ? 'rpc_ceiling_box_blur' : ''} ${\n\t\t\t\t\tisAffixed ? affixedClassName : ''\n\t\t\t\t}`}\n\t\t\t\tstyle={{\n\t\t\t\t\t...computeFixedStyle(),\n\t\t\t\t\t...(isAffixed ? affixedStyle : {}),\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{renderedContent}\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n\nexport default CeilingBox;\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { CloseOutlined } from './chunk-2IDVNTKR.js';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
var AnnouncementBar = ({
|
|
6
|
+
children,
|
|
7
|
+
type = "primary",
|
|
8
|
+
background,
|
|
9
|
+
color,
|
|
10
|
+
sticky = false,
|
|
11
|
+
fixed = false,
|
|
12
|
+
top = 0,
|
|
13
|
+
zIndex = 1e3,
|
|
14
|
+
closable = true,
|
|
15
|
+
closeIcon,
|
|
16
|
+
storageKey,
|
|
17
|
+
marquee = false,
|
|
18
|
+
onClose,
|
|
19
|
+
className = "",
|
|
20
|
+
style
|
|
21
|
+
}) => {
|
|
22
|
+
const [visible, setVisible] = useState(() => {
|
|
23
|
+
if (typeof window !== "undefined" && storageKey) {
|
|
24
|
+
try {
|
|
25
|
+
return localStorage.getItem(`rpc_announcement_${storageKey}`) !== "closed";
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
});
|
|
32
|
+
const [isClosing, setIsClosing] = useState(false);
|
|
33
|
+
if (!visible) return null;
|
|
34
|
+
const handleClose = () => {
|
|
35
|
+
setIsClosing(true);
|
|
36
|
+
if (storageKey && typeof window !== "undefined") {
|
|
37
|
+
try {
|
|
38
|
+
localStorage.setItem(`rpc_announcement_${storageKey}`, "closed");
|
|
39
|
+
} catch (e) {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
setVisible(false);
|
|
44
|
+
onClose == null ? void 0 : onClose();
|
|
45
|
+
}, 250);
|
|
46
|
+
};
|
|
47
|
+
const positionStyle = {};
|
|
48
|
+
if (fixed) {
|
|
49
|
+
positionStyle.position = "fixed";
|
|
50
|
+
positionStyle.top = top;
|
|
51
|
+
positionStyle.left = 0;
|
|
52
|
+
positionStyle.right = 0;
|
|
53
|
+
positionStyle.zIndex = zIndex;
|
|
54
|
+
} else if (sticky) {
|
|
55
|
+
positionStyle.position = "sticky";
|
|
56
|
+
positionStyle.top = top;
|
|
57
|
+
positionStyle.zIndex = zIndex;
|
|
58
|
+
}
|
|
59
|
+
return /* @__PURE__ */ jsxs(
|
|
60
|
+
"div",
|
|
61
|
+
{
|
|
62
|
+
className: `rpc_announcement_bar rpc_announcement_bar_${type} ${sticky ? "rpc_announcement_bar_sticky" : ""} ${fixed ? "rpc_announcement_bar_fixed" : ""} ${isClosing ? "rpc_announcement_bar_closing" : ""} ${className}`,
|
|
63
|
+
style: {
|
|
64
|
+
background: background || void 0,
|
|
65
|
+
color: color || void 0,
|
|
66
|
+
...positionStyle,
|
|
67
|
+
...style
|
|
68
|
+
},
|
|
69
|
+
children: [
|
|
70
|
+
/* @__PURE__ */ jsx("div", { className: "rpc_announcement_bar_body", children: /* @__PURE__ */ jsx("div", { className: `rpc_announcement_bar_content ${marquee ? "rpc_announcement_bar_marquee" : ""}`, children }) }),
|
|
71
|
+
closable && /* @__PURE__ */ jsx(
|
|
72
|
+
"button",
|
|
73
|
+
{
|
|
74
|
+
type: "button",
|
|
75
|
+
className: "rpc_announcement_bar_close",
|
|
76
|
+
onClick: handleClose,
|
|
77
|
+
title: "\u5173\u95ED\u901A\u77E5",
|
|
78
|
+
children: closeIcon || /* @__PURE__ */ jsx(CloseOutlined, { style: { fontSize: 13 } })
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
var AnnouncementBar_default = AnnouncementBar;
|
|
86
|
+
|
|
87
|
+
export { AnnouncementBar_default };
|
|
88
|
+
//# sourceMappingURL=chunk-O4EABET3.js.map
|
|
89
|
+
//# sourceMappingURL=chunk-O4EABET3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../AnnouncementBar/index.tsx"],"names":[],"mappings":";;;;AAuCA,IAAM,kBAAkD,CAAC;AAAA,EACxD,QAAA;AAAA,EACA,IAAA,GAAO,SAAA;AAAA,EACP,UAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA,GAAS,KAAA;AAAA,EACT,KAAA,GAAQ,KAAA;AAAA,EACR,GAAA,GAAM,CAAA;AAAA,EACN,MAAA,GAAS,GAAA;AAAA,EACT,QAAA,GAAW,IAAA;AAAA,EACX,SAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA,GAAU,KAAA;AAAA,EACV,OAAA;AAAA,EACA,SAAA,GAAY,EAAA;AAAA,EACZ;AACD,CAAA,KAAM;AACL,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAkB,MAAM;AACrD,IAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,UAAA,EAAY;AAChD,MAAA,IAAI;AACH,QAAA,OAAO,YAAA,CAAa,OAAA,CAAQ,CAAA,iBAAA,EAAoB,UAAU,EAAE,CAAA,KAAM,QAAA;AAAA,MACnE,CAAA,CAAA,OAAQ,CAAA,EAAA;AACP,QAAA,OAAO,IAAA;AAAA,MACR;AAAA,IACD;AACA,IAAA,OAAO,IAAA;AAAA,EACR,CAAC,CAAA;AAED,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAkB,KAAK,CAAA;AAEzD,EAAA,IAAI,CAAC,SAAS,OAA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N,YAAY,UAAA,IAAc,MAAA;AAAA,QAC1B,OAAO,KAAA,IAAS,MAAA;AAAA,QAChB,GAAG,aAAA;AAAA,QACH,GAAG;AAAA,OACJ;AAAA,MAEA,QAAA,EAAA;AAAA,wBAAA,GAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,2BAAA,EACd,QAAA,kBAAA,GAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAW,CAAA,6BAAA,EAAgC,OAAA,GAAU,8BAAA,GAAiC,EAAE,CAAA,CAAA,EAC3F,QAAA,EACF,CAAA,EACD,CAAA;AAAA,QAEC,QAAA,oBACA,GAAA;AAAA,UAAC,QAAA;AAAA,UAAA;AAAA,YACA,IAAA,EAAK,QAAA;AAAA,YACL,SAAA,EAAU,4BAAA;AAAA,YACV,OAAA,EAAS,WAAA;AAAA,YACT,KAAA,EAAM,0BAAA;AAAA,YAEL,uCAAa,GAAA,CAAC,aAAA,EAAA,EAAc,OAAO,EAAE,QAAA,EAAU,IAAG,EAAG;AAAA;AAAA;AACvD;AAAA;AAAA,GAEF;AAEF,CAAA;AAEA,IAAO,uBAAA,GAAQ","file":"chunk-O4EABET3.js","sourcesContent":["import React, { useState, useEffect, ReactNode, CSSProperties } from 'react';\nimport { CloseOutlined } from '../src/icons';\nimport './index.less';\n\nexport type AnnouncementType = 'primary' | 'warning' | 'success' | 'danger' | 'purple';\n\nexport interface AnnouncementBarProps {\n\t/** 横幅广播内容 */\n\tchildren: ReactNode;\n\t/** 预设主题色系:'primary' | 'warning' | 'success' | 'danger' | 'purple' */\n\ttype?: AnnouncementType;\n\t/** 自定义渐变或背景样式(传值时覆盖 type 预设) */\n\tbackground?: string;\n\t/** 自定义文字颜色 */\n\tcolor?: string;\n\t/** 是否开启智能吸顶 (position: sticky),默认为 false */\n\tsticky?: boolean;\n\t/** 是否开启固定吸顶 (position: fixed),默认为 false */\n\tfixed?: boolean;\n\t/** 吸顶时距离顶部的距离偏移(像素或 CSS 字符串),默认为 0 */\n\ttop?: number | string;\n\t/** 图层层级 z-index,默认为 1000 */\n\tzIndex?: number;\n\t/** 是否支持点击关闭,默认为 true */\n\tclosable?: boolean;\n\t/** 自定义关闭图标 */\n\tcloseIcon?: ReactNode;\n\t/** LocalStorage 记忆 Key(若传入则关闭后自动持久化记忆,不再重复弹出) */\n\tstorageKey?: string;\n\t/** 内容过长时是否开启跑马灯无缝水平滚动,默认为 false */\n\tmarquee?: boolean;\n\t/** 关闭时的回调函数 */\n\tonClose?: () => void;\n\t/** 自定义类名 */\n\tclassName?: string;\n\t/** 自定义样式 */\n\tstyle?: CSSProperties;\n}\n\nconst AnnouncementBar: React.FC<AnnouncementBarProps> = ({\n\tchildren,\n\ttype = 'primary',\n\tbackground,\n\tcolor,\n\tsticky = false,\n\tfixed = false,\n\ttop = 0,\n\tzIndex = 1000,\n\tclosable = true,\n\tcloseIcon,\n\tstorageKey,\n\tmarquee = false,\n\tonClose,\n\tclassName = '',\n\tstyle,\n}) => {\n\tconst [visible, setVisible] = useState<boolean>(() => {\n\t\tif (typeof window !== 'undefined' && storageKey) {\n\t\t\ttry {\n\t\t\t\treturn localStorage.getItem(`rpc_announcement_${storageKey}`) !== 'closed';\n\t\t\t} catch {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t});\n\n\tconst [isClosing, setIsClosing] = useState<boolean>(false);\n\n\tif (!visible) return null;\n\n\tconst handleClose = () => {\n\t\tsetIsClosing(true);\n\n\t\tif (storageKey && typeof window !== 'undefined') {\n\t\t\ttry {\n\t\t\t\tlocalStorage.setItem(`rpc_announcement_${storageKey}`, 'closed');\n\t\t\t} catch {\n\t\t\t\t// ignore\n\t\t\t}\n\t\t}\n\n\t\tsetTimeout(() => {\n\t\t\tsetVisible(false);\n\t\t\tonClose?.();\n\t\t}, 250);\n\t};\n\n\tconst positionStyle: CSSProperties = {};\n\tif (fixed) {\n\t\tpositionStyle.position = 'fixed';\n\t\tpositionStyle.top = top;\n\t\tpositionStyle.left = 0;\n\t\tpositionStyle.right = 0;\n\t\tpositionStyle.zIndex = zIndex;\n\t} else if (sticky) {\n\t\tpositionStyle.position = 'sticky';\n\t\tpositionStyle.top = top;\n\t\tpositionStyle.zIndex = zIndex;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName={`rpc_announcement_bar rpc_announcement_bar_${type} ${\n\t\t\t\tsticky ? 'rpc_announcement_bar_sticky' : ''\n\t\t\t} ${fixed ? 'rpc_announcement_bar_fixed' : ''} ${\n\t\t\t\tisClosing ? 'rpc_announcement_bar_closing' : ''\n\t\t\t} ${className}`}\n\t\t\tstyle={{\n\t\t\t\tbackground: background || undefined,\n\t\t\t\tcolor: color || undefined,\n\t\t\t\t...positionStyle,\n\t\t\t\t...style,\n\t\t\t}}\n\t\t>\n\t\t\t<div className=\"rpc_announcement_bar_body\">\n\t\t\t\t<div className={`rpc_announcement_bar_content ${marquee ? 'rpc_announcement_bar_marquee' : ''}`}>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t{closable && (\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tclassName=\"rpc_announcement_bar_close\"\n\t\t\t\t\tonClick={handleClose}\n\t\t\t\t\ttitle=\"关闭通知\"\n\t\t\t\t>\n\t\t\t\t\t{closeIcon || <CloseOutlined style={{ fontSize: 13 }} />}\n\t\t\t\t</button>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n\nexport default AnnouncementBar;\n"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
// PeriodSelect/index.tsx
|
|
7
|
+
var DEFAULT_PERIOD_OPTIONS = [
|
|
8
|
+
{ label: "\u5468\u5EA6", value: "week" },
|
|
9
|
+
{ label: "\u6708\u5EA6", value: "month" },
|
|
10
|
+
{ label: "\u5B63\u5EA6", value: "quarter" },
|
|
11
|
+
{ label: "\u5E74\u5EA6", value: "year" }
|
|
12
|
+
];
|
|
13
|
+
function PeriodSelect({
|
|
14
|
+
options = DEFAULT_PERIOD_OPTIONS,
|
|
15
|
+
value: controlledValue,
|
|
16
|
+
defaultValue,
|
|
17
|
+
onChange,
|
|
18
|
+
size = "middle",
|
|
19
|
+
activeColor,
|
|
20
|
+
disabled = false,
|
|
21
|
+
block = false,
|
|
22
|
+
className = "",
|
|
23
|
+
style
|
|
24
|
+
}) {
|
|
25
|
+
var _a;
|
|
26
|
+
const initialValue = defaultValue !== void 0 ? defaultValue : (_a = options[0]) == null ? void 0 : _a.value;
|
|
27
|
+
const [internalValue, setInternalValue] = react.useState(initialValue);
|
|
28
|
+
const currentValue = controlledValue !== void 0 ? controlledValue : internalValue;
|
|
29
|
+
const handleSelect = (item) => {
|
|
30
|
+
if (disabled || item.disabled) return;
|
|
31
|
+
if (controlledValue === void 0) {
|
|
32
|
+
setInternalValue(item.value);
|
|
33
|
+
}
|
|
34
|
+
onChange == null ? void 0 : onChange(item.value, item);
|
|
35
|
+
};
|
|
36
|
+
const containerClass = [
|
|
37
|
+
"rpc_period_select",
|
|
38
|
+
`rpc_period_select_${size}`,
|
|
39
|
+
disabled ? "rpc_period_select_disabled" : "",
|
|
40
|
+
block ? "rpc_period_select_block" : "",
|
|
41
|
+
className
|
|
42
|
+
].filter(Boolean).join(" ");
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
"div",
|
|
45
|
+
{
|
|
46
|
+
className: containerClass,
|
|
47
|
+
style: {
|
|
48
|
+
...style,
|
|
49
|
+
...activeColor ? { "--rpc-period-active-color": activeColor } : {}
|
|
50
|
+
},
|
|
51
|
+
children: options.map((item, index) => {
|
|
52
|
+
const isActive = currentValue === item.value;
|
|
53
|
+
const isItemDisabled = disabled || Boolean(item.disabled);
|
|
54
|
+
const showActiveLine = isActive && index > 0;
|
|
55
|
+
const itemClass = [
|
|
56
|
+
"rpc_period_select_item",
|
|
57
|
+
isActive ? "rpc_period_select_item_active" : "",
|
|
58
|
+
showActiveLine ? "rpc_period_select_item_has_active_line" : "",
|
|
59
|
+
isItemDisabled ? "rpc_period_select_item_disabled" : ""
|
|
60
|
+
].filter(Boolean).join(" ");
|
|
61
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
62
|
+
"div",
|
|
63
|
+
{
|
|
64
|
+
className: itemClass,
|
|
65
|
+
onClick: () => handleSelect(item),
|
|
66
|
+
children: [
|
|
67
|
+
showActiveLine && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rpc_period_select_active_line" }),
|
|
68
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "rpc_period_select_text", children: item.label })
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
String(item.value)
|
|
72
|
+
);
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
var PeriodSelect_default = PeriodSelect;
|
|
78
|
+
|
|
79
|
+
exports.DEFAULT_PERIOD_OPTIONS = DEFAULT_PERIOD_OPTIONS;
|
|
80
|
+
exports.PeriodSelect = PeriodSelect;
|
|
81
|
+
exports.PeriodSelect_default = PeriodSelect_default;
|
|
82
|
+
//# sourceMappingURL=chunk-QU33CY3M.cjs.map
|
|
83
|
+
//# sourceMappingURL=chunk-QU33CY3M.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../PeriodSelect/index.tsx"],"names":["useState","jsx","jsxs"],"mappings":";;;;;;AAsCO,IAAM,sBAAA,GAAuD;AAAA,EACnE,EAAE,KAAA,EAAO,cAAA,EAAM,KAAA,EAAO,MAAA,EAAO;AAAA,EAC7B,EAAE,KAAA,EAAO,cAAA,EAAM,KAAA,EAAO,OAAA,EAAQ;AAAA,EAC9B,EAAE,KAAA,EAAO,cAAA,EAAM,KAAA,EAAO,SAAA,EAAU;AAAA,EAChC,EAAE,KAAA,EAAO,cAA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AA,MACA,SAAA,EAAW,cAAA;AAAA,MACX,KAAA,EACC;AAAA,QACC,GAAG,KAAA;AAAA,QACH,GAAI,WAAA,GAAc,EAAE,2BAAA,EAA6B,WAAA,KAAgB;AAAC,OACnE;AAAA,MAGA,QAAA,EAAA,OAAA,CAAQ,GAAA,CAAI,CAAC,IAAA,EAAM,KAAA,KAAU;AAC7B,QAAA,MAAM,QAAA,GAAW,iBAAiB,IAAA,CAAK,KAAA;AACvC,QAAA,MAAM,cAAA,GAAiB,QAAA,IAAY,OAAA,CAAQ,IAAA,CAAK,QAAQ,CAAA;AAIxD,QAAA,MAAM,cAAA,GAAiB,YAAY,KAAA,GAAQ,CAAA;AAE3C,QAAA,MAAM,SAAA,GAAY;AAAA,UACjB,wBAAA;AAAA,UACA,WAAW,+BAAA,GAAkC,EAAA;AAAA,UAC7C,iBAAiB,wCAAA,GAA2C,EAAA;AAAA,UAC5D,iBAAiB,iCAAA,GAAoC;AAAA,SACtD,CACE,MAAA,CAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AAEV,QAAA,uBACCC,eAAA;AAAA,UAAC,KAAA;AAAA,UAAA;AAAA,YAEA,SAAA,EAAW,SAAA;AAAA,YACX,OAAA,EAAS,MAAM,YAAA,CAAa,IAAI,CAAA;AAAA,YAE/B,QAAA,EAAA;AAAA,cAAA,cAAA,oBAAkBD,cAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,+BAAA,EAAgC,CAAA;AAAA,8BACnEA,cAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,wBAAA,EAA0B,eAAK,KAAA,EAAM;AAAA;AAAA,WAAA;AAAA,UALhD,MAAA,CAAO,KAAK,KAAK;AAAA,SAMvB;AAAA,MAEF,CAAC;AAAA;AAAA,GACF;AAEF;AAEA,IAAO,oBAAA,GAAQ","file":"chunk-QU33CY3M.cjs","sourcesContent":["import React, { useState, CSSProperties, ReactNode } from 'react';\nimport './index.less';\n\nexport interface PeriodSelectOption<T = string | number> {\n\t/** 选项展示内容 */\n\tlabel: ReactNode;\n\t/** 选项值 */\n\tvalue: T;\n\t/** 是否禁用当前选项 */\n\tdisabled?: boolean;\n}\n\nexport type PeriodSelectSize = 'small' | 'middle' | 'large';\n\nexport interface PeriodSelectProps<T = string | number> {\n\t/** 选项列表,默认提供【周度、月度、季度、年度】 */\n\toptions?: PeriodSelectOption<T>[];\n\t/** 当前选中值(受控模式) */\n\tvalue?: T;\n\t/** 默认选中值(非受控模式) */\n\tdefaultValue?: T;\n\t/** 切换选项时的回调函数 */\n\tonChange?: (value: T, option: PeriodSelectOption<T>) => void;\n\t/** 尺寸大小,默认为 'middle' */\n\tsize?: PeriodSelectSize;\n\t/** 自定义高亮激活颜色(文字与高亮竖线) */\n\tactiveColor?: string;\n\t/** 是否整体禁用 */\n\tdisabled?: boolean;\n\t/** 是否等宽撑满父容器 */\n\tblock?: boolean;\n\t/** 自定义容器类名 */\n\tclassName?: string;\n\t/** 自定义容器样式 */\n\tstyle?: CSSProperties;\n}\n\n// 默认内置的周期选项(精准匹配周度、月度、季度、年度)\nexport const DEFAULT_PERIOD_OPTIONS: PeriodSelectOption<string>[] = [\n\t{ label: '周度', value: 'week' },\n\t{ label: '月度', value: 'month' },\n\t{ label: '季度', value: 'quarter' },\n\t{ label: '年度', value: 'year' },\n];\n\nexport function PeriodSelect<T = string | number>({\n\toptions = DEFAULT_PERIOD_OPTIONS as unknown as PeriodSelectOption<T>[],\n\tvalue: controlledValue,\n\tdefaultValue,\n\tonChange,\n\tsize = 'middle',\n\tactiveColor,\n\tdisabled = false,\n\tblock = false,\n\tclassName = '',\n\tstyle,\n}: PeriodSelectProps<T>) {\n\tconst initialValue =\n\t\tdefaultValue !== undefined ? defaultValue : (options[0]?.value as T);\n\tconst [internalValue, setInternalValue] = useState<T>(initialValue);\n\n\tconst currentValue =\n\t\tcontrolledValue !== undefined ? controlledValue : internalValue;\n\n\tconst handleSelect = (item: PeriodSelectOption<T>) => {\n\t\tif (disabled || item.disabled) return;\n\t\tif (controlledValue === undefined) {\n\t\t\tsetInternalValue(item.value);\n\t\t}\n\t\tonChange?.(item.value, item);\n\t};\n\n\tconst containerClass = [\n\t\t'rpc_period_select',\n\t\t`rpc_period_select_${size}`,\n\t\tdisabled ? 'rpc_period_select_disabled' : '',\n\t\tblock ? 'rpc_period_select_block' : '',\n\t\tclassName,\n\t]\n\t\t.filter(Boolean)\n\t\t.join(' ');\n\n\treturn (\n\t\t<div\n\t\t\tclassName={containerClass}\n\t\t\tstyle={\n\t\t\t\t{\n\t\t\t\t\t...style,\n\t\t\t\t\t...(activeColor ? { '--rpc-period-active-color': activeColor } : {}),\n\t\t\t\t} as CSSProperties\n\t\t\t}\n\t\t>\n\t\t\t{options.map((item, index) => {\n\t\t\t\tconst isActive = currentValue === item.value;\n\t\t\t\tconst isItemDisabled = disabled || Boolean(item.disabled);\n\n\t\t\t\t// 判断是否需要在当前选项左侧展示蓝色高亮竖线\n\t\t\t\t// 精确还原截图:当激活项不是第一项时,其左侧显示一条与主题色一致的竖线\n\t\t\t\tconst showActiveLine = isActive && index > 0;\n\n\t\t\t\tconst itemClass = [\n\t\t\t\t\t'rpc_period_select_item',\n\t\t\t\t\tisActive ? 'rpc_period_select_item_active' : '',\n\t\t\t\t\tshowActiveLine ? 'rpc_period_select_item_has_active_line' : '',\n\t\t\t\t\tisItemDisabled ? 'rpc_period_select_item_disabled' : '',\n\t\t\t\t]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(' ');\n\n\t\t\t\treturn (\n\t\t\t\t\t<div\n\t\t\t\t\t\tkey={String(item.value)}\n\t\t\t\t\t\tclassName={itemClass}\n\t\t\t\t\t\tonClick={() => handleSelect(item)}\n\t\t\t\t\t>\n\t\t\t\t\t\t{showActiveLine && <span className=\"rpc_period_select_active_line\" />}\n\t\t\t\t\t\t<span className=\"rpc_period_select_text\">{item.label}</span>\n\t\t\t\t\t</div>\n\t\t\t\t);\n\t\t\t})}\n\t\t</div>\n\t);\n}\n\nexport default PeriodSelect;\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// PeriodSelect/index.tsx
|
|
5
|
+
var DEFAULT_PERIOD_OPTIONS = [
|
|
6
|
+
{ label: "\u5468\u5EA6", value: "week" },
|
|
7
|
+
{ label: "\u6708\u5EA6", value: "month" },
|
|
8
|
+
{ label: "\u5B63\u5EA6", value: "quarter" },
|
|
9
|
+
{ label: "\u5E74\u5EA6", value: "year" }
|
|
10
|
+
];
|
|
11
|
+
function PeriodSelect({
|
|
12
|
+
options = DEFAULT_PERIOD_OPTIONS,
|
|
13
|
+
value: controlledValue,
|
|
14
|
+
defaultValue,
|
|
15
|
+
onChange,
|
|
16
|
+
size = "middle",
|
|
17
|
+
activeColor,
|
|
18
|
+
disabled = false,
|
|
19
|
+
block = false,
|
|
20
|
+
className = "",
|
|
21
|
+
style
|
|
22
|
+
}) {
|
|
23
|
+
var _a;
|
|
24
|
+
const initialValue = defaultValue !== void 0 ? defaultValue : (_a = options[0]) == null ? void 0 : _a.value;
|
|
25
|
+
const [internalValue, setInternalValue] = useState(initialValue);
|
|
26
|
+
const currentValue = controlledValue !== void 0 ? controlledValue : internalValue;
|
|
27
|
+
const handleSelect = (item) => {
|
|
28
|
+
if (disabled || item.disabled) return;
|
|
29
|
+
if (controlledValue === void 0) {
|
|
30
|
+
setInternalValue(item.value);
|
|
31
|
+
}
|
|
32
|
+
onChange == null ? void 0 : onChange(item.value, item);
|
|
33
|
+
};
|
|
34
|
+
const containerClass = [
|
|
35
|
+
"rpc_period_select",
|
|
36
|
+
`rpc_period_select_${size}`,
|
|
37
|
+
disabled ? "rpc_period_select_disabled" : "",
|
|
38
|
+
block ? "rpc_period_select_block" : "",
|
|
39
|
+
className
|
|
40
|
+
].filter(Boolean).join(" ");
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
42
|
+
"div",
|
|
43
|
+
{
|
|
44
|
+
className: containerClass,
|
|
45
|
+
style: {
|
|
46
|
+
...style,
|
|
47
|
+
...activeColor ? { "--rpc-period-active-color": activeColor } : {}
|
|
48
|
+
},
|
|
49
|
+
children: options.map((item, index) => {
|
|
50
|
+
const isActive = currentValue === item.value;
|
|
51
|
+
const isItemDisabled = disabled || Boolean(item.disabled);
|
|
52
|
+
const showActiveLine = isActive && index > 0;
|
|
53
|
+
const itemClass = [
|
|
54
|
+
"rpc_period_select_item",
|
|
55
|
+
isActive ? "rpc_period_select_item_active" : "",
|
|
56
|
+
showActiveLine ? "rpc_period_select_item_has_active_line" : "",
|
|
57
|
+
isItemDisabled ? "rpc_period_select_item_disabled" : ""
|
|
58
|
+
].filter(Boolean).join(" ");
|
|
59
|
+
return /* @__PURE__ */ jsxs(
|
|
60
|
+
"div",
|
|
61
|
+
{
|
|
62
|
+
className: itemClass,
|
|
63
|
+
onClick: () => handleSelect(item),
|
|
64
|
+
children: [
|
|
65
|
+
showActiveLine && /* @__PURE__ */ jsx("span", { className: "rpc_period_select_active_line" }),
|
|
66
|
+
/* @__PURE__ */ jsx("span", { className: "rpc_period_select_text", children: item.label })
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
String(item.value)
|
|
70
|
+
);
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
var PeriodSelect_default = PeriodSelect;
|
|
76
|
+
|
|
77
|
+
export { DEFAULT_PERIOD_OPTIONS, PeriodSelect, PeriodSelect_default };
|
|
78
|
+
//# sourceMappingURL=chunk-RFTYEXKU.js.map
|
|
79
|
+
//# sourceMappingURL=chunk-RFTYEXKU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../PeriodSelect/index.tsx"],"names":[],"mappings":";;;;AAsCO,IAAM,sBAAA,GAAuD;AAAA,EACnE,EAAE,KAAA,EAAO,cAAA,EAAM,KAAA,EAAO,MAAA,EAAO;A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AEF,CAAC;AAAA;AAAA,GACF;AAEF;AAEA,IAAO,oBAAA,GAAQ","file":"chunk-RFTYEXKU.js","sourcesContent":["import React, { useState, CSSProperties, ReactNode } from 'react';\nimport './index.less';\n\nexport interface PeriodSelectOption<T = string | number> {\n\t/** 选项展示内容 */\n\tlabel: ReactNode;\n\t/** 选项值 */\n\tvalue: T;\n\t/** 是否禁用当前选项 */\n\tdisabled?: boolean;\n}\n\nexport type PeriodSelectSize = 'small' | 'middle' | 'large';\n\nexport interface PeriodSelectProps<T = string | number> {\n\t/** 选项列表,默认提供【周度、月度、季度、年度】 */\n\toptions?: PeriodSelectOption<T>[];\n\t/** 当前选中值(受控模式) */\n\tvalue?: T;\n\t/** 默认选中值(非受控模式) */\n\tdefaultValue?: T;\n\t/** 切换选项时的回调函数 */\n\tonChange?: (value: T, option: PeriodSelectOption<T>) => void;\n\t/** 尺寸大小,默认为 'middle' */\n\tsize?: PeriodSelectSize;\n\t/** 自定义高亮激活颜色(文字与高亮竖线) */\n\tactiveColor?: string;\n\t/** 是否整体禁用 */\n\tdisabled?: boolean;\n\t/** 是否等宽撑满父容器 */\n\tblock?: boolean;\n\t/** 自定义容器类名 */\n\tclassName?: string;\n\t/** 自定义容器样式 */\n\tstyle?: CSSProperties;\n}\n\n// 默认内置的周期选项(精准匹配周度、月度、季度、年度)\nexport const DEFAULT_PERIOD_OPTIONS: PeriodSelectOption<string>[] = [\n\t{ label: '周度', value: 'week' },\n\t{ label: '月度', value: 'month' },\n\t{ label: '季度', value: 'quarter' },\n\t{ label: '年度', value: 'year' },\n];\n\nexport function PeriodSelect<T = string | number>({\n\toptions = DEFAULT_PERIOD_OPTIONS as unknown as PeriodSelectOption<T>[],\n\tvalue: controlledValue,\n\tdefaultValue,\n\tonChange,\n\tsize = 'middle',\n\tactiveColor,\n\tdisabled = false,\n\tblock = false,\n\tclassName = '',\n\tstyle,\n}: PeriodSelectProps<T>) {\n\tconst initialValue =\n\t\tdefaultValue !== undefined ? defaultValue : (options[0]?.value as T);\n\tconst [internalValue, setInternalValue] = useState<T>(initialValue);\n\n\tconst currentValue =\n\t\tcontrolledValue !== undefined ? controlledValue : internalValue;\n\n\tconst handleSelect = (item: PeriodSelectOption<T>) => {\n\t\tif (disabled || item.disabled) return;\n\t\tif (controlledValue === undefined) {\n\t\t\tsetInternalValue(item.value);\n\t\t}\n\t\tonChange?.(item.value, item);\n\t};\n\n\tconst containerClass = [\n\t\t'rpc_period_select',\n\t\t`rpc_period_select_${size}`,\n\t\tdisabled ? 'rpc_period_select_disabled' : '',\n\t\tblock ? 'rpc_period_select_block' : '',\n\t\tclassName,\n\t]\n\t\t.filter(Boolean)\n\t\t.join(' ');\n\n\treturn (\n\t\t<div\n\t\t\tclassName={containerClass}\n\t\t\tstyle={\n\t\t\t\t{\n\t\t\t\t\t...style,\n\t\t\t\t\t...(activeColor ? { '--rpc-period-active-color': activeColor } : {}),\n\t\t\t\t} as CSSProperties\n\t\t\t}\n\t\t>\n\t\t\t{options.map((item, index) => {\n\t\t\t\tconst isActive = currentValue === item.value;\n\t\t\t\tconst isItemDisabled = disabled || Boolean(item.disabled);\n\n\t\t\t\t// 判断是否需要在当前选项左侧展示蓝色高亮竖线\n\t\t\t\t// 精确还原截图:当激活项不是第一项时,其左侧显示一条与主题色一致的竖线\n\t\t\t\tconst showActiveLine = isActive && index > 0;\n\n\t\t\t\tconst itemClass = [\n\t\t\t\t\t'rpc_period_select_item',\n\t\t\t\t\tisActive ? 'rpc_period_select_item_active' : '',\n\t\t\t\t\tshowActiveLine ? 'rpc_period_select_item_has_active_line' : '',\n\t\t\t\t\tisItemDisabled ? 'rpc_period_select_item_disabled' : '',\n\t\t\t\t]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(' ');\n\n\t\t\t\treturn (\n\t\t\t\t\t<div\n\t\t\t\t\t\tkey={String(item.value)}\n\t\t\t\t\t\tclassName={itemClass}\n\t\t\t\t\t\tonClick={() => handleSelect(item)}\n\t\t\t\t\t>\n\t\t\t\t\t\t{showActiveLine && <span className=\"rpc_period_select_active_line\" />}\n\t\t\t\t\t\t<span className=\"rpc_period_select_text\">{item.label}</span>\n\t\t\t\t\t</div>\n\t\t\t\t);\n\t\t\t})}\n\t\t</div>\n\t);\n}\n\nexport default PeriodSelect;\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
// CeilingBox/index.tsx
|
|
7
|
+
var CeilingBox = ({
|
|
8
|
+
children,
|
|
9
|
+
offsetTop = 0,
|
|
10
|
+
offsetBottom,
|
|
11
|
+
target,
|
|
12
|
+
onChange,
|
|
13
|
+
blur = true,
|
|
14
|
+
zIndex = 1e3,
|
|
15
|
+
className = "",
|
|
16
|
+
style,
|
|
17
|
+
affixedClassName = "",
|
|
18
|
+
affixedStyle
|
|
19
|
+
}) => {
|
|
20
|
+
const [isAffixed, setIsAffixed] = react.useState(false);
|
|
21
|
+
const [boxRect, setBoxRect] = react.useState({ width: 0, height: 0 });
|
|
22
|
+
const placeholderRef = react.useRef(null);
|
|
23
|
+
const contentRef = react.useRef(null);
|
|
24
|
+
const isAffixedRef = react.useRef(false);
|
|
25
|
+
isAffixedRef.current = isAffixed;
|
|
26
|
+
react.useEffect(() => {
|
|
27
|
+
const getTargetElement = () => {
|
|
28
|
+
if (target) {
|
|
29
|
+
const el = target();
|
|
30
|
+
if (el) return el;
|
|
31
|
+
}
|
|
32
|
+
return window;
|
|
33
|
+
};
|
|
34
|
+
const handleScroll = () => {
|
|
35
|
+
if (!placeholderRef.current) return;
|
|
36
|
+
const targetEl = getTargetElement();
|
|
37
|
+
const placeholderRect = placeholderRef.current.getBoundingClientRect();
|
|
38
|
+
let targetTop = 0;
|
|
39
|
+
let targetBottom = window.innerHeight;
|
|
40
|
+
if (targetEl !== window && targetEl instanceof HTMLElement) {
|
|
41
|
+
const containerRect = targetEl.getBoundingClientRect();
|
|
42
|
+
targetTop = containerRect.top;
|
|
43
|
+
targetBottom = containerRect.bottom;
|
|
44
|
+
}
|
|
45
|
+
let shouldAffix = false;
|
|
46
|
+
if (offsetBottom !== void 0) {
|
|
47
|
+
shouldAffix = placeholderRect.bottom >= targetBottom - offsetBottom;
|
|
48
|
+
} else {
|
|
49
|
+
shouldAffix = placeholderRect.top <= targetTop + offsetTop;
|
|
50
|
+
}
|
|
51
|
+
if (shouldAffix !== isAffixedRef.current) {
|
|
52
|
+
if (shouldAffix && contentRef.current) {
|
|
53
|
+
const rect = contentRef.current.getBoundingClientRect();
|
|
54
|
+
setBoxRect({ width: rect.width, height: rect.height });
|
|
55
|
+
}
|
|
56
|
+
setIsAffixed(shouldAffix);
|
|
57
|
+
onChange == null ? void 0 : onChange(shouldAffix);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const targetNode = getTargetElement();
|
|
61
|
+
targetNode.addEventListener("scroll", handleScroll, { passive: true });
|
|
62
|
+
window.addEventListener("resize", handleScroll, { passive: true });
|
|
63
|
+
handleScroll();
|
|
64
|
+
return () => {
|
|
65
|
+
targetNode.removeEventListener("scroll", handleScroll);
|
|
66
|
+
window.removeEventListener("resize", handleScroll);
|
|
67
|
+
};
|
|
68
|
+
}, [offsetTop, offsetBottom, target, onChange]);
|
|
69
|
+
const computeFixedStyle = () => {
|
|
70
|
+
if (!isAffixed) return {};
|
|
71
|
+
const fixedStyle = {
|
|
72
|
+
position: "fixed",
|
|
73
|
+
zIndex,
|
|
74
|
+
width: boxRect.width ? `${boxRect.width}px` : "100%",
|
|
75
|
+
boxSizing: "border-box"
|
|
76
|
+
};
|
|
77
|
+
if (offsetBottom !== void 0) {
|
|
78
|
+
fixedStyle.bottom = `${offsetBottom}px`;
|
|
79
|
+
} else {
|
|
80
|
+
fixedStyle.top = `${offsetTop}px`;
|
|
81
|
+
}
|
|
82
|
+
if (placeholderRef.current) {
|
|
83
|
+
const rect = placeholderRef.current.getBoundingClientRect();
|
|
84
|
+
fixedStyle.left = `${rect.left}px`;
|
|
85
|
+
}
|
|
86
|
+
return fixedStyle;
|
|
87
|
+
};
|
|
88
|
+
const renderedContent = typeof children === "function" ? children(isAffixed) : children;
|
|
89
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
90
|
+
"div",
|
|
91
|
+
{
|
|
92
|
+
ref: placeholderRef,
|
|
93
|
+
className: `rpc_ceiling_box_wrapper ${className}`,
|
|
94
|
+
style: {
|
|
95
|
+
...style,
|
|
96
|
+
height: isAffixed && boxRect.height ? `${boxRect.height}px` : void 0
|
|
97
|
+
},
|
|
98
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
99
|
+
"div",
|
|
100
|
+
{
|
|
101
|
+
ref: contentRef,
|
|
102
|
+
className: `rpc_ceiling_box ${isAffixed ? "rpc_ceiling_box_affixed" : ""} ${isAffixed && blur ? "rpc_ceiling_box_blur" : ""} ${isAffixed ? affixedClassName : ""}`,
|
|
103
|
+
style: {
|
|
104
|
+
...computeFixedStyle(),
|
|
105
|
+
...isAffixed ? affixedStyle : {}
|
|
106
|
+
},
|
|
107
|
+
children: renderedContent
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
var CeilingBox_default = CeilingBox;
|
|
114
|
+
|
|
115
|
+
exports.CeilingBox_default = CeilingBox_default;
|
|
116
|
+
//# sourceMappingURL=chunk-UIU6VCEQ.cjs.map
|
|
117
|
+
//# sourceMappingURL=chunk-UIU6VCEQ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../CeilingBox/index.tsx"],"names":["useState","useRef","useEffect","jsx"],"mappings":";;;;;;AAkCA,IAAM,aAAwC,CAAC;AAAA,EAC9C,QAAA;AAAA,EACA,SAAA,GAAY,CAAA;AAAA,EACZ,YAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,IAAA,GA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,EAAI,SAAA,IAAa,IAAA,GAAO,sBAAA,GAAyB,EAAE,CAAA,CAAA,EAClD,SAAA,GAAY,mBAAmB,EAChC,CAAA,CAAA;AAAA,UACA,KAAA,EAAO;AAAA,YACN,GAAG,iBAAA,EAAkB;AAAA,YACrB,GAAI,SAAA,GAAY,YAAA,GAAe;AAAC,WACjC;AAAA,UAEC,QAAA,EAAA;AAAA;AAAA;AACF;AAAA,GACD;AAEF,CAAA;AAEA,IAAO,kBAAA,GAAQ","file":"chunk-UIU6VCEQ.cjs","sourcesContent":["import React, {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tReactNode,\n\tCSSProperties,\n} from 'react';\nimport './index.less';\n\nexport interface CeilingBoxProps {\n\t/** 子元素内容,支持普通 ReactNode 或 Render Props 函数接收 isAffixed 状态 */\n\tchildren: ReactNode | ((isAffixed: boolean) => ReactNode);\n\t/** 距离视口/容器顶部的吸顶偏移距离(像素),默认为 0 */\n\toffsetTop?: number;\n\t/** 距离视口/容器底部的吸底偏移距离(像素,传值时开启吸底模式) */\n\toffsetBottom?: number;\n\t/** 监听滚动的目标 DOM 容器,不传时默认监听 window 全局滚动 */\n\ttarget?: () => HTMLElement | Window | null;\n\t/** 吸顶/吸底状态改变时的回调函数 */\n\tonChange?: (isAffixed: boolean) => void;\n\t/** 吸顶时是否自动启用毛玻璃磨砂与精致阴影滤镜,默认为 true */\n\tblur?: boolean;\n\t/** 吸顶/吸底状态下的图层层级 z-index,默认为 1000 */\n\tzIndex?: number;\n\t/** 自定义类名 */\n\tclassName?: string;\n\t/** 自定义行内样式 */\n\tstyle?: CSSProperties;\n\t/** 吸顶激活状态下追加的自定义类名 */\n\taffixedClassName?: string;\n\t/** 吸顶激活状态下追加的自定义行内样式 */\n\taffixedStyle?: CSSProperties;\n}\n\nconst CeilingBox: React.FC<CeilingBoxProps> = ({\n\tchildren,\n\toffsetTop = 0,\n\toffsetBottom,\n\ttarget,\n\tonChange,\n\tblur = true,\n\tzIndex = 1000,\n\tclassName = '',\n\tstyle,\n\taffixedClassName = '',\n\taffixedStyle,\n}) => {\n\tconst [isAffixed, setIsAffixed] = useState<boolean>(false);\n\tconst [boxRect, setBoxRect] = useState<{ width: number; height: number }>({ width: 0, height: 0 });\n\n\tconst placeholderRef = useRef<HTMLDivElement>(null);\n\tconst contentRef = useRef<HTMLDivElement>(null);\n\tconst isAffixedRef = useRef<boolean>(false);\n\n\tisAffixedRef.current = isAffixed;\n\n\tuseEffect(() => {\n\t\tconst getTargetElement = (): HTMLElement | Window => {\n\t\t\tif (target) {\n\t\t\t\tconst el = target();\n\t\t\t\tif (el) return el;\n\t\t\t}\n\t\t\treturn window;\n\t\t};\n\n\t\tconst handleScroll = () => {\n\t\t\tif (!placeholderRef.current) return;\n\n\t\t\tconst targetEl = getTargetElement();\n\t\t\tconst placeholderRect = placeholderRef.current.getBoundingClientRect();\n\n\t\t\tlet targetTop = 0;\n\t\t\tlet targetBottom = window.innerHeight;\n\n\t\t\tif (targetEl !== window && targetEl instanceof HTMLElement) {\n\t\t\t\tconst containerRect = targetEl.getBoundingClientRect();\n\t\t\t\ttargetTop = containerRect.top;\n\t\t\t\ttargetBottom = containerRect.bottom;\n\t\t\t}\n\n\t\t\tlet shouldAffix = false;\n\n\t\t\tif (offsetBottom !== undefined) {\n\t\t\t\t// 吸底模式\n\t\t\t\tshouldAffix = placeholderRect.bottom >= targetBottom - offsetBottom;\n\t\t\t} else {\n\t\t\t\t// 吸顶模式 (默认)\n\t\t\t\tshouldAffix = placeholderRect.top <= targetTop + offsetTop;\n\t\t\t}\n\n\t\t\tif (shouldAffix !== isAffixedRef.current) {\n\t\t\t\t// 触发吸顶切换前记录原本的宽高\n\t\t\t\tif (shouldAffix && contentRef.current) {\n\t\t\t\t\tconst rect = contentRef.current.getBoundingClientRect();\n\t\t\t\t\tsetBoxRect({ width: rect.width, height: rect.height });\n\t\t\t\t}\n\n\t\t\t\tsetIsAffixed(shouldAffix);\n\t\t\t\tonChange?.(shouldAffix);\n\t\t\t}\n\t\t};\n\n\t\tconst targetNode = getTargetElement();\n\t\ttargetNode.addEventListener('scroll', handleScroll, { passive: true });\n\t\twindow.addEventListener('resize', handleScroll, { passive: true });\n\n\t\t// 初始检查一次\n\t\thandleScroll();\n\n\t\treturn () => {\n\t\t\ttargetNode.removeEventListener('scroll', handleScroll);\n\t\t\twindow.removeEventListener('resize', handleScroll);\n\t\t};\n\t}, [offsetTop, offsetBottom, target, onChange]);\n\n\t// 计算吸顶定位样式\n\tconst computeFixedStyle = (): CSSProperties => {\n\t\tif (!isAffixed) return {};\n\n\t\tconst fixedStyle: CSSProperties = {\n\t\t\tposition: 'fixed',\n\t\t\tzIndex,\n\t\t\twidth: boxRect.width ? `${boxRect.width}px` : '100%',\n\t\t\tboxSizing: 'border-box',\n\t\t};\n\n\t\tif (offsetBottom !== undefined) {\n\t\t\tfixedStyle.bottom = `${offsetBottom}px`;\n\t\t} else {\n\t\t\tfixedStyle.top = `${offsetTop}px`;\n\t\t}\n\n\t\tif (placeholderRef.current) {\n\t\t\tconst rect = placeholderRef.current.getBoundingClientRect();\n\t\t\tfixedStyle.left = `${rect.left}px`;\n\t\t}\n\n\t\treturn fixedStyle;\n\t};\n\n\tconst renderedContent =\n\t\ttypeof children === 'function' ? children(isAffixed) : children;\n\n\treturn (\n\t\t<div\n\t\t\tref={placeholderRef}\n\t\t\tclassName={`rpc_ceiling_box_wrapper ${className}`}\n\t\t\tstyle={{\n\t\t\t\t...style,\n\t\t\t\theight: isAffixed && boxRect.height ? `${boxRect.height}px` : undefined,\n\t\t\t}}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={contentRef}\n\t\t\t\tclassName={`rpc_ceiling_box ${\n\t\t\t\t\tisAffixed ? 'rpc_ceiling_box_affixed' : ''\n\t\t\t\t} ${isAffixed && blur ? 'rpc_ceiling_box_blur' : ''} ${\n\t\t\t\t\tisAffixed ? affixedClassName : ''\n\t\t\t\t}`}\n\t\t\t\tstyle={{\n\t\t\t\t\t...computeFixedStyle(),\n\t\t\t\t\t...(isAffixed ? affixedStyle : {}),\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{renderedContent}\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n\nexport default CeilingBox;\n"]}
|