-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
256 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
domino-ui/src/main/java/org/dominokit/domino/ui/utils/IntersectionObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright © 2019 Dominokit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dominokit.domino.ui.utils; | ||
|
||
import elemental2.core.JsArray; | ||
import elemental2.dom.Element; | ||
import jsinterop.annotations.JsFunction; | ||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsType; | ||
|
||
/** | ||
* provides a way to asynchronously observe changes in the intersection of a target element with an | ||
* ancestor element or with a top-level document's viewport. | ||
* | ||
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver">MDN Web Docs | ||
* (IntersectionObserver)</a> | ||
*/ | ||
@JsType(isNative = true, namespace = JsPackage.GLOBAL) | ||
public class IntersectionObserver { | ||
|
||
/** | ||
* Disconnects the {@code IntersectionObserver} instance, stopping it from tracking changes in | ||
* element intersection. | ||
*/ | ||
public native void disconnect(); | ||
|
||
/** | ||
* Begins observing the specified {@link Element} for intersection changes. | ||
* | ||
* @param target The DOM element to observe for intersection changes. | ||
*/ | ||
public native void observe(Element target); | ||
|
||
/** | ||
* Stops observing the specified {@link Element} for intersection changes. | ||
* | ||
* @param target The DOM element to stop observing. | ||
*/ | ||
public native void unobserve(Element target); | ||
|
||
public native JsArray<IntersectionObserverEntry> takeRecords(); | ||
|
||
/** | ||
* A functional interface representing a callback function to be invoked when intersection changes | ||
* are observed. | ||
*/ | ||
@JsFunction | ||
public interface IntersectionObserverCallbackFn { | ||
/** | ||
* Invoked when element intersection with viewport is observed. | ||
* | ||
* @param entries An array of {@link IntersectionObserverEntry} objects describing the observed | ||
* intersection changes. | ||
*/ | ||
void onInvoke(JsArray<IntersectionObserverEntry> entries); | ||
} | ||
|
||
/** | ||
* Constructs a {@code IntersectionObserver} instance with the specified callback function. | ||
* | ||
* @param callback The callback function to be invoked when size changes are observed. | ||
* @param options The {@link IntersectionObserverOptions} to configure the IntersectionObserver | ||
*/ | ||
public IntersectionObserver( | ||
IntersectionObserver.IntersectionObserverCallbackFn callback, | ||
IntersectionObserverOptions options) {} | ||
} |
58 changes: 58 additions & 0 deletions
58
domino-ui/src/main/java/org/dominokit/domino/ui/utils/IntersectionObserverEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright © 2019 Dominokit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.dominokit.domino.ui.utils; | ||
|
||
import elemental2.dom.DOMRect; | ||
import elemental2.dom.Element; | ||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsProperty; | ||
import jsinterop.annotations.JsType; | ||
|
||
/** | ||
* The IntersectionObserverEntry interface of the Intersection Observer API describes the | ||
* intersection between the target element and its root container at a specific moment of | ||
* transition. | ||
* | ||
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry">MDN Web | ||
* Docs (IntersectionObserverEntry)</a> | ||
*/ | ||
@JsType(isNative = true, namespace = JsPackage.GLOBAL) | ||
public interface IntersectionObserverEntry { | ||
|
||
@JsProperty | ||
DOMRect getBoundingClientRect(); | ||
|
||
@JsProperty | ||
double getIntersectionRatio(); | ||
|
||
@JsProperty | ||
DOMRect getIntersectionRect(); | ||
|
||
@JsProperty | ||
boolean getIsIntersecting(); | ||
|
||
@JsProperty | ||
boolean getIsVisible(); | ||
|
||
@JsProperty | ||
DOMRect getRootBounds(); | ||
|
||
@JsProperty | ||
Element getTarget(); | ||
|
||
@JsProperty | ||
double getTime(); | ||
} |
53 changes: 53 additions & 0 deletions
53
domino-ui/src/main/java/org/dominokit/domino/ui/utils/IntersectionObserverOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright © 2019 Dominokit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dominokit.domino.ui.utils; | ||
|
||
import elemental2.core.JsArray; | ||
import elemental2.dom.Element; | ||
import jsinterop.annotations.JsOverlay; | ||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsType; | ||
import jsinterop.base.Js; | ||
import jsinterop.base.JsPropertyMap; | ||
|
||
/** | ||
* An optional object which customizes the observer. If options isn't specified, the observer uses | ||
* the document's viewport as the root, with no margin, and a 0% threshold (meaning that even a | ||
* one-pixel change is enough to trigger a callback). You can provide any combination of the | ||
* following options: | ||
* | ||
* @see <a | ||
* href="https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/IntersectionObserver">MDN | ||
* Web Docs (IntersectionObserver)</a> | ||
*/ | ||
@JsType(isNative = true, namespace = JsPackage.GLOBAL) | ||
public class IntersectionObserverOptions { | ||
|
||
/** | ||
* Creates a new instance of {@code ResizeObserverOptions} with default settings. | ||
* | ||
* @return A {@code ResizeObserverOptions} instance with default settings. | ||
*/ | ||
@JsOverlay | ||
public static IntersectionObserverOptions create() { | ||
return Js.uncheckedCast(JsPropertyMap.of()); | ||
} | ||
|
||
public Element root; | ||
public String rootMargin; | ||
public JsArray<Double> threshold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters