Skip to content

Commit 511328e

Browse files
committed
feat: add icon component
1 parent 7b7cf9a commit 511328e

File tree

13 files changed

+136
-0
lines changed

13 files changed

+136
-0
lines changed

packages/components/icon/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Icon
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: "@rck/babel-config",
3+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "*.module.scss" {
2+
const content: Record<string, string>;
3+
export default content;
4+
}

packages/components/icon/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Hack for module resolution of non built packages
2+
export * from "./src/index";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { config as default } from "@rck/jest-config";
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@rck/icon",
3+
"private": false,
4+
"version": "1.0.0",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"files": [
8+
"/dist"
9+
],
10+
"homepage": "https://github.com/abelflopes/rck/tree/master/packages/components/icon#readme",
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/abelflopes/rck.git"
14+
},
15+
"scripts": {
16+
"build": "NODE_ENV=production webpack",
17+
"test": "npx -y npm-run-all -s test:*",
18+
"test:unit": "jest --testPathPattern=\".unit.*\"",
19+
"test:snapshot": "jest --testPathPattern=\".snapshot.*\""
20+
},
21+
"devDependencies": {
22+
"@rck/babel-config": "^1.0.0",
23+
"@rck/jest-config": "^1.0.0",
24+
"@rck/typescript-config": "^1.0.0",
25+
"@rck/webpack-config": "^1.0.0",
26+
"@types/react": "^18.2.33"
27+
},
28+
"peerDependencies": {
29+
"react": "^18.2.0"
30+
},
31+
"dependencies": {
32+
"classnames": "^2.3.2",
33+
"react-icons": "^4.10.1"
34+
}
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from "react";
2+
import { Icon } from "../src/index";
3+
import renderer from "react-test-renderer";
4+
5+
describe("Icon", () => {
6+
test("renders correctly", async () => {
7+
const tree = renderer.create(<Icon />).toJSON();
8+
expect(tree).toMatchSnapshot();
9+
});
10+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from "react";
2+
import { Icon } from "../src/index";
3+
import { render, screen } from "@testing-library/react";
4+
import "@testing-library/jest-dom";
5+
6+
describe("Icon", () => {
7+
test("renders correctly", async () => {
8+
render(<Icon data-testid="icon" />);
9+
const find = await screen.findByTestId("icon");
10+
expect(find).toBeInTheDocument();
11+
});
12+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import styles from "./styles/index.module.scss";
2+
/// React
3+
import React from "react";
4+
// Icons - https://react-icons.github.io/react-icons/icons?name=si
5+
import { type IconType } from "react-icons";
6+
import { BsBellFill } from "react-icons/bs";
7+
8+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
9+
const icons = {
10+
BsBellFill,
11+
};
12+
/* eslint-enable @typescript-eslint/no-unsafe-assignment */
13+
export interface IconProps extends Omit<IconType, "size"> {
14+
title?: string;
15+
url?: string;
16+
name: keyof typeof icons;
17+
}
18+
19+
export const Icon = ({
20+
name,
21+
title,
22+
url,
23+
...otherProps
24+
}: Readonly<IconProps>): React.ReactElement => {
25+
const Icon: IconType = icons[name] as IconType;
26+
const IconElement = <Icon {...otherProps} title={title} size={16} />;
27+
28+
const Component = url ? (
29+
<a href={url} title={title} target="_blank" rel="noreferrer" className={styles.root}>
30+
{IconElement}
31+
</a>
32+
) : (
33+
IconElement
34+
);
35+
36+
return Component;
37+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@import "@rck/theme";
2+
3+
.root {
4+
color: currentColor;
5+
6+
// Add margin for icons next to each other
7+
& + & {
8+
margin-left: get-spacing(1);
9+
}
10+
}

0 commit comments

Comments
 (0)