Skip to content

Commit

Permalink
cleanup date range field picker
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Jul 18, 2024
1 parent 1a51417 commit dbbcf2a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ export class DateRangeFieldRootState {
const value = this.value.value;

untrack(() => {
if (value && value.start !== this.startValue.value) {
if (value.start !== undefined && value.start !== this.startValue.value) {
this.setStartValue(value.start);
}
if (value && value.end !== this.endValue.value) {
if (value.end !== undefined && value.end !== this.endValue.value) {
this.setEndValue(value.end);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
value: box.with(
() => value as DateRange,
(v) => {
if (value !== v) {
if (!$state.is(value, v)) {
value = v;
onValueChange(v);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ class LinkPreviewContentState {
this.root.isPointerInTransit = isPointerInTransit;

onPointerExit(() => {
console.log("pointer exit");
this.root.handleClose();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ export class RangeCalendarRootState {
if (isBefore(endValue, startValue)) {
const start = startValue;
const end = endValue;
this.startValue.value = end;
this.endValue.value = start;
this.setStartValue(end);
this.setEndValue(start);
return { start: endValue, end: startValue };
} else {
return {
Expand Down Expand Up @@ -268,6 +268,14 @@ export class RangeCalendarRootState {
}
};

setStartValue = (value: DateValue | undefined) => {
this.startValue.value = value;
};

setEndValue = (value: DateValue | undefined) => {
this.endValue.value = value;
};

#setMonths = (months: Month<DateValue>[]) => (this.months = months);

/**
Expand Down Expand Up @@ -449,14 +457,14 @@ export class RangeCalendarRootState {
!this.preventDeselect.value &&
!this.endValue.value
) {
this.startValue.value = undefined;
this.setStartValue(undefined);
this.placeholder.value = date;
this.#announceEmpty();
return;
} else if (!this.endValue) {
} else if (!this.endValue.value) {
e.preventDefault();
if (prevLastPressedDate && isSameDay(prevLastPressedDate, date)) {
this.startValue.value = date;
this.setStartValue(date);
this.#announceSelectedDate(date);
}
}
Expand All @@ -468,23 +476,23 @@ export class RangeCalendarRootState {
isSameDay(this.endValue.value, date) &&
!this.preventDeselect.value
) {
this.startValue.value = undefined;
this.endValue.value = undefined;
this.setStartValue(undefined);
this.setEndValue(undefined);
this.placeholder.value = date;
this.#announceEmpty();
return;
}

if (!this.startValue.value) {
this.#announceSelectedDate(date);
this.startValue.value = date;
this.setStartValue(date);
} else if (!this.endValue.value) {
this.#announceSelectedRange(this.startValue.value, date);
this.endValue.value = date;
this.setEndValue(date);
} else if (this.endValue.value && this.startValue.value) {
this.endValue.value = undefined;
this.setEndValue(undefined);
this.#announceSelectedDate(date);
this.startValue.value = date;
this.setStartValue(date);
}
};

Expand Down
5 changes: 0 additions & 5 deletions packages/bits-ui/src/lib/internal/useGraceArea.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function useGraceArea(
}

function handleCreateGraceArea(e: PointerEvent, hoverTarget: HTMLElement) {
console.log("creating grace area");
const currentTarget = e.currentTarget;
if (!isHTMLElement(currentTarget)) return;
const exitPoint = { x: e.clientX, y: e.clientY };
Expand All @@ -36,11 +35,7 @@ export function useGraceArea(
$effect(() => {
const trigger = triggerNode();
const content = contentNode();
console.log("trigger", trigger);
console.log("content", content);
if (!trigger || !content) return;
console.log("triggernode", trigger);
console.log("contentnode", content);

const handleTriggerLeave = (e: PointerEvent) => {
handleCreateGraceArea(e, content!);
Expand Down
2 changes: 0 additions & 2 deletions packages/bits-ui/src/tests/slider/Slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,5 @@ function expectPercentages({
expect(isCloseEnough(percentage, thumb.style.left)).toBeTruthy();
}
expect(isCloseEnough(lesserPercentage, range.style.left)).toBeTruthy();
console.log("higherPercentage", higherPercentage);
console.log("rangeStyleRight", range.style.right);
expect(isCloseEnough(100 - higherPercentage, range.style.right)).toBeTruthy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { CalendarBlank, CaretLeft, CaretRight } from "$icons/index.js";
import { cn } from "$lib/utils/index.js";
let value: DateRange = { start: undefined, end: undefined };
let value: DateRange = $state({ start: undefined, end: undefined });
</script>

<DateRangePicker.Root
Expand Down

0 comments on commit dbbcf2a

Please sign in to comment.