|
| 1 | +import React, {Component} from 'react'; |
| 2 | +import {ScrollView} from 'react-native'; |
| 3 | +import {Colors, View, Text, TextField, Slider, ColorPalette} from 'react-native-ui-lib'; //eslint-disable-line |
| 4 | +import {Navigation} from 'react-native-navigation'; |
| 5 | + |
| 6 | +import { |
| 7 | + renderBooleanOption, |
| 8 | + renderRadioGroup, |
| 9 | + renderSliderOption, |
| 10 | + renderColorOption |
| 11 | +} from '../../ExampleScreenPresenter'; |
| 12 | + |
| 13 | +const ERROR_STATES = { |
| 14 | + noError: 'No Error', |
| 15 | + bottomError: 'Bottom Error', |
| 16 | + topError: 'Top Error' |
| 17 | +}; |
| 18 | + |
| 19 | +const GUIDING_TEXTS = { |
| 20 | + none: 'None', |
| 21 | + useTitle: 'Title', |
| 22 | + floatingPlaceholder: 'Floating Placeholder' |
| 23 | +}; |
| 24 | + |
| 25 | +export default class BasicTextFieldScreen extends Component { |
| 26 | + constructor(props) { |
| 27 | + super(props); |
| 28 | + |
| 29 | + this.state = { |
| 30 | + hideUnderline: false, |
| 31 | + underlineColor: undefined, |
| 32 | + guidingText: GUIDING_TEXTS.none, |
| 33 | + disabled: false, |
| 34 | + centered: false, |
| 35 | + useHelperText: false, |
| 36 | + titleColor: undefined, |
| 37 | + error: ERROR_STATES.noError, |
| 38 | + multiline: false, |
| 39 | + typography: 70, |
| 40 | + charCount: 0 |
| 41 | + }; |
| 42 | + } |
| 43 | + |
| 44 | + render() { |
| 45 | + const { |
| 46 | + hideUnderline, |
| 47 | + underlineColor, |
| 48 | + guidingText, |
| 49 | + titleColor, |
| 50 | + disabled, |
| 51 | + centered, |
| 52 | + useHelperText, |
| 53 | + multiline, |
| 54 | + charCount, |
| 55 | + typography, |
| 56 | + error |
| 57 | + } = this.state; |
| 58 | + |
| 59 | + return ( |
| 60 | + <View flex> |
| 61 | + <View padding-20> |
| 62 | + <Text marginB-20 text40> |
| 63 | + TextField |
| 64 | + </Text> |
| 65 | + <TextField |
| 66 | + key={centered ? 'centered' : 'not-centered'} |
| 67 | + {...{[`text${typography}`]: true}} |
| 68 | + placeholder={disabled ? 'Disabled' : 'Placeholder'} |
| 69 | + hideUnderline={hideUnderline} |
| 70 | + underlineColor={underlineColor} |
| 71 | + title={guidingText === GUIDING_TEXTS.useTitle ? 'Title' : undefined} |
| 72 | + titleColor={titleColor} |
| 73 | + floatingPlaceholder={guidingText === GUIDING_TEXTS.floatingPlaceholder} |
| 74 | + helperText={useHelperText ? 'Helper Text' : undefined} |
| 75 | + editable={!disabled} |
| 76 | + centered={centered} |
| 77 | + multiline={multiline} |
| 78 | + maxLength={charCount > 0 ? charCount : undefined} |
| 79 | + showCharacterCounter={charCount > 0} |
| 80 | + error={error !== ERROR_STATES.noError ? 'Custom error message' : undefined} |
| 81 | + useTopErrors={error === ERROR_STATES.topError} |
| 82 | + /> |
| 83 | + </View> |
| 84 | + <View paddingT-s1 bg-grey50/> |
| 85 | + <ScrollView keyboardShouldPersistTaps="always"> |
| 86 | + <View padding-20> |
| 87 | + <Text text50M marginB-s4> |
| 88 | + Options |
| 89 | + </Text> |
| 90 | + {renderSliderOption.call(this, 'Typography (modifier)', 'typography', { |
| 91 | + min: 30, |
| 92 | + max: 100, |
| 93 | + step: 10, |
| 94 | + initial: 70 |
| 95 | + })} |
| 96 | + {renderBooleanOption.call(this, 'Multiline', 'multiline')} |
| 97 | + {renderBooleanOption.call(this, 'Disabled', 'disabled')} |
| 98 | + {renderBooleanOption.call(this, 'Centered', 'centered')} |
| 99 | + {renderBooleanOption.call(this, 'Hide Underline', 'hideUnderline')} |
| 100 | + {renderColorOption.call(this, 'Underline Color', 'underlineColor')} |
| 101 | + {renderRadioGroup.call(this, 'Guiding Text', 'guidingText', GUIDING_TEXTS)} |
| 102 | + {renderColorOption.call(this, 'Title Color', 'titleColor')} |
| 103 | + {renderSliderOption.call(this, 'Character Counter', 'charCount', {min: 0, max: 150, step: 3})} |
| 104 | + {renderRadioGroup.call(this, 'Errors', 'error', ERROR_STATES)} |
| 105 | + </View> |
| 106 | + </ScrollView> |
| 107 | + </View> |
| 108 | + ); |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +Navigation.registerComponent('unicorn.components.BasicTextFieldScreen', () => BasicTextFieldScreen); |
0 commit comments