-
Notifications
You must be signed in to change notification settings - Fork 2
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
Create dropup for profile #27
Conversation
src/Resources/views/base.html.twig
Outdated
@@ -87,6 +87,10 @@ | |||
</div> | |||
{% endblock %} | |||
{% endblock %} | |||
|
|||
{% block sidebar_profile %} | |||
{% include "@araiseCrud/includes/sidebar/_profile.html.twig" %} |
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.
Nit: Code-Style. Project should add a Code-Style checker for these things to not be Double Quotes for some cases and then again single quotes for other cases (see block('...')
which are all single quotes).
{{ bootstrap_icon('pencil-square', { class: 'h-3 w-3 self-center mr-2', alt: '' }) }} | ||
{% block profile_edit_text %}Profil bearbeiten{% endblock %} | ||
<a | ||
href="{% block logout_link %}{% endblock %}" |
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.
It's odd to use blocks like that. This file probably would be better off as a macro instead of a template, if it needs this level of flexibility. Otherwise, we should use {{ block('logout_link') }}
instead.
The problem with this pattern here is that it is difficult to read. We can't make a readable, proper null/undefined check. And we also can't enforce the block to be set, as the blocks are optional. Yet the href
must never be empty.
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.
Way better as a Macro.
I created it inside the same file and when no macro is imported (just the file included), I added a text with a notification to change it for all projects which has it included differently
<img class="inline-block h-4 w-4 rounded-full self-center mr-2" | ||
src="{% block profile_picture %}{% endblock %}" alt="" | ||
crossorigin="anonymous" referrerpolicy="no-referrer"> | ||
{% block profile_fullname %}[email protected]{% endblock %} |
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.
Do not put static, invalid data as a default to the code. It will be forgotten and it will come up in production.
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's right. I didn't found where to get the data from the backend but wanted to create the MR before I'm in holiday. Sandro has a task to also create the images proper.
data-transition-leave-to="opacity-0 scale-95" | ||
tabindex="-1" | ||
> | ||
<div class="flex flex-col gap-y-2 m-4 -mb-1 px-4 pt-2 pb-3 rounded-sm shadow-md z-10 bg-white ring-1 ring-black ring-opacity-5 focus:outline-none"> |
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.
Based on the design spec, this is a dropdown with multiple options; therefore we'd expect the content to be a list of options (<ul>
and <li>
).
tabindex="-1" | ||
> | ||
<div class="flex flex-col gap-y-2 m-4 -mb-1 px-4 pt-2 pb-3 rounded-sm shadow-md z-10 bg-white ring-1 ring-black ring-opacity-5 focus:outline-none"> | ||
<div class="border-b"> |
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.
Semantically, this would need to be a <p>
for the content to make sense. A <div>
has no semantic meaning, but is required in this case.
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.
Based on the changes above the div with the class border-b
is now a li
.
{{ stimulus_controller('araise/core-bundle/dropdown', {'alignment': 'top'}) }} | ||
> | ||
|
||
<button |
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.
Nit: I didn't check the dropdown controller, so please quickly verify there is either an aria-expanded
or aria-pressed
or similar marked added by it to ensure, the button meaning is correctly reflected in the accessibility tree.
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.
No, there's nothing set like that. We should integrate this in the dropdown controller absolutely
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.
Added to this issue: araise-dev/CoreBundle#14
ceb1b22
to
c28d806
Compare
@renestalder Can you check the updated version with the macro again? Thanks |
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.
Logout
and Profil bearbeiten
are hard coded strings. Is there an i18n system built in that should be called on those string to make it possible to overwrite them with translations?
class="flex whatwedo-utility-paragraph transition-colors hover:text-neutral-500" | ||
> | ||
{{ bootstrap_icon('box-arrow-right', { class: 'h-3 w-3 self-center mr-2', alt: '' }) }} | ||
{% block logout_text %}Logout{% endblock %} | ||
{{ 'Logout' }} |
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.
Nit: Wrapping into a twig expression is unnecessary here. Instead of {{ 'Logout' }}
, use Logout
.
@@ -1,3 +1,4 @@ | |||
{% macro profile(name, edit_link = null, name_detail = null, picture_src = null) %} |
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.
Nit: As with components in other templating systems, we have to take architecture of a growing “component” system into consideration. I don't think there is a good, official styleguide. But here is something that I learned:
- Separating configuration options from data.
- Having a first parameter to be data, a second one to be configuration.
- Having an easy way to extend data, therefore passing it as an object.
As macros grow, having all properties as individual parameters will not be effortless to maintain, as you will have several breaking changes to introduce along the way.
Based on this, the recommendation I would have for upcoming macros is, passing the data in a first parameter as an object, e.g. {{ profile({ name: name, edit_link: edit_link, picture_src: picture_src}) }}
. This allows to update the data object parameters without changing the macro signature.
Second, if you have settings later like additional HTML Attributes, themes etc., this signature could look like this:
{% macro profile(data, opts) %} ....
{{ profile({
name: name,
edit_link: edit_link,
picture_src: picture_src
}, {
variant: 'compact',
attr: {
class: 'example'
}
) }}
I also often look at the form macros of Symfony for inspiration.
https://symfony.com/doc/current/form/form_customization.html
Just some ideas to consider. Not a hard rule.
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.
Good thinking. I changed the params to an object.
One thing which we can't do anymore is setting a default value and forcing an input. Do you know a solution to these issues? The name and link need to be set.
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 set defaults like this, inside the macro:
{% set name = data.name|default('my-default') %}
Or if you want to mirror it into the incoming data object, you can do it as follows. This won't work 1:1 with nested data due to it now being shallow/deep merge. If you pass data that has nested objects, you need to manually use the merge-filter on the nested properties.
{% set default_data = {
name: 'my-name'
} %}
{% set data = default_data|merge(data) %}
I recommend not to use merge on data inputs (only options/properties) and rather use the first approach. If data
can be a PHP class instead of a raw array (which is possible), the merge-filter will throw an error. So if you assume the developers will pass PHP classes as data, do not try to use the merge filter directly on the data object.
@marcwieland95 Added a couple of nitpicking comments and a question about the hard-coded strings. But otherwise lgtm. |
araise/araise-meta#56
…d easier to handle #27
d5ba6ce
to
ad2e1c5
Compare
Frontend code for new "dropup" -> profile sidebar
araise/araise-meta#56