jfs-components 0.0.63 → 0.0.65

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/lib/commonjs/components/Carousel/Carousel.js +12 -9
  3. package/lib/commonjs/components/Drawer/Drawer.js +116 -50
  4. package/lib/commonjs/components/IconButton/IconButton.js +42 -6
  5. package/lib/commonjs/components/IconCapsule/IconCapsule.js +5 -0
  6. package/lib/commonjs/components/Popup/Popup.js +2 -2
  7. package/lib/commonjs/components/Section/Section.js +280 -58
  8. package/lib/commonjs/components/UpiHandle/UpiHandle.js +19 -7
  9. package/lib/commonjs/icons/Icon.js +72 -75
  10. package/lib/commonjs/icons/registry.js +1 -1
  11. package/lib/commonjs/utils/MediaSource.js +181 -0
  12. package/lib/commonjs/utils/index.js +9 -1
  13. package/lib/module/components/Carousel/Carousel.js +12 -9
  14. package/lib/module/components/Drawer/Drawer.js +116 -50
  15. package/lib/module/components/IconButton/IconButton.js +42 -6
  16. package/lib/module/components/IconCapsule/IconCapsule.js +5 -0
  17. package/lib/module/components/Popup/Popup.js +2 -2
  18. package/lib/module/components/Section/Section.js +280 -58
  19. package/lib/module/components/UpiHandle/UpiHandle.js +20 -8
  20. package/lib/module/icons/Icon.js +72 -75
  21. package/lib/module/icons/registry.js +1 -1
  22. package/lib/module/utils/MediaSource.js +176 -0
  23. package/lib/module/utils/index.js +2 -1
  24. package/lib/typescript/src/components/Drawer/Drawer.d.ts +6 -1
  25. package/lib/typescript/src/components/IconButton/IconButton.d.ts +25 -14
  26. package/lib/typescript/src/components/IconCapsule/IconCapsule.d.ts +12 -1
  27. package/lib/typescript/src/components/Section/Section.d.ts +42 -1
  28. package/lib/typescript/src/components/UpiHandle/UpiHandle.d.ts +17 -3
  29. package/lib/typescript/src/icons/Icon.d.ts +35 -16
  30. package/lib/typescript/src/icons/registry.d.ts +1 -1
  31. package/lib/typescript/src/utils/MediaSource.d.ts +63 -0
  32. package/lib/typescript/src/utils/index.d.ts +2 -0
  33. package/package.json +1 -1
  34. package/src/components/Carousel/Carousel.tsx +16 -17
  35. package/src/components/Drawer/Drawer.tsx +136 -60
  36. package/src/components/IconButton/IconButton.tsx +70 -11
  37. package/src/components/IconCapsule/IconCapsule.tsx +13 -0
  38. package/src/components/Popup/Popup.tsx +2 -2
  39. package/src/components/Section/Section.tsx +411 -71
  40. package/src/components/UpiHandle/UpiHandle.tsx +37 -11
  41. package/src/icons/Icon.tsx +91 -76
  42. package/src/icons/registry.ts +1 -1
  43. package/src/utils/MediaSource.tsx +220 -0
  44. package/src/utils/index.ts +2 -0
@@ -4,97 +4,94 @@ import React from 'react';
4
4
  import { View } from 'react-native';
5
5
  import Svg, { Path } from 'react-native-svg';
6
6
  import { getIcon, hasIcon } from './registry';
7
+ import MediaSource from '../utils/MediaSource';
7
8
  import { jsx as _jsx } from "react/jsx-runtime";
8
9
  /**
9
- * Generic Icon Component
10
- *
11
- * Renders an icon from the registry by name with customizable size and color.
12
- *
13
- * @component
14
- * @param {Object} props - Component props
15
- * @param {string} props.name - Icon name from the registry (e.g., 'ic_ccv', 'ic_card')
16
- * @param {number} [props.size=24] - Icon size in pixels (width and height)
17
- * @param {string} [props.color='#141414'] - Icon color (hex, rgb, or named color)
18
- * @param {Object} [props.style] - Additional styles for the container View
19
- *
10
+ * Generic Icon component.
11
+ *
12
+ * Renders an icon from the registry by `name`, or falls back to a
13
+ * smart-detected `source` (SVG / PNG / JPG / require / SVG component /
14
+ * remote URI). External sources are tinted with `color` so they participate
15
+ * in the design-token modes just like built-in icons.
16
+ *
20
17
  * @example
21
- * ```jsx
18
+ * ```tsx
19
+ * // Built-in icon from the registry.
22
20
  * <Icon name="ic_ccv" size={24} color="#141414" />
23
- * <Icon name="ic_card" size={32} color="#5c00b5" />
24
- * <Icon name="ic_cart" size={20} color="red" />
21
+ *
22
+ * // Fallback to a remote SVG (auto-detected by the .svg extension).
23
+ * <Icon source="https://cdn.example.com/avatar.svg" size={24} color="#5c00b5" />
24
+ *
25
+ * // Fallback to a local raster asset.
26
+ * <Icon source={require('./brand.png')} size={32} />
27
+ *
28
+ * // Fallback to an SVG React component (e.g. via react-native-svg-transformer).
29
+ * import BrandLogo from './brand.svg';
30
+ * <Icon source={BrandLogo} size={24} color="red" />
25
31
  * ```
26
32
  */
27
33
  function Icon({
28
34
  name,
35
+ source,
29
36
  size = 24,
30
37
  color = '#141414',
31
38
  style,
32
39
  ...rest
33
40
  }) {
34
- // Validate icon name
35
- if (!name) {
36
- console.warn('Icon: name prop is required');
37
- return null;
38
- }
39
- if (!hasIcon(name)) {
40
- const {
41
- getIconNames
42
- } = require('./registry');
43
- console.warn(`Icon: "${name}" not found in registry. Available icons: ${getIconNames().join(', ')}`);
44
- return null;
45
- }
46
-
47
- // Get icon data from registry
48
- const iconData = getIcon(name);
49
- if (!iconData) {
50
- return null;
51
- }
52
-
53
- // Parse viewBox to get width and height for aspect ratio
54
- const viewBoxParts = iconData.viewBox.split(' ');
55
- // @ts-ignore
56
- const viewBoxWidth = parseFloat(viewBoxParts[2]) || size;
57
- // @ts-ignore
58
- const viewBoxHeight = parseFloat(viewBoxParts[3]) || size;
59
-
60
- // Calculate aspect ratio to maintain proper scaling
61
- const aspectRatio = viewBoxWidth / viewBoxHeight;
62
-
63
- // Determine actual width and height based on size and aspect ratio
64
- let width = size;
65
- let height = size;
66
-
67
- // If viewBox is not square, adjust dimensions to maintain aspect ratio
68
- if (Math.abs(aspectRatio - 1) > 0.01) {
69
- if (aspectRatio > 1) {
70
- // Wider than tall
71
- height = size / aspectRatio;
72
- } else {
73
- // Taller than wide
74
- width = size * aspectRatio;
75
- }
76
- }
77
- const containerStyle = {
41
+ const containerStyle = [{
78
42
  width: size,
79
43
  height: size,
80
44
  alignItems: 'center',
81
- justifyContent: 'center',
82
- ...style
83
- };
84
- return /*#__PURE__*/_jsx(View, {
85
- style: containerStyle,
86
- ...rest,
87
- children: /*#__PURE__*/_jsx(Svg, {
88
- width: width,
89
- height: height,
90
- viewBox: iconData.viewBox,
91
- preserveAspectRatio: "xMidYMid meet",
92
- children: /*#__PURE__*/_jsx(Path, {
93
- d: iconData.path,
94
- fill: color,
95
- fillRule: iconData.fillRule || 'nonzero'
45
+ justifyContent: 'center'
46
+ }, style];
47
+ const iconData = name && hasIcon(name) ? getIcon(name) : null;
48
+ if (iconData) {
49
+ const viewBoxParts = iconData.viewBox.split(' ');
50
+ const viewBoxWidth = parseFloat(viewBoxParts[2] ?? `${size}`) || size;
51
+ const viewBoxHeight = parseFloat(viewBoxParts[3] ?? `${size}`) || size;
52
+ const aspectRatio = viewBoxWidth / viewBoxHeight;
53
+ let width = size;
54
+ let height = size;
55
+ if (Math.abs(aspectRatio - 1) > 0.01) {
56
+ if (aspectRatio > 1) {
57
+ height = size / aspectRatio;
58
+ } else {
59
+ width = size * aspectRatio;
60
+ }
61
+ }
62
+ return /*#__PURE__*/_jsx(View, {
63
+ style: containerStyle,
64
+ ...rest,
65
+ children: /*#__PURE__*/_jsx(Svg, {
66
+ width: width,
67
+ height: height,
68
+ viewBox: iconData.viewBox,
69
+ preserveAspectRatio: "xMidYMid meet",
70
+ children: /*#__PURE__*/_jsx(Path, {
71
+ d: iconData.path,
72
+ fill: color,
73
+ fillRule: iconData.fillRule || 'nonzero'
74
+ })
75
+ })
76
+ });
77
+ }
78
+ if (source !== undefined) {
79
+ return /*#__PURE__*/_jsx(View, {
80
+ style: containerStyle,
81
+ ...rest,
82
+ children: /*#__PURE__*/_jsx(MediaSource, {
83
+ source: source,
84
+ size: size,
85
+ tintColor: color,
86
+ resizeMode: "contain"
96
87
  })
97
- })
98
- });
88
+ });
89
+ }
90
+ if (!name) {
91
+ console.warn('Icon: either `name` or `source` is required');
92
+ return null;
93
+ }
94
+ console.warn(`Icon: "${name}" not found in registry and no \`source\` fallback was provided.`);
95
+ return null;
99
96
  }
100
97
  export default Icon;