-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e1121b
commit f25c883
Showing
4 changed files
with
61 additions
and
2 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
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,58 @@ | ||
import React, { SVGProps } from 'react'; | ||
|
||
interface IconPropsWithTitle extends SVGProps<SVGSVGElement> { | ||
title?: string; | ||
} | ||
|
||
interface CollecticonProps extends IconPropsWithTitle { | ||
meaningful?: boolean; | ||
size?: string; | ||
} | ||
|
||
export type Collecticon = React.ForwardRefExoticComponent< | ||
CollecticonProps & React.RefAttributes<SVGSVGElement> | ||
>; | ||
|
||
/** | ||
* Creates a collecticons component. | ||
* | ||
* @param {function} creatorFn Function to create the collecticon. | ||
*/ | ||
export function createCollecticon( | ||
creatorFn: (props: IconPropsWithTitle) => JSX.Element, | ||
iconSvgProps: IconPropsWithTitle = {} | ||
): Collecticon { | ||
const Collecticon = React.forwardRef<SVGSVGElement, CollecticonProps>( | ||
(props, ref) => { | ||
const { title, size, meaningful, ...rest } = props; | ||
|
||
const s = typeof size !== 'undefined' ? size : '1rem'; | ||
|
||
const iconProps: IconPropsWithTitle = { | ||
title, | ||
width: s, | ||
height: s, | ||
fill: 'currentColor', | ||
role: 'img', | ||
viewBox: '0 0 16 16', | ||
xmlns: 'http://www.w3.org/2000/svg', | ||
// By default icons are rendered decoratively (aria hidden true) Using | ||
// "meaningful" prop (together with a descriptive title) will enable the | ||
// icon to be understood by assistive technologies. | ||
'aria-hidden': !meaningful, | ||
...iconSvgProps, | ||
...rest | ||
}; | ||
return ( | ||
<svg {...iconProps} ref={ref}> | ||
{title && (<title>{title}</title>)} | ||
{creatorFn(iconProps)} | ||
</svg> | ||
); | ||
} | ||
); | ||
|
||
Collecticon.displayName = 'Collecticon'; | ||
|
||
return Collecticon; | ||
} |
File renamed without changes.