Skip to content

Commit

Permalink
feat(frontend): replace brand icons and add samsung
Browse files Browse the repository at this point in the history
  • Loading branch information
t0bst4r committed Nov 30, 2024
1 parent 42cdb96 commit b3991e2
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 32 deletions.
3 changes: 0 additions & 3 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"@emotion/react": "^11.13.5",
"@emotion/styled": "^11.13.5",
"@fontsource/roboto": "^5.1.0",
"@fortawesome/fontawesome-svg-core": "^6.7.1",
"@fortawesome/free-brands-svg-icons": "^6.7.1",
"@fortawesome/react-fontawesome": "^0.2.2",
"@mui/material": "^6.1.8",
"@mui/icons-material": "^6.1.8",
"@reduxjs/toolkit": "^2.3.0",
Expand Down
16 changes: 16 additions & 0 deletions packages/frontend/src/assets/brands/Amazon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/frontend/src/assets/brands/Apple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions packages/frontend/src/assets/brands/Google.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions packages/frontend/src/assets/brands/Samsung.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 36 additions & 20 deletions packages/frontend/src/components/fabric/FabricIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAmazon } from "@fortawesome/free-brands-svg-icons/faAmazon";
import { faApple } from "@fortawesome/free-brands-svg-icons/faApple";
import { faGoogle } from "@fortawesome/free-brands-svg-icons/faGoogle";
import { Tooltip } from "@mui/material";
import QuestionMark from "@mui/icons-material/QuestionMark";
import { BridgeFabric } from "@home-assistant-matter-hub/common";
import { IconLookup } from "@fortawesome/fontawesome-svg-core";
import { useMemo } from "react";
import { FC, SVGProps, useMemo } from "react";

import AmazonIcon from "../../assets/brands/Amazon.svg?react";
import AppleIcon from "../../assets/brands/Apple.svg?react";
import GoogleIcon from "../../assets/brands/Google.svg?react";
import SamsungIcon from "../../assets/brands/Samsung.svg?react";
import Box from "@mui/material/Box";

export interface FabricIconProps {
fabric: BridgeFabric;
}

const iconsPerKeyword: Record<string, IconLookup> = {
Alexa: faAmazon,
Apple: faApple,
Google: faGoogle,
const iconsPerKeyword: Record<string, FC<SVGProps<SVGSVGElement>>> = {
Alexa: AmazonIcon,
Apple: AppleIcon,
Google: GoogleIcon,
};

const iconPerVendorId: Record<number, IconLookup | undefined> = {
0x1217: faAmazon,
0x1349: faApple,
0x1384: faApple,
0x6006: faGoogle,
// 0x10e1: "Samsung SmartThings",
};
const iconPerVendorId: Record<number, FC<SVGProps<SVGSVGElement>> | undefined> =
{
0x1217: AmazonIcon,
0x1349: AppleIcon,
0x1384: AppleIcon,
0x6006: GoogleIcon,
0x10e1: SamsungIcon,
};

function getIcon(fabric: BridgeFabric): IconLookup | undefined {
function getIcon(fabric: BridgeFabric) {
const icon = iconPerVendorId[fabric.rootVendorId];
if (icon) {
return icon;
Expand All @@ -37,10 +39,24 @@ function getIcon(fabric: BridgeFabric): IconLookup | undefined {
}

export const FabricIcon = ({ fabric }: FabricIconProps) => {
const icon = useMemo(() => getIcon(fabric), [fabric]);
const BrandIcon = useMemo(() => getIcon(fabric), [fabric]);
return (
<Tooltip title={`${fabric.label} (${fabric.rootVendorId})`} arrow>
<span>{icon ? <FontAwesomeIcon icon={icon} /> : <QuestionMark />}</span>
<Box
component="span"
sx={{ fill: (theme) => theme.palette.text.primary }}
>
{BrandIcon ? (
<BrandIcon
style={{
maxHeight: "1em",
maxWidth: "3em",
}}
/>
) : (
<QuestionMark />
)}
</Box>
</Tooltip>
);
};
9 changes: 0 additions & 9 deletions packages/frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@ import "@fontsource/roboto/400.css";
import "@fontsource/roboto/500.css";
import "@fontsource/roboto/700.css";

import {
faAmazon,
faApple,
faGoogle,
} from "@fortawesome/free-brands-svg-icons";
import { library as IconLibrary } from "@fortawesome/fontawesome-svg-core";

import { AppLayout } from "./theme/AppLayout.tsx";
import { routes } from "./routes.tsx";
import { store } from "./state/store.ts";

IconLibrary.add(faAmazon, faApple, faGoogle);

let basename = document
.getElementsByTagName("base")[0]
?.href?.replace(/\/$/, "");
Expand Down

0 comments on commit b3991e2

Please sign in to comment.