-
Notifications
You must be signed in to change notification settings - Fork 227
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(dialog): new component #611
Conversation
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
@mgr34 there are files in this PR that shouldn't have been touched, such as top app bar files. It also looks like there are commits from november. Could you please fix this? |
@moog16 uh oh. I really have no idea what happened. Let me see what I can figure out and I'll get back to you. |
@moog16 is my commit history necessary? This task could be more efficient if I would close this PR. create a new branch off of rc0.9.0 and bring in the necessary files and submit a new PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took an initial look. Some foundation methods aren't being used. Also a lot of typescript errors in test/unit.
Once those are all addressed I'll take another look. Thanks!
packages/dialog/index.tsx
Outdated
handleDocumentKeyDown = (e: Event): void => | ||
this.foundation.handleDocumentKeydown(e); | ||
// @ts-ignore parameter never used | ||
handleLayout = (evt: Event): void => this.foundation.layout(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the ts-ignore and evt
packages/dialog/index.tsx
Outdated
@@ -258,7 +260,7 @@ class Dialog<T extends {} = HTMLElement> extends React.Component< | |||
const container: React.ReactElement<HTMLDivElement> | undefined = | |||
this.renderContainer(children); | |||
return ( | |||
// @ts-ignore | |||
// @ts-ignore Tag does not have any construct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a github issue associated with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry - I poorly communicated. Could you please add that issue to the comment on this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my bad, I knew what you meant. (changes forthcoming)
packages/dialog/DialogButton.tsx
Outdated
import Button from '@material/react-button'; | ||
|
||
|
||
export interface DialogButtonProps<ButtonProps> extends React.HTMLProps<ButtonProps> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I meant
DialogButtonProps<...> extends ButtonProps<...>
packages/dialog/index.tsx
Outdated
aria-modal | ||
className={this.classes} | ||
id={id} | ||
role='alertdialog' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget this one too
packages/dialog/index.tsx
Outdated
export type ChildTypes<ChildProps> = DialogTitle<ChildProps> | DialogContent<ChildProps>| DialogFooter<ChildProps>; | ||
export type ChildProps<T> = DialogTitleProps<T> | DialogContentProps<T> | DialogFooterProps<T>; | ||
|
||
export interface DialogProps<T> extends React.HTMLProps<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one too still needs to be addresed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(wait have you not been seeing my previous comments?)
packages/dialog/DialogContent.tsx
Outdated
import {cssClasses} from './constants'; | ||
|
||
|
||
export interface DialogContentProps extends React.HTMLProps<HTMLElement>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still learning TypeScript, and I guess I am not fully groking it yet.
Its not fully clear to me how to implement the generic. But I looked at other components that allow a user to pass a Tag and I am either seeing it implemented the way I have it. For example, with the Drawer [0] or just having the interface not extend anything. Such as with DrawerTitle [1] or ListItemText [2]
Would the answer here to just change L27 to
export interface DialogContentProps { ... }
[0]
export interface DrawerProps extends React.HTMLProps<HTMLElement>{ |
packages/dialog/index.tsx
Outdated
|
||
export type ChildTypes<T> = DialogTitle<T> | DialogContent<T>| DialogFooter<T>; | ||
|
||
export interface DialogProps extends React.HTMLProps<HTMLElement> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment about generics [0]. But would the proper way to do this be the following? If so does that mean Drawer [1] should also be changed?
export type ChildTypes<T> = DialogTitle<T> | DialogContent<T>| DialogFooter<T>;
export interface DialogProps<T> extends React.HTMLProps<T> {
autoStackButtons?: boolean;
children?: ChildTypes<T>;
className?: string;
id?: string;
onClose?: (action: string) => void;
onClosing?: (action: string) => void;
onOpen?: () => void;
onOpening?: () => void;
open?: boolean;
tag?: string;
};
interface DialogState {
classList: Set<string>;
}
class Dialog<T extends {} = HTMLElement> extends React.Component<
DialogProps<T>,
DialogState
> { .... }
test/screenshot/top-app-bar/dense.js
Outdated
@@ -0,0 +1,24 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for real, how did any this top-app-bar stuff get in here. ...must investigate.
packages/dialog/index.tsx
Outdated
import {cssClasses, LAYOUT_EVENTS} from './constants'; | ||
import {FocusTrap} from 'focus-trap'; | ||
|
||
export type ChildTypes<ChildProps> = DialogTitle<ChildProps> | DialogContent<ChildProps>| DialogFooter<ChildProps>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am understanding what you are saying with this comment, and the one below re: T
representing 4 diff types. However, I am struggling to implement this at the moment. I might need to step away for the day and give it a fresh go tomorrow morning.
Ultimately, the reason export type ChildTypes...
exists is because I don't want line 44 to extent to long, and more importantly, I need to reuse ChildTypes in renderContainer
and renderChild
.
packages/dialog/index.tsx
Outdated
import {cssClasses, LAYOUT_EVENTS} from './constants'; | ||
import {FocusTrap} from 'focus-trap'; | ||
|
||
export type ChildTypes<ChildProps> = DialogTitle<ChildProps> | DialogContent<ChildProps>| DialogFooter<ChildProps>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, what If I removed the generic and did something like the following?:
export type ChildTypes = (
DialogTitle<DialogTitleProps<{}>>
| DialogContent<DialogContentProps<{}>>
| DialogFooter<DialogFooterProps<{}>>
);
export interface DialogProps<T> extends React.HTMLProps<T> {
autoStackButtons?: boolean;
children?: ChildTypes | ChildTypes[];
className?: string;
escapeKeyAction?: string;
id?: string;
onClose?: (action: string) => void;
onClosing?: (action: string) => void;
onOpen?: () => void;
onOpening?: () => void;
open?: boolean;
scrimClickAction?: string;
tag?: string;
};
the problem I'm seeing in this implementation and the implementation I had prior is I would expect the following to not be valid
<Dialog>
<p>should fail because !(DialogTitle | DialogContent | DialogFooter)</p>
<DialogContent><p>this is good</p></DialogContent>
</Dialog>
But maybe I shouldn't be trying to place such restrictions on the composition pattern. Although, I thought I was enforcing these restrictions. Perhaps this is because Dialog[Title|Content|Footer] have the type signature of type DialogContent<T> = React.ReactElement<T>
and allows them to be any ReactElement?--am I using the phrase type signature correctly?
packages/dialog/index.tsx
Outdated
@@ -258,7 +260,7 @@ class Dialog<T extends {} = HTMLElement> extends React.Component< | |||
const container: React.ReactElement<HTMLDivElement> | undefined = | |||
this.renderContainer(children); | |||
return ( | |||
// @ts-ignore | |||
// @ts-ignore Tag does not have any construct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import {cssClasses, LAYOUT_EVENTS} from './constants'; | ||
import {FocusTrap} from 'focus-trap'; | ||
|
||
export type ChildTypes = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used anywhere...please remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the export? I do use ChildTypes
in test/unit/dialog/index.test.tsx
. and in renderContainer, renderChild()
and setId
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah please move to the tests then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ah just seeing this. I also use this in the Dialog package. Specifically in rednerContainer, renderChild and setId).
wrapper.instance().renderChild = | ||
coerceForTesting<(child: ChildTypes, i?: number) => ChildTypes>(td.func()); | ||
const children: ChildTypes[] = | ||
wrapper.instance().props.children as ChildTypes[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use coerceForTesting() in ./test/unit/helpers/types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is where I have coerceForTesting imported from. you want me to use it on line 465/466
// change this
const children: ChildTypes[] = wrapper.instance().props.children as ChildTypes[];`
// to this?
const children: ChildTypes[] =
coerceForTesting<ChildTypes[]>(wrapper.instance().props.children as ChildTypes[]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the as ChildTypes[]
...coerce...() does that for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional approval on all other comments...working on screenshot tests.
test/unit/dialog/index.test.tsx
Outdated
const wrapper = shallow<Dialog>(<Dialog />); | ||
wrapper.instance().foundation.adapter_.addBodyClass('test-class'); | ||
const body = document.querySelector('body'); | ||
// @ts-ignore Object is possibly 'null' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
@@ -0,0 +1,117 @@ | |||
import * as React from 'react'; | |||
import '../../../packages/top-app-bar/index.scss'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please remove these from the screenshot tests.
|
also need to add
to ./test/screenshot/screenshot-test-urls.tsx |
reopened tests #629 |
Adds a Dialog Component. golden.json needs to be updated.
I signed it