Skip to content

Commit c1533d7

Browse files
committed
feat(icon)!: allow any content type as icon
1 parent 90d364c commit c1533d7

File tree

17 files changed

+190
-40
lines changed

17 files changed

+190
-40
lines changed

packages/components/_provisional/src/breadcrumbs/Breadcrumbs.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ const Breadcrumbs = ({
1515
...otherProps
1616
}: Readonly<BreadcrumbsProps>): React.ReactElement => {
1717
const computedItems = useMemo(
18-
() => items.flatMap((i, k) => (k === 0 ? i : [<Icon key="_" Icon={IconChevronRight} />, i])),
18+
() =>
19+
items.flatMap((i, k) =>
20+
k === 0
21+
? i
22+
: [
23+
<Icon key="_">
24+
<IconChevronRight />
25+
</Icon>,
26+
i,
27+
],
28+
),
1929
[items],
2030
);
2131

packages/components/_provisional/src/chat/ChatPrompt/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ export const ChatPrompt = ({
5454
autoFocus
5555
required
5656
/>
57-
<Button>
58-
{/* <Icon Icon={<LuSendHorizonal size="20" />} /> */}
57+
<Button
58+
icon={
59+
<Icon>
60+
<LuSendHorizonal />
61+
</Icon>
62+
}>
5963
Send
6064
</Button>
6165
</form>

packages/components/alert/src/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ export const Alert = ({
6161

6262
{dismissable ? (
6363
<Button
64-
icon={<Icon Icon={IconClose} />}
64+
icon={
65+
<Icon>
66+
<IconClose />
67+
</Icon>
68+
}
6569
size="s"
6670
skin="ghost"
6771
onClick={() => {

packages/components/data-table/src/TableHead.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ export const TableHead = ({
2424
})}>
2525
{children}
2626

27-
{sorting === "asc" && <Icon Icon={IconChevronUp} className={styles.sortable_header_icon} />}
27+
{sorting === "asc" && (
28+
<Icon className={styles.sortable_header_icon}>
29+
<IconChevronUp />
30+
</Icon>
31+
)}
2832

29-
{sorting === "desc" && <Icon Icon={IconChevronDown} className={styles.sortable_header_icon} />}
33+
{sorting === "desc" && (
34+
<Icon className={styles.sortable_header_icon}>
35+
<IconChevronDown />
36+
</Icon>
37+
)}
3038
</th>
3139
);

packages/components/icon/specs/index.snapshot.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { IconBellFill } from "../src/icons/IconBellFill";
55

66
describe("snapshot Icon", () => {
77
it("renders correctly", () => {
8-
const tree = renderer.create(<Icon Icon={IconBellFill} />).toJSON();
8+
const tree = renderer
9+
.create(
10+
<Icon>
11+
<IconBellFill />
12+
</Icon>,
13+
)
14+
.toJSON();
915
expect(tree).toMatchSnapshot();
1016
});
1117
});

packages/components/icon/specs/index.unit.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import { IconBellFill } from "../src/icons/IconBellFill";
66

77
describe("unit Icon", () => {
88
it("renders correctly", async () => {
9-
render(<Icon Icon={IconBellFill} data-testid="icon" />);
9+
render(
10+
<Icon data-testid="icon">
11+
<Icon>
12+
<IconBellFill />
13+
</Icon>
14+
</Icon>,
15+
);
1016
const find = await screen.findByTestId("icon");
1117
expect(find).toBeInTheDocument();
1218
});
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import styles from "./styles/index.module.scss";
2-
/// React
3-
import React, { type SVGAttributes } from "react";
4-
// Icons
5-
import { type IconType } from "react-icons";
2+
import React from "react";
63
import { useThemeContext } from "@react-ck/theme";
74
import classNames from "classnames";
85

9-
export interface IconProps extends Omit<IconType, "size"> {
6+
export interface IconProps extends React.HTMLAttributes<HTMLSpanElement> {
107
size?: "text" | "m" | "l";
118
skin?: "default" | "inverted";
12-
/** Additional CSS class */
13-
className?: SVGAttributes<SVGElement>["className"];
14-
Icon: IconType;
9+
children: NonNullable<React.ReactNode>;
1510
}
1611

1712
/**
@@ -24,13 +19,13 @@ export const Icon = ({
2419
size = "text",
2520
skin = "default",
2621
className,
27-
Icon,
22+
children,
2823
...otherProps
2924
}: Readonly<IconProps>): React.ReactElement => {
3025
const themeContext = useThemeContext();
3126

3227
return (
33-
<Icon
28+
<span
3429
{...otherProps}
3530
className={classNames(
3631
styles.root,
@@ -40,7 +35,8 @@ export const Icon = ({
4035
[`${styles.skin_inverted}`]: themeContext.inverted || skin === "inverted",
4136
},
4237
className,
43-
)}
44-
/>
38+
)}>
39+
{children}
40+
</span>
4541
);
4642
};

packages/components/icon/src/styles/index.module.scss

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
.root {
44
color: get-css-var(icon, color);
55
font-size: get-css-var(icon, size);
6+
line-height: get-css-var(icon, size);
7+
height: get-css-var(icon, size);
8+
aspect-ratio: 1 / 1;
9+
display: inline-flex;
10+
align-items: center;
11+
justify-content: center;
612

7-
// Add margin for icons next to each other
8-
& + & {
9-
margin-left: get-spacing(1);
13+
> * {
14+
height: inherit;
15+
width: 100%;
16+
aspect-ratio: inherit;
1017
}
1118
}
1219

packages/components/modal/src/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,15 @@ const Modal = ({
114114
</Text>
115115

116116
{dismissable ? (
117-
<Button skin="ghost" icon={<Icon Icon={IconClose} />} onClick={handleClose} />
117+
<Button
118+
skin="ghost"
119+
icon={
120+
<Icon>
121+
<IconClose />
122+
</Icon>
123+
}
124+
onClick={handleClose}
125+
/>
118126
) : null}
119127
</header>
120128
) : null}

packages/components/spinner/src/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export const Spinner = ({
2323
...otherProps
2424
}: Readonly<SpinnerProps>): React.ReactElement => (
2525
<span {...otherProps} className={classNames(styles.root, styles[skin], className)}>
26-
<Icon Icon={IconSpinner} size={size} />
26+
<Icon size={size}>
27+
<IconSpinner />
28+
</Icon>
2729
</span>
2830
);

0 commit comments

Comments
 (0)