@koine/react 1.0.5 → 1.0.8
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/Alert/Alert.js +18 -0
- package/Alert/index.js +1 -0
- package/Animations/Reveal.js +17 -0
- package/Animations/Underline.js +15 -0
- package/Animations/index.js +3 -0
- package/Animations/useReveal.js +70 -0
- package/Autocomplete/AutocompleteDownshift.js +158 -0
- package/Autocomplete/AutocompleteDownshiftMultiselect.js +353 -0
- package/Autocomplete/AutocompleteMui.js +172 -0
- package/Autocomplete/AutocompleteReach.js +112 -0
- package/Autocomplete/components.js +89 -0
- package/Autocomplete/helpers.js +28 -0
- package/Autocomplete/index.js +3 -0
- package/Bg/BgColor.js +33 -0
- package/Bg/BgPhoto.js +59 -0
- package/Bg/BgSvg.js +15 -0
- package/Bg/index.js +3 -0
- package/Breadcrumbs/Breadcrumbs.js +70 -0
- package/Breadcrumbs/index.js +1 -0
- package/Buttons/Button.js +79 -0
- package/Buttons/ButtonComposite.d.ts +1 -1
- package/Buttons/ButtonComposite.js +53 -0
- package/Buttons/ButtonFab.js +8 -0
- package/Buttons/ButtonLink.js +16 -0
- package/Buttons/IconButton.js +19 -0
- package/Buttons/index.js +5 -0
- package/Calendar/CalendarDaygridCell.js +52 -0
- package/Calendar/CalendarDaygridNav.js +23 -0
- package/Calendar/CalendarDaygridTable.js +49 -0
- package/Calendar/CalendarLegend.js +12 -0
- package/Calendar/calendar-api-google.js +97 -0
- package/Calendar/index.js +6 -0
- package/Calendar/types.js +1 -0
- package/Calendar/useCalendar.js +166 -0
- package/Calendar/utils.js +197 -0
- package/Carousel/Carousel.js +378 -0
- package/Carousel/CarouselCss.js +39 -0
- package/Carousel/index.js +1 -0
- package/Collapsable/Collapsable.js +132 -0
- package/Collapsable/index.js +1 -0
- package/Debug/Debug.js +21 -0
- package/Debug/index.js +1 -0
- package/Dialog/Dialog.js +93 -0
- package/Dialog/index.js +1 -0
- package/Editor/Editor--tiptap.js +21 -0
- package/Editor/components.d.ts +1 -2
- package/Editor/components.js +28 -0
- package/Editor/index.js +1 -0
- package/Favicon/FaviconTags.js +14 -0
- package/Favicon/index.js +1 -0
- package/Forms/Checkbox/Checkbox.js +24 -0
- package/Forms/Checkbox/index.js +1 -0
- package/Forms/Feedback/Feedback.js +10 -0
- package/Forms/Feedback/index.js +1 -0
- package/Forms/Field/Field.js +61 -0
- package/Forms/Field/FieldControl.js +45 -0
- package/Forms/Field/FieldHint.js +6 -0
- package/Forms/Field/index.js +2 -0
- package/Forms/Form/Form.js +64 -0
- package/Forms/Form/index.js +1 -0
- package/Forms/Input/Input.js +25 -0
- package/Forms/Input/index.js +1 -0
- package/Forms/InputGroup/InputGroup.js +42 -0
- package/Forms/InputGroup/index.js +1 -0
- package/Forms/Label/Label.js +24 -0
- package/Forms/Label/index.js +1 -0
- package/Forms/Password/Password.js +32 -0
- package/Forms/Password/index.js +1 -0
- package/Forms/Radio/Radio.js +31 -0
- package/Forms/Radio/index.js +1 -0
- package/Forms/Switch/Switch.js +50 -0
- package/Forms/Switch/index.js +1 -0
- package/Forms/Textarea/Textarea.js +15 -0
- package/Forms/Textarea/TextareaRich.js +44 -0
- package/Forms/Textarea/index.js +2 -0
- package/Forms/Toggle/Toggle.js +79 -0
- package/Forms/Toggle/index.js +1 -0
- package/Forms/Toggle/useToggle.js +143 -0
- package/Forms/antispam.js +56 -0
- package/Forms/helpers.js +44 -0
- package/Forms/index.js +17 -0
- package/Forms/styles.js +60 -0
- package/Gauge/Gauge.js +102 -0
- package/Grid/Grid.js +79 -0
- package/Grid/index.js +1 -0
- package/Hamburger/Hamburger.js +55 -0
- package/Hamburger/index.js +1 -0
- package/Header/index.js +1 -0
- package/Header/useHeader.js +30 -0
- package/Hidden/Hidden.js +14 -0
- package/Hidden/index.js +1 -0
- package/Img/Img.js +34 -0
- package/Img/index.js +1 -0
- package/Link/Link.js +2 -0
- package/Link/LinkBlank.d.ts +1 -1
- package/Link/LinkBlank.js +28 -0
- package/Link/index.js +2 -0
- package/Menu/Menu.js +11 -0
- package/Menu/index.js +1 -0
- package/MenuItem/MenuItem.js +20 -0
- package/MenuItem/index.js +1 -0
- package/Meta/Meta.js +4 -0
- package/Meta/index.js +1 -0
- package/NoJs/NoJs.js +6 -0
- package/NoJs/index.js +1 -0
- package/Pagination/PaginationNav.js +87 -0
- package/Pagination/PaginationResults.js +10 -0
- package/Pagination/index.js +2 -0
- package/Pill/Pill.js +37 -0
- package/Pill/index.js +1 -0
- package/Progress/ProgressCircular.js +38 -0
- package/Progress/ProgressLinear.js +34 -0
- package/Progress/ProgressOverlay.js +40 -0
- package/Progress/index.js +3 -0
- package/Rating/Rating.js +93 -0
- package/Rating/index.js +45 -0
- package/Select/SelectDownshift.js +38 -0
- package/Select/components.js +20 -0
- package/Select/index.js +3 -0
- package/Sidebar/Sidebar.js +48 -0
- package/Sidebar/index.js +1 -0
- package/Spacing/Spacing.js +47 -0
- package/Spacing/index.js +1 -0
- package/Sticky/Sticky.js +220 -0
- package/Sticky/StickyCss.js +6 -0
- package/Sticky/index.js +1 -0
- package/Tabs/Tabs.js +67 -0
- package/Tabs/index.js +1 -0
- package/Typography/CopyPasteVisible.js +6 -0
- package/Typography/Native.js +47 -0
- package/Typography/ReadMore.js +71 -0
- package/Typography/TextLoop.js +45 -0
- package/Typography/TypeStairs.js +46 -0
- package/Typography/index.js +5 -0
- package/helpers/index.js +19 -0
- package/hooks/index.js +5 -0
- package/hooks/useDateLocale.js +30 -0
- package/hooks/useFocus.js +11 -0
- package/hooks/usePrevious.js +8 -0
- package/hooks/useTraceUpdate.js +20 -0
- package/hooks/useWindowSize.js +13 -0
- package/index.js +36 -0
- package/index.umd.js +232 -239
- package/package.json +15 -9
- package/styles/Body.js +17 -0
- package/styles/Global.js +50 -0
- package/styles/classed.js +11 -0
- package/styles/index.js +7 -0
- package/styles/media.js +150 -0
- package/styles/spacing.d.ts +6 -6
- package/styles/spacing.js +46 -0
- package/styles/styled.d.ts +2 -2
- package/styles/styled.js +27 -0
- package/styles/theme--vanilla.js +53 -0
- package/styles/theme.d.ts +0 -7
- package/styles/theme.js +38 -0
- package/types.js +1 -0
- package/typings.d.ts +21 -0
- package/index.esm.js +0 -9456
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import isWithinInterval from "date-fns/isWithinInterval";
|
|
2
|
+
import endOfMonth from "date-fns/endOfMonth";
|
|
3
|
+
import startOfWeek from "date-fns/startOfWeek";
|
|
4
|
+
import endOfWeek from "date-fns/endOfWeek";
|
|
5
|
+
import subMonths from "date-fns/subMonths";
|
|
6
|
+
import addMonths from "date-fns/addMonths";
|
|
7
|
+
import subWeeks from "date-fns/subWeeks";
|
|
8
|
+
import addWeeks from "date-fns/addWeeks";
|
|
9
|
+
import addDays from "date-fns/addDays";
|
|
10
|
+
export function getEventTimestamp(dateLike) {
|
|
11
|
+
const date = new Date(dateLike);
|
|
12
|
+
date.setHours(0, 0, 0, 0);
|
|
13
|
+
return date.valueOf() / 1000;
|
|
14
|
+
}
|
|
15
|
+
export function getDisplayTime(date) {
|
|
16
|
+
return (date.getHours() +
|
|
17
|
+
":" +
|
|
18
|
+
"0".repeat(2 - date.getMinutes().toString().length) +
|
|
19
|
+
date.getMinutes());
|
|
20
|
+
}
|
|
21
|
+
export function getStartDate(date, view) {
|
|
22
|
+
date.setHours(0, 0, 0);
|
|
23
|
+
if (view === "month") {
|
|
24
|
+
date.setDate(1);
|
|
25
|
+
}
|
|
26
|
+
else if (view === "week") {
|
|
27
|
+
date = startOfWeek(date, { weekStartsOn: 1 });
|
|
28
|
+
}
|
|
29
|
+
return date;
|
|
30
|
+
}
|
|
31
|
+
export function getEndDate(start, view) {
|
|
32
|
+
let end = start;
|
|
33
|
+
if (view === "month") {
|
|
34
|
+
end = endOfMonth(start);
|
|
35
|
+
}
|
|
36
|
+
else if (view === "week") {
|
|
37
|
+
end = endOfWeek(start, { weekStartsOn: 1 });
|
|
38
|
+
}
|
|
39
|
+
end.setHours(23, 59, 59);
|
|
40
|
+
return end;
|
|
41
|
+
}
|
|
42
|
+
export function getPrevDate(date, view) {
|
|
43
|
+
if (view === "month") {
|
|
44
|
+
return subMonths(date, 1);
|
|
45
|
+
}
|
|
46
|
+
return subWeeks(date, 1);
|
|
47
|
+
}
|
|
48
|
+
export function getNextDate(date, view) {
|
|
49
|
+
if (view === "month") {
|
|
50
|
+
return addMonths(date, 1);
|
|
51
|
+
}
|
|
52
|
+
return addWeeks(date, 1);
|
|
53
|
+
}
|
|
54
|
+
export function isTodayInView(start, end) {
|
|
55
|
+
return isWithinInterval(new Date(), { start, end });
|
|
56
|
+
}
|
|
57
|
+
export function mergeCalendarEvents(first, second) {
|
|
58
|
+
const all = {};
|
|
59
|
+
addCalendarEvents(first, all);
|
|
60
|
+
addCalendarEvents(second, all);
|
|
61
|
+
return all;
|
|
62
|
+
}
|
|
63
|
+
export function addCalendarEvents(toAdd, toExtend) {
|
|
64
|
+
for (const id in toAdd) {
|
|
65
|
+
const event = toAdd[id];
|
|
66
|
+
toExtend[id] = event;
|
|
67
|
+
}
|
|
68
|
+
return toExtend;
|
|
69
|
+
}
|
|
70
|
+
function getEventsByTimestamp(events) {
|
|
71
|
+
const output = {};
|
|
72
|
+
for (const uid in events) {
|
|
73
|
+
const event = events[uid];
|
|
74
|
+
event.days.forEach((timestamp) => {
|
|
75
|
+
output[timestamp] = (output[timestamp] || {});
|
|
76
|
+
output[timestamp][uid] = event;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return output;
|
|
80
|
+
}
|
|
81
|
+
function getSortedEvents(events) {
|
|
82
|
+
const output = [];
|
|
83
|
+
for (const uid in events) {
|
|
84
|
+
output.push(events[uid]);
|
|
85
|
+
}
|
|
86
|
+
// sort events first multi, then all day then by start then by created date
|
|
87
|
+
output.sort((a, b) => {
|
|
88
|
+
const multi = Number(b.multi) - Number(a.multi);
|
|
89
|
+
const allDay = Number(b.allDay) - Number(a.allDay);
|
|
90
|
+
const start = a.start.getTime() - b.start.getTime();
|
|
91
|
+
const created = a.created.getTime() - b.created.getTime();
|
|
92
|
+
return multi || allDay || start || created;
|
|
93
|
+
});
|
|
94
|
+
return output;
|
|
95
|
+
}
|
|
96
|
+
const FREE_SLOT = 0;
|
|
97
|
+
const BUSY_SLOT = 1;
|
|
98
|
+
export function processEventsInView(eventsMap, calendarView, month, weeks) {
|
|
99
|
+
const eventsByTimestamp = getEventsByTimestamp(eventsMap);
|
|
100
|
+
const eventsList = getSortedEvents(eventsMap);
|
|
101
|
+
const todayDate = new Date();
|
|
102
|
+
const todayTimestamp = getEventTimestamp(todayDate);
|
|
103
|
+
const startedAtTopMap = {};
|
|
104
|
+
const viewWeeks = [];
|
|
105
|
+
for (let weekIdx = 0; weekIdx < weeks.length; weekIdx++) {
|
|
106
|
+
const viewWeek = {
|
|
107
|
+
props: { key: `week.${weekIdx}` },
|
|
108
|
+
days: [],
|
|
109
|
+
};
|
|
110
|
+
const weekStartDate = weeks[weekIdx];
|
|
111
|
+
const weekStartDay = weekStartDate.getDate();
|
|
112
|
+
const weekStartTimestamp = getEventTimestamp(new Date(weekStartDate));
|
|
113
|
+
const weekEndTimestamp = getEventTimestamp(addDays(new Date(weekStartDate), 6));
|
|
114
|
+
for (let dayNumber = 0; dayNumber < 7; dayNumber++) {
|
|
115
|
+
const dayDate = new Date(new Date(weekStartDate).setDate(weekStartDay + dayNumber));
|
|
116
|
+
const dayTimestamp = getEventTimestamp(dayDate);
|
|
117
|
+
const $isToday = todayTimestamp === dayTimestamp;
|
|
118
|
+
const $isOutOfRange = calendarView === "month" && dayDate.getMonth() !== month;
|
|
119
|
+
const contextualProps = {
|
|
120
|
+
$isToday,
|
|
121
|
+
$isOutOfRange,
|
|
122
|
+
};
|
|
123
|
+
const viewDay = {
|
|
124
|
+
props: Object.assign({ key: `day.${dayTimestamp}` }, contextualProps),
|
|
125
|
+
timestamp: dayTimestamp + "",
|
|
126
|
+
label: dayDate.getDate() + "",
|
|
127
|
+
events: [],
|
|
128
|
+
};
|
|
129
|
+
// check that we have events in this day
|
|
130
|
+
if (eventsByTimestamp === null || eventsByTimestamp === void 0 ? void 0 : eventsByTimestamp[dayTimestamp]) {
|
|
131
|
+
const verticalSlots = Object.keys(eventsByTimestamp[dayTimestamp]).map(() => FREE_SLOT);
|
|
132
|
+
for (let eventIdx = 0; eventIdx < eventsList.length; eventIdx++) {
|
|
133
|
+
const event = eventsList[eventIdx];
|
|
134
|
+
let width = 1;
|
|
135
|
+
let top = 0;
|
|
136
|
+
let firstOfMulti;
|
|
137
|
+
if (!event.daysMap[dayTimestamp]) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
// only for multi days events:
|
|
141
|
+
if (event.multi) {
|
|
142
|
+
// filter out the days outside of the current week view to avoid
|
|
143
|
+
// making a multi-days event chip wider than the week row or shorter
|
|
144
|
+
// than it should be (when event spans across weeks)
|
|
145
|
+
width = event.days.filter((t) => t >= weekStartTimestamp && t <= weekEndTimestamp).length;
|
|
146
|
+
// flag the first day of multi-days events, consider that an event
|
|
147
|
+
// might start in a day earlier (hence outside) of the current
|
|
148
|
+
// week/month view, so we always check for Mondays (dayNumber === 0)
|
|
149
|
+
if (event.days.indexOf(dayTimestamp) === 0 || dayNumber === 0) {
|
|
150
|
+
firstOfMulti = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// if we already have the information on when the event has been
|
|
154
|
+
// vertically positioned use that index
|
|
155
|
+
if (startedAtTopMap[event.uid]) {
|
|
156
|
+
top = startedAtTopMap[event.uid];
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// now look for a free slot and use its index as `top`
|
|
160
|
+
for (let verticalIdx = 0; verticalIdx < verticalSlots.length; verticalIdx++) {
|
|
161
|
+
const freeOrBusy = verticalSlots[verticalIdx];
|
|
162
|
+
if (freeOrBusy !== BUSY_SLOT) {
|
|
163
|
+
top = verticalIdx;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// now mark the slot as busy
|
|
169
|
+
verticalSlots[top] = BUSY_SLOT;
|
|
170
|
+
// store the slot vertical position consistently for multi-days events
|
|
171
|
+
if (firstOfMulti) {
|
|
172
|
+
startedAtTopMap[event.uid] = top;
|
|
173
|
+
}
|
|
174
|
+
// push the event, they will be sorted later
|
|
175
|
+
viewDay.events.push(Object.assign(Object.assign(Object.assign({ key: `event.${dayTimestamp}-${top}` }, contextualProps), event), { isPast: todayDate > event.end, firstOfMulti,
|
|
176
|
+
top,
|
|
177
|
+
width }));
|
|
178
|
+
}
|
|
179
|
+
// fill the empty slots with events' placeholders
|
|
180
|
+
for (let i = 0; i < verticalSlots.length; i++) {
|
|
181
|
+
if (verticalSlots[i] !== BUSY_SLOT) {
|
|
182
|
+
viewDay.events.push({
|
|
183
|
+
key: `event.${dayTimestamp}-${i}}`,
|
|
184
|
+
placeholder: true,
|
|
185
|
+
top: i,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// sort events and events placeholders by top position
|
|
190
|
+
viewDay.events.sort((a, b) => a.top - b.top);
|
|
191
|
+
}
|
|
192
|
+
viewWeek.days.push(viewDay);
|
|
193
|
+
}
|
|
194
|
+
viewWeeks.push(viewWeek);
|
|
195
|
+
}
|
|
196
|
+
return viewWeeks;
|
|
197
|
+
}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
export const KoineCarousel = null;
|
|
2
|
+
// import React, { useEffect, useState, useRef } from 'react';
|
|
3
|
+
// import Slide from './slide';
|
|
4
|
+
// import { getSliderListStyles } from './slider-list';
|
|
5
|
+
// import { CarouselProps, KeyCodeFunction } from './types';
|
|
6
|
+
// import renderControls from './controls';
|
|
7
|
+
// import defaultProps from './default-carousel-props';
|
|
8
|
+
// import { getIndexes, addEvent, removeEvent } from './utils';
|
|
9
|
+
// import AnnounceSlide from './announce-slide';
|
|
10
|
+
// export const Carousel = (props: CarouselProps): React.ReactElement => {
|
|
11
|
+
// const count = React.Children.count(props.children);
|
|
12
|
+
// const [currentSlide, setCurrentSlide] = useState<number>(
|
|
13
|
+
// props.autoplayReverse ? count - props.slidesToShow : props.slideIndex
|
|
14
|
+
// );
|
|
15
|
+
// const [animation, setAnimation] = useState<boolean>(false);
|
|
16
|
+
// const [pause, setPause] = useState<boolean>(false);
|
|
17
|
+
// const [dragging, setDragging] = useState<boolean>(false);
|
|
18
|
+
// const [move, setMove] = useState<number>(0);
|
|
19
|
+
// const [keyboardMove, setKeyboardMove] = useState<KeyCodeFunction>(null);
|
|
20
|
+
// const carouselWidth = useRef<number | null>(null);
|
|
21
|
+
// const focus = useRef<boolean>(false);
|
|
22
|
+
// const prevMove = useRef<number>(0);
|
|
23
|
+
// const carouselEl = useRef<HTMLDivElement>(null);
|
|
24
|
+
// const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
25
|
+
// const isMounted = useRef<boolean>(true);
|
|
26
|
+
// useEffect(
|
|
27
|
+
// () => () => {
|
|
28
|
+
// isMounted.current = false;
|
|
29
|
+
// },
|
|
30
|
+
// []
|
|
31
|
+
// );
|
|
32
|
+
// const slidesToScroll =
|
|
33
|
+
// props.animation === 'fade' ? props.slidesToShow : props.slidesToScroll;
|
|
34
|
+
// const dragThreshold = (carouselWidth.current || 0) / props.slidesToShow / 2;
|
|
35
|
+
// const carouselRef = props.innerRef || carouselEl;
|
|
36
|
+
// const moveSlide = (to?: number) => {
|
|
37
|
+
// const [slide, endSlide] = getIndexes(
|
|
38
|
+
// currentSlide,
|
|
39
|
+
// currentSlide - slidesToScroll,
|
|
40
|
+
// count
|
|
41
|
+
// );
|
|
42
|
+
// to && props.beforeSlide(slide, endSlide);
|
|
43
|
+
// !props.disableAnimation && setAnimation(true);
|
|
44
|
+
// setCurrentSlide(to ?? currentSlide);
|
|
45
|
+
// setTimeout(
|
|
46
|
+
// () => {
|
|
47
|
+
// if (!isMounted.current) return;
|
|
48
|
+
// to && props.afterSlide(currentSlide);
|
|
49
|
+
// !props.disableAnimation && setAnimation(false);
|
|
50
|
+
// },
|
|
51
|
+
// !props.disableAnimation ? props.speed || 500 : 40
|
|
52
|
+
// ); // if animation is disabled decrease the speed to 40
|
|
53
|
+
// };
|
|
54
|
+
// const nextSlide = () => {
|
|
55
|
+
// if (props.wrapAround || currentSlide <= count) {
|
|
56
|
+
// moveSlide(currentSlide + slidesToScroll);
|
|
57
|
+
// } else {
|
|
58
|
+
// moveSlide();
|
|
59
|
+
// }
|
|
60
|
+
// };
|
|
61
|
+
// const prevSlide = () => {
|
|
62
|
+
// // boundary
|
|
63
|
+
// if (props.wrapAround || currentSlide > 0) {
|
|
64
|
+
// moveSlide(currentSlide - slidesToScroll);
|
|
65
|
+
// } else {
|
|
66
|
+
// moveSlide();
|
|
67
|
+
// }
|
|
68
|
+
// };
|
|
69
|
+
// useEffect(() => {
|
|
70
|
+
// if (props.autoplay && !animation && props.wrapAround) {
|
|
71
|
+
// if (currentSlide > count) {
|
|
72
|
+
// setCurrentSlide(currentSlide - count);
|
|
73
|
+
// if (timer?.current) {
|
|
74
|
+
// clearTimeout(timer.current);
|
|
75
|
+
// }
|
|
76
|
+
// } else if (currentSlide < 0) {
|
|
77
|
+
// setCurrentSlide(count - -currentSlide);
|
|
78
|
+
// if (timer?.current) {
|
|
79
|
+
// clearTimeout(timer.current);
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
// }
|
|
83
|
+
// }, [animation, currentSlide]);
|
|
84
|
+
// useEffect(() => {
|
|
85
|
+
// if (props.autoplay && !pause) {
|
|
86
|
+
// timer.current = setTimeout(() => {
|
|
87
|
+
// if (props.autoplayReverse) {
|
|
88
|
+
// if (!props.wrapAround && currentSlide > 0) {
|
|
89
|
+
// prevSlide();
|
|
90
|
+
// } else if (props.wrapAround) {
|
|
91
|
+
// prevSlide();
|
|
92
|
+
// }
|
|
93
|
+
// } else if (
|
|
94
|
+
// !props.wrapAround &&
|
|
95
|
+
// currentSlide < count - props.slidesToShow
|
|
96
|
+
// ) {
|
|
97
|
+
// nextSlide();
|
|
98
|
+
// } else if (props.wrapAround) {
|
|
99
|
+
// nextSlide();
|
|
100
|
+
// }
|
|
101
|
+
// }, props.autoplayInterval);
|
|
102
|
+
// }
|
|
103
|
+
// // Clear the timeout if user hover on carousel
|
|
104
|
+
// if (props.autoplay && pause && timer?.current) {
|
|
105
|
+
// clearTimeout(timer.current);
|
|
106
|
+
// }
|
|
107
|
+
// return () => {
|
|
108
|
+
// if (timer.current) {
|
|
109
|
+
// clearTimeout(timer.current);
|
|
110
|
+
// }
|
|
111
|
+
// };
|
|
112
|
+
// }, [currentSlide, pause]);
|
|
113
|
+
// useEffect(() => {
|
|
114
|
+
// // makes the loop infinity
|
|
115
|
+
// if (props.wrapAround && !props.autoplay) {
|
|
116
|
+
// // if animation is disabled decrease the speed to 0
|
|
117
|
+
// const speed = !props.disableAnimation ? props.speed || 500 : 0;
|
|
118
|
+
// if (currentSlide <= -props.slidesToShow) {
|
|
119
|
+
// // prev
|
|
120
|
+
// setTimeout(() => {
|
|
121
|
+
// if (!isMounted.current) return;
|
|
122
|
+
// setCurrentSlide(count - -currentSlide);
|
|
123
|
+
// }, speed + 10);
|
|
124
|
+
// } else if (currentSlide >= count) {
|
|
125
|
+
// // next
|
|
126
|
+
// setTimeout(() => {
|
|
127
|
+
// if (!isMounted.current) return;
|
|
128
|
+
// setCurrentSlide(currentSlide - count);
|
|
129
|
+
// }, speed + 10);
|
|
130
|
+
// }
|
|
131
|
+
// }
|
|
132
|
+
// }, [currentSlide]);
|
|
133
|
+
// useEffect(() => {
|
|
134
|
+
// if (props.enableKeyboardControls && keyboardMove && focus.current) {
|
|
135
|
+
// switch (keyboardMove) {
|
|
136
|
+
// case 'nextSlide':
|
|
137
|
+
// nextSlide(); // set boundaries for !wrapAround
|
|
138
|
+
// break;
|
|
139
|
+
// case 'previousSlide':
|
|
140
|
+
// prevSlide(); // set boundaries for !wrapAround
|
|
141
|
+
// break;
|
|
142
|
+
// case 'firstSlide':
|
|
143
|
+
// setCurrentSlide(0);
|
|
144
|
+
// break;
|
|
145
|
+
// case 'lastSlide':
|
|
146
|
+
// setCurrentSlide(count - props.slidesToShow);
|
|
147
|
+
// break;
|
|
148
|
+
// case 'pause':
|
|
149
|
+
// if (pause && props.autoplay) {
|
|
150
|
+
// setPause(false);
|
|
151
|
+
// break;
|
|
152
|
+
// } else if (props.autoplay) {
|
|
153
|
+
// setPause(true);
|
|
154
|
+
// break;
|
|
155
|
+
// }
|
|
156
|
+
// break;
|
|
157
|
+
// }
|
|
158
|
+
// setKeyboardMove(null);
|
|
159
|
+
// }
|
|
160
|
+
// }, [keyboardMove]);
|
|
161
|
+
// const onKeyPress = (e: Event) => {
|
|
162
|
+
// if (
|
|
163
|
+
// props.enableKeyboardControls &&
|
|
164
|
+
// focus.current &&
|
|
165
|
+
// (e as KeyboardEvent).keyCode
|
|
166
|
+
// ) {
|
|
167
|
+
// const keyConfig = props.keyCodeConfig;
|
|
168
|
+
// for (const func in keyConfig) {
|
|
169
|
+
// if (
|
|
170
|
+
// keyConfig[func as keyof typeof keyConfig]?.includes(
|
|
171
|
+
// (e as KeyboardEvent).keyCode
|
|
172
|
+
// )
|
|
173
|
+
// ) {
|
|
174
|
+
// setKeyboardMove(func as KeyCodeFunction);
|
|
175
|
+
// }
|
|
176
|
+
// }
|
|
177
|
+
// }
|
|
178
|
+
// };
|
|
179
|
+
// useEffect(() => {
|
|
180
|
+
// if (carouselEl && carouselEl.current) {
|
|
181
|
+
// carouselWidth.current = carouselEl.current.offsetWidth;
|
|
182
|
+
// } else if (props.innerRef) {
|
|
183
|
+
// carouselWidth.current = props.innerRef.current.offsetWidth;
|
|
184
|
+
// }
|
|
185
|
+
// if (props.enableKeyboardControls) {
|
|
186
|
+
// addEvent(document, 'keydown', onKeyPress);
|
|
187
|
+
// }
|
|
188
|
+
// return () => {
|
|
189
|
+
// removeEvent(document, 'keydown', onKeyPress);
|
|
190
|
+
// };
|
|
191
|
+
// }, []);
|
|
192
|
+
// const handleDragEnd = () => {
|
|
193
|
+
// if (!props.dragging || !dragging) return;
|
|
194
|
+
// setDragging(false);
|
|
195
|
+
// if (Math.abs(move) <= dragThreshold) {
|
|
196
|
+
// moveSlide();
|
|
197
|
+
// setMove(0);
|
|
198
|
+
// prevMove.current = 0;
|
|
199
|
+
// return;
|
|
200
|
+
// }
|
|
201
|
+
// if (move > 0) {
|
|
202
|
+
// nextSlide();
|
|
203
|
+
// } else {
|
|
204
|
+
// prevSlide();
|
|
205
|
+
// }
|
|
206
|
+
// setMove(0);
|
|
207
|
+
// prevMove.current = 0;
|
|
208
|
+
// };
|
|
209
|
+
// const onTouchStart = () => {
|
|
210
|
+
// if (!props.swiping) {
|
|
211
|
+
// return;
|
|
212
|
+
// }
|
|
213
|
+
// setDragging(true);
|
|
214
|
+
// };
|
|
215
|
+
// const handlePointerMove = (m: number) => {
|
|
216
|
+
// if (!props.dragging || !dragging) return;
|
|
217
|
+
// const moveValue = m * 0.75; // Friction
|
|
218
|
+
// const moveState = move + (moveValue - prevMove.current);
|
|
219
|
+
// // Exit drag early if passed threshold
|
|
220
|
+
// if (Math.abs(move) > dragThreshold) {
|
|
221
|
+
// handleDragEnd();
|
|
222
|
+
// return;
|
|
223
|
+
// }
|
|
224
|
+
// if (
|
|
225
|
+
// !props.wrapAround &&
|
|
226
|
+
// props.disableEdgeSwiping &&
|
|
227
|
+
// ((currentSlide <= 0 && moveState <= 0) ||
|
|
228
|
+
// (moveState > 0 && currentSlide >= count - props.slidesToShow))
|
|
229
|
+
// ) {
|
|
230
|
+
// prevMove.current = moveValue;
|
|
231
|
+
// return;
|
|
232
|
+
// }
|
|
233
|
+
// if (prevMove.current !== 0) {
|
|
234
|
+
// setMove(moveState);
|
|
235
|
+
// }
|
|
236
|
+
// prevMove.current = moveValue;
|
|
237
|
+
// };
|
|
238
|
+
// const onTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {
|
|
239
|
+
// if (!props.dragging || !dragging) return;
|
|
240
|
+
// props.onDragStart(e);
|
|
241
|
+
// const moveValue = (carouselWidth?.current || 0) - e.touches[0].pageX;
|
|
242
|
+
// handlePointerMove(moveValue);
|
|
243
|
+
// };
|
|
244
|
+
// const onMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
245
|
+
// e?.preventDefault();
|
|
246
|
+
// carouselRef?.current?.focus();
|
|
247
|
+
// if (!props.dragging) return;
|
|
248
|
+
// setDragging(true);
|
|
249
|
+
// };
|
|
250
|
+
// const onMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
251
|
+
// if (!props.dragging || !dragging) return;
|
|
252
|
+
// props.onDragStart(e);
|
|
253
|
+
// const offsetX =
|
|
254
|
+
// e.clientX - (carouselRef.current?.getBoundingClientRect().left || 0);
|
|
255
|
+
// const moveValue = (carouselWidth?.current || 0) - offsetX;
|
|
256
|
+
// handlePointerMove(moveValue);
|
|
257
|
+
// };
|
|
258
|
+
// const onMouseUp = (e?: React.MouseEvent<HTMLDivElement>) => {
|
|
259
|
+
// e?.preventDefault();
|
|
260
|
+
// handleDragEnd();
|
|
261
|
+
// };
|
|
262
|
+
// const onMouseEnter = () => {
|
|
263
|
+
// if (props.pauseOnHover) {
|
|
264
|
+
// setPause(true);
|
|
265
|
+
// }
|
|
266
|
+
// };
|
|
267
|
+
// const onMouseLeave = () => {
|
|
268
|
+
// if (props.pauseOnHover) {
|
|
269
|
+
// setPause(false);
|
|
270
|
+
// }
|
|
271
|
+
// };
|
|
272
|
+
// const renderSlides = (typeOfSlide?: 'prev-cloned' | 'next-cloned') => {
|
|
273
|
+
// const slides = React.Children.map(props.children, (child, index) => {
|
|
274
|
+
// const isCurrentSlide = props.wrapAround
|
|
275
|
+
// ? currentSlide === index ||
|
|
276
|
+
// currentSlide === index + count ||
|
|
277
|
+
// currentSlide === index - count
|
|
278
|
+
// : currentSlide === index;
|
|
279
|
+
// return (
|
|
280
|
+
// <Slide
|
|
281
|
+
// key={`${typeOfSlide}-${index}`}
|
|
282
|
+
// count={count}
|
|
283
|
+
// currentSlide={currentSlide}
|
|
284
|
+
// index={index}
|
|
285
|
+
// isCurrentSlide={isCurrentSlide}
|
|
286
|
+
// typeOfSlide={typeOfSlide}
|
|
287
|
+
// wrapAround={props.wrapAround}
|
|
288
|
+
// cellSpacing={props.cellSpacing}
|
|
289
|
+
// animation={props.animation}
|
|
290
|
+
// slidesToShow={props.slidesToShow}
|
|
291
|
+
// speed={props.speed}
|
|
292
|
+
// zoomScale={props.zoomScale}
|
|
293
|
+
// cellAlign={props.cellAlign}
|
|
294
|
+
// >
|
|
295
|
+
// {child}
|
|
296
|
+
// </Slide>
|
|
297
|
+
// );
|
|
298
|
+
// });
|
|
299
|
+
// return slides;
|
|
300
|
+
// };
|
|
301
|
+
// const [slide] = getIndexes(
|
|
302
|
+
// currentSlide,
|
|
303
|
+
// currentSlide - slidesToScroll,
|
|
304
|
+
// count
|
|
305
|
+
// );
|
|
306
|
+
// return (
|
|
307
|
+
// <div
|
|
308
|
+
// className={'slider-container'}
|
|
309
|
+
// style={{
|
|
310
|
+
// position: 'relative',
|
|
311
|
+
// padding: props.withoutControls ? 0 : '0 60px 50px'
|
|
312
|
+
// }}
|
|
313
|
+
// onMouseEnter={onMouseEnter}
|
|
314
|
+
// onMouseLeave={onMouseLeave}
|
|
315
|
+
// >
|
|
316
|
+
// <AnnounceSlide
|
|
317
|
+
// ariaLive={props.autoplay && !pause ? 'off' : 'polite'}
|
|
318
|
+
// message={props.renderAnnounceSlideMessage({
|
|
319
|
+
// currentSlide: slide,
|
|
320
|
+
// count
|
|
321
|
+
// })}
|
|
322
|
+
// />
|
|
323
|
+
// <div
|
|
324
|
+
// className={['slider-frame', props.className || ''].join(' ').trim()}
|
|
325
|
+
// style={{
|
|
326
|
+
// overflow: 'hidden',
|
|
327
|
+
// width: '100%',
|
|
328
|
+
// position: 'relative',
|
|
329
|
+
// outline: 'none',
|
|
330
|
+
// ...props.style
|
|
331
|
+
// }}
|
|
332
|
+
// aria-label="carousel-slider"
|
|
333
|
+
// role="region"
|
|
334
|
+
// tabIndex={0}
|
|
335
|
+
// onFocus={() => (focus.current = true)}
|
|
336
|
+
// onBlur={() => (focus.current = false)}
|
|
337
|
+
// ref={props.innerRef || carouselEl}
|
|
338
|
+
// onMouseUp={onMouseUp}
|
|
339
|
+
// onMouseDown={onMouseDown}
|
|
340
|
+
// onMouseMove={onMouseMove}
|
|
341
|
+
// onMouseLeave={onMouseUp}
|
|
342
|
+
// onTouchStart={onTouchStart}
|
|
343
|
+
// onTouchEnd={handleDragEnd}
|
|
344
|
+
// onTouchMove={onTouchMove}
|
|
345
|
+
// >
|
|
346
|
+
// <div
|
|
347
|
+
// className="slider-list"
|
|
348
|
+
// style={getSliderListStyles(
|
|
349
|
+
// props.children,
|
|
350
|
+
// currentSlide,
|
|
351
|
+
// animation,
|
|
352
|
+
// props.slidesToShow,
|
|
353
|
+
// props.cellAlign,
|
|
354
|
+
// props.wrapAround,
|
|
355
|
+
// props.speed,
|
|
356
|
+
// move,
|
|
357
|
+
// props.animation
|
|
358
|
+
// )}
|
|
359
|
+
// >
|
|
360
|
+
// {props.wrapAround ? renderSlides('prev-cloned') : null}
|
|
361
|
+
// {renderSlides()}
|
|
362
|
+
// {props.wrapAround ? renderSlides('next-cloned') : null}
|
|
363
|
+
// </div>
|
|
364
|
+
// </div>
|
|
365
|
+
// {renderControls(
|
|
366
|
+
// props,
|
|
367
|
+
// count,
|
|
368
|
+
// currentSlide,
|
|
369
|
+
// moveSlide,
|
|
370
|
+
// nextSlide,
|
|
371
|
+
// prevSlide,
|
|
372
|
+
// slidesToScroll
|
|
373
|
+
// )}
|
|
374
|
+
// </div>
|
|
375
|
+
// );
|
|
376
|
+
// };
|
|
377
|
+
// Carousel.defaultProps = defaultProps;
|
|
378
|
+
// export default Carousel;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Children } from "react";
|
|
4
|
+
import styled from "styled-components";
|
|
5
|
+
import { uid } from "@koine/utils";
|
|
6
|
+
import { Row, Col, GRID_GUTTER_DEFAULT as DF, } from "../Grid";
|
|
7
|
+
export const CarouselCssRow = styled(Row) `
|
|
8
|
+
${({ $gutter: cs, theme: { gutter } }) => `
|
|
9
|
+
margin-left: -${cs === DF ? gutter[DF] : (gutter[DF] - gutter[cs]) * 2}px;
|
|
10
|
+
margin-right: -${cs === DF ? gutter[DF] : (gutter[DF] - gutter[cs]) * 2}px;
|
|
11
|
+
padding-left: ${cs === DF ? gutter[DF] : gutter[DF] - gutter[cs]}px;
|
|
12
|
+
padding-right: ${cs === DF ? gutter[DF] : gutter[DF] - gutter[cs]}px;
|
|
13
|
+
`}
|
|
14
|
+
|
|
15
|
+
scroll-behavior: smooth;
|
|
16
|
+
scroll-snap-type: x;
|
|
17
|
+
-ms-overflow-style: none;
|
|
18
|
+
scrollbar-width: none;
|
|
19
|
+
|
|
20
|
+
&::-webkit-scrollbar {
|
|
21
|
+
display: none;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
export const CarouselCssCol = styled(Col) `
|
|
25
|
+
${(p) => p.$width && `flex-basis: ${p.$width}px; min-width: ${p.$width}px;`}
|
|
26
|
+
position: relative;
|
|
27
|
+
scroll-snap-align: ${(p) => p.$snap};
|
|
28
|
+
`;
|
|
29
|
+
/**
|
|
30
|
+
* For programmatic usage an example here @see https://stackoverflow.com/a/65902068/9122820
|
|
31
|
+
*/
|
|
32
|
+
export const KoineCarouselCss = (_a) => {
|
|
33
|
+
var { items, $gutterRow, $gutterCol, $gutter = "quarter", $proportion, $snap = "center", width, children } = _a, colProps = __rest(_a, ["items", "$gutterRow", "$gutterCol", "$gutter", "$proportion", "$snap", "width", "children"]);
|
|
34
|
+
const slides = children ? Children.toArray(children) : items;
|
|
35
|
+
const id = uid();
|
|
36
|
+
if (!slides)
|
|
37
|
+
return null;
|
|
38
|
+
return (_jsx(CarouselCssRow, Object.assign({ "$noWrap": true, "$gutter": $gutterRow || $gutter }, { children: slides.map((_slide, idx) => (_jsx(CarouselCssCol, Object.assign({}, colProps, { "$gutter": $gutterCol || $gutter, "$width": width }, { children: slides[idx] }), `CarouselCssCol-${id}-${idx}`))) })));
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./CarouselCss";
|