microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
iadavis/pipeline-issue-debugging

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/npm/qsharp/ux/atoms/utils.ts

32lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// **** Helper functions for rendering SVG elements ****
5
6type StringMap = Record<string, string>;
7
8export function createSvgElements(...tags: string[]): SVGElement[] {
9 return tags.map((tag) =>
10 document.createElementNS("http://www.w3.org/2000/svg", tag),
11 );
12}
13
14export function setAttributes(el: SVGElement, attrs: StringMap) {
15 for (const key in attrs) el.setAttribute(key, attrs[key]);
16}
17
18export function appendChildren(parent: Element, children: Element[]) {
19 children.forEach((child) => parent.appendChild(child));
20}
21
22export function addChildWithClass(
23 parent: HTMLElement,
24 childTag: string,
25 className: string,
26): HTMLElement {
27 const parentDoc = parent.ownerDocument;
28 const child = parentDoc.createElement(childTag);
29 child.classList.add(className);
30 parent.appendChild(child);
31 return child;
32}
33