-
Notifications
You must be signed in to change notification settings - Fork 150
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
implements input_* form elements #79
Conversation
Hi @alexandrubagu! Awesome job 🎉 I have a question for discussion before we merge this. As far as I could see, some of the inputs have the same properties and generate the same For the record, I'm not sure yet which approach is better so I'm trying to see the pros and cons :) @zamith feel free to share your thoughts too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the comments I left, I tend to agree. We can probably abstract all of these into one Input
component with a type. It will be a lot easier to maintain and the bulk of the work is already done by Phoenix.HTML.Form
anyway.
We can (maybe?) still add a couple of wrappers over Input
for ergonomics. For example RangeInput
here has a min
and max
properties, which seems useful, so you don't have to send it via opts
.
Regarding "creating own component" vs "using a generic input". One advantage of the current implementation (having one component for each function) is that we end up with a 1:1 mapping between them, which may be more intuitive for users. I've just noticed we've missed events for both, the inputs and the form. I believe for the inputs we have at least I guess we should define them without the @doc "Triggered when the component loses focus"
property blur, :event
@doc "Triggered when the component receives focus"
property focus, :event Note: It's important that we add the events explicitly, otherwise, Surface will not set the |
Agree. It was in my plans to add those. As for the 1:1 mapping, I don't think there is much difference in terms of being intuitive from:
to
It both makes it "simpler" in terms of maintainability for us and more closely resembles actual HTML. That being said I don't have a strong preference either way, the main reason I'm leaning towards a generic component is having less code to deal with (E.g. we want to add the events, it would be changes to one file, instead of 10) |
@msaraiva @zamith I've updated the PR but I don't know how to proceed further. From my point of view I prefer to have them in separate components as they are defined in Another idea is to have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @alexandrubagu!
Thank you so much for taking the time to work on this. I think we could start creating a generic <Input>
component with a type
property. We could also define the valid values like:
property type, :string, values: ["hidden", "dete", "time", ...]
if we do this we can statically validate them in the near future and editors could also use that information to provide autocomplete/suggestions.
We can also keep specific components for any of them that we feel might bring better UX, like the RangeInput
. No need to remove it.
Then we can wait for some feedback to see if we need to create the others.
The others should be created on top of the generic one. That would be a perfect scenario to test the :props
directive and the import_props
, which have not been implemented yet but are on the roadmap.
WDYT?
import Phoenix.HTML.Form, only: [range_input: 3] | ||
import Surface.Components.Form.Utils | ||
|
||
alias Surface.Components.Form, warn: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need warn: false
here since Form
is being used in context get
. In case you remove it and start receiving warnings, please let me know, it's a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In tests I've tried to remove warn: false
and I got some warnings, so I kept them in place
@alexandrubagu I took a look at the specification of It looks like some the attributes are only applicable to some of the types. For instance, an input of type So let's move on with separate components. Thanks a lot, @alexandrubagu for your work and sorry for coming back and forth on this. |
Signed-off-by: Alexandru Bagu <alexandrubagu87@gmail.com>
@alexandrubagu thanks! ❤️ |
I've implemented all input_* form elements @msaraiva @zamith