perf: use svg sprite for icons (#16135)
Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
3e28160fa7
commit
da5df7164a
30 files changed
+1511
-1698
No files matched your search
@@ -1,8 +1,8 @@
|
||||
import type { Column } from "@tanstack/react-table";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
import type { IconName } from "../..";
|
||||
import { Icon } from "../..";
|
||||
import { Badge } from "../badge";
|
||||
import { Button } from "../button";
|
||||
@@ -23,7 +23,7 @@ interface DataTableFilter<TData, TValue> {
|
||||
options: {
|
||||
label: string;
|
||||
value: string;
|
||||
icon?: LucideIcon;
|
||||
icon?: IconName;
|
||||
}[];
|
||||
}
|
||||
export function DataTableFilter<TData, TValue>({ column, title, options }: DataTableFilter<TData, TValue>) {
|
||||
@@ -85,7 +85,7 @@ export function DataTableFilter<TData, TValue>({ column, title, options }: DataT
|
||||
)}>
|
||||
<Icon name="check" className={classNames("h-4 w-4")} />
|
||||
</div>
|
||||
{option.icon && <option.icon className="text-muted mr-2 h-4 w-4" />}
|
||||
{option.icon && <Icon name={option.icon} className="text-muted mr-2 h-4 w-4" />}
|
||||
<span>{option.label}</span>
|
||||
{facets?.get(option.value) && (
|
||||
<span className="ml-auto flex h-4 w-4 items-center justify-center font-mono text-xs">
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import type { Table } from "@tanstack/react-table";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { useDebounce } from "@calcom/lib/hooks/useDebounce";
|
||||
@@ -9,6 +8,7 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Button } from "../button";
|
||||
import { Input } from "../form";
|
||||
import type { IconName } from "../icon/icon-names";
|
||||
import { DataTableFilter } from "./DataTableFilter";
|
||||
|
||||
export type FilterableItems = {
|
||||
@@ -17,7 +17,7 @@ export type FilterableItems = {
|
||||
options: {
|
||||
label: string;
|
||||
value: string;
|
||||
icon?: LucideIcon;
|
||||
icon?: IconName;
|
||||
}[];
|
||||
}[];
|
||||
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
// find all lucide icons at https://lucide.dev/
|
||||
// github https://github.com/lucide-icons/lucide
|
||||
import type { LucideProps } from "lucide-react";
|
||||
import dynamic from "next/dynamic";
|
||||
import { memo } from "react";
|
||||
import { type SVGProps } from "react";
|
||||
|
||||
import type { IconName } from "./dynamicIconImports";
|
||||
import type { IconName } from "./icon-names";
|
||||
|
||||
interface IconProps extends Omit<LucideProps, "ref"> {
|
||||
function Icon({
|
||||
name,
|
||||
size,
|
||||
...props
|
||||
}: SVGProps<SVGSVGElement> & {
|
||||
name: IconName;
|
||||
size?: number | string;
|
||||
}) {
|
||||
return (
|
||||
<svg height={size} width={size} {...props} aria-hidden>
|
||||
<use href={`/icons/sprite.svg#${name}`} />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
const IconLazy = dynamic(
|
||||
// Fast refresh doesn't play nice with dynamic imports
|
||||
// This prevent slowdowns in development mode
|
||||
process.env.NODE_ENV === "production" ? () => import("./IconProd") : () => import("./IconDev")
|
||||
);
|
||||
|
||||
const Icon = memo((props: IconProps) => <IconLazy {...props} />);
|
||||
|
||||
Icon.displayName = "Icon";
|
||||
|
||||
export { IconName };
|
||||
export default Icon;
|
||||
@@ -1,22 +0,0 @@
|
||||
// find all lucide icons at https://lucide.dev/
|
||||
// github https://github.com/lucide-icons/lucide
|
||||
import type { LucideProps } from "lucide-react";
|
||||
import { icons } from "lucide-react";
|
||||
|
||||
import type { IconName } from "./dynamicIconImports";
|
||||
|
||||
interface IconProps extends Omit<LucideProps, "ref"> {
|
||||
name: IconName;
|
||||
}
|
||||
|
||||
const clearAndUpper = (text: string) => text.replace(/-/, "").toUpperCase();
|
||||
const toPascalCase = (text: string) => text.replace(/(^\w|-\w)/g, clearAndUpper);
|
||||
|
||||
const IconDev = ({ name, ...props }: IconProps) => {
|
||||
const CamelCaseName = toPascalCase(name);
|
||||
const LucideIcon = icons[CamelCaseName as keyof typeof icons];
|
||||
if (!LucideIcon) return null;
|
||||
return <LucideIcon {...props} />;
|
||||
};
|
||||
|
||||
export default IconDev;
|
||||
@@ -1,30 +0,0 @@
|
||||
"use client";
|
||||
|
||||
// find all lucide icons at https://lucide.dev/
|
||||
// github https://github.com/lucide-icons/lucide
|
||||
import type { LucideProps } from "lucide-react";
|
||||
import { memo } from "react";
|
||||
|
||||
import { dynamicIconImports } from "./dynamicIconImports";
|
||||
|
||||
export type IconName = keyof typeof dynamicIconImports;
|
||||
|
||||
interface IconProps extends Omit<LucideProps, "ref"> {
|
||||
name: IconName;
|
||||
}
|
||||
|
||||
const fallback = <div className="bg-emphasis h-4 w-4 animate-pulse rounded-lg" />;
|
||||
|
||||
const LazyIcon = memo(({ name, ...props }: IconProps) => {
|
||||
const LucideIcon = dynamicIconImports[name];
|
||||
|
||||
// This should never happen, but just in case
|
||||
if (!LucideIcon) return fallback;
|
||||
|
||||
// @ts-expect-error - LucideIcon is a lazy loaded component
|
||||
return <LucideIcon {...props} />;
|
||||
});
|
||||
|
||||
LazyIcon.displayName = "LazyIcon";
|
||||
|
||||
export default LazyIcon;
|
||||
@@ -0,0 +1,5 @@
|
||||
# Icons
|
||||
|
||||
This directory contains SVG icons that are used by the app.
|
||||
|
||||
Everything in this directory is generated by `yarn run build:icons`.
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,139 @@
|
||||
// icon name from lucide-react
|
||||
// this list is extracted based on what icons are currently used
|
||||
export const lucideIconList = new Set([
|
||||
"activity",
|
||||
"arrow-down",
|
||||
"arrow-left",
|
||||
"arrow-right",
|
||||
"arrow-up-right",
|
||||
"arrow-up",
|
||||
"asterisk",
|
||||
"at-sign",
|
||||
"atom",
|
||||
"badge-check",
|
||||
"ban",
|
||||
"bell",
|
||||
"bold",
|
||||
"book-open-check",
|
||||
"book-open",
|
||||
"book-user",
|
||||
"building",
|
||||
"calendar-check-2",
|
||||
"calendar-heart",
|
||||
"calendar-search",
|
||||
"calendar-x-2",
|
||||
"calendar",
|
||||
"chart-bar",
|
||||
"chart-line",
|
||||
"check-check",
|
||||
"check",
|
||||
"chevron-down",
|
||||
"chevron-left",
|
||||
"chevron-right",
|
||||
"chevron-up",
|
||||
"chevrons-left",
|
||||
"chevrons-right",
|
||||
"circle-alert",
|
||||
"circle-arrow-up",
|
||||
"circle-check-big",
|
||||
"circle-check",
|
||||
"circle-help",
|
||||
"circle-x",
|
||||
"circle",
|
||||
"clipboard-check",
|
||||
"clipboard",
|
||||
"clipboard",
|
||||
"clock",
|
||||
"code",
|
||||
"columns-3",
|
||||
"command",
|
||||
"contact",
|
||||
"copy",
|
||||
"corner-down-left",
|
||||
"corner-down-right",
|
||||
"credit-card",
|
||||
"dot",
|
||||
"download",
|
||||
"ellipsis-vertical",
|
||||
"ellipsis",
|
||||
"external-link",
|
||||
"eye-off",
|
||||
"eye",
|
||||
"file-down",
|
||||
"file-text",
|
||||
"file",
|
||||
"filter",
|
||||
"fingerprint",
|
||||
"flag",
|
||||
"folder",
|
||||
"git-merge",
|
||||
"github",
|
||||
"globe",
|
||||
"grid-3x3",
|
||||
"handshake",
|
||||
"info",
|
||||
"italic",
|
||||
"key",
|
||||
"layers",
|
||||
"layout-dashboard",
|
||||
"link-2",
|
||||
"link",
|
||||
"loader",
|
||||
"lock-open",
|
||||
"lock",
|
||||
"log-out",
|
||||
"mail-open",
|
||||
"mail",
|
||||
"map-pin",
|
||||
"map",
|
||||
"menu",
|
||||
"message-circle",
|
||||
"messages-square",
|
||||
"moon",
|
||||
"paintbrush",
|
||||
"paperclip",
|
||||
"pencil",
|
||||
"pencil",
|
||||
"phone-call",
|
||||
"phone",
|
||||
"plus",
|
||||
"refresh-ccw",
|
||||
"refresh-cw",
|
||||
"repeat",
|
||||
"rocket",
|
||||
"rotate-ccw",
|
||||
"rotate-cw",
|
||||
"search",
|
||||
"send",
|
||||
"settings",
|
||||
"share-2",
|
||||
"shield-check",
|
||||
"shield",
|
||||
"shuffle",
|
||||
"sliders-vertical",
|
||||
"smartphone",
|
||||
"sparkles",
|
||||
"square-check",
|
||||
"star",
|
||||
"sun",
|
||||
"sunrise",
|
||||
"sunset",
|
||||
"terminal",
|
||||
"terminal",
|
||||
"trash-2",
|
||||
"trash",
|
||||
"trash",
|
||||
"trello",
|
||||
"triangle-alert",
|
||||
"upload",
|
||||
"user-check",
|
||||
"user-plus",
|
||||
"user-x",
|
||||
"user",
|
||||
"users",
|
||||
"venetian-mask",
|
||||
"video",
|
||||
"webhook",
|
||||
"x",
|
||||
"zap",
|
||||
]);
|
||||
@@ -0,0 +1,134 @@
|
||||
// This file is generated by yarn run build:icons
|
||||
|
||||
export type IconName =
|
||||
| "activity"
|
||||
| "arrow-down"
|
||||
| "arrow-left"
|
||||
| "arrow-right"
|
||||
| "arrow-up-right"
|
||||
| "arrow-up"
|
||||
| "asterisk"
|
||||
| "at-sign"
|
||||
| "atom"
|
||||
| "badge-check"
|
||||
| "ban"
|
||||
| "bell"
|
||||
| "bold"
|
||||
| "book-open-check"
|
||||
| "book-open"
|
||||
| "book-user"
|
||||
| "building"
|
||||
| "calendar-check-2"
|
||||
| "calendar-heart"
|
||||
| "calendar-search"
|
||||
| "calendar-x-2"
|
||||
| "calendar"
|
||||
| "chart-bar"
|
||||
| "chart-line"
|
||||
| "check-check"
|
||||
| "check"
|
||||
| "chevron-down"
|
||||
| "chevron-left"
|
||||
| "chevron-right"
|
||||
| "chevron-up"
|
||||
| "chevrons-left"
|
||||
| "chevrons-right"
|
||||
| "circle-alert"
|
||||
| "circle-arrow-up"
|
||||
| "circle-check-big"
|
||||
| "circle-check"
|
||||
| "circle-help"
|
||||
| "circle-x"
|
||||
| "circle"
|
||||
| "clipboard-check"
|
||||
| "clipboard"
|
||||
| "clock"
|
||||
| "code"
|
||||
| "columns-3"
|
||||
| "command"
|
||||
| "contact"
|
||||
| "copy"
|
||||
| "corner-down-left"
|
||||
| "corner-down-right"
|
||||
| "credit-card"
|
||||
| "dot"
|
||||
| "download"
|
||||
| "ellipsis-vertical"
|
||||
| "ellipsis"
|
||||
| "external-link"
|
||||
| "eye-off"
|
||||
| "eye"
|
||||
| "file-down"
|
||||
| "file-text"
|
||||
| "file"
|
||||
| "filter"
|
||||
| "fingerprint"
|
||||
| "flag"
|
||||
| "folder"
|
||||
| "git-merge"
|
||||
| "github"
|
||||
| "globe"
|
||||
| "grid-3x3"
|
||||
| "handshake"
|
||||
| "info"
|
||||
| "italic"
|
||||
| "key"
|
||||
| "layers"
|
||||
| "layout-dashboard"
|
||||
| "link-2"
|
||||
| "link"
|
||||
| "loader"
|
||||
| "lock-open"
|
||||
| "lock"
|
||||
| "log-out"
|
||||
| "mail-open"
|
||||
| "mail"
|
||||
| "map-pin"
|
||||
| "map"
|
||||
| "menu"
|
||||
| "message-circle"
|
||||
| "messages-square"
|
||||
| "moon"
|
||||
| "paintbrush"
|
||||
| "paperclip"
|
||||
| "pencil"
|
||||
| "phone-call"
|
||||
| "phone"
|
||||
| "plus"
|
||||
| "refresh-ccw"
|
||||
| "refresh-cw"
|
||||
| "repeat"
|
||||
| "rocket"
|
||||
| "rotate-ccw"
|
||||
| "rotate-cw"
|
||||
| "search"
|
||||
| "send"
|
||||
| "settings"
|
||||
| "share-2"
|
||||
| "shield-check"
|
||||
| "shield"
|
||||
| "shuffle"
|
||||
| "sliders-vertical"
|
||||
| "smartphone"
|
||||
| "sparkles"
|
||||
| "square-check"
|
||||
| "star"
|
||||
| "sun"
|
||||
| "sunrise"
|
||||
| "sunset"
|
||||
| "terminal"
|
||||
| "trash-2"
|
||||
| "trash"
|
||||
| "trello"
|
||||
| "triangle-alert"
|
||||
| "upload"
|
||||
| "user-check"
|
||||
| "user-plus"
|
||||
| "user-x"
|
||||
| "user"
|
||||
| "users"
|
||||
| "venetian-mask"
|
||||
| "video"
|
||||
| "webhook"
|
||||
| "x"
|
||||
| "zap";
|
||||
@@ -1,5 +1,4 @@
|
||||
import classNames from "classnames";
|
||||
import type { LucideProps } from "lucide-react";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import { TOP_BANNER_HEIGHT } from "@calcom/lib/constants";
|
||||
@@ -21,8 +20,7 @@ const variantClassName = {
|
||||
|
||||
const defaultIconProps = {
|
||||
className: "text-emphasis h-4 w-4 stroke-[2.5px]",
|
||||
"aria-hidden": "true",
|
||||
} as LucideProps;
|
||||
};
|
||||
|
||||
export function TopBanner(props: TopBannerProps) {
|
||||
const { icon, variant = "default", text, actions } = props;
|
||||
|
||||
Reference in new issue
Block a user