@integrigo/integrigo-ui 1.2.1 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/atoms/Icon/Icon.d.ts +8 -4
- package/lib/components/atoms/Icon/Icon.stories.d.ts +19 -10
- package/lib/index.esm.js +3328 -16
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +3328 -16
- package/lib/index.js.map +1 -1
- package/package.json +2 -1
- package/src/components/atoms/Icon/Icon.stories.tsx +17 -8
- package/src/components/atoms/Icon/Icon.tsx +39 -14
package/package.json
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
"publishConfig": {
|
4
4
|
"registry": "https://npm.pkg.github.com/integrigo"
|
5
5
|
},
|
6
|
-
"version": "1.2.
|
6
|
+
"version": "1.2.4",
|
7
7
|
"main": "lib/index.js",
|
8
8
|
"module": "lib/index.esm.js",
|
9
9
|
"types": "lib/index.d.ts",
|
@@ -34,6 +34,7 @@
|
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
36
|
"@fortawesome/fontawesome-svg-core": "^6.1.1",
|
37
|
+
"@fortawesome/free-brands-svg-icons": "^6.1.1",
|
37
38
|
"@fortawesome/free-solid-svg-icons": "^6.1.1",
|
38
39
|
"@fortawesome/react-fontawesome": "^0.1.18"
|
39
40
|
},
|
@@ -1,20 +1,29 @@
|
|
1
|
-
import React from
|
2
|
-
import { ComponentStory, ComponentMeta } from
|
1
|
+
import React from "react";
|
2
|
+
import { ComponentStory, ComponentMeta } from "@storybook/react";
|
3
3
|
|
4
|
-
import { Icon } from
|
4
|
+
import { Icon } from "./Icon";
|
5
5
|
|
6
6
|
export default {
|
7
|
-
|
8
|
-
|
7
|
+
title: "Atoms/Icon",
|
8
|
+
component: Icon,
|
9
9
|
} as ComponentMeta<typeof Icon>;
|
10
10
|
|
11
11
|
const Template: ComponentStory<typeof Icon> = (args) => <Icon {...args} />;
|
12
12
|
|
13
13
|
export const Bars = Template.bind({});
|
14
|
-
Bars.args = { icon:
|
14
|
+
Bars.args = { icon: "bars" };
|
15
15
|
|
16
16
|
export const Plus = Template.bind({});
|
17
|
-
Plus.args = { icon:
|
17
|
+
Plus.args = { icon: "plus" };
|
18
18
|
|
19
19
|
export const Minus = Template.bind({});
|
20
|
-
Minus.args = { icon:
|
20
|
+
Minus.args = { icon: "minus" };
|
21
|
+
|
22
|
+
export const Facebook = Template.bind({});
|
23
|
+
Facebook.args = { icon: "facebook" };
|
24
|
+
|
25
|
+
export const Instagram = Template.bind({});
|
26
|
+
Instagram.args = { icon: "instagram" };
|
27
|
+
|
28
|
+
export const Linkedin = Template.bind({});
|
29
|
+
Linkedin.args = { icon: "linkedin" };
|
@@ -1,18 +1,43 @@
|
|
1
|
-
import React from
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
1
|
+
import React from "react";
|
2
|
+
import {
|
3
|
+
FontAwesomeIcon,
|
4
|
+
FontAwesomeIconProps,
|
5
|
+
} from "@fortawesome/react-fontawesome";
|
6
|
+
import { IconProp } from "@fortawesome/fontawesome-svg-core";
|
5
7
|
|
6
|
-
|
8
|
+
import * as SolidIcons from "@fortawesome/free-solid-svg-icons";
|
9
|
+
import * as BrandIcons from "@fortawesome/free-brands-svg-icons";
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
}
|
11
|
+
const ICONS = ["bars", "plus", "minus", "phone", "envelope"];
|
12
|
+
const SOCIAL_ICONS = ["facebook", "instagram", "linkedin"];
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
type IconType = typeof ICONS[number];
|
15
|
+
type IconSocialType = typeof SOCIAL_ICONS[number];
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
type IconProps = Omit<FontAwesomeIconProps, "icon"> & {
|
18
|
+
icon: IconType | IconSocialType;
|
19
|
+
};
|
20
|
+
|
21
|
+
const toFaIcon = <T extends typeof BrandIcons | typeof SolidIcons>(
|
22
|
+
icon: IconType | IconSocialType
|
23
|
+
): keyof T => `fa${icon.charAt(0).toUpperCase() + icon.slice(1)}` as keyof T;
|
24
|
+
|
25
|
+
const getIcon = (icon: IconType | IconSocialType): IconProp => {
|
26
|
+
if (SOCIAL_ICONS.includes(icon)) {
|
27
|
+
if (icon === "facebook") {
|
28
|
+
return BrandIcons.faFacebookSquare;
|
29
|
+
}
|
30
|
+
|
31
|
+
const iconName = toFaIcon(icon);
|
32
|
+
return BrandIcons[iconName] as IconProp;
|
33
|
+
}
|
34
|
+
|
35
|
+
const iconName = toFaIcon(icon) as keyof typeof SolidIcons;
|
36
|
+
return SolidIcons[iconName] as IconProp;
|
37
|
+
};
|
38
|
+
|
39
|
+
export const Icon: React.FC<IconProps> = ({ icon, ...props }) => {
|
40
|
+
const iconType = getIcon(icon);
|
41
|
+
|
42
|
+
return <FontAwesomeIcon icon={iconType} {...props} />;
|
43
|
+
};
|