Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collecticons revamp πŸ› οΈ #21

Merged
merged 13 commits into from
Jul 2, 2024
Prev Previous commit
Next Next commit
Standardize icon creation
  • Loading branch information
danielfdsilva committed Jun 24, 2024
commit f25c88397bec53bc459c7a6c305510cefe272f92
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"private": true,
"scripts": {
"icons:react": "./node_modules/@svgr/cli/bin/svgr --out-dir packages/collecticons-react/lib/icons --filename-case camel --typescript --title-prop --ref --svg-props fill=currentColor --svg-props viewBox='0 0 16 16' -- ./icons",
"icons:chakra": "./node_modules/@svgr/cli/bin/svgr --out-dir packages/collecticons-chakra/lib/icons --filename-case camel --ext tsx --template chakra-svco-template.js -- ./icons",
"icons:react": "./node_modules/@svgr/cli/bin/svgr --out-dir packages/collecticons-react/lib/icons --filename-case camel --ext tsx --template svco-template.js -- ./icons",
"icons:chakra": "./node_modules/@svgr/cli/bin/svgr --out-dir packages/collecticons-chakra/lib/icons --filename-case camel --ext tsx --template svco-template.js -- ./icons",
"icons:zip": "zip showcase/static/collecticons.zip icons/*",
"icons": "yarn icons:zip && yarn icons:react && yarn icons:chakra",
"build": "lerna run build",
Expand Down
1 change: 1 addition & 0 deletions packages/collecticons-chakra/lib/collecticon-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function createCollecticon(
};
return (
<Icon {...iconProps} ref={ref}>
{title && (<title>{title}</title>)}
{creatorFn(iconProps)}
</Icon>
);
Expand Down
58 changes: 58 additions & 0 deletions packages/collecticons-react/lib/collecticon-creator.tsx
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.