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

toggle show sub-views like TAB behavior #17

Closed
17x opened this issue Sep 27, 2017 · 0 comments
Closed

toggle show sub-views like TAB behavior #17

17x opened this issue Sep 27, 2017 · 0 comments

Comments

@17x
Copy link

17x commented Sep 27, 2017

I made a react app with ui-router and sticky-state . I just want switch show views between sub-views of Home (you may notice i do sth in Home component . but its not working by some weird issue) .

How to straightforwardly approach my target ? thank !

//route
const configRouter = router => {
    // default to home
    router.urlRouter.otherwise('/home');

    //transition watch
    router.transitionService.onEnter({}, (trans, state) => {
        // ...
        console.log(trans, state);
    });
};

class App extends Component {
    render() {
        return (
            <UIRouter plugins={[hashLocationPlugin, StickyStatesPlugin]}
                      states={states}
                      config={configRouter}>
                <div>
                    <UIView name="home" />
                    <Footer />
                </div>
            </UIRouter>
        );
    };
}

//Home 
class Home extends Component {
    constructor(props) {
        super(props);
    }

    state = ({
        num: 2
    });

    render() {
        const {stateService} = this.props.transition.router;

        let style1 = {display: stateService.includes('home.tab1') ? 'block' : 'none'},
            style2 = {display: stateService.includes('home.tab2') ? 'block' : 'none'},
            style3 = {display: stateService.includes('home.tab3') ? 'block' : 'none'},
            style4 = {display: stateService.includes('home.tab4') ? 'block' : 'none'},
            style5 = {display: stateService.includes('home.tab5') ? 'block' : 'none'};      

        return (<div className="home">
            <Header />
            <div className="scroll-content scroll-content-top scroll-content-bottom">
                <ul className="tabHeader row">
                    {[1, 2, 3, 4, 5].map((val, index) => (
                        <UISrefActive class="active" key={index}>
                            <UISref to={'.tab' + val.toString()}>
                                <a key={index}
                                   className="col-fifth text-center height100p">
                                    {val.toString()}
                                </a>
                            </UISref>
                        </UISrefActive>
                    ))}
                </ul>
                <div>
                    <div className="homeTab1" style={style1}><UIView name="homeTab1" /></div>
                    <div className="homeTab2" style={style2}><UIView name="homeTab2" /></div>
                    <div className="homeTab3" style={style3}><UIView name="homeTab3" /></div>
                    <div className="homeTab4" style={style4}><UIView name="homeTab4" /></div>
                    <div className="homeTab5" style={style5}><UIView name="homeTab5" /></div>
                </div>
            </div>
        </div>);
    };
}

//homeStates
const homeState = [
    {
        name: 'home',
        url: '/home',
        sticky: true,
        redirectTo: 'home.tab1',
        views: {
            'home': {
                component: Home
            }
        }
    },
    {
        name: 'home.tab1',
        url: '/1',
        sticky: true,
        views: {
            'homeTab1': {
                component: HomeTab1
            }
        }
    },
    {
        name: 'home.tab2',
        url: '/2',
        sticky: true,
        views: {
            'homeTab2': {
                component: () => (<div>HomeTab2</div>)
            }
        }
    },
    {
        name: 'home.tab3',
        url: '/3',
        sticky: true,
        views: {
            'homeTab3': {
                component: () => (<div>HomeTab3</div>)
            }
        }
    },
    {
        name: 'home.tab4',
        url: '/4',
        sticky: true,
        views: {
            'homeTab4': {
                component: () => (<div>HomeTab4</div>)
            }
        }
    },
    {
        name: 'home.tab5',
        url: '/5',
        sticky: true,
        views: {
            'homeTab5': {
                component: () => (<div>HomeTab5</div>)
            }
        }
    }
];
@17x 17x closed this as completed Jan 4, 2018
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

No branches or pull requests

1 participant