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(dialog): new component #611

Merged
merged 45 commits into from
Jan 23, 2019
Merged

Conversation

mgr34
Copy link
Contributor

@mgr34 mgr34 commented Jan 11, 2019

Adds a Dialog Component. golden.json needs to be updated.

note: heading to lunch, plan to add commit later this afternoon with Documentation, but anticipate some changes.


I signed it

Matt Goo and others added 23 commits November 30, 2018 14:49
@googlebot
Copy link

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 cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@moog16
Copy link

moog16 commented Jan 11, 2019

@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?

@mgr34
Copy link
Contributor Author

mgr34 commented Jan 11, 2019

@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.

@mgr34
Copy link
Contributor Author

mgr34 commented Jan 11, 2019

@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.

Copy link

@moog16 moog16 left a 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!

package.json Outdated Show resolved Hide resolved
packages/dialog/DialogButton.tsx Outdated Show resolved Hide resolved
packages/dialog/DialogButton.tsx Outdated Show resolved Hide resolved
packages/dialog/DialogButton.tsx Show resolved Hide resolved
packages/dialog/DialogContent.tsx Outdated Show resolved Hide resolved
packages/dialog/package.json Outdated Show resolved Hide resolved
packages/dialog/package.json Outdated Show resolved Hide resolved
packages/dialog/index.tsx Show resolved Hide resolved
handleDocumentKeyDown = (e: Event): void =>
this.foundation.handleDocumentKeydown(e);
// @ts-ignore parameter never used
handleLayout = (evt: Event): void => this.foundation.layout();
Copy link

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 Show resolved Hide resolved
packages/dialog/README.md Outdated Show resolved Hide resolved
@@ -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
Copy link

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, an issue you opened ;)

microsoft/TypeScript#28892

Perhaps I phrased it wrong

Copy link

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

Copy link
Contributor Author

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)

test/screenshot/dialog/confirmation.tsx Outdated Show resolved Hide resolved
import Button from '@material/react-button';


export interface DialogButtonProps<ButtonProps> extends React.HTMLProps<ButtonProps> {
Copy link

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<...>

aria-modal
className={this.classes}
id={id}
role='alertdialog'
Copy link

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

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> {
Copy link

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

Copy link
Contributor Author

@mgr34 mgr34 left a 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/package.json Outdated Show resolved Hide resolved
packages/dialog/index.tsx Show resolved Hide resolved
import {cssClasses} from './constants';


export interface DialogContentProps extends React.HTMLProps<HTMLElement>{
Copy link
Contributor Author

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>{

[1] https://github.com/material-components/material-components-web-react/blob/rc0.9.0/packages/drawer/Title.tsx#L4

[2] https://github.com/material-components/material-components-web-react/blob/43cd5796ff70757f7b4ccec668a1a76300aa53fc/packages/list/ListItemText.tsx


export type ChildTypes<T> = DialogTitle<T> | DialogContent<T>| DialogFooter<T>;

export interface DialogProps extends React.HTMLProps<HTMLElement> {
Copy link
Contributor Author

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                                                                                             
  > {   .... }            

[0] https://github.com/material-components/material-components-web-react/pull/611/files/36deb8cc601396cb29a97023fd3550d9f8200c6b#r247227131

[1] https://github.com/material-components/material-components-web-react/blob/rc0.9.0/packages/drawer/index.tsx

packages/dialog/DialogTitle.tsx Show resolved Hide resolved
@@ -0,0 +1,24 @@
import React from 'react';
Copy link
Contributor Author

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.

import {cssClasses, LAYOUT_EVENTS} from './constants';
import {FocusTrap} from 'focus-trap';

export type ChildTypes<ChildProps> = DialogTitle<ChildProps> | DialogContent<ChildProps>| DialogFooter<ChildProps>;
Copy link
Contributor Author

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.

import {cssClasses, LAYOUT_EVENTS} from './constants';
import {FocusTrap} from 'focus-trap';

export type ChildTypes<ChildProps> = DialogTitle<ChildProps> | DialogContent<ChildProps>| DialogFooter<ChildProps>;
Copy link
Contributor Author

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?

@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, an issue you opened ;)

microsoft/TypeScript#28892

Perhaps I phrased it wrong

test/screenshot/dialog/confirmation.tsx Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
import {cssClasses, LAYOUT_EVENTS} from './constants';
import {FocusTrap} from 'focus-trap';

export type ChildTypes = (
Copy link

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

Copy link
Contributor Author

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.

Copy link

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

Copy link
Contributor Author

@mgr34 mgr34 Jan 22, 2019

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[];
Copy link

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

Copy link
Contributor Author

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[]);

Copy link

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

Copy link

@moog16 moog16 left a 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 Show resolved Hide resolved
test/unit/dialog/index.test.tsx Outdated Show resolved Hide resolved
test/unit/dialog/index.test.tsx Outdated Show resolved Hide resolved
test/unit/dialog/index.test.tsx Show resolved Hide resolved
test/unit/dialog/index.test.tsx Outdated Show resolved Hide resolved
test/unit/dialog/index.test.tsx Outdated Show resolved Hide resolved
test/unit/dialog/index.test.tsx Outdated Show resolved Hide resolved
test/unit/dialog/index.test.tsx Outdated Show resolved Hide resolved
test/unit/dialog/index.test.tsx Outdated Show resolved Hide resolved
const wrapper = shallow<Dialog>(<Dialog />);
wrapper.instance().foundation.adapter_.addBodyClass('test-class');
const body = document.querySelector('body');
// @ts-ignore Object is possibly 'null'
Copy link

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';
Copy link

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.

@moog16
Copy link

moog16 commented Jan 18, 2019

@mgr34

  "dialog/alert": "e0c9b5fd4468c5fff9902b4e8e79c488b0fe8300b08a9620f32ed380b5c2af79",
  "dialog/simple": "2b72930b7711c258d4fead83055ec02b10edebda722901e7ed3ecb7365827dd1",
  "dialog/confirmation": "0d548366130de2aeb85d993a0e9d2030840db0ba10bc49b2721ae05cbd42b058",
  "dialog/scrollable": "91bf3789cc22928df667c96a8a7f1cfdcaad4868c55ab5d830d132249a620f1c"

@moog16
Copy link

moog16 commented Jan 18, 2019

also need to add

dialogVariants.forEach((variant: string) => {
  urls.push(`dialog/${variant}`);
});

to ./test/screenshot/screenshot-test-urls.tsx

@moog16 moog16 changed the title Feat/dialog feat(dialog): new component Jan 22, 2019
@moog16
Copy link

moog16 commented Jan 22, 2019

reopened tests #629

@moog16
Copy link

moog16 commented Jan 23, 2019

#629 passes with the change reflected in 7ed0101.

CLA Signed in first commit. Going to merge.

@moog16 moog16 merged commit 00c1a42 into material-components:rc0.9.0 Jan 23, 2019
@moog16 moog16 mentioned this pull request Jan 23, 2019
moog16 pushed a commit that referenced this pull request Jan 23, 2019
@moog16 moog16 mentioned this pull request Jan 23, 2019
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.

8 participants