dashboard/src/components/icon.tsx

69 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-07-09 16:22:18 +02:00
import React from "react";
2020-07-08 19:36:36 +02:00
import styled from "styled-components";
2021-03-21 18:05:24 +01:00
import selectedTheme from "../lib/theme";
2020-07-08 19:36:36 +02:00
2021-03-21 18:05:24 +01:00
interface IIconProps {
name: string;
size?: string;
}
2021-06-14 11:29:03 +02:00
interface IIconButtonProps {
icon: string;
onClick: (e: React.FormEvent) => void;
}
const StyledButton = styled.button`
float: right;
border: none;
padding: 0;
background: none;
&:hover {
cursor: pointer;
}
`;
const IconContainer = styled.i`
font-family: "Material Icons";
font-weight: normal;
font-style: normal;
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
-moz-osx-font-smoothing: grayscale;
font-feature-settings: "liga";
`;
2021-03-21 19:59:18 +01:00
/**
* Renders an Icon
2021-06-14 11:29:03 +02:00
* @param {IIconProps} props props needed for the given icon
* @returns {React.ReactNode} the icon node
2021-03-21 19:59:18 +01:00
*/
2021-03-21 18:05:24 +01:00
export const Icon = ({ name, size }: IIconProps) => {
2021-06-14 11:29:03 +02:00
let Container = styled(IconContainer)`
2021-03-21 19:59:18 +01:00
font-size: ${size ? size : "24px"};
color: ${selectedTheme.mainColor};
`;
2020-07-08 19:36:36 +02:00
2021-06-14 11:29:03 +02:00
return <Container>{name}</Container>;
2020-07-09 16:22:18 +02:00
};
2021-06-14 11:29:03 +02:00
/**
* Renders a button with an icon
* @param {IIconProps} props - The props of the given IconButton
* @returns {React.ReactNode} the icon button node
*/
export const IconButton = ({ icon, onClick }: IIconButtonProps) => (
<StyledButton onClick={onClick}>
<Icon name={icon} />
</StyledButton>
);
2021-03-21 18:05:24 +01:00
export default Icon;