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.
@@ -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,5 +1,6 @@
1
1
  import { Dayjs } from 'dayjs';
2
- import type { CSSProperties, ReactNode } from 'react';
2
+ import './index.scss';
3
+ import { CSSProperties, ReactNode } from 'react';
3
4
  export interface CalendarProps {
4
5
  value?: Dayjs;
5
6
  defaultValue?: Dayjs;
@@ -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
- // import './index.scss';
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 { value, style, className, locale, onChange } = props;
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
  });
@@ -1,4 +1,5 @@
1
- import type { CSSProperties, ReactNode } from "react";
1
+ import { CSSProperties, ReactNode } from "react";
2
+ import './index.scss';
2
3
  export type Position = 'top' | 'bottom';
3
4
  export interface MessageProps {
4
5
  style?: CSSProperties;
@@ -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
- // import './index.scss';
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,6 @@
1
1
  import { Dayjs } from 'dayjs';
2
- import type { CSSProperties, ReactNode } from 'react';
2
+ import './index.scss';
3
+ import { CSSProperties, ReactNode } from 'react';
3
4
  export interface CalendarProps {
4
5
  value?: Dayjs;
5
6
  defaultValue?: Dayjs;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- // import './index.scss';
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 { value, style, className, locale, onChange } = props;
11
+ const { style, className, locale, onChange } = props;
12
12
  const [curValue, setCurValue] = useControllableValue(props, {
13
13
  defaultValue: dayjs()
14
14
  });
@@ -1,4 +1,5 @@
1
- import type { CSSProperties, ReactNode } from "react";
1
+ import { CSSProperties, ReactNode } from "react";
2
+ import './index.scss';
2
3
  export type Position = 'top' | 'bottom';
3
4
  export interface MessageProps {
4
5
  style?: CSSProperties;
@@ -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
- // import './index.scss';
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,5 @@
1
+ export interface LocaleContextType {
2
+ locale: string;
3
+ }
4
+ declare const LocaleContext: import("react").Context<LocaleContextType>;
5
+ export default LocaleContext;
@@ -0,0 +1,5 @@
1
+ import { createContext } from "react";
2
+ const LocaleContext = createContext({
3
+ locale: 'zh-CN'
4
+ });
5
+ export default LocaleContext;
@@ -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,3 @@
1
+ import { CalendarType } from "./interface";
2
+ declare const CalendarLocale: CalendarType;
3
+ export default CalendarLocale;
@@ -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,3 @@
1
+ import { CalendarType } from "./interface";
2
+ declare const allLocales: Record<string, CalendarType>;
3
+ export default allLocales;
@@ -0,0 +1,7 @@
1
+ import zhCN from "./zh-CN";
2
+ import enUS from "./en-US";
3
+ const allLocales = {
4
+ 'zh-CN': zhCN,
5
+ 'en-US': enUS
6
+ };
7
+ export default allLocales;
@@ -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,3 @@
1
+ import { CalendarType } from "./interface";
2
+ declare const CalendarLocale: CalendarType;
3
+ export default CalendarLocale;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wlw-components",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "tsc -b && vite build",