Skip to main content

DWC Controls With Extended Attributes

This chapter covers BBj controls implemented as web components for the Dynamic Web Client and their extended attributes.

Overview​

In creating DWC controls, BASIS has added new functionality and configuration parameters based on today's web standards and customer requests. Many of these features are available as attributes listed in the DWC-specific documentation.

Concepts Covered in This Chapter​

  • Component themes for controls
  • Attributes
  • The BBjTree's built-in search
  • Input control labels

Component Themes​

Many controls offer a "theme" attribute that can be set to one of the DWC's component themes:

ThemePurposeDefault Color
primaryMain color, typically brand-basedBlue
defaultGray variations tinted with primary colorLight gray with blue tint
infoInformation to end-user, complementary to primaryPurple
successDenoting successful operationsGreen
warningPresenting warningsYellow
dangerPresenting problemsRed
grayDesaturated graysGray

Color Properties​

Theme colors are defined by CSS custom properties with three main properties:

  • Hue - Degree on color wheel (0-360). Example: --dwc-color-primary-h: 211; (blue)
  • Saturation - Percentage (0-100%). Example: --dwc-color-primary-s: 100%; (bright)
  • Contrast threshold - When text should flip from white to black. Example: --dwc-color-primary-c: 50%;

Colors range from 5% to 95% lightness: --dwc-color-primary-25 (dark) to --dwc-color-primary-85 (light).

DWC Themer showing color themes

Color CSS properties

In effect, the DWC Themer only rewrites the underlying values of these CSS custom properties. When you pick a primary color with a BBjColorChooser, the DWC Themer takes the hue and saturation of the chosen color and uses them as the values of --dwc-color-primary-h and --dwc-color-primary-s. Some colors need a different contrast threshold. For example, --dwc-color-warning-c is set to 35 so that text on the yellow warning color stays legible.

Setting the Theme Attribute​

Most controls offer the theme attribute as an easy way to set the control's appearance. Two samples from the first chapter use it.

In MessageBox.bbj, the message box's theme is set to primary:

A message box using the primary theme

In DWC1.bbj, the [Say Hello] button's theme is set to success:

The Hello window with a green button using the success theme

Attributes​

DWC controls offer attributes providing extra functionality beyond GUI and BUI clients.

Common Attributes​

  • theme - Sets the control's color theme
  • expanse - Shortcut for affecting font size and padding (controls overall size)

BBjTree Search Attributes​

AttributeDescription
search-inputShows edit box above tree for client-side filtering
search-case-sensitiveMakes search case-sensitive
search-nodataCustom message when no search results
search-placeholderPlaceholder text for search box
search-termFilter tree contents programmatically (supports regex)

Example 1 - Setting Attributes on BBjTree​

  1. Run DWCTraining/04_ExtendedAttributes/TreeSearch.bbj
  2. Toggle checkboxes to enable/disable named attributes
  3. Search in individual trees and via global search
  4. Note custom error messages via search-nodata attribute
  5. As time permits, read the source code and look at all the attributes it sets, including search-input, search-placeholder, search-nodata, icon-collapsed and icon-expanded. The code also injects custom CSS that sets the --dwc-tree-icon-fill custom property to a different value for each tree. The first tree paints its icons orange and the second paints them blue.

Tree Search Demo

Input Control Labels​

BBj input controls offer a "label" attribute that creates and places a label automatically.

Benefits of Attribute Labels​

  1. Reduced developer work - No need to create, size, and place separate text controls
  2. Validation integration - Labels change color to denote valid/invalid states
  3. Accessibility - Narrators recognize the label as associated with the control
  4. Responsive layouts - Easier to design since labels are part of the control

With attribute label:

EditBox with attribute label

Without attribute label (separate BBjStaticText):

EditBox without attribute label

Example 2 - Comparing Label Types​

  1. Run DWCTraining/04_ExtendedAttributes/LabelAttributes.bbj
  2. Choose "yes" for attribute labels, then run again and choose "no"
  3. Resize the window - notice how attribute labels stay with their inputs

Why Attribute Labels Work Better​

With attribute labels: Labels are part of the control in the DOM, staying attached during resize.

With BBjStaticText: Labels are separate elements that can separate from inputs when resizing.

Label Attributes Demo

Discrete Labels Comparison