@macive/ui 0.0.14 → 0.0.16

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.
@@ -8,67 +8,85 @@ const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const css_1 = require("../../utilities/css");
9
9
  const Text_1 = require("../Text");
10
10
  const Icon_classnames_1 = __importDefault(require("./Icon.classnames"));
11
+ const react_1 = require("react");
11
12
  const COLORS_WITH_BACKDROPS = ['base', 'critical', 'highlight', 'success', 'warning'];
12
13
  function Icon({ source, color, backdrop, accessibilityLabel, size = 20, theme }) {
14
+ var _a, _b;
13
15
  let sourceType;
14
- if (typeof source === 'function') {
15
- sourceType = 'function';
16
- }
17
- else if (source === 'placeholder') {
16
+ // Detect source type
17
+ if (source === 'placeholder') {
18
18
  sourceType = 'placeholder';
19
19
  }
20
+ else if (typeof source === 'string') {
21
+ // Check if the string is a URL (absolute or relative) or an SVG data URI
22
+ if (source.startsWith('http://') ||
23
+ source.startsWith('https://') ||
24
+ source.startsWith('/') ||
25
+ source.startsWith('./') ||
26
+ source.startsWith('../')) {
27
+ sourceType = 'url';
28
+ }
29
+ else if (source.startsWith('data:image/svg+xml')) {
30
+ sourceType = 'external';
31
+ }
32
+ else {
33
+ // Treat other strings as external (fallback)
34
+ sourceType = 'external';
35
+ }
36
+ }
37
+ else if (typeof source === 'function') {
38
+ // Differentiate between plain functions and React components
39
+ if (((_a = source.prototype) === null || _a === void 0 ? void 0 : _a.isReactComponent) ||
40
+ source.name.includes('__') ||
41
+ source.$$typeof === Symbol.for('react.element')) {
42
+ sourceType = 'react-component';
43
+ }
44
+ else {
45
+ sourceType = 'function';
46
+ }
47
+ }
48
+ else if (typeof source === 'object' && source !== null) {
49
+ // Handle objects (e.g., raw SVG data or custom icon objects)
50
+ sourceType = 'object';
51
+ }
20
52
  else {
21
- sourceType = 'external';
53
+ // Fallback to placeholder for unrecognized types
54
+ sourceType = 'placeholder';
22
55
  }
23
- if (color && sourceType === 'external' && process.env.NODE_ENV === 'development') {
24
- // eslint-disable-next-line no-console
25
- console.warn('Recoloring external SVGs is not supported. Set the intended color on your SVG instead.');
56
+ // Warn for unsupported recoloring of external SVGs, URLs, or objects
57
+ if (color &&
58
+ (sourceType === 'external' || sourceType === 'url' || sourceType === 'object') &&
59
+ process.env.NODE_ENV === 'development') {
60
+ console.warn(`Recoloring ${sourceType} sources is not supported. Set the intended color on your icon source instead.`);
26
61
  }
62
+ // Warn for unsupported backdrop colors
27
63
  if (backdrop &&
28
64
  color &&
29
65
  !COLORS_WITH_BACKDROPS.includes(color) &&
30
66
  process.env.NODE_ENV === 'development') {
31
- // eslint-disable-next-line no-console
32
67
  console.warn(`The ${color} variant does not have a supported backdrop color`);
33
68
  }
34
69
  const className = (0, css_1.classNames)(Icon_classnames_1.default.Icon,
35
70
  //@ts-expect-error index
36
- color && Icon_classnames_1.default[(0, css_1.variationName)('color', color)],
37
- // color && oldStyles[color ?? 'base'],
38
- // color && styles.applyColor,
39
- backdrop && Icon_classnames_1.default.hasBackdrop);
71
+ color && Icon_classnames_1.default[(0, css_1.variationName)('color', color)], backdrop && Icon_classnames_1.default.hasBackdrop);
40
72
  const SourceComponent = source;
41
73
  const contentMarkup = {
42
74
  function: ((0, jsx_runtime_1.jsx)(SourceComponent, { size: size, theme: theme, className: Icon_classnames_1.default.Svg, focusable: 'false', "aria-hidden": 'true' })),
75
+ 'react-component': ((0, jsx_runtime_1.jsx)(SourceComponent, { size: size, className: Icon_classnames_1.default.Svg, focusable: 'false', "aria-hidden": 'true' })),
76
+ object:
77
+ // Handle objects (assume they contain SVG markup or a renderable element)
78
+ (0, react_1.isValidElement)(source) ? (source) : ((0, jsx_runtime_1.jsx)("span", { className: Icon_classnames_1.default.Svg, dangerouslySetInnerHTML: {
79
+ __html:
80
+ //@ts-expect-error index
81
+ typeof source.svg === 'string'
82
+ ? //@ts-expect-error index
83
+ source.svg
84
+ : (_b = JSON.stringify(source)) === null || _b === void 0 ? void 0 : _b.replace(/"/g, "'"),
85
+ }, "aria-hidden": 'true' })),
43
86
  placeholder: (0, jsx_runtime_1.jsx)("div", { className: Icon_classnames_1.default.Placeholder }),
44
87
  external: ((0, jsx_runtime_1.jsx)("img", { className: Icon_classnames_1.default.Img, src: `data:image/svg+xml;utf8,${source}`, alt: '', "aria-hidden": 'true' })),
88
+ url: ((0, jsx_runtime_1.jsx)("img", { className: Icon_classnames_1.default.Img, src: source, alt: '', style: { width: size, height: size }, "aria-hidden": 'true' })),
45
89
  };
46
90
  return ((0, jsx_runtime_1.jsxs)("span", { className: className, children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { as: 'span', visuallyHidden: true, children: accessibilityLabel }), contentMarkup[sourceType]] }));
47
91
  }
48
92
  exports.Icon = Icon;
49
- const oldStyles = {
50
- Icon: 'block h-[20px] w-[20px] max-h-full max-w-full m-auto',
51
- applyColor: '',
52
- hasBackdrop: 'relative flex bg-gray-100 items-center xp-4 before:absolute before:left-auto before:rounded-full before:right-auto',
53
- colorBase: 'bg-red-500 text-red-red-500',
54
- colorSubdued: 'bg-red-500 text-red-red-500',
55
- colorCritical: 'bg-red-500 text-red-red-500',
56
- colorInteractive: 'bg-red-500 text-red-red-500',
57
- colorWarning: 'bg-red-500 text-red-red-500',
58
- colorHighlight: 'bg-red-500 text-red-red-500',
59
- colorSuccess: 'bg-red-500 text-red-red-500',
60
- base: 'text-gray-600',
61
- subdued: 'text-gray-400',
62
- critical: 'text-danger',
63
- interactive: 'text-teal-500',
64
- warning: 'text-orange-500',
65
- primary: 'text-gray-500',
66
- highlight: 'text-yellow-500',
67
- success: 'text-green-500',
68
- magic: 'text-gray-500',
69
- colorPrimary: 'fill',
70
- colorMagic: 'fill',
71
- Svg: 'relative block w-full max-w-full max-h-full',
72
- Img: 'relative block w-full max-w-full max-h-full',
73
- Placeholder: 'pb-[100%]',
74
- };