@chayns-components/date 5.0.0-beta.998 → 5.0.0
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/lib/cjs/components/calendar/Calendar.js +9 -22
- package/lib/cjs/components/calendar/Calendar.js.map +1 -1
- package/lib/cjs/components/calendar/Calendar.styles.js +7 -1
- package/lib/cjs/components/calendar/Calendar.styles.js.map +1 -1
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.js +9 -4
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.js.map +1 -1
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.styles.js +2 -2
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.styles.js.map +1 -1
- package/lib/cjs/components/calendar/month-wrapper/month/Month.js +64 -32
- package/lib/cjs/components/calendar/month-wrapper/month/Month.js.map +1 -1
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js +5 -4
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js.map +1 -1
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.js +7 -4
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.js.map +1 -1
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js +17 -3
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js.map +1 -1
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js +1 -2
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js.map +1 -1
- package/lib/cjs/components/calendar/month-year-pickers/MonthYearPickers.js +4 -3
- package/lib/cjs/components/calendar/month-year-pickers/MonthYearPickers.js.map +1 -1
- package/lib/cjs/components/date-info/DateInfo.js +4 -3
- package/lib/cjs/components/date-info/DateInfo.js.map +1 -1
- package/lib/cjs/components/opening-times/OpeningTimes.js +12 -15
- package/lib/cjs/components/opening-times/OpeningTimes.js.map +1 -1
- package/lib/cjs/components/opening-times/hint-text/HintText.js +1 -2
- package/lib/cjs/components/opening-times/hint-text/HintText.js.map +1 -1
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.js +16 -17
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.js.map +1 -1
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.styles.js +3 -4
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.styles.js.map +1 -1
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.js +1 -2
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.js.map +1 -1
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js +2 -2
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js.map +1 -1
- package/lib/cjs/hooks/useDateInfo.js +3 -1
- package/lib/cjs/hooks/useDateInfo.js.map +1 -1
- package/lib/cjs/index.js +6 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types/calendar.js.map +1 -1
- package/lib/cjs/types/dateinfo.js +4 -0
- package/lib/cjs/types/dateinfo.js.map +1 -1
- package/lib/cjs/types/openingTimes.js.map +1 -1
- package/lib/cjs/utils/calendar.js.map +1 -1
- package/lib/cjs/utils/date.js.map +1 -1
- package/lib/cjs/utils/dateInfo.js +52 -28
- package/lib/cjs/utils/dateInfo.js.map +1 -1
- package/lib/esm/components/calendar/Calendar.js +26 -39
- package/lib/esm/components/calendar/Calendar.js.map +1 -1
- package/lib/esm/components/calendar/Calendar.styles.js +12 -12
- package/lib/esm/components/calendar/Calendar.styles.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.js +28 -23
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.styles.js +7 -13
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.styles.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/Month.js +51 -25
- package/lib/esm/components/calendar/month-wrapper/month/Month.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/Month.styles.js +3 -6
- package/lib/esm/components/calendar/month-wrapper/month/Month.styles.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js +20 -19
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.js +22 -19
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js +51 -53
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js +5 -8
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js +3 -6
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js +4 -5
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js +3 -6
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js.map +1 -1
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js +3 -6
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js.map +1 -1
- package/lib/esm/components/calendar/month-year-pickers/MonthYearPickers.js +13 -12
- package/lib/esm/components/calendar/month-year-pickers/MonthYearPickers.js.map +1 -1
- package/lib/esm/components/date-info/DateInfo.js +12 -11
- package/lib/esm/components/date-info/DateInfo.js.map +1 -1
- package/lib/esm/components/opening-times/OpeningTimes.js +34 -44
- package/lib/esm/components/opening-times/OpeningTimes.js.map +1 -1
- package/lib/esm/components/opening-times/OpeningTimes.styles.js +3 -6
- package/lib/esm/components/opening-times/OpeningTimes.styles.js.map +1 -1
- package/lib/esm/components/opening-times/hint-text/HintText.js +3 -4
- package/lib/esm/components/opening-times/hint-text/HintText.js.map +1 -1
- package/lib/esm/components/opening-times/hint-text/HintText.styles.js +6 -12
- package/lib/esm/components/opening-times/hint-text/HintText.styles.js.map +1 -1
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.js +21 -26
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.js.map +1 -1
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.styles.js +8 -14
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.styles.js.map +1 -1
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.js +11 -12
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.js.map +1 -1
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js +7 -13
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js.map +1 -1
- package/lib/esm/hooks/useDateInfo.js +13 -12
- package/lib/esm/hooks/useDateInfo.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types/calendar.js.map +1 -1
- package/lib/esm/types/dateinfo.js +1 -1
- package/lib/esm/types/dateinfo.js.map +1 -1
- package/lib/esm/types/openingTimes.js.map +1 -1
- package/lib/esm/utils/calendar.js +10 -12
- package/lib/esm/utils/calendar.js.map +1 -1
- package/lib/esm/utils/date.js.map +1 -1
- package/lib/esm/utils/dateInfo.js +65 -45
- package/lib/esm/utils/dateInfo.js.map +1 -1
- package/lib/types/components/calendar/Calendar.d.ts +5 -1
- package/lib/types/components/calendar/Calendar.styles.d.ts +1 -0
- package/lib/types/components/calendar/month-wrapper/MonthWrapper.d.ts +5 -2
- package/lib/types/components/calendar/month-wrapper/MonthWrapper.styles.d.ts +2 -263
- package/lib/types/components/calendar/month-wrapper/month/Month.d.ts +5 -2
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.d.ts +2 -1
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/Day.d.ts +2 -1
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.d.ts +5 -1
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.d.ts +1 -1
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.d.ts +1 -1
- package/lib/types/components/calendar/month-year-pickers/MonthYearPickers.d.ts +1 -1
- package/lib/types/components/opening-times/OpeningTimes.d.ts +2 -6
- package/lib/types/components/opening-times/OpeningTimes.styles.d.ts +1 -1
- package/lib/types/components/opening-times/hint-text/HintText.styles.d.ts +1 -1
- package/lib/types/components/opening-times/opening-inputs/OpeningInputs.styles.d.ts +3 -264
- package/lib/types/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.d.ts +2 -263
- package/lib/types/hooks/useDateInfo.d.ts +1 -1
- package/lib/types/index.d.ts +3 -3
- package/lib/types/types/dateinfo.d.ts +14 -5
- package/lib/types/types/openingTimes.d.ts +2 -0
- package/lib/types/utils/calendar.d.ts +1 -1
- package/lib/types/utils/dateInfo.d.ts +6 -1
- package/package.json +18 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpeningTimes.js","names":["Checkbox","Popup","useElementSize","React","useCallback","useEffect","useMemo","useRef","useState","HintTextPosition","HintText","OpeningInputs","StyledOpeningTimes","StyledOpeningTimesTooltipContent","StyledOpeningTimesWeekDay","StyledOpeningTimesWrapper","OpeningTimes","_ref","closedText","currentDayId","editMode","hintText","hintTextPosition","Bottom","openingTimes","weekdays","onChange","onTimeAdd","onTimeRemove","shouldNotValidate","newOpeningTimes","setNewOpeningTimes","invalidOpeningTimes","setInvalidOpeningTimes","isPopupOpen","setIsPopupOpen","ref","popupRef","validateTime","newTime","dayId","start","end","dayTimes","find","day","id","times","every","time","handleCheckBoxChange","prevOpeningTimes","updatedOpeningTimes","map","openingTime","isDisabled","enabledDays","filter","item","handleChange","isValid","newTimes","changedOpeningTime","updatedOpeningTime","handleAdd","handleUpdateInvalidIds","openingTimeId","invalidTimeIds","prevState","updatedInvalidOpeningTimes","invalidOpeningTime","some","_ref2","updatedInvalidOpeningId","length","push","updatedInvalidOpeningTime","handleRemove","content","items","forEach","_ref3","weekdayId","weekday","weekDay","name","createElement","key","isChecked","onInvalid","onRemove","onAdd","size","hidePopup","current","hide","showPopup","show","displayedContent","singleDay","_ref4","style","width","onMouseEnter","onMouseLeave","onClick","onShow","onHide","shouldShowHint","Top","text","displayName"],"sources":["../../../../src/components/opening-times/OpeningTimes.tsx"],"sourcesContent":["import { Checkbox, Popup, useElementSize, type PopupRef } from '@chayns-components/core';\nimport React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactElement,\n} from 'react';\nimport {\n HintTextPosition,\n type OnChange,\n type OnTimeAdd,\n type OpeningTime,\n type Time,\n type Weekday,\n} from '../../types/openingTimes';\nimport HintText from './hint-text/HintText';\nimport OpeningInputs from './opening-inputs/OpeningInputs';\nimport {\n StyledOpeningTimes,\n StyledOpeningTimesTooltipContent,\n StyledOpeningTimesWeekDay,\n StyledOpeningTimesWrapper,\n} from './OpeningTimes.styles';\n\nexport type OpeningTimesProps = {\n /**\n * The text that should be displayed when a day is closed.\n */\n closedText?: string;\n /**\n * If set just the current day is displayed and the whole week in a tooltip.\n */\n currentDayId?: OpeningTime['id'];\n /**\n * Whether the opening times can be edited.\n */\n editMode?: boolean;\n /**\n * The text that should be displayed if times are colliding.\n */\n hintText?: string;\n /**\n * The position of the hint text.\n */\n hintTextPosition?: HintTextPosition;\n /**\n * Function to be executed when a time is changed or a day is enabled/disabled.\n * @param openingTimes\n */\n onChange?: ({ time, enabledDays, dayId }: OnChange) => void;\n /**\n * Function to be executed when a time is added.\n */\n onTimeAdd?: ({ time, dayId }: OnTimeAdd) => void;\n /**\n * Function to be executed when a time is removed.\n */\n onTimeRemove?: (id: string) => void;\n /**\n * The opening times corresponding to its weekday.\n */\n openingTimes: OpeningTime[];\n /**\n * The weekdays that should be displayed.\n */\n weekdays: Weekday[];\n /**\n * When set to true, events are triggered without validation.\n */\n shouldNotValidate?: boolean;\n};\n\nconst OpeningTimes: FC<OpeningTimesProps> = ({\n closedText = 'closed',\n currentDayId,\n editMode = false,\n hintText,\n hintTextPosition = HintTextPosition.Bottom,\n openingTimes,\n weekdays,\n onChange,\n onTimeAdd,\n onTimeRemove,\n shouldNotValidate = false,\n}) => {\n const [newOpeningTimes, setNewOpeningTimes] = useState<OpeningTime[]>();\n const [invalidOpeningTimes, setInvalidOpeningTimes] = useState<\n { openingTimeId: string; invalidTimeIds: string[] }[]\n >([]);\n const [isPopupOpen, setIsPopupOpen] = useState(false);\n\n const ref = useRef<HTMLDivElement>(null);\n const popupRef = useRef<PopupRef>(null);\n\n useEffect(() => {\n setNewOpeningTimes(openingTimes);\n }, [openingTimes]);\n\n const validateTime = useCallback(\n (newTime: Time, dayId: string): boolean => {\n if (newTime.start === newTime.end) {\n return false;\n }\n const dayTimes = newOpeningTimes?.find((day) => day.id === dayId)?.times || [];\n\n return dayTimes.every(\n (time) =>\n time.id === newTime.id ||\n newTime.end <= time.start ||\n newTime.start >= time.end,\n );\n },\n [newOpeningTimes],\n );\n\n const handleCheckBoxChange = useCallback(\n (id: string) => {\n setNewOpeningTimes((prevOpeningTimes) => {\n const updatedOpeningTimes = (prevOpeningTimes ?? []).map((openingTime) => {\n if (openingTime.id === id) {\n return { ...openingTime, isDisabled: !openingTime.isDisabled };\n }\n return openingTime;\n });\n\n if (typeof onChange === 'function') {\n onChange({\n enabledDays: updatedOpeningTimes\n .filter((item) => !item.isDisabled)\n .map((item) => item.id),\n });\n }\n\n return updatedOpeningTimes;\n });\n },\n [onChange],\n );\n\n const handleChange = useCallback(\n (newTime: Time, id: string) => {\n const isValid = shouldNotValidate || validateTime(newTime, id);\n if (!isValid) {\n return;\n }\n\n setNewOpeningTimes((prevOpeningTimes) => {\n const updatedOpeningTimes = (prevOpeningTimes ?? []).map((openingTime) => {\n if (openingTime.id === id) {\n const newTimes = openingTime.times.map((time) => {\n if (time.id === newTime.id) {\n return newTime;\n }\n return time;\n });\n return { ...openingTime, times: newTimes };\n }\n return openingTime;\n });\n\n const changedOpeningTime = updatedOpeningTimes.find(\n (updatedOpeningTime) => updatedOpeningTime.id === id,\n );\n\n if (isValid && typeof onChange === 'function') {\n onChange({\n dayId: changedOpeningTime?.id,\n time: newTime,\n });\n }\n\n return updatedOpeningTimes;\n });\n },\n [onChange, shouldNotValidate, validateTime],\n );\n\n const handleAdd = useCallback(\n (time: Time, id: string) => {\n const isValid = shouldNotValidate || validateTime(time, id);\n\n if (isValid && typeof onTimeAdd === 'function') {\n onTimeAdd({ time, dayId: id });\n }\n\n setNewOpeningTimes((prevOpeningTimes) =>\n (prevOpeningTimes ?? []).map((openingTime) => {\n if (openingTime.id === id) {\n return { ...openingTime, times: [...openingTime.times, time] };\n }\n return openingTime;\n }),\n );\n },\n [onTimeAdd, shouldNotValidate, validateTime],\n );\n\n const handleUpdateInvalidIds = useCallback(\n (openingTimeId: string, invalidTimeIds: string[]) => {\n setInvalidOpeningTimes((prevState) => {\n const updatedInvalidOpeningTimes = prevState.map((invalidOpeningTime) => {\n if (invalidOpeningTime.openingTimeId === openingTimeId) {\n return {\n openingTimeId,\n invalidTimeIds,\n };\n }\n return invalidOpeningTime;\n });\n\n if (\n !updatedInvalidOpeningTimes.some(\n ({ openingTimeId: updatedInvalidOpeningId }) =>\n updatedInvalidOpeningId === openingTimeId,\n ) &&\n invalidTimeIds.length > 0\n ) {\n updatedInvalidOpeningTimes.push({ openingTimeId, invalidTimeIds });\n }\n\n return updatedInvalidOpeningTimes.filter(\n (updatedInvalidOpeningTime) =>\n updatedInvalidOpeningTime.invalidTimeIds.length !== 0,\n );\n });\n },\n [],\n );\n\n const handleRemove = useCallback(\n (id: string) => {\n setNewOpeningTimes((prevOpeningTimes) =>\n (prevOpeningTimes ?? []).map((openingTime) => {\n const newTimes = openingTime.times.filter((time) => time.id !== id);\n\n return { ...openingTime, times: newTimes };\n }),\n );\n\n if (typeof onTimeRemove === 'function') {\n onTimeRemove(id);\n }\n },\n [onTimeRemove],\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n if (!newOpeningTimes) {\n return items;\n }\n\n newOpeningTimes.forEach(({ times, id, weekdayId, isDisabled }) => {\n const weekday = weekdays.find((weekDay) => weekDay.id === weekdayId)?.name;\n\n if (!weekday) {\n return;\n }\n\n items.push(\n <StyledOpeningTimesWrapper key={`openingTimes__${id}`}>\n {editMode ? (\n <Checkbox isChecked={!isDisabled} onChange={() => handleCheckBoxChange(id)}>\n {weekday}\n </Checkbox>\n ) : (\n <StyledOpeningTimesWeekDay>{weekday}</StyledOpeningTimesWeekDay>\n )}\n <OpeningInputs\n closedText={closedText}\n currentDayId={currentDayId}\n id={id}\n times={times}\n isDisabled={isDisabled}\n onInvalid={handleUpdateInvalidIds}\n onChange={(newTime) => handleChange(newTime, id)}\n onRemove={handleRemove}\n onAdd={handleAdd}\n editMode={editMode}\n />\n </StyledOpeningTimesWrapper>,\n );\n });\n\n return items;\n }, [\n closedText,\n currentDayId,\n editMode,\n handleAdd,\n handleChange,\n handleCheckBoxChange,\n handleRemove,\n handleUpdateInvalidIds,\n newOpeningTimes,\n weekdays,\n ]);\n\n const size = useElementSize(ref);\n\n const hidePopup = useCallback(() => {\n setIsPopupOpen(false);\n popupRef.current?.hide();\n }, []);\n\n const showPopup = useCallback(() => {\n setIsPopupOpen(true);\n popupRef.current?.show();\n }, []);\n\n const displayedContent = useMemo(() => {\n if (!currentDayId || editMode) {\n return content;\n }\n\n const singleDay = newOpeningTimes?.find(({ id }) => id === currentDayId);\n\n if (!singleDay) {\n return content;\n }\n\n const { id, times, weekdayId } = singleDay;\n\n const weekday = weekdays.find((weekDay) => weekDay.id === weekdayId)?.name;\n\n return (\n <StyledOpeningTimesWrapper\n key={`currentDay__${currentDayId}`}\n style={size && { width: size.width }}\n onMouseEnter={showPopup}\n onMouseLeave={hidePopup}\n onClick={() => (isPopupOpen ? hidePopup() : showPopup())}\n >\n <Popup\n onShow={() => setIsPopupOpen(true)}\n onHide={() => setIsPopupOpen(false)}\n ref={popupRef}\n content={\n <StyledOpeningTimesTooltipContent key=\"opening-time-tooltip\">\n {content}\n </StyledOpeningTimesTooltipContent>\n }\n >\n <StyledOpeningTimesWeekDay>{weekday}</StyledOpeningTimesWeekDay>\n </Popup>\n <OpeningInputs\n closedText={closedText}\n currentDayId={currentDayId}\n onInvalid={handleUpdateInvalidIds}\n id={id}\n times={times}\n editMode={editMode}\n />\n </StyledOpeningTimesWrapper>\n );\n }, [\n currentDayId,\n editMode,\n newOpeningTimes,\n weekdays,\n size,\n showPopup,\n hidePopup,\n content,\n closedText,\n handleUpdateInvalidIds,\n isPopupOpen,\n ]);\n\n const shouldShowHint = useMemo(\n () => invalidOpeningTimes.length > 0,\n [invalidOpeningTimes.length],\n );\n\n return useMemo(\n () => (\n <StyledOpeningTimes ref={ref}>\n {shouldShowHint && hintText && hintTextPosition === HintTextPosition.Top && (\n <HintText text={hintText} />\n )}\n {displayedContent}\n {shouldShowHint && hintText && hintTextPosition === HintTextPosition.Bottom && (\n <HintText text={hintText} />\n )}\n </StyledOpeningTimes>\n ),\n [displayedContent, hintText, hintTextPosition, shouldShowHint],\n );\n};\n\nOpeningTimes.displayName = 'OpeningTimes';\n\nexport default OpeningTimes;\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,KAAK,EAAEC,cAAc,QAAuB,yBAAyB;AACxF,OAAOC,KAAK,IAERC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QAEL,OAAO;AACd,SAC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C/B,CAAC;EAED,OAAOpE,OAAO,CACV,mBACIH,KAAA,CAAAmF,aAAA,CAAC1E,kBAAkB;IAACwB,GAAG,EAAEA;EAAI,GACxBwE,cAAc,IAAIvF,QAAQ,IAAIC,gBAAgB,KAAKb,gBAAgB,CAACoG,GAAG,iBACpE1G,KAAA,CAAAmF,aAAA,CAAC5E,QAAQ;IAACoG,IAAI,EAAEzF;EAAS,CAAE,CAC9B,EACA6E,gBAAgB,EAChBU,cAAc,IAAIvF,QAAQ,IAAIC,gBAAgB,KAAKb,gBAAgB,CAACc,MAAM,iBACvEpB,KAAA,CAAAmF,aAAA,CAAC5E,QAAQ;IAACoG,IAAI,EAAEzF;EAAS,CAAE,CAEf,CACvB,EACD,CAAC6E,gBAAgB,EAAE7E,QAAQ,EAAEC,gBAAgB,EAAEsF,cAAc,CACjE,CAAC;AACL,CAAC;AAED5F,YAAY,CAAC+F,WAAW,GAAG,cAAc;AAEzC,eAAe/F,YAAY","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"OpeningTimes.js","names":["Checkbox","Popup","useElementSize","React","useCallback","useEffect","useMemo","useRef","useState","HintTextPosition","HintText","OpeningInputs","StyledOpeningTimes","StyledOpeningTimesTooltipContent","StyledOpeningTimesWeekDay","StyledOpeningTimesWrapper","OpeningTimes","closedText","currentDayId","editMode","hintText","hintTextPosition","Bottom","openingTimes","weekdays","onChange","onTimeAdd","onTimeRemove","newOpeningTimes","setNewOpeningTimes","invalidOpeningTimes","setInvalidOpeningTimes","isPopupOpen","setIsPopupOpen","ref","popupRef","validateTime","newTime","dayId","start","end","dayTimes","find","day","id","times","every","time","handleCheckBoxChange","prevOpeningTimes","updatedOpeningTimes","map","openingTime","isDisabled","enabledDays","filter","item","handleChange","isValid","newTimes","changedOpeningTime","updatedOpeningTime","handleAdd","handleUpdateInvalidIds","openingTimeId","invalidTimeIds","prevState","updatedInvalidOpeningTimes","invalidOpeningTime","some","updatedInvalidOpeningId","length","push","updatedInvalidOpeningTime","handleRemove","content","items","forEach","weekdayId","weekday","weekDay","name","createElement","key","isChecked","onInvalid","onRemove","onAdd","size","hidePopup","current","hide","showPopup","show","displayedContent","singleDay","style","width","onMouseEnter","onMouseLeave","onClick","onShow","onHide","shouldShowHint","Top","text","displayName"],"sources":["../../../../src/components/opening-times/OpeningTimes.tsx"],"sourcesContent":["import { Checkbox, Popup, useElementSize, type PopupRef } from '@chayns-components/core';\nimport React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactElement,\n} from 'react';\nimport {\n HintTextPosition,\n type OnChange,\n type OnTimeAdd,\n type OpeningTime,\n type Time,\n type Weekday,\n} from '../../types/openingTimes';\nimport HintText from './hint-text/HintText';\nimport OpeningInputs from './opening-inputs/OpeningInputs';\nimport {\n StyledOpeningTimes,\n StyledOpeningTimesTooltipContent,\n StyledOpeningTimesWeekDay,\n StyledOpeningTimesWrapper,\n} from './OpeningTimes.styles';\n\nexport type OpeningTimesProps = {\n /**\n * The text that should be displayed when a day is closed.\n */\n closedText?: string;\n /**\n * If set just the current day is displayed and the whole week in a tooltip.\n */\n currentDayId?: OpeningTime['id'];\n /**\n * Whether the opening times can be edited.\n */\n editMode?: boolean;\n /**\n * The text that should be displayed if times are colliding.\n */\n hintText?: string;\n /**\n * The position of the hint text.\n */\n hintTextPosition?: HintTextPosition;\n /**\n * Function to be executed when a time is changed or a day is enabled/disabled.\n * @param openingTimes\n */\n onChange?: ({ time, enabledDays, dayId, isValid }: OnChange) => void;\n /**\n * Function to be executed when a time is added.\n */\n onTimeAdd?: ({ time, dayId, isValid }: OnTimeAdd) => void;\n /**\n * Function to be executed when a time is removed.\n */\n onTimeRemove?: (id: string) => void;\n /**\n * The opening times corresponding to its weekday.\n */\n openingTimes: OpeningTime[];\n /**\n * The weekdays that should be displayed.\n */\n weekdays: Weekday[];\n};\n\nconst OpeningTimes: FC<OpeningTimesProps> = ({\n closedText = 'closed',\n currentDayId,\n editMode = false,\n hintText,\n hintTextPosition = HintTextPosition.Bottom,\n openingTimes,\n weekdays,\n onChange,\n onTimeAdd,\n onTimeRemove,\n}) => {\n const [newOpeningTimes, setNewOpeningTimes] = useState<OpeningTime[]>();\n const [invalidOpeningTimes, setInvalidOpeningTimes] = useState<\n { openingTimeId: string; invalidTimeIds: string[] }[]\n >([]);\n const [isPopupOpen, setIsPopupOpen] = useState(false);\n\n const ref = useRef<HTMLDivElement>(null);\n const popupRef = useRef<PopupRef>(null);\n\n useEffect(() => {\n setNewOpeningTimes(openingTimes);\n }, [openingTimes]);\n\n const validateTime = useCallback(\n (newTime: Time, dayId: string): boolean => {\n if (newTime.start === newTime.end || newTime.start >= newTime.end) {\n return false;\n }\n const dayTimes = newOpeningTimes?.find((day) => day.id === dayId)?.times || [];\n\n return dayTimes.every(\n (time) =>\n time.id === newTime.id ||\n newTime.end <= time.start ||\n newTime.start >= time.end,\n );\n },\n [newOpeningTimes],\n );\n\n const handleCheckBoxChange = useCallback(\n (id: string) => {\n setNewOpeningTimes((prevOpeningTimes) => {\n const updatedOpeningTimes = (prevOpeningTimes ?? []).map((openingTime) => {\n if (openingTime.id === id) {\n return { ...openingTime, isDisabled: !openingTime.isDisabled };\n }\n return openingTime;\n });\n\n if (typeof onChange === 'function') {\n onChange({\n enabledDays: updatedOpeningTimes\n .filter((item) => !item.isDisabled)\n .map((item) => item.id),\n });\n }\n\n return updatedOpeningTimes;\n });\n },\n [onChange],\n );\n\n const handleChange = useCallback(\n (newTime: Time, id: string) => {\n const isValid = validateTime(newTime, id);\n\n setNewOpeningTimes((prevOpeningTimes) => {\n const updatedOpeningTimes = (prevOpeningTimes ?? []).map((openingTime) => {\n if (openingTime.id === id) {\n const newTimes = openingTime.times.map((time) => {\n if (time.id === newTime.id) {\n return newTime;\n }\n return time;\n });\n return { ...openingTime, times: newTimes };\n }\n return openingTime;\n });\n\n const changedOpeningTime = updatedOpeningTimes.find(\n (updatedOpeningTime) => updatedOpeningTime.id === id,\n );\n\n if (typeof onChange === 'function') {\n onChange({\n isValid,\n dayId: changedOpeningTime?.id,\n time: newTime,\n });\n }\n\n return updatedOpeningTimes;\n });\n },\n [onChange, validateTime],\n );\n\n const handleAdd = useCallback(\n (time: Time, id: string) => {\n const isValid = validateTime(time, id);\n\n if (typeof onTimeAdd === 'function') {\n onTimeAdd({ time, dayId: id, isValid });\n }\n\n setNewOpeningTimes((prevOpeningTimes) =>\n (prevOpeningTimes ?? []).map((openingTime) => {\n if (openingTime.id === id) {\n return { ...openingTime, times: [...openingTime.times, time] };\n }\n return openingTime;\n }),\n );\n },\n [onTimeAdd, validateTime],\n );\n\n const handleUpdateInvalidIds = useCallback(\n (openingTimeId: string, invalidTimeIds: string[]) => {\n setInvalidOpeningTimes((prevState) => {\n const updatedInvalidOpeningTimes = prevState.map((invalidOpeningTime) => {\n if (invalidOpeningTime.openingTimeId === openingTimeId) {\n return {\n openingTimeId,\n invalidTimeIds,\n };\n }\n return invalidOpeningTime;\n });\n\n if (\n !updatedInvalidOpeningTimes.some(\n ({ openingTimeId: updatedInvalidOpeningId }) =>\n updatedInvalidOpeningId === openingTimeId,\n ) &&\n invalidTimeIds.length > 0\n ) {\n updatedInvalidOpeningTimes.push({ openingTimeId, invalidTimeIds });\n }\n\n return updatedInvalidOpeningTimes.filter(\n (updatedInvalidOpeningTime) =>\n updatedInvalidOpeningTime.invalidTimeIds.length !== 0,\n );\n });\n },\n [],\n );\n\n const handleRemove = useCallback(\n (id: string) => {\n setNewOpeningTimes((prevOpeningTimes) =>\n (prevOpeningTimes ?? []).map((openingTime) => {\n const newTimes = openingTime.times.filter((time) => time.id !== id);\n\n return { ...openingTime, times: newTimes };\n }),\n );\n\n if (typeof onTimeRemove === 'function') {\n onTimeRemove(id);\n }\n },\n [onTimeRemove],\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n if (!newOpeningTimes) {\n return items;\n }\n\n newOpeningTimes.forEach(({ times, id, weekdayId, isDisabled }) => {\n const weekday = weekdays.find((weekDay) => weekDay.id === weekdayId)?.name;\n\n if (!weekday) {\n return;\n }\n\n items.push(\n <StyledOpeningTimesWrapper key={`openingTimes__${id}`}>\n {editMode ? (\n <Checkbox isChecked={!isDisabled} onChange={() => handleCheckBoxChange(id)}>\n {weekday}\n </Checkbox>\n ) : (\n <StyledOpeningTimesWeekDay>{weekday}</StyledOpeningTimesWeekDay>\n )}\n <OpeningInputs\n closedText={closedText}\n currentDayId={currentDayId}\n id={id}\n times={times}\n isDisabled={isDisabled}\n onInvalid={handleUpdateInvalidIds}\n onChange={(newTime) => handleChange(newTime, id)}\n onRemove={handleRemove}\n onAdd={handleAdd}\n editMode={editMode}\n />\n </StyledOpeningTimesWrapper>,\n );\n });\n\n return items;\n }, [\n closedText,\n currentDayId,\n editMode,\n handleAdd,\n handleChange,\n handleCheckBoxChange,\n handleRemove,\n handleUpdateInvalidIds,\n newOpeningTimes,\n weekdays,\n ]);\n\n const size = useElementSize(ref);\n\n const hidePopup = useCallback(() => {\n setIsPopupOpen(false);\n popupRef.current?.hide();\n }, []);\n\n const showPopup = useCallback(() => {\n setIsPopupOpen(true);\n popupRef.current?.show();\n }, []);\n\n const displayedContent = useMemo(() => {\n if (!currentDayId || editMode) {\n return content;\n }\n\n const singleDay = newOpeningTimes?.find(({ id }) => id === currentDayId);\n\n if (!singleDay) {\n return content;\n }\n\n const { id, times, weekdayId } = singleDay;\n\n const weekday = weekdays.find((weekDay) => weekDay.id === weekdayId)?.name;\n\n return (\n <StyledOpeningTimesWrapper\n key={`currentDay__${currentDayId}`}\n style={size && { width: size.width }}\n onMouseEnter={showPopup}\n onMouseLeave={hidePopup}\n onClick={() => (isPopupOpen ? hidePopup() : showPopup())}\n >\n <Popup\n onShow={() => setIsPopupOpen(true)}\n onHide={() => setIsPopupOpen(false)}\n ref={popupRef}\n content={\n <StyledOpeningTimesTooltipContent key=\"opening-time-tooltip\">\n {content}\n </StyledOpeningTimesTooltipContent>\n }\n >\n <StyledOpeningTimesWeekDay>{weekday}</StyledOpeningTimesWeekDay>\n </Popup>\n <OpeningInputs\n closedText={closedText}\n currentDayId={currentDayId}\n onInvalid={handleUpdateInvalidIds}\n id={id}\n times={times}\n editMode={editMode}\n />\n </StyledOpeningTimesWrapper>\n );\n }, [\n currentDayId,\n editMode,\n newOpeningTimes,\n weekdays,\n size,\n showPopup,\n hidePopup,\n content,\n closedText,\n handleUpdateInvalidIds,\n isPopupOpen,\n ]);\n\n const shouldShowHint = useMemo(\n () => invalidOpeningTimes.length > 0,\n [invalidOpeningTimes.length],\n );\n\n return useMemo(\n () => (\n <StyledOpeningTimes ref={ref}>\n {shouldShowHint && hintText && hintTextPosition === HintTextPosition.Top && (\n <HintText text={hintText} />\n )}\n {displayedContent}\n {shouldShowHint && hintText && hintTextPosition === HintTextPosition.Bottom && (\n <HintText text={hintText} />\n )}\n </StyledOpeningTimes>\n ),\n [displayedContent, hintText, hintTextPosition, shouldShowHint],\n );\n};\n\nOpeningTimes.displayName = 'OpeningTimes';\n\nexport default OpeningTimes;\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,KAAK,EAAEC,cAAc,QAAuB,yBAAyB;AACxF,OAAOC,KAAK,IAERC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QAEL,OAAO;AACd,SACIC,gBAAgB,QAMb,0BAA0B;AACjC,OAAOC,QAAQ,MAAM,sBAAsB;AAC3C,OAAOC,aAAa,MAAM,gCAAgC;AAC1D,SACIC,kBAAkB,EAClBC,gCAAgC,EAChCC,yBAAyB,EACzBC,yBAAyB,QACtB,uBAAuB;AA8C9B,MAAMC,YAAmC,GAAGA,CAAC;EACzCC,UAAU,GAAG,QAAQ;EACrBC,YAAY;EACZC,QAAQ,GAAG,KAAK;EAChBC,QAAQ;EACRC,gBAAgB,GAAGZ,gBAAgB,CAACa,MAAM;EAC1CC,YAAY;EACZC,QAAQ;EACRC,QAAQ;EACRC,SAAS;EACTC;AACJ,CAAC,KAAK;EACF,MAAM,CAACC,eAAe,EAAEC,kBAAkB,C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padding: 8px;
|
|
15
15
|
`;
|
|
16
16
|
export const StyledOpeningTimesWeekDay = styled.div`
|
|
17
|
-
color: ${
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} = _ref;
|
|
21
|
-
return theme.text;
|
|
22
|
-
}};
|
|
17
|
+
color: ${({
|
|
18
|
+
theme
|
|
19
|
+
}) => theme.text};
|
|
23
20
|
`;
|
|
24
21
|
//# sourceMappingURL=OpeningTimes.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpeningTimes.styles.js","names":["styled","StyledOpeningTimes","div","StyledOpeningTimesWrapper","StyledOpeningTimesTooltipContent","StyledOpeningTimesWeekDay","
|
|
1
|
+
{"version":3,"file":"OpeningTimes.styles.js","names":["styled","StyledOpeningTimes","div","StyledOpeningTimesWrapper","StyledOpeningTimesTooltipContent","StyledOpeningTimesWeekDay","theme","text"],"sources":["../../../../src/components/opening-times/OpeningTimes.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\n\ntype StyledSliderButtonProps = WithTheme<{ $isDisabled?: boolean }>;\n\nexport const StyledOpeningTimes = styled.div<StyledSliderButtonProps>`\n display: flex;\n flex-direction: column;\n gap: 8px;\n`;\n\nexport const StyledOpeningTimesWrapper = styled.div`\n display: flex;\n align-items: baseline;\n justify-content: space-between;\n min-width: 300px;\n`;\n\nexport const StyledOpeningTimesTooltipContent = styled.div`\n padding: 8px;\n`;\n\ntype StyledOpeningTimesWeekDayProps = WithTheme<unknown>;\n\nexport const StyledOpeningTimesWeekDay = styled.div<StyledOpeningTimesWeekDayProps>`\n color: ${({ theme }: StyledOpeningTimesWeekDayProps) => theme.text};\n`;\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,mBAAmB;AAItC,OAAO,MAAMC,kBAAkB,GAAGD,MAAM,CAACE,GAA4B;AACrE;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,yBAAyB,GAAGH,MAAM,CAACE,GAAG;AACnD;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAME,gCAAgC,GAAGJ,MAAM,CAACE,GAAG;AAC1D;AACA,CAAC;AAID,OAAO,MAAMG,yBAAyB,GAAGL,MAAM,CAACE,GAAmC;AACnF,aAAa,CAAC;EAAEI;AAAsC,CAAC,KAAKA,KAAK,CAACC,IAAI;AACtE,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import React, { useMemo, useState } from 'react';
|
|
2
2
|
import { StyledHintText } from './HintText.styles';
|
|
3
|
-
const HintText =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} = _ref;
|
|
3
|
+
const HintText = ({
|
|
4
|
+
text
|
|
5
|
+
}) => {
|
|
7
6
|
const [newHintText, setNewHintText] = useState();
|
|
8
7
|
return useMemo(() => /*#__PURE__*/React.createElement(StyledHintText, null, text), [text]);
|
|
9
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HintText.js","names":["React","useMemo","useState","StyledHintText","HintText","
|
|
1
|
+
{"version":3,"file":"HintText.js","names":["React","useMemo","useState","StyledHintText","HintText","text","newHintText","setNewHintText","createElement","displayName"],"sources":["../../../../../src/components/opening-times/hint-text/HintText.tsx"],"sourcesContent":["import React, { FC, useMemo, useState } from 'react';\nimport { StyledHintText } from './HintText.styles';\n\nexport type HintTextProps = {\n text: string;\n};\n\nconst HintText: FC<HintTextProps> = ({ text }) => {\n const [newHintText, setNewHintText] = useState<string>();\n\n return useMemo(() => <StyledHintText>{text}</StyledHintText>, [text]);\n};\n\nHintText.displayName = 'HintText';\n\nexport default HintText;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACpD,SAASC,cAAc,QAAQ,mBAAmB;AAMlD,MAAMC,QAA2B,GAAGA,CAAC;EAAEC;AAAK,CAAC,KAAK;EAC9C,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGL,QAAQ,CAAS,CAAC;EAExD,OAAOD,OAAO,CAAC,mBAAMD,KAAA,CAAAQ,aAAA,CAACL,cAAc,QAAEE,IAAqB,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;AACzE,CAAC;AAEDD,QAAQ,CAACK,WAAW,GAAG,UAAU;AAEjC,eAAeL,QAAQ","ignoreList":[]}
|
|
@@ -7,17 +7,11 @@ export const StyledHintText = styled.div`
|
|
|
7
7
|
color: #222;
|
|
8
8
|
padding: 8px 12px;
|
|
9
9
|
|
|
10
|
-
border-radius: ${
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}}
|
|
16
|
-
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, ${_ref2 => {
|
|
17
|
-
let {
|
|
18
|
-
theme
|
|
19
|
-
} = _ref2;
|
|
20
|
-
return theme.cardShadow;
|
|
21
|
-
}});
|
|
10
|
+
border-radius: ${({
|
|
11
|
+
theme
|
|
12
|
+
}) => theme.cardBorderRadius}px;
|
|
13
|
+
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, ${({
|
|
14
|
+
theme
|
|
15
|
+
}) => theme.cardShadow});
|
|
22
16
|
`;
|
|
23
17
|
//# sourceMappingURL=HintText.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HintText.styles.js","names":["styled","StyledHintText","div","
|
|
1
|
+
{"version":3,"file":"HintText.styles.js","names":["styled","StyledHintText","div","theme","cardBorderRadius","cardShadow"],"sources":["../../../../../src/components/opening-times/hint-text/HintText.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\n\ntype StyledHintTextProp = WithTheme<unknown>;\n\nexport const StyledHintText = styled.div<StyledHintTextProp>`\n border-width: 1px;\n border-style: solid;\n border-color: #9f5f00;\n background-color: #fff3e0;\n color: #222;\n padding: 8px 12px;\n\n border-radius: ${({ theme }: StyledHintTextProp) => theme.cardBorderRadius}px;\n box-shadow: 0 2px 6px 0 rgba(0, 0, 0, ${({ theme }: StyledHintTextProp) => theme.cardShadow});\n`;\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,mBAAmB;AAItC,OAAO,MAAMC,cAAc,GAAGD,MAAM,CAACE,GAAuB;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB,CAAC;EAAEC;AAA0B,CAAC,KAAKA,KAAK,CAACC,gBAAgB;AAC9E,4CAA4C,CAAC;EAAED;AAA0B,CAAC,KAAKA,KAAK,CAACE,UAAU;AAC/F,CAAC","ignoreList":[]}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { AnimatePresence } from '
|
|
1
|
+
import { AnimatePresence } from 'motion/react';
|
|
2
2
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { v4 as uuidV4 } from 'uuid';
|
|
4
4
|
import { OpeningTimesButtonType } from '../../../types/openingTimes';
|
|
5
5
|
import OpeningInput from './opening-input/OpeningInput';
|
|
6
6
|
import { StyledOpeningInputPreview, StyledOpeningInputs } from './OpeningInputs.styles';
|
|
7
|
-
const OpeningInputs =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} = _ref;
|
|
7
|
+
const OpeningInputs = ({
|
|
8
|
+
times,
|
|
9
|
+
isDisabled,
|
|
10
|
+
onRemove,
|
|
11
|
+
onAdd,
|
|
12
|
+
onInvalid,
|
|
13
|
+
id,
|
|
14
|
+
onChange,
|
|
15
|
+
currentDayId,
|
|
16
|
+
editMode = false,
|
|
17
|
+
closedText = ''
|
|
18
|
+
}) => {
|
|
20
19
|
const [newTimes, setNewTimes] = useState();
|
|
21
20
|
const [invalidTimes, setInvalidTimes] = useState([]);
|
|
22
21
|
useEffect(() => {
|
|
@@ -58,12 +57,9 @@ const OpeningInputs = _ref => {
|
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
const invalidTimeIds = result.map(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} = _ref2;
|
|
65
|
-
return invalidId;
|
|
66
|
-
});
|
|
60
|
+
const invalidTimeIds = result.map(({
|
|
61
|
+
id: invalidId
|
|
62
|
+
}) => invalidId);
|
|
67
63
|
setInvalidTimes(invalidTimeIds);
|
|
68
64
|
if (typeof onInvalid === 'function') {
|
|
69
65
|
onInvalid(id, invalidTimeIds);
|
|
@@ -88,12 +84,11 @@ const OpeningInputs = _ref => {
|
|
|
88
84
|
if (!newTimes) {
|
|
89
85
|
return items;
|
|
90
86
|
}
|
|
91
|
-
newTimes.forEach((
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
} = _ref3;
|
|
87
|
+
newTimes.forEach(({
|
|
88
|
+
end,
|
|
89
|
+
start,
|
|
90
|
+
id: timeId
|
|
91
|
+
}, index) => {
|
|
97
92
|
if (!editMode) {
|
|
98
93
|
const text = isDisabled ? closedText : `${start} - ${end}`;
|
|
99
94
|
items.push(/*#__PURE__*/React.createElement(StyledOpeningInputPreview, {
|
|
@@ -1 +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;EAE9D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C4D,WAAW,GAAG,eAAe;AAE3C,eAAe5D,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"OpeningInputs.js","names":["AnimatePresence","React","useCallback","useEffect","useMemo","useState","v4","uuidV4","OpeningTimesButtonType","OpeningInput","StyledOpeningInputPreview","StyledOpeningInputs","OpeningInputs","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","invalidId","handleChange","newTime","updatedTimes","content","items","forEach","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 'motion/react';\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,cAAc;AAC9C,OAAOC,KAAK,IAAQC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAA2B,OAAO;AAC/F,SAASC,EAAE,IAAIC,MA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OnB,OAAO,CACV,mBACIH,KAAA,CAAAwD,aAAA,CAAC9C,mBAAmB;IAChBuD,SAAS,EAAE,CAAC9C,YAAa;IACzBsC,GAAG,EAAE,mBAAmBxC,EAAE,EAAG;IAC7BiD,OAAO,EAAE;MAAEF;IAAI,CAAE;IACjBG,OAAO,EAAE;MAAEH,GAAG,EAAE;IAAE;EAAE,gBAEpBhE,KAAA,CAAAwD,aAAA,CAACzD,eAAe;IAACoE,OAAO,EAAE;EAAM,GAAEhB,OAAyB,CAC1C,CACxB,EACD,CAACA,OAAO,EAAEhC,YAAY,EAAE6C,GAAG,EAAE/C,EAAE,CACnC,CAAC;AACL,CAAC;AAEDN,aAAa,CAACyD,WAAW,GAAG,eAAe;AAE3C,eAAezD,aAAa","ignoreList":[]}
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import { motion } from '
|
|
1
|
+
import { motion } from 'motion/react';
|
|
2
2
|
import styled, { css } from 'styled-components';
|
|
3
3
|
export const StyledOpeningInputs = styled(motion.div)`
|
|
4
4
|
display: flex;
|
|
5
|
-
${
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} = _ref;
|
|
9
|
-
return $editMode && css`
|
|
5
|
+
${({
|
|
6
|
+
$editMode
|
|
7
|
+
}) => $editMode && css`
|
|
10
8
|
flex-direction: column;
|
|
11
|
-
|
|
12
|
-
}}
|
|
9
|
+
`}
|
|
13
10
|
`;
|
|
14
11
|
export const StyledOpeningInputPreview = styled.div`
|
|
15
|
-
color: ${
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} = _ref2;
|
|
19
|
-
return theme.text;
|
|
20
|
-
}};
|
|
12
|
+
color: ${({
|
|
13
|
+
theme
|
|
14
|
+
}) => theme.text};
|
|
21
15
|
`;
|
|
22
16
|
//# sourceMappingURL=OpeningInputs.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpeningInputs.styles.js","names":["motion","styled","css","StyledOpeningInputs","div","
|
|
1
|
+
{"version":3,"file":"OpeningInputs.styles.js","names":["motion","styled","css","StyledOpeningInputs","div","$editMode","StyledOpeningInputPreview","theme","text"],"sources":["../../../../../src/components/opening-times/opening-inputs/OpeningInputs.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport { motion } from 'motion/react';\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,cAAc;AACrC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAI/C,OAAO,MAAMC,mBAAmB,GAAGF,MAAM,CAACD,MAAM,CAACI,GAAG,CAA2B;AAC/E;AACA,MAAM,CAAC;EAAEC;AAAU,CAAC,KACZA,SAAS,IACTH,GAAG;AACX;AACA,SAAS;AACT,CAAC;AAID,OAAO,MAAMI,yBAAyB,GAAGL,MAAM,CAACG,GAAmC;AACnF,aAAa,CAAC;EAAEG;AAAsC,CAAC,KAAKA,KAAK,CAACC,IAAI;AACtE,CAAC","ignoreList":[]}
|
|
@@ -2,18 +2,17 @@ import { Icon, NumberInput } from '@chayns-components/core';
|
|
|
2
2
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
3
|
import { OpeningTimesButtonType } from '../../../../types/openingTimes';
|
|
4
4
|
import { StyledOpeningInput, StyledOpeningInputButtonWrapper, StyledOpeningInputPseudoButton, StyledOpeningInputText, StyledOpeningInputWrapper } from './OpeningInput.styles';
|
|
5
|
-
const OpeningInput =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = _ref;
|
|
5
|
+
const OpeningInput = ({
|
|
6
|
+
end,
|
|
7
|
+
start,
|
|
8
|
+
isDisabled,
|
|
9
|
+
isInvalid,
|
|
10
|
+
buttonType,
|
|
11
|
+
onRemove,
|
|
12
|
+
onAdd,
|
|
13
|
+
onChange,
|
|
14
|
+
id
|
|
15
|
+
}) => {
|
|
17
16
|
const [startTime, setStartTime] = useState(start);
|
|
18
17
|
const [endTime, setEndTime] = useState(end);
|
|
19
18
|
const button = useMemo(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpeningInput.js","names":["Icon","NumberInput","React","useCallback","useMemo","useState","OpeningTimesButtonType","StyledOpeningInput","StyledOpeningInputButtonWrapper","StyledOpeningInputPseudoButton","StyledOpeningInputText","StyledOpeningInputWrapper","OpeningInput","
|
|
1
|
+
{"version":3,"file":"OpeningInput.js","names":["Icon","NumberInput","React","useCallback","useMemo","useState","OpeningTimesButtonType","StyledOpeningInput","StyledOpeningInputButtonWrapper","StyledOpeningInputPseudoButton","StyledOpeningInputText","StyledOpeningInputWrapper","OpeningInput","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,GAAGA,CAAC;EACzCC,GAAG;EACHC,KAAK;EACLC,UAAU;EACVC,SAAS;EACTC,UAAU;EACVC,QAAQ;EACRC,KAAK;EACLC,QAAQ;EACRC;AACJ,CAAC,KAAK;EACF,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGlB,QAAQ,CAACS,KAAK,CAAC;EACjD,MAAM,CAACU,OAAO,EAAEC,UAAU,CAAC,GAAGpB,QAAQ,CAACQ,GAAG,CAAC;EAE3C,MAAMa,MAAM,GAAGtB,OAAO,CAAC,MAAM;IACzB,QAAQa,UAAU;MACd,KAAKX,sBAAsB,CAACqB,GAAG;QAC3B,oBACIzB,KAAA,CAAA0B,aAAA,CAACpB,+BAA+B;UAACqB,OAAO,EAAEV;QAAM,gBAC5CjB,KAAA,CAAA0B,aAAA,CAAC5B,IAAI;UAAC8B,KAAK,EA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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { motion } from '
|
|
1
|
+
import { motion } from 'motion/react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
export const StyledOpeningInput = styled(motion.div)`
|
|
4
4
|
display: flex;
|
|
@@ -10,22 +10,16 @@ export const StyledOpeningInputWrapper = styled.div`
|
|
|
10
10
|
width: 60px;
|
|
11
11
|
`;
|
|
12
12
|
export const StyledOpeningInputText = styled.div`
|
|
13
|
-
opacity: ${
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = _ref;
|
|
17
|
-
return $isDisabled ? 0.5 : 1;
|
|
18
|
-
}};
|
|
13
|
+
opacity: ${({
|
|
14
|
+
$isDisabled
|
|
15
|
+
}) => $isDisabled ? 0.5 : 1};
|
|
19
16
|
`;
|
|
20
17
|
export const StyledOpeningInputButtonWrapper = styled.div`
|
|
21
18
|
width: 20px;
|
|
22
19
|
height: 20px;
|
|
23
|
-
background-color: ${
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} = _ref2;
|
|
27
|
-
return theme['202'];
|
|
28
|
-
}};
|
|
20
|
+
background-color: ${({
|
|
21
|
+
theme
|
|
22
|
+
}) => theme['202']};
|
|
29
23
|
border-radius: 3px;
|
|
30
24
|
box-shadow: 1px 2px 3px rgba(0, 0, 0, 0.2);
|
|
31
25
|
border: none;
|
package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpeningInput.styles.js","names":["motion","styled","StyledOpeningInput","div","StyledOpeningInputWrapper","StyledOpeningInputText","
|
|
1
|
+
{"version":3,"file":"OpeningInput.styles.js","names":["motion","styled","StyledOpeningInput","div","StyledOpeningInputWrapper","StyledOpeningInputText","$isDisabled","StyledOpeningInputButtonWrapper","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 'motion/react';\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,cAAc;AACrC,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,eAAe,CAAC;EAAEG;AAAY,CAAC,KAAMA,WAAW,GAAG,GAAG,GAAG,CAAE;AAC3D,CAAC;AAID,OAAO,MAAMC,+BAA+B,GAAGN,MAAM,CAACE,GAAG;AACzD;AACA;AACA,wBAAwB,CAAC;EAAEK;AAA4C,CAAC,KAAKA,KAAK,CAAC,KAAK,CAAC;AACzF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,8BAA8B,GAAGR,MAAM,CAACE,GAAG;AACxD;AACA,CAAC","ignoreList":[]}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { getLanguage } from 'chayns-api';
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { getDateInfo, getTimeTillNow } from '../utils/dateInfo';
|
|
4
|
-
export const useDateInfo =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
export const useDateInfo = ({
|
|
5
|
+
date,
|
|
6
|
+
shouldShowDateToNowDifference,
|
|
7
|
+
shouldShowRelativeDayOfWeek,
|
|
8
|
+
shouldShowDayOfWeek,
|
|
9
|
+
shouldShowTime,
|
|
10
|
+
shouldUseShortText,
|
|
11
|
+
shouldShowOnlyTime,
|
|
12
|
+
shouldShowYear,
|
|
13
|
+
preText
|
|
14
|
+
}) => {
|
|
15
15
|
const {
|
|
16
16
|
active: language
|
|
17
17
|
} = getLanguage();
|
|
@@ -24,12 +24,13 @@ export const useDateInfo = _ref => {
|
|
|
24
24
|
setFormattedDate(getDateInfo({
|
|
25
25
|
date,
|
|
26
26
|
shouldShowYear,
|
|
27
|
+
shouldShowOnlyTime,
|
|
27
28
|
shouldShowTime,
|
|
28
29
|
shouldUseShortText,
|
|
29
30
|
shouldShowDayOfWeek,
|
|
30
31
|
shouldShowRelativeDayOfWeek
|
|
31
32
|
}));
|
|
32
|
-
}, [date, shouldShowDateToNowDifference, shouldShowDayOfWeek, shouldShowRelativeDayOfWeek, shouldShowTime, shouldShowYear, shouldUseShortText]);
|
|
33
|
+
}, [date, shouldShowDateToNowDifference, shouldShowDayOfWeek, shouldShowOnlyTime, shouldShowRelativeDayOfWeek, shouldShowTime, shouldShowYear, shouldUseShortText]);
|
|
33
34
|
useEffect(() => {
|
|
34
35
|
if (!shouldShowDateToNowDifference) return () => {};
|
|
35
36
|
const updateCurrentDate = () => setCurrentDate(new Date());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDateInfo.js","names":["getLanguage","useEffect","useMemo","useState","getDateInfo","getTimeTillNow","useDateInfo","
|
|
1
|
+
{"version":3,"file":"useDateInfo.js","names":["getLanguage","useEffect","useMemo","useState","getDateInfo","getTimeTillNow","useDateInfo","date","shouldShowDateToNowDifference","shouldShowRelativeDayOfWeek","shouldShowDayOfWeek","shouldShowTime","shouldUseShortText","shouldShowOnlyTime","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 shouldShowOnlyTime,\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 shouldShowOnlyTime,\n shouldShowTime,\n shouldUseShortText,\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n }),\n );\n }, [\n date,\n shouldShowDateToNowDifference,\n shouldShowDayOfWeek,\n shouldShowOnlyTime,\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,GAAGA,CAAC;EACxBC,IAAI;EACJC,6BAA6B;EAC7BC,2BAA2B;EAC3BC,mBAAmB;EACnBC,cAAc;EACdC,kBAAkB;EAClBC,kBAAkB;EAClBC,cAAc;EACdC;AACgB,CAAC,KAAK;EACtB,MAAM;IAAEC,MAAM,EAAEC;EAAS,CAAC,GAAGjB,WAAW,CAAC,CAAC;EAE1C,MAAM,CAACkB,aAAa,EAAEC,gBAAgB,CAAC,GAAGhB,QAAQ,CAACI,IAAI,CAACa,kBAAkB,CAAC,CAAC,CAAC;EAC7E,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGnB,QAAQ,CAAC,IAAIoB,IAAI,CAAC,CAAC,CAAC;EAE1DtB,SAAS,CAAC,MAAM;IACZ,IAAIO,6BAA6B,EAAE;MAC/B;IACJ;IAEAW,gBAAgB,CACZf,WAAW,CAAC;MACRG,IAAI;MACJO,cAAc;MACdD,kBAAkB;MAClBF,cAAc;MAC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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
CHANGED
|
@@ -8,7 +8,7 @@ export { default as OpeningTimes } from './components/opening-times/OpeningTimes
|
|
|
8
8
|
// DateInfo
|
|
9
9
|
export { default as DateInfo } from './components/date-info/DateInfo';
|
|
10
10
|
export { useDateInfo } from './hooks/useDateInfo';
|
|
11
|
-
export { getDateInfo, getTimeTillNow } from './utils/dateInfo';
|
|
11
|
+
export { getDateInfo, getTimeTillNow, getFormattedTime } from './utils/dateInfo';
|
|
12
12
|
|
|
13
13
|
// Utils
|
|
14
14
|
export { isToday, getIsDateNearToday, isTomorrow, isYesterday, isMorning, isCurrentYear, addYears, addDays, isSameDay, eachDayOfInterval, isWithinInterval, subYears, endOfWeek, startOfWeek, isSameMonth, differenceInCalendarMonths, startOfMonth, isAfter, isBefore } from './utils/date';
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +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
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","Calendar","CalendarType","OpeningInputs","OpeningTimes","DateInfo","useDateInfo","getDateInfo","getTimeTillNow","getFormattedTime","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 {\n Categories,\n HighlightedDates,\n HighlightedDateStyles,\n DateInterval,\n CustomThumbColors,\n} 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, getFormattedTime } 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,SAASA,OAAO,IAAIC,QAAQ,QAAQ,gCAAgC;AAQpE,SAASC,YAAY,QAAQ,kBAAkB;;AAE/C;AACA,SAASF,OAAO,IAAIG,aAAa,QAAQ,yDAAyD;AAClG,SAASH,OAAO,IAAII,YAAY,QAAQ,yCAAyC;AAGjF;AACA,SAASJ,OAAO,IAAIK,QAAQ,QAAQ,iCAAiC;AACrE,SAASC,WAAW,QAAQ,qBAAqB;AACjD,SAASC,WAAW,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,kBAAkB;;AAEhF;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":[]}
|