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
@@ -1,30 +0,0 @@
|
|
1
|
-
import React, { useMemo } from 'react'
|
2
|
-
import { ThemeProvider } from '@emotion/react'
|
3
|
-
import { makeColorPallet } from '../../style/colorPallete'
|
4
|
-
import { ACCENT_COLOR } from '../../constants'
|
5
|
-
import localeCache from '../../utils/locale'
|
6
|
-
import { gray } from '../../style/colors'
|
7
|
-
import type { CalendarProviderProps } from './CalendarProvider.types'
|
8
|
-
|
9
|
-
export const CalendarProvider = (props: CalendarProviderProps) => {
|
10
|
-
const {
|
11
|
-
accentColor = ACCENT_COLOR,
|
12
|
-
locale,
|
13
|
-
round = 'thin',
|
14
|
-
direction = 'rtl'
|
15
|
-
} = props
|
16
|
-
useMemo(() => localeCache.setLocale(locale), [locale])
|
17
|
-
const primaryColors = useMemo(() => makeColorPallet(accentColor), [])
|
18
|
-
|
19
|
-
const theme = {
|
20
|
-
colors: {
|
21
|
-
primary: primaryColors,
|
22
|
-
gray
|
23
|
-
},
|
24
|
-
round,
|
25
|
-
direction
|
26
|
-
}
|
27
|
-
return <ThemeProvider theme={theme}>{props.children}</ThemeProvider>
|
28
|
-
}
|
29
|
-
|
30
|
-
export default CalendarProvider
|
@@ -1,54 +0,0 @@
|
|
1
|
-
import React from 'react'
|
2
|
-
import DatePicker from './DatePicker'
|
3
|
-
import { HeaderClass } from '../../style/classNames'
|
4
|
-
|
5
|
-
describe('<DatePicker />', () => {
|
6
|
-
const initialDate = '2023 04 25'
|
7
|
-
it('renders', () => {
|
8
|
-
const onChangeSpy = cy.spy().as('onChangeSpy')
|
9
|
-
cy.mount(<DatePicker defaultValue={initialDate} onChange={onChangeSpy} />)
|
10
|
-
.get('input')
|
11
|
-
.click()
|
12
|
-
|
13
|
-
// change the year
|
14
|
-
cy.get(`.${HeaderClass}`).click()
|
15
|
-
// click on the current month
|
16
|
-
cy.findByText('۱۴۰۲').click()
|
17
|
-
// click on the mordad month
|
18
|
-
cy.findByText('مرداد').click()
|
19
|
-
// click on the mordad month
|
20
|
-
cy.findByText('۱۸').click()
|
21
|
-
cy.get('@onChangeSpy').should('have.callCount', 1)
|
22
|
-
cy.get('@onChangeSpy').should('be.calledWith', { value: new Date('Tue, 08 Aug 2023 20:30:00 GMT') })
|
23
|
-
// now input's value should be changed
|
24
|
-
cy.get('input').should('have.value', '۱۴۰۲/۰۵/۱۸')
|
25
|
-
})
|
26
|
-
it('check range renders', () => {
|
27
|
-
const onChangeSpy = cy.spy().as('onChangeSpy')
|
28
|
-
cy.mount(<DatePicker defaultValue={initialDate} onChange={onChangeSpy} range />)
|
29
|
-
.get('input')
|
30
|
-
.click()
|
31
|
-
|
32
|
-
// change the year
|
33
|
-
cy.get(`.${HeaderClass}`).click()
|
34
|
-
// click on the current month
|
35
|
-
cy.findByText('۱۴۰۲').click()
|
36
|
-
// click on the mordad month
|
37
|
-
cy.findByText('مرداد').click()
|
38
|
-
// click on the mordad month
|
39
|
-
cy.findByText('۱۸').click()
|
40
|
-
// click on the mordad month
|
41
|
-
cy.findByText('۱۹').click()
|
42
|
-
cy.get('@onChangeSpy').should('have.callCount', 1)
|
43
|
-
cy.get('@onChangeSpy').should('be.calledWith', { from: new Date('Tue, 08 Aug 2023 20:30:00 GMT'), to: new Date('Tue, 09 Aug 2023 20:30:00 GMT') })
|
44
|
-
})
|
45
|
-
it('close the DatePicker ', () => {
|
46
|
-
const onChangeSpy = cy.spy().as('onChangeSpy')
|
47
|
-
cy.mount(<DatePicker defaultValue={initialDate} onChange={onChangeSpy} />)
|
48
|
-
.get('input')
|
49
|
-
.click()
|
50
|
-
|
51
|
-
cy.get('body').click()
|
52
|
-
cy.get(`.${HeaderClass}`).should('not.exist')
|
53
|
-
})
|
54
|
-
})
|
@@ -1,127 +0,0 @@
|
|
1
|
-
import React, {useEffect, useMemo, useRef, useState} from 'react'
|
2
|
-
import RenderCalendar from '../../components/RenderCalendar'
|
3
|
-
import Calendar from '../Calendar'
|
4
|
-
import useClickOutside from '../../hooks/useClickOutside'
|
5
|
-
import formatDate from '../../utils/format'
|
6
|
-
import locales from '../../utils/locales'
|
7
|
-
import type { DatePickerProps } from './DatePicker.types'
|
8
|
-
import CalendarProvider from '../CalendarProvider/CalendarProvider'
|
9
|
-
import localeCache from '../../utils/locale'
|
10
|
-
import type { OnChangePayload } from '../Calendar/Calendar.types'
|
11
|
-
|
12
|
-
export const DatePicker = (props: DatePickerProps) => {
|
13
|
-
const {
|
14
|
-
defaultValue,
|
15
|
-
locale = 'fa',
|
16
|
-
weekends = [],
|
17
|
-
direction = 'rtl',
|
18
|
-
accentColor,
|
19
|
-
controlledValue
|
20
|
-
} = props
|
21
|
-
useMemo(() => localeCache.setLocale(locale), [locale])
|
22
|
-
// refs
|
23
|
-
const inputRef = useRef<HTMLInputElement>(null)
|
24
|
-
const containerRef = useRef<HTMLDivElement>(null)
|
25
|
-
// states
|
26
|
-
const [value, setValue] = useState<Date | undefined>(
|
27
|
-
defaultValue !== undefined ? new Date(defaultValue) : undefined
|
28
|
-
)
|
29
|
-
const [from, setFrom] = useState<Date | undefined>(
|
30
|
-
props.range === true && props.from !== undefined
|
31
|
-
? new Date(props.from)
|
32
|
-
: undefined
|
33
|
-
)
|
34
|
-
const [to, setTo] = useState<Date | undefined>(
|
35
|
-
props.range === true && props.to !== undefined
|
36
|
-
? new Date(props.to)
|
37
|
-
: undefined
|
38
|
-
)
|
39
|
-
const [showCalendar, setShowCalendar] = useState<boolean>(false)
|
40
|
-
// hooks
|
41
|
-
useEffect(() => {
|
42
|
-
if(!controlledValue || controlledValue === value) return;
|
43
|
-
setValue(controlledValue as Date)
|
44
|
-
}, [controlledValue]);
|
45
|
-
|
46
|
-
useClickOutside(containerRef, () => setShowCalendar(false))
|
47
|
-
// handlers
|
48
|
-
const toggleShowCalendar = () => {
|
49
|
-
setShowCalendar(!showCalendar)
|
50
|
-
}
|
51
|
-
|
52
|
-
const handleChangeDay = (e: OnChangePayload) => {
|
53
|
-
if (props.range === true && typeof props.onChange === 'function') {
|
54
|
-
const from = 'from' in e ? e.from : new Date()
|
55
|
-
const to = 'to' in e ? e.to : new Date()
|
56
|
-
setFrom(from)
|
57
|
-
setTo(to)
|
58
|
-
|
59
|
-
props.onChange({
|
60
|
-
from,
|
61
|
-
to
|
62
|
-
})
|
63
|
-
} else if (
|
64
|
-
(props.range === false || props.range === undefined) &&
|
65
|
-
typeof props.onChange === 'function'
|
66
|
-
) {
|
67
|
-
const value = 'value' in e ? e.value : new Date()
|
68
|
-
setValue(value)
|
69
|
-
|
70
|
-
props.onChange({
|
71
|
-
value
|
72
|
-
})
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
const getInputValue = useMemo(() => {
|
77
|
-
const format = props?.customShowDateFormat ?? locales[locale].format
|
78
|
-
if (props.range === undefined && value !== undefined) {
|
79
|
-
return formatDate(value, format)
|
80
|
-
}
|
81
|
-
console.log('from >>', from)
|
82
|
-
if (from !== undefined && to !== undefined) {
|
83
|
-
return `
|
84
|
-
${formatDate(from, format)}
|
85
|
-
-
|
86
|
-
${formatDate(to, format)}
|
87
|
-
`
|
88
|
-
}
|
89
|
-
return ''
|
90
|
-
}, [value, from, to])
|
91
|
-
return (
|
92
|
-
<CalendarProvider
|
93
|
-
accentColor={accentColor}
|
94
|
-
round={props.round}
|
95
|
-
direction={direction}
|
96
|
-
>
|
97
|
-
<input
|
98
|
-
ref={inputRef}
|
99
|
-
{...props?.inputAttributes}
|
100
|
-
onClick={toggleShowCalendar}
|
101
|
-
type="text"
|
102
|
-
value={getInputValue}
|
103
|
-
className={props.inputClass !== null ? props.inputClass : ''}
|
104
|
-
readOnly
|
105
|
-
/>
|
106
|
-
<RenderCalendar
|
107
|
-
toggleOpen={toggleShowCalendar}
|
108
|
-
showCalendar={showCalendar}
|
109
|
-
destinationRef={inputRef}
|
110
|
-
position={props.position}
|
111
|
-
>
|
112
|
-
<Calendar
|
113
|
-
defaultValue={value}
|
114
|
-
ref={containerRef}
|
115
|
-
className={props.className}
|
116
|
-
weekends={weekends}
|
117
|
-
onChange={handleChangeDay}
|
118
|
-
range={props.range}
|
119
|
-
from={props.range === true ? props.from : undefined}
|
120
|
-
to={props.range === true ? props.to : undefined}
|
121
|
-
/>
|
122
|
-
</RenderCalendar>
|
123
|
-
</CalendarProvider>
|
124
|
-
)
|
125
|
-
}
|
126
|
-
|
127
|
-
export default DatePicker
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import type { InputHTMLAttributes } from 'react'
|
2
|
-
import type {
|
3
|
-
BaseProps,
|
4
|
-
DatePickerValue,
|
5
|
-
DaysRange,
|
6
|
-
Positions
|
7
|
-
} from '../../types'
|
8
|
-
import type {
|
9
|
-
CalendarDefaultProps,
|
10
|
-
CalendarRangeProps
|
11
|
-
} from '../Calendar/Calendar.types'
|
12
|
-
|
13
|
-
export interface DatePickerBaseProps extends BaseProps {
|
14
|
-
defaultValue?: DatePickerValue
|
15
|
-
weekends?: DaysRange[]
|
16
|
-
show?: boolean
|
17
|
-
inputClass?: string
|
18
|
-
className?: string
|
19
|
-
inputAttributes?: InputHTMLAttributes<HTMLInputElement>
|
20
|
-
position?: Positions
|
21
|
-
customShowDateFormat?: string
|
22
|
-
controlledValue? : DatePickerValue
|
23
|
-
}
|
24
|
-
|
25
|
-
export type DatePickerProps = DatePickerBaseProps &
|
26
|
-
(CalendarRangeProps | CalendarDefaultProps)
|
@@ -1,77 +0,0 @@
|
|
1
|
-
import styled from '@emotion/styled'
|
2
|
-
import { radius } from '../../style/radius'
|
3
|
-
|
4
|
-
export const Clock = styled.div`
|
5
|
-
width: 260px;
|
6
|
-
height: 260px;
|
7
|
-
position: relative;
|
8
|
-
z-index: 1;
|
9
|
-
border-radius: 50%;
|
10
|
-
background-color: ${(props) => props.theme.colors.primary[95]};
|
11
|
-
`
|
12
|
-
|
13
|
-
export interface IStyledHandProps {
|
14
|
-
hour: number
|
15
|
-
minute: number
|
16
|
-
value: number
|
17
|
-
isInsideHour: boolean
|
18
|
-
isSelectingHour: boolean
|
19
|
-
}
|
20
|
-
|
21
|
-
export const Hand = styled('div')<IStyledHandProps>`
|
22
|
-
left: 50%;
|
23
|
-
width: 1.5px;
|
24
|
-
bottom: 50%;
|
25
|
-
height: ${(props) => (props.isInsideHour ? '26%' : '40%')};
|
26
|
-
position: absolute;
|
27
|
-
background-color: ${(props) => props.theme.colors.primary[85]};
|
28
|
-
transform-origin: center bottom 0;
|
29
|
-
transition: height 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
30
|
-
pointer-events: none;
|
31
|
-
${(props) =>
|
32
|
-
props.isSelectingHour
|
33
|
-
? `transform: ${`rotateZ(${(props.value / 12) * 360}deg)`}; `
|
34
|
-
: `transform: ${`rotateZ(${(props.value / 60) * 360}deg)`}; `}
|
35
|
-
`
|
36
|
-
|
37
|
-
export const HandCircle = styled('div')<{ isSelectingHour: boolean }>`
|
38
|
-
top: -22px;
|
39
|
-
right: -16px;
|
40
|
-
border: 16px solid ${(props) => props.theme.colors.primary[85]};
|
41
|
-
position: absolute;
|
42
|
-
box-sizing: content-box;
|
43
|
-
border-radius: 100%;
|
44
|
-
background-color: ${(props) => props.theme.colors.primary[85]};
|
45
|
-
pointer-events: none;
|
46
|
-
`
|
47
|
-
|
48
|
-
export const TimeWrapper = styled.div`
|
49
|
-
position: absolute;
|
50
|
-
top: 16px;
|
51
|
-
left: 16px;
|
52
|
-
display: flex;
|
53
|
-
align-items: center;
|
54
|
-
gap: 8px;
|
55
|
-
`
|
56
|
-
|
57
|
-
export const Time = styled.div`
|
58
|
-
padding: 4px 8px;
|
59
|
-
border-radius: ${(props) => radius[props.theme.round].calendarItem}px;
|
60
|
-
background-color: ${(props) => props.theme.colors.gray[20]};
|
61
|
-
`
|
62
|
-
|
63
|
-
export const ClockTimeWrapper = styled.div`
|
64
|
-
display: flex;
|
65
|
-
gap: 4px;
|
66
|
-
`
|
67
|
-
|
68
|
-
export const ClockTime = styled.div`
|
69
|
-
cursor: pointer;
|
70
|
-
font-size: 12px;
|
71
|
-
padding: 4px;
|
72
|
-
border-radius: 4px;
|
73
|
-
|
74
|
-
&.cl_selected {
|
75
|
-
background-color: ${(props) => props.theme.colors.gray[20]};
|
76
|
-
}
|
77
|
-
`
|
@@ -1,121 +0,0 @@
|
|
1
|
-
import React, { useMemo, useRef, useState } from 'react'
|
2
|
-
import RenderCalendar from '../../components/RenderCalendar'
|
3
|
-
import {
|
4
|
-
Clock,
|
5
|
-
ClockTime,
|
6
|
-
ClockTimeWrapper,
|
7
|
-
Hand,
|
8
|
-
HandCircle,
|
9
|
-
Time,
|
10
|
-
TimeWrapper
|
11
|
-
} from './TimePicker.styled'
|
12
|
-
import CalendarProvider from '../CalendarProvider/CalendarProvider'
|
13
|
-
import Numbers from './components/Numbers'
|
14
|
-
import type { TimePickerProps } from './TimePicker.types'
|
15
|
-
import localeCache from '../../utils/locale'
|
16
|
-
import CalendarWrapper from '../../components/CalendarWrapper'
|
17
|
-
import { localizeNumber } from '../../utils'
|
18
|
-
import locales from '../../utils/locales'
|
19
|
-
import useClickOutside from '../../hooks/useClickOutside'
|
20
|
-
import { useTimePicker } from '../../hooks/useTimePicker'
|
21
|
-
|
22
|
-
export const TimePicker = (props: TimePickerProps) => {
|
23
|
-
const {
|
24
|
-
defaultValue,
|
25
|
-
onChange,
|
26
|
-
round = 'x2',
|
27
|
-
locale = 'fa',
|
28
|
-
clockTime = 24
|
29
|
-
} = props
|
30
|
-
useMemo(() => localeCache.setLocale(locale), [locale])
|
31
|
-
|
32
|
-
const inputRef = useRef<HTMLInputElement>(null)
|
33
|
-
const containerRef = useRef<HTMLDivElement>(null)
|
34
|
-
|
35
|
-
const [showCalendar, setShowCalendar] = useState<boolean>(false)
|
36
|
-
const [timeConvention, setTimeConvention] = useState<'am' | 'pm'>('am')
|
37
|
-
|
38
|
-
useClickOutside(containerRef, () => setShowCalendar(false))
|
39
|
-
const toggleShowCalendar = () => {
|
40
|
-
setShowCalendar(!showCalendar)
|
41
|
-
}
|
42
|
-
const {
|
43
|
-
hour,
|
44
|
-
minute,
|
45
|
-
isInsideHour,
|
46
|
-
selectingHour,
|
47
|
-
handleMouseMove,
|
48
|
-
handleMouseUp,
|
49
|
-
handleSelecting
|
50
|
-
} = useTimePicker({ defaultValue, clockTime, timeConvention, onChange })
|
51
|
-
|
52
|
-
const getInputValue = useMemo(() => {
|
53
|
-
return `${hour}:${minute}`
|
54
|
-
}, [hour, minute])
|
55
|
-
return (
|
56
|
-
<CalendarProvider accentColor={props.accentColor} round={round}>
|
57
|
-
<input
|
58
|
-
ref={inputRef}
|
59
|
-
{...props?.inputAttributes}
|
60
|
-
onClick={toggleShowCalendar}
|
61
|
-
type="text"
|
62
|
-
value={getInputValue}
|
63
|
-
className={props.inputClass !== null ? props.inputClass : ''}
|
64
|
-
readOnly
|
65
|
-
/>
|
66
|
-
<RenderCalendar
|
67
|
-
toggleOpen={toggleShowCalendar}
|
68
|
-
showCalendar={showCalendar}
|
69
|
-
destinationRef={inputRef}
|
70
|
-
>
|
71
|
-
<CalendarWrapper ref={containerRef}>
|
72
|
-
<TimeWrapper>
|
73
|
-
{clockTime === 12 ? (
|
74
|
-
<ClockTimeWrapper>
|
75
|
-
<ClockTime
|
76
|
-
className={timeConvention === 'am' ? 'cl_selected' : ''}
|
77
|
-
onClick={() => setTimeConvention('am')}
|
78
|
-
>
|
79
|
-
{locales[locale].am}
|
80
|
-
</ClockTime>
|
81
|
-
<ClockTime
|
82
|
-
className={timeConvention === 'pm' ? 'cl_selected' : ''}
|
83
|
-
onClick={() => setTimeConvention('pm')}
|
84
|
-
>
|
85
|
-
{locales[locale].pm}
|
86
|
-
</ClockTime>
|
87
|
-
</ClockTimeWrapper>
|
88
|
-
) : null}
|
89
|
-
<Time>
|
90
|
-
{localizeNumber(hour)}:{localizeNumber(minute)}
|
91
|
-
</Time>
|
92
|
-
</TimeWrapper>
|
93
|
-
<Clock
|
94
|
-
onMouseMove={handleMouseMove}
|
95
|
-
onMouseUp={handleMouseUp}
|
96
|
-
onMouseDown={handleSelecting}
|
97
|
-
onTouchMove={handleSelecting}
|
98
|
-
onTouchEnd={handleMouseUp}
|
99
|
-
>
|
100
|
-
<Hand
|
101
|
-
value={selectingHour ? hour : minute}
|
102
|
-
hour={hour}
|
103
|
-
minute={minute}
|
104
|
-
isSelectingHour={selectingHour}
|
105
|
-
isInsideHour={isInsideHour}
|
106
|
-
>
|
107
|
-
<HandCircle isSelectingHour={selectingHour} />
|
108
|
-
</Hand>
|
109
|
-
<Numbers
|
110
|
-
insideHour={isInsideHour}
|
111
|
-
hourSelecting={selectingHour}
|
112
|
-
clockTime={clockTime}
|
113
|
-
/>
|
114
|
-
</Clock>
|
115
|
-
</CalendarWrapper>
|
116
|
-
</RenderCalendar>
|
117
|
-
</CalendarProvider>
|
118
|
-
)
|
119
|
-
}
|
120
|
-
|
121
|
-
export default TimePicker
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import type { InputHTMLAttributes } from 'react'
|
2
|
-
import type { BaseProps, DatePickerValue } from '../../types'
|
3
|
-
|
4
|
-
export interface onChangePayload {
|
5
|
-
hour: number
|
6
|
-
minute: number
|
7
|
-
timeConvention?: 'am' | 'pm'
|
8
|
-
}
|
9
|
-
|
10
|
-
export interface TimePickerProps extends BaseProps {
|
11
|
-
defaultValue?: DatePickerValue
|
12
|
-
clockTime?: 12 | 24
|
13
|
-
onChange?: (payload: onChangePayload) => void
|
14
|
-
inputClass?: string
|
15
|
-
inputAttributes?: InputHTMLAttributes<HTMLInputElement>
|
16
|
-
}
|
@@ -1,36 +0,0 @@
|
|
1
|
-
import styled from '@emotion/styled'
|
2
|
-
import { numberPositionX, numberPositionY } from '../../../../utils/timePicker'
|
3
|
-
import { fade } from '../../../../style/animation'
|
4
|
-
import type { NumbersItemProps } from './Numbers.types'
|
5
|
-
|
6
|
-
export const MinuteWithAnimation = styled('div')`
|
7
|
-
animation: ${fade} 0.7s linear alternate;
|
8
|
-
`
|
9
|
-
|
10
|
-
export const NumbersItem = styled.span<NumbersItemProps>`
|
11
|
-
left: calc(50% - 16px);
|
12
|
-
top: ${(props) => props.top};
|
13
|
-
width: 32px;
|
14
|
-
height: 32px;
|
15
|
-
display: inline-flex;
|
16
|
-
position: absolute;
|
17
|
-
align-items: center;
|
18
|
-
border-radius: 32px;
|
19
|
-
justify-content: center;
|
20
|
-
user-select: none;
|
21
|
-
pointer-events: none;
|
22
|
-
color: black;
|
23
|
-
transform: ${(props) =>
|
24
|
-
`translate(${numberPositionX(
|
25
|
-
props.idx,
|
26
|
-
props.clockHalfWidth,
|
27
|
-
props.numbersPadd
|
28
|
-
)}px,
|
29
|
-
${numberPositionY(props.idx, props.clockHalfWidth, props.numbersPadd)}px)`};
|
30
|
-
`
|
31
|
-
|
32
|
-
NumbersItem.defaultProps = {
|
33
|
-
clockHalfWidth: 130,
|
34
|
-
numbersPadd: 24,
|
35
|
-
top: '2%'
|
36
|
-
}
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import React from 'react'
|
2
|
-
import { hours, hours24, minutes } from '../../../../utils/timePicker'
|
3
|
-
import { MinuteWithAnimation, NumbersItem } from './Numbers.styled'
|
4
|
-
import { localizeNumber } from '../../../../utils'
|
5
|
-
import type { NumbersProps } from './Numbers.types'
|
6
|
-
|
7
|
-
export const Hours = (props: NumbersProps) => {
|
8
|
-
const { insideHour, hourSelecting, clockTime } = props
|
9
|
-
if (!hourSelecting) {
|
10
|
-
return (
|
11
|
-
<MinuteWithAnimation>
|
12
|
-
{minutes.map((m, i) => (
|
13
|
-
<NumbersItem key={m} idx={i}>
|
14
|
-
{localizeNumber(m)}
|
15
|
-
</NumbersItem>
|
16
|
-
))}
|
17
|
-
</MinuteWithAnimation>
|
18
|
-
)
|
19
|
-
}
|
20
|
-
if (clockTime === 12) {
|
21
|
-
return (
|
22
|
-
<>
|
23
|
-
{hours.map((h, i) => (
|
24
|
-
<NumbersItem
|
25
|
-
key={h}
|
26
|
-
idx={i}
|
27
|
-
style={{ opacity: !insideHour ? 1 : 0.3 }}
|
28
|
-
>
|
29
|
-
{localizeNumber(h)}
|
30
|
-
</NumbersItem>
|
31
|
-
))}
|
32
|
-
</>
|
33
|
-
)
|
34
|
-
}
|
35
|
-
return (
|
36
|
-
<>
|
37
|
-
{hours.map((h, i) => (
|
38
|
-
<NumbersItem
|
39
|
-
key={h}
|
40
|
-
idx={i}
|
41
|
-
top="15%"
|
42
|
-
clockHalfWidth={85}
|
43
|
-
numbersPadd={10}
|
44
|
-
style={{ opacity: insideHour ? 1 : 0.3 }}
|
45
|
-
>
|
46
|
-
{localizeNumber(h)}
|
47
|
-
</NumbersItem>
|
48
|
-
))}
|
49
|
-
{hours24.map((h, i) => (
|
50
|
-
<NumbersItem key={h} idx={i} style={{ opacity: !insideHour ? 1 : 0.3 }}>
|
51
|
-
{localizeNumber(h)}
|
52
|
-
</NumbersItem>
|
53
|
-
))}
|
54
|
-
</>
|
55
|
-
)
|
56
|
-
}
|
57
|
-
|
58
|
-
export default Hours
|
@@ -1,14 +0,0 @@
|
|
1
|
-
export interface NumbersProps {
|
2
|
-
insideHour: boolean
|
3
|
-
hourSelecting: boolean
|
4
|
-
clockTime: 12 | 24
|
5
|
-
}
|
6
|
-
|
7
|
-
export interface NumbersItemProps {
|
8
|
-
idx: number
|
9
|
-
clockHalfWidth?: number
|
10
|
-
numbersPadd?: number
|
11
|
-
top?: string
|
12
|
-
insideHour?: boolean
|
13
|
-
isSelectedNumber?: boolean
|
14
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export { default } from './Numbers'
|
package/src/style/animation.ts
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
import { keyframes } from '@emotion/react'
|
2
|
-
|
3
|
-
export const slideDown = keyframes`
|
4
|
-
from {
|
5
|
-
visibility: hidden;
|
6
|
-
opacity: 0;
|
7
|
-
transform: translateY(-4px);
|
8
|
-
}
|
9
|
-
to {
|
10
|
-
visibility: visible;
|
11
|
-
opacity: 1;
|
12
|
-
transform: translateY(0px);
|
13
|
-
}
|
14
|
-
`
|
15
|
-
|
16
|
-
export const fade = keyframes`
|
17
|
-
from {
|
18
|
-
opacity: 0;
|
19
|
-
}
|
20
|
-
to {
|
21
|
-
opacity: 1;
|
22
|
-
}
|
23
|
-
`
|
package/src/style/classNames.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
export const MonthYearButton = 'zm-MonthYearButton'
|
2
|
-
export const IconNextButton = 'zm-IconNextButton'
|
3
|
-
export const IconPrevButton = 'zm-IconPrevButton'
|
4
|
-
export const HeaderClass = 'zm-Header'
|
5
|
-
export const DaysButton = 'zm-DaysButton'
|
6
|
-
|
7
|
-
export const MonthPickerButton = 'zm-MonthPickerButton'
|
8
|
-
export const YearPickerButton = 'zm-YearPickerButton'
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import hexToHSL from './hexToHSL'
|
2
|
-
const getHsl = (h: number, s: number, l: number) => {
|
3
|
-
return `hsl(${h}deg ${s}% ${l}%)`
|
4
|
-
}
|
5
|
-
export const makeColorPallet = (accentColor: string) => {
|
6
|
-
const { h, s, l } = hexToHSL(accentColor)
|
7
|
-
const result: Record<number, string> = {}
|
8
|
-
|
9
|
-
result[40] = getHsl(h, s, l - 10)
|
10
|
-
result[50] = getHsl(h, s, l)
|
11
|
-
result[85] = getHsl(h, s, 85)
|
12
|
-
result[90] = getHsl(h, s, 90)
|
13
|
-
result[95] = getHsl(h, s, 95)
|
14
|
-
|
15
|
-
return result
|
16
|
-
}
|
package/src/style/colors.ts
DELETED