TypeScript
List of exported types from the @ycloud-web/icons-preact package. These can be used to type your components when using YCloud icons in a TypeScript React project
YCloudProps
Exports all props that can be passed to an icon component and any other SVG attributes, see: SVG Presentation Attributes on MDN.
interface YCloudProps {
size?: number | string;
color?: string;
strokeWidth?: number;
absoluteStrokeWidth?: boolean;
[key: string]: any; // Any other SVG attributes
}Using YCloudProps
You can use the YCloudProps interface to type your custom icon components or when you need to work with icon props.
import { type YCloudProps } from '@ycloud-web/icons-preact';
import { Camera } from '@ycloud-web/icons-preact';
const WrapIcon = (props: YCloudProps) => {
return <Camera {...props} />;
};
export default WrapIcon;YCloudIcon
Type for individual icon components.
type YCloudIcon = React.FC<YCloudProps>;Using YCloudIcon
You can use the YCloudIcon type when you need to work with icon components directly.
import { type YCloudIcon } from '@ycloud-web/icons-preact';
interface ButtonProps {
icon: YCloudIcon;
label: string;
}
const IconButton = ({ icon: Icon, label }: ButtonProps) => {
return (
<button aria-label={label}>
<Icon size={16} />
</button>
);
};
export default IconButton;IconNode
Type for the raw SVG structure of an icon. This is an array of SVG elements and their attributes to render the icon. Not commonly used directly in application code. But can be useful for advanced use cases, such as using custom icons or custom rendering utilities.
type IconNode = [elementName: string, attrs: Record<string, string | number>][];Using IconNode
You can use the IconNode type when you need to work with the raw SVG structure of an icon.
import { type IconNode, Icon } from '@ycloud-web/icons-preact';
const customIcon: IconNode = [
['circle', { cx: 12, cy: 12, r: 10 }],
['line', { x1: 12, y1: 8, x2: 12, y2: 12 }],
['line', { x1: 12, y1: 16, x2: 12, y2: 16 }],
];
const MyCustomIcon = () => {
return (
<Icon
iconNode={customIcon}
size={24}
color="blue"
/>
);
};
export default MyCustomIcon;