Skip to content

pantoken / packages/core/src / toVectorDrawable

Mahi: toVectorDrawable()

toVectorDrawable(svg, options?): string

Beta

Hurihia he SVG whakauru ki te aho XML VectorDrawable mō Android. Ko ngā tohu ā-tau (stroke-based) (Lucide) ka whakaputa strokeColor/strokeWidth; ko ngā tohu ā-kakī (fill-based) (Custom) ka whakaputa fillColor.

Ngā Tawhā

svg

string

Hōputu SVG ā-roto.

options?

VectorDrawableOptions = {}

VectorDrawableOptions.

Whakahokia

string

Te XML VectorDrawable.

Ngā tauira

He tohu ā-tau (Lucide) e whakaputa ana i te 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"

He tohu ā-kakī (Custom) me te tae whakakikorua e whakaputa ana i te 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"