Skip to content

Commit

Permalink
refactor: show types
Browse files Browse the repository at this point in the history
  • Loading branch information
leonwgc committed Apr 19, 2024
1 parent 6b0199b commit 520fb55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { MountContainerType, Placement } from './types';

export const isNumber = (n) => {
return Object.prototype.toString.call(n) === '[object Number]' && n === n;
};

const isObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]';
/**
* Get Popover mount container.
Expand Down
20 changes: 6 additions & 14 deletions src/show.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import React from 'react';
import { Dispose, renderElement } from './dom';
import Popover from './Popover';
import { PopoverProps } from './types';

export type Props = Omit<PopoverProps, 'children' | 'onVisibleChange' | 'closeOnClickOutside'> & {
left?: number | string;
top?: number | string;
anchor?: Element | string | React.MutableRefObject<Element>;
};
import { Dispose, renderElement } from './dom';
import { isNumber } from './helper';
import { ShowProps } from './types';

let _hide;

Expand All @@ -21,16 +16,13 @@ export const hide = (): void => {
}
};

const isNumber = (n) => {
return Object.prototype.toString.call(n) === '[object Number]' && n === n;
};
/**
* Static method of Popover
*
* @param {Props} props
* @param {ShowProps} props
* @return {*} hide popover fun.
*/
export const show = (props: Props): (() => void) => {
export const show = (props: ShowProps): (() => void) => {
const { left, top, placement = 'top', style, ...rest } = props;
let anchor = props.anchor,
x = left,
Expand Down Expand Up @@ -86,7 +78,7 @@ export const show = (props: Props): (() => void) => {
visibility: 'hidden',
pointerEvents: 'none',
}}
className="uc-popover-anchor"
className="w-popover__anchor"
/>
</Popover>,
div
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,12 @@ export type EventTargetType =
| EventTarget
| React.MutableRefObject<EventTarget>
| (() => EventTarget);

export type ShowProps = Omit<
PopoverProps,
'children' | 'onVisibleChange' | 'closeOnClickOutside'
> & {
left?: number | string;
top?: number | string;
anchor?: Element | string | React.MutableRefObject<Element>;
};

0 comments on commit 520fb55

Please sign in to comment.