Skip to content

Provide an ActiveStore-ish mixin #85

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

Closed
rexxars opened this issue Jul 17, 2014 · 5 comments
Closed

Provide an ActiveStore-ish mixin #85

rexxars opened this issue Jul 17, 2014 · 5 comments

Comments

@rexxars
Copy link

rexxars commented Jul 17, 2014

This is a little silly, but I'm basically trying to wrap <Link> in an <li> and have the active-class be applied to the li instead of the link (see https://twitter.com/ryanflorence/status/482334466375819265)

I got this working by basically duplicating most of Link, but referencing an internal component (react-nested-router/modules/stores/ActiveStore) seems a little hacky and is prone to break in the future.

Preferably, I'd like to see some sort of mixin that you can include in your components to easily check if a route is active. An alternative would be to expose ActiveStore on the router if it's there to stay.

Thoughts?

@ryanflorence
Copy link
Member

Bootstrap has always been wrong to do this.

I like the mixin idea though.

Sent from my iPhone

On Jul 17, 2014, at 2:45 AM, Espen Hovlandsdal [email protected] wrote:

This is a little silly, but I'm basically trying to wrap in an

  • and have the active-class be applied to the li instead of the link (see https://twitter.com/ryanflorence/status/482334466375819265)

    I got this working by basically duplicating most of Link, but referencing an internal component (react-nested-router/modules/stores/ActiveStore) seems a little hacky and is prone to break in the future.

    Preferably, I'd like to see some sort of mixin that you can include in your components to easily check if a route is active. An alternative would be to expose ActiveStore on the router if it's there to stay.

    Thoughts?


    Reply to this email directly or view it on GitHub.

  • @ryanflorence
    Copy link
    Member

    Something really low level like:

    var SomeWellNamedMixin = require('react-nested-router').SomeWellNamedMixin;
    
    var ListLink = React.createClass({
      mixins: [SomeWellNamedMixin]
      render: function() {
        return (
          <li className={this.props.isActive ? 'active' : 'inactive'}>
            <Link to={this.props.route}>{this.props.children}</Link>
          </li>;
      }
    });
    
    var link = <ListLink route="about">About</ListLink>;
    

    All it would do is take this.props.route and this.props.params and tell you if the route you care about is active, then anybody can make their own abstractions on top for bootstrap, etc.

    @rexxars
    Copy link
    Author

    rexxars commented Jul 17, 2014

    Wow, great work. Quickly delivered! Thanks a ton!

    @ryanflorence
    Copy link
    Member

    I have a feeling michael is or anticipates using bootstrap somewhere ...

    On Thu, Jul 17, 2014 at 1:05 PM, Espen Hovlandsdal <[email protected]

    wrote:

    Wow, great work. Quickly delivered! Thanks a ton!


    Reply to this email directly or view it on GitHub
    #85 (comment)
    .

    @mjackson
    Copy link
    Member

    Haha, nope :) After being forced to use Bootstrap on stuff while working for Twitter, I'm quite happy to leave it alone these days.

    @lock lock bot locked as resolved and limited conversation to collaborators Jan 25, 2019
    Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants