guestbell-forms 3.0.40 → 3.0.42

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.
Files changed (31) hide show
  1. package/build/components/bookingCalendar/BookingCalendar.d.ts +4 -2
  2. package/build/components/bookingCalendar/BookingCalendar.js +38 -13
  3. package/build/components/bookingCalendar/BookingCalendar.js.map +1 -1
  4. package/build/components/bookingCalendar/bookingCalendarItem/BookingCalendarItem.js +2 -1
  5. package/build/components/bookingCalendar/bookingCalendarItem/BookingCalendarItem.js.map +1 -1
  6. package/build/components/bookingCalendar/bookingCalendarSelection/BookingCalendarSelection.d.ts +1 -1
  7. package/build/components/bookingCalendar/bookingCalendarSelection/BookingCalendarSelection.js +11 -9
  8. package/build/components/bookingCalendar/bookingCalendarSelection/BookingCalendarSelection.js.map +1 -1
  9. package/build/components/bookingCalendar/bookingCalendarSelection/classes.d.ts +5 -0
  10. package/build/components/bookingCalendar/bookingCalendarSelection/classes.js +12 -0
  11. package/build/components/bookingCalendar/bookingCalendarSelection/classes.js.map +1 -0
  12. package/build/components/bookingCalendar/common.d.ts +1 -0
  13. package/build/components/bookingCalendar/common.js.map +1 -1
  14. package/build/components/bookingCalendar/utils.d.ts +4 -1
  15. package/build/components/bookingCalendar/utils.js +2 -1
  16. package/build/components/bookingCalendar/utils.js.map +1 -1
  17. package/build/dist/guestbell-forms.css +3 -1
  18. package/build/dist/guestbell-forms.css.map +1 -1
  19. package/build/dist/guestbell-forms.min.css +1 -1
  20. package/build/dist/report.html +2 -2
  21. package/build/scss/components/bookingCalendar/bookingCalendar.scss +2 -0
  22. package/package.json +1 -1
  23. package/src/lib/components/bookingCalendar/BookingCalendar.tsx +72 -14
  24. package/src/lib/components/bookingCalendar/bookingCalendarItem/BookingCalendarItem.tsx +5 -4
  25. package/src/lib/components/bookingCalendar/bookingCalendarSelection/BookingCalendarSelection.tsx +30 -16
  26. package/src/lib/components/bookingCalendar/bookingCalendarSelection/classes.ts +10 -0
  27. package/src/lib/components/bookingCalendar/common.ts +1 -0
  28. package/src/lib/components/bookingCalendar/utils.ts +3 -1
  29. package/src/lib/scss/components/bookingCalendar/bookingCalendar.scss +2 -0
  30. package/src/stories/Schedule.tsx +15 -3
  31. package/tsconfig.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { bookingCalendarSelectionDefaultClasses } from './classes';
2
3
 
3
4
  export type BookingCalendarSelectionCoordinates = [number, number];
4
5
  export interface BookingCalendarSelectionData {
@@ -11,10 +12,13 @@ export interface BookingCalendarSelectionProps {
11
12
  origin: BookingCalendarSelectionCoordinates;
12
13
  target: BookingCalendarSelectionCoordinates;
13
14
  }) => void;
14
- onSelected?: (data: {
15
- origin: BookingCalendarSelectionCoordinates;
16
- target: BookingCalendarSelectionCoordinates;
17
- }) => void;
15
+ onSelected?: (
16
+ data: {
17
+ origin: BookingCalendarSelectionCoordinates;
18
+ target: BookingCalendarSelectionCoordinates;
19
+ },
20
+ e: React.MouseEvent<HTMLElement>
21
+ ) => void;
18
22
  dataRowsCount: number;
19
23
  minSelectionSize: number;
20
24
  children?: React.ReactNode;
@@ -116,10 +120,13 @@ export default class BookingCalendarSelection extends React.Component<
116
120
  if (distance < this.props.minSelectionSize) {
117
121
  return;
118
122
  }
119
- this.props.onSelected?.({
120
- origin: this.state.selectionBoxOrigin,
121
- target: this.state.selectionBoxTarget,
122
- });
123
+ this.props.onSelected?.(
124
+ {
125
+ origin: this.state.selectionBoxOrigin,
126
+ target: this.state.selectionBoxTarget,
127
+ },
128
+ evt
129
+ );
123
130
  }
124
131
  }
125
132
 
@@ -168,8 +175,14 @@ export default class BookingCalendarSelection extends React.Component<
168
175
  render() {
169
176
  const baseStyle: React.CSSProperties = {
170
177
  zIndex: 10,
171
- left: this.state.selectionBoxOrigin[0],
172
- top: this.state.selectionBoxOrigin[1],
178
+ left: Math.min(
179
+ this.state.selectionBoxOrigin[0],
180
+ this.state.selectionBoxTarget[0]
181
+ ),
182
+ top: Math.min(
183
+ this.state.selectionBoxOrigin[1],
184
+ this.state.selectionBoxTarget[1]
185
+ ),
173
186
  height: Math.abs(
174
187
  this.state.selectionBoxTarget[1] - this.state.selectionBoxOrigin[1] - 1
175
188
  ),
@@ -177,8 +190,8 @@ export default class BookingCalendarSelection extends React.Component<
177
190
  this.state.selectionBoxTarget[0] - this.state.selectionBoxOrigin[0] - 1
178
191
  ),
179
192
  userSelect: 'none',
180
- transformOrigin: 'top left',
181
- transform: this.handleTransformBox(),
193
+ // transformOrigin: 'top left',
194
+ // transform: this.handleTransformBox(),
182
195
  };
183
196
  const boxVisible =
184
197
  Math.sqrt(
@@ -194,7 +207,7 @@ export default class BookingCalendarSelection extends React.Component<
194
207
  return (
195
208
  <div
196
209
  ref={this.containerRef}
197
- className="bookingCalendar__selection__container"
210
+ className={bookingCalendarSelectionDefaultClasses.root}
198
211
  style={{
199
212
  zIndex: this.state.selectionBox ? 99999 : undefined,
200
213
  gridRowEnd: `span ${this.props.dataRowsCount}`,
@@ -206,11 +219,12 @@ export default class BookingCalendarSelection extends React.Component<
206
219
  >
207
220
  {boxVisible && this.state.selectionBox && (
208
221
  <div
209
- className={`bookingCalendar__selection ${this.state.animation}`}
222
+ className={`${bookingCalendarSelectionDefaultClasses.selection} ${this.state.animation}`}
210
223
  style={baseStyle}
211
- />
224
+ >
225
+ {this.props.children}
226
+ </div>
212
227
  )}
213
- {this.props.children}
214
228
  </div>
215
229
  );
216
230
  }
@@ -0,0 +1,10 @@
1
+ export interface BookingCalendarSelectionClasses {
2
+ root?: string;
3
+ selection?: string;
4
+ }
5
+
6
+ export const bookingCalendarSelectionDefaultClasses: BookingCalendarSelectionClasses =
7
+ {
8
+ root: 'bookingCalendar__selection__container',
9
+ selection: 'bookingCalendar__selection',
10
+ };
@@ -3,6 +3,7 @@ import moment, { Moment, Duration } from 'moment';
3
3
  export interface BookingCalendarItemT {
4
4
  from: Moment;
5
5
  till: Moment;
6
+ id: string | number;
6
7
  /*
7
8
  Optional index that identifies the lane
8
9
  */
@@ -180,7 +180,8 @@ export function splitBookingsToLanes<T extends BookingCalendarItemT, TLaneData>(
180
180
  return lanes;
181
181
  }
182
182
 
183
- export function itemsOverlap<T extends BookingCalendarItemT>(a: T, b: T) {
183
+ type Picked = Pick<BookingCalendarItemT, 'from' | 'till'>;
184
+ export function itemsOverlap(a: Picked, b: Picked) {
184
185
  if (!a?.from || !a?.till || !b?.from || !b?.till) {
185
186
  return false;
186
187
  }
@@ -267,6 +268,7 @@ export const generateControlItems = (
267
268
  .clone()
268
269
  .add(subtract)
269
270
  .add(step.asMilliseconds() * (index + 1)),
271
+ id: index
270
272
  }));
271
273
  };
272
274
 
@@ -263,6 +263,8 @@ $border-color-dark: black;
263
263
  animation-duration: 0.2s;
264
264
  animation-name: fadeIn;
265
265
  user-select: none;
266
+ padding: 0.5rem;
267
+ overflow: hidden;
266
268
  }
267
269
 
268
270
  .bookingCalendar__selection--fadeout {
@@ -12,20 +12,21 @@ const generateBookingItemsBetweenDates = (
12
12
  from: Moment,
13
13
  till: Moment,
14
14
  count = 50
15
- ) => {
15
+ ): BookingCalendarItemT[] => {
16
16
  const width = till.valueOf() - from.valueOf();
17
17
  const startMs = from.valueOf();
18
- return new Array(count).fill(0).map(() => {
18
+ return new Array(count).fill(0).map((_, index) => {
19
19
  const _from = randomIntFromInterval(0, till.valueOf() - startMs) + startMs;
20
20
  const _width = randomIntFromInterval(width / 100, width / 50);
21
21
  return {
22
+ id: index,
22
23
  from: moment(_from),
23
24
  till: moment(_from).add(_width, 'ms'),
24
25
  laneKey:
25
26
  randomIntFromInterval(1, 3) === 1
26
27
  ? undefined
27
28
  : randomIntFromInterval(1, 3),
28
- } as BookingCalendarItemT;
29
+ };
29
30
  });
30
31
  };
31
32
 
@@ -47,6 +48,15 @@ export const Schedule = () => {
47
48
  () => bookings.filter((b) => itemsOverlap(b, { from, till })),
48
49
  [from, till, bookings]
49
50
  );
51
+ const onSelection = React.useCallback(
52
+ (items: BookingCalendarItemT[], _from, _till, e) => {
53
+ console.log(items);
54
+ if (e.ctrlKey) {
55
+ setRange({ from: _from, till: _till });
56
+ }
57
+ },
58
+ []
59
+ );
50
60
  return (
51
61
  <div className="container">
52
62
  <BookingCalendar
@@ -55,6 +65,8 @@ export const Schedule = () => {
55
65
  till={till}
56
66
  step={duration(1, 'day')}
57
67
  onRangeChange={setRange}
68
+ onSelection={onSelection}
69
+ selectionContent={'Hold CTRL to zoom'}
58
70
  // lanesCount={3}
59
71
  lanesSource={new Array(3).fill(0).map((_, index) => ({
60
72
  laneKey: index,
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "rootDir": "./src/lib",
3
+ "rootDir": ".",
4
4
  "outDir": "./dist",
5
5
  "declarationDir": "./dist/dts",
6
6
  "baseUrl": ".",