Skip to content

pantoken / packages/core/src / toVectorDrawable

Swyddogaeth: toVectorDrawable()

toVectorDrawable(svg, options?): string

Bêta

Trosi SVG mewnol i llinyn XML VectorDrawable Android. Mae eiconau sy'n seiliedig ar stroc (Lucide) yn allyrru strokeColor/strokeWidth; mae eiconau sy'n seiliedig ar lenwi (Custom) yn allyrru fillColor.

Paramedrau

svg

string

Marciad SVG mewnlínol.

options?

VectorDrawableOptions = {}

VectorDrawableOptions.

Yn dychwelyd

string

Y XML VectorDrawable.

Enghreifftiau

Mae eicon sy'n seiliedig ar stroc (Lucide) yn allyrru strokeColor

ts
import { toVectorDrawable } from "@pantoken/core";

const xml = toVectorDrawable(
  '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">' +
    '<path d="M5 12h14"/></svg>',
);
// → <vector …> with android:strokeColor and android:pathData="M5 12h14"

Mae eicon sy'n seiliedig ar lenwi (Custom) gyda lliw tîn yn allyrru fillColor

ts
import { toVectorDrawable } from "@pantoken/core";

toVectorDrawable('<svg viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>', {
  color: "#FF0374B5",
});
// → <vector …> with android:fillColor="#FF0374B5"