1 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2 |
|
3 | import * as React from 'react';
|
4 | import { StyleSheet } from 'react-native';
|
5 | import { withTheme } from '../../core/theming';
|
6 | import color from 'color';
|
7 | import IconButton from '../IconButton';
|
8 | import { ToggleButtonGroupContext } from './ToggleButtonGroup';
|
9 | import { black, white } from '../../styles/colors';
|
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 | const ToggleButton = _ref => {
|
46 | let {
|
47 | icon,
|
48 | size,
|
49 | theme,
|
50 | accessibilityLabel,
|
51 | disabled,
|
52 | style,
|
53 | value,
|
54 | status,
|
55 | onPress,
|
56 | ...rest
|
57 | } = _ref;
|
58 | const borderRadius = theme.roundness;
|
59 | return React.createElement(ToggleButtonGroupContext.Consumer, null, context => {
|
60 | let backgroundColor;
|
61 | const checked = context && context.value === value || status === 'checked';
|
62 |
|
63 | if (checked) {
|
64 | backgroundColor = theme.dark ? 'rgba(255, 255, 255, .12)' : 'rgba(0, 0, 0, .08)';
|
65 | } else {
|
66 | backgroundColor = 'transparent';
|
67 | }
|
68 |
|
69 | return React.createElement(IconButton, _extends({
|
70 | borderless: false,
|
71 | icon: icon,
|
72 | onPress: e => {
|
73 | if (onPress) {
|
74 | onPress(e);
|
75 | }
|
76 |
|
77 | if (context) {
|
78 | context.onValueChange(!checked ? value : null);
|
79 | }
|
80 | },
|
81 | size: size,
|
82 | accessibilityLabel: accessibilityLabel,
|
83 | accessibilityState: {
|
84 | disabled,
|
85 | selected: checked
|
86 | },
|
87 | disabled: disabled,
|
88 | style: [styles.content, {
|
89 | backgroundColor,
|
90 | borderRadius,
|
91 | borderColor: color(theme.dark ? white : black).alpha(0.29).rgb().string()
|
92 | }, style]
|
93 | }, rest));
|
94 | });
|
95 | };
|
96 |
|
97 | const styles = StyleSheet.create({
|
98 | content: {
|
99 | width: 42,
|
100 | height: 42,
|
101 | margin: 0
|
102 | }
|
103 | });
|
104 | export default withTheme(ToggleButton);
|
105 |
|
106 | const ToggleButtonWithTheme = withTheme(ToggleButton);
|
107 |
|
108 | export { ToggleButtonWithTheme as ToggleButton };
|
109 |
|
\ | No newline at end of file |