Skip to content

Commit bfef3c5

Browse files
update code thread
1 parent c6dd3b8 commit bfef3c5

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

figma-core/event-handlers/create-icon.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { NamedIconConfig } from "@reflect-ui/core";
21
import { EK_CREATE_ICON, EK_ICON_DRAG_AND_DROPPED } from "@core/constant";
32
import { PluginSdkService } from "@plugin-sdk/service";
43
import { IconPlacement, renderSvgIcon } from "../reflect-render/icons.render";
@@ -7,7 +6,12 @@ import { addEventHandler } from "../code-thread";
76
interface CreateIconProps {
87
key: string;
98
svg: string;
10-
config: NamedIconConfig;
9+
config: {
10+
name: string;
11+
size: number;
12+
variant?: string;
13+
package: string;
14+
};
1115
}
1216

1317
function createIcon(

figma-core/reflect-render/icons.render/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function renderSvgIcon(
1818
data: string,
1919
color: Color = "#000000",
2020
placement: IconPlacement = "center",
21-
config?: NamedIconConfig
21+
config?: { size: number; name: string; package: string; variant?: string }
2222
): FrameNode {
2323
console.log(`inserting icon with name ${name} and data ${data}`);
2424

@@ -47,7 +47,7 @@ export function renderSvgIcon(
4747

4848
// operate extra manipulation if config is available.
4949
if (config) {
50-
const size = Number(config.default_size);
50+
const size = Number(config.size);
5151
node.resize(size, size);
5252
}
5353

@@ -62,14 +62,19 @@ export function renderSvgIcon(
6262

6363
export function buildReflectIconNameForRender(
6464
name: string,
65-
config: NamedIconConfig
65+
config: { name: string; package: string; variant?: string }
6666
): string {
67-
if (config.host == "material") {
68-
return `icons/mdi_${name}`;
69-
} else if (config.host == "ant-design") {
70-
return `icons/antd-${name}`;
71-
} else {
72-
return `icons/${name}`;
67+
switch (config.package) {
68+
case "material":
69+
return `icons/mdi_${name}`;
70+
case "ant-design":
71+
return `icons/antd-${name}`;
72+
case "radix-ui":
73+
return `icons/radix-${name}`;
74+
case "unicons":
75+
return `icons/unicons-${name}`;
76+
default:
77+
return `icons/${name}`;
7378
}
7479
}
7580

packages/app-icons-loader/icon-item.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ export function IconItem({ onClick, ...props }: IconItemProps) {
4343
const data = {
4444
key: name,
4545
svg: svg,
46-
// TODO:
47-
// config: config,
46+
config: {
47+
name: props.name,
48+
variant: props.variant,
49+
size: props.size,
50+
package: props.package,
51+
},
4852
};
4953
return data;
5054
} catch (_) {
@@ -73,7 +77,7 @@ export function IconItem({ onClick, ...props }: IconItemProps) {
7377
return (
7478
<Draggable customDataLoader={loadData} eventKey={EK_ICON_DRAG_AND_DROPPED}>
7579
<Tooltip
76-
title={`${name} (${variant}) (${_package})`}
80+
title={`${name} (${variant ?? "default"}) (${_package})`}
7781
placement="top"
7882
PopperProps={{
7983
popperOptions: {

packages/app-icons-loader/icons-loader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ const Section = styled.div`
161161
.title {
162162
margin: 0;
163163
padding: 16px;
164+
padding-right: 0;
164165
font-size: 12px;
165166
font-weight: normal;
166167
color: rgba(0, 0, 0, 0.54);

packages/app-icons-loader/resources.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ export function useIcons({
9797

9898
let result = Array.from(icons ?? []);
9999

100-
console.log(meta.filter((m) => m.package === "radix-ui"));
101-
102100
// sort by package name
103101

104102
const pkg_order = query

0 commit comments

Comments
 (0)