Exercise: Make your login dialog responsive
A possible solution is at the end of this page.
In the prior lesson, you wrote a login dialog. Make this one responsive with what you know about CSS responsive design. How do you want it on a phone? Full Screen? On a tablet or desktop? In the centered middle on a wallpaper background?
Hint: depending on what you want to do you will need a BBjChildWindow, or even a nested series of them The BBjChildWindow also has the same flag $00100000$ we saw for the BBjTopLevelWindow that allows you use the CSS-based positioning and sizing. We will use BBjChildWindows later in this course, but with what you know about BBj and the Documentation you should already be able to figure it out. It has setDockStyle / setStyle / setPanelStyle to directly set style attributes for the outer / mid / inner div, and addStyle and addPanelStyle to set CSS classes to the middle and the inner div. ( Yes, yes. We know about this inconsistency which is on the roadmap for cleanup. ;-) )
Possible solution
The original course had no solution for this exercise, so this one was written for this book. It starts from the login dialog solution LoginDialog.bbj and is a complete program of its own. From 600px up the dialog is a centered card of fixed width on a tinted background, and below 600px it fills the screen. The controls sit in a BBjChildWindow with the CSS layout flag, and the program reads responsive-login.css and injects it with injectStyle, so you do not need to register the file in Enterprise Manager. The files are ResponsiveLoginDialog.bbj and responsive-login.css, and you find them in the exercises.zip link.
/* The screen behind the dialog: the card sits in the middle of a colored background. */
.login-screen {
display: grid;
place-items: center;
min-height: 100vh;
box-sizing: border-box;
padding: var(--dwc-space-l);
background: var(--dwc-color-primary-95);
}
/* The dialog itself: a card with a fixed width. */
.login-card {
display: grid;
gap: var(--dwc-space-m);
width: 22rem;
padding: var(--dwc-space-xl);
border-radius: var(--dwc-border-radius);
background: var(--dwc-surface-3);
box-shadow: var(--dwc-shadow-m);
}
/* From 600px up the dialog is a centered card. Below 600px it fills the screen. */
@media (width < 600px) {
.login-screen {
padding: 0;
place-items: stretch;
background: var(--dwc-surface-3);
}
.login-card {
width: auto;
min-height: 100vh;
border-radius: 0;
box-shadow: none;
}
}