wlw-components 0.0.1 → 0.0.2
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/dist/cjs/Calendar/MonthCalendar.js +0 -1
- package/dist/cjs/Calendar/index.d.ts +2 -1
- package/dist/cjs/Calendar/index.js +2 -2
- package/dist/cjs/Message/index.d.ts +2 -1
- package/dist/cjs/Message/index.js +1 -1
- package/dist/esm/Calendar/MonthCalendar.js +0 -1
- package/dist/esm/Calendar/index.d.ts +2 -1
- package/dist/esm/Calendar/index.js +2 -2
- package/dist/esm/Message/index.d.ts +2 -1
- package/dist/esm/Message/index.js +1 -1
- package/dist/esm/components/Calendar/Header.d.ts +9 -0
- package/dist/esm/components/Calendar/Header.js +11 -0
- package/dist/esm/components/Calendar/LocaleContext.d.ts +5 -0
- package/dist/esm/components/Calendar/LocaleContext.js +5 -0
- package/dist/esm/components/Calendar/MonthCalendar.d.ts +8 -0
- package/dist/esm/components/Calendar/MonthCalendar.js +56 -0
- package/dist/esm/components/Calendar/index.d.ts +15 -0
- package/dist/esm/components/Calendar/index.js +39 -0
- package/dist/esm/components/Calendar/locale/en-US.d.ts +3 -0
- package/dist/esm/components/Calendar/locale/en-US.js +29 -0
- package/dist/esm/components/Calendar/locale/index.d.ts +3 -0
- package/dist/esm/components/Calendar/locale/index.js +7 -0
- package/dist/esm/components/Calendar/locale/interface.d.ts +28 -0
- package/dist/esm/components/Calendar/locale/interface.js +1 -0
- package/dist/esm/components/Calendar/locale/zh-CN.d.ts +3 -0
- package/dist/esm/components/Calendar/locale/zh-CN.js +29 -0
- package/package.json +1 -1
|
@@ -7,7 +7,6 @@ const LocaleContext_1 = require("./LocaleContext");
|
|
|
7
7
|
const locale_1 = require("./locale");
|
|
8
8
|
const classnames_1 = require("classnames");
|
|
9
9
|
function getAllDays(date) {
|
|
10
|
-
const daysInMonth = date.daysInMonth();
|
|
11
10
|
const startDate = date.startOf('month');
|
|
12
11
|
const day = startDate.day();
|
|
13
12
|
const daysInfo = new Array(6 * 7);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
-
|
|
4
|
+
require("./index.scss");
|
|
5
5
|
const MonthCalendar_1 = require("./MonthCalendar");
|
|
6
6
|
const Header_1 = require("./Header");
|
|
7
7
|
const classnames_1 = require("classnames");
|
|
@@ -10,7 +10,7 @@ const dayjs_1 = require("dayjs");
|
|
|
10
10
|
const react_1 = require("react");
|
|
11
11
|
const ahooks_1 = require("ahooks");
|
|
12
12
|
function Calendar(props) {
|
|
13
|
-
const {
|
|
13
|
+
const { style, className, locale, onChange } = props;
|
|
14
14
|
const [curValue, setCurValue] = (0, ahooks_1.useControllableValue)(props, {
|
|
15
15
|
defaultValue: (0, dayjs_1.default)()
|
|
16
16
|
});
|
|
@@ -6,7 +6,7 @@ const react_1 = require("react");
|
|
|
6
6
|
const useStore_1 = require("./useStore");
|
|
7
7
|
const react_transition_group_1 = require("react-transition-group");
|
|
8
8
|
const useTimer_1 = require("./useTimer");
|
|
9
|
-
|
|
9
|
+
require("./index.scss");
|
|
10
10
|
const react_dom_1 = require("react-dom");
|
|
11
11
|
const MessageItem = (item) => {
|
|
12
12
|
const { onMouseEnter, onMouseLeave } = (0, useTimer_1.useTimer)({
|
|
@@ -5,7 +5,6 @@ import LocaleContext from "./LocaleContext";
|
|
|
5
5
|
import allLocales from "./locale";
|
|
6
6
|
import cs from 'classnames';
|
|
7
7
|
function getAllDays(date) {
|
|
8
|
-
const daysInMonth = date.daysInMonth();
|
|
9
8
|
const startDate = date.startOf('month');
|
|
10
9
|
const day = startDate.day();
|
|
11
10
|
const daysInfo = new Array(6 * 7);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
2
|
+
import './index.scss';
|
|
3
3
|
import MonthCalendar from './MonthCalendar';
|
|
4
4
|
import Header from './Header';
|
|
5
5
|
import cs from 'classnames';
|
|
@@ -8,7 +8,7 @@ import dayjs from 'dayjs';
|
|
|
8
8
|
import { useState } from 'react';
|
|
9
9
|
import { useControllableValue } from 'ahooks';
|
|
10
10
|
function Calendar(props) {
|
|
11
|
-
const {
|
|
11
|
+
const { style, className, locale, onChange } = props;
|
|
12
12
|
const [curValue, setCurValue] = useControllableValue(props, {
|
|
13
13
|
defaultValue: dayjs()
|
|
14
14
|
});
|
|
@@ -3,7 +3,7 @@ import { useMemo, forwardRef } from "react";
|
|
|
3
3
|
import useStore from "./useStore";
|
|
4
4
|
import { CSSTransition, TransitionGroup } from "react-transition-group";
|
|
5
5
|
import { useTimer } from "./useTimer";
|
|
6
|
-
|
|
6
|
+
import './index.scss';
|
|
7
7
|
import { createPortal } from "react-dom";
|
|
8
8
|
const MessageItem = (item) => {
|
|
9
9
|
const { onMouseEnter, onMouseLeave } = useTimer({
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Dayjs } from "dayjs";
|
|
2
|
+
interface HeaderProps {
|
|
3
|
+
curMonth: Dayjs;
|
|
4
|
+
prevMonthHandler: () => void;
|
|
5
|
+
nextMonthHandler: () => void;
|
|
6
|
+
todayHandler: () => void;
|
|
7
|
+
}
|
|
8
|
+
declare function Header(props: HeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default Header;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import LocaleContext from "./LocaleContext";
|
|
4
|
+
import allLocales from "./locale";
|
|
5
|
+
function Header(props) {
|
|
6
|
+
const { curMonth, prevMonthHandler, nextMonthHandler, todayHandler, } = props;
|
|
7
|
+
const localeContext = useContext(LocaleContext);
|
|
8
|
+
const CalendarContext = allLocales[localeContext.locale];
|
|
9
|
+
return _jsx("div", { className: "calendar-header", children: _jsxs("div", { className: "calendar-header-left", children: [_jsx("div", { className: "calendar-header-icon", onClick: prevMonthHandler, children: "<" }), _jsx("div", { className: "calendar-header-value", children: curMonth.format(CalendarContext.formatMonth) }), _jsx("div", { className: "calendar-header-icon", onClick: nextMonthHandler, children: ">" }), _jsx("button", { className: "calendar-header-btn", onClick: todayHandler, children: CalendarContext.today })] }) });
|
|
10
|
+
}
|
|
11
|
+
export default Header;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CalendarProps } from ".";
|
|
2
|
+
import { Dayjs } from "dayjs";
|
|
3
|
+
interface MonthCalendarProps extends CalendarProps {
|
|
4
|
+
curMonth: Dayjs;
|
|
5
|
+
selectHandler?: (date: Dayjs) => void;
|
|
6
|
+
}
|
|
7
|
+
declare function MonthCalendar(props: MonthCalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default MonthCalendar;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// import CalendarLocale from "./locale/en-US";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import LocaleContext from "./LocaleContext";
|
|
5
|
+
import allLocales from "./locale";
|
|
6
|
+
import cs from 'classnames';
|
|
7
|
+
function getAllDays(date) {
|
|
8
|
+
const startDate = date.startOf('month');
|
|
9
|
+
const day = startDate.day();
|
|
10
|
+
const daysInfo = new Array(6 * 7);
|
|
11
|
+
for (let i = 0; i < day; i++) {
|
|
12
|
+
daysInfo[i] = {
|
|
13
|
+
date: startDate.subtract(day - i, 'day'),
|
|
14
|
+
currentMonth: false
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
for (let i = day; i < daysInfo.length; i++) {
|
|
18
|
+
const calcDate = startDate.add(i - day, 'day');
|
|
19
|
+
daysInfo[i] = {
|
|
20
|
+
date: calcDate,
|
|
21
|
+
currentMonth: calcDate.month() === date.month()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// debugger;
|
|
25
|
+
return daysInfo;
|
|
26
|
+
}
|
|
27
|
+
// function renderDays(
|
|
28
|
+
// days: Array<{date: Dayjs, currentMonth: boolean}>,
|
|
29
|
+
// dateRender: MonthCalendarProps['dateRender'],
|
|
30
|
+
// dateInnerContent: MonthCalendarProps['dateInnerContent'],
|
|
31
|
+
// value: Dayjs,
|
|
32
|
+
// selectHandler: MonthCalendarProps['selectHandler']
|
|
33
|
+
// )
|
|
34
|
+
function MonthCalendar(props) {
|
|
35
|
+
const localeContext = useContext(LocaleContext);
|
|
36
|
+
const { value, curMonth, dateRender, dateInnerContent, selectHandler, } = props;
|
|
37
|
+
const CalendarLocale = allLocales[localeContext.locale];
|
|
38
|
+
const weekList = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
|
|
39
|
+
const allDays = getAllDays(curMonth);
|
|
40
|
+
function renderDays(days) {
|
|
41
|
+
const rows = [];
|
|
42
|
+
for (let i = 0; i < 6; i++) {
|
|
43
|
+
const row = [];
|
|
44
|
+
for (let j = 0; j < 7; j++) {
|
|
45
|
+
const item = days[i * 7 + j];
|
|
46
|
+
row[j] = _jsx("div", { className: "calendar-month-body-cell" + (item.currentMonth ? ' calendar-month-body-cell-current' : ''), onClick: () => selectHandler === null || selectHandler === void 0 ? void 0 : selectHandler(item.date), children: dateRender ? dateRender(item.date) : (_jsxs("div", { className: "calendar-month-body-cell-date", children: [_jsx("div", { className: cs("calendar-month-body-cell-date-value", (value === null || value === void 0 ? void 0 : value.format('YYYY-MM-DD')) === item.date.format('YYYY-MM-DD')
|
|
47
|
+
? "calendar-month-body-cell-date-selected"
|
|
48
|
+
: ""), children: item.date.date() }), _jsx("div", { className: "calendar-month-body-cell-date-content", children: dateInnerContent === null || dateInnerContent === void 0 ? void 0 : dateInnerContent(item.date) })] })) });
|
|
49
|
+
}
|
|
50
|
+
rows.push(row);
|
|
51
|
+
}
|
|
52
|
+
return rows.map(row => _jsx("div", { className: "calendar-month-body-row", children: row }));
|
|
53
|
+
}
|
|
54
|
+
return _jsxs("div", { className: "calendar-month", children: [_jsx("div", { className: "calendar-month-week-list", children: weekList.map((week) => (_jsx("div", { className: "calendar-month-week-list-item", children: CalendarLocale.week[week] }, week))) }), _jsx("div", { className: "calendar-month-body", children: renderDays(allDays) })] });
|
|
55
|
+
}
|
|
56
|
+
export default MonthCalendar;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
import './index.scss';
|
|
3
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
4
|
+
export interface CalendarProps {
|
|
5
|
+
value?: Dayjs;
|
|
6
|
+
defaultValue?: Dayjs;
|
|
7
|
+
style?: CSSProperties;
|
|
8
|
+
className?: string | string[];
|
|
9
|
+
dateRender?: (currentDate: Dayjs) => ReactNode;
|
|
10
|
+
dateInnerContent?: (currentDate: Dayjs) => ReactNode;
|
|
11
|
+
locale?: string;
|
|
12
|
+
onChange?: (date: Dayjs) => void;
|
|
13
|
+
}
|
|
14
|
+
declare function Calendar(props: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
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 { 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;
|