Skip to content

Commit

Permalink
refactor(types): Type definitions for Position and PositionAnimated (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored May 28, 2021
1 parent fc91054 commit 8c08d28
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
10 changes: 10 additions & 0 deletions packages/fuselage/src/components/Box/Position/Position.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Placements, PositionOptions } from '@rocket.chat/fuselage-hooks';
import { ComponentProps, FC, RefObject } from 'react';

type PositionProps = {
anchor?: RefObject<Element>;
placement?: Placements;
margin?: PositionOptions['margin'];
} & ComponentProps<typeof Box>;

declare const Position: FC<PositionProps>;
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { usePosition } from '@rocket.chat/fuselage-hooks';
import React, { useRef, useMemo, useEffect } from 'react';
import ReactDOM from 'react-dom';

import AnimatedVisibility from '../AnimatedVisibility';
import { useRef, useMemo, useEffect, cloneElement } from 'react';
import { createPortal } from 'react-dom';

const Position = ({
anchor,
Expand Down Expand Up @@ -33,8 +31,8 @@ const Position = ({
portalContainer,
]);

return ReactDOM.createPortal(
React.cloneElement(children, {
return createPortal(
cloneElement(children, {
ref: target,
style,
...props,
Expand All @@ -44,19 +42,4 @@ const Position = ({
);
};

export const PositionAnimated = ({
width,
margin,
placement,
visible,
children,
...props
}) => (
<AnimatedVisibility visibility={visible}>
<Position margin={margin} placement={placement} {...props}>
{children}
</Position>
</AnimatedVisibility>
);

export default Position;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ComponentProps } from 'react';

import Position from '.';

type PositionAnimatedProps = {
visibility?: boolean;
} & ComponentProps<typeof Position>;

declare const PositionAnimated: FC<PositionAnimatedProps>;
12 changes: 12 additions & 0 deletions packages/fuselage/src/components/Box/Position/PositionAnimated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

import Position from '.';
import AnimatedVisibility from '../AnimatedVisibility';

const PositionAnimated = ({ width, visible, children, ...props }) => (
<AnimatedVisibility visibility={visible}>
<Position {...props}>{children}</Position>
</AnimatedVisibility>
);

export default PositionAnimated;
3 changes: 3 additions & 0 deletions packages/fuselage/src/components/Box/Position/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default } from './Position';

export { default as PositionAnimated } from './PositionAnimated';

0 comments on commit 8c08d28

Please sign in to comment.