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

Improve routing #494

Closed
sapegin opened this issue Jun 12, 2017 · 9 comments
Closed

Improve routing #494

sapegin opened this issue Jun 12, 2017 · 9 comments

Comments

@sapegin
Copy link
Member

sapegin commented Jun 12, 2017

Right now all routing is hardcoded into index.js — it’s hard to maintain end extend. It also doesn’t support browser back / forward buttons (#467). We have to have several new features that would benefit from the proper router:

  • Single-component mode (or single-component mode by default) — basically start style guide in isolated mode, do not have (or do not show by default) a page with all components.
  • Split bundle by component or by section to make loading of large style guides faster (or make it possible at all).

I’m not sure what would be the best solution here. Should we use React Router or should we use something simpler?

Related issues: #467, #333.

@tizmagik
Copy link
Collaborator

This is an interesting problem. I think it should be doable to make dynamic routes in RRv4. I'll think through this a bit and post back/create a PR when I get a chance.

@sapegin
Copy link
Member Author

sapegin commented Jun 23, 2017

I’m not sure we need a RR here because we don’t really have real routes — we have a component filter. So we need a way to parse URL and call different filtering functions and react to URL changes. And allow extension by plugins.

@n1313
Copy link
Collaborator

n1313 commented Jun 23, 2017

Would having "real" routing make it easier to potentially split the bundle into lazily loaded chunks, one component per chunk?

@sapegin
Copy link
Member Author

sapegin commented Jun 23, 2017

I’m not sure, probably not or it won’t be the hard part anyway.

@tizmagik
Copy link
Collaborator

tizmagik commented Jun 23, 2017

So we need a way to parse URL and call different filtering functions and react to URL changes

Hmm but isn't that what a router such as RR essentially does? Would also take care of browser back button semantics, deep linking and isolation, no?

Happy to explore other approaches. What did you have in mind?

@sapegin
Copy link
Member Author

sapegin commented Jun 24, 2017

RR is mostly used to render different components depending on a route which we don’t need — we alway render the same component but with different props. I think we need something like Navigo.

@tizmagik
Copy link
Collaborator

RR is mostly used to render different components depending on a route which we don’t need

Right, but I think that might be part of the perf problem when you have a large number of components. This is the refactor I was alluding to in #212

I'll take a look at Navigo though, it would probably be less of a refactor, I'm assuming.

@zecaptus
Copy link

As I wanted to have a single component / page, I have done something that probably can help you.
Take a look here : https://github.com/zecaptus/styleguide

sapegin pushed a commit that referenced this issue Mar 22, 2018
👋 **[Support Styleguidist](https://opencollective.com/styleguidist) on Open Collective** 👋

## New features

### Page per section 🚧

This is a huge improvement for large style guides: now you can show only one component at a page instead of all components.

![](https://d3vv6lp55qjaqc.cloudfront.net/items/0W2q2K2s3n2k311O1J0y/Screen%20Recording%202018-03-22%20at%2010.06%20AM.gif)

To enable:

```js
module.exports = {
  pagePerSection: true
};
```

This is an experimental feature and we need your feedback to make it better and really useful. For example, right now there’s no isolated mode. So feel free to share your ideas [in issues](https://github.com/styleguidist/react-styleguidist/issues).

(#835 by @bitionaire and @stepancar, closes #494 and #768)

### “Fork me” ribbon

One more step to make Styleguidist usable for documenting open source projects:

![](https://d3vv6lp55qjaqc.cloudfront.net/items/1t331n2a3v0F2i290K0Z/Image%202018-03-22%20at%209.13.11%20AM.png)

New config option to enable the ribbon, define the URL and change the label:

```js
module.exports = {
  ribbon: {
    url: 'http://example.com/',
    text: 'Fork me on GitHub'
  }
};
```

And two new [theme variables](https://github.com/styleguidist/react-styleguidist/blob/master/src/styles/theme.js) to change colors: `color.ribbonBackground` and `color.ribbonText`.

(#861 by @glebez and @wkwiatek, part of #195, closes #647)

### Options to change CLI output on server start and build

Two new options, `printServerInstructions` and `printBuildInstructions`:

```js
module.exports = {
  printBuildInstructions(config) {
    console.log(
      `Style guide published to ${
        config.styleguideDir
      }. Something else interesting.`
    );
  }
};
```

(#878 by @roblevintennis, closes #876)

### Option to modify props

A new option, `updateDocs` to modify props before rendering. For example, you can load a component version number from a JSON file:

```js
module.exports = {
  updateDocs(docs) {
    if (docs.doclets.version) {
      const versionFilePath = path.resolve(
        path.dirname(file),
        docs.doclets.version
      );
      const version = require(versionFilePath).version;

      docs.doclets.version = version;
      docs.tags.version[0].description = version;
    }

    return docs;
  }
};
```

(#868 by @ryanoglesby08)

### Limited support for named exports

Styleguidist used to require default exports for components. Now you can use named exports too, though Styleguidist still supports only one component per file. I hope this change will make some users happier, see more details [in the docs](https://react-styleguidist.js.org/docs/components.html#loading-and-exposing-components).

(#825 by @marcdavi-es, closes #820 and #633)

### Allow arrays of component paths in sections

More flexibility in structuring your style guide:

```js
module.exports = {
  sections: [
    {
      name: 'Forms',
      components: [
        'lib/components/ui/Button.js',
        'lib/components/ui/Input.js'
      ]
    }
  ]
};
```

(#794 by @glebez, closes #774)

### Sort properties by `required` and `name` attributes

This change should make props tables more predictable for the users. Instead of relying on developers to sort props in a meaningful way, Styleguidist will show required props first, and sort props in each group alphabetically.

To disable sorting, use the identity function:

```javascript
module.exports = {
  sortProps: props => props
};
```

(#784 by @dotcs)

## Bug fixes

* Allow `Immutable` state in examples (#870 by @nicoffee, closes #864)
* Change template container ID to prevent clashes (#859 by @glebez, closes #753)
* Better props definitions with Flow types (#781 by @nanot1m)
@sapegin
Copy link
Member Author

sapegin commented Mar 22, 2018

🎉 This issue has been resolved in version 6.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants