Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Change type from ClientRect to DOMRect #2481

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/core/rect/src/observeElementRect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Measurable = { getBoundingClientRect(): ClientRect };
type Measurable = { getBoundingClientRect(): DOMRect };

/**
* Observes an element's rectangle on screen (getBoundingClientRect)
Expand All @@ -16,7 +16,7 @@ function observeElementRect(
if (observedData === undefined) {
// add the element to the map of observed elements with its first callback
// because this is the first time this element is observed
observedElements.set(elementToObserve, { rect: {} as ClientRect, callbacks: [callback] });
observedElements.set(elementToObserve, { rect: {} as DOMRect, callbacks: [callback] });

if (observedElements.size === 1) {
// start the internal loop once at least 1 element is observed
Expand Down Expand Up @@ -54,10 +54,10 @@ function observeElementRect(
// ========================================================================
// module internals

type CallbackFn = (rect: ClientRect) => void;
type CallbackFn = (rect: DOMRect) => void;

type ObservedData = {
rect: ClientRect;
rect: DOMRect;
callbacks: Array<CallbackFn>;
};

Expand Down Expand Up @@ -91,7 +91,7 @@ function runLoop() {
/**
* Returns whether 2 rects are equal in values
*/
function rectEquals(rect1: ClientRect, rect2: ClientRect) {
function rectEquals(rect1: DOMRect, rect2: DOMRect) {
return (
rect1.width === rect2.width &&
rect1.height === rect2.height &&
Expand Down
2 changes: 1 addition & 1 deletion packages/react/scroll-area/src/ScrollArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ const ScrollAreaScrollbarImpl = React.forwardRef<
const context = useScrollAreaContext(SCROLLBAR_NAME, __scopeScrollArea);
const [scrollbar, setScrollbar] = React.useState<ScrollAreaScrollbarElement | null>(null);
const composeRefs = useComposedRefs(forwardedRef, (node) => setScrollbar(node));
const rectRef = React.useRef<ClientRect | null>(null);
const rectRef = React.useRef<DOMRect | null>(null);
const prevWebkitUserSelectRef = React.useRef<string>('');
const viewport = context.viewport;
const maxScrollPos = sizes.content - sizes.viewport;
Expand Down
4 changes: 2 additions & 2 deletions packages/react/slider/src/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const SliderHorizontal = React.forwardRef<SliderHorizontalElement, SliderHorizon
} = props;
const [slider, setSlider] = React.useState<SliderImplElement | null>(null);
const composedRefs = useComposedRefs(forwardedRef, (node) => setSlider(node));
const rectRef = React.useRef<ClientRect>();
const rectRef = React.useRef<DOMRect>();
const direction = useDirection(dir);
const isDirectionLTR = direction === 'ltr';
const isSlidingFromLeft = (isDirectionLTR && !inverted) || (!isDirectionLTR && inverted);
Expand Down Expand Up @@ -322,7 +322,7 @@ const SliderVertical = React.forwardRef<SliderVerticalElement, SliderVerticalPro
} = props;
const sliderRef = React.useRef<SliderImplElement>(null);
const ref = useComposedRefs(forwardedRef, sliderRef);
const rectRef = React.useRef<ClientRect>();
const rectRef = React.useRef<DOMRect>();
const isSlidingFromBottom = !inverted;

function getValueFromPointer(pointerPosition: number) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/use-rect/src/useRect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Measurable } from '@radix-ui/rect';
* and observe it along time.
*/
function useRect(measurable: Measurable | null) {
const [rect, setRect] = React.useState<ClientRect>();
const [rect, setRect] = React.useState<DOMRect>();
React.useEffect(() => {
if (measurable) {
const unobserve = observeElementRect(measurable, setRect);
Expand Down
Loading