@samatawy/diagrams
    Preparing search index...

    Class WidthSelect

    A dropdown component for selecting line widths. It displays a list of predefined widths and allows the user to select one. The selected width is reflected in the trigger button and can be accessed via the value property. The component emits a 'widthchange' event when the selected width changes.

    Index

    Constructors

    Properties

    host: HTMLElement
    config: Required<Omit<WidthSelectConfig, "widths">> & { widths: number[] }
    selected: number
    trigger: HTMLButtonElement
    triggerSwatch: HTMLDivElement
    triggerLabel?: HTMLSpanElement
    menu: HTMLDivElement

    Accessors

    Methods

    • Sets the available width options and optionally selects a width.

      Parameters

      • widths: number[]

        An array of widths.

      • OptionalselectedWidth: number

        The width to select. Defaults to the first width in the array.

      Returns void

    • Handles the click event on the document. Closes the dropdown menu if the click is outside the host element.

      Parameters

      • event: Event

        The click event.

      Returns void

    • Handles the click event on an option. Selects the clicked width and closes the dropdown menu.

      Parameters

      • event: Event

        The click event.

      Returns void

    • Replaces the current option list with a new set of widths.

      Parameters

      • widths: number[]

        The pixel-width values to render.

      Returns void

    • Builds a single option button containing an SVG stroke-width preview.

      Parameters

      • width: number

        The pixel width value for this option.

      Returns HTMLButtonElement

      The constructed option button element.

    • Creates an SVG element visualising a horizontal line at the given stroke width.

      Parameters

      • width: number

        The stroke width in pixels.

      Returns SVGElement

      The SVG element.

    • Updates the internal selection state, syncs the trigger and option list, and optionally emits 'widthchange'.

      Parameters

      • width: number

        The new width value to select.

      • emit: boolean = true

        Whether to dispatch the change event. Defaults to true.

      Returns void