Skip to content

Commit 40bef8a

Browse files
committed
add transition to icon change
1 parent ccfb2e1 commit 40bef8a

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

packages/dev/s2-docs/pages/s2/home/Header.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ const colorSchemeToggleStyles = style({
3838

3939
const whiteIconStyle = iconStyle({color: 'white'});
4040

41+
const iconContainerStyles = style({
42+
position: 'relative',
43+
size: 20
44+
});
45+
4146
function ColorSchemeToggle() {
4247
let {colorScheme, toggleColorScheme, systemColorScheme} = useSettings();
4348
let isOverriding = colorScheme !== systemColorScheme;
4449
let label = isOverriding
4550
? `Using ${colorScheme} mode (press to follow system)`
4651
: `Using system ${systemColorScheme} mode (press to switch)`;
4752
let ref = useRef<HTMLButtonElement>(null);
53+
let isDark = colorScheme === 'dark';
4854

4955
return (
5056
<Button
@@ -53,7 +59,26 @@ function ColorSchemeToggle() {
5359
onPress={toggleColorScheme}
5460
className={renderProps => colorSchemeToggleStyles(renderProps)}
5561
style={pressScale(ref)}>
56-
{colorScheme === 'dark' ? <Lighten styles={whiteIconStyle} /> : <Contrast styles={whiteIconStyle} />}
62+
<span className={iconContainerStyles}>
63+
<Contrast
64+
styles={whiteIconStyle}
65+
UNSAFE_style={{
66+
position: 'absolute',
67+
inset: 0,
68+
opacity: isDark ? 0 : 1,
69+
transform: isDark ? 'rotate(-90deg) scale(0.5)' : 'rotate(0deg) scale(1)',
70+
transition: 'opacity 200ms ease-out, transform 200ms ease-out'
71+
}} />
72+
<Lighten
73+
styles={whiteIconStyle}
74+
UNSAFE_style={{
75+
position: 'absolute',
76+
inset: 0,
77+
opacity: isDark ? 1 : 0,
78+
transform: isDark ? 'rotate(0deg) scale(1)' : 'rotate(90deg) scale(0.5)',
79+
transition: 'opacity 200ms ease-out, transform 200ms ease-out'
80+
}} />
81+
</span>
5782
</Button>
5883
);
5984
}

packages/dev/s2-docs/src/Header.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,19 @@ const colorSchemeToggleStyles = style({
6666
borderWidth: 0
6767
});
6868

69+
const iconContainerStyles = style({
70+
position: 'relative',
71+
size: 20
72+
});
73+
6974
function ColorSchemeToggle() {
7075
let {colorScheme, toggleColorScheme, systemColorScheme} = useSettings();
7176
let isOverriding = colorScheme !== systemColorScheme;
7277
let label = isOverriding
7378
? `Using ${colorScheme} mode (press to use system)`
7479
: `Using system ${systemColorScheme} mode (press to switch)`;
7580
let ref = useRef(null);
81+
let isDark = colorScheme === 'dark';
7682

7783
return (
7884
<Button
@@ -81,7 +87,24 @@ function ColorSchemeToggle() {
8187
onPress={toggleColorScheme}
8288
className={renderProps => colorSchemeToggleStyles(renderProps)}
8389
style={pressScale(ref)}>
84-
{colorScheme === 'dark' ? <Lighten /> : <Contrast />}
90+
<span className={iconContainerStyles}>
91+
<Contrast
92+
UNSAFE_style={{
93+
position: 'absolute',
94+
inset: 0,
95+
opacity: isDark ? 0 : 1,
96+
transform: isDark ? 'rotate(-90deg) scale(0.5)' : 'rotate(0deg) scale(1)',
97+
transition: 'opacity 200ms ease-out, transform 200ms ease-out'
98+
}} />
99+
<Lighten
100+
UNSAFE_style={{
101+
position: 'absolute',
102+
inset: 0,
103+
opacity: isDark ? 1 : 0,
104+
transform: isDark ? 'rotate(0deg) scale(1)' : 'rotate(90deg) scale(0.5)',
105+
transition: 'opacity 200ms ease-out, transform 200ms ease-out'
106+
}} />
107+
</span>
85108
</Button>
86109
);
87110
}

packages/dev/s2-docs/src/MobileHeader.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,19 @@ const colorSchemeToggleStyles = style({
8787
borderWidth: 0
8888
});
8989

90+
const iconContainerStyles = style({
91+
position: 'relative',
92+
size: 20
93+
});
94+
9095
function ColorSchemeToggle() {
9196
let {colorScheme, toggleColorScheme, systemColorScheme} = useSettings();
9297
let isOverriding = colorScheme !== systemColorScheme;
9398
let label = isOverriding
9499
? `Using ${colorScheme} mode (press to use system)`
95100
: `Using system ${systemColorScheme} mode (press to switch)`;
96101
let ref = useRef(null);
102+
let isDark = colorScheme === 'dark';
97103

98104
return (
99105
<Button
@@ -102,7 +108,24 @@ function ColorSchemeToggle() {
102108
onPress={toggleColorScheme}
103109
className={renderProps => colorSchemeToggleStyles(renderProps)}
104110
style={pressScale(ref)}>
105-
{colorScheme === 'dark' ? <Lighten /> : <Contrast />}
111+
<span className={iconContainerStyles}>
112+
<Contrast
113+
UNSAFE_style={{
114+
position: 'absolute',
115+
inset: 0,
116+
opacity: isDark ? 0 : 1,
117+
transform: isDark ? 'rotate(-90deg) scale(0.5)' : 'rotate(0deg) scale(1)',
118+
transition: 'opacity 200ms ease-out, transform 200ms ease-out'
119+
}} />
120+
<Lighten
121+
UNSAFE_style={{
122+
position: 'absolute',
123+
inset: 0,
124+
opacity: isDark ? 1 : 0,
125+
transform: isDark ? 'rotate(0deg) scale(1)' : 'rotate(90deg) scale(0.5)',
126+
transition: 'opacity 200ms ease-out, transform 200ms ease-out'
127+
}} />
128+
</span>
106129
</Button>
107130
);
108131
}

0 commit comments

Comments
 (0)