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

Components structure #2080

Open
flacial opened this issue Jul 13, 2022 · 2 comments
Open

Components structure #2080

flacial opened this issue Jul 13, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request ongoing Ongoing task

Comments

@flacial
Copy link
Member

flacial commented Jul 13, 2022

Problem

Our current components structure looks like the following:

  • Component test under components/
  • Component code under components/
  • Component styles under styles/
  • Component story under stories/

They're scattered into 3 directories. And within the components/ folder, there are two files, the component code, and the test. Having such a structure makes it cluttered and hard to work with. As our codebase isn't huge yet, it's better to fix this issue now than later.

Solution

Each component will have its folder. This folder will contain the component and its: test, story, and styles

The component entry point will be called index.tsx so it can be easily imported (or it could be used to export to [componentName].tsx, so we don't end up with all the file names being index.tsx). The folder will also contain the CSS, test file, and story.

components/
  CopyButton/
    index.tsx
    CopyButton.tsx
    CopyButton.module.scss
    CopyButton.stories.ts # Currently, it's not possible to include the story
    CopyButton.test.js

index.tsx will contain the following, so we can do import Component from '../components/ComponentFolder' instead of ./components/ComponentFolder/ComponentFolder

export { default } from './CopyButton.tsx'

@flacial flacial added the enhancement New feature or request label Jul 13, 2022
@flacial flacial self-assigned this Jul 13, 2022
@flacial flacial changed the title Folders structure Components structure Jul 13, 2022
flacial added a commit to flacial/c0d3-app that referenced this issue Jul 14, 2022
@evo777
Copy link

evo777 commented Jul 27, 2022

Folders are good.

flacial added a commit to flacial/c0d3-app that referenced this issue Aug 4, 2022
flacial added a commit to flacial/c0d3-app that referenced this issue Aug 4, 2022
flacial added a commit to flacial/c0d3-app that referenced this issue Aug 4, 2022
@flacial flacial added the ongoing Ongoing task label Aug 25, 2022
@flacial flacial pinned this issue Sep 18, 2022
@scotthallock
Copy link
Collaborator

@flacial Is this something I can help out with? It would be nice to have everything in folders.

Also, I'm not sure I understand the problem with moving the *.stories.tsx files into the same folder as the component. Is it about the stories glob in ./storybook/main.js?

I played around with the glob on the Learn Storybook repo:

Example 1

stories: ["../src/components/*/*.stories.js"] matches the stories in the src/components/[ComponentName]/ folder but not elsewhere:

Screenshot 2023-04-02 at 5 23 41 AM

Example 2

stories: ["../src/**/*.stories.js"] matches stories anywhere in the src/ folder, at any level:
Screenshot 2023-04-02 at 5 36 21 AM

For c0d3 app

If we changed the glob to "../**/*.stories.tsx" - wouldn't that match all [ComponentName].stories.tsx files anywhere in our repo?

This will also allow us to keep the pages and MDX stories wherever we want. I can try this it out later to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ongoing Ongoing task
Projects
Status: No status
Development

No branches or pull requests

3 participants