Calcite Design System

repository·dev·Indexed 18 days ago

https://github.com/esri/calcite-design-system

A comprehensive set of UI components, design tokens, and icons for creating consistent, high-quality user interfaces, primarily for ArcGIS-related applications. It provides web components compatible with Angular, React (including @esri/calcite-components-react for versions 18 and below), Preact, and various build tools like Vite and Rollup.

Tokens
53.9K
Snippets
152
Records
293
Agent score
60%

What's inside calcite-design-system

  1. Overview of Calcite Components Sass structure

    dev

    The Calcite Components styling system is built using Sass and organized into several functional directories to support modularity and LitElement-based component styling:

    • global/: Contains styles and variables used to generate the project's global styles during the build process.
    • includes/: Contains utilities and mixins designed to be imported into individual components for local use.
    • component/: Contains styles specifically intended to be used as LitElement static styles within custom components.
    • modules/: Contains helper utilities and shared style modules that can be imported across the codebase as needed.
  2. Overview of Calcite Design System packages

    dev

    The Calcite Design System is distributed as a monorepo containing several specialized packages. Depending on your needs, you should use the specific package designed for your environment:

    • Web Components: Use @esri/calcite-components for standard web component usage.
    • React: Use @esri/calcite-components-react for optimized React integration.
    • Design Tokens: Use @esri/calcite-design-tokens to access the design system's visual constants.
    • Icons: Use @esri/calcite-ui-icons for the Calcite icon set.
    • Linting: Use @esri/eslint-plugin-calcite-components to enforce best practices when using Calcite components in your ESLint configuration.
  3. Overview of Calcite components

    dev
    Calcite components are a library of flexible, framework-agnostic web components built with Lit. They are designed for building applications within the Esri Calcite Design System. Components support properties, slots, styles, and theming. Because they are web components, they can be used in various environments including vanilla HTML, React, Vue, Angular, and more.
  4. Track color picker input values during dragging

    dev

    In version 1.0.0-beta.61, the behavior of the color-picker component changed. The calciteColorPickerChange event is no longer emitted while the color field or hue slider thumb is being dragged; it only fires upon release.

    To track color values in real-time as a user drags the thumb, use the calciteColorPickerInput event instead.

    // Use this for real-time updates during drag
    element.addEventListener('calciteColorPickerInput', (event) => {
      // handle input
    });
    
    // Use this for updates only when the user releases the thumb
    element.addEventListener('calciteColorPickerChange', (event) => {
      // handle change
    });
  5. Understand icon sizes and variants

    dev

    Calcite UI icons are provided in three standard sizes to optimize scaling behavior:

    • 16x16
    • 24x24
    • 32x32

    Variants:

    • Outline (Standard): The default style. The filename/name is the base name (e.g., trash-16.svg).
    • Filled: An alternative state for certain icons. Append -f to the name (e.g., information-16-f.svg).
  6. Use Calcite component events in React 18 and below

    dev

    In React 18 and earlier, the synthetic event system does not support custom events emitted by web components.

    Option 1: Using @esri/calcite-components-react (Recommended) The React wrappers bridge these events for you, allowing you to use them as standard props (e.g., onCalciteSliderUpdate).

    Option 2: Using Web Components directly If you use the raw web components instead of the wrappers, you must manually manage a ref and add an event listener inside a useEffect hook.

    // Using the React wrapper (Recommended)
    const [sliderValue, setSliderValue] = useState(50);
    <CalciteSlider onCalciteSliderUpdate={(e) => setSliderValue(e.target.value)} />
    
    // Using raw web components (Manual approach)
    const sliderEl = useRef(null);
    const [sliderValue, setSliderValue] = useState(50);
    
    function onUpdate(event) {
      setSliderValue(event.target.value);
    }
    
    useEffect(() => {
      sliderEl.current.addEventListener("calciteSliderUpdate", onUpdate);
    }, [sliderEl]);
  7. Understanding slots in Calcite Components

    dev

    Calcite Components use Web Component slots to allow you to pass content into specific parts of a component.

    • Default Slots: Content placed inside a component without a slot attribute is typically placed in the component's default slot.
    • Named Slots: Used to position specific elements in designated areas of a component. You assign an element to a named slot using the slot attribute.

    Example of using a named slot to provide a trigger for a dropdown:

    <calcite-dropdown>
      <calcite-button slot="trigger">Open Dropdown</calcite-button>
      <calcite-dropdown-item active>Date modified</calcite-dropdown-item>
      <calcite-dropdown-item>Title</calcite-dropdown-item>
    </calcite-dropdown>

    In this example, the calcite-button is assigned to the trigger slot, while the calcite-dropdown-item elements occupy the default slot.

  8. Implement the menu role

    dev

    The menu role provides a list of choices, typically common actions or functions. It is appropriate when items are presented similarly to a desktop application menu. Elements within a menu have an implicit aria-orientation of vertical.

    Note: Authors should manage the focus of descendants for all instances of this role.

    Keyboard Functionality

    KeyFunction
    space / enterActivates the menu item (equivalent to activating the underlying link element).
    EscCloses the menu and sets focus back to the menu.
    Moves focus to the previous menu item. If on the first item, moves to the last.
    Moves focus to the next menu item. If on the last item, moves to the first.
    HomeMoves focus to the first menu item.
    EndMoves focus to the last menu item.
    A-Z / a-zMoves focus to the next menu item starting with the typed character (if it exists).
    <!-- Menu role example -->
    <div class="dropdown">
      <button type="button" id="dropdown-menu">
        Actions
        <span class="caret"></span>
      </button>
      <!-- Selection mode: Single -->
      <ul role="menu">
        Create
        <li role="menuitemradio" class="dropdown-item">Event</li>
        <li role="menuitemradio" class="dropdown-item" aria-checked="true">Survey</li>
        <li role="menuitemradio" class="dropdown-item">Poll</li>
      </ul>
      <ul class="dropdown-separator" role="separator"></ul>
      <!-- Selection mode: Multi -->
      <ul role="menu">
        Save
        <li role="menuitemcheckbox" class="dropdown-item">Save</li>
        <li role="menuitemcheckbox" class="dropdown-item">Duplicate</li>
      </ul>
    </div>
  9. Implement the treegrid role for expandable data grids

    dev

    The treegrid role identifies a grid where rows can be expanded and collapsed, similar to a tree. This is useful for complex data sets that have hierarchical relationships.

    Implementation Requirements

    • The container element (e.g., <table>) must have role="treegrid".
    • Rows must use role="row".
    • Cells must use role="gridcell".
    • To support hierarchy, rows must use:
      • aria-level: The depth of the row in the hierarchy.
      • aria-posinset: The position of the row within its parent.
      • aria-setsize: The total number of siblings at this level.
      • aria-expanded="true"|"false": To indicate if the row can be expanded/collapsed.

    Note: It is critical that all cells are capable of receiving or containing keyboard focus. Because screen readers often operate in 'application mode' when interacting with grids, they may only announce focusable elements. If content is not focusable, it may be skipped by screen reader users.

    <!-- Treegrid role example -->
    <table id="treegrid" role="treegrid" aria-label="Project hours">
      <colgroup>
        <col id="treegrid-column1" />
        <col id="treegrid-column2" />
      </colgroup>
      <thead>
        <tr>
          <th scope="col">Project Name</th>
          <th scope="col">Hours Done</th>
        </tr>
      </thead>
      <tbody>
        <tr role="row" aria-level="1" aria-posinset="1" aria-setsize="1" aria-expanded="true">
          <td role="gridcell">All Projects</td>
          <td role="gridcell">360</td>
        </tr>
        <tr role="row" aria-level="2" aria-posinset="1" aria-setsize="3" aria-expanded="false">
          <td role="gridcell">Year 2010</td>
          <td role="gridcell">56</td>
        </tr>
        <tr role="row" aria-level="2" aria-posinset="1" aria-setsize="3" aria-expanded="true">
          <td role="gridcell">Year 2011</td>
          <td role="gridcell">188</td>
        </tr>
        <tr role="row" aria-level="3" aria-posinset="1" aria-setsize="3" aria-expanded="false">
          <td role="gridcell">Q1</td>
          <td role="gridcell">30</td>
        </tr>
        <tr role="row" aria-level="3" aria-posinset="1" aria-setsize="3" aria-expanded="true">
          <td role="gridcell">Q2</td>
          <td role="gridcell">95</td>
        </tr>
        <tr role="row" aria-level="4" aria-posinset="1" aria-setsize="1">
          <td role="gridcell">Website Re-brand</td>
          <td role="gridcell">95</td>
        </tr>
      </tbody>
    </table>