|
1 |
| -import _ from 'lodash'; |
2 | 1 | import React, {PureComponent} from 'react';
|
3 | 2 | import {ScrollView, StyleSheet} from 'react-native';
|
4 |
| -import {Card, Text, Image, ListItem, Carousel, View, ExpandableSection, Switch} from 'react-native-ui-lib'; |
| 3 | +import {Text, View, ExpandableSection, SegmentedControl, Colors, Icon} from 'react-native-ui-lib'; |
5 | 4 |
|
6 |
| -const cardImage2 = require('../../assets/images/empty-state.jpg'); |
7 |
| -const cardImage = require('../../assets/images/card-example.jpg'); |
8 | 5 | const chevronDown = require('../../assets/icons/chevronDown.png');
|
9 | 6 | const chevronUp = require('../../assets/icons/chevronUp.png');
|
| 7 | +const infoIcon = require('../../assets/icons/info.png'); |
| 8 | +const DEFAULT = undefined; |
| 9 | +const PARTIALLY_EXPANDED_HEIGHT = 100; |
| 10 | +const FULLY_EXPANDED_HEIGHT = 300; |
10 | 11 |
|
11 | 12 | class ExpandableSectionScreen extends PureComponent {
|
12 | 13 | state = {
|
13 | 14 | expanded: false,
|
14 |
| - top: false |
| 15 | + minHeight: DEFAULT |
15 | 16 | };
|
16 | 17 |
|
17 |
| - elements = [ |
18 |
| - <Card key={0} style={{marginBottom: 10}} onPress={() => this.onExpand()}> |
19 |
| - <Card.Section |
20 |
| - content={[ |
21 |
| - {text: 'Card #1', text70: true, grey10: true}, |
22 |
| - {text: 'card description', text90: true, grey50: true} |
23 |
| - ]} |
24 |
| - style={{padding: 20}} |
25 |
| - /> |
26 |
| - <Card.Section imageSource={cardImage2} imageStyle={{height: 120}}/> |
27 |
| - </Card>, |
28 |
| - <Card key={1} style={{marginBottom: 10}} onPress={() => this.onExpand()}> |
29 |
| - <Card.Section |
30 |
| - content={[ |
31 |
| - {text: 'Card #2', text70: true, grey10: true}, |
32 |
| - {text: 'card description', text90: true, grey50: true} |
33 |
| - ]} |
34 |
| - style={{padding: 20}} |
35 |
| - /> |
36 |
| - <Card.Section imageSource={cardImage} imageStyle={{height: 120}}/> |
37 |
| - </Card>, |
38 |
| - <Card key={2} style={{marginBottom: 10}} onPress={() => this.onExpand()}> |
39 |
| - <Card.Section |
40 |
| - content={[ |
41 |
| - {text: 'Card #3', text70: true, grey10: true}, |
42 |
| - {text: 'card description', text90: true, grey50: true} |
43 |
| - ]} |
44 |
| - style={{padding: 20}} |
45 |
| - /> |
46 |
| - <Card.Section imageSource={cardImage2} imageStyle={{height: 120}}/> |
47 |
| - </Card> |
48 |
| - ]; |
49 |
| - |
50 |
| - onExpand() { |
| 18 | + onExpand = () => { |
51 | 19 | this.setState({
|
52 | 20 | expanded: !this.state.expanded
|
53 | 21 | });
|
54 |
| - } |
| 22 | + }; |
55 | 23 |
|
56 |
| - getChevron() { |
57 |
| - if (this.state.expanded) { |
58 |
| - return this.state.top ? chevronDown : chevronUp; |
59 |
| - } |
60 |
| - return this.state.top ? chevronUp : chevronDown; |
| 24 | + getChevron(expanded: boolean) { |
| 25 | + return expanded ? chevronUp : chevronDown; |
61 | 26 | }
|
62 | 27 |
|
63 |
| - getHeaderElement() { |
| 28 | + renderReadMoreHeader = () => { |
| 29 | + const {expanded} = this.state; |
64 | 30 | return (
|
65 |
| - <View margin-10 spread row> |
66 |
| - <Text grey10 text60> |
67 |
| - ExpandableSection sectionHeader |
| 31 | + <View marginH-page marginT-10 row> |
| 32 | + <Text text80 marginL-40 marginR-5 $textPrimary> |
| 33 | + Read More |
| 34 | + </Text> |
| 35 | + <Icon style={styles.icon} source={this.getChevron(expanded)} tintColor={Colors.$iconPrimary}/> |
| 36 | + </View> |
| 37 | + ); |
| 38 | + }; |
| 39 | + |
| 40 | + renderHeader = (text: string, |
| 41 | + expanded: boolean, |
| 42 | + {disabled, showInfo}: {disabled?: boolean; showInfo?: boolean} = {}) => { |
| 43 | + return ( |
| 44 | + <View marginH-page marginV-20 spread row> |
| 45 | + <View row> |
| 46 | + {showInfo ? <Icon source={infoIcon} marginR-10 tintColor={disabled ? Colors.grey40 : undefined}/> : null} |
| 47 | + <Text text60 marginL-4 grey40={disabled}> |
| 48 | + {text} |
| 49 | + </Text> |
| 50 | + </View> |
| 51 | + <Icon style={styles.icon} source={this.getChevron(expanded)} tintColor={disabled ? Colors.grey40 : undefined}/> |
| 52 | + </View> |
| 53 | + ); |
| 54 | + }; |
| 55 | + |
| 56 | + renderContent() { |
| 57 | + return ( |
| 58 | + <View marginH-60> |
| 59 | + <Text text80> |
| 60 | + If you have any questions, comments, or concerns, please don't hesitate to get in touch with us. You can |
| 61 | + easily reach out to us through our contact form on our website. |
| 62 | + </Text> |
| 63 | + <Text text80> |
| 64 | + Alternatively, you can reach us via email at [email protected], where our team is ready to assist you promptly. If |
| 65 | + you prefer speaking with someone directly, feel free to give us a call at 1-833-350-1066. |
68 | 66 | </Text>
|
69 |
| - <Image style={styles.icon} source={this.getChevron()}/> |
70 | 67 | </View>
|
71 | 68 | );
|
72 | 69 | }
|
73 | 70 |
|
74 |
| - getBodyElement() { |
| 71 | + renderOptions = () => { |
| 72 | + return ( |
| 73 | + <View marginH-page> |
| 74 | + <Text text70BO marginB-8> |
| 75 | + Minimum Height |
| 76 | + </Text> |
| 77 | + <Text text80 marginB-16> |
| 78 | + The expandable section can be either fully collapsed, partially expanded to reveal some of the items, or fully |
| 79 | + expanded by default. |
| 80 | + </Text> |
| 81 | + <SegmentedControl |
| 82 | + activeColor={Colors.$textDefaultLight} |
| 83 | + activeBackgroundColor={Colors.$backgroundInverted} |
| 84 | + segments={[{label: 'Default'}, {label: 'Partially'}, {label: 'Fully Expanded'}]} |
| 85 | + onChangeIndex={index => { |
| 86 | + switch (index) { |
| 87 | + case 0: |
| 88 | + return this.setState({minHeight: DEFAULT}); |
| 89 | + case 1: |
| 90 | + return this.setState({minHeight: PARTIALLY_EXPANDED_HEIGHT}); |
| 91 | + case 2: |
| 92 | + return this.setState({minHeight: FULLY_EXPANDED_HEIGHT}); |
| 93 | + } |
| 94 | + }} |
| 95 | + /> |
| 96 | + </View> |
| 97 | + ); |
| 98 | + }; |
| 99 | + |
| 100 | + renderExpandableSection = () => { |
| 101 | + const {expanded, minHeight} = this.state; |
75 | 102 | return (
|
76 |
| - <Carousel> |
77 |
| - {_.map(this.elements, (element, key) => { |
78 |
| - return ( |
79 |
| - <View key={key} margin-12> |
80 |
| - {element} |
81 |
| - </View> |
82 |
| - ); |
83 |
| - })} |
84 |
| - </Carousel> |
| 103 | + <ExpandableSection |
| 104 | + top={minHeight === PARTIALLY_EXPANDED_HEIGHT} |
| 105 | + expanded={expanded} |
| 106 | + sectionHeader={ |
| 107 | + minHeight === PARTIALLY_EXPANDED_HEIGHT |
| 108 | + ? this.renderReadMoreHeader() |
| 109 | + : this.renderHeader('How can I contact you?', expanded, {showInfo: true}) |
| 110 | + } |
| 111 | + onPress={this.onExpand} |
| 112 | + minHeight={minHeight} |
| 113 | + > |
| 114 | + {this.renderContent()} |
| 115 | + </ExpandableSection> |
85 | 116 | );
|
| 117 | + }; |
| 118 | + |
| 119 | + renderNextItem() { |
| 120 | + return this.renderHeader('Where are you located?', false, {disabled: true, showInfo: true}); |
86 | 121 | }
|
87 | 122 |
|
88 | 123 | render() {
|
89 |
| - const {expanded, top} = this.state; |
90 |
| - |
| 124 | + const {minHeight} = this.state; |
91 | 125 | return (
|
92 | 126 | <ScrollView>
|
93 |
| - <View row center margin-20> |
94 |
| - <Text grey10 text70 marginR-10> |
95 |
| - Open section on top |
96 |
| - </Text> |
97 |
| - <Switch |
98 |
| - value={this.state.top} |
99 |
| - onValueChange={() => { |
100 |
| - this.setState({top: !this.state.top}); |
101 |
| - }} |
102 |
| - /> |
103 |
| - </View> |
104 |
| - <ExpandableSection |
105 |
| - top={top} |
106 |
| - expanded={expanded} |
107 |
| - sectionHeader={this.getHeaderElement()} |
108 |
| - onPress={() => this.onExpand()} |
109 |
| - > |
110 |
| - {this.getBodyElement()} |
111 |
| - </ExpandableSection> |
112 |
| - <ListItem> |
113 |
| - <Text grey10 text60 marginL-10> |
114 |
| - {'The next item'} |
115 |
| - </Text> |
116 |
| - </ListItem> |
| 127 | + <Text text40 margin-20> |
| 128 | + ExpandableSection |
| 129 | + </Text> |
| 130 | + {this.renderOptions()} |
| 131 | + {this.renderExpandableSection()} |
| 132 | + {minHeight !== PARTIALLY_EXPANDED_HEIGHT ? this.renderNextItem() : null} |
117 | 133 | </ScrollView>
|
118 | 134 | );
|
119 | 135 | }
|
|
0 commit comments