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

Typescript and docs #794

Merged
merged 10 commits into from
Apr 17, 2020
Merged

Typescript and docs #794

merged 10 commits into from
Apr 17, 2020

Conversation

jquense
Copy link
Member

@jquense jquense commented Apr 7, 2020

Started as a quick docs refactor but i figured I might as well switch to TS while i'm at it

@jquense jquense requested review from taion and mxschmitt April 7, 2020 20:41
Copy link
Member

@mxschmitt mxschmitt left a comment

Choose a reason for hiding this comment

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

Insane, great job!

How useful are actually prop types if you have typescript? To give the user better feedback about his props probably so still useful.

Quite hard to review, because it's quite big. Are there a lot of API changes? seems not what I've saw, then once the tests are passing I think we are ready to go. Incredible work!

@@ -0,0 +1,8 @@
export interface TransitionCallbacks {
onEnter?(node: HTMLElement): any;
Copy link
Member

Choose a reason for hiding this comment

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

not void as return value?

Copy link
Member Author

Choose a reason for hiding this comment

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

void is more correct, but any allows folks to do early returns like return callSomething() slightly more flexible and less descriptive. TBH tho i just copied this type from RB

@jquense
Copy link
Member Author

jquense commented Apr 7, 2020

Are there a lot of API changes?

Hopefully not! Should just be type additions where there weren't any

@jquense
Copy link
Member Author

jquense commented Apr 7, 2020

https://5e8ceea3ab1e79639efdf4c3--react-overlays.netlify.com/

@jquense
Copy link
Member Author

jquense commented Apr 9, 2020

👍 / 👎 ?

Copy link
Contributor

@sloria sloria left a comment

Choose a reason for hiding this comment

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

Just some drive-by copy editing while I was poking around...

This is quite a nice improvement!

www/src/pages/index.mdx Outdated Show resolved Hide resolved
www/src/pages/index.mdx Outdated Show resolved Hide resolved
www/src/pages/index.mdx Outdated Show resolved Hide resolved
www/src/pages/index.mdx Outdated Show resolved Hide resolved
www/src/pages/index.mdx Outdated Show resolved Hide resolved
www/src/examples/Modal.mdx Outdated Show resolved Hide resolved
www/src/examples/Dropdown.mdx Outdated Show resolved Hide resolved
www/src/examples/Dropdown.mdx Outdated Show resolved Hide resolved
www/src/examples/Dropdown.mdx Outdated Show resolved Hide resolved
www/src/examples/Dropdown.mdx Outdated Show resolved Hide resolved
@@ -69,7 +69,7 @@ const propTypes = {
* A callback fired when the Dropdown wishes to change visibility. Called with the requested
* `show` value, the DOM event, and the source that fired it: `'click'`,`'keydown'`,`'rootClose'`, or `'select'`.
*
* ```js
* ```ts static
Copy link
Member

Choose a reason for hiding this comment

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

what does static mean here?

Copy link
Member Author

Choose a reason for hiding this comment

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

not editable in place

{ show: 'onToggle' },
const [show, onToggle] = useUncontrolledProp(
rawShow,
defaultShow!,
Copy link
Member

Choose a reason for hiding this comment

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

non-null assertion here seems somewhat wrong? this is potentially legitimately null-y, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

It can, the bang is just to make the type correct without specifying the generic

{ show: 'onToggle' },
const [show, onToggle] = useUncontrolledProp(
rawShow,
defaultShow!,
Copy link
Member

Choose a reason for hiding this comment

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

non-null assertion here seems somewhat wrong? this is potentially legitimately null-y, no?

drop?: DropDirection;
};

const DropdownContext = React.createContext<DropdownContextValue | null>(null);
Copy link
Member

Choose a reason for hiding this comment

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

might be safer to do null as any? i mean, we don't really deal with the case where the context isn't available, right? no point being robust to that

Copy link
Member Author

Choose a reason for hiding this comment

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

needed for examples and things where we just show e.g. the Dropdown Menu

import { createPopper } from './popper';

const initialPopperStyles = {
const initialPopperStyles: Partial<CSSStyleDeclaration> = {
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be the react css properties?

Copy link
Member Author

Choose a reason for hiding this comment

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

there is an annoying incompatibility there with what Popper typed this as and what react does

src/DropdownToggle.tsx Outdated Show resolved Hide resolved
toggle: DropdownContextValue['toggle'];
}

const noop: any = () => {};
Copy link
Member

Choose a reason for hiding this comment

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

this matches the typing, no? do we need the explicit any type?

src/Modal.tsx Outdated Show resolved Hide resolved
Comment on lines +166 to +167
if (canUseDOM && !prevShow && show) {
lastFocusRef.current = activeElement() as HTMLElement;
}
Copy link
Member

Choose a reason for hiding this comment

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

is it really safe to access the DOM during render? should this not go in useLayoutEffect?

Copy link
Member Author

Choose a reason for hiding this comment

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

an effect is too late, even layoutEffect. I believe this is safe, but there isn't actually a getSnapshot lifecycle hook equiv. Also we do this in Dropdown and it's been fine so far

src/Modal.tsx Outdated
Comment on lines 227 to 247
// Show logic when:
// - show is `true` _and_ `container` has resolved
useEffect(() => {
if (!show || !container) return;

handleShow();
}, [show, container, /* show never change: */ handleShow]);

// Hide cleanup logic when:
// - `exited` switches to true
// - component unmounts;
useEffect(() => {
if (!exited) return;

handleHide();
}, [exited, handleHide]);

useWillUnmount(() => {
handleHide();
});
Copy link
Member

Choose a reason for hiding this comment

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

is there no good way to write this as a single effect? e.g. calculate a shown value, and then have an effect block?

if (show && container && !foo) {
  setFoo(true);
} else if (exited) {
  setFoo(false);
}

useEffect(() => {
  if (!foo) {
    return undefined;
  }

  handleShow();
  return handleHide;
}, [foo, handleShow, handleHide]);

Copy link
Member Author

Choose a reason for hiding this comment

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

ah maybe, wasn't sure if it helped us much tho. I guess it would simplify it nicely. I can try

Copy link
Member Author

Choose a reason for hiding this comment

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

imma try that as a follow up

@jquense jquense merged commit 9c9b441 into master Apr 17, 2020
@jquense jquense deleted the typescript branch April 17, 2020 16:34
@@ -30,11 +30,11 @@
"scripts": {
"bootstrap": "yarn && yarn --cwd www",
"build": "rimraf lib && yarn build:cjs && yarn build:esm && yarn build:pick",
"build:cjs": "babel src -d lib/cjs && rollup src/popper.js --file lib/cjs/popper.js --format cjs --name popper --plugin @rollup/plugin-node-resolve",
"build:cjs": "babel src -d lib/cjs && rollup src/popper.ts --file lib/cjs/popper.js --format cjs --name popper --plugin @rollup/plugin-node-resolve",

Choose a reason for hiding this comment

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

mmaguebo

peterblazejewicz added a commit to peterblazejewicz/DefinitelyTyped that referenced this pull request Jul 29, 2020
The `react-overlays` switched to fully blown TS version as of 3.1.0:
react-bootstrap/react-overlays#794

Should fix issue when installing current `react-overlays` with previous
version of types.

/cc @NicoleRauch

Thanks!

Fixes: DefinitelyTyped#40940
typescript-bot pushed a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Jul 31, 2020
…zejewicz

The `react-overlays` switched to fully blown TS version as of 3.1.0:
react-bootstrap/react-overlays#794

Should fix issue when installing current `react-overlays` with previous
version of types.

/cc @NicoleRauch

Thanks!

Fixes: #40940
danielrearden pushed a commit to danielrearden/DefinitelyTyped that referenced this pull request Sep 22, 2020
…ge by @peterblazejewicz

The `react-overlays` switched to fully blown TS version as of 3.1.0:
react-bootstrap/react-overlays#794

Should fix issue when installing current `react-overlays` with previous
version of types.

/cc @NicoleRauch

Thanks!

Fixes: DefinitelyTyped#40940
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.

5 participants