Skip to content

Commit

Permalink
[#2036] Added single-page tab script
Browse files Browse the repository at this point in the history
  • Loading branch information
jiromaykin committed Apr 18, 2024
1 parent 04dc704 commit 6e0f006
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1 class="utrecht-heading-1">{% trans 'Registreren' %}</h1>
<a href="{{ digid_url }}" class="link digid-logo">
<img class="digid-logo__image" src="{% static 'accounts/digid_logo.svg' %}" alt="DigiD inlogpagina">
</a>
{% link bold=True href=digid_url text=_('Registreren met DigiD') secondary=True icon='arrow_forward' %}
{% link bold=True href=digid_url text=_('Registreren met DigiD') primary=True icon='arrow_forward' %}
{% endrender_card %}
{% endrender_column %}
{% endif %}
Expand All @@ -22,7 +22,7 @@ <h1 class="utrecht-heading-1">{% trans 'Registreren' %}</h1>
<a href="{{ eherkenning_url }}" class="link eherkenning-logo">
<img class="eherkenning-logo__image" src="{% static 'accounts/eherkenning.png' %}" height=30 alt="eHerkenning inlogpagina">
</a>
{% link bold=True href=eherkenning_url text=_('Registreren met eHerkenning') secondary=True icon='arrow_forward' %}
{% link bold=True href=eherkenning_url text=_('Registreren met eHerkenning') primary=True icon='arrow_forward' %}
{% endrender_card %}
{% endrender_column %}
{% endif %}
Expand Down
8 changes: 4 additions & 4 deletions src/open_inwoner/accounts/templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ <h1 class="utrecht-heading-1">{% trans 'Welkom' %}</h1>
{% endif %}

{% if login_allow_registration %}
{% render_column start=4 span=5 %}
<div class="column column--start-4 column--span-5" id="column__email-toggle">
{% render_card direction='horizontal' tinted=True compact=True %}
<a href="/accounts/login#particuliermail" class="link icon--large">
{% icon icon="login" icon_position="before" outlined=True %}
</a>
{% link href="/accounts/login#particuliermail" text=_('Log in met e-mail adres') primary=True icon='east' extra_classes="link--next link--email" %}
{% endrender_card %}
{% endrender_column %}
</div>

{# Hide mail login initially #}
{% render_column start=4 span=5 %}
<div class="column column--start-4 column--span-5" id="column__login-form">
{% if login_allow_registration %}
{% render_card tinted=True compact=True %}
{% render_form id="login-form" method="POST" form=form show_required=True %}
Expand All @@ -98,7 +98,7 @@ <h1 class="utrecht-heading-1">{% trans 'Welkom' %}</h1>
{% endrender_form %}
{% endrender_card %}
{% endif %}
{% endrender_column %}
</div>
{# End hidden #}

{% render_column start=4 span=5 %}
Expand Down
64 changes: 51 additions & 13 deletions src/open_inwoner/js/components/form/LoginForm.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,51 @@
// bindEvents() {
// this.node.addEventListener('click', (e) => {
// /**
// * Remove focus from search in order to prevent native keyboard on mobile
// */
// const blurFormInput = document.querySelectorAll(
// '#login-form .input'
// )
// blurFormInput.forEach((elem) => {
// elem.blur()
// })
// })
// }
export class LoginFormFocus {
static selector = '#login-form'

constructor(node) {
this.node = node
this.usernameInput = node.querySelector('input[name="username"]')
this.loginFormColumn = document.getElementById('column__login-form')
this.emailToggleParent = document.getElementById('column__email-toggle')

this.removeAutofocusAndFocus()
this.hideLoginFormOnLoad()
this.addEmailToggleListener()
}

removeAutofocusAndFocus() {
if (this.usernameInput) {
this.usernameInput.removeAttribute('autofocus')
this.usernameInput.blur()
}
}

hideLoginFormOnLoad() {
if (this.loginFormColumn) {
this.emailToggleParent.setAttribute('aria-expanded', 'false')
this.loginFormColumn.classList.add('hide')
}
}

addEmailToggleListener() {
if (this.emailToggleParent) {
const emailToggleParents =
this.emailToggleParent.querySelectorAll('.link')
emailToggleParents.forEach((link) => {
link.addEventListener('click', (event) => {
event.preventDefault()
this.toggleLoginFormVisibility()
})
})
}
}

toggleLoginFormVisibility() {
if (this.loginFormColumn) {
this.loginFormColumn.classList.toggle('hide')
this.usernameInput.focus()
}
}
}

const loginformFocuses = document.querySelectorAll(LoginFormFocus.selector)
;[...loginformFocuses].forEach((element) => new LoginFormFocus(element))
28 changes: 13 additions & 15 deletions src/open_inwoner/js/components/tab-panels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ export class TabPanel {
this.showContent()

this.tabHeadersRow.addEventListener('click', (e) => {
const target = e.target
if (target.classList.contains('tab__header')) {
console.log('there is a tabheader')
this.tabHeaders.forEach((item, i) => {
if (target == item) {
this.hideContent()
this.showContent(i)
}
})
e.preventDefault() // Prevent the default action of anchor tag clicks

const target = e.target.closest('.tab__header')
if (target) {
const index = [...this.tabHeaders].indexOf(target)
if (index !== -1) {
this.hideContent()
this.showContent(index)
}
}
})
}

hideContent() {
console.log('Hide tab...')
this.tabContent.forEach((item) => {
item.classList.add('hide')
item.classList.remove('active')
Expand All @@ -35,11 +34,10 @@ export class TabPanel {
})
}

showContent(i = 0) {
console.log('Show tab...')
this.tabContent[i].classList.add('active')
this.tabContent[i].classList.remove('hide')
this.tabHeaders[i].classList.add('active')
showContent(index = 0) {
this.tabContent[index].classList.add('active')
this.tabContent[index].classList.remove('hide')
this.tabHeaders[index].classList.add('active')
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/open_inwoner/scss/components/TabPanel/TabPanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
&:target {
scroll-margin-top: 150px;
}

&:target::before {
scroll-margin-top: 150px;
}
Expand Down Expand Up @@ -99,12 +100,11 @@
}

.active {
display: block;
display: block !important;
}

.hide {
//display: none;
opacity: 0.1;
display: none;
}

.tabs__body {
Expand Down Expand Up @@ -183,6 +183,20 @@
font-size: var(--font-size-body);
}
}

&#particulier {
#column__email-toggle,
#column__login-form {
&.hide {
display: none;
}
}

#column__login-form .button--transparent {
color: var(--color-primary);
padding-left: 0;
}
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/open_inwoner/scss/views/_view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@
color: var(--color-primary);
}
}

&---django_registration_register {
.label__label--required {
color: var(--color-red);
padding-left: var(--spacing-tiny);
//make asterisks invisible by default, only make them visible if component has the caption
display: inline;
}
}
}
25 changes: 15 additions & 10 deletions src/open_inwoner/templates/registration/password_reset_form.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{% extends 'master.html' %}
{% load i18n static form_tags %}
{% load i18n static grid_tags form_tags %}

{% block content %}
<h1 class="h1">{% trans "Reset password" %}</h1>
<p class="p">{% trans "Forgot your password? Enter your email address below. Then you will receive an email with instructions to set a new password." %}</p>
<p class="p">{% trans "Please note: this only works if you do are not using DigiD to log in." %}</p>

{% render_form id="password-reset-form" method="POST" form=form%}
{% csrf_token %}
{% input form.email %}
{% form_actions primary_text=_("Reset password") primary_icon="arrow_forward" %}
{% endrender_form %}

{% render_grid %}
{% render_column start=0 span=6 %}
<h1 class="h1">{% trans "Reset password" %}</h1>
<p class="p">{% trans "Forgot your password? Enter your email address below. Then you will receive an email with instructions to set a new password." %}</p>
<p class="p">{% trans "Please note: this only works if you do are not using DigiD to log in." %}</p>

{% render_form id="password-reset-form" method="POST" form=form %}
{% csrf_token %}
{% input form.email %}
{% form_actions primary_text=_("Reset password") primary_icon="arrow_forward" %}
{% endrender_form %}
{% endrender_column %}
{% endrender_grid %}

{% endblock content %}

0 comments on commit 6e0f006

Please sign in to comment.