@leafygreen-ui/icon 14.7.0 → 14.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/esm/AIModel.js.map +1 -1
- package/dist/esm/ActivityFeed.js.map +1 -1
- package/dist/esm/AddFile.js.map +1 -1
- package/dist/esm/AllProducts.js.map +1 -1
- package/dist/esm/AnalyticsNode.js.map +1 -1
- package/dist/esm/Apps.js.map +1 -1
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/ArrowDown.js.map +1 -1
- package/dist/esm/ArrowLeft.js.map +1 -1
- package/dist/esm/ArrowRight.js.map +1 -1
- package/dist/esm/ArrowUp.js.map +1 -1
- package/dist/esm/Award.js.map +1 -1
- package/dist/esm/Beaker.js.map +1 -1
- package/dist/esm/Bell.js.map +1 -1
- package/dist/esm/Biometric.js.map +1 -1
- package/dist/esm/Boolean.js.map +1 -1
- package/dist/esm/Building.js.map +1 -1
- package/dist/esm/Bulb.js.map +1 -1
- package/dist/esm/Calendar.js.map +1 -1
- package/dist/esm/Camera.js.map +1 -1
- package/dist/esm/Cap.js.map +1 -1
- package/dist/esm/CaretDown.js.map +1 -1
- package/dist/esm/CaretLeft.js.map +1 -1
- package/dist/esm/CaretRight.js.map +1 -1
- package/dist/esm/CaretUp.js.map +1 -1
- package/dist/esm/ChartFilled.js.map +1 -1
- package/dist/esm/Charts.js.map +1 -1
- package/dist/esm/Checkmark.js.map +1 -1
- package/dist/esm/CheckmarkWithCircle.js.map +1 -1
- package/dist/esm/ChevronDown.js.map +1 -1
- package/dist/esm/ChevronLeft.js.map +1 -1
- package/dist/esm/ChevronRight.js.map +1 -1
- package/dist/esm/ChevronUp.js.map +1 -1
- package/dist/esm/Circle.js.map +1 -1
- package/dist/esm/Clock.js.map +1 -1
- package/dist/esm/ClockWithArrow.js.map +1 -1
- package/dist/esm/Clone.js.map +1 -1
- package/dist/esm/Cloud.js.map +1 -1
- package/dist/esm/Code.js.map +1 -1
- package/dist/esm/CodeBlock.js.map +1 -1
- package/dist/esm/Coin.js.map +1 -1
- package/dist/esm/Colon.js.map +1 -1
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Connect.js.map +1 -1
- package/dist/esm/Copy.js.map +1 -1
- package/dist/esm/CreditCard.js.map +1 -1
- package/dist/esm/CurlyBraces.js.map +1 -1
- package/dist/esm/Cursor.js.map +1 -1
- package/dist/esm/Dashboard.js.map +1 -1
- package/dist/esm/Database.js.map +1 -1
- package/dist/esm/Diagram.js.map +1 -1
- package/dist/esm/Diagram2.js.map +1 -1
- package/dist/esm/Diagram3.js.map +1 -1
- package/dist/esm/Disconnect.js.map +1 -1
- package/dist/esm/Download.js.map +1 -1
- package/dist/esm/Drag.js.map +1 -1
- package/dist/esm/Edit.js.map +1 -1
- package/dist/esm/Ellipsis.js.map +1 -1
- package/dist/esm/Email.js.map +1 -1
- package/dist/esm/EmptyDatabase.js.map +1 -1
- package/dist/esm/EmptyFolder.js.map +1 -1
- package/dist/esm/Eraser.js.map +1 -1
- package/dist/esm/Escalation.js.map +1 -1
- package/dist/esm/Export.js.map +1 -1
- package/dist/esm/Favorite.js.map +1 -1
- package/dist/esm/Federation.js.map +1 -1
- package/dist/esm/File.js.map +1 -1
- package/dist/esm/Filter.js.map +1 -1
- package/dist/esm/Folder.js.map +1 -1
- package/dist/esm/Format.js.map +1 -1
- package/dist/esm/FullScreenEnter.js.map +1 -1
- package/dist/esm/FullScreenExit.js.map +1 -1
- package/dist/esm/Function.js.map +1 -1
- package/dist/esm/Gauge.js.map +1 -1
- package/dist/esm/GlobeAmericas.js.map +1 -1
- package/dist/esm/GovernmentBuilding.js.map +1 -1
- package/dist/esm/Guide.js.map +1 -1
- package/dist/esm/Hash.js.map +1 -1
- package/dist/esm/HiddenSecondaryNode.js.map +1 -1
- package/dist/esm/Highlight.js.map +1 -1
- package/dist/esm/Home.js.map +1 -1
- package/dist/esm/HorizontalDrag.js.map +1 -1
- package/dist/esm/Import.js.map +1 -1
- package/dist/esm/ImportantWithCircle.js.map +1 -1
- package/dist/esm/InfoWithCircle.js.map +1 -1
- package/dist/esm/InternalEmployee.js.map +1 -1
- package/dist/esm/InviteUser.js.map +1 -1
- package/dist/esm/Key.js.map +1 -1
- package/dist/esm/Laptop.js.map +1 -1
- package/dist/esm/LightningBolt.js.map +1 -1
- package/dist/esm/Link.js.map +1 -1
- package/dist/esm/List.js.map +1 -1
- package/dist/esm/Lock.js.map +1 -1
- package/dist/esm/LogIn.js.map +1 -1
- package/dist/esm/LogOut.js.map +1 -1
- package/dist/esm/MagnifyingGlass.js.map +1 -1
- package/dist/esm/Megaphone.js.map +1 -1
- package/dist/esm/Menu.js.map +1 -1
- package/dist/esm/Minus.js.map +1 -1
- package/dist/esm/Mobile.js.map +1 -1
- package/dist/esm/Moon.js.map +1 -1
- package/dist/esm/MultiDirectionArrow.js.map +1 -1
- package/dist/esm/MultiLayers.js.map +1 -1
- package/dist/esm/NavCollapse.js.map +1 -1
- package/dist/esm/NavExpand.js.map +1 -1
- package/dist/esm/NoFilter.js.map +1 -1
- package/dist/esm/NotAllowed.js.map +1 -1
- package/dist/esm/Note.js.map +1 -1
- package/dist/esm/NumberedList.js.map +1 -1
- package/dist/esm/OpenNewTab.js.map +1 -1
- package/dist/esm/OutlineFavorite.js.map +1 -1
- package/dist/esm/Package.js.map +1 -1
- package/dist/esm/Pause.js.map +1 -1
- package/dist/esm/Pending.js.map +1 -1
- package/dist/esm/Person.js.map +1 -1
- package/dist/esm/PersonGroup.js.map +1 -1
- package/dist/esm/PersonWithLock.js.map +1 -1
- package/dist/esm/Pin.js.map +1 -1
- package/dist/esm/Play.js.map +1 -1
- package/dist/esm/Plus.js.map +1 -1
- package/dist/esm/PlusWithCircle.js.map +1 -1
- package/dist/esm/Primary.js.map +1 -1
- package/dist/esm/Project.js.map +1 -1
- package/dist/esm/QuestionMarkWithCircle.js.map +1 -1
- package/dist/esm/Read.js.map +1 -1
- package/dist/esm/Recommended.js.map +1 -1
- package/dist/esm/Redo.js.map +1 -1
- package/dist/esm/Refresh.js.map +1 -1
- package/dist/esm/Relationship.js.map +1 -1
- package/dist/esm/ReplicaSet.js.map +1 -1
- package/dist/esm/Resize.js.map +1 -1
- package/dist/esm/Resource.js.map +1 -1
- package/dist/esm/Return.js.map +1 -1
- package/dist/esm/Revert.js.map +1 -1
- package/dist/esm/Router.js.map +1 -1
- package/dist/esm/SMS.js.map +1 -1
- package/dist/esm/Save.js.map +1 -1
- package/dist/esm/SearchIndex.js.map +1 -1
- package/dist/esm/Secondary.js.map +1 -1
- package/dist/esm/Serverless.js.map +1 -1
- package/dist/esm/Settings.js.map +1 -1
- package/dist/esm/ShardedCluster.js.map +1 -1
- package/dist/esm/Shell.js.map +1 -1
- package/dist/esm/Shield.js.map +1 -1
- package/dist/esm/Shirt.js.map +1 -1
- package/dist/esm/Shortcut.js.map +1 -1
- package/dist/esm/SortAscending.js.map +1 -1
- package/dist/esm/SortDescending.js.map +1 -1
- package/dist/esm/Sparkle.js.map +1 -1
- package/dist/esm/SplitHorizontal.js.map +1 -1
- package/dist/esm/SplitVertical.js.map +1 -1
- package/dist/esm/Stitch.js.map +1 -1
- package/dist/esm/Stop.js.map +1 -1
- package/dist/esm/Streaming.js.map +1 -1
- package/dist/esm/String.js.map +1 -1
- package/dist/esm/Sun.js.map +1 -1
- package/dist/esm/Support.js.map +1 -1
- package/dist/esm/Sweep.js.map +1 -1
- package/dist/esm/Table.js.map +1 -1
- package/dist/esm/Tag.js.map +1 -1
- package/dist/esm/TemporaryTable.js.map +1 -1
- package/dist/esm/ThumbsDown.js.map +1 -1
- package/dist/esm/ThumbsUp.js.map +1 -1
- package/dist/esm/TimeSeries.js.map +1 -1
- package/dist/esm/TimeSeriesCollection.js.map +1 -1
- package/dist/esm/Trash.js.map +1 -1
- package/dist/esm/Undo.js.map +1 -1
- package/dist/esm/University.js.map +1 -1
- package/dist/esm/Unlock.js.map +1 -1
- package/dist/esm/Unsorted.js.map +1 -1
- package/dist/esm/UpDownCarets.js.map +1 -1
- package/dist/esm/Upload.js.map +1 -1
- package/dist/esm/VerticalEllipsis.js.map +1 -1
- package/dist/esm/View.js.map +1 -1
- package/dist/esm/Visibility.js.map +1 -1
- package/dist/esm/VisibilityOff.js.map +1 -1
- package/dist/esm/Warning.js.map +1 -1
- package/dist/esm/Wizard.js.map +1 -1
- package/dist/esm/Wrench.js.map +1 -1
- package/dist/esm/Write.js.map +1 -1
- package/dist/esm/X.js.map +1 -1
- package/dist/esm/XWithCircle.js.map +1 -1
- package/dist/esm/glyphCommon-cTThlth0.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/types/createGlyphComponent.d.ts.map +1 -1
- package/dist/types/createGlyphComponent.spec.d.ts +2 -0
- package/dist/types/createGlyphComponent.spec.d.ts.map +1 -0
- package/dist/types/createIconComponent.d.ts.map +1 -1
- package/dist/types/createIconComponent.spec.d.ts +2 -0
- package/dist/types/createIconComponent.spec.d.ts.map +1 -0
- package/dist/types/testUtils.d.ts +10 -0
- package/dist/types/testUtils.d.ts.map +1 -0
- package/dist/umd/AIModel.js.map +1 -1
- package/dist/umd/ActivityFeed.js.map +1 -1
- package/dist/umd/AddFile.js.map +1 -1
- package/dist/umd/AllProducts.js.map +1 -1
- package/dist/umd/AnalyticsNode.js.map +1 -1
- package/dist/umd/Apps.js.map +1 -1
- package/dist/umd/Array.js.map +1 -1
- package/dist/umd/ArrowDown.js.map +1 -1
- package/dist/umd/ArrowLeft.js.map +1 -1
- package/dist/umd/ArrowRight.js.map +1 -1
- package/dist/umd/ArrowUp.js.map +1 -1
- package/dist/umd/Award.js.map +1 -1
- package/dist/umd/Beaker.js.map +1 -1
- package/dist/umd/Bell.js.map +1 -1
- package/dist/umd/Biometric.js.map +1 -1
- package/dist/umd/Boolean.js.map +1 -1
- package/dist/umd/Building.js.map +1 -1
- package/dist/umd/Bulb.js.map +1 -1
- package/dist/umd/Calendar.js.map +1 -1
- package/dist/umd/Camera.js.map +1 -1
- package/dist/umd/Cap.js.map +1 -1
- package/dist/umd/CaretDown.js.map +1 -1
- package/dist/umd/CaretLeft.js.map +1 -1
- package/dist/umd/CaretRight.js.map +1 -1
- package/dist/umd/CaretUp.js.map +1 -1
- package/dist/umd/ChartFilled.js.map +1 -1
- package/dist/umd/Charts.js.map +1 -1
- package/dist/umd/Checkmark.js.map +1 -1
- package/dist/umd/CheckmarkWithCircle.js.map +1 -1
- package/dist/umd/ChevronDown.js.map +1 -1
- package/dist/umd/ChevronLeft.js.map +1 -1
- package/dist/umd/ChevronRight.js.map +1 -1
- package/dist/umd/ChevronUp.js.map +1 -1
- package/dist/umd/Circle.js.map +1 -1
- package/dist/umd/Clock.js.map +1 -1
- package/dist/umd/ClockWithArrow.js.map +1 -1
- package/dist/umd/Clone.js.map +1 -1
- package/dist/umd/Cloud.js.map +1 -1
- package/dist/umd/Code.js.map +1 -1
- package/dist/umd/CodeBlock.js.map +1 -1
- package/dist/umd/Coin.js.map +1 -1
- package/dist/umd/Colon.js.map +1 -1
- package/dist/umd/Config.js.map +1 -1
- package/dist/umd/Connect.js.map +1 -1
- package/dist/umd/Copy.js.map +1 -1
- package/dist/umd/CreditCard.js.map +1 -1
- package/dist/umd/CurlyBraces.js.map +1 -1
- package/dist/umd/Cursor.js.map +1 -1
- package/dist/umd/Dashboard.js.map +1 -1
- package/dist/umd/Database.js.map +1 -1
- package/dist/umd/Diagram.js.map +1 -1
- package/dist/umd/Diagram2.js.map +1 -1
- package/dist/umd/Diagram3.js.map +1 -1
- package/dist/umd/Disconnect.js.map +1 -1
- package/dist/umd/Download.js.map +1 -1
- package/dist/umd/Drag.js.map +1 -1
- package/dist/umd/Edit.js.map +1 -1
- package/dist/umd/Ellipsis.js.map +1 -1
- package/dist/umd/Email.js.map +1 -1
- package/dist/umd/EmptyDatabase.js.map +1 -1
- package/dist/umd/EmptyFolder.js.map +1 -1
- package/dist/umd/Eraser.js.map +1 -1
- package/dist/umd/Escalation.js.map +1 -1
- package/dist/umd/Export.js.map +1 -1
- package/dist/umd/Favorite.js.map +1 -1
- package/dist/umd/Federation.js.map +1 -1
- package/dist/umd/File.js.map +1 -1
- package/dist/umd/Filter.js.map +1 -1
- package/dist/umd/Folder.js.map +1 -1
- package/dist/umd/Format.js.map +1 -1
- package/dist/umd/FullScreenEnter.js.map +1 -1
- package/dist/umd/FullScreenExit.js.map +1 -1
- package/dist/umd/Function.js.map +1 -1
- package/dist/umd/Gauge.js.map +1 -1
- package/dist/umd/GlobeAmericas.js.map +1 -1
- package/dist/umd/GovernmentBuilding.js.map +1 -1
- package/dist/umd/Guide.js.map +1 -1
- package/dist/umd/Hash.js.map +1 -1
- package/dist/umd/HiddenSecondaryNode.js.map +1 -1
- package/dist/umd/Highlight.js.map +1 -1
- package/dist/umd/Home.js.map +1 -1
- package/dist/umd/HorizontalDrag.js.map +1 -1
- package/dist/umd/Import.js.map +1 -1
- package/dist/umd/ImportantWithCircle.js.map +1 -1
- package/dist/umd/InfoWithCircle.js.map +1 -1
- package/dist/umd/InternalEmployee.js.map +1 -1
- package/dist/umd/InviteUser.js.map +1 -1
- package/dist/umd/Key.js.map +1 -1
- package/dist/umd/Laptop.js.map +1 -1
- package/dist/umd/LightningBolt.js.map +1 -1
- package/dist/umd/Link.js.map +1 -1
- package/dist/umd/List.js.map +1 -1
- package/dist/umd/Lock.js.map +1 -1
- package/dist/umd/LogIn.js.map +1 -1
- package/dist/umd/LogOut.js.map +1 -1
- package/dist/umd/MagnifyingGlass.js.map +1 -1
- package/dist/umd/Megaphone.js.map +1 -1
- package/dist/umd/Menu.js.map +1 -1
- package/dist/umd/Minus.js.map +1 -1
- package/dist/umd/Mobile.js.map +1 -1
- package/dist/umd/Moon.js.map +1 -1
- package/dist/umd/MultiDirectionArrow.js.map +1 -1
- package/dist/umd/MultiLayers.js.map +1 -1
- package/dist/umd/NavCollapse.js.map +1 -1
- package/dist/umd/NavExpand.js.map +1 -1
- package/dist/umd/NoFilter.js.map +1 -1
- package/dist/umd/NotAllowed.js.map +1 -1
- package/dist/umd/Note.js.map +1 -1
- package/dist/umd/NumberedList.js.map +1 -1
- package/dist/umd/OpenNewTab.js.map +1 -1
- package/dist/umd/OutlineFavorite.js.map +1 -1
- package/dist/umd/Package.js.map +1 -1
- package/dist/umd/Pause.js.map +1 -1
- package/dist/umd/Pending.js.map +1 -1
- package/dist/umd/Person.js.map +1 -1
- package/dist/umd/PersonGroup.js.map +1 -1
- package/dist/umd/PersonWithLock.js.map +1 -1
- package/dist/umd/Pin.js.map +1 -1
- package/dist/umd/Play.js.map +1 -1
- package/dist/umd/Plus.js.map +1 -1
- package/dist/umd/PlusWithCircle.js.map +1 -1
- package/dist/umd/Primary.js.map +1 -1
- package/dist/umd/Project.js.map +1 -1
- package/dist/umd/QuestionMarkWithCircle.js.map +1 -1
- package/dist/umd/Read.js.map +1 -1
- package/dist/umd/Recommended.js.map +1 -1
- package/dist/umd/Redo.js.map +1 -1
- package/dist/umd/Refresh.js.map +1 -1
- package/dist/umd/Relationship.js.map +1 -1
- package/dist/umd/ReplicaSet.js.map +1 -1
- package/dist/umd/Resize.js.map +1 -1
- package/dist/umd/Resource.js.map +1 -1
- package/dist/umd/Return.js.map +1 -1
- package/dist/umd/Revert.js.map +1 -1
- package/dist/umd/Router.js.map +1 -1
- package/dist/umd/SMS.js.map +1 -1
- package/dist/umd/Save.js.map +1 -1
- package/dist/umd/SearchIndex.js.map +1 -1
- package/dist/umd/Secondary.js.map +1 -1
- package/dist/umd/Serverless.js.map +1 -1
- package/dist/umd/Settings.js.map +1 -1
- package/dist/umd/ShardedCluster.js.map +1 -1
- package/dist/umd/Shell.js.map +1 -1
- package/dist/umd/Shield.js.map +1 -1
- package/dist/umd/Shirt.js.map +1 -1
- package/dist/umd/Shortcut.js.map +1 -1
- package/dist/umd/SortAscending.js.map +1 -1
- package/dist/umd/SortDescending.js.map +1 -1
- package/dist/umd/Sparkle.js.map +1 -1
- package/dist/umd/SplitHorizontal.js.map +1 -1
- package/dist/umd/SplitVertical.js.map +1 -1
- package/dist/umd/Stitch.js.map +1 -1
- package/dist/umd/Stop.js.map +1 -1
- package/dist/umd/Streaming.js.map +1 -1
- package/dist/umd/String.js.map +1 -1
- package/dist/umd/Sun.js.map +1 -1
- package/dist/umd/Support.js.map +1 -1
- package/dist/umd/Sweep.js.map +1 -1
- package/dist/umd/Table.js.map +1 -1
- package/dist/umd/Tag.js.map +1 -1
- package/dist/umd/TemporaryTable.js.map +1 -1
- package/dist/umd/ThumbsDown.js.map +1 -1
- package/dist/umd/ThumbsUp.js.map +1 -1
- package/dist/umd/TimeSeries.js.map +1 -1
- package/dist/umd/TimeSeriesCollection.js.map +1 -1
- package/dist/umd/Trash.js.map +1 -1
- package/dist/umd/Undo.js.map +1 -1
- package/dist/umd/University.js.map +1 -1
- package/dist/umd/Unlock.js.map +1 -1
- package/dist/umd/Unsorted.js.map +1 -1
- package/dist/umd/UpDownCarets.js.map +1 -1
- package/dist/umd/Upload.js.map +1 -1
- package/dist/umd/VerticalEllipsis.js.map +1 -1
- package/dist/umd/View.js.map +1 -1
- package/dist/umd/Visibility.js.map +1 -1
- package/dist/umd/VisibilityOff.js.map +1 -1
- package/dist/umd/Warning.js.map +1 -1
- package/dist/umd/Wizard.js.map +1 -1
- package/dist/umd/Wrench.js.map +1 -1
- package/dist/umd/Write.js.map +1 -1
- package/dist/umd/X.js.map +1 -1
- package/dist/umd/XWithCircle.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +7 -7
- package/scripts/build/build-batch.ts +13 -6
- package/scripts/build/build.ts +2 -1
- package/scripts/postbuild/index.ts +0 -5
- package/src/Icon.spec.tsx +13 -0
- package/src/Icon.stories.tsx +13 -1
- package/src/createGlyphComponent.spec.tsx +274 -0
- package/src/createGlyphComponent.tsx +3 -1
- package/src/createIconComponent.spec.tsx +395 -0
- package/src/createIconComponent.tsx +14 -1
- package/src/testUtils.tsx +26 -0
- package/stories.js +1 -1
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { createGlyphComponent } from './createGlyphComponent';
|
|
5
|
+
import { createIconComponent } from './createIconComponent';
|
|
6
|
+
import * as generatedGlyphs from './generated';
|
|
7
|
+
import { Size } from './glyphCommon';
|
|
8
|
+
import { isComponentGlyph } from './isComponentGlyph';
|
|
9
|
+
import {
|
|
10
|
+
AnotherCustomGlyph,
|
|
11
|
+
createTestSVGRComponent,
|
|
12
|
+
CustomSVGRGlyph,
|
|
13
|
+
} from './testUtils';
|
|
14
|
+
|
|
15
|
+
// Create glyph components from the SVGR components
|
|
16
|
+
const customGlyphs = {
|
|
17
|
+
CustomGlyph: createGlyphComponent('CustomGlyph', CustomSVGRGlyph),
|
|
18
|
+
AnotherGlyph: createGlyphComponent('AnotherGlyph', AnotherCustomGlyph),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe('packages/Icon/createIconComponent', () => {
|
|
22
|
+
describe('basic functionality', () => {
|
|
23
|
+
const IconComponent = createIconComponent(customGlyphs);
|
|
24
|
+
|
|
25
|
+
test('returns a function', () => {
|
|
26
|
+
expect(typeof IconComponent).toBe('function');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('returned function has the displayName: "Icon"', () => {
|
|
30
|
+
expect(IconComponent.displayName).toBe('Icon');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('returned function has the property: `isGlyph`', () => {
|
|
34
|
+
expect(IconComponent).toHaveProperty('isGlyph');
|
|
35
|
+
expect(IconComponent.isGlyph).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('returned function passes `isComponentGlyph`', () => {
|
|
39
|
+
expect(isComponentGlyph(IconComponent)).toBeTruthy();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('rendering glyphs', () => {
|
|
44
|
+
const IconComponent = createIconComponent(customGlyphs);
|
|
45
|
+
|
|
46
|
+
test('renders the correct glyph when passed a valid glyph name', () => {
|
|
47
|
+
render(<IconComponent glyph="CustomGlyph" />);
|
|
48
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
49
|
+
expect(glyph).toBeInTheDocument();
|
|
50
|
+
expect(glyph.nodeName.toLowerCase()).toBe('svg');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('renders different glyphs based on glyph prop', () => {
|
|
54
|
+
const { rerender } = render(<IconComponent glyph="CustomGlyph" />);
|
|
55
|
+
expect(screen.getByTestId('custom-svgr-glyph')).toBeInTheDocument();
|
|
56
|
+
|
|
57
|
+
rerender(<IconComponent glyph="AnotherGlyph" />);
|
|
58
|
+
expect(screen.getByTestId('another-custom-glyph')).toBeInTheDocument();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('logs an error and renders nothing when glyph does not exist', () => {
|
|
62
|
+
const consoleSpy = jest
|
|
63
|
+
.spyOn(console, 'error')
|
|
64
|
+
.mockImplementation(() => {});
|
|
65
|
+
|
|
66
|
+
const { container } = render(<IconComponent glyph="NonExistentGlyph" />);
|
|
67
|
+
|
|
68
|
+
// Should log an error
|
|
69
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
70
|
+
'Error in Icon',
|
|
71
|
+
'Could not find glyph named "NonExistentGlyph" in the icon set.',
|
|
72
|
+
undefined,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Should not render an SVG
|
|
76
|
+
const svg = container.querySelector('svg');
|
|
77
|
+
expect(svg).not.toBeInTheDocument();
|
|
78
|
+
|
|
79
|
+
consoleSpy.mockRestore();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('suggests near match when glyph name has incorrect casing', () => {
|
|
83
|
+
const consoleSpy = jest
|
|
84
|
+
.spyOn(console, 'error')
|
|
85
|
+
.mockImplementation(() => {});
|
|
86
|
+
|
|
87
|
+
render(<IconComponent glyph="custom-glyph" />);
|
|
88
|
+
|
|
89
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
90
|
+
'Error in Icon',
|
|
91
|
+
'Could not find glyph named "custom-glyph" in the icon set.',
|
|
92
|
+
'Did you mean "CustomGlyph?"',
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
consoleSpy.mockRestore();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('custom SVG support', () => {
|
|
100
|
+
const RawSVGGlyph = createTestSVGRComponent('raw-svg-glyph');
|
|
101
|
+
|
|
102
|
+
const customSVGGlyphs = {
|
|
103
|
+
RawSVG: createGlyphComponent('RawSVG', RawSVGGlyph),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const IconComponent = createIconComponent(customSVGGlyphs);
|
|
107
|
+
|
|
108
|
+
test('renders custom SVG components correctly', () => {
|
|
109
|
+
render(<IconComponent glyph="RawSVG" />);
|
|
110
|
+
const glyph = screen.getByTestId('raw-svg-glyph');
|
|
111
|
+
expect(glyph).toBeInTheDocument();
|
|
112
|
+
expect(glyph.nodeName.toLowerCase()).toBe('svg');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('applies size prop to custom SVGs', () => {
|
|
116
|
+
render(<IconComponent glyph="RawSVG" size={32} />);
|
|
117
|
+
const glyph = screen.getByTestId('raw-svg-glyph');
|
|
118
|
+
expect(glyph).toHaveAttribute('height', '32');
|
|
119
|
+
expect(glyph).toHaveAttribute('width', '32');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('applies Size enum to custom SVGs', () => {
|
|
123
|
+
render(<IconComponent glyph="RawSVG" size={Size.Large} />);
|
|
124
|
+
const glyph = screen.getByTestId('raw-svg-glyph');
|
|
125
|
+
expect(glyph).toHaveAttribute('height', '20');
|
|
126
|
+
expect(glyph).toHaveAttribute('width', '20');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('raw SVGR component support (auto-wrapped)', () => {
|
|
131
|
+
// Pass raw SVGR components directly without wrapping with createGlyphComponent
|
|
132
|
+
const RawSVGRGlyph = createTestSVGRComponent('raw-svgr-glyph');
|
|
133
|
+
|
|
134
|
+
const IconComponent = createIconComponent({ RawSVGR: RawSVGRGlyph });
|
|
135
|
+
|
|
136
|
+
test('automatically wraps raw SVGR components with createGlyphComponent', () => {
|
|
137
|
+
render(<IconComponent glyph="RawSVGR" />);
|
|
138
|
+
const glyph = screen.getByTestId('raw-svgr-glyph');
|
|
139
|
+
expect(glyph).toBeInTheDocument();
|
|
140
|
+
expect(glyph.nodeName.toLowerCase()).toBe('svg');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('applies size prop to auto-wrapped SVGR components', () => {
|
|
144
|
+
render(<IconComponent glyph="RawSVGR" size={28} />);
|
|
145
|
+
const glyph = screen.getByTestId('raw-svgr-glyph');
|
|
146
|
+
expect(glyph).toHaveAttribute('height', '28');
|
|
147
|
+
expect(glyph).toHaveAttribute('width', '28');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('applies Size enum to auto-wrapped SVGR components', () => {
|
|
151
|
+
render(<IconComponent glyph="RawSVGR" size={Size.XLarge} />);
|
|
152
|
+
const glyph = screen.getByTestId('raw-svgr-glyph');
|
|
153
|
+
expect(glyph).toHaveAttribute('height', '24');
|
|
154
|
+
expect(glyph).toHaveAttribute('width', '24');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('applies className to auto-wrapped SVGR components', () => {
|
|
158
|
+
render(<IconComponent glyph="RawSVGR" className="my-raw-class" />);
|
|
159
|
+
const glyph = screen.getByTestId('raw-svgr-glyph');
|
|
160
|
+
expect(glyph).toHaveClass('my-raw-class');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('applies fill to auto-wrapped SVGR components', () => {
|
|
164
|
+
render(<IconComponent glyph="RawSVGR" fill="red" />);
|
|
165
|
+
const glyph = screen.getByTestId('raw-svgr-glyph');
|
|
166
|
+
// Fill is applied as a CSS color via an emotion-generated class
|
|
167
|
+
expect(glyph.classList.length).toBeGreaterThan(0);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('applies accessibility props to auto-wrapped SVGR components', () => {
|
|
171
|
+
render(<IconComponent glyph="RawSVGR" />);
|
|
172
|
+
const glyph = screen.getByTestId('raw-svgr-glyph');
|
|
173
|
+
expect(glyph).toHaveAttribute('role', 'img');
|
|
174
|
+
// Default aria-label is generated from glyph name
|
|
175
|
+
expect(glyph).toHaveAttribute('aria-label', 'Raw SVGR Icon');
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('className prop', () => {
|
|
180
|
+
const IconComponent = createIconComponent(customGlyphs);
|
|
181
|
+
|
|
182
|
+
test('applies className to glyph SVG element', () => {
|
|
183
|
+
render(<IconComponent glyph="CustomGlyph" className="custom-class" />);
|
|
184
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
185
|
+
expect(glyph).toHaveClass('custom-class');
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe('className prop with custom SVGs', () => {
|
|
190
|
+
const RawSVGGlyph = createTestSVGRComponent('raw-svg-for-class');
|
|
191
|
+
|
|
192
|
+
const customSVGGlyphs = {
|
|
193
|
+
RawSVG: createGlyphComponent('RawSVG', RawSVGGlyph),
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const IconComponent = createIconComponent(customSVGGlyphs);
|
|
197
|
+
|
|
198
|
+
test('applies className to custom SVG components', () => {
|
|
199
|
+
render(<IconComponent glyph="RawSVG" className="my-custom-class" />);
|
|
200
|
+
const glyph = screen.getByTestId('raw-svg-for-class');
|
|
201
|
+
expect(glyph).toHaveClass('my-custom-class');
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('size prop', () => {
|
|
206
|
+
const IconComponent = createIconComponent(customGlyphs);
|
|
207
|
+
|
|
208
|
+
test('applies numeric size to glyph', () => {
|
|
209
|
+
render(<IconComponent glyph="CustomGlyph" size={24} />);
|
|
210
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
211
|
+
expect(glyph).toHaveAttribute('height', '24');
|
|
212
|
+
expect(glyph).toHaveAttribute('width', '24');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('applies Size.Small correctly', () => {
|
|
216
|
+
render(<IconComponent glyph="CustomGlyph" size={Size.Small} />);
|
|
217
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
218
|
+
expect(glyph).toHaveAttribute('height', '14');
|
|
219
|
+
expect(glyph).toHaveAttribute('width', '14');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('applies Size.Default correctly', () => {
|
|
223
|
+
render(<IconComponent glyph="CustomGlyph" size={Size.Default} />);
|
|
224
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
225
|
+
expect(glyph).toHaveAttribute('height', '16');
|
|
226
|
+
expect(glyph).toHaveAttribute('width', '16');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('applies Size.Large correctly', () => {
|
|
230
|
+
render(<IconComponent glyph="CustomGlyph" size={Size.Large} />);
|
|
231
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
232
|
+
expect(glyph).toHaveAttribute('height', '20');
|
|
233
|
+
expect(glyph).toHaveAttribute('width', '20');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('applies Size.XLarge correctly', () => {
|
|
237
|
+
render(<IconComponent glyph="CustomGlyph" size={Size.XLarge} />);
|
|
238
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
239
|
+
expect(glyph).toHaveAttribute('height', '24');
|
|
240
|
+
expect(glyph).toHaveAttribute('width', '24');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test('uses default size when size prop is not provided', () => {
|
|
244
|
+
render(<IconComponent glyph="CustomGlyph" />);
|
|
245
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
246
|
+
expect(glyph).toHaveAttribute('height', '16');
|
|
247
|
+
expect(glyph).toHaveAttribute('width', '16');
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe('accessibility props', () => {
|
|
252
|
+
const IconComponent = createIconComponent(customGlyphs);
|
|
253
|
+
|
|
254
|
+
test('applies role="img" by default', () => {
|
|
255
|
+
render(<IconComponent glyph="CustomGlyph" />);
|
|
256
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
257
|
+
expect(glyph).toHaveAttribute('role', 'img');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('applies role="presentation" when specified', () => {
|
|
261
|
+
render(<IconComponent glyph="CustomGlyph" role="presentation" />);
|
|
262
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
263
|
+
expect(glyph).toHaveAttribute('role', 'presentation');
|
|
264
|
+
expect(glyph).toHaveAttribute('aria-hidden', 'true');
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test('generates default aria-label when no accessibility props provided', () => {
|
|
268
|
+
render(<IconComponent glyph="CustomGlyph" />);
|
|
269
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
270
|
+
expect(glyph).toHaveAttribute('aria-label', 'Custom Glyph Icon');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('applies custom aria-label when provided', () => {
|
|
274
|
+
render(
|
|
275
|
+
<IconComponent glyph="CustomGlyph" aria-label="My Custom Label" />,
|
|
276
|
+
);
|
|
277
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
278
|
+
expect(glyph).toHaveAttribute('aria-label', 'My Custom Label');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('applies aria-labelledby when provided', () => {
|
|
282
|
+
render(
|
|
283
|
+
<IconComponent glyph="CustomGlyph" aria-labelledby="my-label-id" />,
|
|
284
|
+
);
|
|
285
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
286
|
+
expect(glyph).toHaveAttribute('aria-labelledby', 'my-label-id');
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe('fill prop', () => {
|
|
291
|
+
const IconComponent = createIconComponent(customGlyphs);
|
|
292
|
+
|
|
293
|
+
test('applies fill as CSS color via className', () => {
|
|
294
|
+
render(<IconComponent glyph="CustomGlyph" fill="red" />);
|
|
295
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
296
|
+
// Fill is applied as a CSS color via an emotion-generated class
|
|
297
|
+
expect(glyph).toHaveAttribute('class');
|
|
298
|
+
expect(glyph.classList.length).toBeGreaterThan(0);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test('applies fill alongside className', () => {
|
|
302
|
+
render(
|
|
303
|
+
<IconComponent
|
|
304
|
+
glyph="CustomGlyph"
|
|
305
|
+
fill="blue"
|
|
306
|
+
className="custom-class"
|
|
307
|
+
/>,
|
|
308
|
+
);
|
|
309
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
310
|
+
expect(glyph).toHaveClass('custom-class');
|
|
311
|
+
// Fill adds an emotion class in addition to custom-class
|
|
312
|
+
expect(glyph.classList.length).toBeGreaterThan(1);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
describe('fill prop with generated glyphs', () => {
|
|
317
|
+
const IconComponent = createIconComponent(generatedGlyphs);
|
|
318
|
+
|
|
319
|
+
test('applies fill as CSS color to generated glyph', () => {
|
|
320
|
+
render(<IconComponent glyph="Edit" fill="purple" />);
|
|
321
|
+
const glyph = screen.getByRole('img');
|
|
322
|
+
// Fill is applied as a CSS color via an emotion-generated class
|
|
323
|
+
expect(glyph).toHaveAttribute('class');
|
|
324
|
+
expect(glyph.classList.length).toBeGreaterThan(0);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe('combined props with generated glyphs', () => {
|
|
329
|
+
const IconComponent = createIconComponent(generatedGlyphs);
|
|
330
|
+
|
|
331
|
+
test('applies all props correctly together', () => {
|
|
332
|
+
render(
|
|
333
|
+
<IconComponent
|
|
334
|
+
glyph="Edit"
|
|
335
|
+
size={24}
|
|
336
|
+
className="combined-class"
|
|
337
|
+
title="Combined Title"
|
|
338
|
+
fill="green"
|
|
339
|
+
/>,
|
|
340
|
+
);
|
|
341
|
+
const glyph = screen.getByRole('img');
|
|
342
|
+
|
|
343
|
+
expect(glyph).toHaveAttribute('height', '24');
|
|
344
|
+
expect(glyph).toHaveAttribute('width', '24');
|
|
345
|
+
expect(glyph).toHaveClass('combined-class');
|
|
346
|
+
|
|
347
|
+
// Check title
|
|
348
|
+
const titleElement = glyph.querySelector('title');
|
|
349
|
+
expect(titleElement).toBeInTheDocument();
|
|
350
|
+
expect(titleElement?.textContent).toBe('Combined Title');
|
|
351
|
+
|
|
352
|
+
// Check aria-labelledby points to title
|
|
353
|
+
expect(glyph.getAttribute('aria-labelledby')).toBe(titleElement?.id);
|
|
354
|
+
|
|
355
|
+
// Fill adds an emotion class in addition to combined-class
|
|
356
|
+
expect(glyph.classList.length).toBeGreaterThan(1);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
describe('combined props with custom SVGR glyphs', () => {
|
|
361
|
+
const IconComponent = createIconComponent(customGlyphs);
|
|
362
|
+
|
|
363
|
+
test('applies size, className, and fill together', () => {
|
|
364
|
+
render(
|
|
365
|
+
<IconComponent
|
|
366
|
+
glyph="CustomGlyph"
|
|
367
|
+
size={32}
|
|
368
|
+
className="combined-custom-class"
|
|
369
|
+
fill="orange"
|
|
370
|
+
/>,
|
|
371
|
+
);
|
|
372
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
373
|
+
|
|
374
|
+
expect(glyph).toHaveAttribute('height', '32');
|
|
375
|
+
expect(glyph).toHaveAttribute('width', '32');
|
|
376
|
+
expect(glyph).toHaveClass('combined-custom-class');
|
|
377
|
+
// Fill adds an emotion class in addition to combined-custom-class
|
|
378
|
+
expect(glyph.classList.length).toBeGreaterThan(1);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
test('applies accessibility props with className', () => {
|
|
382
|
+
render(
|
|
383
|
+
<IconComponent
|
|
384
|
+
glyph="CustomGlyph"
|
|
385
|
+
className="accessible-class"
|
|
386
|
+
aria-label="Accessible Custom Icon"
|
|
387
|
+
/>,
|
|
388
|
+
);
|
|
389
|
+
const glyph = screen.getByTestId('custom-svgr-glyph');
|
|
390
|
+
|
|
391
|
+
expect(glyph).toHaveClass('accessible-class');
|
|
392
|
+
expect(glyph).toHaveAttribute('aria-label', 'Accessible Custom Icon');
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import kebabCase from 'lodash/kebabCase';
|
|
3
|
+
import mapValues from 'lodash/mapValues';
|
|
3
4
|
|
|
5
|
+
import { createGlyphComponent } from './createGlyphComponent';
|
|
4
6
|
import { Size } from './glyphCommon';
|
|
7
|
+
import { isComponentGlyph } from './isComponentGlyph';
|
|
5
8
|
import { LGGlyph } from './types';
|
|
6
9
|
|
|
7
10
|
// We omit size here because we map string values for size to numbers in this component.
|
|
@@ -27,8 +30,18 @@ type GlyphObject = Record<string, LGGlyph.Component>;
|
|
|
27
30
|
export function createIconComponent<G extends GlyphObject = GlyphObject>(
|
|
28
31
|
glyphs: G,
|
|
29
32
|
) {
|
|
33
|
+
const allGlyphsAreComponents = Object.values(glyphs).every(isComponentGlyph);
|
|
34
|
+
const glyphDict = allGlyphsAreComponents
|
|
35
|
+
? glyphs
|
|
36
|
+
: mapValues(glyphs, (val, key) => {
|
|
37
|
+
// We do not currently check for valid SVG files. TODO: LG-5827
|
|
38
|
+
if (isComponentGlyph(val)) return val;
|
|
39
|
+
|
|
40
|
+
return createGlyphComponent(key, val);
|
|
41
|
+
});
|
|
42
|
+
|
|
30
43
|
const Icon = ({ glyph, ...rest }: IconProps) => {
|
|
31
|
-
const SVGComponent =
|
|
44
|
+
const SVGComponent = glyphDict[glyph];
|
|
32
45
|
|
|
33
46
|
if (SVGComponent) {
|
|
34
47
|
return <SVGComponent {...rest} />;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { SVGR } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a mock SVGR component for testing purposes.
|
|
7
|
+
*/
|
|
8
|
+
export const createTestSVGRComponent = (testId: string): SVGR.Component => {
|
|
9
|
+
const TestComponent: SVGR.Component = ({ children, ...props }) => (
|
|
10
|
+
<svg data-testid={testId} {...props}>
|
|
11
|
+
{children}
|
|
12
|
+
</svg>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return TestComponent;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Pre-built mock components for common test scenarios
|
|
19
|
+
export const TestSVGRGlyph = createTestSVGRComponent('mock-glyph');
|
|
20
|
+
export const TestSVGRGlyphWithChildren = createTestSVGRComponent(
|
|
21
|
+
'mock-glyph-with-children',
|
|
22
|
+
);
|
|
23
|
+
export const CustomSVGRGlyph = createTestSVGRComponent('custom-svgr-glyph');
|
|
24
|
+
export const AnotherCustomGlyph = createTestSVGRComponent(
|
|
25
|
+
'another-custom-glyph',
|
|
26
|
+
);
|