VSCode Elements

repository·main·Indexed 19 days ago

https://github.com/vscode-elements/elements

A library of Lit-based web components designed to provide UI elements that match the Visual Studio Code experience. It is intended for developers building extensions or webviews that require VSCode-like aesthetics and behavior, offering components for buttons, form inputs, layout containers, data display, and navigation.

Tokens
16.3K
Snippets
67
Records
93
Agent score
66%

What's inside @vscode-elements/elements

  1. Run tests and check coverage

    main

    VSCode Elements includes a testing suite written in TypeScript.

    • npm run test: Compiles test files and runs them.
    • npm run test:coverage: Runs tests and generates code coverage.
    • npm run test:watch: Watches for file changes and runs tests automatically when modifications are detected.
    npm run test
  2. Run development server and watch mode

    main

    For active development, use the start command. This starts the development server and the TypeScript compiler in watch mode, then automatically opens your default browser.

    Alternatively, you can use npm run serve to start the Web Test Runner development server, or npm run wtr:watch to start the web-test-runner in watch mode without rebuilding files (useful for running in a separate terminal to catch errors quickly).

    npm run start
  3. Use a local copy of VSCode Elements via npm link

    main

    If you want to use a local copy of the VSCode Elements library in your own codebase for development, you can use npm link.

    Prerequisites:

    • Ensure you have NodeJS 22 or newer installed.
    • Run the build script in the VSCode Elements directory before linking.

    Steps:

    1. Navigate to the VSCode Elements directory and run npm link.
    2. Navigate to your target project directory and run npm link @vscode-elements/elements.

    Note: If you are working with multiple packages, you must link them in a single command:

    npm link @vscode-elements/elements @vscode-elements/webview-playground
    npm link
    # In your project directory:
    npm link @vscode-elements/elements
  4. Build VSCode Elements

    main

    Use the build scripts to generate the necessary files for the package.

    • npm run build: Generates everything included in the package, including transpiled JavaScript (with type definitions and source maps), the custom elements manifest file, VSCode custom data files, and a single minified JavaScript bundle.
    • npm run built:ts: Transpiles TypeScript files into standard ES6 JavaScript without minification. Use this if you want to import files into an end-user application for further optimization.
    • npm run build:watch: Runs the TypeScript compiler in watch mode, automatically recompiling modified files.
    npm run build
  5. Use development templates for VSCode Elements

    main

    When developing your elements, you can use the following HTML templates as starting points. Each template provides a different environment configuration:

    • _template.html: The default template. It includes access to all VSCode theme variables, codicons, and components.
    • _template-csp.html: A template with strict Content Security Policy (CSP) settings. It still provides access to all VSCode theme variables, codicons, and components.
    • _template-fallback-styles.html: A template used for demoing default styles. It provides access to codicons and all components, but does not include VSCode theme variables.
  6. Run the development server for VSCode Elements

    main
    To develop your elements with live updates without needing to run a full bundle process, use the npm run start command. This directory contains HTML files that serve as the development environment for your elements.
    npm run start
  7. Use the vscode-textarea component

    main

    The vscode-textarea component is a multi-line text input designed to mimic the VSCode editor experience. It supports form participation, validation, and can be styled to match VSCode themes.

    Key Features

    • Form Integration: Implements AssociatedFormControl, allowing it to participate in native HTML forms and support :invalid pseudo-classes.
    • Monospace Mode: Enabling the monospace property applies font settings (family, weight, size, and color) consistent with the VSCode code editor.
    • Validation: Supports standard HTML validation attributes like required, minlength, and maxlength.
    • Events: Fires input and change events when the text content is modified.
    <vscode-textarea 
      label="Description"
      placeholder="Enter text here..."
      rows="4"
      monospace
    ></vscode-textarea>
  8. Use VSCode Elements components

    main

    The @vscode-elements/elements package provides a collection of Web Components designed to mimic the VS Code user interface. You can import these components to build web applications that look and feel like VS Code extensions or parts of the editor itself.

    Available components include:

    • Buttons & Actions: VscodeButton, VscodeButtonGroup, VscodeToolbarButton, VscodeToolbarContainer
    • Form Inputs: VscodeCheckbox, VscodeCheckboxGroup, VscodeMultiSelect, VscodeOption, VscodeRadio, VscodeRadioGroup, VscodeSingleSelect, VscodeTextarea, VscodeTextfield
    • Layout & Containers: VscodeCollapsible, VscodeDivider, VscodeFormContainer, VscodeFormGroup, VscodeFormHelper, VscodeScrollable, VscodeSplitLayout, VscodeTabs, VscodeTabHeader, VscodeTabPanel
    • Data Display: VscodeBadge, VscodeIcon, VscodeLabel, VscodeProgressBar, VscodeProgressRing, VscodeTable, VscodeTableBody, VscodeTableRow, VscodeTableCell, VscodeTableHeader, VscodeTableHeaderCell
    • Navigation & Menus: VscodeContextMenu, VscodeContextMenuItem, VscodeTree, VscodeTreeItem
    • Others: VscodeToolbarContainer
  9. Use the vscode-split-layout component

    main

    The vscode-split-layout component provides a resizable divider (sash) to split a container into two panes: a start pane and an end pane. It supports both vertical and horizontal orientations and allows for minimum size constraints on the panes.

    Usage Pattern

    Place your content into the named slots start and end:

    <vscode-split-layout split="vertical" min-start="100px">
      <div slot="start">Left Pane Content</div>
      <div slot="end">Right Pane Content</div>
    </vscode-split-layout>
    <vscode-split-layout split="vertical">
      <div slot="start">Start Content</div>
      <div slot="end">End Content</div>
    </vscode-split-layout>
  10. Use the vscode-table component

    main

    The vscode-table component is a highly configurable table element designed to mimic the VS Code table experience. It supports column resizing, responsive layouts, and various styling options like zebra stripes and borders.

    To use it, you must provide content via slots:

    • header slot: For vscode-table-header elements.
    • body slot: For vscode-table-body elements.
    • caption slot: For optional table captions.

    If you do not specify slots, the component will attempt to assign vscode-table-header and vscode-table-body elements from the default slot to their respective named slots automatically.

    <vscode-table 
      resizable 
      bordered 
      zebra 
      .columns='["100px", "auto", "50%"]'>
      <div slot="header">
        <vscode-table-header>
          <vscode-table-header-cell>Name</vscode-table-header-cell>
          <vscode-table-header-cell>Status</vscode-table-header-cell>
        </vscode-table-header>
      </div>
      <div slot="body">
        <vscode-table-body>
          <vscode-table-row>
            <vscode-table-cell>Item 1</vscode-table-cell>
            <vscode-table-cell>Active</vscode-table-cell>
          </vscode-table-row>
        </vscode-table-body>
      </div>
    </vscode-table>