@react-spectrum/parcel-transformer-s2-icon 0.1.1-nightly.5042 → 0.1.2

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 +6 -52
  2. package/package.json +7 -4
@@ -57,11 +57,11 @@ module.exports = new Transformer({
57
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}))`
58
58
  },
59
59
  typescript: true,
60
+ ref: true,
60
61
  plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx']
61
62
  })
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);
63
+ ).replace('export default ForwardRef;', '');
64
+ let newFile = template(asset, optimized);
65
65
  return [{
66
66
  type: 'tsx',
67
67
  content: newFile,
@@ -72,62 +72,16 @@ module.exports = new Transformer({
72
72
  }
73
73
  });
74
74
 
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
- }
75
+ function template(asset, svg) {
83
76
  let normalizedPath = asset.filePath.replaceAll('\\', '/');
84
77
  let context = asset.pipeline === 'illustration' || normalizedPath.includes('@react-spectrum/s2/spectrum-illustrations') ? 'IllustrationContext' : 'IconContext';
85
78
  return (
86
79
  `
87
- import {IconProps, ${context}, IconContextValue} from '${normalizedPath.includes('@react-spectrum/s2') ? '~/src/Icon' : '@react-spectrum/s2'}';
88
- import {SVGProps, useRef} from 'react';
89
- import {useContextProps} from 'react-aria-components';
80
+ import {createIcon, ${context}} from '${normalizedPath.includes('@react-spectrum/s2') ? '~/src/Icon' : '@react-spectrum/s2'}';
90
81
 
91
82
  ${svg.replace('import { SVGProps } from "react";', '')}
92
83
 
93
- export default function ${iconRename}(props: IconProps) {
94
- let ref = useRef<SVGElement>(null);
95
- let ctx;
96
- // TODO: remove this default once we release RAC and use DEFAULT_SLOT.
97
- [ctx, ref] = useContextProps({slot: props.slot || 'icon'} as IconContextValue, ref, ${context});
98
- let {render, styles} = ctx;
99
- let {
100
- UNSAFE_className,
101
- UNSAFE_style,
102
- slot,
103
- 'aria-label': ariaLabel,
104
- 'aria-hidden': ariaHidden,
105
- ...otherProps
106
- } = props;
107
-
108
- if (!ariaHidden) {
109
- ariaHidden = undefined;
110
- }
111
-
112
- let svg = (
113
- <SvgComponent
114
- {...otherProps}
115
- focusable={false}
116
- aria-label={ariaLabel}
117
- aria-hidden={ariaLabel ? (ariaHidden || undefined) : true}
118
- role="img"
119
- data-slot={slot}
120
- className={(UNSAFE_className ?? '') + ' ' + (styles || '')}
121
- style={UNSAFE_style} />
122
- );
123
-
124
- if (render) {
125
- return render(svg);
126
- }
127
-
128
- return svg;
129
- }
130
-
84
+ export default /*#__PURE__*/ createIcon(ForwardRef, ${context});
131
85
  `
132
86
  );
133
87
  }
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@react-spectrum/parcel-transformer-s2-icon",
3
- "version": "0.1.1-nightly.5042+68403fe55",
3
+ "version": "0.1.2",
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
9
  "@adobe/spectrum-tokens": "^13.0.0-beta.46",
10
- "@parcel/plugin": "2.0.0-dev.1601"
10
+ "@parcel/plugin": "^2.0.0",
11
+ "@svgr/core": "^6.2.0",
12
+ "@svgr/plugin-jsx": "^6.2.0",
13
+ "@svgr/plugin-svgo": "^6.2.0"
11
14
  },
12
15
  "rsp": {
13
16
  "type": "cli"
@@ -20,5 +23,5 @@
20
23
  "publishConfig": {
21
24
  "access": "public"
22
25
  },
23
- "gitHead": "68403fe55489dce3de1b3094c957d598ad719861"
26
+ "gitHead": "03cfde2890d0e2fe2cbbf7d57848dfd539cd7f82"
24
27
  }