@linagora/twake-icons 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # @linagora/twake-icons [2.5.0](https://github.com/linagora/twake-ui/compare/@linagora/twake-icons@2.4.1...@linagora/twake-icons@2.5.0) (2026-06-22)
2
+
3
+
4
+ ### Features
5
+
6
+ * **twake-icons:** Use exact code from cozy-ui ([cf5ae51](https://github.com/linagora/twake-ui/commit/cf5ae517a3e37006c62a10c28116ceb3ea92a670))
7
+
1
8
  ## @linagora/twake-icons [2.4.1](https://github.com/linagora/twake-ui/compare/@linagora/twake-icons@2.4.0...@linagora/twake-icons@2.4.1) (2026-06-18)
2
9
 
3
10
 
@@ -1,10 +1,13 @@
1
- import { type SVGAttributes, type ComponentType, type ReactElement } from 'react';
2
- export interface IconProps extends SVGAttributes<SVGElement> {
3
- icon: string | ComponentType<SVGAttributes<SVGElement>> | ReactElement;
1
+ import { type ComponentType, type ReactElement, type SVGAttributes } from 'react';
2
+ export interface IconProps extends SVGAttributes<SVGSVGElement> {
3
+ icon: string | ComponentType<SVGAttributes<SVGSVGElement>> | ReactElement;
4
+ width?: number | string;
5
+ height?: number | string;
4
6
  size?: number | string;
5
7
  color?: string;
8
+ preserveColor?: boolean;
6
9
  rotate?: number;
7
10
  spin?: boolean;
8
11
  }
9
- declare function Icon({ icon, color, style, className, rotate, size, spin, ...restProps }: IconProps): ReactElement | null;
12
+ declare function Icon(props: IconProps): ReactElement | null;
10
13
  export default Icon;
@@ -1,39 +1,46 @@
1
1
  import React from 'react';
2
- import { iconBaseStyle, iconSpinStyle } from './styles';
3
- function isComponentType(value) {
2
+ import { iconSpinStyle } from './styles';
3
+ const DEFAULT_SIZE = '16';
4
+ const iconStyle = {
5
+ fill: 'currentColor',
6
+ transform: 'translateZ(0)'
7
+ };
8
+ function makeSvgObject(icon) {
9
+ const anchor = icon.startsWith('#') ? icon : `#${icon}`;
10
+ function SvgObject(props) {
11
+ return (React.createElement("svg", { ...props },
12
+ React.createElement("use", { href: anchor })));
13
+ }
14
+ SvgObject.displayName = 'SvgObject';
15
+ return SvgObject;
16
+ }
17
+ function isFunction(value) {
4
18
  return typeof value === 'function';
5
19
  }
6
- function Icon({ icon, color, style, className, rotate, size, spin, ...restProps }) {
20
+ function Icon(props) {
21
+ const { icon, width, height, color, style, className, preserveColor, rotate, size, spin, ...restProps } = props;
7
22
  if (!icon)
8
23
  return null;
9
- if (React.isValidElement(icon))
10
- return icon;
11
- const resolvedSizeNum = typeof size === 'number' ? size : parseInt(String(size ?? 16), 10) || 16;
12
- const selfStyle = { ...iconBaseStyle, ...style };
13
- if (color) {
14
- selfStyle.fill = color;
15
- }
16
- if (rotate) {
17
- selfStyle.transform = `rotate(${rotate}deg)`;
18
- }
19
- if (spin) {
20
- selfStyle.animation = iconSpinStyle.animation;
24
+ if (React.isValidElement(icon)) {
25
+ const isIconComp = icon.type === Icon;
26
+ const isImg = icon.type === 'img';
27
+ if (isIconComp || isImg)
28
+ return icon;
21
29
  }
22
- const styleWithSize = {
23
- ...selfStyle,
24
- width: resolvedSizeNum,
25
- height: resolvedSizeNum
30
+ const isPngPath = typeof icon === 'string' && icon.includes('.png');
31
+ if (isPngPath)
32
+ return (React.createElement("img", { src: icon, className: className, style: style, width: width || size || DEFAULT_SIZE, height: height || size || DEFAULT_SIZE, ...restProps }));
33
+ const Svg = isFunction(icon) ? icon : makeSvgObject(icon);
34
+ const _style = {
35
+ ...iconStyle,
36
+ ...style,
37
+ ...(color ? { fill: color } : {}),
38
+ ...(preserveColor ? { fill: 'inherit' } : {}),
39
+ ...(rotate ? { transform: `rotate(${rotate}deg)` } : {}),
40
+ ...(spin ? iconSpinStyle : {})
26
41
  };
27
- if (isComponentType(icon)) {
28
- const Svg = icon;
29
- return (React.createElement(Svg, { className: className, style: styleWithSize, width: resolvedSizeNum, height: resolvedSizeNum, ...restProps }));
30
- }
31
- if (typeof icon !== 'string')
32
- return null;
33
- if (typeof icon !== 'string')
34
- return null;
35
- const anchor = icon.includes('#') ? icon : `#${icon}`;
36
- return (React.createElement("svg", { className: className, style: styleWithSize, width: resolvedSizeNum, height: resolvedSizeNum, ...restProps },
37
- React.createElement("use", { href: anchor })));
42
+ return Svg ? (
43
+ // eslint-disable-next-line react-hooks/static-components
44
+ React.createElement(Svg, { className: className, style: _style, width: width || size || DEFAULT_SIZE, height: height || size || DEFAULT_SIZE, ...restProps })) : null;
38
45
  }
39
46
  export default Icon;
@@ -1,3 +1,2 @@
1
- import { CSSProperties } from 'react';
2
- export declare const iconBaseStyle: CSSProperties;
1
+ import { type CSSProperties } from 'react';
3
2
  export declare const iconSpinStyle: CSSProperties;
@@ -9,11 +9,6 @@ if (typeof document !== 'undefined') {
9
9
  `;
10
10
  document.head.appendChild(style);
11
11
  }
12
- export const iconBaseStyle = {
13
- fill: 'currentColor',
14
- // Fix blurry icons on Firefox
15
- transform: 'translateZ(0)'
16
- };
17
12
  export const iconSpinStyle = {
18
13
  animation: 'twake-icon-spin 1s linear infinite'
19
14
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linagora/twake-icons",
3
3
  "type": "module",
4
- "version": "2.4.1",
4
+ "version": "2.5.0",
5
5
  "description": "Icon library for Twake applications — SVG icons and illustrations",
6
6
  "author": "Twake",
7
7
  "license": "MIT",