@expo/html-elements 0.0.0 → 0.0.1-canary-20231129-c0ec023

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 (88) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +124 -53
  3. package/babel/__tests__/__snapshots__/transform.test.js.snap +55 -0
  4. package/babel/__tests__/fixtures/one.js +29 -0
  5. package/babel/__tests__/transform.test.js +96 -0
  6. package/babel/jest.config.js +12 -0
  7. package/babel.js +37 -3
  8. package/build/Elements.d.ts +1 -0
  9. package/build/Elements.d.ts.map +1 -0
  10. package/build/css/createSafeStyledView.d.ts +2 -0
  11. package/build/css/createSafeStyledView.d.ts.map +1 -0
  12. package/build/css/createSafeStyledView.js +5 -0
  13. package/build/css/createSafeStyledView.js.map +1 -0
  14. package/build/css/createSafeStyledView.native.d.ts +3 -0
  15. package/build/css/createSafeStyledView.native.d.ts.map +1 -0
  16. package/build/css/createSafeStyledView.native.js +10 -0
  17. package/build/css/createSafeStyledView.native.js.map +1 -0
  18. package/build/css/filterStyles.d.ts +2 -0
  19. package/build/css/filterStyles.d.ts.map +1 -0
  20. package/build/css/filterStyles.js +83 -0
  21. package/build/css/filterStyles.js.map +1 -0
  22. package/build/css/units.d.ts +1 -0
  23. package/build/css/units.d.ts.map +1 -0
  24. package/build/elements/Anchor.d.ts +3 -4
  25. package/build/elements/Anchor.d.ts.map +1 -0
  26. package/build/elements/Anchor.js +8 -4
  27. package/build/elements/Anchor.js.map +1 -1
  28. package/build/elements/Headings.d.ts +1 -0
  29. package/build/elements/Headings.d.ts.map +1 -0
  30. package/build/elements/Headings.js +26 -3
  31. package/build/elements/Headings.js.map +1 -1
  32. package/build/elements/Layout.d.ts +2 -0
  33. package/build/elements/Layout.d.ts.map +1 -0
  34. package/build/elements/Layout.js +9 -8
  35. package/build/elements/Layout.js.map +1 -1
  36. package/build/elements/Lists.d.ts +4 -1
  37. package/build/elements/Lists.d.ts.map +1 -0
  38. package/build/elements/Lists.js +8 -8
  39. package/build/elements/Lists.js.map +1 -1
  40. package/build/elements/Rules.d.ts +1 -0
  41. package/build/elements/Rules.d.ts.map +1 -0
  42. package/build/elements/Rules.js +1 -1
  43. package/build/elements/Rules.js.map +1 -1
  44. package/build/elements/Rules.web.d.ts +1 -0
  45. package/build/elements/Rules.web.d.ts.map +1 -0
  46. package/build/elements/Table.d.ts +1 -0
  47. package/build/elements/Table.d.ts.map +1 -0
  48. package/build/elements/Table.js +8 -8
  49. package/build/elements/Table.js.map +1 -1
  50. package/build/elements/Table.web.d.ts +10 -11
  51. package/build/elements/Table.web.d.ts.map +1 -0
  52. package/build/elements/Table.web.js +25 -33
  53. package/build/elements/Table.web.js.map +1 -1
  54. package/build/elements/Text.d.ts +7 -10
  55. package/build/elements/Text.d.ts.map +1 -0
  56. package/build/elements/Text.js +20 -16
  57. package/build/elements/Text.js.map +1 -1
  58. package/build/elements/Text.types.d.ts +9 -4
  59. package/build/elements/Text.types.d.ts.map +1 -0
  60. package/build/elements/Text.types.js +1 -0
  61. package/build/elements/Text.types.js.map +1 -1
  62. package/build/primitives/Image.d.ts +22 -0
  63. package/build/primitives/Image.d.ts.map +1 -0
  64. package/build/primitives/Image.js +5 -0
  65. package/build/primitives/Image.js.map +1 -0
  66. package/build/primitives/RNWView.d.ts +17 -0
  67. package/build/primitives/RNWView.d.ts.map +1 -0
  68. package/build/primitives/RNWView.js +118 -0
  69. package/build/primitives/RNWView.js.map +1 -0
  70. package/build/primitives/Table.d.ts +3 -2
  71. package/build/primitives/Table.d.ts.map +1 -0
  72. package/build/primitives/Text.d.ts +31 -8
  73. package/build/primitives/Text.d.ts.map +1 -0
  74. package/build/primitives/Text.js +3 -2
  75. package/build/primitives/Text.js.map +1 -1
  76. package/build/primitives/View.d.ts +11 -9
  77. package/build/primitives/View.d.ts.map +1 -0
  78. package/build/primitives/View.js +9 -3
  79. package/build/primitives/View.js.map +1 -1
  80. package/build/primitives/createDevView.d.ts +4 -0
  81. package/build/primitives/createDevView.d.ts.map +1 -0
  82. package/build/primitives/createDevView.js +41 -0
  83. package/build/primitives/createDevView.js.map +1 -0
  84. package/expo-html-elements-0.0.1-canary-20231129-c0ec023.tgz +0 -0
  85. package/package.json +27 -9
  86. package/build/elements/_Text.web.d.ts +0 -23
  87. package/build/elements/_Text.web.js +0 -63
  88. package/build/elements/_Text.web.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,61 @@
1
+ # Changelog
2
+
3
+ ## Unpublished
4
+
5
+ ### 🛠 Breaking changes
6
+
7
+ ### 🎉 New features
8
+
9
+ - Added support for React Native 0.73.0. ([#24971](https://github.com/expo/expo/pull/24971), [#25453](https://github.com/expo/expo/pull/25453) by [@gabrieldonadel](https://github.com/gabrieldonadel))
10
+
11
+ ### 🐛 Bug fixes
12
+
13
+ ### 💡 Others
14
+
15
+ ## 0.8.0 — 2023-11-14
16
+
17
+ ### 💡 Others
18
+
19
+ - Migrate to use non-deprecated `react-native-web` props. ([#24930](https://github.com/expo/expo/pull/24930) by [@EvanBacon](https://github.com/EvanBacon))
20
+
21
+ ## 0.7.0 — 2023-10-17
22
+
23
+ ### 💡 Others
24
+
25
+ - Ship untranspiled JSX to support custom handling of `jsx` and `createElement`. ([#24889](https://github.com/expo/expo/pull/24889) by [@EvanBacon](https://github.com/EvanBacon))
26
+
27
+ ## 0.6.2 — 2023-09-04
28
+
29
+ _This version does not introduce any user-facing changes._
30
+
31
+ ## 0.6.1 — 2023-08-02
32
+
33
+ _This version does not introduce any user-facing changes._
34
+
35
+ ## 0.6.0 — 2023-07-28
36
+
37
+ _This version does not introduce any user-facing changes._
38
+
39
+ ## 0.5.1 - 2023-06-30
40
+
41
+ ### 💡 Others
42
+
43
+ - Update snapshots. ([#23238](https://github.com/expo/expo/pull/23238) by [@gabrieldonadel](https://github.com/gabrieldonadel))
44
+
45
+ ## 0.5.0 — 2023-06-21
46
+
47
+ _This version does not introduce any user-facing changes._
48
+
49
+ ## 0.4.3 — 2023-05-08
50
+
51
+ ### 🐛 Bug fixes
52
+
53
+ - Prevent babel plugin from running on node_modules. ([#21594](https://github.com/expo/expo/pull/21594) by [@EvanBacon](https://github.com/EvanBacon))
54
+ - Prevent babel plugin from transforming `html` and `body` on web. ([#21594](https://github.com/expo/expo/pull/21594) by [@EvanBacon](https://github.com/EvanBacon))
55
+
56
+ ## 0.4.1 — 2023-02-09
57
+
58
+ ### 🎉 New features
59
+
60
+ - Strip unsupported web styles on native platforms. ([#21069](https://github.com/expo/expo/pull/21069) by [@EvanBacon](https://github.com/EvanBacon))
61
+ - Provide better assertions for text children in View components in development-mode. ([#21069](https://github.com/expo/expo/pull/21069) by [@EvanBacon](https://github.com/EvanBacon))
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  <img alt="Supports Expo Android" longdesc="Supports Expo Android" src="https://img.shields.io/badge/Android-4630EB.svg?style=flat-square&logo=ANDROID&labelColor=A4C639&logoColor=fff" />
10
10
  <!-- Web -->
11
11
  <img alt="Supports Expo Web" longdesc="Supports Expo Web" src="https://img.shields.io/badge/web-4630EB.svg?style=flat-square&logo=GOOGLE-CHROME&labelColor=4285F4&logoColor=fff" />
12
- <a aria-label="Circle CI" href="https://circleci.com/gh/expo/expo/tree/master">
12
+ <a aria-label="Circle CI" href="https://circleci.com/gh/expo/expo/tree/main">
13
13
  <img alt="Circle CI" src="https://flat.badgen.net/circleci/github/expo/expo?label=Circle%20CI&labelColor=555555&icon=circleci">
14
14
  </a>
15
15
  </p>
@@ -32,7 +32,7 @@ We at Expo recommend using platform agnostic primitives like `View`, `Image`, an
32
32
 
33
33
  Install:
34
34
 
35
- ```sh
35
+ ```
36
36
  yarn add @expo/html-elements
37
37
  ```
38
38
 
@@ -57,6 +57,7 @@ Here is a list of all the currently supported elements and the web feature they
57
57
  | [`<caption />`][html-caption] | [`<Caption />`](#caption) |
58
58
  | [`<code />`][html-code] | [`<Code />`](#code) |
59
59
  | [`<del />`][html-del] | [`<Del />`](#del) |
60
+ | [`<div />`][html-div] | [`<Div />`](#div) |
60
61
  | [`<em />`][html-em] | [`<EM />`](#em) |
61
62
  | [`<footer />`][html-footer] | [`<Footer />`](#footer) |
62
63
  | [`<h1 />`][html-h1] | [`<H1 />`](#h1) |
@@ -76,6 +77,7 @@ Here is a list of all the currently supported elements and the web feature they
76
77
  | [`<q />`][html-q] | [`<Q />`](#q) |
77
78
  | [`<s />`][html-s] | [`<S />`](#s) |
78
79
  | [`<section />`][html-section] | [`<Section />`](#section) |
80
+ | [`<span />`][html-span] | [`<Span />`](#span) |
79
81
  | [`<strong />`][html-strong] | [`<Strong />`](#strong) |
80
82
  | [`<table />`][html-table] | [`<Table />`](#table) |
81
83
  | [`<tbody />`][html-tbody] | [`<TBody />`](#tbody) |
@@ -87,15 +89,15 @@ Here is a list of all the currently supported elements and the web feature they
87
89
  | [`<tr />`][html-tr] | [`<TR />`](#tr) |
88
90
  | [`<ul />`][html-ul] | [`<UL />`](#ul) |
89
91
  | [`<li />`][html-li] | [`<LI />`](#li) |
90
- | [`<details />`][html-details] | ⏱ Pending |
91
- | [`<summary />`][html-summary] | ⏱ Pending |
92
- | [`<progress />`][html-progress] | ⏱ Pending |
93
- | [`<select />`][html-select] | ⏱ Pending |
94
- | [`<picture />`][html-picture] | ⏱ Pending |
95
- | [`<figure />`][html-figure] | ⏱ Pending |
96
- | [`<figcaption />`][html-figcaption] | ⏱ Pending |
97
- | [`<form />`][html-form] | ⏱ Pending |
98
- | [`<label />`][html-label] | ⏱ Pending |
92
+ | [`<details />`][html-details] | ⏱ Pending |
93
+ | [`<summary />`][html-summary] | ⏱ Pending |
94
+ | [`<progress />`][html-progress] | ⏱ Pending |
95
+ | [`<select />`][html-select] | ⏱ Pending |
96
+ | [`<picture />`][html-picture] | ⏱ Pending |
97
+ | [`<figure />`][html-figure] | ⏱ Pending |
98
+ | [`<figcaption />`][html-figcaption] | ⏱ Pending |
99
+ | [`<form />`][html-form] | ⏱ Pending |
100
+ | [`<label />`][html-label] | ⏱ Pending |
99
101
 
100
102
  ## External
101
103
 
@@ -105,13 +107,13 @@ Other features not implemented in this package can be found in different parts o
105
107
  | ------------------------------- | :------------------: | :--------------------------------------------------------------------------------------------------------------------: |
106
108
  | `<audio />` | `Audio` | [`expo-av`][ex-audio] |
107
109
  | `<button />` | `<Button />` | `react-native` |
108
- | `<input type="text" />` | `<TextView />` | `react-native` |
110
+ | `<input type="text" />` | `<TextInput />` | `react-native` |
109
111
  | `<input type="file" />` | `ImagePicker` | [`expo-image-picker`][ex-ipick] |
110
112
  | `<input type="file" />` | `DocumentPicker` | [`expo-document-picker`][ex-dpick] |
111
113
  | `<canvas />` | `<GLView />` | [`expo-gl`][ex-gl] & [Expo Canvas][ex-canvas] |
112
114
  | `<iframe />` | `<WebView />` | [`<WebView />`][ex-webview]. `@react-native-community/web-view` is not maintained by Expo and doesn't have web support |
113
- | [`<link />`][html-link] | None | Eject the `index.html` with `expo customize:web` and link resources directly with `<link />` |
114
- | [`<noscript />`][html-noscript] | None | Eject the `index.html` with `expo customize:web` and use `<noscript />` directly as HTML |
115
+ | [`<link />`][html-link] | None | Eject the `index.html` with `npx expo customize` and link resources directly with `<link />` |
116
+ | [`<noscript />`][html-noscript] | None | Eject the `index.html` with `npx expo customize` and use `<noscript />` directly as HTML |
115
117
  | `<div />` | `<View />` | `react-native` |
116
118
  | `<img />` | `<Image />` | `react-native` |
117
119
  | `<span />` | `<Text />` | `react-native` |
@@ -119,17 +121,17 @@ Other features not implemented in this package can be found in different parts o
119
121
  | `style="backdrop-filter"` | `<BlurView />` | [`expo-blur`][ex-blur] |
120
122
  | `style="linear-gradient()"` | `<LinearGradient />` | [`expo-linear-gradient`][ex-gradient] |
121
123
 
122
- [ex-gradient]: https://docs.expo.io/versions/latest/sdk/linear-gradient/
123
- [ex-webview]: https://docs.expo.io/versions/latest/sdk/webview/
124
- [ex-audio]: https://docs.expo.io/versions/latest/sdk/audio
125
- [ex-gl]: https://docs.expo.io/versions/latest/sdk/gl-view
124
+ [ex-gradient]: https://docs.expo.dev/versions/latest/sdk/linear-gradient/
125
+ [ex-webview]: https://docs.expo.dev/versions/latest/sdk/webview/
126
+ [ex-audio]: https://docs.expo.dev/versions/latest/sdk/audio
127
+ [ex-gl]: https://docs.expo.dev/versions/latest/sdk/gl-view
126
128
  [ex-canvas]: https://github.com/expo/expo-2d-context
127
129
  [html-noscript]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript
128
130
  [html-link]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
129
- [ex-blur]: https://docs.expo.io/versions/latest/sdk/blur-view/
130
- [ex-vid]: https://docs.expo.io/versions/latest/sdk/video/
131
- [ex-ipick]: https://docs.expo.io/versions/latest/sdk/imagepicker/
132
- [ex-dpick]: https://docs.expo.io/versions/latest/sdk/document-picker/
131
+ [ex-blur]: https://docs.expo.dev/versions/latest/sdk/blur-view/
132
+ [ex-vid]: https://docs.expo.dev/versions/latest/sdk/video/
133
+ [ex-ipick]: https://docs.expo.dev/versions/latest/sdk/imagepicker/
134
+ [ex-dpick]: https://docs.expo.dev/versions/latest/sdk/document-picker/
133
135
 
134
136
  ## Headings
135
137
 
@@ -146,10 +148,10 @@ import { H1 } from '@expo/html-elements';
146
148
  export default () => <H1>Example<H1/>
147
149
  ```
148
150
 
149
- | Platform | Output |
150
- | -------- | ------------------------------------------------------ |
151
- | Web | `<h1 aria-level="1" dir="auto" role="heading" />` |
152
- | Native | `<Text accessibilityRole="header" style={[Custom]} />` |
151
+ | Platform | Output |
152
+ | -------- | ------------------------------------------------- |
153
+ | Web | `<h1 aria-level="1" dir="auto" role="heading" />` |
154
+ | Native | `<Text role="header" style={[Custom]} />` |
153
155
 
154
156
  ### `<H2/>`
155
157
 
@@ -158,10 +160,10 @@ import { H2 } from '@expo/html-elements';
158
160
  export default () => <H2>Example<H2/>
159
161
  ```
160
162
 
161
- | Platform | Output |
162
- | -------- | ------------------------------------------------------ |
163
- | Web | `<h2 aria-level="2" dir="auto" role="heading" />` |
164
- | Native | `<Text accessibilityRole="header" style={[Custom]} />` |
163
+ | Platform | Output |
164
+ | -------- | ------------------------------------------------- |
165
+ | Web | `<h2 aria-level="2" dir="auto" role="heading" />` |
166
+ | Native | `<Text role="header" style={[Custom]} />` |
165
167
 
166
168
  ### `<H3/>`
167
169
 
@@ -170,10 +172,10 @@ import { H3 } from '@expo/html-elements';
170
172
  export default () => <H3>Example<H3/>
171
173
  ```
172
174
 
173
- | Platform | Output |
174
- | -------- | ------------------------------------------------------ |
175
- | Web | `<h3 aria-level="3" dir="auto" role="heading" />` |
176
- | Native | `<Text accessibilityRole="header" style={[Custom]} />` |
175
+ | Platform | Output |
176
+ | -------- | ------------------------------------------------- |
177
+ | Web | `<h3 aria-level="3" dir="auto" role="heading" />` |
178
+ | Native | `<Text role="header" style={[Custom]} />` |
177
179
 
178
180
  ### `<H4/>`
179
181
 
@@ -182,10 +184,10 @@ import { H4 } from '@expo/html-elements';
182
184
  export default () => <H4>Example<H4/>
183
185
  ```
184
186
 
185
- | Platform | Output |
186
- | -------- | ------------------------------------------------------ |
187
- | Web | `<h4 aria-level="4" dir="auto" role="heading" />` |
188
- | Native | `<Text accessibilityRole="header" style={[Custom]} />` |
187
+ | Platform | Output |
188
+ | -------- | ------------------------------------------------- |
189
+ | Web | `<h4 aria-level="4" dir="auto" role="heading" />` |
190
+ | Native | `<Text role="header" style={[Custom]} />` |
189
191
 
190
192
  ### `<H5/>`
191
193
 
@@ -194,10 +196,10 @@ import { H5 } from '@expo/html-elements';
194
196
  export default () => <H5>Example<H5/>
195
197
  ```
196
198
 
197
- | Platform | Output |
198
- | -------- | ------------------------------------------------------ |
199
- | Web | `<h5 aria-level="5" dir="auto" role="heading" />` |
200
- | Native | `<Text accessibilityRole="header" style={[Custom]} />` |
199
+ | Platform | Output |
200
+ | -------- | ------------------------------------------------- |
201
+ | Web | `<h5 aria-level="5" dir="auto" role="heading" />` |
202
+ | Native | `<Text role="header" style={[Custom]} />` |
201
203
 
202
204
  ### `<H6/>`
203
205
 
@@ -206,10 +208,10 @@ import { H6 } from '@expo/html-elements';
206
208
  export default () => <H6>Example<H6/>
207
209
  ```
208
210
 
209
- | Platform | Output |
210
- | -------- | ------------------------------------------------------ |
211
- | Web | `<h6 aria-level="6" dir="auto" role="heading" />` |
212
- | Native | `<Text accessibilityRole="header" style={[Custom]} />` |
211
+ | Platform | Output |
212
+ | -------- | ------------------------------------------------- |
213
+ | Web | `<h6 aria-level="6" dir="auto" role="heading" />` |
214
+ | Native | `<Text role="header" style={[Custom]} />` |
213
215
 
214
216
  ## Link
215
217
 
@@ -218,7 +220,7 @@ export default () => <H6>Example<H6/>
218
220
  You can use the anchor element with href prop to open links. On native this will attempt to use the `Linking` API to open the `href`.
219
221
 
220
222
  - The CSS style is fully normalized to match `<Text />`
221
- - For pseudo-class effects like hover and focus states check out the package [`react-native-web-hooks`](https://www.npmjs.com/package/react-native-web-hooks) | [tutorial](https://blog.expo.io/css-pseudo-class-effects-in-expo-for-web-56649f88eb6b)
223
+ - For pseudo-class effects like hover and focus states check out the package [`react-native-web-hooks`](https://www.npmjs.com/package/react-native-web-hooks) | [tutorial](https://blog.expo.dev/css-pseudo-class-effects-in-expo-for-web-56649f88eb6b)
222
224
 
223
225
  ```tsx
224
226
  import { A } from '@expo/html-elements';
@@ -230,7 +232,7 @@ export default () => <A href="#" target="_blank" />;
230
232
  | Platform | Output |
231
233
  | -------- | ------------------------------------------------------------------------------- |
232
234
  | Web | `<a data-focusable="{true}" dir="auto" href="#" role="link" target="_blank" />` |
233
- | Native | `<Text accessibilityRole="link" onPress={[Function]} />` |
235
+ | Native | `<Text role="link" onPress={[Function]} />` |
234
236
 
235
237
  ## Layout
236
238
 
@@ -253,6 +255,26 @@ Consider the following: in your app you have a basic element at the top which wr
253
255
 
254
256
  Some elements like `Footer` and `Main` have no iOS, or Android enhancements, but they'll still improve web. Using the proper HTML 5 elements will make your layout compliant with the [HTML5 outline algorithm](https://html.spec.whatwg.org/multipage/sections.html#outlines).
255
257
 
258
+ ### `<Div/>`
259
+
260
+ Renders a `<div />` on web and a `View` with no ARIA set on mobile.
261
+
262
+ ```tsx
263
+ import { Div } from '@expo/html-elements';
264
+
265
+ export default () => (
266
+ <Div>
267
+ <P>Some content in the main element</P>
268
+ </Div>
269
+ );
270
+ )
271
+ ```
272
+
273
+ | Platform | Output |
274
+ | -------- | ---------- |
275
+ | Web | `<div />` |
276
+ | Native | `<View />` |
277
+
256
278
  ### `<Nav/>`
257
279
 
258
280
  ```tsx
@@ -320,7 +342,7 @@ export default () => <Section />;
320
342
  | Platform | Output |
321
343
  | -------- | ------------------------------------------------ |
322
344
  | Web | `<section role="region" style="display:flex" />` |
323
- | Native | `<View accessibilityRole="summary" />` |
345
+ | Native | `<View role="summary" />` |
324
346
 
325
347
  ### `<Article/>`
326
348
 
@@ -393,8 +415,8 @@ export default () => (
393
415
 
394
416
  Standard paragraph element.
395
417
 
396
- | Platform | Output |
397
- | --------- | ------------------------------------------------------------- |
418
+ | Platform | Output |
419
+ | --------- | ---------------------------------------------------------- |
398
420
  | Universal | `<Text style={{ fontSize: 14, marginVertical: '1em' }} />` |
399
421
 
400
422
  ### `<B/>`
@@ -413,6 +435,14 @@ Alternate bold text.
413
435
  | --------- | ----------------------------------------- |
414
436
  | Universal | `<Text style={{ fontWeight: 'bold' }} />` |
415
437
 
438
+ ### `<Span/>`
439
+
440
+ Inline text element.
441
+
442
+ | Platform | Output |
443
+ | --------- | ---------- |
444
+ | Universal | `<Text />` |
445
+
416
446
  ### `<S/>`
417
447
 
418
448
  Strike through text.
@@ -712,11 +742,50 @@ Used to caption your table. Excepts text as a child.
712
742
  | Web | `<caption />` |
713
743
  | Native | `<Text style={[Custom]} />` |
714
744
 
715
- ## TODO
745
+ # TODO
716
746
 
717
747
  - Improve relative imports for better tree-shaking.
718
748
 
719
- ## Contributing
749
+ # Babel
750
+
751
+ You can write `react-dom` elements in your code and use the babel plugin to transform them to `@expo/html-elements` elements.
752
+
753
+ ```js
754
+ // babel.config.js
755
+ module.exports = {
756
+ plugins: ['@expo/html-elements/babel'],
757
+ };
758
+ ```
759
+
760
+ ## Input
761
+
762
+ ```js
763
+ export default function Page() {
764
+ return (
765
+ <div>
766
+ <h1>Hello World</h1>
767
+ </div>
768
+ );
769
+ }
770
+ ```
771
+
772
+ ## Output
773
+
774
+ The import is automatically added if it's not already present. All props are passed through without any additional transforms.
775
+
776
+ ```js
777
+ import { Div, H1 } from '@expo/html-elements';
778
+
779
+ export default function Page() {
780
+ return (
781
+ <Div>
782
+ <H1>Hello World</H1>
783
+ </Div>
784
+ );
785
+ }
786
+ ```
787
+
788
+ # Contributing
720
789
 
721
790
  Contributions are very welcome! Please refer to guidelines described in the [contributing guide](https://github.com/expo/expo#contributing).
722
791
 
@@ -733,6 +802,7 @@ Contributions are very welcome! Please refer to guidelines described in the [con
733
802
  [html-caption]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption
734
803
  [html-code]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code
735
804
  [html-del]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del
805
+ [html-div]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div
736
806
  [html-em]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/em
737
807
  [html-footer]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer
738
808
  [html-form]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
@@ -754,6 +824,7 @@ Contributions are very welcome! Please refer to guidelines described in the [con
754
824
  [html-q]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/q
755
825
  [html-s]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/s
756
826
  [html-section]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section
827
+ [html-span]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
757
828
  [html-small]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/small
758
829
  [html-strong]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/strong
759
830
  [html-table]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table
@@ -0,0 +1,55 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Converts basic link 1`] = `
4
+ "import { A } from "@expo/html-elements";import { jsx as _jsx } from "react/jsx-runtime";
5
+ function App() {
6
+ return _jsx(A, { href: "#", children: "Link" });
7
+ }"
8
+ `;
9
+
10
+ exports[`Converts fixture 1`] = `
11
+ "import { Main, Article, P, Code, Div } from "@expo/html-elements";import { Image } from 'react-native';import { jsx as _jsx } from "react/jsx-runtime";import { jsxs as _jsxs } from "react/jsx-runtime";
12
+
13
+ export default function App() {
14
+ return (
15
+ _jsx(Main, { className: "flex-1 items-center justify-center", children:
16
+ _jsxs(Article, { className: "md:flex bg-slate-100 rounded-xl p-8 md:p-0 dark:bg-slate-800", children: [
17
+ _jsx(Image, {
18
+ className: "w-24 h-24 md:w-48 md:h-auto md:rounded-none rounded-full mx-auto",
19
+ source: {
20
+ uri: 'https://en.gravatar.com/userimage/120276729/078ee8361156d0e1c37b90e7851fed4b.png'
21
+ },
22
+ width: "384",
23
+ height: "512" }),
24
+
25
+ _jsxs(Main, { className: "pt-6 md:p-8 text-center md:text-left space-y-4", children: [
26
+ _jsxs(P, { className: "text-lg font-medium", children: ["With ",
27
+ _jsx(Code, { children: "@expo/html-elements" }), ", you can write HTML syntax that renders to real native components. Combined with Tailwind CSS, you have an experience that makes web developers feel at home.\\u201D"] }),
28
+
29
+
30
+
31
+ _jsxs(Div, { className: "font-medium", children: [
32
+ _jsx(P, { className: "text-sky-500 dark:text-sky-400 my-0", children: "Evan Bacon" }),
33
+ _jsx(P, { className: "text-slate-700 dark:text-slate-500 my-2", children: "Engineer, Expo" })] })] })] }) }));
34
+
35
+
36
+
37
+
38
+
39
+ }"
40
+ `;
41
+
42
+ exports[`Doesn't support unknowns 1`] = `
43
+ "import { jsx as _jsx } from "react/jsx-runtime";
44
+ function App() {
45
+ return _jsx("foobar", { href: "#", children: "Link" });
46
+ }"
47
+ `;
48
+
49
+ exports[`Skips injecting the import if one is already present 1`] = `
50
+ "import { A } from "@expo/html-elements";
51
+ import { A } from '@expo/html-elements';import { jsx as _jsx } from "react/jsx-runtime";
52
+ function App() {
53
+ return _jsx(A, { href: "#", children: "Link" });
54
+ }"
55
+ `;
@@ -0,0 +1,29 @@
1
+ import { Image } from 'react-native';
2
+
3
+ export default function App() {
4
+ return (
5
+ <main className="flex-1 items-center justify-center">
6
+ <article className="md:flex bg-slate-100 rounded-xl p-8 md:p-0 dark:bg-slate-800">
7
+ <Image
8
+ className="w-24 h-24 md:w-48 md:h-auto md:rounded-none rounded-full mx-auto"
9
+ source={{
10
+ uri: 'https://en.gravatar.com/userimage/120276729/078ee8361156d0e1c37b90e7851fed4b.png',
11
+ }}
12
+ width="384"
13
+ height="512"
14
+ />
15
+ <main className="pt-6 md:p-8 text-center md:text-left space-y-4">
16
+ <p className="text-lg font-medium">
17
+ With <code>@expo/html-elements</code>, you can write HTML syntax that renders to real
18
+ native components. Combined with Tailwind CSS, you have an experience that makes web
19
+ developers feel at home.”
20
+ </p>
21
+ <div className="font-medium">
22
+ <p className="text-sky-500 dark:text-sky-400 my-0">Evan Bacon</p>
23
+ <p className="text-slate-700 dark:text-slate-500 my-2">Engineer, Expo</p>
24
+ </div>
25
+ </main>
26
+ </article>
27
+ </main>
28
+ );
29
+ }
@@ -0,0 +1,96 @@
1
+ const babel = require('@babel/core');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const plugin = require('../../babel');
6
+
7
+ const options = {
8
+ babelrc: false,
9
+ presets: [
10
+ [
11
+ require.resolve('@react-native/babel-preset'),
12
+ {
13
+ useTransformReactJSXExperimental: false,
14
+ disableImportExportTransform: true,
15
+ },
16
+ ],
17
+ ],
18
+ caller: {
19
+ name: 'metro',
20
+ platform: 'ios',
21
+ },
22
+ minified: false,
23
+ plugins: [plugin],
24
+ compact: false,
25
+
26
+ filename: 'unknown',
27
+ // Snapshot sanity
28
+ retainLines: true,
29
+ cwd: __dirname,
30
+ babelrcRoots: false,
31
+ };
32
+
33
+ it(`Doesn't support unknowns`, () => {
34
+ const sourceCode = `
35
+ function App() {
36
+ return <foobar href="#">Link</foobar>;
37
+ }`;
38
+ const { code } = babel.transform(sourceCode, options);
39
+ expect(code).toMatchSnapshot();
40
+ expect(code).not.toMatch(`@expo/html-elements`);
41
+ });
42
+
43
+ it(`Skips html and body on web`, () => {
44
+ const sourceCode = `
45
+ function App() {
46
+ return <html><body>Test</body></html>;
47
+ }`;
48
+ const { code } = babel.transform(sourceCode, {
49
+ ...options,
50
+ caller: {
51
+ ...options.caller,
52
+ platform: 'web',
53
+ },
54
+ });
55
+ expect(code).toMatch(`_jsx("html", { children: _jsx("body", { children: "Test" }) });`);
56
+ const { code: nativeCode } = babel.transform(sourceCode, options);
57
+ expect(nativeCode).toMatch(`_jsx(Div, { children: _jsx(Div, { children: "Test" }) });`);
58
+ });
59
+
60
+ it(`Skips conversion in node modules`, () => {
61
+ const sourceCode = `
62
+ function App() {
63
+ return <a href="#">Link</a>;
64
+ }`;
65
+ const { code } = babel.transform(sourceCode, {
66
+ ...options,
67
+ filename: '/node_modules/foo/bar.js',
68
+ });
69
+ expect(code).not.toMatch(`import { A } from "@expo/html-elements";`);
70
+ });
71
+
72
+ it(`Converts basic link`, () => {
73
+ const sourceCode = `
74
+ function App() {
75
+ return <a href="#">Link</a>;
76
+ }`;
77
+ const { code } = babel.transform(sourceCode, options);
78
+ expect(code).toMatchSnapshot();
79
+ expect(code).toMatch(`import { A } from "@expo/html-elements";`);
80
+ });
81
+
82
+ it(`Skips injecting the import if one is already present`, () => {
83
+ const sourceCode = `
84
+ import '@expo/html-elements';
85
+ function App() {
86
+ return <a href="#">Link</a>;
87
+ }`;
88
+ const { code } = babel.transform(sourceCode, options);
89
+ expect(code).toMatchSnapshot();
90
+ });
91
+
92
+ it(`Converts fixture`, () => {
93
+ const sourceCode = fs.readFileSync(path.join(__dirname, 'fixtures/one.js'), 'utf8');
94
+ const { code } = babel.transform(sourceCode, options);
95
+ expect(code).toMatchSnapshot();
96
+ });
@@ -0,0 +1,12 @@
1
+ const path = require('path');
2
+
3
+ const roots = ['.'];
4
+
5
+ module.exports = {
6
+ testEnvironment: 'node',
7
+ testRegex: './__tests__/.*(test|spec)\\.[jt]sx?$',
8
+ watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
9
+ rootDir: path.resolve(__dirname),
10
+ displayName: require('../package').name,
11
+ roots,
12
+ };