-
Notifications
You must be signed in to change notification settings - Fork 6
/
BottomToolbarPrimaryAction.tsx
95 lines (85 loc) · 2.97 KB
/
BottomToolbarPrimaryAction.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React from 'react';
import { StyleSheet, ScrollView, View, Alert } from 'react-native';
import { ToolbarButton, Checkbox, BottomToolbarPrimaryAction, RadioButton, getColor } from '@carbon/react-native';
import DashboardIcon from '@carbon/icons/es/dashboard/20';
import MapIcon from '@carbon/icons/es/map/20';
import AddIcon from '@carbon/icons/es/add/24';
const styles = StyleSheet.create({
parentView: {
flex: 1,
},
view: {
padding: 16,
flex: 1,
},
container: {
flexGrow: 1,
paddingBottom: 64,
},
appBreaker: {
backgroundColor: getColor('tagBackgroundMagenta'),
height: 20,
},
});
export default class TestBottomToolbarPrimaryAction extends React.Component {
state = {
disabled: false,
disabledAction: false,
type: 'center',
noItems: false,
};
private get items(): ToolbarButton[] {
const { disabled } = this.state;
return [
{
text: 'Dashboard',
icon: DashboardIcon,
alignItem: 'left',
onPress: () => {
Alert.alert('Pressed dashboard');
},
},
{
text: 'Map',
icon: MapIcon,
disabled: disabled,
onPress: () => {
Alert.alert('Pressed map');
},
},
];
}
render(): React.ReactNode {
const { disabled, type, noItems, disabledAction } = this.state;
const textTypes: any = {
center: 'Center button',
left: 'Left button',
right: 'Right button',
};
let itemsToUseLeft = this.items;
let itemsToUseRight = this.items;
if (type === 'left') {
itemsToUseRight = [...itemsToUseRight, ...itemsToUseLeft];
} else if (type === 'right') {
itemsToUseLeft = [...itemsToUseRight, ...itemsToUseLeft];
}
if (noItems) {
itemsToUseLeft = [];
itemsToUseRight = [];
}
return (
<View style={styles.parentView}>
<ScrollView keyboardShouldPersistTaps="handled" contentInsetAdjustmentBehavior="automatic" contentContainerStyle={styles.container} style={styles.view}>
{Object.keys(textTypes).map((item) => (
<RadioButton key={item} checked={type === item} id={item} label={textTypes[item]} onPress={() => this.setState({ type: item })} />
))}
<Checkbox checked={disabled} id="disabled" onPress={(value) => this.setState({ disabled: value })} label="Disable second item" />
<Checkbox checked={disabledAction} id="disabledAction" onPress={(value) => this.setState({ disabledAction: value })} label="Disable primary action" />
<Checkbox checked={noItems} id="noItems" onPress={(value) => this.setState({ noItems: value })} label="No items only primary action" />
</ScrollView>
<BottomToolbarPrimaryAction leftItems={itemsToUseLeft} disabled={disabledAction} rightItems={itemsToUseRight} position={type as any} icon={AddIcon} text="Primary action" onPress={() => Alert.alert('Pressed primary button')} />
<View style={styles.appBreaker} />
</View>
);
}
}