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

Sort sidebar entries #517

Open
cblavier opened this issue Nov 28, 2024 · 5 comments
Open

Sort sidebar entries #517

cblavier opened this issue Nov 28, 2024 · 5 comments
Labels
enhancement New feature or request
Milestone

Comments

@cblavier
Copy link
Contributor

All entries are currently sorted alphabetically.
We should implement manual sorting, such as custom indexes or a similar method.

@cblavier cblavier added the enhancement New feature or request label Nov 28, 2024
@cblavier cblavier added this to the v0.8.0 milestone Dec 10, 2024
@sodapopcan
Copy link
Contributor

sodapopcan commented Jan 23, 2025

Hello again!

So my company very much wants this. If you're open to me taking it on, I've been given the go ahead to do this on the clock.

Do you have an API in mind?

My thinking was to add a callback to PhoenixStorybook.Index. You could either do the whole thing in _root of specify overrides per directory. So with this structure:

storybook/
  _root.index.exs
  menu.story.exs
  buttons/
    _buttons.index.exs
    button.story.exs
    submit.story.exs    

You could do:

# _root.index.exs
def order do
  [
    :menu,
    buttons: [
      :submit,
      :button
    ]
  ]
end

or:

# _root.index.exs
def order, do: [:menu, :buttons]

# _buttons.index.exs
def order, do: [:submit, :button]

Another idea would be to add "weights" to the stories themselves. This option feels harder to maintain, although it could be useful if you always want to sort one story to the top (like a summary/usage page) and have everything else alphabetical.

Lastly, I'm not sure if anyone wants this (I don't think we do) but it would be to define a sort function:

def sort_function, do: &MyApp.sort_function/2

Of course all three could be implemented.

What are your thoughts?

@cblavier
Copy link
Contributor Author

What about folder_index/0 and a new :index key for entry/1 functions?

  • nil indexes are put at the end
  • items with the same index are sorted in alphabetical order
defmodule Storybook.CoreComponents do
  use PhoenixStorybook.Index

  def folder_open?, do: true
  def folder_icon, do: {:fa, "box-open", :thin}
  def folder_index, do: 0

  def entry("back"), do: [icon: {:fa, "circle-left", :thin}, index: 0]
  def entry("button"), do: [icon: {:fa, "rectangle-ad", :thin}, index: 1]
  def entry("error"), do: [icon: {:fa, "circle-exclamation", :thin}, index: 2]
  def entry("flash"), do: [icon: {:fa, "bolt", :thin}]
end

WDYT?

@sodapopcan
Copy link
Contributor

Oh ya, I totally forgot about entry/1 as we don't use it. Ya, I'm super happy with this!

@sodapopcan
Copy link
Contributor

Let me know if you would like me to handle this. If so, I can get started tomorrow.

@cblavier
Copy link
Contributor Author

Yes please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants