zaman-backoffice 1.0.2 → 1.0.4
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/components/CalendarItem/CalendarItem.styled.d.ts +10 -0
- package/dist/components/CalendarItem/CalendarItem.types.d.ts +7 -0
- package/dist/components/CalendarItem/index.d.ts +1 -0
- package/dist/components/CalendarWrapper/CalendarWrapper.styled.d.ts +5 -0
- package/dist/components/CalendarWrapper/index.d.ts +1 -0
- package/dist/components/FloatingElement/FloatingElement.d.ts +4 -0
- package/dist/components/FloatingElement/FloatingElement.styled.d.ts +4 -0
- package/dist/components/FloatingElement/FloatingElement.types.d.ts +7 -0
- package/dist/components/FloatingElement/index.d.ts +1 -0
- package/dist/components/Header/Header.d.ts +3 -0
- package/dist/components/Header/Header.styled.d.ts +12 -0
- package/dist/components/Header/Header.types.d.ts +6 -0
- package/dist/components/Header/index.d.ts +1 -0
- package/dist/components/IconButton/IconButton.d.ts +2 -0
- package/dist/components/IconButton/IconButton.styled.d.ts +4 -0
- package/dist/components/IconButton/index.d.ts +1 -0
- package/dist/components/Icons/ChevronLeft/index.d.ts +2 -0
- package/dist/components/Icons/ChevronRight/index.d.ts +2 -0
- package/dist/components/Modal/Modal.d.ts +3 -0
- package/dist/components/Modal/Modal.styled.d.ts +4 -0
- package/dist/components/Modal/index.d.ts +1 -0
- package/dist/components/Modal/types.d.ts +6 -0
- package/dist/components/MonthPicker/Month.styled.d.ts +4 -0
- package/dist/components/MonthPicker/MonthPicker.d.ts +3 -0
- package/dist/components/MonthPicker/MonthPicker.types.d.ts +4 -0
- package/dist/components/MonthPicker/index.d.ts +1 -0
- package/dist/components/RenderCalendar/RenderCalendar.d.ts +3 -0
- package/dist/components/RenderCalendar/RenderCalendar.types.d.ts +9 -0
- package/dist/components/RenderCalendar/index.d.ts +1 -0
- package/dist/components/YearPicker/YearPicker.d.ts +3 -0
- package/dist/components/YearPicker/YearPicker.styled.d.ts +4 -0
- package/dist/components/YearPicker/YearPicker.types.d.ts +4 -0
- package/dist/components/YearPicker/index.d.ts +1 -0
- package/dist/constants.d.ts +5 -0
- package/dist/hooks/useCalendarHandlers.d.ts +19 -0
- package/dist/hooks/useClickOutside.d.ts +3 -0
- package/dist/hooks/useSlideCalendar.d.ts +12 -0
- package/dist/hooks/useTimePicker.d.ts +19 -0
- package/dist/index.cjs.js +303 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +303 -0
- package/dist/packages/Calendar/Calendar.d.ts +4 -0
- package/dist/packages/Calendar/Calendar.styled.d.ts +20 -0
- package/dist/packages/Calendar/Calendar.types.d.ts +19 -0
- package/dist/packages/Calendar/index.d.ts +2 -0
- package/dist/packages/CalendarProvider/CalendarProvider.d.ts +3 -0
- package/dist/packages/CalendarProvider/CalendarProvider.types.d.ts +5 -0
- package/{src/packages/CalendarProvider/index.ts → dist/packages/CalendarProvider/index.d.ts} +2 -2
- package/dist/packages/DatePicker/DatePicker.d.ts +3 -0
- package/dist/packages/DatePicker/DatePicker.types.d.ts +15 -0
- package/dist/packages/DatePicker/index.d.ts +2 -0
- package/dist/packages/TimePicker/TimePicker.d.ts +3 -0
- package/dist/packages/TimePicker/TimePicker.styled.d.ts +37 -0
- package/dist/packages/TimePicker/TimePicker.types.d.ts +14 -0
- package/dist/packages/TimePicker/components/Numbers/Numbers.d.ts +3 -0
- package/dist/packages/TimePicker/components/Numbers/Numbers.styled.d.ts +9 -0
- package/dist/packages/TimePicker/components/Numbers/Numbers.types.d.ts +13 -0
- package/dist/packages/TimePicker/components/Numbers/index.d.ts +1 -0
- package/dist/packages/TimePicker/index.d.ts +2 -0
- package/dist/style/animation.d.ts +2 -0
- package/dist/style/classNames.d.ts +7 -0
- package/dist/style/colorPallete.d.ts +1 -0
- package/dist/style/colors.d.ts +5 -0
- package/dist/style/hexToHSL.d.ts +6 -0
- package/dist/style/radius.d.ts +7 -0
- package/dist/types.d.ts +41 -0
- package/dist/utils/dateHelper/dateHelper.d.ts +15 -0
- package/dist/utils/dateHelper/index.d.ts +1 -0
- package/dist/utils/dateTimeFormat/dateTimeFormat.d.ts +13 -0
- package/dist/utils/dateTimeFormat/index.d.ts +1 -0
- package/dist/utils/format/format.d.ts +4 -0
- package/dist/utils/format/format.types.d.ts +10 -0
- package/dist/utils/format/index.d.ts +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/locale.d.ts +6 -0
- package/dist/utils/locales/en.d.ts +3 -0
- package/dist/utils/locales/fa.d.ts +3 -0
- package/dist/utils/locales/index.d.ts +3 -0
- package/dist/utils/locales/locales.types.d.ts +12 -0
- package/dist/utils/month/index.d.ts +1 -0
- package/dist/utils/month/month.d.ts +5 -0
- package/dist/utils/month/month.types.d.ts +10 -0
- package/dist/utils/timePicker.d.ts +36 -0
- package/package.json +1 -1
- package/.eslintrc.cjs +0 -26
- package/.husky/commit-msg +0 -4
- package/.husky/pre-commit +0 -4
- package/.idea/git_toolbox_blame.xml +0 -6
- package/.idea/git_toolbox_prj.xml +0 -15
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/material_theme_project_new.xml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/zaman-backoffice2.iml +0 -12
- package/.prettierrc +0 -9
- package/.travis.yml +0 -10
- package/client/index.html +0 -12
- package/client/main.tsx +0 -84
- package/client/style.css +0 -62
- package/cypress/fixtures/example.json +0 -5
- package/cypress/support/commands.ts +0 -38
- package/cypress/support/component-index.html +0 -12
- package/cypress/support/component.ts +0 -39
- package/cypress/videos/Calendar/CalendarComponent.cy.tsx.mp4 +0 -0
- package/cypress/videos/DatePicker/DatePicker.cy.tsx.mp4 +0 -0
- package/cypress.config.ts +0 -10
- package/help/banner.png +0 -0
- package/jest.config.ts +0 -47
- package/src/components/CalendarItem/CalendarItem.styled.tsx +0 -96
- package/src/components/CalendarItem/CalendarItem.types.ts +0 -7
- package/src/components/CalendarItem/index.ts +0 -1
- package/src/components/CalendarWrapper/CalendarWrapper.styled.tsx +0 -19
- package/src/components/CalendarWrapper/index.ts +0 -1
- package/src/components/FloatingElement/FloatingElement.styled.tsx +0 -8
- package/src/components/FloatingElement/FloatingElement.tsx +0 -83
- package/src/components/FloatingElement/FloatingElement.types.ts +0 -8
- package/src/components/FloatingElement/index.tsx +0 -1
- package/src/components/Header/Header.styled.tsx +0 -40
- package/src/components/Header/Header.tsx +0 -46
- package/src/components/Header/Header.types.ts +0 -6
- package/src/components/Header/index.ts +0 -1
- package/src/components/IconButton/IconButton.styled.tsx +0 -22
- package/src/components/IconButton/IconButton.tsx +0 -3
- package/src/components/IconButton/index.tsx +0 -1
- package/src/components/Icons/ChevronLeft/index.tsx +0 -22
- package/src/components/Icons/ChevronRight/index.tsx +0 -22
- package/src/components/Modal/Modal.styled.tsx +0 -23
- package/src/components/Modal/Modal.tsx +0 -29
- package/src/components/Modal/index.tsx +0 -1
- package/src/components/Modal/types.ts +0 -7
- package/src/components/MonthPicker/Month.styled.tsx +0 -11
- package/src/components/MonthPicker/MonthPicker.tsx +0 -35
- package/src/components/MonthPicker/MonthPicker.types.ts +0 -4
- package/src/components/MonthPicker/index.ts +0 -1
- package/src/components/RenderCalendar/RenderCalendar.tsx +0 -31
- package/src/components/RenderCalendar/RenderCalendar.types.ts +0 -10
- package/src/components/RenderCalendar/index.ts +0 -1
- package/src/components/YearPicker/YearPicker.styled.tsx +0 -14
- package/src/components/YearPicker/YearPicker.tsx +0 -49
- package/src/components/YearPicker/YearPicker.types.ts +0 -4
- package/src/components/YearPicker/index.ts +0 -1
- package/src/constants.ts +0 -6
- package/src/hooks/__tests__/useClickOutside.test.tsx +0 -32
- package/src/hooks/useCalendarHandlers.tsx +0 -113
- package/src/hooks/useClickOutside.tsx +0 -23
- package/src/hooks/useSlideCalendar.tsx +0 -95
- package/src/hooks/useTimePicker.tsx +0 -95
- package/src/index.tsx +0 -4
- package/src/packages/Calendar/Calendar.styled.tsx +0 -42
- package/src/packages/Calendar/Calendar.tsx +0 -159
- package/src/packages/Calendar/Calendar.types.ts +0 -31
- package/src/packages/Calendar/CalendarComponent.cy.tsx +0 -69
- package/src/packages/Calendar/index.ts +0 -2
- package/src/packages/CalendarProvider/CalendarProvider.tsx +0 -30
- package/src/packages/CalendarProvider/CalendarProvider.types.ts +0 -6
- package/src/packages/DatePicker/DatePicker.cy.tsx +0 -54
- package/src/packages/DatePicker/DatePicker.tsx +0 -127
- package/src/packages/DatePicker/DatePicker.types.ts +0 -26
- package/src/packages/DatePicker/index.ts +0 -2
- package/src/packages/TimePicker/TimePicker.styled.tsx +0 -77
- package/src/packages/TimePicker/TimePicker.tsx +0 -121
- package/src/packages/TimePicker/TimePicker.types.ts +0 -16
- package/src/packages/TimePicker/components/Numbers/Numbers.styled.tsx +0 -36
- package/src/packages/TimePicker/components/Numbers/Numbers.tsx +0 -58
- package/src/packages/TimePicker/components/Numbers/Numbers.types.ts +0 -14
- package/src/packages/TimePicker/components/Numbers/index.ts +0 -1
- package/src/packages/TimePicker/index.ts +0 -2
- package/src/style/animation.ts +0 -23
- package/src/style/classNames.ts +0 -8
- package/src/style/colorPallete.ts +0 -16
- package/src/style/colors.ts +0 -15
- package/src/style/hexToHSL.ts +0 -52
- package/src/style/radius.ts +0 -28
- package/src/types.ts +0 -75
- package/src/utils/dateHelper/dateHelper.ts +0 -67
- package/src/utils/dateHelper/index.ts +0 -1
- package/src/utils/dateTimeFormat/dateTimeFormat.ts +0 -43
- package/src/utils/dateTimeFormat/index.ts +0 -1
- package/src/utils/format/format.test.ts +0 -37
- package/src/utils/format/format.ts +0 -56
- package/src/utils/format/format.types.ts +0 -11
- package/src/utils/format/index.ts +0 -1
- package/src/utils/index.ts +0 -21
- package/src/utils/locale.ts +0 -13
- package/src/utils/locales/en.ts +0 -89
- package/src/utils/locales/fa.ts +0 -89
- package/src/utils/locales/index.ts +0 -10
- package/src/utils/locales/locales.types.ts +0 -11
- package/src/utils/month/index.ts +0 -1
- package/src/utils/month/month.ts +0 -54
- package/src/utils/month/month.types.ts +0 -11
- package/src/utils/timePicker.ts +0 -107
- package/src/utils/type.ts +0 -0
- package/tsconfig.json +0 -22
- package/tsconfig.test.json +0 -7
- package/vite.config.ts +0 -7
package/src/style/hexToHSL.ts
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
export function hexToHSL(hex: string): { h: number; s: number; l: number } {
|
2
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
3
|
-
|
4
|
-
if (result == null) {
|
5
|
-
throw new Error('Could not parse Hex Color')
|
6
|
-
}
|
7
|
-
|
8
|
-
const rHex = parseInt(result[1], 16)
|
9
|
-
const gHex = parseInt(result[2], 16)
|
10
|
-
const bHex = parseInt(result[3], 16)
|
11
|
-
|
12
|
-
const r = rHex / 255
|
13
|
-
const g = gHex / 255
|
14
|
-
const b = bHex / 255
|
15
|
-
|
16
|
-
const max = Math.max(r, g, b)
|
17
|
-
const min = Math.min(r, g, b)
|
18
|
-
|
19
|
-
let h = (max + min) / 2
|
20
|
-
let s = h
|
21
|
-
let l = h
|
22
|
-
|
23
|
-
if (max === min) {
|
24
|
-
// Achromatic
|
25
|
-
return { h: 0, s: 0, l }
|
26
|
-
}
|
27
|
-
|
28
|
-
const d = max - min
|
29
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
|
30
|
-
switch (max) {
|
31
|
-
case r:
|
32
|
-
h = (g - b) / d + (g < b ? 6 : 0)
|
33
|
-
break
|
34
|
-
case g:
|
35
|
-
h = (b - r) / d + 2
|
36
|
-
break
|
37
|
-
case b:
|
38
|
-
h = (r - g) / d + 4
|
39
|
-
break
|
40
|
-
}
|
41
|
-
h /= 6
|
42
|
-
|
43
|
-
s = s * 100
|
44
|
-
s = Math.round(s)
|
45
|
-
l = l * 100
|
46
|
-
l = Math.round(l)
|
47
|
-
h = Math.round(360 * h)
|
48
|
-
|
49
|
-
return { h, s, l }
|
50
|
-
}
|
51
|
-
|
52
|
-
export default hexToHSL
|
package/src/style/radius.ts
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
export type Radius = 'thin' | 'x1' | 'x2' | 'x3' | 'x4'
|
2
|
-
|
3
|
-
interface radiusObject {
|
4
|
-
wrapper: number
|
5
|
-
calendarItem: number
|
6
|
-
}
|
7
|
-
export const radius: Record<Radius, radiusObject> = {
|
8
|
-
thin: {
|
9
|
-
wrapper: 0,
|
10
|
-
calendarItem: 0
|
11
|
-
},
|
12
|
-
x1: {
|
13
|
-
wrapper: 8,
|
14
|
-
calendarItem: 4
|
15
|
-
},
|
16
|
-
x2: {
|
17
|
-
wrapper: 16,
|
18
|
-
calendarItem: 8
|
19
|
-
},
|
20
|
-
x3: {
|
21
|
-
wrapper: 24,
|
22
|
-
calendarItem: 16
|
23
|
-
},
|
24
|
-
x4: {
|
25
|
-
wrapper: 24,
|
26
|
-
calendarItem: 20
|
27
|
-
}
|
28
|
-
}
|
package/src/types.ts
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
import '@emotion/react'
|
2
|
-
import type { Radius } from './style/radius'
|
3
|
-
|
4
|
-
export type DatePickerValue = number | Date | string
|
5
|
-
|
6
|
-
export type Locales = 'fa' | 'en'
|
7
|
-
|
8
|
-
export type Directions = 'rtl' | 'ltr'
|
9
|
-
|
10
|
-
export type DaysRange = 0 | 1 | 2 | 3 | 4 | 5 | 6
|
11
|
-
|
12
|
-
export type Pickers = 'days' | 'year' | 'month'
|
13
|
-
|
14
|
-
export type Positions = 'right' | 'left' | 'center'
|
15
|
-
|
16
|
-
export interface BaseProps {
|
17
|
-
round?: Radius
|
18
|
-
accentColor?: string
|
19
|
-
locale?: Locales
|
20
|
-
direction?: Directions
|
21
|
-
}
|
22
|
-
|
23
|
-
export interface onDatePickerChangePayload {
|
24
|
-
value: Date
|
25
|
-
}
|
26
|
-
|
27
|
-
export interface onRangeDatePickerChangePayload {
|
28
|
-
from: Date
|
29
|
-
to: Date
|
30
|
-
}
|
31
|
-
|
32
|
-
// export type RangeProp = boolean | undefined
|
33
|
-
|
34
|
-
// export type onChangeTypeBasedOnRange<Range extends RangeProp> =
|
35
|
-
// Range extends false | undefined
|
36
|
-
// ? onDatePickerChangePayload
|
37
|
-
// : onRangeDatePickerChangePayload
|
38
|
-
|
39
|
-
interface MyProps1 {
|
40
|
-
range: true
|
41
|
-
myMethod: (arg: onRangeDatePickerChangePayload) => void
|
42
|
-
}
|
43
|
-
|
44
|
-
interface MyProps2 {
|
45
|
-
range: false
|
46
|
-
myMethod: (arg: onDatePickerChangePayload) => void
|
47
|
-
}
|
48
|
-
|
49
|
-
export type CalendarTypeProps = MyProps1 | MyProps2
|
50
|
-
const obj1: CalendarTypeProps = {
|
51
|
-
range: true,
|
52
|
-
myMethod: ({ from, to }) => {
|
53
|
-
console.log(from, to)
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
const obj2: CalendarTypeProps = {
|
58
|
-
range: false,
|
59
|
-
myMethod: ({ value }) => {
|
60
|
-
console.log(value)
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
console.log(obj1, obj2)
|
65
|
-
|
66
|
-
declare module '@emotion/react' {
|
67
|
-
export interface Theme {
|
68
|
-
colors: {
|
69
|
-
gray: Record<number, string>
|
70
|
-
primary: Record<number, string>
|
71
|
-
}
|
72
|
-
round: Radius
|
73
|
-
direction: Directions
|
74
|
-
}
|
75
|
-
}
|
@@ -1,67 +0,0 @@
|
|
1
|
-
import dayjs from 'dayjs'
|
2
|
-
import isBetween from 'dayjs/plugin/isBetween'
|
3
|
-
import { getMonth, getYear } from '../dateTimeFormat/dateTimeFormat'
|
4
|
-
dayjs.extend(isBetween)
|
5
|
-
|
6
|
-
export const sameMonth = (date: Date, date2: Date) => {
|
7
|
-
return getMonth(date) === getMonth(date2)
|
8
|
-
}
|
9
|
-
|
10
|
-
export const sameDay = (date?: Date, date2?: Date): boolean => {
|
11
|
-
if (date === undefined) {
|
12
|
-
return false
|
13
|
-
}
|
14
|
-
return dayjs(date).isSame(date2, 'day')
|
15
|
-
}
|
16
|
-
|
17
|
-
export const getYears = (date: Date, from: number = 80, to: number = 50) => {
|
18
|
-
const getCurrentYear = parseInt(getYear(date, 'latn'), 10)
|
19
|
-
const startFrom = getCurrentYear - from
|
20
|
-
const till = getCurrentYear + to
|
21
|
-
const result: number[] = []
|
22
|
-
|
23
|
-
for (let i = startFrom; i <= till; i++) {
|
24
|
-
result.push(i)
|
25
|
-
}
|
26
|
-
return result
|
27
|
-
}
|
28
|
-
|
29
|
-
export const selectMonth = (date: Date, selectedMonth: number) => {
|
30
|
-
const currentMonth = parseInt(getMonth(date, 'latn'), 10)
|
31
|
-
const diffMonth = selectedMonth - currentMonth
|
32
|
-
|
33
|
-
if (diffMonth > 0) {
|
34
|
-
return dayjs(date).add(diffMonth, 'months').toDate()
|
35
|
-
}
|
36
|
-
return dayjs(date).subtract(Math.abs(diffMonth), 'months').toDate()
|
37
|
-
}
|
38
|
-
|
39
|
-
export const selectYear = (date: Date, selectedYear: number) => {
|
40
|
-
const currentYear = parseInt(getYear(date, 'latn'), 10)
|
41
|
-
const diffYear = selectedYear - currentYear
|
42
|
-
|
43
|
-
if (diffYear > 0) {
|
44
|
-
return dayjs(date).add(diffYear, 'years').toDate()
|
45
|
-
}
|
46
|
-
return dayjs(date).subtract(Math.abs(diffYear), 'years').toDate()
|
47
|
-
}
|
48
|
-
|
49
|
-
export const isInBetween = (
|
50
|
-
day: Date,
|
51
|
-
from?: Date | null,
|
52
|
-
to?: Date | null
|
53
|
-
): boolean => {
|
54
|
-
if (from !== null && to !== null) {
|
55
|
-
return dayjs(day).isBetween(dayjs(from), dayjs(to))
|
56
|
-
}
|
57
|
-
return false
|
58
|
-
}
|
59
|
-
|
60
|
-
export default {
|
61
|
-
sameMonth,
|
62
|
-
sameDay,
|
63
|
-
getYears,
|
64
|
-
selectMonth,
|
65
|
-
selectYear,
|
66
|
-
isInBetween
|
67
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export { default } from './dateHelper'
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import localeCache from '../locale'
|
2
|
-
|
3
|
-
export const getDateFormat = (
|
4
|
-
date: Date,
|
5
|
-
options: Intl.DateTimeFormatOptions,
|
6
|
-
numberingSystem?: string
|
7
|
-
) => {
|
8
|
-
const { locale } = localeCache
|
9
|
-
const defaultOptions = {
|
10
|
-
...options,
|
11
|
-
...(numberingSystem != null && { numberingSystem })
|
12
|
-
}
|
13
|
-
const intl = new Date(date).toLocaleString(locale, defaultOptions)
|
14
|
-
return intl
|
15
|
-
}
|
16
|
-
|
17
|
-
export const getDayOfMonth = (date: Date): number => {
|
18
|
-
return parseInt(getDateFormat(date, { day: 'numeric' }, 'latn'), 10)
|
19
|
-
}
|
20
|
-
|
21
|
-
export const getDayString = (date: Date, numberingSystem?: string): string => {
|
22
|
-
return getDateFormat(date, { day: 'numeric' }, numberingSystem)
|
23
|
-
}
|
24
|
-
export const getYear = (date: Date, numberingSystem?: string): string => {
|
25
|
-
return getDateFormat(date, { year: 'numeric' }, numberingSystem)
|
26
|
-
}
|
27
|
-
export const getYear2Digit = (date: Date, numberingSystem?: string): string => {
|
28
|
-
return getDateFormat(date, { year: '2-digit' }, numberingSystem)
|
29
|
-
}
|
30
|
-
|
31
|
-
export const getMonthName = (date: Date, numberingSystem?: string): string => {
|
32
|
-
return getDateFormat(date, { month: 'short' }, numberingSystem)
|
33
|
-
}
|
34
|
-
|
35
|
-
export const getMonth = (date: Date, numberingSystem?: string): string => {
|
36
|
-
return getDateFormat(date, { month: '2-digit' }, numberingSystem)
|
37
|
-
}
|
38
|
-
|
39
|
-
export default {
|
40
|
-
getDayOfMonth,
|
41
|
-
getMonth,
|
42
|
-
getMonthName
|
43
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export { default } from './dateTimeFormat'
|
@@ -1,37 +0,0 @@
|
|
1
|
-
import formatDate from './format'
|
2
|
-
import localeCache from '../locale'
|
3
|
-
|
4
|
-
const date = 'Wed Mar 08 2023'
|
5
|
-
|
6
|
-
describe('formatDate test', () => {
|
7
|
-
test('simple format date', () => {
|
8
|
-
localeCache.setLocale('fa')
|
9
|
-
expect(formatDate(new Date(date), 'YYYY/MM/DD')).toBe('۱۴۰۱/۱۲/۱۷')
|
10
|
-
expect(formatDate(new Date(date), 'YYYY/MMMM/DD')).toBe('۱۴۰۱/اسفند/۱۷')
|
11
|
-
})
|
12
|
-
|
13
|
-
test('format with space date', () => {
|
14
|
-
localeCache.setLocale('en')
|
15
|
-
expect(formatDate(new Date(date), 'YYYY MM DD')).toBe('2023 03 8')
|
16
|
-
})
|
17
|
-
|
18
|
-
test('format with dash date', () => {
|
19
|
-
localeCache.setLocale('en')
|
20
|
-
expect(formatDate(new Date(date), 'MM-DD-YY')).toBe('03-8-23')
|
21
|
-
})
|
22
|
-
|
23
|
-
test('get month', () => {
|
24
|
-
localeCache.setLocale('en')
|
25
|
-
expect(formatDate(new Date(date), 'MMMM')).toBe('Mar')
|
26
|
-
})
|
27
|
-
|
28
|
-
test('get day', () => {
|
29
|
-
localeCache.setLocale('en')
|
30
|
-
expect(formatDate(new Date(date), 'DD')).toBe('8')
|
31
|
-
})
|
32
|
-
|
33
|
-
test('get year', () => {
|
34
|
-
localeCache.setLocale('fa')
|
35
|
-
expect(formatDate(new Date(date), 'YYYY')).toBe('۱۴۰۱')
|
36
|
-
})
|
37
|
-
})
|
@@ -1,56 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
getDayString,
|
3
|
-
getMonth,
|
4
|
-
getMonthName,
|
5
|
-
getYear,
|
6
|
-
getYear2Digit
|
7
|
-
} from '../dateTimeFormat/dateTimeFormat'
|
8
|
-
import { type formatFunctions, type Formats } from './format.types'
|
9
|
-
|
10
|
-
export const formats: Record<Formats, formatFunctions> = {
|
11
|
-
MMMM: getMonthName,
|
12
|
-
MM: getMonth,
|
13
|
-
M: getMonth,
|
14
|
-
YYYY: getYear,
|
15
|
-
YY: getYear2Digit,
|
16
|
-
DD: getDayString,
|
17
|
-
D: getDayString
|
18
|
-
}
|
19
|
-
|
20
|
-
const regex = /\/|\s|-/
|
21
|
-
|
22
|
-
const validateFormat = (format: string) => {
|
23
|
-
const splitFormat = format.trimStart().trimEnd().split(regex) as Formats[]
|
24
|
-
if (format === '' || format.trim() === '') {
|
25
|
-
throw new Error('format is empty')
|
26
|
-
}
|
27
|
-
splitFormat.forEach((format) => {
|
28
|
-
if (!(format in formats)) {
|
29
|
-
throw new Error(`format is not valid, format passed is: ${format}`)
|
30
|
-
}
|
31
|
-
})
|
32
|
-
}
|
33
|
-
export const formatDate = (
|
34
|
-
date: Date,
|
35
|
-
format: string,
|
36
|
-
numberingSystem?: string
|
37
|
-
): string => {
|
38
|
-
try {
|
39
|
-
validateFormat(format)
|
40
|
-
const splitFormat = format.trimStart().trimEnd().split(regex) as Formats[]
|
41
|
-
const splitCharacterSearch = format.match(regex)
|
42
|
-
const splitCharacter =
|
43
|
-
splitCharacterSearch !== null ? splitCharacterSearch[0] : ''
|
44
|
-
|
45
|
-
return splitFormat
|
46
|
-
.map((format) => {
|
47
|
-
return formats[format](date, numberingSystem)
|
48
|
-
})
|
49
|
-
.join(splitCharacter)
|
50
|
-
} catch (ex) {
|
51
|
-
console.error(ex)
|
52
|
-
}
|
53
|
-
return ''
|
54
|
-
}
|
55
|
-
|
56
|
-
export default formatDate
|
@@ -1 +0,0 @@
|
|
1
|
-
export { default } from './format'
|
package/src/utils/index.ts
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
import localeCache from './locale'
|
2
|
-
|
3
|
-
export const isRtl = (): boolean => {
|
4
|
-
if (document.dir !== '') {
|
5
|
-
return document.dir === 'rtl'
|
6
|
-
}
|
7
|
-
const { body } = document
|
8
|
-
return getComputedStyle(body).direction === 'rtl'
|
9
|
-
}
|
10
|
-
|
11
|
-
export const localizeNumber = (n: string | number) => {
|
12
|
-
if (process.env.NODE_ENV === 'test') {
|
13
|
-
return n
|
14
|
-
}
|
15
|
-
const { locale } = localeCache
|
16
|
-
return Number(n).toLocaleString(locale, {
|
17
|
-
useGrouping: false
|
18
|
-
})
|
19
|
-
}
|
20
|
-
|
21
|
-
export const weekDayNames = ['ش', 'ی', 'د', 'س', 'چ', 'پ', 'ج']
|
package/src/utils/locale.ts
DELETED
package/src/utils/locales/en.ts
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
import type { LocalesTypes } from './locales.types'
|
2
|
-
|
3
|
-
export const en: LocalesTypes = {
|
4
|
-
shortWeekDays: [
|
5
|
-
{
|
6
|
-
key: 0,
|
7
|
-
name: 'S'
|
8
|
-
},
|
9
|
-
{
|
10
|
-
key: 1,
|
11
|
-
name: 'M'
|
12
|
-
},
|
13
|
-
{
|
14
|
-
key: 2,
|
15
|
-
name: 'T'
|
16
|
-
},
|
17
|
-
{
|
18
|
-
key: 3,
|
19
|
-
name: 'W'
|
20
|
-
},
|
21
|
-
{
|
22
|
-
key: 4,
|
23
|
-
name: 'T'
|
24
|
-
},
|
25
|
-
{
|
26
|
-
key: 5,
|
27
|
-
name: 'F'
|
28
|
-
},
|
29
|
-
{
|
30
|
-
key: 6,
|
31
|
-
name: 'S'
|
32
|
-
}
|
33
|
-
],
|
34
|
-
months: [
|
35
|
-
{
|
36
|
-
key: 1,
|
37
|
-
name: 'January'
|
38
|
-
},
|
39
|
-
{
|
40
|
-
key: 2,
|
41
|
-
name: 'February'
|
42
|
-
},
|
43
|
-
{
|
44
|
-
key: 3,
|
45
|
-
name: 'March'
|
46
|
-
},
|
47
|
-
{
|
48
|
-
key: 4,
|
49
|
-
name: 'April'
|
50
|
-
},
|
51
|
-
{
|
52
|
-
key: 5,
|
53
|
-
name: 'May'
|
54
|
-
},
|
55
|
-
{
|
56
|
-
key: 6,
|
57
|
-
name: 'June'
|
58
|
-
},
|
59
|
-
{
|
60
|
-
key: 7,
|
61
|
-
name: 'July'
|
62
|
-
},
|
63
|
-
{
|
64
|
-
key: 8,
|
65
|
-
name: 'August'
|
66
|
-
},
|
67
|
-
{
|
68
|
-
key: 9,
|
69
|
-
name: 'September'
|
70
|
-
},
|
71
|
-
{
|
72
|
-
key: 10,
|
73
|
-
name: 'October'
|
74
|
-
},
|
75
|
-
{
|
76
|
-
key: 11,
|
77
|
-
name: 'November'
|
78
|
-
},
|
79
|
-
{
|
80
|
-
key: 12,
|
81
|
-
name: 'December'
|
82
|
-
}
|
83
|
-
],
|
84
|
-
format: 'MM-DD-YY',
|
85
|
-
am: 'AM',
|
86
|
-
pm: 'PM'
|
87
|
-
}
|
88
|
-
|
89
|
-
export default en
|
package/src/utils/locales/fa.ts
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
import type { LocalesTypes } from './locales.types'
|
2
|
-
|
3
|
-
export const fa: LocalesTypes = {
|
4
|
-
shortWeekDays: [
|
5
|
-
{
|
6
|
-
key: 0,
|
7
|
-
name: 'ش'
|
8
|
-
},
|
9
|
-
{
|
10
|
-
key: 1,
|
11
|
-
name: 'ی'
|
12
|
-
},
|
13
|
-
{
|
14
|
-
key: 2,
|
15
|
-
name: 'د'
|
16
|
-
},
|
17
|
-
{
|
18
|
-
key: 3,
|
19
|
-
name: 'س'
|
20
|
-
},
|
21
|
-
{
|
22
|
-
key: 4,
|
23
|
-
name: 'چ'
|
24
|
-
},
|
25
|
-
{
|
26
|
-
key: 5,
|
27
|
-
name: 'پ'
|
28
|
-
},
|
29
|
-
{
|
30
|
-
key: 6,
|
31
|
-
name: 'ج'
|
32
|
-
}
|
33
|
-
],
|
34
|
-
months: [
|
35
|
-
{
|
36
|
-
key: 1,
|
37
|
-
name: 'فروردین'
|
38
|
-
},
|
39
|
-
{
|
40
|
-
key: 2,
|
41
|
-
name: 'اردیبهشت'
|
42
|
-
},
|
43
|
-
{
|
44
|
-
key: 3,
|
45
|
-
name: 'خرداد'
|
46
|
-
},
|
47
|
-
{
|
48
|
-
key: 4,
|
49
|
-
name: 'تیر'
|
50
|
-
},
|
51
|
-
{
|
52
|
-
key: 5,
|
53
|
-
name: 'مرداد'
|
54
|
-
},
|
55
|
-
{
|
56
|
-
key: 6,
|
57
|
-
name: 'شهریور'
|
58
|
-
},
|
59
|
-
{
|
60
|
-
key: 7,
|
61
|
-
name: 'مهر'
|
62
|
-
},
|
63
|
-
{
|
64
|
-
key: 8,
|
65
|
-
name: 'آبان'
|
66
|
-
},
|
67
|
-
{
|
68
|
-
key: 9,
|
69
|
-
name: 'آذر'
|
70
|
-
},
|
71
|
-
{
|
72
|
-
key: 10,
|
73
|
-
name: 'دی'
|
74
|
-
},
|
75
|
-
{
|
76
|
-
key: 11,
|
77
|
-
name: 'بهمن'
|
78
|
-
},
|
79
|
-
{
|
80
|
-
key: 12,
|
81
|
-
name: 'اسفند'
|
82
|
-
}
|
83
|
-
],
|
84
|
-
format: 'YYYY/MM/DD',
|
85
|
-
am: 'ق.ظ',
|
86
|
-
pm: 'ب.ظ'
|
87
|
-
}
|
88
|
-
|
89
|
-
export default fa
|
package/src/utils/month/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export { default } from './month'
|
package/src/utils/month/month.ts
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
import dayjs from 'dayjs'
|
2
|
-
import 'dayjs/locale/fa'
|
3
|
-
import weekday from 'dayjs/plugin/weekday'
|
4
|
-
import LocalizedFormat from 'dayjs/plugin/LocalizedFormat'
|
5
|
-
import { getDayOfMonth } from '../dateTimeFormat/dateTimeFormat'
|
6
|
-
import { sameMonth } from '../dateHelper/dateHelper'
|
7
|
-
import formatDate from '../format'
|
8
|
-
import localeCache from '../locale'
|
9
|
-
import type { DaysInMonth } from './month.types'
|
10
|
-
import { type DatePickerValue } from '../../types'
|
11
|
-
|
12
|
-
dayjs.extend(weekday)
|
13
|
-
dayjs.extend(LocalizedFormat)
|
14
|
-
|
15
|
-
const getDays = (date: DatePickerValue | undefined): DaysInMonth => {
|
16
|
-
const { locale } = localeCache
|
17
|
-
dayjs.locale(locale)
|
18
|
-
const startDate = date === undefined ? new Date() : dayjs(date).toDate()
|
19
|
-
const selectedDayOnMonth = getDayOfMonth(new Date(startDate))
|
20
|
-
const firstDayOfMonth = dayjs(new Date(startDate)).subtract(
|
21
|
-
selectedDayOnMonth - 1,
|
22
|
-
'days'
|
23
|
-
)
|
24
|
-
const dayNumberOfWeek = firstDayOfMonth.weekday()
|
25
|
-
const firstDayOfWeek = dayjs(firstDayOfMonth).subtract(
|
26
|
-
dayNumberOfWeek,
|
27
|
-
'days'
|
28
|
-
)
|
29
|
-
const middleOfMonth = firstDayOfMonth.add(15, 'days')
|
30
|
-
|
31
|
-
const weeks = []
|
32
|
-
let initialDate = dayjs(firstDayOfWeek.format())
|
33
|
-
for (let i = 0; i <= 5; i++) {
|
34
|
-
const day = []
|
35
|
-
for (let j = 0; j < 7; j++) {
|
36
|
-
const currentDay = new Date(initialDate.format())
|
37
|
-
day.push({
|
38
|
-
date: currentDay,
|
39
|
-
disabled: !sameMonth(firstDayOfMonth.toDate(), currentDay)
|
40
|
-
})
|
41
|
-
initialDate = initialDate.add(1, 'day')
|
42
|
-
}
|
43
|
-
weeks.push(day)
|
44
|
-
}
|
45
|
-
|
46
|
-
return {
|
47
|
-
id: Date.now(),
|
48
|
-
monthName: formatDate(new Date(startDate), 'MMMM YYYY'),
|
49
|
-
middleOfMonth: middleOfMonth.toDate(),
|
50
|
-
weeks
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
export default getDays
|