Wolfr / sveltekit-jui

Sveltekit-JUI is a kit of UI components to be used in conjunction with Svelte and Svelte Kit
https://sveltekit-jui-wolfr.vercel.app/
Other
45 stars 3 forks source link

Implement category sorting for styleguide #5

Open Wolfr opened 3 years ago

Wolfr commented 3 years ago

I would like to be able to set the order of categories in an array, and for that order to be used in the styleguide.

PaxPax commented 3 years ago

Are you talking about something like?

  let categories = ['basics', 'components', 'objects', 'dev-notes']

  function sortByCategories(array, data) {
    let sortedCategories = []
    array.forEach((value) => {
      data.forEach((category) => {
        if (value === category["category"]) {
          sortedCategories.push(category)
        }
      })
    })
    return sortedCategories;
  }
Wolfr commented 3 years ago

Yes! Currently the data is here but is also ran through a reduce function to get the categories out of it (by grouping them).

https://github.com/Wolfr/sveltekit-jui/blob/main/src/routes/styleguide/$layout.svelte#L21-L187

PaxPax commented 3 years ago

Yes! Currently the data is here but is also ran through a reduce function to get the categories out of it (by grouping them).

https://github.com/Wolfr/sveltekit-jui/blob/main/src/routes/styleguide/$layout.svelte#L21-L187

Nice, we could just run the sortByCategories after the reduce and it should be fine. This is what it looks like with the above example ran. image

Wolfr commented 3 years ago

I am sorry but I can't seem to connect the two functions to return the right data, is this something you can PR? 🙏

PaxPax commented 3 years ago

Sure.