Skip to content

Commit

Permalink
Attempt at texmo icons
Browse files Browse the repository at this point in the history
  • Loading branch information
ianvexler committed Feb 28, 2024
1 parent 299f571 commit 8f524dc
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 16 deletions.
4 changes: 4 additions & 0 deletions custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.svg' {
const content: string;
export default content;
}
4 changes: 4 additions & 0 deletions example/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.svg' {
const content: string;
export default content;
}
3 changes: 2 additions & 1 deletion example/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { InfoTile, Title } from '@the-curve-consulting/texmo-react-components';
import { Row, Col } from 'react-bootstrap';

const HomePage = () => {

return (
<>
<Row className="my-4">
Expand Down Expand Up @@ -78,4 +79,4 @@ const HomePage = () => {
)
}

export default HomePage;
export default HomePage;
2 changes: 1 addition & 1 deletion example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"include": ["src", "custom.d.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
}
23 changes: 11 additions & 12 deletions src/components/texmoIcon/TexmoIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import React, { useEffect, useState } from 'react';
import React, { useState, useEffect } from 'react';
import { TexmoIcons } from 'types';

export interface TexmoIconProps {
icon: TexmoIcons;
}

const TexmoIcon = ({ icon }: TexmoIconProps) => {
const [Icon, setIcon] = useState<React.FC | null>(null);
const [svgComponent, setSvgComponent] = useState(null);

useEffect(() => {
const loadIcon = async () => {
const importSVG = async () => {
try {
const importedIcon = await import(`../../icons/${icon}.svg`);
console.log(importedIcon.default);
setIcon(importedIcon.default);
const svg = await import(`../../icons/users2.svg`);
setSvgComponent(svg.default);

Check failure on line 15 in src/components/texmoIcon/TexmoIcon.tsx

View workflow job for this annotation

GitHub Actions / Build (and lint) the package

Argument of type 'string' is not assignable to parameter of type 'SetStateAction<null>'.
} catch (error) {
console.error('Error loading SVG:', error);
}
};

loadIcon();
}, [icon]);
importSVG();

if (!Icon) {
return <div>SVG not found</div>;
}
return () => {
setSvgComponent(null);
};
}, [icon]);

return <Icon />;
return <div>{svgComponent && <img src={svgComponent} alt={icon} />}</div>;
};

export default TexmoIcon;
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Nav from './components/nav/Nav';
import Subtitle from './components/subtitle/Subtitle';
import Layout from './components/layout/Layout';
import Tabs from './components/tabs/Tabs';
// import TexmoIcon from './components/texmoIcon/TexmoIcon';
import TexmoIcon from './components/texmoIcon/TexmoIcon';
import '../scss/texmo-react-components.scss';

export {
Expand All @@ -44,4 +44,5 @@ export {
Subtitle,
Layout,
Tabs,
TexmoIcon,
};
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
],
},
"include": [
"src/**/*"
"src/**/*",
"custom.d.ts"
],
"exclude": [
"node_modules",
Expand Down

0 comments on commit 8f524dc

Please sign in to comment.