@react-spectrum/parcel-transformer-s2-icon 1.0.1-nightly.5002 → 1.1.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.
Files changed (2) hide show
  1. package/IconTransformer.js +25 -62
  2. package/package.json +12 -5
@@ -38,30 +38,38 @@ module.exports = new Transformer({
38
38
  onlyMatchedOnce: false,
39
39
  removeMatchedSelectors: true
40
40
  },
41
- cleanupIDs: {
42
- prefix
43
- },
44
41
  convertPathData: {
45
42
  makeArcs: false
46
43
  }
47
44
  }
48
- },
49
- removeAttrs: {
50
- attrs: ['id', 'data.*'] // data attribute removal not working
45
+ }
46
+ },
47
+ {
48
+ name: 'prefixIds',
49
+ params: {
50
+ prefix
51
+ }
52
+ },
53
+ {
54
+ name: 'removeAttrs',
55
+ params: {
56
+ attrs: ['data.*']
51
57
  }
52
58
  }
53
59
  ]
54
60
  },
55
61
  replaceAttrValues: {
56
- 'var(--iconPrimary, #222)': `var(--iconPrimary, var(--lightningcss-light, ${tokens['gray-800'].sets.light.value}) var(--lightningcss-dark, ${tokens['gray-800'].sets.dark.value}))`,
57
- 'var(--spectrum-global-color-gray-800, #292929)': `var(--iconPrimary, var(--lightningcss-light, ${tokens['gray-800'].sets.light.value}) var(--lightningcss-dark, ${tokens['gray-800'].sets.dark.value}))`
62
+ 'var(--iconPrimary, #222)': `var(--iconPrimary, light-dark(${tokens['gray-800'].sets.light.value}, ${tokens['gray-800'].sets.dark.value}))`,
63
+ 'var(--iconPrimary, #222222)': `var(--iconPrimary, light-dark(${tokens['gray-800'].sets.light.value}, ${tokens['gray-800'].sets.dark.value}))`,
64
+ 'var(--iconPrimary, #292929)': `var(--iconPrimary, light-dark(${tokens['gray-800'].sets.light.value}, ${tokens['gray-800'].sets.dark.value}))`,
65
+ 'var(--spectrum-global-color-gray-800, #292929)': `var(--iconPrimary, light-dark(${tokens['gray-800'].sets.light.value}, ${tokens['gray-800'].sets.dark.value}))`
58
66
  },
59
67
  typescript: true,
68
+ ref: true,
60
69
  plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx']
61
70
  })
62
- ).replace('export default SvgComponent;', '');
63
- // will need to use svgr's templating to add ref support if we want that https://github.com/facebook/create-react-app/pull/5457
64
- let newFile = template(asset, iconName, optimized);
71
+ ).replace('export default ForwardRef;', '');
72
+ let newFile = template(asset, optimized);
65
73
  return [{
66
74
  type: 'tsx',
67
75
  content: newFile,
@@ -72,61 +80,16 @@ module.exports = new Transformer({
72
80
  }
73
81
  });
74
82
 
75
- function template(asset, iconName, svg) {
76
- let importName = iconName
77
- .replace(/^S2_Icon_(.*?)_\d+(?:x\d+)?_N$/, '$1')
78
- .replace(/^S2_(fill|lin)_(.+)_(.+_)?(\d+)$/, (m, name) => name[0].toUpperCase() + name.slice(1));
79
- let iconRename = importName;
80
- if (/^[0-9]/.test(importName)) {
81
- iconRename = '_' + importName;
82
- }
83
- let context = asset.pipeline === 'illustration' ? 'IllustrationContext' : 'IconContext';
83
+ function template(asset, svg) {
84
+ let normalizedPath = asset.filePath.replaceAll('\\', '/');
85
+ let fn = asset.pipeline === 'illustration' || normalizedPath.includes('@react-spectrum/s2/spectrum-illustrations') ? 'createIllustration' : 'createIcon';
84
86
  return (
85
- `
86
- import {IconProps, ${context}, IconContextValue} from '${asset.filePath.includes('@react-spectrum/s2') ? '~/src/Icon' : '@react-spectrum/s2'}';
87
- import {SVGProps, useRef} from 'react';
88
- import {useContextProps} from 'react-aria-components';
87
+ `"use client";
88
+ import {${fn}} from '${normalizedPath.includes('@react-spectrum/s2') ? '~/src/Icon' : '@react-spectrum/s2'}';
89
89
 
90
90
  ${svg.replace('import { SVGProps } from "react";', '')}
91
91
 
92
- export default function ${iconRename}(props: IconProps) {
93
- let ref = useRef<SVGElement>(null);
94
- let ctx;
95
- // TODO: remove this default once we release RAC and use DEFAULT_SLOT.
96
- [ctx, ref] = useContextProps({slot: props.slot || 'icon'} as IconContextValue, ref, ${context});
97
- let {render, styles} = ctx;
98
- let {
99
- UNSAFE_className,
100
- UNSAFE_style,
101
- slot,
102
- 'aria-label': ariaLabel,
103
- 'aria-hidden': ariaHidden,
104
- ...otherProps
105
- } = props;
106
-
107
- if (!ariaHidden) {
108
- ariaHidden = undefined;
109
- }
110
-
111
- let svg = (
112
- <SvgComponent
113
- {...otherProps}
114
- focusable={false}
115
- aria-label={ariaLabel}
116
- aria-hidden={ariaLabel ? (ariaHidden || undefined) : true}
117
- role="img"
118
- data-slot={slot}
119
- className={(UNSAFE_className ?? '') + ' ' + (styles || '')}
120
- style={UNSAFE_style} />
121
- );
122
-
123
- if (render) {
124
- return render(svg);
125
- }
126
-
127
- return svg;
128
- }
129
-
92
+ export default /*#__PURE__*/ ${fn}(ForwardRef);
130
93
  `
131
94
  );
132
95
  }
package/package.json CHANGED
@@ -1,13 +1,20 @@
1
1
  {
2
2
  "name": "@react-spectrum/parcel-transformer-s2-icon",
3
- "version": "1.0.1-nightly.5002+cfd890edf",
3
+ "version": "1.1.0",
4
4
  "main": "IconTransformer.js",
5
5
  "engines": {
6
- "parcel": "2.0.0-dev.1599"
6
+ "parcel": "^2.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@adobe/spectrum-tokens": "^13.0.0-beta.34",
10
- "@parcel/plugin": "2.0.0-dev.1601"
9
+ "@adobe/spectrum-tokens": "14.0.0",
10
+ "@parcel/plugin": "^2.0.0",
11
+ "@svgr/core": "^8.1.0",
12
+ "@svgr/plugin-jsx": "^8.1.0",
13
+ "@svgr/plugin-svgo": "^8.1.0",
14
+ "prettier": "^3.6.2"
15
+ },
16
+ "devDependencies": {
17
+ "prettier": "^3.3.3"
11
18
  },
12
19
  "rsp": {
13
20
  "type": "cli"
@@ -20,5 +27,5 @@
20
27
  "publishConfig": {
21
28
  "access": "public"
22
29
  },
23
- "gitHead": "cfd890edf73783cbea0b94316d69f4bdced5ed8a"
30
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
24
31
  }