Skip to content

Commit

Permalink
ci: adds basic visual regression testing for icons (#16408)
Browse files Browse the repository at this point in the history
  • Loading branch information
zomars authored Sep 4, 2024
1 parent 2e36cad commit 36e79bf
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 136 deletions.
77 changes: 77 additions & 0 deletions apps/web/pages/icons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"use client";

import type { InferGetStaticPropsType } from "next";
import { Inter } from "next/font/google";
import localFont from "next/font/local";
import Head from "next/head";

import { APP_NAME } from "@calcom/lib/constants";
import type { IconName } from "@calcom/ui";
import { Icon, IconSprites } from "@calcom/ui";

import { lucideIconList } from "../../../packages/ui/components/icon/icon-list.mjs";

const interFont = Inter({ subsets: ["latin"], variable: "--font-inter", preload: true, display: "swap" });
const calFont = localFont({
src: "../fonts/CalSans-SemiBold.woff2",
variable: "--font-cal",
preload: true,
display: "swap",
weight: "600",
});

export const getStaticProps = async () => {
return {
props: {
icons: Array.from(lucideIconList).sort() as IconName[],
},
};
};

const IconGrid = (props: {
title: string;
icons: IconName[];
rootClassName?: string;
iconClassName?: string;
}) => (
<div className={props.rootClassName}>
<h2 className="font-cal mt-6 text-lg font-medium">{props.title}</h2>
<div className="grid grid-cols-2 lg:grid-cols-6">
{props.icons.map((icon) => {
return (
<div key={icon} className="flex items-center gap-1">
<Icon name={icon} className={props.iconClassName} />
<div>{icon}</div>
</div>
);
})}
</div>
</div>
);

export default function IconsPage(props: InferGetStaticPropsType<typeof getStaticProps>) {
return (
<div className="bg-subtle flex h-screen">
<Head>
<title>Icon showcase | {APP_NAME}</title>
</Head>
<style jsx global>{`
:root {
--font-cal: ${calFont.style.fontFamily};
--font-inter: ${interFont.style.fontFamily};
}
`}</style>
<IconSprites />
<div className="bg-default m-auto min-w-full rounded-md p-10 text-right ltr:text-left">
<h1 className="text-emphasis font-cal text-2xl font-medium">Icons showcase</h1>
<IconGrid title="Regular Icons" icons={props.icons} />
<IconGrid
title="Filled Icons"
icons={props.icons}
rootClassName="bg-darkgray-100 text-gray-50"
iconClassName="fill-blue-500"
/>
</div>
</div>
);
}
10 changes: 10 additions & 0 deletions apps/web/playwright/icons.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expect } from "@playwright/test";

import { test } from "./lib/fixtures";

test("Icons render properly", async ({ page }, testInfo) => {
await page.goto("/icons");
await expect(page).toHaveScreenshot("icons.png", {
fullPage: true,
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
262 changes: 131 additions & 131 deletions apps/web/public/icons/sprite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion packages/ui/components/icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { type SVGProps } from "react";

import cn from "@calcom/lib/classNames";

import type { IconName } from "./icon-names";

function Icon({
name,
size = 16,
className,
...props
}: SVGProps<SVGSVGElement> & {
name: IconName;
size?: number | string;
}) {
return (
<svg height={size} width={size} {...props} aria-hidden>
<svg
height={size}
width={size}
// Fill are inherited so we transparent by default. Can be overiden tailwind.
className={cn("fill-transparent", className)}
{...props}
aria-hidden>
<use href={`#${name}`} />
</svg>
);
Expand Down
4 changes: 0 additions & 4 deletions packages/ui/components/icon/icon-list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const lucideIconList = new Set([
"circle",
"clipboard-check",
"clipboard",
"clipboard",
"clock",
"code",
"columns-3",
Expand Down Expand Up @@ -95,7 +94,6 @@ export const lucideIconList = new Set([
"paintbrush",
"paperclip",
"pencil",
"pencil",
"phone-call",
"phone",
"plus",
Expand All @@ -121,10 +119,8 @@ export const lucideIconList = new Set([
"sunrise",
"sunset",
"terminal",
"terminal",
"trash-2",
"trash",
"trash",
"trello",
"triangle-alert",
"upload",
Expand Down
1 change: 1 addition & 0 deletions packages/ui/scripts/build-icons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async function generateSvgSprite({ files, inputDir, outputPath }) {

svg.tagName = "symbol";
svg.setAttribute("id", iconName(file));
svg.setAttribute("fill", "inherit");
svg.removeAttribute("xmlns");
svg.removeAttribute("xmlns:xlink");
svg.removeAttribute("version");
Expand Down

0 comments on commit 36e79bf

Please sign in to comment.