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

[WIP] close popins with escape #1094

Closed
wants to merge 4 commits into from

Conversation

plepaisant
Copy link
Contributor

Popin closed with esc

Description

issue #824 :
Escape, in order to close each and every opened panel (and popin and such).
Meaning we have to keep track of the order in which popins have been opened to close them in reverse order.

the z-order of the popins is managed with the data-level attribute. The view is responsible of attributting a new level each time a popin is opened.

Example

  /**
  *  return a level - z-order -  higher then the previous
  */ 
    getLevel(){
        this.currentLevel++;
        return this.currentLevel;
    }
    /**
    *  open a popin and set its level ie z-order 
    */  
    popinOpener(ref) {
        var self = this;
        return function (event) {
            event.preventDefault();
            // setting the new level when opening the popin
            self.refs[ref].setLevel(self.getLevel());
            self.refs[ref].toggleOpen();
        }
    }

    render() {
        return (
            <div>
                <Button handleOnClick={this.popinOpener('from-left')} label='Open from-left popin'
                        style={{className:'btn-primary'}}/>
                <Button handleOnClick={this.popinOpener('from-right')} label='Open from-right popin'
                        style={{className:'btn-primary'}}/>
                <Button handleOnClick={this.popinOpener('full')} label='Open full popin'
                        style={{className: 'btn-primary'}}/>
                <div className="popins-container">
                    <Popin ref="full" type="full">
                        {PopinContent}
                    </Popin>
                    <Popin ref="from-left" type="from-left" >
                        {PopinContent}
                    </Popin>
                    <Popin ref="from-menu-second"  type="from-menu">
                        {PopinContent}
                    </Popin>
                    <Popin ref="from-right" type="from-right">
                        {PopinContent}
                    </Popin>
                </div>
            </div>
        );
    }

@plepaisant plepaisant force-pushed the feature-panel-closed-with-esc branch from 6b967a0 to 38e7c72 Compare April 6, 2016 13:06
e.preventDefault();
if (e.code === "Escape") {
if (this.state.opened) {
const popins = [].slice.call(document.querySelectorAll("[data-focus='popin']")).reduce((prec, current) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

[...document.querySelectpr]

@pierr
Copy link
Contributor

pierr commented Apr 6, 2016

render(){
const {isPopin1, isPopin2} = this.state;
{
isPopin && <Popin1 />
}

}

@plepaisant plepaisant force-pushed the feature-panel-closed-with-esc branch 2 times, most recently from 1cc0e33 to f2bbe5e Compare April 11, 2016 07:33
if (this.state.opened) {
const popins = [...document.querySelectorAll("[data-focus='popin']")].reduce((prec, current) => {
if (current.hasChildNodes()) {
prec.push(Number(current.getAttribute('data-level')));
Copy link
Contributor

Choose a reason for hiding this comment

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

+

@plepaisant plepaisant force-pushed the feature-panel-closed-with-esc branch 2 times, most recently from 2efce0c to 357c29d Compare April 12, 2016 08:02
*/
handleKeyDown(e) {
e.preventDefault();
if (e.code === "Escape") {
Copy link
Contributor

Choose a reason for hiding this comment

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

'Escape'

@pierr
Copy link
Contributor

pierr commented Apr 14, 2016

I don't see why the level cannot be a props

@pierr
Copy link
Contributor

pierr commented Apr 14, 2016

@plepaisant

@pierr pierr added this to the 0.15.0 milestone Apr 14, 2016
@plepaisant
Copy link
Contributor Author

In the Popin code example, the popins are created in the render method of the parent. To handle the z-order, the level property needs to be updated when the popins toggle to visible state. At that time, the prop level cannot be changed so I had to create a state level.

 render() {
        return (
            <div>
                <MenuLeft items={this.itemsBuilder()} handleBrandClick={this.goHome}>
                </MenuLeft>
                <div style={this.style} className="demo-card-wide mdl-card mdl-shadow--2dp">
                    <div className="mdl-card__title" style={this.titleStyle}>
                        <h2 className="mdl-card__title-text">The Superman</h2>
                    </div>
                    <div className="mdl-card__supporting-text" style={this.divSupportText}>
                        <h5>
                            Through this example you'll find the different possibilities you got with the Focus Popin component.
                            <br/><br/>
                            Click on <div className="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect"><i  className="material-icons">notifications</i></div> icon to have a menu slidding popin
                            <br/>
                            Click on <div className="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect"><i  className="material-icons">chat</i></div> icon to have a right slidding popin
                            <br/>
                            And <button className="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" onClick={this.makeTheSecondPopinPop}><b>Click here</b></button> to display a fade-in popin example.
                            <br/>
                        </h5>
                    </div>
                </div>
                <MyPopin ref='popin'/>
                <SecondPopin ref='secondPopin'/>
                <ThirdPopin ref='thirdPopin'/>
            </div>
        );
    }

@plepaisant plepaisant force-pushed the feature-panel-closed-with-esc branch 3 times, most recently from eb52aef to 30f9ea1 Compare April 15, 2016 07:20
@plepaisant plepaisant force-pushed the feature-panel-closed-with-esc branch from 30f9ea1 to 6b4ae85 Compare April 15, 2016 13:57
@pierr pierr modified the milestones: 0.15.0, 0.16.0 May 25, 2016
@TomGallon TomGallon modified the milestones: 0.16.0, 0.17.0 Jun 16, 2016
@TomGallon TomGallon changed the base branch from develop to v2.x.x September 5, 2016 08:36
@GuenoleK GuenoleK self-assigned this Oct 17, 2016
@TomGallon TomGallon closed this Oct 27, 2016
@TomGallon TomGallon changed the base branch from v2.x.x to develop October 27, 2016 17:52
@TomGallon TomGallon reopened this Oct 27, 2016
@fconstantin fconstantin deleted the feature-panel-closed-with-esc branch March 16, 2017 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants