wlw-components 0.0.1
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 +73 -0
- package/dist/cjs/Calendar/Header.d.ts +9 -0
- package/dist/cjs/Calendar/Header.js +13 -0
- package/dist/cjs/Calendar/LocaleContext.d.ts +5 -0
- package/dist/cjs/Calendar/LocaleContext.js +7 -0
- package/dist/cjs/Calendar/MonthCalendar.d.ts +8 -0
- package/dist/cjs/Calendar/MonthCalendar.js +59 -0
- package/dist/cjs/Calendar/index.css +113 -0
- package/dist/cjs/Calendar/index.css.map +1 -0
- package/dist/cjs/Calendar/index.d.ts +14 -0
- package/dist/cjs/Calendar/index.js +41 -0
- package/dist/cjs/Calendar/locale/en-US.d.ts +3 -0
- package/dist/cjs/Calendar/locale/en-US.js +31 -0
- package/dist/cjs/Calendar/locale/index.d.ts +3 -0
- package/dist/cjs/Calendar/locale/index.js +9 -0
- package/dist/cjs/Calendar/locale/interface.d.ts +28 -0
- package/dist/cjs/Calendar/locale/interface.js +2 -0
- package/dist/cjs/Calendar/locale/zh-CN.d.ts +3 -0
- package/dist/cjs/Calendar/locale/zh-CN.js +31 -0
- package/dist/cjs/Message/ConfigProvider.d.ts +8 -0
- package/dist/cjs/Message/ConfigProvider.js +13 -0
- package/dist/cjs/Message/index.css +50 -0
- package/dist/cjs/Message/index.css.map +1 -0
- package/dist/cjs/Message/index.d.ts +18 -0
- package/dist/cjs/Message/index.js +58 -0
- package/dist/cjs/Message/useMessage.d.ts +2 -0
- package/dist/cjs/Message/useMessage.js +13 -0
- package/dist/cjs/Message/useStore.d.ts +19 -0
- package/dist/cjs/Message/useStore.js +81 -0
- package/dist/cjs/Message/useTimer.d.ts +9 -0
- package/dist/cjs/Message/useTimer.js +34 -0
- package/dist/cjs/Watermark/index.d.ts +22 -0
- package/dist/cjs/Watermark/index.js +51 -0
- package/dist/cjs/Watermark/useWatermark.d.ts +7 -0
- package/dist/cjs/Watermark/useWatermark.js +211 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +11 -0
- package/dist/esm/Calendar/Header.d.ts +9 -0
- package/dist/esm/Calendar/Header.js +11 -0
- package/dist/esm/Calendar/LocaleContext.d.ts +5 -0
- package/dist/esm/Calendar/LocaleContext.js +5 -0
- package/dist/esm/Calendar/MonthCalendar.d.ts +8 -0
- package/dist/esm/Calendar/MonthCalendar.js +57 -0
- package/dist/esm/Calendar/index.css +113 -0
- package/dist/esm/Calendar/index.css.map +1 -0
- package/dist/esm/Calendar/index.d.ts +14 -0
- package/dist/esm/Calendar/index.js +39 -0
- package/dist/esm/Calendar/locale/en-US.d.ts +3 -0
- package/dist/esm/Calendar/locale/en-US.js +29 -0
- package/dist/esm/Calendar/locale/index.d.ts +3 -0
- package/dist/esm/Calendar/locale/index.js +7 -0
- package/dist/esm/Calendar/locale/interface.d.ts +28 -0
- package/dist/esm/Calendar/locale/interface.js +1 -0
- package/dist/esm/Calendar/locale/zh-CN.d.ts +3 -0
- package/dist/esm/Calendar/locale/zh-CN.js +29 -0
- package/dist/esm/Message/ConfigProvider.d.ts +8 -0
- package/dist/esm/Message/ConfigProvider.js +9 -0
- package/dist/esm/Message/index.css +50 -0
- package/dist/esm/Message/index.css.map +1 -0
- package/dist/esm/Message/index.d.ts +18 -0
- package/dist/esm/Message/index.js +55 -0
- package/dist/esm/Message/useMessage.d.ts +2 -0
- package/dist/esm/Message/useMessage.js +10 -0
- package/dist/esm/Message/useStore.d.ts +19 -0
- package/dist/esm/Message/useStore.js +76 -0
- package/dist/esm/Message/useTimer.d.ts +9 -0
- package/dist/esm/Message/useTimer.js +31 -0
- package/dist/esm/Watermark/index.d.ts +22 -0
- package/dist/esm/Watermark/index.js +49 -0
- package/dist/esm/Watermark/useWatermark.d.ts +7 -0
- package/dist/esm/Watermark/useWatermark.js +207 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +5 -0
- package/package.json +43 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sourceRoot":"","sources":["../../../src/Calendar/index.scss"],"names":[],"mappings":"AAAA;EACE;EACA;EACA;EAEA;EACA;;;AAIF;EACI;EACA;EACA;EACA;;AAEA;EACI;EACA;EACA;EACA;;AAGJ;EACI;;AAGJ;EACI;EACA;EACA;EACA;EACA;;AAEA;EACI;;AAIR;EACI;EACA;EAEA;EAEA;EACA;EACA;EAEA;EACA;EAEA;;AACA;EACI;;AAGJ;EACI;;;AAMR;EACI;EACA;EACA;EACA;EACA;;AAEA;EACI;EACA;EACA;EACA;;AAKJ;EACI;EACA;EACA;EACA;;AAEJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AACA;EACI;;AAEJ;EACI;;AACA;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA","file":"index.css"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
export interface CalendarProps {
|
|
4
|
+
value?: Dayjs;
|
|
5
|
+
defaultValue?: Dayjs;
|
|
6
|
+
style?: CSSProperties;
|
|
7
|
+
className?: string | string[];
|
|
8
|
+
dateRender?: (currentDate: Dayjs) => ReactNode;
|
|
9
|
+
dateInnerContent?: (currentDate: Dayjs) => ReactNode;
|
|
10
|
+
locale?: string;
|
|
11
|
+
onChange?: (date: Dayjs) => void;
|
|
12
|
+
}
|
|
13
|
+
declare function Calendar(props: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export default Calendar;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// import './index.scss';
|
|
3
|
+
import MonthCalendar from './MonthCalendar';
|
|
4
|
+
import Header from './Header';
|
|
5
|
+
import cs from 'classnames';
|
|
6
|
+
import LocaleContext from './LocaleContext';
|
|
7
|
+
import dayjs from 'dayjs';
|
|
8
|
+
import { useState } from 'react';
|
|
9
|
+
import { useControllableValue } from 'ahooks';
|
|
10
|
+
function Calendar(props) {
|
|
11
|
+
const { value, style, className, locale, onChange } = props;
|
|
12
|
+
const [curValue, setCurValue] = useControllableValue(props, {
|
|
13
|
+
defaultValue: dayjs()
|
|
14
|
+
});
|
|
15
|
+
const [curMonth, setCurMonth] = useState(curValue);
|
|
16
|
+
const classNames = cs("calendar", className);
|
|
17
|
+
function changeDate(date) {
|
|
18
|
+
setCurValue(date);
|
|
19
|
+
setCurMonth(date);
|
|
20
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(date);
|
|
21
|
+
}
|
|
22
|
+
function selectHandler(date) {
|
|
23
|
+
changeDate(date);
|
|
24
|
+
}
|
|
25
|
+
function prevMonthHandler() {
|
|
26
|
+
setCurMonth(curMonth.subtract(1, 'month'));
|
|
27
|
+
}
|
|
28
|
+
function nextMonthHandler() {
|
|
29
|
+
setCurMonth(curMonth.add(1, 'month'));
|
|
30
|
+
}
|
|
31
|
+
function todayHandler() {
|
|
32
|
+
const date = dayjs(Date.now());
|
|
33
|
+
changeDate(date);
|
|
34
|
+
}
|
|
35
|
+
return _jsx(LocaleContext.Provider, { value: {
|
|
36
|
+
locale: locale || navigator.language
|
|
37
|
+
}, children: _jsx("div", { className: classNames, style: style, children: _jsxs("div", { className: 'calendar', children: [_jsx(Header, { curMonth: curMonth, prevMonthHandler: prevMonthHandler, nextMonthHandler: nextMonthHandler, todayHandler: todayHandler }), _jsx(MonthCalendar, Object.assign({}, props, { value: curValue, curMonth: curMonth, selectHandler: selectHandler }))] }) }) });
|
|
38
|
+
}
|
|
39
|
+
export default Calendar;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const CalendarLocale = {
|
|
2
|
+
formatYear: 'YYYY',
|
|
3
|
+
formatMonth: 'MMM YYYY',
|
|
4
|
+
today: 'Today',
|
|
5
|
+
month: {
|
|
6
|
+
January: 'January',
|
|
7
|
+
February: 'February',
|
|
8
|
+
March: 'March',
|
|
9
|
+
April: 'April',
|
|
10
|
+
May: 'May',
|
|
11
|
+
June: 'June',
|
|
12
|
+
July: 'July',
|
|
13
|
+
August: 'August',
|
|
14
|
+
September: 'September',
|
|
15
|
+
October: 'October',
|
|
16
|
+
November: 'November',
|
|
17
|
+
December: 'December',
|
|
18
|
+
},
|
|
19
|
+
week: {
|
|
20
|
+
monday: 'Monday',
|
|
21
|
+
tuesday: 'Tuesday',
|
|
22
|
+
wednesday: 'Wednesday',
|
|
23
|
+
thursday: 'Thursday',
|
|
24
|
+
friday: 'Friday',
|
|
25
|
+
saturday: 'Saturday',
|
|
26
|
+
sunday: 'Sunday',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export default CalendarLocale;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface CalendarType {
|
|
2
|
+
formatYear: string;
|
|
3
|
+
formatMonth: string;
|
|
4
|
+
today: string;
|
|
5
|
+
month: {
|
|
6
|
+
January: string;
|
|
7
|
+
February: string;
|
|
8
|
+
March: string;
|
|
9
|
+
April: string;
|
|
10
|
+
May: string;
|
|
11
|
+
June: string;
|
|
12
|
+
July: string;
|
|
13
|
+
August: string;
|
|
14
|
+
September: string;
|
|
15
|
+
October: string;
|
|
16
|
+
November: string;
|
|
17
|
+
December: string;
|
|
18
|
+
} & Record<string, any>;
|
|
19
|
+
week: {
|
|
20
|
+
monday: string;
|
|
21
|
+
tuesday: string;
|
|
22
|
+
wednesday: string;
|
|
23
|
+
thursday: string;
|
|
24
|
+
friday: string;
|
|
25
|
+
saturday: string;
|
|
26
|
+
sunday: string;
|
|
27
|
+
} & Record<string, any>;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const CalendarLocale = {
|
|
2
|
+
formatYear: 'YYYY 年',
|
|
3
|
+
formatMonth: 'YYYY 年 MM 月',
|
|
4
|
+
today: '今天',
|
|
5
|
+
month: {
|
|
6
|
+
January: '一月',
|
|
7
|
+
February: '二月',
|
|
8
|
+
March: '三月',
|
|
9
|
+
April: '四月',
|
|
10
|
+
May: '五月',
|
|
11
|
+
June: '六月',
|
|
12
|
+
July: '七月',
|
|
13
|
+
August: '八月',
|
|
14
|
+
September: '九月',
|
|
15
|
+
October: '十月',
|
|
16
|
+
November: '十一月',
|
|
17
|
+
December: '十二月',
|
|
18
|
+
},
|
|
19
|
+
week: {
|
|
20
|
+
monday: '周一',
|
|
21
|
+
tuesday: '周二',
|
|
22
|
+
wednesday: '周三',
|
|
23
|
+
thursday: '周四',
|
|
24
|
+
friday: '周五',
|
|
25
|
+
saturday: '周六',
|
|
26
|
+
sunday: '周日',
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export default CalendarLocale;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PropsWithChildren, RefObject } from "react";
|
|
2
|
+
import { MessageRef } from ".";
|
|
3
|
+
interface ConfigProviderProps {
|
|
4
|
+
messageRef?: RefObject<MessageRef | null>;
|
|
5
|
+
}
|
|
6
|
+
export declare const ConfigContext: import("react").Context<ConfigProviderProps>;
|
|
7
|
+
export declare function ConfigProvider(props: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useRef } from "react";
|
|
3
|
+
import { MessageProvider } from ".";
|
|
4
|
+
export const ConfigContext = createContext({});
|
|
5
|
+
export function ConfigProvider(props) {
|
|
6
|
+
const { children } = props;
|
|
7
|
+
const messageRef = useRef(null);
|
|
8
|
+
return (_jsxs(ConfigContext.Provider, { value: { messageRef }, children: [_jsx(MessageProvider, { ref: messageRef }), children] }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
.message-enter {
|
|
2
|
+
opacity: 0;
|
|
3
|
+
transform: scale(1.1);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.message-enter-active {
|
|
7
|
+
opacity: 1;
|
|
8
|
+
transform: scale(1);
|
|
9
|
+
transition: opacity, transform 1s ease;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.message-exit {
|
|
13
|
+
opacity: 1;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.message-exit-active {
|
|
17
|
+
opacity: 0;
|
|
18
|
+
transition: opacity 1s ease;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.message-wrapper {
|
|
22
|
+
position: fixed;
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: 100%;
|
|
25
|
+
pointer-events: none;
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
justify-content: flex-start;
|
|
29
|
+
align-items: center;
|
|
30
|
+
}
|
|
31
|
+
.message-wrapper-top {
|
|
32
|
+
position: absolute;
|
|
33
|
+
top: 20px;
|
|
34
|
+
}
|
|
35
|
+
.message-wrapper-bottom {
|
|
36
|
+
position: absolute;
|
|
37
|
+
bottom: 20px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.message-item {
|
|
41
|
+
margin-bottom: 12px;
|
|
42
|
+
padding: 10px 16px;
|
|
43
|
+
line-height: 14px;
|
|
44
|
+
font-size: 14px;
|
|
45
|
+
border: 1px solid #ccc;
|
|
46
|
+
box-shadow: 0 0 3px #ccc;
|
|
47
|
+
pointer-events: all;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sourceRoot":"","sources":["../../../src/Message/index.scss"],"names":[],"mappings":"AAAA;EACE;EACA;;;AAGF;EACE;EACA;EACA;;;AAGF;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;EACA;EAEA;EAEA;EACA;EACA;EACA;;AAEA;EACE;EACA;;AAGF;EACE;EACA;;;AAIJ;EACE;EAEA;EACA;EACA;EAEA;EACA;EAEA","file":"index.css"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
+
export type Position = 'top' | 'bottom';
|
|
3
|
+
export interface MessageProps {
|
|
4
|
+
style?: CSSProperties;
|
|
5
|
+
className?: string | string[];
|
|
6
|
+
content: ReactNode | string;
|
|
7
|
+
duration?: number;
|
|
8
|
+
onClose?: (...args: any) => void;
|
|
9
|
+
id?: number;
|
|
10
|
+
position?: Position;
|
|
11
|
+
}
|
|
12
|
+
export interface MessageRef {
|
|
13
|
+
add: (messageProps: MessageProps) => number;
|
|
14
|
+
remove: (id: number) => void;
|
|
15
|
+
update: (id: number, messageProps: MessageProps) => void;
|
|
16
|
+
clearAll: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare const MessageProvider: import("react").ForwardRefExoticComponent<import("react").RefAttributes<MessageRef>>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, forwardRef } from "react";
|
|
3
|
+
import useStore from "./useStore";
|
|
4
|
+
import { CSSTransition, TransitionGroup } from "react-transition-group";
|
|
5
|
+
import { useTimer } from "./useTimer";
|
|
6
|
+
// import './index.scss';
|
|
7
|
+
import { createPortal } from "react-dom";
|
|
8
|
+
const MessageItem = (item) => {
|
|
9
|
+
const { onMouseEnter, onMouseLeave } = useTimer({
|
|
10
|
+
id: item.id,
|
|
11
|
+
duration: item.duration,
|
|
12
|
+
remove: item.onClose,
|
|
13
|
+
});
|
|
14
|
+
return _jsx("div", { className: "message-item", onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, children: item.content });
|
|
15
|
+
};
|
|
16
|
+
export const MessageProvider = forwardRef((props, ref) => {
|
|
17
|
+
const { messageList, add, update, remove, clearAll } = useStore('top');
|
|
18
|
+
// useEffect(() => {
|
|
19
|
+
// setInterval(() => {
|
|
20
|
+
// add({
|
|
21
|
+
// content: Math.random().toString().slice(2, 8)
|
|
22
|
+
// })
|
|
23
|
+
// }, 2000);
|
|
24
|
+
// }, []);
|
|
25
|
+
if ('current' in ref) {
|
|
26
|
+
ref.current = {
|
|
27
|
+
add,
|
|
28
|
+
update,
|
|
29
|
+
remove,
|
|
30
|
+
clearAll
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// useImperativeHandle(ref, () => {
|
|
34
|
+
// debugger;
|
|
35
|
+
// return {
|
|
36
|
+
// add,
|
|
37
|
+
// update,
|
|
38
|
+
// remove,
|
|
39
|
+
// clearAll
|
|
40
|
+
// }
|
|
41
|
+
// }, []);
|
|
42
|
+
const positions = Object.keys(messageList);
|
|
43
|
+
const messageWrapper = _jsx("div", { className: "message-wrapper", children: positions.map(direction => {
|
|
44
|
+
return _jsx(TransitionGroup, { className: `message-wrapper-${direction}`, children: messageList[direction].map(item => {
|
|
45
|
+
return _jsx(CSSTransition, { timeout: 1000, classNames: 'message', children: _jsx(MessageItem, Object.assign({ onClose: remove }, item)) }, item.id);
|
|
46
|
+
}) }, direction);
|
|
47
|
+
}) });
|
|
48
|
+
const el = useMemo(() => {
|
|
49
|
+
const el = document.createElement('div');
|
|
50
|
+
el.className = `wrapper`;
|
|
51
|
+
document.body.appendChild(el);
|
|
52
|
+
return el;
|
|
53
|
+
}, []);
|
|
54
|
+
return createPortal(messageWrapper, el);
|
|
55
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { ConfigContext } from './ConfigProvider';
|
|
3
|
+
export function useMessage() {
|
|
4
|
+
const { messageRef } = useContext(ConfigContext);
|
|
5
|
+
if (!messageRef) {
|
|
6
|
+
throw new Error('请在最外层添加 ConfigProvider 组件');
|
|
7
|
+
}
|
|
8
|
+
debugger;
|
|
9
|
+
return messageRef.current;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MessageProps, Position } from '.';
|
|
2
|
+
export type MessageList = {
|
|
3
|
+
top: MessageProps[];
|
|
4
|
+
bottom: MessageProps[];
|
|
5
|
+
};
|
|
6
|
+
declare function useStore(defaultPosition: Position): {
|
|
7
|
+
messageList: MessageList;
|
|
8
|
+
add: (messageProps: MessageProps) => number;
|
|
9
|
+
update: (id: number, messageProps: MessageProps) => void;
|
|
10
|
+
remove: (id: number) => void;
|
|
11
|
+
clearAll: () => void;
|
|
12
|
+
};
|
|
13
|
+
export declare function getId(messageProps: MessageProps): number;
|
|
14
|
+
export declare function getMessagePosition(messageList: MessageList, id: number): Position | undefined;
|
|
15
|
+
export declare function findMessage(messageList: MessageList, id: number): {
|
|
16
|
+
position: Position | undefined;
|
|
17
|
+
index: number;
|
|
18
|
+
};
|
|
19
|
+
export default useStore;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
const initialState = {
|
|
3
|
+
top: [],
|
|
4
|
+
bottom: []
|
|
5
|
+
};
|
|
6
|
+
function useStore(defaultPosition) {
|
|
7
|
+
const [messageList, setMessageList] = useState(Object.assign({}, initialState));
|
|
8
|
+
return {
|
|
9
|
+
messageList,
|
|
10
|
+
add: (messageProps) => {
|
|
11
|
+
const id = getId(messageProps);
|
|
12
|
+
setMessageList((preState) => {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
if (messageProps === null || messageProps === void 0 ? void 0 : messageProps.id) {
|
|
15
|
+
const position = getMessagePosition(preState, messageProps.id);
|
|
16
|
+
if (position)
|
|
17
|
+
return preState;
|
|
18
|
+
}
|
|
19
|
+
const position = messageProps.position || defaultPosition;
|
|
20
|
+
const isTop = position.includes('top');
|
|
21
|
+
const messages = isTop
|
|
22
|
+
? [Object.assign(Object.assign({}, messageProps), { id }), ...((_a = preState[position]) !== null && _a !== void 0 ? _a : [])]
|
|
23
|
+
: [...((_b = preState[position]) !== null && _b !== void 0 ? _b : []), Object.assign(Object.assign({}, messageProps), { id })];
|
|
24
|
+
return Object.assign(Object.assign({}, preState), { [position]: messages });
|
|
25
|
+
});
|
|
26
|
+
return id;
|
|
27
|
+
},
|
|
28
|
+
update: (id, messageProps) => {
|
|
29
|
+
if (!id)
|
|
30
|
+
return;
|
|
31
|
+
setMessageList((preState) => {
|
|
32
|
+
const nextState = Object.assign({}, preState);
|
|
33
|
+
const { position, index } = findMessage(nextState, id);
|
|
34
|
+
if (position && index !== -1) {
|
|
35
|
+
nextState[position][index] = Object.assign(Object.assign({}, nextState[position][index]), messageProps);
|
|
36
|
+
}
|
|
37
|
+
return nextState;
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
remove: (id) => {
|
|
41
|
+
setMessageList((prevState) => {
|
|
42
|
+
const position = getMessagePosition(prevState, id);
|
|
43
|
+
if (!position)
|
|
44
|
+
return prevState;
|
|
45
|
+
return Object.assign(Object.assign({}, prevState), { [position]: prevState[position].filter((notice) => notice.id !== id) });
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
clearAll: () => {
|
|
49
|
+
setMessageList(Object.assign({}, initialState));
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
let count = 1;
|
|
54
|
+
export function getId(messageProps) {
|
|
55
|
+
if (messageProps.id) {
|
|
56
|
+
return messageProps.id;
|
|
57
|
+
}
|
|
58
|
+
count += 1;
|
|
59
|
+
return count;
|
|
60
|
+
}
|
|
61
|
+
export function getMessagePosition(messageList, id) {
|
|
62
|
+
for (const [position, list] of Object.entries(messageList)) {
|
|
63
|
+
if (list.find((item) => item.id === id)) {
|
|
64
|
+
return position;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export function findMessage(messageList, id) {
|
|
69
|
+
const position = getMessagePosition(messageList, id);
|
|
70
|
+
const index = position ? messageList[position].findIndex((message) => message.id === id) : -1;
|
|
71
|
+
return {
|
|
72
|
+
position,
|
|
73
|
+
index,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export default useStore;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
export function useTimer(props) {
|
|
3
|
+
const { remove, id, duration = 2000 } = props;
|
|
4
|
+
const timer = useRef(null);
|
|
5
|
+
const startTimer = () => {
|
|
6
|
+
timer.current = window.setTimeout(() => {
|
|
7
|
+
remove(id);
|
|
8
|
+
removeTimer();
|
|
9
|
+
}, duration);
|
|
10
|
+
};
|
|
11
|
+
const removeTimer = () => {
|
|
12
|
+
if (timer.current) {
|
|
13
|
+
clearTimeout(timer.current);
|
|
14
|
+
timer.current = null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
startTimer();
|
|
19
|
+
return () => removeTimer();
|
|
20
|
+
}, []);
|
|
21
|
+
const onMouseEnter = () => {
|
|
22
|
+
removeTimer();
|
|
23
|
+
};
|
|
24
|
+
const onMouseLeave = () => {
|
|
25
|
+
startTimer();
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
onMouseEnter,
|
|
29
|
+
onMouseLeave,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PropsWithChildren, CSSProperties, FC } from 'react';
|
|
2
|
+
export interface WatermarkProps extends PropsWithChildren {
|
|
3
|
+
style?: CSSProperties;
|
|
4
|
+
className?: string;
|
|
5
|
+
zIndex?: string | number;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
rotate?: number;
|
|
9
|
+
image?: string;
|
|
10
|
+
content?: string | string[];
|
|
11
|
+
fontStyle?: {
|
|
12
|
+
color?: string;
|
|
13
|
+
fontFamily?: string;
|
|
14
|
+
fontSize?: number | string;
|
|
15
|
+
fontWeight?: number | string;
|
|
16
|
+
};
|
|
17
|
+
gap?: [number, number];
|
|
18
|
+
offset?: [number, number];
|
|
19
|
+
getContainer?: () => HTMLElement;
|
|
20
|
+
}
|
|
21
|
+
declare const Watermark: FC<WatermarkProps>;
|
|
22
|
+
export default Watermark;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
3
|
+
import useWatermark from './useWatermark';
|
|
4
|
+
const Watermark = (props) => {
|
|
5
|
+
const { className, style, zIndex, width, height, rotate, image, content, fontStyle, gap, offset } = props;
|
|
6
|
+
const containerRef = useRef(null);
|
|
7
|
+
const getContainer = useCallback(() => {
|
|
8
|
+
return props.getContainer ? props.getContainer() : containerRef.current;
|
|
9
|
+
}, [containerRef.current, props.getContainer]);
|
|
10
|
+
const { generateWatermark } = useWatermark({
|
|
11
|
+
zIndex,
|
|
12
|
+
width,
|
|
13
|
+
height,
|
|
14
|
+
rotate,
|
|
15
|
+
image,
|
|
16
|
+
content,
|
|
17
|
+
fontStyle,
|
|
18
|
+
gap,
|
|
19
|
+
offset,
|
|
20
|
+
getContainer,
|
|
21
|
+
});
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
generateWatermark({
|
|
24
|
+
zIndex,
|
|
25
|
+
width,
|
|
26
|
+
height,
|
|
27
|
+
rotate,
|
|
28
|
+
image,
|
|
29
|
+
content,
|
|
30
|
+
fontStyle,
|
|
31
|
+
gap,
|
|
32
|
+
offset,
|
|
33
|
+
getContainer,
|
|
34
|
+
});
|
|
35
|
+
}, [
|
|
36
|
+
zIndex,
|
|
37
|
+
width,
|
|
38
|
+
height,
|
|
39
|
+
rotate,
|
|
40
|
+
image,
|
|
41
|
+
content,
|
|
42
|
+
JSON.stringify(props.fontStyle),
|
|
43
|
+
JSON.stringify(props.gap),
|
|
44
|
+
JSON.stringify(props.offset),
|
|
45
|
+
getContainer,
|
|
46
|
+
]);
|
|
47
|
+
return props.children ? (_jsx("div", { className: className, style: style, ref: containerRef, children: props.children })) : null;
|
|
48
|
+
};
|
|
49
|
+
export default Watermark;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WatermarkProps } from '.';
|
|
2
|
+
export type WatermarkOptions = Omit<WatermarkProps, 'className' | 'style' | 'children'>;
|
|
3
|
+
export declare function isNumber(obj: any): obj is number;
|
|
4
|
+
export default function useWatermark(params: WatermarkOptions): {
|
|
5
|
+
generateWatermark: (newOptions: Partial<WatermarkOptions>) => void;
|
|
6
|
+
destroy: () => void;
|
|
7
|
+
};
|