-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes unicons support and introduces
CareIcons
library for intern…
…al use (#4071)
- Loading branch information
1 parent
9b1cbcd
commit 5165535
Showing
24 changed files
with
4,991 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useEffect } from "react"; | ||
import { transformIcons } from "./icon"; | ||
|
||
export interface CareIconProps { | ||
className?: string | undefined; | ||
} | ||
|
||
export default function CareIcon({ className }: CareIconProps) { | ||
useEffect(() => transformIcons(), [className]); | ||
return ( | ||
<span key={className}> | ||
<i className={`care ${className}`} /> | ||
</span> | ||
); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* Pulling the svg icon down by -0.125em places the icon onto the proper baseline of the text. */ | ||
|
||
.care-svg-icon__baseline { | ||
display: inline-block; | ||
height: 1em; | ||
overflow: visible; | ||
vertical-align: -0.125em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import "./icon.css"; | ||
import iconData from "./UniconPaths.json"; | ||
|
||
const xmlns = "http://www.w3.org/2000/svg"; | ||
|
||
const findIconName = (className) => { | ||
const iconName = className.match(/care-([a-zA-Z0-9-]+)/); | ||
return iconName ? iconName[1] : "default"; | ||
}; | ||
|
||
const getIconData = (className) => { | ||
const data = iconData[findIconName(className)]; | ||
return typeof data === "undefined" ? iconData["default"] : data; | ||
}; | ||
|
||
const createSvg = (className) => { | ||
const icon = getIconData(className); | ||
const el = document.createElementNS(xmlns, "svg"); | ||
el.setAttribute( | ||
"class", | ||
className.replace("care", "care-svg-icon__baseline") | ||
); | ||
el.setAttribute("role", "img"); | ||
el.setAttribute("xmlns", xmlns); | ||
el.setAttribute("viewBox", `0 0 ${icon[0]} ${icon[0]}`); | ||
|
||
const path = document.createElementNS(xmlns, "path"); | ||
path.setAttribute("fill", "currentColor"); | ||
path.setAttribute("d", icon[1]); | ||
el.appendChild(path); | ||
return el; | ||
}; | ||
|
||
export const transformIcons = () => { | ||
const elements = Array.from(document.getElementsByClassName("care")); | ||
elements.forEach((element) => { | ||
if (element.tagName == "I") { | ||
element.parentNode.replaceChild(createSvg(element.className), element); | ||
} | ||
}); | ||
}; | ||
|
||
export const addListener = () => { | ||
window.addEventListener("load", transformIcons); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.