@chayns-components/date 5.0.0-beta.1000
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/LICENSE +21 -0
- package/README.md +34 -0
- package/lib/cjs/components/calendar/Calendar.js +314 -0
- package/lib/cjs/components/calendar/Calendar.js.map +1 -0
- package/lib/cjs/components/calendar/Calendar.styles.js +34 -0
- package/lib/cjs/components/calendar/Calendar.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.js +158 -0
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.styles.js +23 -0
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/Month.js +65 -0
- package/lib/cjs/components/calendar/month-wrapper/month/Month.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/Month.styles.js +26 -0
- package/lib/cjs/components/calendar/month-wrapper/month/Month.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js +129 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js +16 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.js +63 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js +114 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js +17 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js +18 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js +42 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js +16 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js +15 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js +17 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-year-pickers/MonthYearPickers.js +86 -0
- package/lib/cjs/components/calendar/month-year-pickers/MonthYearPickers.js.map +1 -0
- package/lib/cjs/components/date-info/DateInfo.js +35 -0
- package/lib/cjs/components/date-info/DateInfo.js.map +1 -0
- package/lib/cjs/components/opening-times/OpeningTimes.js +246 -0
- package/lib/cjs/components/opening-times/OpeningTimes.js.map +1 -0
- package/lib/cjs/components/opening-times/OpeningTimes.styles.js +28 -0
- package/lib/cjs/components/opening-times/OpeningTimes.styles.js.map +1 -0
- package/lib/cjs/components/opening-times/hint-text/HintText.js +19 -0
- package/lib/cjs/components/opening-times/hint-text/HintText.js.map +1 -0
- package/lib/cjs/components/opening-times/hint-text/HintText.styles.js +24 -0
- package/lib/cjs/components/opening-times/hint-text/HintText.styles.js.map +1 -0
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.js +153 -0
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.js.map +1 -0
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.styles.js +24 -0
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.styles.js.map +1 -0
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.js +106 -0
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.js.map +1 -0
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js +41 -0
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js.map +1 -0
- package/lib/cjs/hooks/useDateInfo.js +63 -0
- package/lib/cjs/hooks/useDateInfo.js.map +1 -0
- package/lib/cjs/index.js +177 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/types/calendar.js +28 -0
- package/lib/cjs/types/calendar.js.map +1 -0
- package/lib/cjs/types/dateinfo.js +2 -0
- package/lib/cjs/types/dateinfo.js.map +1 -0
- package/lib/cjs/types/openingTimes.js +18 -0
- package/lib/cjs/types/openingTimes.js.map +1 -0
- package/lib/cjs/utils/calendar.js +73 -0
- package/lib/cjs/utils/calendar.js.map +1 -0
- package/lib/cjs/utils/date.js +114 -0
- package/lib/cjs/utils/date.js.map +1 -0
- package/lib/cjs/utils/dateInfo.js +126 -0
- package/lib/cjs/utils/dateInfo.js.map +1 -0
- package/lib/esm/components/calendar/Calendar.js +306 -0
- package/lib/esm/components/calendar/Calendar.js.map +1 -0
- package/lib/esm/components/calendar/Calendar.styles.js +33 -0
- package/lib/esm/components/calendar/Calendar.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.js +150 -0
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.styles.js +22 -0
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/Month.js +61 -0
- package/lib/esm/components/calendar/month-wrapper/month/Month.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/Month.styles.js +22 -0
- package/lib/esm/components/calendar/month-wrapper/month/Month.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js +121 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js +9 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.js +54 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js +123 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js +13 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js +14 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js +34 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js +9 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js +11 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js +13 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-year-pickers/MonthYearPickers.js +79 -0
- package/lib/esm/components/calendar/month-year-pickers/MonthYearPickers.js.map +1 -0
- package/lib/esm/components/date-info/DateInfo.js +28 -0
- package/lib/esm/components/date-info/DateInfo.js.map +1 -0
- package/lib/esm/components/opening-times/OpeningTimes.js +240 -0
- package/lib/esm/components/opening-times/OpeningTimes.js.map +1 -0
- package/lib/esm/components/opening-times/OpeningTimes.styles.js +24 -0
- package/lib/esm/components/opening-times/OpeningTimes.styles.js.map +1 -0
- package/lib/esm/components/opening-times/hint-text/HintText.js +12 -0
- package/lib/esm/components/opening-times/hint-text/HintText.js.map +1 -0
- package/lib/esm/components/opening-times/hint-text/HintText.styles.js +23 -0
- package/lib/esm/components/opening-times/hint-text/HintText.styles.js.map +1 -0
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.js +149 -0
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.js.map +1 -0
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.styles.js +22 -0
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.styles.js.map +1 -0
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.js +99 -0
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.js.map +1 -0
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js +40 -0
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js.map +1 -0
- package/lib/esm/hooks/useDateInfo.js +57 -0
- package/lib/esm/hooks/useDateInfo.js.map +1 -0
- package/lib/esm/index.js +15 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/types/calendar.js +22 -0
- package/lib/esm/types/calendar.js.map +1 -0
- package/lib/esm/types/dateinfo.js +2 -0
- package/lib/esm/types/dateinfo.js.map +1 -0
- package/lib/esm/types/openingTimes.js +12 -0
- package/lib/esm/types/openingTimes.js.map +1 -0
- package/lib/esm/utils/calendar.js +63 -0
- package/lib/esm/utils/calendar.js.map +1 -0
- package/lib/esm/utils/date.js +89 -0
- package/lib/esm/utils/date.js.map +1 -0
- package/lib/esm/utils/dateInfo.js +120 -0
- package/lib/esm/utils/dateInfo.js.map +1 -0
- package/lib/types/components/calendar/Calendar.d.ts +97 -0
- package/lib/types/components/calendar/Calendar.styles.d.ts +8 -0
- package/lib/types/components/calendar/month-wrapper/MonthWrapper.d.ts +26 -0
- package/lib/types/components/calendar/month-wrapper/MonthWrapper.styles.d.ts +274 -0
- package/lib/types/components/calendar/month-wrapper/month/Month.d.ts +26 -0
- package/lib/types/components/calendar/month-wrapper/month/Month.styles.d.ts +8 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.d.ts +20 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.d.ts +1 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/Day.d.ts +19 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.d.ts +20 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.d.ts +6 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.d.ts +7 -0
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.d.ts +7 -0
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.d.ts +1 -0
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.d.ts +6 -0
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.d.ts +3 -0
- package/lib/types/components/calendar/month-year-pickers/MonthYearPickers.d.ts +19 -0
- package/lib/types/components/date-info/DateInfo.d.ts +5 -0
- package/lib/types/components/opening-times/OpeningTimes.d.ts +51 -0
- package/lib/types/components/opening-times/OpeningTimes.styles.d.ts +11 -0
- package/lib/types/components/opening-times/hint-text/HintText.d.ts +6 -0
- package/lib/types/components/opening-times/hint-text/HintText.styles.d.ts +3 -0
- package/lib/types/components/opening-times/opening-inputs/OpeningInputs.d.ts +46 -0
- package/lib/types/components/opening-times/opening-inputs/OpeningInputs.styles.d.ts +272 -0
- package/lib/types/components/opening-times/opening-inputs/opening-input/OpeningInput.d.ts +15 -0
- package/lib/types/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.d.ts +273 -0
- package/lib/types/hooks/useDateInfo.d.ts +2 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/types/calendar.d.ts +55 -0
- package/lib/types/types/dateinfo.d.ts +34 -0
- package/lib/types/types/openingTimes.d.ts +33 -0
- package/lib/types/utils/calendar.d.ts +18 -0
- package/lib/types/utils/date.d.ts +27 -0
- package/lib/types/utils/dateInfo.d.ts +14 -0
- package/package.json +86 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpeningInputs.js","names":["AnimatePresence","React","useCallback","useEffect","useMemo","useState","v4","uuidV4","OpeningTimesButtonType","OpeningInput","StyledOpeningInputPreview","StyledOpeningInputs","OpeningInputs","_ref","times","isDisabled","onRemove","onAdd","onInvalid","id","onChange","currentDayId","editMode","closedText","newTimes","setNewTimes","invalidTimes","setInvalidTimes","handleAdd","defaultTime","start","end","prevState","handleRemove","timeId","filter","time","result","i","length","currentTime","prevTime","currStart","Date","currEnd","push","prevEnd","invalidTimeIds","map","_ref2","invalidId","handleChange","newTime","updatedTimes","content","items","forEach","_ref3","index","text","createElement","key","buttonType","NONE","ADD","REMOVE","isInvalid","includes","gap","$editMode","animate","initial","displayName"],"sources":["../../../../../src/components/opening-times/opening-inputs/OpeningInputs.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, { FC, useCallback, useEffect, useMemo, useState, type ReactElement } from 'react';\nimport { v4 as uuidV4 } from 'uuid';\nimport { OpeningTimesButtonType, type OpeningTime, type Time } from '../../../types/openingTimes';\nimport OpeningInput from './opening-input/OpeningInput';\nimport { StyledOpeningInputPreview, StyledOpeningInputs } from './OpeningInputs.styles';\n\nexport type OpeningInputsProps = {\n /**\n * Array of opening times\n */\n times: Time[];\n /**\n * If the inputs are disabled\n */\n isDisabled?: boolean;\n /**\n * Function that is called when a time is changed\n */\n onChange?: (time: Time) => void;\n /**\n * Function that is called when a new time is added\n */\n onAdd?: (time: Time, id: string) => void;\n /**\n * Function that is called when a time is removed\n */\n onRemove?: (id: Time['id']) => void;\n /**\n * Function that is called when the times are invalid\n */\n onInvalid?: (openingTimeId: string, timeIds: string[]) => void;\n /**\n * The id of the opening time\n */\n id: string;\n /**\n * The id of the current day\n */\n currentDayId?: OpeningTime['id'];\n /**\n * If the edit mode is enabled\n */\n editMode?: boolean;\n /**\n * The text to show when the inputs are disabled\n */\n closedText?: string;\n};\n\nconst OpeningInputs: FC<OpeningInputsProps> = ({\n times,\n isDisabled,\n onRemove,\n onAdd,\n onInvalid,\n id,\n onChange,\n currentDayId,\n editMode = false,\n closedText = '',\n}) => {\n const [newTimes, setNewTimes] = useState<Time[]>();\n const [invalidTimes, setInvalidTimes] = useState<string[]>([]);\n\n useEffect(() => {\n setNewTimes(times);\n }, [times]);\n\n const handleAdd = useCallback(() => {\n const defaultTime: Time = { start: '08:00', end: '18:00', id: uuidV4() };\n\n setNewTimes((prevState) => (prevState ? [...prevState, defaultTime] : [defaultTime]));\n\n if (typeof onAdd === 'function') {\n onAdd(defaultTime, id);\n }\n }, [id, onAdd]);\n\n const handleRemove = useCallback(\n (timeId: string) => {\n setNewTimes((prevState) => (prevState ?? []).filter((time) => time.id !== timeId));\n\n if (typeof onRemove === 'function') {\n onRemove(timeId);\n }\n },\n [onRemove],\n );\n\n useEffect(() => {\n const result: Time[] = [];\n\n for (let i = 0; i < times.length; i++) {\n const currentTime = times[i];\n const prevTime = times[i - 1];\n\n if (currentTime) {\n const currStart = new Date(`2000-01-01T${currentTime.start}`);\n const currEnd = new Date(`2000-01-01T${currentTime.end}`);\n\n if (currStart >= currEnd) {\n result.push(currentTime);\n }\n\n if (prevTime) {\n const prevEnd = new Date(`2000-01-01T${prevTime.end}`);\n\n if (prevEnd > currStart) {\n result.push(prevTime, currentTime);\n }\n }\n }\n }\n\n const invalidTimeIds = result.map(({ id: invalidId }) => invalidId);\n\n setInvalidTimes(invalidTimeIds);\n\n if (typeof onInvalid === 'function') {\n onInvalid(id, invalidTimeIds);\n }\n }, [id, onInvalid, times]);\n\n const handleChange = useCallback(\n (newTime: Time) => {\n setNewTimes((prevState) => {\n const updatedTimes = (prevState ?? []).map((time) => {\n if (time.id === newTime.id) {\n return newTime;\n }\n return time;\n });\n\n if (typeof onChange === 'function') {\n onChange(newTime);\n }\n\n return updatedTimes;\n });\n },\n [onChange],\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n if (!newTimes) {\n return items;\n }\n\n newTimes.forEach(({ end, start, id: timeId }, index) => {\n if (!editMode) {\n const text = isDisabled ? closedText : `${start} - ${end}`;\n\n items.push(\n <StyledOpeningInputPreview key={`opening-times-preview__${id}.${timeId}`}>\n {`${text}${currentDayId && newTimes.length > 1 && index === 0 ? ', ' : ''}`}\n </StyledOpeningInputPreview>,\n );\n\n return;\n }\n\n if (index > 1) {\n return;\n }\n\n let buttonType = OpeningTimesButtonType.NONE;\n\n if (index === 0 && times.length === 1 && !isDisabled) {\n buttonType = OpeningTimesButtonType.ADD;\n } else if (index === 1 && !isDisabled) {\n buttonType = OpeningTimesButtonType.REMOVE;\n }\n\n items.push(\n <OpeningInput\n key={`opening-times-input__${id}.${timeId}`}\n start={start}\n id={timeId}\n end={end}\n isDisabled={isDisabled}\n isInvalid={invalidTimes.includes(timeId)}\n buttonType={buttonType}\n onAdd={handleAdd}\n onChange={(time) => handleChange(time)}\n onRemove={() => handleRemove(timeId)}\n />,\n );\n });\n\n return items;\n }, [\n closedText,\n currentDayId,\n editMode,\n handleAdd,\n handleChange,\n handleRemove,\n id,\n invalidTimes,\n isDisabled,\n newTimes,\n times.length,\n ]);\n\n const gap = useMemo(() => {\n if ((newTimes && newTimes.length > 1 && editMode) || (!editMode && currentDayId)) {\n return '8px';\n }\n\n return 0;\n }, [currentDayId, editMode, newTimes]);\n\n return useMemo(\n () => (\n <StyledOpeningInputs\n $editMode={!currentDayId}\n key={`opening-inputs__${id}`}\n animate={{ gap }}\n initial={{ gap: 0 }}\n >\n <AnimatePresence initial={false}>{content}</AnimatePresence>\n </StyledOpeningInputs>\n ),\n [content, currentDayId, gap, id],\n );\n};\n\nOpeningInputs.displayName = 'OpeningInputs';\n\nexport default OpeningInputs;\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,eAAe;AAC/C,OAAOC,KAAK,IAAQC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAA2B,OAAO;AAC/F,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AACnC,SAASC,sBAAsB,QAAqC,6BAA6B;AACjG,OAAOC,YAAY,MAAM,8BAA8B;AACvD,SAASC,yBAAyB,EAAEC,mBAAmB,QAAQ,wBAAwB;AA6CvF,MAAMC,aAAqC,GAAGC,IAAA,IAWxC;EAAA,IAXyC;IAC3CC,KAAK;IACLC,UAAU;IACVC,QAAQ;IACRC,KAAK;IACLC,SAAS;IACTC,EAAE;IACFC,QAAQ;IACRC,YAAY;IACZC,QAAQ,GAAG,KAAK;IAChBC,UAAU,GAAG;EACjB,CAAC,GAAAV,IAAA;EACG,MAAM,CAACW,QAAQ,EAAEC,WAAW,CAAC,GAAGpB,QAAQ,CAAS,CAAC;EAClD,MAAM,CAACqB,YAAY,EAAEC,eAAe,CAAC,GAAGtB,QAAQ,CAAW,EAAE,CAAC;EAE9DF,SAAS,CAAC,MAAM;IACZsB,WAAW,CAACX,KAAK,CAAC;EACtB,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX,MAAMc,SAAS,GAAG1B,WAAW,CAAC,MAAM;IAChC,MAAM2B,WAAiB,GAAG;MAAEC,KAAK,EAAE,OAAO;MAAEC,GAAG,EAAE,OAAO;MAA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AE;QACvCpB,QAAQ,EAAEA,CAAA,KAAMiB,YAAY,CAACC,MAAM;MAAE,CACxC,CACL,CAAC;IACL,CAAC,CAAC;IAEF,OAAOqB,KAAK;EAChB,CAAC,EAAE,CACChC,UAAU,EACVF,YAAY,EACZC,QAAQ,EACRM,SAAS,EACTuB,YAAY,EACZlB,YAAY,EACZd,EAAE,EACFO,YAAY,EACZX,UAAU,EACVS,QAAQ,EACRV,KAAK,CAACyB,MAAM,CACf,CAAC;EAEF,MAAM6B,GAAG,GAAGhE,OAAO,CAAC,MAAM;IACtB,IAAKoB,QAAQ,IAAIA,QAAQ,CAACe,MAAM,GAAG,CAAC,IAAIjB,QAAQ,IAAM,CAACA,QAAQ,IAAID,YAAa,EAAE;MAC9E,OAAO,KAAK;IAChB;IAEA,OAAO,CAAC;EACZ,CAAC,EAAE,CAACA,YAAY,EAAEC,QAAQ,EAAEE,QAAQ,CAAC,CAAC;EAEtC,OAAOpB,OAAO,CACV,mBACIH,KAAA,CAAA2D,aAAA,CAACjD,mBAAmB;IAChB0D,SAAS,EAAE,CAAChD,YAAa;IACzBwC,GAAG,EAAE,mBAAmB1C,EAAE,EAAG;IAC7BmD,OAAO,EAAE;MAAEF;IAAI,CAAE;IACjBG,OAAO,EAAE;MAAEH,GAAG,EAAE;IAAE;EAAE,gBAEpBnE,KAAA,CAAA2D,aAAA,CAAC5D,eAAe;IAACuE,OAAO,EAAE;EAAM,GAAEjB,OAAyB,CAC1C,CACxB,EACD,CAACA,OAAO,EAAEjC,YAAY,EAAE+C,GAAG,EAAEjD,EAAE,CACnC,CAAC;AACL,CAAC;AAEDP,aAAa,CAAC4D,WAAW,GAAG,eAAe;AAE3C,eAAe5D,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { motion } from 'framer-motion';
|
|
2
|
+
import styled, { css } from 'styled-components';
|
|
3
|
+
export const StyledOpeningInputs = styled(motion.div)`
|
|
4
|
+
display: flex;
|
|
5
|
+
${_ref => {
|
|
6
|
+
let {
|
|
7
|
+
$editMode
|
|
8
|
+
} = _ref;
|
|
9
|
+
return $editMode && css`
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
`;
|
|
12
|
+
}}
|
|
13
|
+
`;
|
|
14
|
+
export const StyledOpeningInputPreview = styled.div`
|
|
15
|
+
color: ${_ref2 => {
|
|
16
|
+
let {
|
|
17
|
+
theme
|
|
18
|
+
} = _ref2;
|
|
19
|
+
return theme.text;
|
|
20
|
+
}};
|
|
21
|
+
`;
|
|
22
|
+
//# sourceMappingURL=OpeningInputs.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpeningInputs.styles.js","names":["motion","styled","css","StyledOpeningInputs","div","_ref","$editMode","StyledOpeningInputPreview","_ref2","theme","text"],"sources":["../../../../../src/components/opening-times/opening-inputs/OpeningInputs.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\n\ntype StyledOpeningInputsProps = WithTheme<{ $editMode: boolean }>;\n\nexport const StyledOpeningInputs = styled(motion.div)<StyledOpeningInputsProps>`\n display: flex;\n ${({ $editMode }) =>\n $editMode &&\n css`\n flex-direction: column;\n `}\n`;\n\ntype StyledOpeningInputPreviewProps = WithTheme<unknown>;\n\nexport const StyledOpeningInputPreview = styled.div<StyledOpeningInputPreviewProps>`\n color: ${({ theme }: StyledOpeningInputPreviewProps) => theme.text};\n`;\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAI/C,OAAO,MAAMC,mBAAmB,GAAGF,MAAM,CAACD,MAAM,CAACI,GAAG,CAA2B;AAC/E;AACA,MAAMC,IAAA;EAAA,IAAC;IAAEC;EAAU,CAAC,GAAAD,IAAA;EAAA,OACZC,SAAS,IACTJ,GAAG;AACX;AACA,SAAS;AAAA;AACT,CAAC;AAID,OAAO,MAAMK,yBAAyB,GAAGN,MAAM,CAACG,GAAmC;AACnF,aAAaI,KAAA;EAAA,IAAC;IAAEC;EAAsC,CAAC,GAAAD,KAAA;EAAA,OAAKC,KAAK,CAACC,IAAI;AAAA;AACtE,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Icon, NumberInput } from '@chayns-components/core';
|
|
2
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import { OpeningTimesButtonType } from '../../../../types/openingTimes';
|
|
4
|
+
import { StyledOpeningInput, StyledOpeningInputButtonWrapper, StyledOpeningInputPseudoButton, StyledOpeningInputText, StyledOpeningInputWrapper } from './OpeningInput.styles';
|
|
5
|
+
const OpeningInput = _ref => {
|
|
6
|
+
let {
|
|
7
|
+
end,
|
|
8
|
+
start,
|
|
9
|
+
isDisabled,
|
|
10
|
+
isInvalid,
|
|
11
|
+
buttonType,
|
|
12
|
+
onRemove,
|
|
13
|
+
onAdd,
|
|
14
|
+
onChange,
|
|
15
|
+
id
|
|
16
|
+
} = _ref;
|
|
17
|
+
const [startTime, setStartTime] = useState(start);
|
|
18
|
+
const [endTime, setEndTime] = useState(end);
|
|
19
|
+
const button = useMemo(() => {
|
|
20
|
+
switch (buttonType) {
|
|
21
|
+
case OpeningTimesButtonType.ADD:
|
|
22
|
+
return /*#__PURE__*/React.createElement(StyledOpeningInputButtonWrapper, {
|
|
23
|
+
onClick: onAdd
|
|
24
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
25
|
+
icons: ['ts-plus'],
|
|
26
|
+
size: 15
|
|
27
|
+
}));
|
|
28
|
+
case OpeningTimesButtonType.REMOVE:
|
|
29
|
+
return /*#__PURE__*/React.createElement(StyledOpeningInputButtonWrapper, {
|
|
30
|
+
onClick: onRemove
|
|
31
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
32
|
+
icons: ['ts-wrong'],
|
|
33
|
+
size: 15
|
|
34
|
+
}));
|
|
35
|
+
default:
|
|
36
|
+
return /*#__PURE__*/React.createElement(StyledOpeningInputPseudoButton, null);
|
|
37
|
+
}
|
|
38
|
+
}, [buttonType, onAdd, onRemove]);
|
|
39
|
+
const handleStartTimeBlur = useCallback((value, isTimeInvalid) => {
|
|
40
|
+
if (isTimeInvalid || typeof value === 'number' || !value) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
setStartTime(value);
|
|
44
|
+
onChange({
|
|
45
|
+
end: endTime,
|
|
46
|
+
start: value,
|
|
47
|
+
id
|
|
48
|
+
});
|
|
49
|
+
}, [endTime, id, onChange]);
|
|
50
|
+
const handleEndTimeBlur = useCallback((value, isTimeInvalid) => {
|
|
51
|
+
if (isTimeInvalid || typeof value === 'number' || !value) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setEndTime(value);
|
|
55
|
+
onChange({
|
|
56
|
+
end: value,
|
|
57
|
+
start: startTime,
|
|
58
|
+
id
|
|
59
|
+
});
|
|
60
|
+
}, [id, onChange, startTime]);
|
|
61
|
+
return useMemo(() => /*#__PURE__*/React.createElement(StyledOpeningInput, {
|
|
62
|
+
key: id,
|
|
63
|
+
animate: {
|
|
64
|
+
opacity: 1,
|
|
65
|
+
height: 'auto'
|
|
66
|
+
},
|
|
67
|
+
initial: {
|
|
68
|
+
opacity: 0,
|
|
69
|
+
height: 0
|
|
70
|
+
},
|
|
71
|
+
exit: {
|
|
72
|
+
opacity: 0,
|
|
73
|
+
height: 0
|
|
74
|
+
},
|
|
75
|
+
transition: {
|
|
76
|
+
duration: 0.2,
|
|
77
|
+
type: 'tween'
|
|
78
|
+
}
|
|
79
|
+
}, /*#__PURE__*/React.createElement(StyledOpeningInputWrapper, null, /*#__PURE__*/React.createElement(NumberInput, {
|
|
80
|
+
shouldShowOnlyBottomBorder: true,
|
|
81
|
+
isTimeInput: true,
|
|
82
|
+
isInvalid: isInvalid,
|
|
83
|
+
value: startTime,
|
|
84
|
+
onBlur: handleStartTimeBlur,
|
|
85
|
+
isDisabled: isDisabled
|
|
86
|
+
})), /*#__PURE__*/React.createElement(StyledOpeningInputText, {
|
|
87
|
+
$isDisabled: isDisabled
|
|
88
|
+
}, "-"), /*#__PURE__*/React.createElement(StyledOpeningInputWrapper, null, /*#__PURE__*/React.createElement(NumberInput, {
|
|
89
|
+
shouldShowOnlyBottomBorder: true,
|
|
90
|
+
isTimeInput: true,
|
|
91
|
+
isInvalid: isInvalid,
|
|
92
|
+
value: endTime,
|
|
93
|
+
onBlur: handleEndTimeBlur,
|
|
94
|
+
isDisabled: isDisabled
|
|
95
|
+
})), button), [button, endTime, handleEndTimeBlur, handleStartTimeBlur, id, isDisabled, isInvalid, startTime]);
|
|
96
|
+
};
|
|
97
|
+
OpeningInput.displayName = 'OpeningInput';
|
|
98
|
+
export default OpeningInput;
|
|
99
|
+
//# sourceMappingURL=OpeningInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpeningInput.js","names":["Icon","NumberInput","React","useCallback","useMemo","useState","OpeningTimesButtonType","StyledOpeningInput","StyledOpeningInputButtonWrapper","StyledOpeningInputPseudoButton","StyledOpeningInputText","StyledOpeningInputWrapper","OpeningInput","_ref","end","start","isDisabled","isInvalid","buttonType","onRemove","onAdd","onChange","id","startTime","setStartTime","endTime","setEndTime","button","ADD","createElement","onClick","icons","size","REMOVE","handleStartTimeBlur","value","isTimeInvalid","handleEndTimeBlur","key","animate","opacity","height","initial","exit","transition","duration","type","shouldShowOnlyBottomBorder","isTimeInput","onBlur","$isDisabled","displayName"],"sources":["../../../../../../src/components/opening-times/opening-inputs/opening-input/OpeningInput.tsx"],"sourcesContent":["import { Icon, NumberInput } from '@chayns-components/core';\nimport React, { FC, useCallback, useMemo, useState } from 'react';\nimport { OpeningTimesButtonType, type Time } from '../../../../types/openingTimes';\nimport {\n StyledOpeningInput,\n StyledOpeningInputButtonWrapper,\n StyledOpeningInputPseudoButton,\n StyledOpeningInputText,\n StyledOpeningInputWrapper,\n} from './OpeningInput.styles';\n\nexport type OpeningInputProps = {\n start: Time['start'];\n end: Time['end'];\n isDisabled?: boolean;\n isInvalid?: boolean;\n id: string;\n buttonType: OpeningTimesButtonType;\n onAdd: () => void;\n onRemove: () => void;\n onChange: (time: Time) => void;\n};\n\nconst OpeningInput: FC<OpeningInputProps> = ({\n end,\n start,\n isDisabled,\n isInvalid,\n buttonType,\n onRemove,\n onAdd,\n onChange,\n id,\n}) => {\n const [startTime, setStartTime] = useState(start);\n const [endTime, setEndTime] = useState(end);\n\n const button = useMemo(() => {\n switch (buttonType) {\n case OpeningTimesButtonType.ADD:\n return (\n <StyledOpeningInputButtonWrapper onClick={onAdd}>\n <Icon icons={['ts-plus']} size={15} />\n </StyledOpeningInputButtonWrapper>\n );\n case OpeningTimesButtonType.REMOVE:\n return (\n <StyledOpeningInputButtonWrapper onClick={onRemove}>\n <Icon icons={['ts-wrong']} size={15} />\n </StyledOpeningInputButtonWrapper>\n );\n default:\n return <StyledOpeningInputPseudoButton />;\n }\n }, [buttonType, onAdd, onRemove]);\n\n const handleStartTimeBlur = useCallback(\n (value: string | number | null, isTimeInvalid: boolean) => {\n if (isTimeInvalid || typeof value === 'number' || !value) {\n return;\n }\n\n setStartTime(value);\n\n onChange({ end: endTime, start: value, id });\n },\n [endTime, id, onChange],\n );\n\n const handleEndTimeBlur = useCallback(\n (value: string | number | null, isTimeInvalid: boolean) => {\n if (isTimeInvalid || typeof value === 'number' || !value) {\n return;\n }\n\n setEndTime(value);\n\n onChange({ end: value, start: startTime, id });\n },\n [id, onChange, startTime],\n );\n\n return useMemo(\n () => (\n <StyledOpeningInput\n key={id}\n animate={{ opacity: 1, height: 'auto' }}\n initial={{ opacity: 0, height: 0 }}\n exit={{ opacity: 0, height: 0 }}\n transition={{ duration: 0.2, type: 'tween' }}\n >\n <StyledOpeningInputWrapper>\n <NumberInput\n shouldShowOnlyBottomBorder\n isTimeInput\n isInvalid={isInvalid}\n value={startTime}\n onBlur={handleStartTimeBlur}\n isDisabled={isDisabled}\n />\n </StyledOpeningInputWrapper>\n <StyledOpeningInputText $isDisabled={isDisabled}>-</StyledOpeningInputText>\n <StyledOpeningInputWrapper>\n <NumberInput\n shouldShowOnlyBottomBorder\n isTimeInput\n isInvalid={isInvalid}\n value={endTime}\n onBlur={handleEndTimeBlur}\n isDisabled={isDisabled}\n />\n </StyledOpeningInputWrapper>\n {button}\n </StyledOpeningInput>\n ),\n [\n button,\n endTime,\n handleEndTimeBlur,\n handleStartTimeBlur,\n id,\n isDisabled,\n isInvalid,\n startTime,\n ],\n );\n};\n\nOpeningInput.displayName = 'OpeningInput';\n\nexport default OpeningInput;\n"],"mappings":"AAAA,SAASA,IAAI,EAAEC,WAAW,QAAQ,yBAAyB;AAC3D,OAAOC,KAAK,IAAQC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACjE,SAASC,sBAAsB,QAAmB,gCAAgC;AAClF,SACIC,kBAAkB,EAClBC,+BAA+B,EAC/BC,8BAA8B,EAC9BC,sBAAsB,EACtBC,yBAAyB,QACtB,uBAAuB;AAc9B,MAAMC,YAAmC,GAAGC,IAAA,IAUtC;EAAA,IAVuC;IACzCC,GAAG;IACHC,KAAK;IACLC,UAAU;IACVC,SAAS;IACTC,UAAU;IACVC,QAAQ;IACRC,KAAK;IACLC,QAAQ;IACRC;EACJ,CAAC,GAAAT,IAAA;EACG,MAAM,CAACU,SAAS,EAAEC,YAAY,CAAC,GAAGnB,QAAQ,CAACU,KAAK,CAAC;EACjD,MAAM,CAACU,OAAO,EAAEC,UAAU,CAAC,GAAGrB,QAAQ,CAACS,GAAG,CAAC;EAE3C,MAAMa,MAAM,GAAGvB,OAAO,CAAC,MAAM;IACzB,QAAQc,UAAU;MACd,KAAKZ,sBAAsB,CAACsB,GAAG;QAC3B,oBACI1B,KAAA,CAAA2B,aAAA,CAACrB,+BAA+B;UAACsB,OAAO,EAAEV;QAAM,gBAC5ClB,KAAA,CAAA2B,aAAA,CAAC7B,IAAI;UAAC+B,KAAK,EAAE,CA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
+
import styled from 'styled-components';
|
|
3
|
+
export const StyledOpeningInput = styled(motion.div)`
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: 6px;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
`;
|
|
9
|
+
export const StyledOpeningInputWrapper = styled.div`
|
|
10
|
+
width: 60px;
|
|
11
|
+
`;
|
|
12
|
+
export const StyledOpeningInputText = styled.div`
|
|
13
|
+
opacity: ${_ref => {
|
|
14
|
+
let {
|
|
15
|
+
$isDisabled
|
|
16
|
+
} = _ref;
|
|
17
|
+
return $isDisabled ? 0.5 : 1;
|
|
18
|
+
}};
|
|
19
|
+
`;
|
|
20
|
+
export const StyledOpeningInputButtonWrapper = styled.div`
|
|
21
|
+
width: 20px;
|
|
22
|
+
height: 20px;
|
|
23
|
+
background-color: ${_ref2 => {
|
|
24
|
+
let {
|
|
25
|
+
theme
|
|
26
|
+
} = _ref2;
|
|
27
|
+
return theme['202'];
|
|
28
|
+
}};
|
|
29
|
+
border-radius: 3px;
|
|
30
|
+
box-shadow: 1px 2px 3px rgba(0, 0, 0, 0.2);
|
|
31
|
+
border: none;
|
|
32
|
+
cursor: pointer;
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
`;
|
|
37
|
+
export const StyledOpeningInputPseudoButton = styled.div`
|
|
38
|
+
width: 20px;
|
|
39
|
+
`;
|
|
40
|
+
//# sourceMappingURL=OpeningInput.styles.js.map
|
package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpeningInput.styles.js","names":["motion","styled","StyledOpeningInput","div","StyledOpeningInputWrapper","StyledOpeningInputText","_ref","$isDisabled","StyledOpeningInputButtonWrapper","_ref2","theme","StyledOpeningInputPseudoButton"],"sources":["../../../../../../src/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport { motion } from 'framer-motion';\nimport styled from 'styled-components';\n\nexport const StyledOpeningInput = styled(motion.div)`\n display: flex;\n align-items: center;\n gap: 6px;\n overflow: hidden;\n`;\n\nexport const StyledOpeningInputWrapper = styled.div`\n width: 60px;\n`;\n\ntype StyledOpeningInputTextProps = WithTheme<{ $isDisabled?: boolean }>;\n\nexport const StyledOpeningInputText = styled.div<StyledOpeningInputTextProps>`\n opacity: ${({ $isDisabled }) => ($isDisabled ? 0.5 : 1)};\n`;\n\ntype StyledOpeningInputButtonWrapperProps = WithTheme<unknown>;\n\nexport const StyledOpeningInputButtonWrapper = styled.div`\n width: 20px;\n height: 20px;\n background-color: ${({ theme }: StyledOpeningInputButtonWrapperProps) => theme['202']};\n border-radius: 3px;\n box-shadow: 1px 2px 3px rgba(0, 0, 0, 0.2);\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n`;\n\nexport const StyledOpeningInputPseudoButton = styled.div`\n width: 20px;\n`;\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,MAAM,mBAAmB;AAEtC,OAAO,MAAMC,kBAAkB,GAAGD,MAAM,CAACD,MAAM,CAACG,GAAG,CAAC;AACpD;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,yBAAyB,GAAGH,MAAM,CAACE,GAAG;AACnD;AACA,CAAC;AAID,OAAO,MAAME,sBAAsB,GAAGJ,MAAM,CAACE,GAAgC;AAC7E,eAAeG,IAAA;EAAA,IAAC;IAAEC;EAAY,CAAC,GAAAD,IAAA;EAAA,OAAMC,WAAW,GAAG,GAAG,GAAG,CAAC;AAAA,CAAC;AAC3D,CAAC;AAID,OAAO,MAAMC,+BAA+B,GAAGP,MAAM,CAACE,GAAG;AACzD;AACA;AACA,wBAAwBM,KAAA;EAAA,IAAC;IAAEC;EAA4C,CAAC,GAAAD,KAAA;EAAA,OAAKC,KAAK,CAAC,KAAK,CAAC;AAAA;AACzF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,8BAA8B,GAAGV,MAAM,CAACE,GAAG;AACxD;AACA,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getLanguage } from 'chayns-api';
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { getDateInfo, getTimeTillNow } from '../utils/dateInfo';
|
|
4
|
+
export const useDateInfo = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
date,
|
|
7
|
+
shouldShowDateToNowDifference,
|
|
8
|
+
shouldShowRelativeDayOfWeek,
|
|
9
|
+
shouldShowDayOfWeek,
|
|
10
|
+
shouldShowTime,
|
|
11
|
+
shouldUseShortText,
|
|
12
|
+
shouldShowYear,
|
|
13
|
+
preText
|
|
14
|
+
} = _ref;
|
|
15
|
+
const {
|
|
16
|
+
active: language
|
|
17
|
+
} = getLanguage();
|
|
18
|
+
const [formattedDate, setFormattedDate] = useState(date.toLocaleDateString());
|
|
19
|
+
const [currentDate, setCurrentDate] = useState(new Date());
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (shouldShowDateToNowDifference) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
setFormattedDate(getDateInfo({
|
|
25
|
+
date,
|
|
26
|
+
shouldShowYear,
|
|
27
|
+
shouldShowTime,
|
|
28
|
+
shouldUseShortText,
|
|
29
|
+
shouldShowDayOfWeek,
|
|
30
|
+
shouldShowRelativeDayOfWeek
|
|
31
|
+
}));
|
|
32
|
+
}, [date, shouldShowDateToNowDifference, shouldShowDayOfWeek, shouldShowRelativeDayOfWeek, shouldShowTime, shouldShowYear, shouldUseShortText]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!shouldShowDateToNowDifference) return () => {};
|
|
35
|
+
const updateCurrentDate = () => setCurrentDate(new Date());
|
|
36
|
+
const now = new Date();
|
|
37
|
+
const timeDiffInMs = Math.abs(date.getTime() - now.getTime());
|
|
38
|
+
const updateInterval = timeDiffInMs < 60000 ? 1000 : 60000 - now.getSeconds() * 1000;
|
|
39
|
+
const intervalId = setInterval(updateCurrentDate, 1000);
|
|
40
|
+
const timeout = setTimeout(updateCurrentDate, updateInterval);
|
|
41
|
+
return () => {
|
|
42
|
+
clearTimeout(timeout);
|
|
43
|
+
clearInterval(intervalId);
|
|
44
|
+
};
|
|
45
|
+
}, [date, shouldShowDateToNowDifference]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (shouldShowDateToNowDifference) {
|
|
48
|
+
setFormattedDate(getTimeTillNow({
|
|
49
|
+
date,
|
|
50
|
+
currentDate,
|
|
51
|
+
language
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
}, [date, currentDate, language, shouldShowDateToNowDifference]);
|
|
55
|
+
return useMemo(() => `${preText ? `${preText.trim()} ` : ''}${formattedDate}`, [formattedDate, preText]);
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=useDateInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDateInfo.js","names":["getLanguage","useEffect","useMemo","useState","getDateInfo","getTimeTillNow","useDateInfo","_ref","date","shouldShowDateToNowDifference","shouldShowRelativeDayOfWeek","shouldShowDayOfWeek","shouldShowTime","shouldUseShortText","shouldShowYear","preText","active","language","formattedDate","setFormattedDate","toLocaleDateString","currentDate","setCurrentDate","Date","updateCurrentDate","now","timeDiffInMs","Math","abs","getTime","updateInterval","getSeconds","intervalId","setInterval","timeout","setTimeout","clearTimeout","clearInterval","trim"],"sources":["../../../src/hooks/useDateInfo.ts"],"sourcesContent":["import { getLanguage } from 'chayns-api';\nimport { useEffect, useMemo, useState } from 'react';\nimport { UseDateInfoOptions } from '../types/dateinfo';\nimport { getDateInfo, getTimeTillNow } from '../utils/dateInfo';\n\nexport const useDateInfo = ({\n date,\n shouldShowDateToNowDifference,\n shouldShowRelativeDayOfWeek,\n shouldShowDayOfWeek,\n shouldShowTime,\n shouldUseShortText,\n shouldShowYear,\n preText,\n}: UseDateInfoOptions) => {\n const { active: language } = getLanguage();\n\n const [formattedDate, setFormattedDate] = useState(date.toLocaleDateString());\n const [currentDate, setCurrentDate] = useState(new Date());\n\n useEffect(() => {\n if (shouldShowDateToNowDifference) {\n return;\n }\n\n setFormattedDate(\n getDateInfo({\n date,\n shouldShowYear,\n shouldShowTime,\n shouldUseShortText,\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n }),\n );\n }, [\n date,\n shouldShowDateToNowDifference,\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldShowTime,\n shouldShowYear,\n shouldUseShortText,\n ]);\n\n useEffect(() => {\n if (!shouldShowDateToNowDifference) return () => {};\n\n const updateCurrentDate = () => setCurrentDate(new Date());\n const now = new Date();\n const timeDiffInMs = Math.abs(date.getTime() - now.getTime());\n\n const updateInterval = timeDiffInMs < 60000 ? 1000 : 60000 - now.getSeconds() * 1000;\n\n const intervalId = setInterval(updateCurrentDate, 1000);\n const timeout = setTimeout(updateCurrentDate, updateInterval);\n\n return () => {\n clearTimeout(timeout);\n clearInterval(intervalId);\n };\n }, [date, shouldShowDateToNowDifference]);\n\n useEffect(() => {\n if (shouldShowDateToNowDifference) {\n setFormattedDate(getTimeTillNow({ date, currentDate, language }));\n }\n }, [date, currentDate, language, shouldShowDateToNowDifference]);\n\n return useMemo(\n () => `${preText ? `${preText.trim()} ` : ''}${formattedDate}`,\n [formattedDate, preText],\n );\n};\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,YAAY;AACxC,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAEpD,SAASC,WAAW,EAAEC,cAAc,QAAQ,mBAAmB;AAE/D,OAAO,MAAMC,WAAW,GAAGC,IAAA,IASD;EAAA,IATE;IACxBC,IAAI;IACJC,6BAA6B;IAC7BC,2BAA2B;IAC3BC,mBAAmB;IACnBC,cAAc;IACdC,kBAAkB;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EAAEM,cAAc,CAAC;IAE7D,OAAO,MAAM;MACTM,YAAY,CAACF,OAAO,CAAC;MACrBG,aAAa,CAACL,UAAU,CAAC;IAC7B,CAAC;EACL,CAAC,EAAE,CAACxB,IAAI,EAAEC,6BAA6B,CAAC,CAAC;EAEzCR,SAAS,CAAC,MAAM;IACZ,IAAIQ,6BAA6B,EAAE;MAC/BU,gBAAgB,CAACd,cAAc,CAAC;QAAEG,IAAI;QAAEa,WAAW;QAAEJ;MAAS,CAAC,CAAC,CAAC;IACrE;EACJ,CAAC,EAAE,CAACT,IAAI,EAAEa,WAAW,EAAEJ,QAAQ,EAAER,6BAA6B,CAAC,CAAC;EAEhE,OAAOP,OAAO,CACV,MAAM,GAAGa,OAAO,GAAG,GAAGA,OAAO,CAACuB,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,GAAGpB,aAAa,EAAE,EAC9D,CAACA,aAAa,EAAEH,OAAO,CAC3B,CAAC;AACL,CAAC","ignoreList":[]}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Calendar
|
|
2
|
+
export { default as Calendar } from './components/calendar/Calendar';
|
|
3
|
+
export { CalendarType } from './types/calendar';
|
|
4
|
+
|
|
5
|
+
// OpeningTimes
|
|
6
|
+
export { default as OpeningInputs } from './components/opening-times/opening-inputs/OpeningInputs';
|
|
7
|
+
export { default as OpeningTimes } from './components/opening-times/OpeningTimes';
|
|
8
|
+
// DateInfo
|
|
9
|
+
export { default as DateInfo } from './components/date-info/DateInfo';
|
|
10
|
+
export { useDateInfo } from './hooks/useDateInfo';
|
|
11
|
+
export { getDateInfo, getTimeTillNow } from './utils/dateInfo';
|
|
12
|
+
|
|
13
|
+
// Utils
|
|
14
|
+
export { isToday, getIsDateNearToday, isTomorrow, isYesterday, isMorning, isCurrentYear, addYears, addDays, isSameDay, eachDayOfInterval, isWithinInterval, subYears, endOfWeek, startOfWeek, isSameMonth, differenceInCalendarMonths, startOfMonth, isAfter, isBefore } from './utils/date';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","Calendar","CalendarType","OpeningInputs","OpeningTimes","DateInfo","useDateInfo","getDateInfo","getTimeTillNow","isToday","getIsDateNearToday","isTomorrow","isYesterday","isMorning","isCurrentYear","addYears","addDays","isSameDay","eachDayOfInterval","isWithinInterval","subYears","endOfWeek","startOfWeek","isSameMonth","differenceInCalendarMonths","startOfMonth","isAfter","isBefore"],"sources":["../../src/index.ts"],"sourcesContent":["// Calendar\nexport {default as Calendar} from './components/calendar/Calendar';\nexport type {Categories, HighlightedDates, HighlightedDateStyles, DateInterval, CustomThumbColors} from './types/calendar';\nexport {CalendarType} from './types/calendar';\n\n// OpeningTimes\nexport {default as OpeningInputs} from './components/opening-times/opening-inputs/OpeningInputs';\nexport {default as OpeningTimes} from './components/opening-times/OpeningTimes';\nexport type {HintTextPosition, OpeningTime, Time, Weekday} from './types/openingTimes';\n\n// DateInfo\nexport {default as DateInfo} from './components/date-info/DateInfo';\nexport {useDateInfo} from './hooks/useDateInfo';\nexport {getDateInfo, getTimeTillNow} from './utils/dateInfo'\n\n// Utils\nexport {\n isToday,\n getIsDateNearToday,\n isTomorrow,\n isYesterday,\n isMorning,\n isCurrentYear,\n addYears,\n addDays,\n isSameDay,\n eachDayOfInterval,\n isWithinInterval,\n subYears,\n endOfWeek,\n startOfWeek,\n isSameMonth,\n differenceInCalendarMonths,\n startOfMonth,\n isAfter,\n isBefore\n} from './utils/date'\n"],"mappings":"AAAA;AACA,SAAQA,OAAO,IAAIC,QAAQ,QAAO,gCAAgC;AAElE,SAAQC,YAAY,QAAO,kBAAkB;;AAE7C;AACA,SAAQF,OAAO,IAAIG,aAAa,QAAO,yDAAyD;AAChG,SAAQH,OAAO,IAAII,YAAY,QAAO,yCAAyC;AAG/E;AACA,SAAQJ,OAAO,IAAIK,QAAQ,QAAO,iCAAiC;AACnE,SAAQC,WAAW,QAAO,qBAAqB;AAC/C,SAAQC,WAAW,EAAEC,cAAc,QAAO,kBAAkB;;AAE5D;AACA,SACIC,OAAO,EACPC,kBAAkB,EAClBC,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,aAAa,EACbC,QAAQ,EACRC,OAAO,EACPC,SAAS,EACTC,iBAAiB,EACjBC,gBAAgB,EAChBC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,0BAA0B,EAC1BC,YAAY,EACZC,OAAO,EACPC,QAAQ,QACL,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export let EMonth = /*#__PURE__*/function (EMonth) {
|
|
2
|
+
EMonth[EMonth["January"] = 1] = "January";
|
|
3
|
+
EMonth[EMonth["February"] = 2] = "February";
|
|
4
|
+
EMonth[EMonth["March"] = 3] = "March";
|
|
5
|
+
EMonth[EMonth["April"] = 4] = "April";
|
|
6
|
+
EMonth[EMonth["May"] = 5] = "May";
|
|
7
|
+
EMonth[EMonth["June"] = 6] = "June";
|
|
8
|
+
EMonth[EMonth["July"] = 7] = "July";
|
|
9
|
+
EMonth[EMonth["August"] = 8] = "August";
|
|
10
|
+
EMonth[EMonth["September"] = 9] = "September";
|
|
11
|
+
EMonth[EMonth["October"] = 10] = "October";
|
|
12
|
+
EMonth[EMonth["November"] = 11] = "November";
|
|
13
|
+
EMonth[EMonth["December"] = 12] = "December";
|
|
14
|
+
return EMonth;
|
|
15
|
+
}({});
|
|
16
|
+
export let CalendarType = /*#__PURE__*/function (CalendarType) {
|
|
17
|
+
CalendarType["Single"] = "single";
|
|
18
|
+
CalendarType["Multiple"] = "multiple";
|
|
19
|
+
CalendarType["Interval"] = "interval";
|
|
20
|
+
return CalendarType;
|
|
21
|
+
}({});
|
|
22
|
+
//# sourceMappingURL=calendar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.js","names":["EMonth","CalendarType"],"sources":["../../../src/types/calendar.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nexport interface HighlightedDates {\n dates: Date[];\n style: HighlightedDateStyles;\n}\n\nexport interface HighlightedDateStyles {\n backgroundColor: CSSProperties['backgroundColor'];\n textColor: CSSProperties['color'];\n}\n\nexport interface Categories {\n id: string;\n dates: Date[];\n color: CSSProperties['color'];\n}\n\nexport interface IMonth {\n month: EMonth;\n year: number;\n}\n\nexport interface CustomThumbColors {\n /**\n * The background color of the main thumbs (single, multi, interval)\n */\n mainBackgroundColor?: CSSProperties['color'];\n /**\n * The text color of the main thumbs (single, multi, interval)\n */\n mainTextColor?: CSSProperties['color'];\n /**\n * The background color of the middle part of the interval thumb\n */\n secondaryBackgroundColor?: CSSProperties['color'];\n\n}\n\nexport enum EMonth {\n January = 1,\n February,\n March,\n April,\n May,\n June,\n July,\n August,\n September,\n October,\n November,\n December,\n}\n\nexport enum CalendarType {\n Single = 'single',\n Multiple = 'multiple',\n Interval = 'interval',\n}\n\nexport type DateInterval = {\n start: Date;\n end?: Date;\n};\n"],"mappings":"AAuCA,WAAYA,MAAM,0BAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAANA,MAAM,CAANA,MAAM;EAAA,OAANA,MAAM;AAAA;AAelB,WAAYC,YAAY,0BAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAA,OAAZA,YAAY;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateinfo.js","names":[],"sources":["../../../src/types/dateinfo.ts"],"sourcesContent":["export interface UseDateInfoOptions {\n /**\n * The date, that should be displayed\n */\n date: Date;\n /**\n * Additional text for \"shouldShowDateToNowDifference\" prop. Writes a text before the calculated time\n */\n preText?: string;\n /**\n * Adds the current year to the display\n */\n shouldShowYear?: boolean;\n /**\n * Adds the time to the display.\n */\n shouldShowTime?: boolean;\n /**\n * Whether the relative day of week to today should be shown (today, yesterday or tomorrow).\n */\n shouldShowRelativeDayOfWeek?: boolean;\n /**\n * Shortens the day and month text to maximum three digits\n */\n shouldUseShortText?: boolean;\n /**\n * Adds the day of week to the display\n */\n shouldShowDayOfWeek?: boolean;\n /**\n * Shows the difference from the date to now. The component handles updates itself.\n */\n shouldShowDateToNowDifference?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export let OpeningTimesButtonType = /*#__PURE__*/function (OpeningTimesButtonType) {
|
|
2
|
+
OpeningTimesButtonType[OpeningTimesButtonType["NONE"] = 0] = "NONE";
|
|
3
|
+
OpeningTimesButtonType[OpeningTimesButtonType["ADD"] = 1] = "ADD";
|
|
4
|
+
OpeningTimesButtonType[OpeningTimesButtonType["REMOVE"] = 2] = "REMOVE";
|
|
5
|
+
return OpeningTimesButtonType;
|
|
6
|
+
}({});
|
|
7
|
+
export let HintTextPosition = /*#__PURE__*/function (HintTextPosition) {
|
|
8
|
+
HintTextPosition[HintTextPosition["Top"] = 0] = "Top";
|
|
9
|
+
HintTextPosition[HintTextPosition["Bottom"] = 1] = "Bottom";
|
|
10
|
+
return HintTextPosition;
|
|
11
|
+
}({});
|
|
12
|
+
//# sourceMappingURL=openingTimes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openingTimes.js","names":["OpeningTimesButtonType","HintTextPosition"],"sources":["../../../src/types/openingTimes.ts"],"sourcesContent":["export interface Weekday {\n name: string;\n id: number;\n}\n\nexport interface Time {\n id: string;\n start: string;\n end: string;\n}\n\nexport interface OpeningTime {\n weekdayId: Weekday['id'];\n id: string;\n isDisabled?: boolean;\n times: Time[];\n}\n\nexport interface OnTimeAdd {\n dayId: OpeningTime['id'];\n time: Time;\n}\n\nexport interface OnChange {\n enabledDays?: OpeningTime['id'][];\n dayId?: OpeningTime['id'];\n time?: Time;\n}\n\nexport enum OpeningTimesButtonType {\n NONE,\n ADD,\n REMOVE,\n}\n\nexport enum HintTextPosition {\n Top,\n Bottom,\n}\n"],"mappings":"AA6BA,WAAYA,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB,CAAtBA,sBAAsB;EAAtBA,sBAAsB,CAAtBA,sBAAsB;EAAtBA,sBAAsB,CAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAMlC,WAAYC,gBAAgB,0BAAhBA,gBAAgB;EAAhBA,gBAAgB,CAAhBA,gBAAgB;EAAhBA,gBAAgB,CAAhBA,gBAAgB;EAAA,OAAhBA,gBAAgB;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isAfter, isBefore, startOfMonth } from "./date";
|
|
2
|
+
export const getMonthAndYear = date => {
|
|
3
|
+
const month = date.getMonth() + 1;
|
|
4
|
+
const year = date.getFullYear();
|
|
5
|
+
return {
|
|
6
|
+
month,
|
|
7
|
+
year
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export const isDateInRange = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
minDate,
|
|
13
|
+
maxDate,
|
|
14
|
+
currentDate
|
|
15
|
+
} = _ref;
|
|
16
|
+
const monthStartOfCurrentDate = startOfMonth(currentDate);
|
|
17
|
+
const monthStartOfMaxDate = startOfMonth(maxDate);
|
|
18
|
+
const monthStartOfMinDate = startOfMonth(minDate);
|
|
19
|
+
switch (true) {
|
|
20
|
+
case isAfter(monthStartOfCurrentDate, monthStartOfMaxDate):
|
|
21
|
+
return monthStartOfMaxDate;
|
|
22
|
+
case isBefore(monthStartOfCurrentDate, monthStartOfMinDate):
|
|
23
|
+
return monthStartOfMinDate;
|
|
24
|
+
default:
|
|
25
|
+
return monthStartOfCurrentDate;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export const getNewDate = (index, currentDate) => {
|
|
29
|
+
const newDate = new Date(currentDate);
|
|
30
|
+
newDate.setMonth(currentDate.getMonth() + index);
|
|
31
|
+
if (currentDate.getMonth() === 11 && newDate.getMonth() === 0) {
|
|
32
|
+
newDate.setFullYear(currentDate.getFullYear() + 1);
|
|
33
|
+
}
|
|
34
|
+
if (currentDate.getMonth() === 0 && newDate.getMonth() === 11) {
|
|
35
|
+
newDate.setFullYear(currentDate.getFullYear() - 1);
|
|
36
|
+
}
|
|
37
|
+
return newDate;
|
|
38
|
+
};
|
|
39
|
+
export const formatMonth = _ref2 => {
|
|
40
|
+
let {
|
|
41
|
+
month,
|
|
42
|
+
locale
|
|
43
|
+
} = _ref2;
|
|
44
|
+
const date = new Date(2022, month - 1, 1);
|
|
45
|
+
return date.toLocaleString(locale, {
|
|
46
|
+
month: 'long'
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
export const findNextDate = (date, dateArray) => {
|
|
50
|
+
const futureDates = dateArray.filter(d => d > date);
|
|
51
|
+
futureDates.sort((a, b) => a.getTime() - b.getTime());
|
|
52
|
+
return futureDates[0];
|
|
53
|
+
};
|
|
54
|
+
export const getYearsBetween = (startDate, endDate) => {
|
|
55
|
+
const startYear = startDate.getFullYear();
|
|
56
|
+
const endYear = endDate.getFullYear();
|
|
57
|
+
const years = [];
|
|
58
|
+
for (let year = startYear; year <= endYear; year++) {
|
|
59
|
+
years.push(year);
|
|
60
|
+
}
|
|
61
|
+
return years;
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=calendar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.js","names":["isAfter","isBefore","startOfMonth","getMonthAndYear","date","month","getMonth","year","getFullYear","isDateInRange","_ref","minDate","maxDate","currentDate","monthStartOfCurrentDate","monthStartOfMaxDate","monthStartOfMinDate","getNewDate","index","newDate","Date","setMonth","setFullYear","formatMonth","_ref2","locale","toLocaleString","findNextDate","dateArray","futureDates","filter","d","sort","a","b","getTime","getYearsBetween","startDate","endDate","startYear","endYear","years","push"],"sources":["../../../src/utils/calendar.ts"],"sourcesContent":["import type { EMonth, IMonth } from '../types/calendar';\nimport {isAfter, isBefore, startOfMonth} from \"./date\";\nimport {Language} from \"chayns-api\";\n\nexport const getMonthAndYear = (date: Date): IMonth => {\n const month = date.getMonth() + 1;\n\n const year = date.getFullYear();\n\n return {\n month,\n year,\n };\n};\n\ninterface FormatMonthOptions {\n month: EMonth;\n locale: Language;\n}\n\ninterface IsDateInRange {\n minDate: Date;\n maxDate: Date;\n currentDate: Date;\n}\n\nexport const isDateInRange = ({ minDate, maxDate, currentDate }: IsDateInRange): Date => {\n const monthStartOfCurrentDate = startOfMonth(currentDate);\n const monthStartOfMaxDate = startOfMonth(maxDate);\n const monthStartOfMinDate = startOfMonth(minDate);\n\n switch (true) {\n case isAfter(monthStartOfCurrentDate, monthStartOfMaxDate):\n return monthStartOfMaxDate;\n case isBefore(monthStartOfCurrentDate, monthStartOfMinDate):\n return monthStartOfMinDate;\n default:\n return monthStartOfCurrentDate;\n }\n};\n\nexport const getNewDate = (index: number, currentDate: Date) => {\n const newDate = new Date(currentDate);\n newDate.setMonth(currentDate.getMonth() + index);\n\n if (currentDate.getMonth() === 11 && newDate.getMonth() === 0) {\n newDate.setFullYear(currentDate.getFullYear() + 1);\n }\n\n if (currentDate.getMonth() === 0 && newDate.getMonth() === 11) {\n newDate.setFullYear(currentDate.getFullYear() - 1);\n }\n\n return newDate;\n};\n\nexport const formatMonth = ({ month, locale }: FormatMonthOptions) => {\n const date = new Date(2022, month - 1, 1);\n return date.toLocaleString(locale, { month: 'long' });\n}\n\nexport const findNextDate = (date: Date, dateArray: Date[]): Date | undefined => {\n const futureDates = dateArray.filter((d) => d > date);\n\n futureDates.sort((a, b) => a.getTime() - b.getTime());\n\n return futureDates[0];\n};\n\nexport const getYearsBetween = (startDate: Date, endDate: Date): number[] => {\n const startYear = startDate.getFullYear();\n const endYear = endDate.getFullYear();\n const years: number[] = [];\n\n for (let year = startYear; year <= endYear; year++) {\n years.push(year);\n }\n\n return years;\n};\n"],"mappings":"AACA,SAAQA,OAAO,EAAEC,QAAQ,EAAEC,YAAY,QAAO,QAAQ;AAGtD,OAAO,MAAMC,eAAe,GAAIC,IAAU,IAAa;EACnD,MAAMC,KAAK,GAAGD,IAAI,CAACE,QAAQ,CAAC,CAAC,GAAG,CAAC;EAEjC,MAAMC,IAAI,GAAGH,IAAI,CAACI,WAAW,CAAC,CAAC;EAE/B,OAAO;IACHH,KAAK;IACLE;EACJ,CAAC;AACL,CAAC;AAaD,OAAO,MAAME,aAAa,GAAGC,IAAA,IAA4D;EAAA,IAA3D;IAAEC,OAAO;IAAEC,OAAO;IAAEC;EAA2B,CAAC,GAAAH,IAAA;EAC1E,MAAMI,uBAAuB,GAAGZ,YAAY,CAACW,WAAW,CAAC;EACzD,MAAME,mBAAmB,GAAGb,YAAY,CAACU,OAAO,CAAC;EACjD,MAAMI,mBAAmB,GAAGd,YAAY,CAACS,OAAO,CAAC;EAEjD,QAAQ,IAAI;IACR,KAAKX,OAAO,CAACc,uBAAuB,EAAEC,mBAAmB,CAAC;MACtD,OAAOA,mBAAmB;IAC9B,KAAKd,QAAQ,CAACa,uBAAuB,EAAEE,mBAAmB,CAAC;MACvD,OAAOA,mBAAmB;IAC9B;MACI,OAAOF,uBAAuB;EACtC;AACJ,CAAC;AAED,OAAO,MAAMG,UAAU,GAAGA,CAACC,KAAa,EAAEL,WAAiB,KAAK;EAC5D,MAAMM,OAAO,GAAG,IAAIC,IAAI,CAACP,WAAW,CAAC;EACrCM,OAAO,CAACE,QAAQ,CAACR,WAAW,CAACP,QAAQ,CAAC,CAAC,GAAGY,KAAK,CAAC;EAEhD,IAAIL,WAAW,CAACP,QAAQ,CAAC,CAAC,KAAK,EAAE,IAAIa,OAAO,CAACb,QAAQ,CAAC,CAAC,KAAK,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,SAAS,EAAEhC,IAAI,IAAIiC,OAAO,EAAEjC,IAAI,EAAE,EAAE;IAChDkC,KAAK,CAACC,IAAI,CAACnC,IAAI,CAAC;EACpB;EAEA,OAAOkC,KAAK;AAChB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export const isToday = date => {
|
|
2
|
+
const today = new Date();
|
|
3
|
+
return today.toDateString() === date.toDateString();
|
|
4
|
+
};
|
|
5
|
+
export const isTomorrow = date => {
|
|
6
|
+
const tomorrow = new Date();
|
|
7
|
+
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
8
|
+
return tomorrow.toDateString() === date.toDateString();
|
|
9
|
+
};
|
|
10
|
+
export const isYesterday = date => {
|
|
11
|
+
const yesterday = new Date();
|
|
12
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
13
|
+
return yesterday.toDateString() === date.toDateString();
|
|
14
|
+
};
|
|
15
|
+
export const isCurrentYear = date => {
|
|
16
|
+
const currentYear = new Date().getFullYear();
|
|
17
|
+
const yearOfGivenDate = date.getFullYear();
|
|
18
|
+
return currentYear === yearOfGivenDate;
|
|
19
|
+
};
|
|
20
|
+
export const getIsDateNearToday = date => {
|
|
21
|
+
const today = new Date();
|
|
22
|
+
today.setHours(0, 0, 0, 0);
|
|
23
|
+
const targetDate = new Date(date);
|
|
24
|
+
targetDate.setHours(0, 0, 0, 0);
|
|
25
|
+
const diffInDays = (targetDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24);
|
|
26
|
+
return diffInDays === 0 || diffInDays === -1 || diffInDays === 1;
|
|
27
|
+
};
|
|
28
|
+
export const isMorning = date => {
|
|
29
|
+
const hours = date.getHours();
|
|
30
|
+
return hours >= 0 && hours < 12;
|
|
31
|
+
};
|
|
32
|
+
export const isAfter = (firstDate, secondDate) => {
|
|
33
|
+
return firstDate.getTime() > secondDate.getTime();
|
|
34
|
+
};
|
|
35
|
+
export const isBefore = (firstDate, secondDate) => {
|
|
36
|
+
return firstDate.getTime() < secondDate.getTime();
|
|
37
|
+
};
|
|
38
|
+
export const startOfMonth = date => {
|
|
39
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
40
|
+
};
|
|
41
|
+
export const addYears = (date, years) => {
|
|
42
|
+
return new Date(date.getFullYear() + years, date.getMonth(), date.getDate());
|
|
43
|
+
};
|
|
44
|
+
export const differenceInCalendarMonths = (firstDate, secondDate) => {
|
|
45
|
+
return (firstDate.getFullYear() - secondDate.getFullYear()) * 12 + (firstDate.getMonth() - secondDate.getMonth());
|
|
46
|
+
};
|
|
47
|
+
export const isSameDay = (firstDate, secondDate) => {
|
|
48
|
+
return firstDate.getFullYear() === secondDate.getFullYear() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getDate() === secondDate.getDate();
|
|
49
|
+
};
|
|
50
|
+
export const isSameMonth = (firstDate, secondDate) => {
|
|
51
|
+
return firstDate.getFullYear() === secondDate.getFullYear() && firstDate.getMonth() === secondDate.getMonth();
|
|
52
|
+
};
|
|
53
|
+
export const isWithinInterval = (date, interval) => {
|
|
54
|
+
return date.getTime() >= interval.start.getTime() && date.getTime() <= interval.end.getTime();
|
|
55
|
+
};
|
|
56
|
+
export const subYears = (date, years) => {
|
|
57
|
+
return new Date(date.getFullYear() - years, date.getMonth(), date.getDate());
|
|
58
|
+
};
|
|
59
|
+
export const startOfWeek = date => {
|
|
60
|
+
const day = date.getDay();
|
|
61
|
+
const diff = day === 0 ? -6 : 1 - day;
|
|
62
|
+
const start = new Date(date);
|
|
63
|
+
start.setDate(date.getDate() + diff);
|
|
64
|
+
start.setHours(0, 0, 0, 0);
|
|
65
|
+
return start;
|
|
66
|
+
};
|
|
67
|
+
export const endOfWeek = date => {
|
|
68
|
+
const day = date.getDay();
|
|
69
|
+
const diff = day === 0 ? 0 : 7 - day;
|
|
70
|
+
const end = new Date(date);
|
|
71
|
+
end.setDate(date.getDate() + diff);
|
|
72
|
+
end.setHours(23, 59, 59, 999);
|
|
73
|
+
return end;
|
|
74
|
+
};
|
|
75
|
+
export const eachDayOfInterval = interval => {
|
|
76
|
+
const days = [];
|
|
77
|
+
const currentDate = new Date(interval.start);
|
|
78
|
+
while (currentDate <= interval.end) {
|
|
79
|
+
days.push(new Date(currentDate));
|
|
80
|
+
currentDate.setDate(currentDate.getDate() + 1);
|
|
81
|
+
}
|
|
82
|
+
return days;
|
|
83
|
+
};
|
|
84
|
+
export const addDays = (date, days) => {
|
|
85
|
+
const result = new Date(date);
|
|
86
|
+
result.setDate(date.getDate() + days);
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","names":["isToday","date","today","Date","toDateString","isTomorrow","tomorrow","setDate","getDate","isYesterday","yesterday","isCurrentYear","currentYear","getFullYear","yearOfGivenDate","getIsDateNearToday","setHours","targetDate","diffInDays","getTime","isMorning","hours","getHours","isAfter","firstDate","secondDate","isBefore","startOfMonth","getMonth","addYears","years","differenceInCalendarMonths","isSameDay","isSameMonth","isWithinInterval","interval","start","end","subYears","startOfWeek","day","getDay","diff","endOfWeek","eachDayOfInterval","days","currentDate","push","addDays","result"],"sources":["../../../src/utils/date.ts"],"sourcesContent":["export const isToday = (date: Date): boolean => {\n const today = new Date();\n return today.toDateString() === date.toDateString();\n};\n\nexport const isTomorrow = (date: Date): boolean => {\n const tomorrow = new Date();\n tomorrow.setDate(tomorrow.getDate() + 1);\n return tomorrow.toDateString() === date.toDateString();\n};\n\nexport const isYesterday = (date: Date): boolean => {\n const yesterday = new Date();\n yesterday.setDate(yesterday.getDate() - 1);\n return yesterday.toDateString() === date.toDateString();\n};\n\nexport const isCurrentYear = (date: Date): boolean => {\n const currentYear = new Date().getFullYear();\n const yearOfGivenDate = date.getFullYear();\n return currentYear === yearOfGivenDate;\n};\n\nexport const getIsDateNearToday = (date: Date) => {\n const today = new Date();\n today.setHours(0, 0, 0, 0);\n\n const targetDate = new Date(date);\n targetDate.setHours(0, 0, 0, 0);\n\n const diffInDays = (targetDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24);\n\n return diffInDays === 0 || diffInDays === -1 || diffInDays === 1;\n};\n\nexport const isMorning = (date: Date) => {\n const hours = date.getHours();\n\n return hours >= 0 && hours < 12;\n};\n\nexport const isAfter = (firstDate: Date, secondDate: Date): boolean => {\n return firstDate.getTime() > secondDate.getTime();\n}\n\nexport const isBefore = (firstDate: Date, secondDate: Date): boolean => {\n return firstDate.getTime() < secondDate.getTime();\n}\n\nexport const startOfMonth = (date: Date): Date => {\n return new Date(date.getFullYear(), date.getMonth(), 1);\n}\n\nexport const addYears = (date: Date, years: number): Date => {\n return new Date(date.getFullYear() + years, date.getMonth(), date.getDate());\n};\n\nexport const differenceInCalendarMonths = (firstDate: Date, secondDate: Date): number => {\n return (firstDate.getFullYear() - secondDate.getFullYear()) * 12 + (firstDate.getMonth() - secondDate.getMonth());\n};\n\nexport const isSameDay = (firstDate: Date, secondDate: Date): boolean => {\n return (\n firstDate.getFullYear() === secondDate.getFullYear() &&\n firstDate.getMonth() === secondDate.getMonth() &&\n firstDate.getDate() === secondDate.getDate()\n );\n};\n\nexport const isSameMonth = (firstDate: Date, secondDate: Date): boolean => {\n return (\n firstDate.getFullYear() === secondDate.getFullYear() &&\n firstDate.getMonth() === secondDate.getMonth()\n );\n};\n\ninterface Interval {\n start: Date;\n end: Date;\n}\n\nexport const isWithinInterval = (date: Date, interval: Interval): boolean => {\n return date.getTime() >= interval.start.getTime() && date.getTime() <= interval.end.getTime();\n};\n\nexport const subYears = (date: Date, years: number): Date => {\n return new Date(date.getFullYear() - years, date.getMonth(), date.getDate());\n};\n\nexport const startOfWeek = (date: Date): Date => {\n const day = date.getDay();\n const diff = day === 0 ? -6 : 1 - day;\n const start = new Date(date);\n start.setDate(date.getDate() + diff);\n start.setHours(0, 0, 0, 0);\n return start;\n};\n\nexport const endOfWeek = (date: Date): Date => {\n const day = date.getDay();\n const diff = day === 0 ? 0 : 7 - day;\n const end = new Date(date);\n end.setDate(date.getDate() + diff);\n end.setHours(23, 59, 59, 999);\n return end;\n};\n\nexport const eachDayOfInterval = (interval: { start: Date, end: Date }): Date[] => {\n const days: Date[] = [];\n const currentDate = new Date(interval.start);\n\n while (currentDate <= interval.end) {\n days.push(new Date(currentDate));\n currentDate.setDate(currentDate.getDate() + 1);\n }\n\n return days;\n};\n\nexport const addDays = (date: Date, days: number): Date => {\n const result = new Date(date);\n result.setDate(date.getDate() + days);\n return result;\n};\n"],"mappings":"AAAA,OAAO,MAAMA,OAAO,GAAIC,IAAU,IAAc;EAC5C,MAAMC,KAAK,GAAG,IAAIC,IAAI,CAAC,CAAC;EACxB,OAAOD,KAAK,CAACE,YAAY,CAAC,CAAC,KAAKH,IAAI,CAACG,YAAY,CAAC,CAAC;AACvD,CAAC;AAED,OAAO,MAAMC,UAAU,GAAIJ,IAAU,IAAc;EAC/C,MAAMK,QAAQ,GAAG,IAAIH,IAAI,CAAC,CAAC;EAC3BG,QAAQ,CAACC,OAAO,CAACD,QAAQ,CAACE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;EACxC,OAAOF,QAAQ,CAACF,YAAY,CAAC,CAAC,KAAKH,IAAI,CAACG,YAAY,CAAC,CAAC;AAC1D,CAAC;AAED,OAAO,MAAMK,WAAW,GAAIR,IAAU,IAAc;EAChD,MAAMS,SAAS,GAAG,IAAIP,IAAI,CAAC,CAAC;EAC5BO,SAAS,CAACH,OAAO,CAACG,SAAS,CAACF,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;EAC1C,OAAOE,SAAS,CAACN,YAAY,CAAC,CAAC,KAAKH,IAAI,CAACG,YAAY,CAAC,CAAC;AAC3D,CAAC;AAED,OAAO,MAAMO,aAAa,GAAIV,IAAU,IAAc;EAClD,MAAMW,WAAW,GAAG,IAAIT,IAAI,CAAC,CAAC,CAACU,WAAW,CAAC,CAAC;EAC5C,MAAMC,eAAe,GAAGb,IAAI,CAACY,WAAW,CAAC,CAA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