Skip to content

Commit 2c51347

Browse files
committed
Add transition type const
1 parent 277cf6c commit 2c51347

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

compiler/apps/playground/components/TabbedWindow.tsx

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import React, {
1111
unstable_addTransitionType as addTransitionType,
1212
} from 'react';
1313
import clsx from 'clsx';
14+
import {TOGGLE_TAB_TRANSITION} from '../lib/transitionTypes';
1415

1516
export default function TabbedWindow({
1617
tabs,
@@ -26,45 +27,51 @@ export default function TabbedWindow({
2627

2728
const handleTabChange = (tab: string): void => {
2829
startTransition(() => {
29-
addTransitionType('tab');
30+
addTransitionType(TOGGLE_TAB_TRANSITION);
3031
onTabChange(tab);
3132
});
3233
};
3334

3435
return (
35-
<div className="flex-1 min-w-[550px] sm:min-w-0">
36-
37-
<div className="flex flex-col h-full max-w-full">
38-
<div className="flex p-2 flex-shrink-0">
39-
{Array.from(tabs.keys()).map(tab => {
40-
const isActive = activeTab === tab;
41-
return (
42-
<button
43-
key={tab}
44-
onClick={() => handleTabChange(tab)}
45-
className={clsx(
46-
'transition-transform py-1.5 px-1.5 xs:px-3 sm:px-4 rounded-full text-sm relative',
47-
isActive ? 'text-link' : 'hover:bg-primary/5',
48-
)}>
49-
{isActive && (
36+
<div className="flex-1 min-w-[550px] sm:min-w-0">
37+
<div className="flex flex-col h-full max-w-full">
38+
<div className="flex p-2 flex-shrink-0">
39+
{Array.from(tabs.keys()).map(tab => {
40+
const isActive = activeTab === tab;
41+
return (
42+
<button
43+
key={tab}
44+
onClick={() => handleTabChange(tab)}
45+
className={clsx(
46+
'transition-transform py-1.5 px-1.5 xs:px-3 sm:px-4 rounded-full text-sm relative',
47+
isActive ? 'text-link' : 'hover:bg-primary/5',
48+
)}>
49+
{isActive && (
50+
<ViewTransition
51+
name={transitionName}
52+
share={{
53+
[TOGGLE_TAB_TRANSITION]: 'tab-highlight',
54+
default: 'none',
55+
}}
56+
update={{default: 'none'}}>
57+
<div className="absolute inset-0 bg-highlight rounded-full" />
58+
</ViewTransition>
59+
)}
5060
<ViewTransition
51-
name={transitionName}
52-
share={{tab: 'tab-highlight'}}
53-
update={{default: 'none'}}>
54-
<div className="absolute inset-0 bg-highlight rounded-full" />
61+
update={{
62+
[TOGGLE_TAB_TRANSITION]: 'tab-text',
63+
default: 'none',
64+
}}>
65+
<span className="relative z-1">{tab}</span>
5566
</ViewTransition>
56-
)}
57-
<ViewTransition update={{tab: 'tab-text', default: 'none'}}>
58-
<span className="relative z-1">{tab}</span>
59-
</ViewTransition>
60-
</button>
61-
);
62-
})}
63-
</div>
64-
<div className="flex-1 overflow-hidden w-full h-full">
65-
{tabs.get(activeTab)}
67+
</button>
68+
);
69+
})}
70+
</div>
71+
<div className="flex-1 overflow-hidden w-full h-full">
72+
{tabs.get(activeTab)}
73+
</div>
6674
</div>
6775
</div>
68-
</div>
6976
);
7077
}

compiler/apps/playground/lib/transitionTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
*/
77

88
export const CONFIG_PANEL_TRANSITION = 'config-panel';
9+
export const TOGGLE_TAB_TRANSITION = 'toggle-tab';

0 commit comments

Comments
 (0)