Skip to content

Commit 05632a4

Browse files
committed
+ Minor update
- Add transition (group) support. - Update key support.
1 parent c884e47 commit 05632a4

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,61 @@ If you want to disable this behavior, add `direct` modifier:
414414
<input v-model={userInputRef} >
415415
```
416416

417+
### Key
418+
419+
Because `key` has been deprecated in new JSX transform, we have to use `v-bind:key` instead:
420+
421+
```tsx
422+
<TransitionGroup>{
423+
userList.map(item => (
424+
<div v-bind:key={item.id}>{item.name}</div>
425+
))
426+
}</TransitionGroup>
427+
```
428+
429+
Please [check it out](https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md) for more information.
430+
431+
### Transition / TransitionGroup
432+
433+
```tsx
434+
import Vue from 'vue'
435+
436+
const Transition = Vue.component('Transition')
437+
const TransitionGroup = Vue.component('TransitionGroup')
438+
439+
setup () {
440+
return () => (
441+
<div>
442+
<TransitionGroup>
443+
<div v-bind:key='key-1'>Some element</div>
444+
<div v-bind:key='key-2'>Some element</div>
445+
</TransitionGroup>
446+
<Transition>
447+
<div>Some element</div>
448+
</Transition>
449+
</div>
450+
)
451+
}
452+
```
453+
454+
or
455+
456+
```tsx
457+
setup () {
458+
return () => (
459+
<div>
460+
<transition-group>
461+
<div v-bind:key='key-1'>Some element</div>
462+
<div v-bind:key='key-2'>Some element</div>
463+
</transition-group>
464+
<transition>
465+
<div>Some element</div>
466+
</transition>
467+
</div>
468+
)
469+
}
470+
```
471+
417472
## Compatibility
418473

419474
These format below are also available, but they are NOT recommended, just for compatibility.
@@ -431,6 +486,13 @@ These format below are also available, but they are NOT recommended, just for co
431486
<input vModel={userInpuptRef.value} />
432487
```
433488

489+
### Key
490+
491+
```tsx
492+
<div v-bind:key='key-1' />
493+
<div vBind:key='key-1' />
494+
```
495+
434496
## For Vite users
435497

436498
For Vite users, it's better to use TSC or SWC instead of built-in ESBuild. Because ESBuild is very finicky at handling JSX for now, and it gives you no room to change its behavior.

lib/jsx.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ const jsx = function (
3939
on: {}
4040
}
4141

42+
// Support for using <transition> and <transition-group>.
43+
if (tag === 'transition') {
44+
tag = 'Transition'
45+
} else if (tag === 'transition-group') {
46+
tag = 'TransitionGroup'
47+
}
48+
4249
// I treat every lowercase string as HTML element.
4350
// Because in JSX Vue component should be (Upper) CamelCase named.
4451
const isHTMLElement = checkIsHTMLElement(tag)
@@ -52,6 +59,9 @@ const jsx = function (
5259

5360
const value = config[key]
5461

62+
// Because of 'key' is deprecated in new JSX transform,
63+
// we gonna use 'v-key' or 'vKey' instead.
64+
// https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md#deprecate-spreading-key-from-objects
5565
if (checkKeyIsKey(key)) {
5666
vNodeData.key = value
5767
continue

lib/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const domPropsList = 'accept,accesskey,action,align,alt,async,autocomplete,' +
1919
const ON_EVENT_REGEXP = /^((v(-o|O)n:)|on)/
2020
const HTML_TAG_REGEXP = /^[\da-z]+$/
2121
const NATIVE_ON_REGEXP = /:native$/
22+
const KEY_REGEXP = /^v(-b|B)ind:key$/
23+
const VUE_DIRECTIVE_REGEXP = /^v(-|[A-Z])/
2224

2325
const isArray = (target: unknown): target is any[] => Array.isArray(target)
2426
const isBoolean = (target: unknown): target is boolean => typeof target === 'symbol'
@@ -38,9 +40,9 @@ const checkKeyIsOnEvent = (key: string) => ON_EVENT_REGEXP.test(key)
3840
const checkKeyIsOnObject = (key: string) => key === 'on'
3941
const checkKeyIsSlot = (key: string) => key === 'slot'
4042
const checkKeyIsScopedSlots = (key: string) => key === 'scopedSlots'
41-
const checkKeyIsKey = (key: string) => key === 'key'
43+
const checkKeyIsKey = (key: string) => KEY_REGEXP.test(key)
4244
const checkKeyIsNativeOn = (key: string) => NATIVE_ON_REGEXP.test(key)
43-
const checkKeyIsVueDirective = (key: string) => /^v(-|[A-Z])/.test(key)
45+
const checkKeyIsVueDirective = (key: string) => VUE_DIRECTIVE_REGEXP.test(key)
4446
const checkKeyIsRef = (key: string) => key === 'ref'
4547

4648
// The reason why I don't use "isRef" which is provided by @vue/composition-api is that

0 commit comments

Comments
 (0)