Skip to content

Commit ca4cc8e

Browse files
committed
refactor(icon): migrate to classes convention
1 parent c2f3af6 commit ca4cc8e

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const CLASSES = {
2+
base: "icon",
3+
} as const;
4+

src/components/icon/Icon.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@layer components {
2+
.icon {
3+
display: inline-flex;
4+
align-items: center;
5+
justify-content: center;
6+
flex-shrink: 0;
7+
line-height: 1;
8+
}
9+
}
10+

src/components/icon/Icon.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import clsx from "clsx";
1+
import "./Icon.css";
22
import { createMemo, type JSX, splitProps } from "solid-js";
33
import { twMerge } from "tailwind-merge";
44
import type { IComponentBaseProps } from "../types";
55
import type { ComponentColor } from "../types";
6+
import { CLASSES } from "./Icon.classes";
67

78
export type IconProps = IComponentBaseProps & {
89
width?: number;
@@ -26,17 +27,19 @@ const Icon = (props: IconProps): JSX.Element => {
2627
const height = local.height ?? 24;
2728
const name = local.name;
2829

29-
const sizeClass = createMemo(() => `${name} w-${width / 4} h-${height / 4}`);
30-
31-
const classes = createMemo(() => {
32-
return twMerge(clsx(sizeClass(), local.className ?? local.class));
33-
});
30+
const classes = createMemo(() =>
31+
twMerge(CLASSES.base, name, local.class, local.className),
32+
);
3433

3534
return (
3635
<span
3736
{...others}
3837
class={classes()}
39-
style={local.style}
38+
style={{
39+
width: `${width}px`,
40+
height: `${height}px`,
41+
...(typeof local.style === "object" ? local.style : {}),
42+
}}
4043
data-theme={local.dataTheme}
4144
/>
4245
);

0 commit comments

Comments
 (0)