Teradata Covalent

repository·main·Indexed 24 days ago

https://github.com/teradata/covalent

Teradata's design system providing a library of web components and Angular support to create consistent, branded user experiences. Version 11.20.1 includes specialized modules such as @covalent/code-editor for Monaco Editor integration, @covalent/dynamic-forms for configuration-driven form generation, and @covalent/echarts for declarative ECharts visualizations including bar series, axes, and dataset management.

Tokens
58.7K
Snippets
179
Records
255
Agent score
80%

What's inside Covalent

  1. Overview of the Covalent UI Platform

    main
    Covalent is a UI Platform designed to solve common enterprise needs. It follows the Material Design specification and is designed to work alongside Angular Material to provide a unified user experience. The platform is distributed as a collection of specialized npm packages.
  2. Structure a side sheet with directives and components

    main

    When defining the template for your side sheet, use the following directives and components to apply standard Covalent styling and behavior:

    • td-sidesheet-title: Adds title styling to an element (optional).
    • td-side-sheet-close: An attribute directive that closes the side sheet when the element is clicked or interacted with (e.g., via Enter key).
    • td-side-sheet-content: A component that provides a container for content with Material-spec margins and automatic scrolling if the content exceeds the viewport.
    • td-sidesheet-actions: A component that creates a sticky footer for holding multiple action buttons (optional).
    <span td-sidesheet-title>
      Side Sheet Title
      <button mat-icon-button td-side-sheet-close>close</button>
    </span>
    
    <td-side-sheet-content> Sidesheet Content </td-side-sheet-content>
    
    <td-sidesheet-actions>
      <button mat-icon-button td-side-sheet-close>close</button>
      <button mat-icon-button td-side-sheet-close>save</button>
    </td-sidesheet-actions>
  3. Define menu structure with IMenuItem

    main

    The IMenuItem interface allows you to create n-level deep cascading menus. Items fall into one of four roles based on their properties:

    1. Submenu trigger: Includes a children property (an array of IMenuItem).
    2. URL link: Includes a link property (a relative or fully qualified URL). Use newTab: boolean to control if it opens in a new browser tab.
    3. Action link: Includes an action property. Clicking this item emits the itemClicked event.
    4. Grouping label: Includes neither children, link, nor action properties.

    Common Properties

    • id: Optional identifier.
    • text: Display text.
    • icon: Optional icon name.
    • svgIcon: Optional SVG icon path.
    • iconClasses: Optional array of styling classes.
  4. Handle Props and Events in Covalent React

    main

    The React wrapper simplifies interaction with the underlying web components:

    • Props: Pass props naturally. The wrapper automatically distinguishes between attributes (strings) and properties (objects, arrays, etc.) and sets them correctly on the web component.
    • Events: Use standard React on-prefixed event handlers (e.g., onClick, onRowClick). The wrapper maps native DOM events from the web component to these React handlers.
    • Type Safety: Components come with auto-generated TypeScript types for both props and events.
    import { cvDataTable } from '@covalent/components-react';
    
    function TableDemo() {
      const columns = [{ label: 'Name', key: 'name' }];
      const data = [{ name: 'Item 1' }, { name: 'Item 2' }];
    
      return (
        <cvDataTable
          columns={columns}
          data={data}
          onRowClick={(event) => console.log('Row clicked:', event.detail)}
        />
      );
    }
  5. How Utility Classes vs Classless/Semantic modes work

    main

    Covalent Foundations offers two distinct ways to apply styles:

    1. Utility Classes (covalent.css): You apply explicit classes (e.g., cv-headline-1) to elements. Use this when you need different styles for the same element type on a single page.
    2. Classless/Semantic (elements.css): Standard HTML elements (like <h1>, <p>, <ul>) are automatically styled. Use this for Markdown content, blogs, or documentation sites where you want zero configuration.
  6. Compare Core Web Components vs. React Wrapper

    main

    Using @covalent/components-react is preferred over using the raw @covalent/components web components directly in React because it eliminates boilerplate and provides a native React developer experience.

    TaskWith Core Web Components (No Wrapper)With React Wrapper
    Passing DataManually distinguish between attributes (strings) and properties (objects).Pass props naturally; the wrapper handles conversion.
    Event HandlingUse ref to add event listeners.Use React-style onEvent props.
    Type SupportNo built-in TypeScript types.Full TypeScript support.
    Code ReadabilityMore boilerplate.Clean, declarative JSX.
  7. Configure tour step attachment and advancement

    main

    When defining IGuidedTourStep, you can control how steps are attached to elements and how users advance through them using attachToOptions and advanceOnOptions.

    attachToOptions

    Used to anchor the tour step to a specific DOM element.

    • highlight: boolean
    • retries: number (attempts to find element)
    • skipIfNotFound: boolean
    • else: string (step ID to go to if element not found)
    • goBackTo: string (step ID for the back button)
    • skipFromStepCount: boolean

    advanceOnOptions

    Used to define triggers for moving to the next step.

    • jumpTo: string (next button will jump to this step ID)
    • allowGoBack: boolean

    advanceOn

    An array of ITourEventOn objects defining which events (e.g., 'click', 'keyup', 'added') trigger advancement.

  8. Best practices for using Dialogs

    main

    When implementing Dialogs in your application, follow these UX guidelines:

    • Use sparingly: Only use a dialog when the user must make a decision immediately.
    • Prefer 'Undo' over 'Confirm': It is better to perform an action immediately and provide an "undo" option rather than interrupting the user with an "Are you sure?" dialog.
    • Use Snackbars for notifications: For less intrusive user notifications, use the snackbar component instead of a dialog.
  9. Covalent Package Ecosystem

    main

    Covalent is modular. Depending on your requirements, you can install specific packages from the following ecosystem:

    • @covalent/core: The foundation, containing 20+ UI components including layouts, data tables, wizard steppers, custom pipes, services, and utility functions.
    • @covalent/echarts: Atomic components for data visualization, supporting 9+ chart types (e.g., bar, scatter, treemap).
    • @covalent/highlight: Provides syntax highlighting for multiple programming languages.
    • @covalent/markdown-parser: Parses GitHub flavored markdown.
    • @covalent/flavored-markdown: Converts markdown into Material Design components.
    • @covalent/markdown-navigator: Tools for navigating markdown sources, including a draggable window for inline documentation.
    • @covalent/dynamic-forms: Enables building forms dynamically from a JavaScript object.
    • @covalent/code-editor: A multi-language code editor component.
    • @covalent/text-editor: A simple markdown text editor component.
  10. Anatomy of a List Item

    main

    A cv-list-item within a cv-list can be composed of several elements to provide context and information:

    • Text Lines: Supports 1, 2, or 3 lines of text. Use the twoline attribute to enable a secondary line.
    • Leading Graphic: An icon or avatar image placed at the start of the item using the graphic attribute (e.g., graphic="avatar") and the slot="graphic" on a cv-icon.
    • Trailing Meta: An icon or metadata placed at the end of the item using the slot="meta" on a cv-icon.
    • Secondary Text: Additional text content placed in the slot="secondary".
    <cv-list>
      <cv-list-item graphic="avatar" hasMeta twoline>
        <span>Two-line list item</span>
        <span slot="secondary">Secondary line</span>
        <cv-icon slot="graphic">folder</cv-icon>
        <cv-icon slot="meta">help</cv-icon>
      </cv-list-item>
    </cv-list>
  11. Compare Utility Classes vs Classless/Semantic styles

    main

    Covalent offers two distinct styling approaches. You can use them independently or combine them.

    Utility Classes (covalent.css)

    • Setup: Requires adding specific classes to your HTML elements.
    • Control: Provides full control over every element.
    • Best For: Complex applications and UIs.
    • Markdown: Requires post-processing to apply classes.

    Classless/Semantic (elements.css)

    • Setup: Zero configuration; just import the CSS.
    • Control: Styles are applied to tag types (e.g., <h1>, <p>), offering less granular control.
    • Best For: Documentation, blogs, and rapid prototyping.
    • Markdown: Works directly with standard Markdown output.

    Combining Both

    For the best results, import elements.css for base styling and use covalent.css utility classes to override specific elements.

    <link rel="stylesheet" href="themes/light.css" />
    <link rel="stylesheet" href="elements.css" />
    <!-- Base styles -->
    <link rel="stylesheet" href="covalent.css" />
    <!-- Override utilities -->
    
    <h1 class="">Normal heading</h1>
    <!-- Uses elements.css -->
    <h1 class="cv-headline-3">Smaller heading</h1>
    <!-- Override with utility -->
  12. Use td-chart-dataset to manage chart data

    main

    The td-chart-dataset element allows you to set the dataset option inside a td-chart. This provides flexibility by separating data management from the series property, enabling data reuse across different series and enabling data encoding. It is the Angular equivalent of creating a JavaScript dataset object in ECharts.

    Note: If you provide data via series.data, it will override the data provided in dataset.source.

    <td-chart [style.height.px]="300">
      <td-chart-x-axis></td-chart-x-axis>
      <td-chart-y-axis [type]="'category'"> </td-chart-y-axis>
      <td-chart-series td-bar></td-chart-series>
      <td-chart-dataset
        [source]="[['product', '2015', '2016', '2017'],
        ['Matcha Latte', 43.3, 85.8, 93.7], ['Milk Tea', 83.1, 73.4, 55.1],
        ['Cheese Cocoa', 86.4, 65.2, 82.5], ['Walnut Brownie', 72.4, 53.9, 39.1]]"
      >
      </td-chart-dataset>
    </td-chart>