Skip to content

Commit

Permalink
feat: bundle svg files to prevent image flicker
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstark authored and malmen237 committed Apr 26, 2024
1 parent 375e27f commit 06a46de
Show file tree
Hide file tree
Showing 7 changed files with 459 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
"plugin:react-hooks/recommended",
"plugin:prettier/recommended",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
ignorePatterns: ["dist", ".eslintrc.cjs", "vite.config.ts"],
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
Expand Down Expand Up @@ -47,5 +47,6 @@ module.exports = {
"warn",
{ allowConstantExport: true },
],
"no-console": "off",
},
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"typescript": "5.4.5",
"vite": "^5.2.10"
"vite": "^5.2.10",
"vite-plugin-svgr": "^4.2.0"
}
}
33 changes: 12 additions & 21 deletions src/assets/icons/icon.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import styled from "@emotion/styled";
import MicMute from "./mic_off.svg";
import MicUnmute from "./mic_on.svg";
import Arrow from "./arrow_back.svg";
import RemoveSvg from "./clear.svg";
import VolumeOn from "./volume_on.svg";
import VolumeOff from "./volume_off.svg";
import MicMute from "./mic_off.svg?react";
import MicUnmute from "./mic_on.svg?react";
import Arrow from "./arrow_back.svg?react";
import RemoveSvg from "./clear.svg?react";
import VolumeOn from "./volume_on.svg?react";
import VolumeOff from "./volume_off.svg?react";

const Icon = styled.img`
width: 100%;
height: auto;
display: block;
`;
export const MicMuted = () => <MicMute />;

export const MicMuted = () => <Icon src={MicMute} alt="off-microphone" />;
export const MicUnmuted = () => <MicUnmute />;

export const MicUnmuted = () => <Icon src={MicUnmute} alt="on-microphone" />;
export const BackArrow = () => <Arrow />;

export const BackArrow = () => <Icon src={Arrow} alt="arrow-left" />;
export const RemoveIcon = () => <RemoveSvg />;

export const RemoveIcon = () => <Icon src={RemoveSvg} alt="cross" />;
export const SpeakerOff = () => <VolumeOff />;

export const SpeakerOff = () => (
<Icon src={VolumeOff} alt="speaker-crossed-over" />
);

export const SpeakerOn = () => <Icon src={VolumeOn} alt="speaker" />;
export const SpeakerOn = () => <VolumeOn />;
4 changes: 3 additions & 1 deletion src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ body {
}

/* image size contstrained to container size */
img {
img,
svg {
/* max-width: 100%; */
width: 100%;
height: auto;
display: block;
}

#root {
Expand Down
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/// <reference types="vite/client" />
/// <reference types="vite-plugin-svgr/client" />
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import svgr from "vite-plugin-svgr";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [react(), svgr()],
});
Loading

0 comments on commit 06a46de

Please sign in to comment.