mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-07-22 08:05:41 +00:00
971df8edba
- Remove all 3rd party parachain configurations from endpoints: - productionRelayPolkadot.ts: Keep only system parachains - productionRelayDicle.ts: Keep only system parachains - testingRelayZagros.ts: Keep only system parachains - testingRelayTeyrChain.ts: Keep only system parachains - Update domain references: - polkadot.js.org → pezkuwichain.app - wiki.polkadot.network → wiki.pezkuwichain.io - dotapps.io → pezkuwichain.app - statement.polkadot.network → docs.pezkuwichain.io/statement - support.polkadot.network → docs.pezkuwichain.io - Update repository references: - github.com/pezkuwi-js/apps → github.com/pezkuwichain/pwap - Rename system parachains to Pezkuwi ecosystem: - PolkadotAssetHub → PezkuwiAssetHub - polkadotBridgeHub → pezkuwiBridgeHub - polkadotCollectives → pezkuwiCollectives - polkadotCoretime → pezkuwiCoretime - polkadotPeople → pezkuwiPeople - Update network name in claims utility: - Polkadot → Pezkuwi
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/react-hooks authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type React from 'react';
|
|
import type { HorizontalPosition, VerticalPosition } from '@pezkuwi/react-components/Popup/types';
|
|
|
|
import { useEffect, useMemo, useState } from 'react';
|
|
|
|
import { getPosition } from '@pezkuwi/react-components/Popup/utils';
|
|
|
|
import { createNamedHook } from './createNamedHook.js';
|
|
import { useElementPosition } from './useElementPosition.js';
|
|
import { useScroll } from './useScroll.js';
|
|
import { useWindowSize } from './useWindowSize.js';
|
|
|
|
interface Coord {
|
|
x: number;
|
|
y: number;
|
|
}
|
|
|
|
interface Result {
|
|
pointerStyle: VerticalPosition;
|
|
renderCoords: Coord;
|
|
}
|
|
|
|
const COORD_0: Coord = { x: 0, y: 0 };
|
|
|
|
function usePopupWindowImpl (windowRef: React.RefObject<HTMLDivElement>, triggerRef: React.RefObject<HTMLDivElement>, position: HorizontalPosition): Result {
|
|
const [renderCoords, setRenderCoords] = useState<Coord>(COORD_0);
|
|
const [pointerStyle, setPointerStyle] = useState<VerticalPosition>('top');
|
|
const windowCoords = useElementPosition(windowRef);
|
|
const triggerCoords = useElementPosition(triggerRef);
|
|
const scrollY = useScroll();
|
|
const windowSize = useWindowSize();
|
|
|
|
useEffect(() => {
|
|
if (windowSize && triggerCoords) {
|
|
setPointerStyle((triggerCoords.y > windowSize.height / 2) ? 'top' : 'bottom');
|
|
}
|
|
}, [triggerCoords, windowSize]);
|
|
|
|
useEffect(() => {
|
|
if (windowCoords && triggerCoords) {
|
|
setRenderCoords(getPosition(triggerCoords, position, pointerStyle, windowCoords, scrollY, windowSize));
|
|
}
|
|
}, [position, scrollY, triggerCoords, pointerStyle, windowCoords, windowSize]);
|
|
|
|
return useMemo(
|
|
() => ({ pointerStyle, renderCoords }),
|
|
[renderCoords, pointerStyle]
|
|
);
|
|
}
|
|
|
|
export const usePopupWindow = createNamedHook('usePopupWindow', usePopupWindowImpl);
|