-
Notifications
You must be signed in to change notification settings - Fork 0
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
phoenix_html v4 compatibility #130
phoenix_html v4 compatibility #130
Conversation
53b6d0d
to
73f7a85
Compare
73f7a85
to
7918745
Compare
@@ -100,7 +106,7 @@ defmodule BitstylesPhoenix.Component.Form do | |||
* | |||
</span> | |||
</label> | |||
<input id="user_name" maxlength="255" name="user[name]" required="required" type="text"/> | |||
<input id="user_name" name="user[name]" type="text" maxlength="255" required="required"/> |
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 all the existing test cases in this module that have a git diff, the diff is only about reordering attributes.
The regular unit test job runs phoenix_html v3, the one with unlocked deps runs v4. Both succeeding meaning that I achieved the task 🎉 |
<%= render_slot(@inner_block) %> | ||
<% end %> |
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.
🥳
elixir-version: '1.14.5' | ||
- run: mix deps.unlock --all | ||
- run: mix deps.get | ||
- run: mix test |
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.
Nice test
<%= render_slot(@inner_block) %> | ||
</label> | ||
""" | ||
end |
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.
Awesome work ✨
''' | ||
) | ||
|
||
def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do |
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.
Since you want this one to be public to test it we should actually have a less generic name for this one, since otherwise we get the .input
component everywhere, which might even clash with existing helper components.
How about ui_raw_input
?
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.
That makes sense, done: 5b61a76
(#130)
end | ||
|> Safe.to_iodata() | ||
|> IO.iodata_to_binary() |
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.
👏
CHANGELOG.md
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
## Unreleased | |||
|
|||
- Added support for phoenix_html `v4`. You can also continue using phoenix_html `v3`. |
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.
Maybe we can also document the newly added components for raw inputs and labels (whatever name you choose)
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.
Is this enough ca1ec04
(#130) ? I was struggling to find the right words to describe the components in the changelog and gave up on writing more, hoping people would just look for more details in the components' documentation
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.
Perfect!
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.
💚
Resolves #129
Goal: make bitstyles_phoenix work in any combination of phoenix_live_view versions 18 to 20, and phoenix_html versions 3 to 4
Replacements
Phoenix.HTML.Tag.content_tag
in a LV context can be replaced withdynamic_tag
which exists in phoenix_live_view v18Phoenix.HTML.Tag.content_tag
in a non-LV context is used for generating the "showcase" macros, can be replaced with a copy-paste of the function. It relies onimport Phoenix.HTML, only: [attributes_escape: 1, html_escape: 1]
which both still exist in phoenix_html v4Phoenix.HTML.Form.humanize
- this function was previously used by Phoenix to generate default label text from a field name. It looks like there no longer is a default label text. We can copy-paste this function and keep using it.Phoenix.HTML.Form.label
- should be replaced with a newBitstylesPhoenix.Component.Form.label
component that's a copy-paste from Phoenix's CoreComponentsPhoenix.HTML.Form.text_input
,Phoenix.HTML.Form.email_input
, and so on, andPhoenix.HTML.Form.textarea
, andPhoenix.HTML.Form.select
- should all be replaced with a newBitstylesPhoenix.Component.Form.input
component that's a copy-paste from Phoenix's CoreComponents but modified to be just the input, no label and no errors. (yes, "textarea" and "select" are handled by an "input" component in CoreComponents 🤷)CI changes
https://hexdocs.pm/elixir/library-guidelines.html#dependency-handling recommends:
Running tests with unlocked deps would detect that bitstyles_phoenix does not work with the newest phoenix_html version because there was no version specification for this dependency in the mix file.
Other notes
Phoenix.Component.used_input?
that's used by PLV 1.0.0-RC in core components does not exist in lower versions. It's used to decide whether input errors should be rendered.Phoenix.HTML.FormField
was added to phoenix_html in 3.3.0, so we need to require that version at minimum.Phoenix.Component.to_form
used in the tests was added to PLV in 18.12. Since we cannot provide different PLV version requirements for local development and for library usage, we need to bump the lowest supported version from 18.9 to 18.12.