analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
1 lines • 9.51 kB
Source Map (JSON)
{"version":3,"sources":["../src/components/IconRender/IconRender.tsx"],"sourcesContent":["import { cloneElement, ComponentType, JSX, ReactElement } from 'react';\nimport { QuestionIcon } from '@phosphor-icons/react/dist/csr/Question';\nimport { ArticleNyTimesIcon } from '@phosphor-icons/react/dist/csr/ArticleNyTimes';\nimport { AtomIcon } from '@phosphor-icons/react/dist/csr/Atom';\nimport { BasketballIcon } from '@phosphor-icons/react/dist/csr/Basketball';\nimport { BookIcon } from '@phosphor-icons/react/dist/csr/Book';\nimport { BookBookmarkIcon } from '@phosphor-icons/react/dist/csr/BookBookmark';\nimport { BookOpenIcon } from '@phosphor-icons/react/dist/csr/BookOpen';\nimport { CalculatorIcon } from '@phosphor-icons/react/dist/csr/Calculator';\nimport { CastleTurretIcon } from '@phosphor-icons/react/dist/csr/CastleTurret';\nimport { ChartLineIcon } from '@phosphor-icons/react/dist/csr/ChartLine';\nimport { ChatTextIcon } from '@phosphor-icons/react/dist/csr/ChatText';\nimport { CheckCircleIcon } from '@phosphor-icons/react/dist/csr/CheckCircle';\nimport { CheckSquareIcon } from '@phosphor-icons/react/dist/csr/CheckSquare';\nimport { CircleHalfIcon } from '@phosphor-icons/react/dist/csr/CircleHalf';\nimport { ClockIcon } from '@phosphor-icons/react/dist/csr/Clock';\nimport { CylinderIcon } from '@phosphor-icons/react/dist/csr/Cylinder';\nimport { DribbbleLogoIcon } from '@phosphor-icons/react/dist/csr/DribbbleLogo';\nimport { FlaskIcon } from '@phosphor-icons/react/dist/csr/Flask';\nimport { GlobeIcon } from '@phosphor-icons/react/dist/csr/Globe';\nimport { GlobeHemisphereWestIcon } from '@phosphor-icons/react/dist/csr/GlobeHemisphereWest';\nimport { GraduationCapIcon } from '@phosphor-icons/react/dist/csr/GraduationCap';\nimport { HeartIcon } from '@phosphor-icons/react/dist/csr/Heart';\nimport { LeafIcon } from '@phosphor-icons/react/dist/csr/Leaf';\nimport { LightbulbIcon } from '@phosphor-icons/react/dist/csr/Lightbulb';\nimport { LightningIcon } from '@phosphor-icons/react/dist/csr/Lightning';\nimport { MapPinIcon } from '@phosphor-icons/react/dist/csr/MapPin';\nimport { MathOperationsIcon } from '@phosphor-icons/react/dist/csr/MathOperations';\nimport { MusicNoteIcon } from '@phosphor-icons/react/dist/csr/MusicNote';\nimport { NotebookIcon } from '@phosphor-icons/react/dist/csr/Notebook';\nimport { PaletteIcon } from '@phosphor-icons/react/dist/csr/Palette';\nimport { PencilLineIcon } from '@phosphor-icons/react/dist/csr/PencilLine';\nimport { PencilSimpleIcon } from '@phosphor-icons/react/dist/csr/PencilSimple';\nimport { PersonIcon } from '@phosphor-icons/react/dist/csr/Person';\nimport { ScrollIcon } from '@phosphor-icons/react/dist/csr/Scroll';\nimport { StarIcon } from '@phosphor-icons/react/dist/csr/Star';\nimport { TestTubeIcon } from '@phosphor-icons/react/dist/csr/TestTube';\nimport { TrashIcon } from '@phosphor-icons/react/dist/csr/Trash';\nimport { ChatPT } from '../../assets/icons/subjects/ChatPT';\nimport { ChatEN } from '../../assets/icons/subjects/ChatEN';\nimport { ChatES } from '../../assets/icons/subjects/ChatES';\nimport { BookOpenText } from '../../assets/icons/subjects/BookOpenText';\nimport { Microscope } from '../../assets/icons/subjects/Microscope';\nimport { HeadCircuit } from '../../assets/icons/subjects/HeadCircuit';\n\ntype PhosphorIconComponent = ComponentType<{\n size?: number;\n color?: string;\n weight?: 'thin' | 'light' | 'regular' | 'bold' | 'fill' | 'duotone';\n}>;\ntype CustomIconComponent = ComponentType<{\n size: number;\n color: string;\n}>;\n\n/**\n * Statically-imported Phosphor icons that the apps render by name.\n *\n * IMPORTANT: this is an explicit allowlist on purpose. The previous\n * implementation did `import * as PhosphorIcons` + dynamic key access, which\n * forced bundlers to ship ALL ~1500 Phosphor icons (~6MB) into every app.\n * Importing each icon from its own `dist/csr/<Name>` entry lets the bundler\n * tree-shake to only what is used. The icon names come from `subject.icon`\n * (backend) and are constrained by the backoffice IconSelector\n * (SUBJECT_ICONS). To support a new icon: add a granular import above and an\n * entry in PHOSPHOR_ICONS below. Unknown names fall back to QuestionIcon.\n */\nconst PHOSPHOR_ICONS: Record<string, PhosphorIconComponent> = {\n ArticleNyTimes: ArticleNyTimesIcon,\n Atom: AtomIcon,\n Basketball: BasketballIcon,\n Book: BookIcon,\n BookBookmark: BookBookmarkIcon,\n BookOpen: BookOpenIcon,\n Calculator: CalculatorIcon,\n CastleTurret: CastleTurretIcon,\n ChartLine: ChartLineIcon,\n ChatText: ChatTextIcon,\n CheckCircle: CheckCircleIcon,\n CheckSquare: CheckSquareIcon,\n CircleHalf: CircleHalfIcon,\n Clock: ClockIcon,\n Cylinder: CylinderIcon,\n DribbbleLogo: DribbbleLogoIcon,\n Flask: FlaskIcon,\n Globe: GlobeIcon,\n GlobeHemisphereWest: GlobeHemisphereWestIcon,\n GraduationCap: GraduationCapIcon,\n Heart: HeartIcon,\n Leaf: LeafIcon,\n Lightbulb: LightbulbIcon,\n Lightning: LightningIcon,\n MapPin: MapPinIcon,\n MathOperations: MathOperationsIcon,\n MusicNote: MusicNoteIcon,\n Notebook: NotebookIcon,\n Palette: PaletteIcon,\n PencilLine: PencilLineIcon,\n PencilSimple: PencilSimpleIcon,\n Person: PersonIcon,\n Scroll: ScrollIcon,\n Star: StarIcon,\n TestTube: TestTubeIcon,\n Trash: TrashIcon,\n};\n\n// Custom icons act as a fallback when Phosphor doesn't expose the name —\n// Chat_* have no Phosphor equivalent, and the others stay as a safety net.\nconst CUSTOM_ICONS: Record<string, CustomIconComponent> = {\n Chat_PT: ChatPT,\n Chat_EN: ChatEN,\n Chat_ES: ChatES,\n BookOpenText,\n Microscope,\n HeadCircuit,\n};\n\nexport interface IconRenderProps {\n /**\n * The name of the icon to render\n */\n iconName: string | ReactElement;\n /**\n * The color of the icon\n * @default '#000000'\n */\n color?: string;\n /**\n * The size of the icon in pixels\n * @default 24\n */\n size?: number;\n /**\n * The weight/style of the icon (for Phosphor icons)\n * @default 'regular'\n */\n weight?: 'thin' | 'light' | 'regular' | 'bold' | 'fill' | 'duotone';\n}\n\n/**\n * Dynamic icon component that renders icons based on name.\n * Supports Phosphor icons (from a tree-shakeable allowlist) and custom Chat\n * icons (ChatPT, ChatEN, ChatES). Unknown names render the Question fallback.\n *\n * @param iconName - The name of the icon to render\n * @param color - The color of the icon\n * @param size - The size of the icon in pixels\n * @param weight - The weight/style of the icon (for Phosphor icons)\n * @returns JSX element with the corresponding icon\n */\nexport const IconRender = ({\n iconName,\n color = '#000000',\n size = 24,\n weight = 'regular',\n}: IconRenderProps): JSX.Element => {\n // Guard against undefined/null iconName\n if (!iconName) {\n return <QuestionIcon size={size} color={color} weight={weight} />;\n }\n\n if (typeof iconName === 'string') {\n const PhosphorIcon = PHOSPHOR_ICONS[iconName];\n if (PhosphorIcon) {\n return <PhosphorIcon size={size} color={color} weight={weight} />;\n }\n\n const CustomIcon = CUSTOM_ICONS[iconName];\n if (CustomIcon) {\n return <CustomIcon size={size} color={color} />;\n }\n\n return <QuestionIcon size={size} color={color} weight={weight} />;\n } else {\n // Clone the ReactElement with icon props, casting to avoid TypeScript errors\n return cloneElement(iconName, {\n size,\n color: 'currentColor',\n } as Partial<{\n size: number;\n color: string;\n }>);\n }\n};\n\nexport default IconRender;\n"],"mappings":";;;;;;;;;;AAAA,SAAS,oBAAsD;AAC/D,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AAC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