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

SlidePanel #18

Merged
merged 23 commits into from
Feb 7, 2017
Merged

SlidePanel #18

merged 23 commits into from
Feb 7, 2017

Conversation

bitpshr
Copy link
Member

@bitpshr bitpshr commented Feb 3, 2017

Type: feature

The following has been addressed in the PR:

  • There is a related issue
  • All code matches the style guide
  • Unit or Functional tests are included in the PR

Description:

This PR introduces a SlidePanel component, updates the existing Dialog component to the new widget API, and adds custom element wrappers for each. It also adds accessibility features to the Dialog based on suggestions from @smhigley. Focus accessibility was omitted until we work through a focus manager.

Initial SlidePanel API:

align?: string;
open?: boolean;
underlay?: boolean;
width?: number;
onOpen?(): void;
onRequestClose?(): void;

Resolves #2, Resolves #12, Resolves #17

@codecov-io
Copy link

codecov-io commented Feb 4, 2017

Codecov Report

Merging #18 into master will not impact coverage.

@@          Coverage Diff          @@
##           master    #18   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      3    +1     
  Lines          26    105   +79     
  Branches       13     44   +31     
=====================================
+ Hits           26    105   +79
Impacted Files Coverage Δ
src/components/dialog/createDialog.ts 100% <100%> (ø)
src/components/slidePanel/createSlidePanel.ts 100% <100%> (ø)
src/main.ts 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0692f44...ca67210. Read the comment docs.


export interface SlidePanelFactory extends WidgetFactory<SlidePanel, SlidePanelProperties> { };

let content: HTMLElement;
Copy link
Member

Choose a reason for hiding this comment

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

Do these not have to be stored in a weakmap keyed by the instance? Otherwise having multiple instances will mess with the values.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. Do you have an example of how that would look?

Copy link
Member

Choose a reason for hiding this comment

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

Something like this I'd imagine.

interface InternalState {
    content: any;
}

const internalStateMap = new Weakmap<SlidePanel, InternalState>();

// and something like this in the initialise
initialize(instance) {
    internalStateMap.set(instance, initialValues):
}

@agubler
Copy link
Member

agubler commented Feb 4, 2017

Can we add a custom element wrapper by default for all our components? There are instructions on the readme.

Copy link
Member

@agubler agubler left a comment

Choose a reason for hiding this comment

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

A few comments/questions

package.json Outdated
"@dojo/compose": "2.0.0-beta.21",
"@dojo/core": "2.0.0-alpha.20",
"@dojo/has": "2.0.0-alpha.7",
"@dojo/i18n": "2.0.0-alpha.5",
"@dojo/shim": "2.0.0-beta.8",
"@dojo/widget-core": "^2.0.0-alpha.23",
Copy link
Member

Choose a reason for hiding this comment

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

we are trying to work with pinned dependencies at the moment.

import * as animations from '../../styles/animations.css';
import themeable, { ThemeableMixin } from '@dojo/widget-core/mixins/themeable';

export interface SlidePanelProperties extends WidgetProperties {
Copy link
Member

Choose a reason for hiding this comment

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

let's add some jsdoc for the properties (and other exported APIs)

} = this.properties;

// Current pointer position
let currentX = event.type === 'touchmove' ? event.changedTouches[0].screenX : event.pageX;
Copy link
Member

Choose a reason for hiding this comment

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

presume these can both be const?

onRequestClose && onRequestClose();
}
// If the underlay was clicked
else if (delta > -5 && delta < 5 && (<HTMLElement> event.target).classList.contains(css.underlay)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we might have a type somewhere for this (I'll see if I can find it)

const classes: {[key: string]: any} = {};
const styles: {[key: string]: any} = {};

classes[css.content] = true;
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should be using the this.class( function as it effectively manages the creation of any required false classes, so for this example you could just have an array of classNames that you want to be set and then spread them this.classes(...classesToSet).get()?

const classes = [css.content];

if (open && !state.wasOpen) {
    classes.push(css.slideIn);
}
else if (!open && state.wasOpen) {
    classes.push(css.slideOut);
    if (state.transform !== 0) {
        styles['transform'] = `translateX(${ align === 'left' ? '-' : '' }${ state.transform }%)`;
    }
}

const content = v('div', { 
    key: 'content', 
    classes:  this.classes(...classes).get(), 
    styles, 
    afterCreate: this.afterCreate 
}, this.children);

@dylans dylans added this to the 2017.02 milestone Feb 6, 2017
@bitpshr
Copy link
Member Author

bitpshr commented Feb 7, 2017

@agubler: Ready for another review when you get a chance. Want to make sure my JSDoc looks ok, I was a little confused what to document for returned factory functions.

Copy link
Member

@agubler agubler left a comment

Choose a reason for hiding this comment

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

couple small questions?

* @property {Function?} onCloseClick Event handler for when the close button is clicked
* @property {Function?} onUnderlayClick Event handler for when a click occurs outside the dialog
*/
export type Dialog = Widget<DialogProperties> & ThemeableMixin & {
Copy link
Member

Choose a reason for hiding this comment

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

these are mandatory really? as you implement them as the author?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

* @property {Function?} afterCreate Called after the panel is rendered as DOM
* @property {Function?} onTransitionEnd Event handler for when the panel finishes any animation
*/
export type SlidePanel = Widget<SlidePanelProperties> & ThemeableMixin & {
Copy link
Member

Choose a reason for hiding this comment

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

pretty much same comment, they are all implemented below so can remove the ??

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

};

export type SlidePanel = Widget<SlidePanelProperties> & ThemeableMixin & {
onSwipeStart?(event: MouseEvent & TouchEvent): void;
Copy link
Member

Choose a reason for hiding this comment

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

Should these be optional? They're all implemented and part of the widget so it feels like they should not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@bitpshr
Copy link
Member Author

bitpshr commented Feb 7, 2017

Ready for another look.

},
{
attributeName: 'modal',
value: value => Boolean(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

These Boolean conversions aren't working quite right. Boolean('false') and Boolean('0') return true.

Copy link
Contributor

@rorticus rorticus left a comment

Choose a reason for hiding this comment

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

The custom element wrappers look good 👍 I created a little test page with a slide panel and was able to interact with it as a custom element.

@bitpshr bitpshr merged commit 6c8a5d1 into dojo:master Feb 7, 2017
@bitpshr bitpshr deleted the slidepanel branch February 7, 2017 19:42
@bitpshr
Copy link
Member Author

bitpshr commented Feb 7, 2017

Party on.

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.

6 participants