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: refactor hooks useEventBroker and useLayer #1060

Merged
merged 5 commits into from
Oct 30, 2023
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
5 changes: 3 additions & 2 deletions src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {Portal} from '../Portal';
import type {DOMProps, QAProps} from '../types';
import {FocusTrap} from '../utils/FocusTrap';
import {block} from '../utils/cn';
import type {LayerCloseReason} from '../utils/layer-manager';
import {useLayer} from '../utils/layer-manager';
import type {LayerExtendableProps} from '../utils/layer-manager/LayerManager';
import {getCSSTransitionClassNames} from '../utils/transition';
import {useLayer} from '../utils/useLayer';
import type {LayerCloseReason, LayerExtendableProps} from '../utils/useLayer';
import {useRestoreFocus} from '../utils/useRestoreFocus';

import './Modal.scss';
Expand Down
4 changes: 2 additions & 2 deletions src/components/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {Portal} from '../Portal';
import type {DOMProps, QAProps} from '../types';
import {FocusTrap, useParentFocusTrap} from '../utils/FocusTrap';
import {block} from '../utils/cn';
import {useLayer} from '../utils/layer-manager';
import type {LayerExtendableProps} from '../utils/layer-manager/LayerManager';
import {getCSSTransitionClassNames} from '../utils/transition';
import {useLayer} from '../utils/useLayer';
import type {LayerExtendableProps} from '../utils/useLayer';
import {usePopper} from '../utils/usePopper';
import type {PopperAnchorRef, PopperPlacement, PopperProps} from '../utils/usePopper';
import {useRestoreFocus} from '../utils/useRestoreFocus';
Expand Down
4 changes: 1 addition & 3 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ export * from './utils/class-transform';
export * from './utils/event-broker';
export {getComponentName} from './utils/getComponentName';
export * from './utils/withEventBrokerDomHandlers';
export * from './utils/useEventBroker';
export * from './utils/useLayer';
export * from './utils/layer-manager';
export {Lang, configure} from './utils/configure';
export {useOnFocusOutside} from './utils/useOnFocusOutside';
export * from './utils/interactions';
export * from './utils/xpath';
export {getLayersCount} from './utils/LayerManager';
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {QAProps} from '../types';

import {NAMESPACE} from './cn';
import type {QAProps} from '../../types';
import {NAMESPACE} from '../cn';

export interface EventBrokerData<T = unknown> extends QAProps {
componentId: string;
Expand Down
3 changes: 3 additions & 0 deletions src/components/utils/event-broker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export {eventBroker} from './EventBroker';
export {useEventBroker} from './useEventBroker';
export type {EventBrokerSubscription, EventBrokerData} from './EventBroker';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import {eventBroker} from './event-broker';
import type {EventBrokerSubscription} from './event-broker';
import {eventBroker} from './EventBroker';
import type {EventBrokerSubscription} from './EventBroker';

export function useEventBroker(subscription: EventBrokerSubscription, broker = eventBroker) {
React.useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type {VirtualElement} from '@popperjs/core';

import {KeyCode} from '../../constants';

import {eventBroker} from './event-broker';
import {KeyCode} from '../../../constants';
import {eventBroker} from '../event-broker';

export type LayerCloseReason = 'outsideClick' | 'escapeKeyDown';

Expand All @@ -16,9 +15,7 @@ export interface LayerExtendableProps {
type?: string;
}

export type ContentElement =
| Element
| (VirtualElement & {contains?: (other: Node | null) => boolean});
type ContentElement = Element | (VirtualElement & {contains?: (other: Node | null) => boolean});

export interface LayerConfig extends LayerExtendableProps {
contentRefs?: Array<React.RefObject<ContentElement> | undefined>;
Expand Down
4 changes: 4 additions & 0 deletions src/components/utils/layer-manager/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {layerManager, getLayersCount} from './LayerManager';
export type {LayerConfig, LayerCloseReason} from './LayerManager';
export {useLayer} from './useLayer';
export type {LayerProps} from './useLayer';
2 changes: 1 addition & 1 deletion src/components/utils/withEventBrokerDomHandlers.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import {eventBroker} from './event-broker';
import type {EventBrokerData} from './event-broker';
import {eventBroker} from './event-broker';
import {getComponentName} from './getComponentName';

type SupportedEvents = 'onClick' | 'onClickCapture';
Expand Down
Loading