Skip to content

Commit 08dd188

Browse files
Copilotchiaramooney
andcommitted
Move dynamic Button examples from ButtonExample.js to ButtonExample.windows.js
Co-authored-by: chiaramooney <34109996+chiaramooney@users.noreply.github.com>
1 parent 8a169ba commit 08dd188

File tree

2 files changed

+137
-137
lines changed

2 files changed

+137
-137
lines changed

packages/@react-native-windows/tester/src/js/examples-win/Button/ButtonExample.windows.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,146 @@ exports.examples = [
273273
);
274274
},
275275
},
276+
{
277+
title: 'Button with dynamic text',
278+
description: 'Button text updates when pressed',
279+
render: function (): React.Node {
280+
return <DynamicTextButton />;
281+
},
282+
},
283+
{
284+
title: 'Button with dynamic color',
285+
description: 'Button color updates when pressed',
286+
render: function (): React.Node {
287+
return <DynamicColorButton />;
288+
},
289+
},
290+
{
291+
title: 'Button with dynamic disabled state',
292+
description: 'Button disabled state toggles when pressed',
293+
render: function (): React.Node {
294+
return <DynamicDisabledButton />;
295+
},
296+
},
297+
{
298+
title: 'Button with dynamic styling on press',
299+
description: 'Button updates styling when pressed',
300+
render: function (): React.Node {
301+
return <DynamicStyleButton />;
302+
},
303+
},
276304
];
277305

306+
// Dynamic Button Components for fast refresh testing
307+
function DynamicTextButton(): React.Node {
308+
const [buttonText, setButtonText] = React.useState('Initial Text');
309+
const [pressCount, setPressCount] = React.useState(0);
310+
311+
const onPress = () => {
312+
const newCount = pressCount + 1;
313+
setPressCount(newCount);
314+
setButtonText(`Pressed ${newCount} times`);
315+
};
316+
317+
return (
318+
<Button
319+
onPress={onPress}
320+
testID="dynamic_text_button"
321+
title={buttonText}
322+
accessibilityLabel="Press to change button text"
323+
/>
324+
);
325+
}
326+
327+
function DynamicColorButton(): React.Node {
328+
const [colorIndex, setColorIndex] = React.useState(0);
329+
const colors = ['#007AFF', '#FF3B30', '#34C759', '#FF9500', '#5856D6'];
330+
331+
const onPress = () => {
332+
setColorIndex((prev) => (prev + 1) % colors.length);
333+
};
334+
335+
return (
336+
<RNTesterThemeContext.Consumer>
337+
{theme => (
338+
<Button
339+
onPress={onPress}
340+
testID="dynamic_color_button"
341+
color={colors[colorIndex]}
342+
title="Change Color"
343+
accessibilityLabel="Press to change button color"
344+
/>
345+
)}
346+
</RNTesterThemeContext.Consumer>
347+
);
348+
}
349+
350+
function DynamicDisabledButton(): React.Node {
351+
const [isDisabled, setIsDisabled] = React.useState(false);
352+
const [toggleText, setToggleText] = React.useState('Disable Me');
353+
354+
const onPress = () => {
355+
if (!isDisabled) {
356+
setIsDisabled(true);
357+
setToggleText('Disabled');
358+
// Re-enable after 2 seconds for testing
359+
setTimeout(() => {
360+
setIsDisabled(false);
361+
setToggleText('Disable Me');
362+
}, 2000);
363+
}
364+
};
365+
366+
return (
367+
<Button
368+
disabled={isDisabled}
369+
onPress={onPress}
370+
testID="dynamic_disabled_button"
371+
title={toggleText}
372+
accessibilityLabel="Press to toggle disabled state"
373+
/>
374+
);
375+
}
376+
377+
function DynamicStyleButton(): React.Node {
378+
const [isPressed, setIsPressed] = React.useState(false);
379+
const [pressCount, setPressCount] = React.useState(0);
380+
381+
const onPress = () => {
382+
setIsPressed(true);
383+
setPressCount(prev => prev + 1);
384+
// Reset pressed state after visual feedback
385+
setTimeout(() => setIsPressed(false), 300);
386+
};
387+
388+
return (
389+
<RNTesterThemeContext.Consumer>
390+
{theme => (
391+
<View style={[styles.dynamicContainer, isPressed && styles.pressedContainer]} testID="dynamic_style_container">
392+
<Button
393+
onPress={onPress}
394+
testID="dynamic_style_button"
395+
color={isPressed ? theme.SystemRedColor : theme.LinkColor}
396+
title={`Style Button (${pressCount})`}
397+
accessibilityLabel="Press to update styling"
398+
/>
399+
</View>
400+
)}
401+
</RNTesterThemeContext.Consumer>
402+
);
403+
}
404+
278405
const styles = StyleSheet.create({
279406
container: {
280407
flexDirection: 'row',
281408
justifyContent: 'space-between',
282409
},
410+
dynamicContainer: {
411+
padding: 10,
412+
borderRadius: 5,
413+
backgroundColor: 'transparent',
414+
},
415+
pressedContainer: {
416+
backgroundColor: '#f0f0f0',
417+
},
283418
});

packages/@react-native/tester/js/examples/Button/ButtonExample.js

Lines changed: 2 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ exports.examples = [
7272
<RNTesterThemeContext.Consumer>
7373
{theme => {
7474
return (
75-
<View style={styles.container} testID="two_button_container">
75+
<View style={styles.container}>
7676
<Button
7777
onPress={() => onButtonPress('cancelled')}
7878
testID="two_cancel_button"
@@ -101,7 +101,7 @@ exports.examples = [
101101
<RNTesterThemeContext.Consumer>
102102
{theme => {
103103
return (
104-
<View style={styles.container} testID="three_button_container">
104+
<View style={styles.container}>
105105
<Button
106106
onPress={() => onButtonPress('cancelled')}
107107
testID="three_cancel_button"
@@ -221,146 +221,11 @@ exports.examples = [
221221
);
222222
},
223223
},
224-
{
225-
title: 'Button with dynamic text',
226-
description: 'Button text updates when pressed',
227-
render: function (): React.Node {
228-
return <DynamicTextButton />;
229-
},
230-
},
231-
{
232-
title: 'Button with dynamic color',
233-
description: 'Button color updates when pressed',
234-
render: function (): React.Node {
235-
return <DynamicColorButton />;
236-
},
237-
},
238-
{
239-
title: 'Button with dynamic disabled state',
240-
description: 'Button disabled state toggles when pressed',
241-
render: function (): React.Node {
242-
return <DynamicDisabledButton />;
243-
},
244-
},
245-
{
246-
title: 'Button with dynamic styling on press',
247-
description: 'Button updates styling when pressed',
248-
render: function (): React.Node {
249-
return <DynamicStyleButton />;
250-
},
251-
},
252224
];
253225

254-
// Dynamic Button Components for fast refresh testing
255-
function DynamicTextButton(): React.Node {
256-
const [buttonText, setButtonText] = React.useState('Initial Text');
257-
const [pressCount, setPressCount] = React.useState(0);
258-
259-
const onPress = () => {
260-
const newCount = pressCount + 1;
261-
setPressCount(newCount);
262-
setButtonText(`Pressed ${newCount} times`);
263-
};
264-
265-
return (
266-
<Button
267-
onPress={onPress}
268-
testID="dynamic_text_button"
269-
title={buttonText}
270-
accessibilityLabel="Press to change button text"
271-
/>
272-
);
273-
}
274-
275-
function DynamicColorButton(): React.Node {
276-
const [colorIndex, setColorIndex] = React.useState(0);
277-
const colors = ['#007AFF', '#FF3B30', '#34C759', '#FF9500', '#5856D6'];
278-
279-
const onPress = () => {
280-
setColorIndex((prev) => (prev + 1) % colors.length);
281-
};
282-
283-
return (
284-
<RNTesterThemeContext.Consumer>
285-
{theme => (
286-
<Button
287-
onPress={onPress}
288-
testID="dynamic_color_button"
289-
color={colors[colorIndex]}
290-
title="Change Color"
291-
accessibilityLabel="Press to change button color"
292-
/>
293-
)}
294-
</RNTesterThemeContext.Consumer>
295-
);
296-
}
297-
298-
function DynamicDisabledButton(): React.Node {
299-
const [isDisabled, setIsDisabled] = React.useState(false);
300-
const [toggleText, setToggleText] = React.useState('Disable Me');
301-
302-
const onPress = () => {
303-
if (!isDisabled) {
304-
setIsDisabled(true);
305-
setToggleText('Disabled');
306-
// Re-enable after 2 seconds for testing
307-
setTimeout(() => {
308-
setIsDisabled(false);
309-
setToggleText('Disable Me');
310-
}, 2000);
311-
}
312-
};
313-
314-
return (
315-
<Button
316-
disabled={isDisabled}
317-
onPress={onPress}
318-
testID="dynamic_disabled_button"
319-
title={toggleText}
320-
accessibilityLabel="Press to toggle disabled state"
321-
/>
322-
);
323-
}
324-
325-
function DynamicStyleButton(): React.Node {
326-
const [isPressed, setIsPressed] = React.useState(false);
327-
const [pressCount, setPressCount] = React.useState(0);
328-
329-
const onPress = () => {
330-
setIsPressed(true);
331-
setPressCount(prev => prev + 1);
332-
// Reset pressed state after visual feedback
333-
setTimeout(() => setIsPressed(false), 300);
334-
};
335-
336-
return (
337-
<RNTesterThemeContext.Consumer>
338-
{theme => (
339-
<View style={[styles.dynamicContainer, isPressed && styles.pressedContainer]} testID="dynamic_style_container">
340-
<Button
341-
onPress={onPress}
342-
testID="dynamic_style_button"
343-
color={isPressed ? theme.SystemRedColor : theme.LinkColor}
344-
title={`Style Button (${pressCount})`}
345-
accessibilityLabel="Press to update styling"
346-
/>
347-
</View>
348-
)}
349-
</RNTesterThemeContext.Consumer>
350-
);
351-
}
352-
353226
const styles = StyleSheet.create({
354227
container: {
355228
flexDirection: 'row',
356229
justifyContent: 'space-between',
357230
},
358-
dynamicContainer: {
359-
padding: 10,
360-
borderRadius: 5,
361-
backgroundColor: 'transparent',
362-
},
363-
pressedContainer: {
364-
backgroundColor: '#f0f0f0',
365-
},
366231
});

0 commit comments

Comments
 (0)