11ty / webc

Single File Web Components
MIT License
1.3k stars 36 forks source link

How do you list all of the props of a component? #192

Open hasanhaja opened 9 months ago

hasanhaja commented 9 months ago

Context

I really like WebC and I love that it's decoupled from 11ty. I find the authoring experiencing very similar to writing Astro components, but I can take this with me anywhere. I'm still figuring out all the different ways it works through work on my website, but I can already see its potential in this being a tool to author framework-independent components.

What I'm trying to achieve

As a part of research I've been doing on building a component library framework-independently that is still SSR friendly, I'm working on generating React components (and others in the future) from the WebC compiler output. I'm doing it this way because:

Repo: 🔗 https://github.com/hasanhaja/webcc

Problem

I've started aggragating a list of APIs to poke at here, but I haven't gotten anything to work yet.

Example of why I'm after this is below. I'd like to be able to convert this:

<div>
  <p @text="greeting"></p>
  <p @text="message"></p>
</div>

To this:

type ComponentWithPropsProps = {greeting: string; message: string;};

export const ComponentWithProps = ({ greeting, message }) => (
  <>
    <div>
      <p>{greeting}</p>
      <p>{message}</p>
    </div>
  </>
);

export default ComponentWithProps;

I currently have this working, but I expect a .json file to be provided that matches the schema. This isn't very ergonomic and I would like the "WebCC" tool (I haven't been able to come up with a better name yet 😅) to just work out of the box.

In general, I'm not 100% sure about my approach, so I would also really appreciate any pointers and general feedback you have