Skip to content

Conversation

@ztanner
Copy link
Contributor

@ztanner ztanner commented Jul 4, 2022

  • Props.ts can now be used rather than Props.js for assigning props to a component (see: examples/basic/link & examples/basic/button)
  • If a defaultValue is specified for a prop, it will attempt to infer the type based on that.
  • Props.js will still work as before

TODO: Some API cleanup & remove some ts-ignores

@ztanner ztanner requested a review from brkalow July 4, 2022 17:13
},
}

export type { Props } from './index'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an example of just using Props from the component itself, rather than the contrived example in Button, where the Props are declared there :)

@brkalow
Copy link
Contributor

brkalow commented Jul 13, 2022

@ztanner Awesome! I wonder if it would be possible to automatically extract props from the component definition itself, instead of having to export it from the props.ts file. It appears that @structured-types can also parse out docs comments by default, e.g. https://structured-types.vercel.app/?code=%22export%20interface%20Props%20%7B%5Cn%20%20%2F%2A%2A%20The%20text%20in%20the%20link%20%2A%2F%5Cn%20%20text%3A%20string%5Cn%20%20%5Cn%20%20href%3A%20string%5Cn%7D%5Cn%5Cnexport%20default%20function%20Link%28%7B%20text%2C%20href%20%7D%3A%20Props%29%20%7B%5Cn%20%20return%20%28%5Cn%20%20%20%20%3Ca%20className%3D%7Bs.root%7D%20href%3D%7Bhref%7D%3E%5Cn%20%20%20%20%20%20%7Btext%7D%5Cn%20%20%20%20%3C%2Fa%3E%5Cn%20%20%29%5Cn%7D%22&selected-tab=%22structured-types%22

The thought being that we could make the entire props.ts file optional if desired and have a fully dynamic props table out of the box. It feels like the heuristic would be:

  • Look at the default export
  • if it's a component and the name matches, look at its properties and use the type information provided by @structured-types there

@ztanner
Copy link
Contributor Author

ztanner commented Jul 25, 2022

Ahh, that's a much simpler API! I'll get this loaded in

@hashicorp-cla
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes


1 out of 2 committers have signed the CLA.

  • ztanner
  • Bryce Kalow

Bryce Kalow seems not to be a GitHub user.
You need a GitHub account to be able to sign the CLA. If you already have a GitHub account, please add the email address used for this commit to your account.

Have you signed the CLA already but the status is still pending? Recheck it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants