UNPKG

crn-cli

Version:

The Ctrip React Native CLI Tools

1 lines 13.9 kB
__d(function(g,r,i,a,m,e,d){'use strict';var t=r(d[0]),n=r(d[1]),l=r(d[2]),u=r(d[3]),o=r(d[4]),s=r(d[5]),c=r(d[6]),h=r(d[7]),p=r(d[8]),f=r(d[9]),y=f.Text,E=f.TextInput,x=f.View,v=f.StyleSheet,b=f.Slider,S=f.Switch,T=(function(t){function n(){var t,l;u(this,n);for(var o=arguments.length,h=new Array(o),p=0;p<o;p++)h[p]=arguments[p];return(l=s(this,(t=c(n)).call.apply(t,[this].concat(h)))).state={curText:'<No Event>',prevText:'<No Event>',prev2Text:'<No Event>',prev3Text:'<No Event>'},l.updateText=function(t){l.setState(function(n){return{curText:t,prevText:n.curText,prev2Text:n.prevText,prev3Text:n.prev2Text}})},l}return h(n,t),o(n,[{key:"render",value:function(){var t=this;return p.createElement(x,null,p.createElement(E,{autoCapitalize:"none",placeholder:"Enter text to see events",autoCorrect:!1,multiline:!0,onFocus:function(){return t.updateText('onFocus')},onBlur:function(){return t.updateText('onBlur')},onChange:function(n){return t.updateText('onChange text: '+n.nativeEvent.text)},onContentSizeChange:function(n){return t.updateText('onContentSizeChange size: '+JSON.stringify(n.nativeEvent.contentSize))},onEndEditing:function(n){return t.updateText('onEndEditing text: '+n.nativeEvent.text)},onSubmitEditing:function(n){return t.updateText('onSubmitEditing text: '+n.nativeEvent.text)},onKeyPress:function(n){return t.updateText('onKeyPress key: '+n.nativeEvent.key)},style:z.singleLine}),p.createElement(y,{style:z.eventLabel},this.state.curText,'\n',"(prev: ",this.state.prevText,")",'\n',"(prev2: ",this.state.prev2Text,")",'\n',"(prev3: ",this.state.prev3Text,")"))}}]),n})(p.Component),C=(function(t){function n(t){var l;return u(this,n),(l=s(this,c(n).call(this,t))).state={text:''},l}return h(n,t),o(n,[{key:"render",value:function(){var t=this,n=20-this.state.text.length,l=n>5?'blue':'red';return p.createElement(x,{style:z.rewriteContainer},p.createElement(E,{multiline:!1,maxLength:20,onChangeText:function(n){n=n.replace(/ /g,'_'),t.setState({text:n})},style:z.default,value:this.state.text}),p.createElement(y,{style:[z.remainder,{color:l}]},n))}}]),n})(p.Component),L=(function(t){function n(t){var l;return u(this,n),(l=s(this,c(n).call(this,t))).state={text:'Hello #World'},l}return h(n,t),o(n,[{key:"render",value:function(){for(var t,n,l=this,u=/\s+/,o=this.state.text,s=[];o&&(u.lastIndex=0,null!==(t=u.exec(o)));)n=t.index,0===t[0].length&&(n=1),s.push(o.substr(0,n)),s.push(t[0]),n+=t[0].length,o=o.slice(n);return s.push(o),s=s.map(function(t){return/^#/.test(t)?p.createElement(y,{key:t,style:z.hashtag},t):t}),p.createElement(x,null,p.createElement(E,{multiline:!0,style:z.multiline,onChangeText:function(t){l.setState({text:t})}},p.createElement(y,null,s)))}}]),n})(p.Component),k=(function(t){function n(){var t,l;u(this,n);for(var o=arguments.length,h=new Array(o),p=0;p<o;p++)h[p]=arguments[p];return(l=s(this,(t=c(n)).call.apply(t,[this].concat(h)))).focusNextField=function(t){l.refs[t].focus()},l}return h(n,t),o(n,[{key:"render",value:function(){var t=this;return p.createElement(x,null,p.createElement(E,{ref:"1",style:z.singleLine,placeholder:"blurOnSubmit = false",returnKeyType:"next",blurOnSubmit:!1,onSubmitEditing:function(){return t.focusNextField('2')}}),p.createElement(E,{ref:"2",style:z.singleLine,keyboardType:"email-address",placeholder:"blurOnSubmit = false",returnKeyType:"next",blurOnSubmit:!1,onSubmitEditing:function(){return t.focusNextField('3')}}),p.createElement(E,{ref:"3",style:z.singleLine,keyboardType:"url",placeholder:"blurOnSubmit = false",returnKeyType:"next",blurOnSubmit:!1,onSubmitEditing:function(){return t.focusNextField('4')}}),p.createElement(E,{ref:"4",style:z.singleLine,keyboardType:"numeric",placeholder:"blurOnSubmit = false",blurOnSubmit:!1,onSubmitEditing:function(){return t.focusNextField('5')}}),p.createElement(E,{ref:"5",style:z.singleLine,keyboardType:"numbers-and-punctuation",placeholder:"blurOnSubmit = true",returnKeyType:"done"}))}}]),n})(p.Component),P=(function(t){function n(t){var l;return u(this,n),(l=s(this,c(n).call(this,t))).state={hasPadding:!1},l}return h(n,t),o(n,[{key:"render",value:function(){var t=this;return p.createElement(x,null,p.createElement(E,{style:this.state.hasPadding?{padding:0}:null}),p.createElement(y,{onPress:function(){return t.setState({hasPadding:!t.state.hasPadding})}},"Toggle padding"))}}]),n})(p.Component),A=(function(t){function n(t){var l;return u(this,n),(l=s(this,c(n).call(this,t))).state={selection:{start:0,end:0},value:t.value},l}return h(n,t),o(n,[{key:"onSelectionChange",value:function(t){var n=t.nativeEvent.selection;this.setState({selection:n})}},{key:"getRandomPosition",value:function(){var t=this.state.value.length;return Math.round(Math.random()*t)}},{key:"select",value:function(t,n){this._textInput.focus(),this.setState({selection:{start:t,end:n}})}},{key:"selectRandom",value:function(){var t=[this.getRandomPosition(),this.getRandomPosition()].sort();this.select.apply(this,l(t))}},{key:"placeAt",value:function(t){this.select(t,t)}},{key:"placeAtRandom",value:function(){this.placeAt(this.getRandomPosition())}},{key:"render",value:function(){var t=this,n=this.state.value.length;return p.createElement(x,null,p.createElement(E,{multiline:this.props.multiline,onChangeText:function(n){return t.setState({value:n})},onSelectionChange:this.onSelectionChange.bind(this),ref:function(n){return t._textInput=n},selection:this.state.selection,style:this.props.style,value:this.state.value}),p.createElement(x,null,p.createElement(y,null,"selection = ",JSON.stringify(this.state.selection)),p.createElement(y,{onPress:this.placeAt.bind(this,0)},"Place at Start (0, 0)"),p.createElement(y,{onPress:this.placeAt.bind(this,n)},"Place at End (",n,", ",n,")"),p.createElement(y,{onPress:this.placeAtRandom.bind(this)},"Place at Random"),p.createElement(y,{onPress:this.select.bind(this,0,n)},"Select All"),p.createElement(y,{onPress:this.selectRandom.bind(this)},"Select Random")))}}]),n})(p.Component),w=(function(l){function f(t){var n;return u(this,f),(n=s(this,c(f).call(this,t))).state={width:100,multiline:!0,text:'',contentSize:{width:0,height:0}},n}return h(f,l),o(f,[{key:"UNSAFE_componentWillReceiveProps",value:function(t){this.setState({multiline:t.multiline})}},{key:"render",value:function(){var l=this,u=this.props,o=u.style,s=(u.multiline,n(u,["style","multiline"]));return p.createElement(x,null,p.createElement(y,null,"Width:"),p.createElement(b,{value:100,minimumValue:0,maximumValue:100,step:10,onValueChange:function(t){return l.setState({width:t})}}),p.createElement(y,null,"Multiline:"),p.createElement(S,{value:this.state.multiline,onValueChange:function(t){return l.setState({multiline:t})}}),p.createElement(y,null,"TextInput:"),p.createElement(E,t({multiline:this.state.multiline,style:[o,{width:this.state.width+'%'}],onChangeText:function(t){return l.setState({text:t})},onContentSizeChange:function(t){return l.setState({contentSize:t.nativeEvent.contentSize})}},s)),p.createElement(y,null,"Plain text value representation:"),p.createElement(y,null,this.state.text),p.createElement(y,null,"Content Size: ",JSON.stringify(this.state.contentSize)))}}]),f})(p.Component),z=v.create({multiline:{height:60,fontSize:16},eventLabel:{margin:3,fontSize:12},singleLine:{fontSize:16},singleLineWithHeightTextInput:{height:30},hashtag:{color:'blue',fontWeight:'bold'}});e.title='<TextInput>',e.description='Single and multi-line text inputs.',e.examples=[{title:'Auto-focus',render:function(){return p.createElement(E,{autoFocus:!0,multiline:!0,style:z.input,accessibilityLabel:"I am the accessibility label for text input"})}},{title:"Live Re-Write (<sp> -> '_')",render:function(){return p.createElement(C,null)}},{title:'Auto-capitalize',render:function(){var t=['none','sentences','words','characters'].map(function(t){return p.createElement(E,{key:t,autoCapitalize:t,placeholder:'autoCapitalize: '+t,style:z.singleLine})});return p.createElement(x,null,t)}},{title:'Auto-correct',render:function(){return p.createElement(x,null,p.createElement(E,{autoCorrect:!0,placeholder:"This has autoCorrect",style:z.singleLine}),p.createElement(E,{autoCorrect:!1,placeholder:"This does not have autoCorrect",style:z.singleLine}))}},{title:'Keyboard types',render:function(){var t=['default','email-address','numeric','phone-pad'].map(function(t){return p.createElement(E,{key:t,keyboardType:t,placeholder:'keyboardType: '+t,style:z.singleLine})});return p.createElement(x,null,t)}},{title:'Blur on submit',render:function(){return p.createElement(k,null)}},{title:'Event handling',render:function(){return p.createElement(T,null)}},{title:'Colors and text inputs',render:function(){return p.createElement(x,null,p.createElement(E,{style:[z.singleLine],defaultValue:"Default color text"}),p.createElement(E,{style:[z.singleLine,{color:'green'}],defaultValue:"Green Text"}),p.createElement(E,{placeholder:"Default placeholder text color",style:z.singleLine}),p.createElement(E,{placeholder:"Red placeholder text color",placeholderTextColor:"red",style:z.singleLine}),p.createElement(E,{placeholder:"Default underline color",style:z.singleLine}),p.createElement(E,{placeholder:"Blue underline color",style:z.singleLine,underlineColorAndroid:"blue"}),p.createElement(E,{defaultValue:"Same BackgroundColor as View ",style:[z.singleLine,{backgroundColor:'rgba(100, 100, 100, 0.3)'}]},p.createElement(y,{style:{backgroundColor:'rgba(100, 100, 100, 0.3)'}},"Darker backgroundColor")),p.createElement(E,{defaultValue:"Highlight Color is red",selectionColor:'red',style:z.singleLine}))}},{title:'Text input, themes and heights',render:function(){return p.createElement(E,{placeholder:"If you set height, beware of padding set from themes",style:[z.singleLineWithHeightTextInput]})}},{title:'fontFamily, fontWeight and fontStyle',render:function(){return p.createElement(x,null,p.createElement(E,{style:[z.singleLine,{fontFamily:'sans-serif'}],placeholder:"Custom fonts like Sans-Serif are supported"}),p.createElement(E,{style:[z.singleLine,{fontFamily:'sans-serif',fontWeight:'bold'}],placeholder:"Sans-Serif bold"}),p.createElement(E,{style:[z.singleLine,{fontFamily:'sans-serif',fontStyle:'italic'}],placeholder:"Sans-Serif italic"}),p.createElement(E,{style:[z.singleLine,{fontFamily:'serif'}],placeholder:"Serif"}))}},{title:'letterSpacing',render:function(){return p.createElement(x,null,p.createElement(E,{style:[z.singleLine,{letterSpacing:0}],placeholder:"letterSpacing = 0"}),p.createElement(E,{style:[z.singleLine,{letterSpacing:2}],placeholder:"letterSpacing = 2"}),p.createElement(E,{style:[z.singleLine,{letterSpacing:9}],placeholder:"letterSpacing = 9"}),p.createElement(E,{style:[z.singleLine,{letterSpacing:-1}],placeholder:"letterSpacing = -1"}))}},{title:'Passwords',render:function(){return p.createElement(x,null,p.createElement(E,{defaultValue:"iloveturtles",secureTextEntry:!0,style:z.singleLine}),p.createElement(E,{secureTextEntry:!0,style:[z.singleLine,{color:'red'}],placeholder:"color is supported too",placeholderTextColor:"red"}))}},{title:'Editable',render:function(){return p.createElement(E,{defaultValue:"Can't touch this! (>'-')> ^(' - ')^ <('-'<) (>'-')> ^(' - ')^",editable:!1,style:z.singleLine})}},{title:'Multiline',render:function(){return p.createElement(x,null,p.createElement(E,{autoCorrect:!0,placeholder:"multiline, aligned top-left",placeholderTextColor:"red",multiline:!0,style:[z.multiline,{textAlign:'left',textAlignVertical:'top'}]}),p.createElement(E,{autoCorrect:!0,placeholder:"multiline, aligned center",placeholderTextColor:"green",multiline:!0,style:[z.multiline,{textAlign:'center',textAlignVertical:'center'}]}),p.createElement(E,{autoCorrect:!0,multiline:!0,style:[z.multiline,{color:'blue'},{textAlign:'right',textAlignVertical:'bottom'}]},p.createElement(y,{style:z.multiline},"multiline with children, aligned bottom-right")))}},{title:'Fixed number of lines',platform:'android',render:function(){return p.createElement(x,null,p.createElement(E,{numberOfLines:2,multiline:!0,placeholder:"Two line input"}),p.createElement(E,{numberOfLines:5,multiline:!0,placeholder:"Five line input"}))}},{title:'Auto-expanding',render:function(){return p.createElement(x,null,p.createElement(w,{enablesReturnKeyAutomatically:!0,returnKeyType:"done",multiline:!0,style:{maxHeight:400,minHeight:20,backgroundColor:'#eeeeee'}},"generic generic generic",p.createElement(y,{style:{fontSize:6,color:'red'}},"small small small small small small"),p.createElement(y,null,"regular regular"),p.createElement(y,{style:{fontSize:30,color:'green'}},"huge huge huge huge huge"),"generic generic generic"))}},{title:'Attributed text',render:function(){return p.createElement(L,null)}},{title:'Return key',render:function(){var t=['none','go','search','send','done','previous','next'].map(function(t){return p.createElement(E,{key:t,returnKeyType:t,placeholder:'returnKeyType: '+t,style:z.singleLine})}),n=['Compile','React Native'].map(function(t){return p.createElement(E,{key:t,returnKeyLabel:t,placeholder:'returnKeyLabel: '+t,style:z.singleLine})});return p.createElement(x,null,t,n)}},{title:'Inline Images',render:function(){return p.createElement(x,null,p.createElement(E,{inlineImageLeft:"ic_menu_black_24dp",placeholder:"This has drawableLeft set",style:z.singleLine}),p.createElement(E,{inlineImageLeft:"ic_menu_black_24dp",inlineImagePadding:30,placeholder:"This has drawableLeft and drawablePadding set",style:z.singleLine}),p.createElement(E,{placeholder:"This does not have drawable props set",style:z.singleLine}))}},{title:'Toggle Default Padding',render:function(){return p.createElement(P,null)}},{title:'Text selection & cursor placement',render:function(){return p.createElement(x,null,p.createElement(A,{style:z.default,value:"text selection can be changed"}),p.createElement(A,{multiline:!0,style:z.multiline,value:'multiline text selection\ncan also be changed'}))}}]},666823,[14,22,30,3,4,5,8,9,11,15]);