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

feat: implement InternalOverlay component #1581

Merged
merged 18 commits into from
May 27, 2020

Conversation

HellWolf93
Copy link
Collaborator

fix: #1540

Changes proposed in this PR:

  • Add useWindowResize hook

  • Define InternalOverlay component typescript interface

  • Add tests for InternalOverlay component

  • Improve examples of InternalOverlay component

  • Fix triggerElementRef prop type

  • I have followed (at least) the PR section of the contributing guide.

@commit-lint
Copy link

commit-lint bot commented May 23, 2020

Features

  • add useWindowResize hook (20ecbd8)
  • define InternalOverlay typescript interface (ce9be78)

Bug Fixes

  • InternalOverlay triggerElementRef prop type (a01574d)
  • add more real functionality for the two examples (d2d6f33)
  • improve InternalOverlay docs (61688ff)
  • add positionResolver parameter type (99c15ae)
  • add test for second click on button (eab8025)
  • add useCallback to returned functions in useWindowResize (27b3aff)
  • change useWindowResize api (480f350)
  • make all props optional (9df4db7)
  • error on ci unit tests (5e287f1)
  • internalOverlay 'should resolve content meta' test case (0fea2fc)

Tests

  • add tests for InternalOverlay component (474acb8)

Contributors

@HellWolf93, @reiniergs, @LeandroTorresSicilia

Comment on lines 7 to +9
import RenderIf from '../RenderIf';
import useOutsideClick from '../../libs/hooks/useOutsideClick';
import useWindowResize from '../../libs/hooks/useWindowResize';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeandroTorresSicilia I have doubts we put to use the hooks and internal components in the examples?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should start documenting every internal implementation as part of the internal session, I will avoid code duplication since the library is huge and something we can end up repeating same implementation.

things under internal session will only for internal use and we specific to consumers of the library that the API of internal could change and it won't be considered breaking change

variant="neutral"
icon={<PlusIcon />}
icon={<StyledPlusIcon />}
ref={ref}
onClick={handleClick}
/>
<InternalOverlay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeandroTorresSicilia here I also have doubts about how to export and import this component. It is not clear how InternalOverlay was imported

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relative-path since it's internal, it won't be part of the public API

src/components/InternalOverlay/readme.md Outdated Show resolved Hide resolved
src/components/InternalOverlay/readme.md Outdated Show resolved Hide resolved
src/components/InternalOverlay/readme.md Outdated Show resolved Hide resolved
src/libs/hooks/useWindowResize.js Outdated Show resolved Hide resolved
};
}, [isListening, listener]);

return [() => setIsListening(true), () => setIsListening(false)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these 2 functions you also have to make it useCallback because otherwise they will be defined over and over again. If outside the hook other hook depends on them, you will cause that hook to be executed.

Every time you go to make a reusable hook everything you return must be done useMemo or useCallback

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yvmunayev those 2 functions does not have dependencies, so useCallback will do nothing, I need some advice on this...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions can be dependencies of other hooks, if you don't Memo it then the other hooks will always be executed. The conditional of the hooks uses the javascript comparison, where 2 functions, even if they are the same if the references are different, returns false.

src/components/InternalOverlay/readme.md Outdated Show resolved Hide resolved
src/components/InternalOverlay/index.d.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,27 @@
import { useEffect, useState, useCallback } from 'react';

export default function useWindowResize(handler) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be something similar to useEffect, the implementation depend of when should listen(generally when something is open).

Possible API could be

useWindowResize(handler, isListening = true);

so it can be used to listen always or on and off

always:

useWindowResize(() => something()};

on and off

const [isOpen, setOpenState] = useState(false);
useWindowResize(() => setOpenState(false), isOpen);

render: ComponentClass | FunctionComponent;
isVisible?: boolean;
triggerElementRef: RefObject | TriggerElementRefFunction;
positionResolver: (opts: PositionResolverOpts) => Position;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all props should be optional

@TahimiLeonBravo TahimiLeonBravo self-requested a review May 25, 2020 20:03
Copy link
Collaborator

@reiniergs reiniergs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@reiniergs
Copy link
Collaborator

@HellWolf93 there are a couple of tests failing

@LeandroTorresSicilia LeandroTorresSicilia merged commit 0a4be49 into nexxtway:master May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: implement InternalOverlay component
5 participants