2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-09 16:26:25 +00:00
iconify/packages/react/src/props.ts

72 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-08-16 07:55:28 +00:00
import type { SVGProps, RefAttributes } from 'react';
2021-04-23 15:06:49 +00:00
import type { IconifyIcon } from '@iconify/types';
import type { IconifyIconCustomisations as RawIconCustomisations } from '@iconify/utils/lib/customisations';
export { RawIconCustomisations };
2021-04-23 15:06:49 +00:00
2022-04-13 06:55:07 +00:00
/**
* Icon render mode
*
* 'style' = 'bg' or 'mask', depending on icon content
* 'bg' = <span> with style using `background`
* 'mask' = <span> with style using `mask`
* 'svg' = <svg>
2022-04-13 06:55:07 +00:00
*/
export type IconifyRenderMode = 'style' | 'bg' | 'mask' | 'svg';
2022-04-13 06:55:07 +00:00
2021-04-23 15:06:49 +00:00
// Allow rotation to be string
/**
* Icon customisations
*/
2021-08-16 07:55:28 +00:00
export type IconifyIconCustomisations = Omit<
RawIconCustomisations,
'rotate'
> & {
2021-04-23 15:06:49 +00:00
rotate?: string | number;
};
/**
* Callback for when icon has been loaded (only triggered for icons loaded from API)
*/
export type IconifyIconOnLoad = (name: string) => void;
2021-04-23 15:06:49 +00:00
/**
* Icon properties
*/
export interface IconifyIconProps extends IconifyIconCustomisations {
// Icon object or icon name (must be added to storage using addIcon for offline package)
icon: IconifyIcon | string;
2022-04-13 06:55:07 +00:00
// Render mode
mode?: IconifyRenderMode;
2021-04-23 15:06:49 +00:00
// Style
color?: string;
// Shorthand properties
flip?: string;
align?: string;
// Unique id, used as base for ids for shapes. Use it to get consistent ids for server side rendering
id?: string;
// Callback to call when icon data has been loaded. Used only for icons loaded from API
onLoad?: IconifyIconOnLoad;
2021-04-23 15:06:49 +00:00
}
/**
* React component properties: generic element for Icon component, SVG for generated component
*/
2021-08-16 07:55:28 +00:00
type IconifyElementProps = SVGProps<SVGSVGElement>;
2021-04-23 15:06:49 +00:00
2021-08-16 02:04:15 +00:00
export type IconRef = RefAttributes<SVGSVGElement>;
2021-04-23 15:06:49 +00:00
export interface ReactRefProp {
ref?: IconRef;
}
/**
2021-08-16 02:04:15 +00:00
* Mix of icon properties and SVGSVGElement properties
2021-04-23 15:06:49 +00:00
*/
export type IconProps = IconifyElementProps & IconifyIconProps & ReactRefProp;