Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

Friday, May 6, 2016

Toast and Growl Notifications with Oracle JET

My colleague Paul Thaden just posted Creating a Popup Message Box for Oracle JET Forms which uses Oracle JET's Offcanvas functionality. While not exactly "toast," that was my first thought when I saw it. I really like the toast/growl notification concept and have been wondering how to add this type of notification to an Oracle JET project. Let's take Paul's work and convert it into a growl-like (or toast) notification complete with timeout. We will start with this modified version of Paul's jsFiddle. This fiddle displays a notification message when you change the selected browser.

Paul already explained the whole inner-wrapper/outer-wrapper thing so I won't repeat it here. Mainly I want to focus on styling the oj-offcanvas-top element (named toast) so that it floats on the right side of the page and then disappears after a specified period of time. Here is the only CSS we need:

#toast {
  /* Make the message look pretty */
  border: 1px solid #0572ce;
  box-shadow: 0 1px 3px #777;
 
  /* set the location of the toast message */
  left: auto;
  right: 10px;
  width: 200px;

  /* z-index required to overlay oj form controls */
  z-index: 1;
}

Next we refactor the ojSelect optionChange event handler from the prior jsFiddle to close the notification message after a specified interval:

var closeToast = function() {
  return oj.OffcanvasUtils.close(toastOptions);
};

self.browserChangedHandler = function (event, data) {
  if (data.option == "value") {
    oj.OffcanvasUtils.open(toastOptions);
    window.setTimeout(closeToast, 5*1000);
  }
};

Here is the jsFiddle example. Select a browser and watch the message appear and then disappear.

That is nice for a "Transaction saved" type of message, but let's get dramatic and make this look like a real growl notification. With a little bit of CSS, we can turn that Offcanvas notification into something like this:

And here is the jsFiddle:

Thursday, April 28, 2016

Animate Oracle JET Utility Classes (oj-selected)

Sometimes I build card-like user interfaces that allow users to select from a group of "cards." The visual state of a selected "card" should change once selected. The Oracle JET oj-panel, oj-margin, and oj-selected utility classes are great for this type of experience. The oj-panel and oj-margin classes setup the cards according to the Alta UI design patterns and oj-selected changes the appearance upon selection. Toggling oj-selected with a click binding is trivial with jQuery.toggleClass().

Out of the box, the oj-selected visual changes are either on or off. There are no transition states. I like user interface changes to morph between states. With just a couple of lines of CSS, we can animate what happens to an oj-panel when oj-selected is added to the panel:

.oj-panel {
  cursor: pointer;
  transition: border-color .3s ease-in-out;
}

Here is the jsFiddle

Is the fade effect too subtle for you? Take a look at this CodePen for some impressive animation examples.

Wednesday, April 27, 2016

Oracle JET Utility Classes for Bootstrap Designers

I came to Oracle JET from a Bootstrap background. By looking through the examples and cookbook, it was easy to see Oracle JET's routing, data bound components, and layout features, but I missed Bootstrap's utility classes such as pull-right and text-right (Note: you can use Bootstrap and Alta together, but that is another story). I even began creating my own utility classes. Then, while reading a recipe in the cookbook, I stumbled across oj-helper-text-align-right. I thought to myself, "No kidding... Oracle JET has utility classes." In fact, the cookbook is littered with utility class references. For example, the Panel Selected recipe introduces oj-panel, oj-selected, and oj-margin. What is the significance of these classes? Just as Bootstrap helps developers adopt a common, modern look and feel based on the Bootstrap design guidelines, Oracle JET's utility classes ensure that we adhere to the Oracle Alta design patterns. We no longer have to ask, "How much margin should we place between infolets in a dashboard?" Instead, we can add the oj-margin class and know that we are adhering to the Oracle Alta design guidelines.

Oracle published a great Oracle JET CSS class reference so I won't repeat all of the utility classes here. But don't stop with that reference. Dig into the Sassy CSS (scss) where you will find even more gems such as oj-helper-hidden (a great class to mix with $(...).toggleClass). "Help! I looked I looked in the scss subfolder and there are TONS of files in there. Where do I start?" I suggest starting with _oj.common.utilities.scss and _oj.common.helpers.scss.

Helper classes such as .oj-helper-text-align-left and .oj-helper-text-align-right are great, but what about RTL? Here is where things get really cool: Oracle JET was designed for an international audience. Oracle JET alignment, padding, and margin classes include *-start and *-end complements that align, pad, and space elements properly for RTL languages.