Skip to content

Commit 4f1b313

Browse files
committed
chore(example): improve example
1 parent 0dd717b commit 4f1b313

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

example/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {TanStackFormExample} from './src/views/TanStackFormExample';
88
import {AdvancedFormExample} from './src/views/AdvancedFormExample.private';
99

1010
function App(): React.JSX.Element {
11-
return <WorkoutExample />;
11+
return <FullFormExample />;
1212
}
1313

1414
export default App;

example/src/views/FullFormExample.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const FullFormExample: FunctionComponent = () => {
1111
<SwiftUI.Form>
1212
<LazyVGridSection />
1313
<TextFieldSection />
14-
<PickerSection />
14+
<PickerMenuSection />
15+
<PickerSegmentedSection />
1516
<DatePickerSection />
1617
<StepperSection />
1718
<SliderSection />
@@ -42,11 +43,33 @@ const TextFieldSection: FunctionComponent = () => {
4243
);
4344
};
4445

45-
const PickerSection: FunctionComponent = () => {
46+
const PickerMenuSection: FunctionComponent = () => {
47+
const [options, setOptions] = useState(['x1', 'x2', 'x3']);
48+
const [selectedOption, setSelectedOption] = useState(options[0]);
49+
return (
50+
<SwiftUI.Section header="Picker Menu Example">
51+
<SwiftUI.Picker
52+
label="Scale"
53+
selection={selectedOption}
54+
options={options}
55+
onChange={value => setSelectedOption(value)}
56+
pickerStyle="segmented"
57+
/>
58+
<SwiftUI.Button
59+
title={`Add a new option 'x${options.length + 1}'`}
60+
onPress={() => {
61+
setOptions([...options, `x${options.length + 1}`]);
62+
}}
63+
/>
64+
</SwiftUI.Section>
65+
);
66+
};
67+
68+
const PickerSegmentedSection: FunctionComponent = () => {
4669
const [options, setOptions] = useState(['Option 1', 'Option 2', 'Option 3']);
4770
const [selectedOption, setSelectedOption] = useState(options[0]);
4871
return (
49-
<SwiftUI.Section header="Picker Example">
72+
<SwiftUI.Section header="Picker Segmented Example">
5073
<SwiftUI.Picker
5174
label="Option"
5275
selection={selectedOption}

0 commit comments

Comments
 (0)