Simplify prop binding and conditional props #109
Labels
Semver: Next
Will make it's way to the bleeding edge version of the package
Type: Enhancement
Improving an existing feature
Description
Currently, it can be quite a chore passing props to elements. For example, when creating an input field component:
Now, let's make this more dynamic. I'd like to set the placeholder, name and optionally value attributes and overwrite classes if needed. The
type
should betext
by default, but also be customizable. Furthermore, optionally an error can be provided. In a template, it would be used something like this:Implementing this is quite difficult, especially when compared to other templating languages:
I have found some issues with this:
class
attribute will contain whitespaces at the end. It's possible for classes to be printed twice, if predefined classes are also passed in prop. Also, using the conditional operator adds a lot of boilerplate code. Just feels a bit strange to me.$props.serializeOnly
seems handy at first, but will not work in many cases, as it returns the stringundefined
, when passed that value. Furthermore, it doesn't work when the attribute key does not match the prop key, as witharia-errormessage
/error
.Proposed changes
Firstly, I'd find it much more intuitive if
undefined
would render to an empty string, instead of the string literalundefined
. Vue and React (JSX) behave the same in this, and I'd assume most other templating languages behave the same.Also, I'd love if binding attributes would be easier. Coming from Vue, I'm used to the comfort of bindings like these:
Maybe Edge could take some inspiration from other modern templating languages, like Vue or JSX.
Thanks for your time and great work!
The text was updated successfully, but these errors were encountered: