-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #613 from hy916/dev
添加LoginPagePC文档和优化LoginPage登录页面组件
- Loading branch information
Showing
11 changed files
with
297 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, {Component} from 'react'; | ||
import Layout, {Container} from '../../Layout'; | ||
import {LoginPage} from '@uiw/react-native'; | ||
import {ComProps} from '../../routes'; | ||
import {View} from 'react-native'; | ||
const {Header, Body, Card, Footer} = Layout; | ||
|
||
export interface LoginPageProps extends ComProps {} | ||
|
||
export default class LoginPageView extends Component<LoginPageProps> { | ||
render() { | ||
const {route} = this.props; | ||
const description = route.params.description; | ||
const title = route.params.title; | ||
return ( | ||
<Container> | ||
<Layout> | ||
<Header title={title} description={description} /> | ||
<Body> | ||
<LoginPage /> | ||
</Body> | ||
<Footer /> | ||
</Layout> | ||
</Container> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
LoginPage 登录页 | ||
--- | ||
|
||
用于项目的登录页面 | ||
### 基础示例 | ||
|
||
<!--DemoStart--> | ||
```jsx mdx:preview&background=#bebebe29 | ||
import React,{Fragment} from 'react'; | ||
import { View} from 'react-native'; | ||
import { LoginPage } from '@uiw/react-native'; | ||
|
||
const Demo = () => { | ||
return ( | ||
<Fragment> | ||
<View> | ||
<LoginPage /> | ||
</View> | ||
</Fragment> | ||
); | ||
} | ||
export default Demo | ||
``` | ||
<!--End--> | ||
|
||
### Props | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
|------|------|-----|------| | ||
| `usernamePlaceholder` | 自定义账号输入框为空时显示的文字 | `string` | - | | ||
| `inputContainerStyle` | 自定义账号,密码,验证码输入框样式 |`Boolean` | - | | ||
| `buttonStyle` | 登录按钮自定义样式 | `Object` | - | | ||
| `containerStyle` | 登录页自定义最外层样式 | `object` | - | | ||
| `buttonText` | 登录按钮自定义文字 | `string` | - | | ||
| `customContent` | 自定义忘记密码,切换登录方式 | `React.ReactNode` | - | | ||
| `onLogin` | 登录按钮事件 | `(username: string, password: string) => void` | - | | ||
| `onForgetPassword` | 忘记密码按钮事件 | `() => void` | - | | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import React, { useState } from 'react'; | ||
import { View, Text, TextInput, TouchableOpacity, StyleSheet } from 'react-native'; | ||
import Icon from '../Icon'; | ||
import VerificationCode from '../VerificationCode'; | ||
import { Theme } from '../theme'; | ||
import { useTheme } from '@shopify/restyle'; | ||
import { logSvg, cEyes, oEyes } from './svg'; | ||
|
||
interface LoginPageProps { | ||
/** 自定义账号输入框为空时显示的文字 */ | ||
usernamePlaceholder?: string; | ||
/** 自定义账号,密码,验证码输入框样式 */ | ||
inputContainerStyle?: object; | ||
/** 登录按钮自定义样式 */ | ||
buttonStyle?: object; | ||
/** 登录页自定义最外层样式 */ | ||
containerStyle?: object; | ||
/** 登录按钮自定义文字 */ | ||
buttonText?: string; | ||
/** 自定义忘记密码,切换登录方式 */ | ||
customContent?: React.ReactNode; | ||
/** 登录按钮事件 */ | ||
onLogin?: (username: string, password: string) => void; | ||
/** 忘记密码按钮事件 */ | ||
onForgetPassword?: () => void; | ||
} | ||
|
||
const LoginPage: React.FC<LoginPageProps> = ({ | ||
usernamePlaceholder, | ||
inputContainerStyle = {}, | ||
containerStyle = {}, | ||
buttonStyle = {}, | ||
buttonText = 'Login', | ||
customContent, | ||
onLogin, | ||
onForgetPassword, | ||
}) => { | ||
const [showPsd, setShowPsd] = useState(false); | ||
const [showCode, setShowCode] = useState(false); // added state | ||
console.log('showCode', showCode); | ||
|
||
const theme = useTheme<Theme>(); | ||
const styles = createStyles({ | ||
border: theme.colors.border || '#CCC', | ||
putCol: theme.colors.primary_text || '#CCC', | ||
}); | ||
const [username, setUsername] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
|
||
const onChangeUsername = (val: string) => { | ||
console.log('onChange--> 输入改变事件 ', val); | ||
setUsername(val); | ||
}; | ||
|
||
const onChangePassword = (val: string) => { | ||
console.log('onChange--> 输入改变事件 ', val); | ||
setPassword(val); | ||
}; | ||
|
||
const handleLogin = () => { | ||
if (onLogin) { | ||
onLogin(username, password); | ||
} | ||
}; | ||
|
||
return ( | ||
<View style={[styles.container, { backgroundColor: theme.colors.background }, containerStyle]}> | ||
<View style={styles.content}> | ||
<View style={styles.center}> | ||
<Icon xml={logSvg(theme)} size={30} /> | ||
<Text style={styles.title}>Login</Text> | ||
</View> | ||
<View style={[styles.inputContainer, { paddingHorizontal: 15 }, inputContainerStyle]}> | ||
<TextInput | ||
placeholder={usernamePlaceholder ? usernamePlaceholder : `请输入${showCode ? '手机号码' : '用户名'}`} | ||
placeholderTextColor={theme.colors.border} | ||
style={styles.input} | ||
keyboardType={showCode ? 'numeric' : 'default'} | ||
onChangeText={onChangeUsername} | ||
/> | ||
</View> | ||
{!showCode ? ( | ||
<View style={[styles.inputContainer, styles.inputC, { paddingHorizontal: 15 }, inputContainerStyle]}> | ||
<TextInput | ||
placeholder="请输入密码" | ||
placeholderTextColor={theme.colors.border} | ||
secureTextEntry={!showPsd} | ||
style={[styles.input, { width: '92%' }]} | ||
onChangeText={onChangePassword} | ||
/> | ||
<TouchableOpacity onPress={() => setShowPsd(!showPsd)}> | ||
<Icon xml={showPsd ? cEyes : oEyes} size={20} /> | ||
</TouchableOpacity> | ||
</View> | ||
) : ( | ||
<VerificationCode | ||
value={password} | ||
count={60} | ||
onChange={onChangePassword} | ||
outerStyle={[styles.inputContainer, styles.inputC, inputContainerStyle]} | ||
/> | ||
)} | ||
|
||
<View> | ||
{customContent || ( | ||
<View style={styles.textSty1}> | ||
<TouchableOpacity onPress={onForgetPassword}> | ||
<Text style={styles.textSty}>忘记密码</Text> | ||
</TouchableOpacity> | ||
<TouchableOpacity onPress={() => setShowCode(!showCode)}> | ||
<Text style={styles.textSty}>{`${showCode ? '用户名' : '验证码'}登录`}</Text> | ||
</TouchableOpacity> | ||
</View> | ||
)} | ||
</View> | ||
|
||
<TouchableOpacity style={[styles.button, buttonStyle]} onPress={handleLogin}> | ||
<Text style={[styles.buttonText, styles.buttonTextStyle]}>{buttonText}</Text> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
type CreStyle = { | ||
border: string; | ||
putCol: string; | ||
}; | ||
|
||
function createStyles({ border, putCol }: CreStyle) { | ||
return StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
content: { | ||
width: '80%', | ||
}, | ||
center: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
marginBottom: 20, | ||
}, | ||
title: { | ||
fontSize: 24, | ||
fontWeight: 'bold', | ||
marginLeft: 15, | ||
color: putCol, | ||
}, | ||
inputContainer: { | ||
height: 40, | ||
borderColor: border, | ||
borderWidth: 1, | ||
borderRadius: 5, | ||
justifyContent: 'center', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
inputC: { | ||
paddingHorizontal: 10, | ||
marginTop: 20, | ||
marginBottom: 5, | ||
}, | ||
input: { | ||
flex: 1, | ||
color: putCol, | ||
}, | ||
button: { | ||
backgroundColor: '#1890ff', | ||
height: 40, | ||
marginTop: 5, | ||
borderRadius: 5, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
buttonText: { | ||
color: '#fff', | ||
}, | ||
buttonTextStyle: { | ||
color: '#fff', | ||
}, | ||
textSty: { | ||
color: '#3578e5', | ||
fontWeight: 'bold', | ||
}, | ||
textSty1: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}, | ||
}); | ||
} | ||
|
||
export default LoginPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const logSvg = (theme: any) => ` | ||
<svg width="28" height="28" viewBox="0 0 92 92"><path fill=${theme.colors.primary_text} d="M64.0334418,3.00001993 C79.6854418,3.00001993 89.016442,12.3310199 88.9737367,27.9830199 L88.9737367,64.0170199 C88.9737367,79.6690199 79.6424418,89.0000199 63.9904418,89.0000199 L27.9994418,89.0000199 C12.347442,89.0000199 3.01644198,79.6690199 3.01644198,63.9740199 L3.01644198,27.9830199 C3.01644198,12.3310199 12.347442,3.00001993 27.9994418,3.00001993 L64.0334418,3.00001993 Z M32.6078468,17.0000199 C31.7278468,17.0000199 30.8478468,17.2400199 30.1278468,17.7200199 C29.3278468,18.2000199 28.7678468,18.8400199 28.4478468,19.6400199 C27.8878468,20.6000199 27.6478468,21.6400199 27.5678468,22.7600199 C27.5678468,23.8000199 27.4878468,24.9200199 27.4078468,25.9600199 L27.4078468,26.3600199 C27.3278468,29.9600199 27.2478468,32.6000199 27.2478468,36.4400199 L27.2478468,47.1600199 L27.0878468,58.7600199 C27.0878468,62.2000199 26.8478468,65.7200199 27.2478468,69.3200199 C27.2478468,69.8000199 27.4078468,70.3600199 27.5678468,70.8400199 C29.2478468,75.4000199 36.6078468,74.1200199 40.7678468,74.2800199 C45.1678468,74.3600199 49.3278468,74.3600199 53.4878468,74.2800199 L53.8078468,74.2800199 C55.0878468,74.1200199 56.3678468,74.1200199 57.5678468,74.0400199 C58.7678468,74.0400199 59.9678468,73.8000199 61.1678468,73.4000199 C62.0478468,73.0800199 62.6878468,72.6800199 63.2478468,71.9600199 C63.7278468,71.3200199 64.1278468,70.5200199 64.1278468,69.7200199 C64.1278468,69.0800199 64.1278468,67.8800199 63.9678468,67.3200199 C63.8078468,66.7600199 63.4878468,66.2800199 62.8478468,65.7200199 C62.5278468,65.4000199 62.0478468,65.0800199 61.4078468,64.9200199 C60.7678468,64.7600199 60.1278468,64.6000199 59.3278468,64.5200199 C58.6078468,64.4400199 57.8078468,64.3600199 57.1678468,64.3600199 L53.4078468,64.3600199 L37.5678468,64.2000199 L37.8878468,26.5200199 L37.8878468,25.0800199 C37.8878468,24.5200199 37.8878468,23.8800199 38.0478468,23.2400199 C38.0478468,22.6000199 37.8878468,21.9600199 37.8078468,21.2400199 C37.7278468,20.6000199 37.5678468,19.9600199 37.4078468,19.4800199 C37.1678468,18.9200199 36.8478468,18.4400199 36.5278468,18.1200199 C35.8878468,17.6400199 35.3278468,17.2400199 34.6878468,17.1600199 C34.0478468,17.0800199 33.3278468,17.0000199 32.6078468,17.0000199 Z" transform="rotate(7 45.995 46)"></path></svg>`; | ||
|
||
export const cEyes: string = ` | ||
<svg t="1682326713832" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1092" width="200" height="200"><path d="M511.930182 209.454545c174.638545 0 335.965091 128.907636 458.007273 290.932364a39.563636 39.563636 0 0 1 3.211636 41.122909l-3.328 5.399273-4.328727 5.701818C842.984727 712.727273 683.054545 837.818182 512 837.818182c-174.382545 0-335.150545-128.512-457.890909-290.978909a39.447273 39.447273 0 0 1-3.258182-41.169455l3.351273-5.422545 4.421818-5.678546C186.298182 330.705455 340.968727 209.454545 511.906909 209.454545z m0.139636 74.868364c-134.144 0-265.355636 95.301818-375.738182 228.026182l-9.099636 11.077818 9.192727 11.287273c107.008 128.791273 230.888727 220.858182 360.517818 227.514182l14.987637 0.395636c133.981091 0 264.075636-94.394182 376.087273-227.956364l9.239272-11.240727-9.239272-11.170909c-107.845818-128.581818-232.424727-220.881455-361.099637-227.560727l-14.848-0.372364z m-1.559273 82.664727a138.705455 138.705455 0 0 1 93.463273 36.957091l8.285091 8.261818 7.586909 8.773819a160.186182 160.186182 0 0 1 34.350546 99.630545c0 84.805818-64.279273 153.646545-143.709091 153.646546-79.313455 0-143.592727-68.840727-143.592728-153.646546 0-81.408 59.182545-148.084364 134.144-153.297454l9.472-0.325819zM464.756364 458.938182l-5.818182 5.655273-5.166546 6.167272a83.246545 83.246545 0 0 0-13.777454 71.773091l2.653091 8.075637 3.281454 7.424c11.52 22.877091 32.744727 38.074182 56.552728 40.890181l8.005818 0.465455 0.581818 0.605091 7.726545-0.442182a70.516364 70.516364 0 0 0 37.469091-16.756364l6.190546-5.981091a81.454545 81.454545 0 0 0 21.387636-56.203636c0-31.883636-17.943273-60.695273-45.335273-72.797091a69.469091 69.469091 0 0 0-73.774545 11.124364z" fill="#8a8a8a" p-id="1093"></path> | ||
</svg> | ||
`; | ||
|
||
export const oEyes: string = ` | ||
<svg t="1682326825185" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1414" width="200" height="200"><path d="M963.909818 289.233455c16.244364 14.894545 18.152727 41.122909 4.258909 58.554181a629.573818 629.573818 0 0 1-110.010182 107.799273l84.014546 90.112c14.824727 16.523636 14.405818 42.798545-0.977455 58.740364a36.840727 36.840727 0 0 1-53.76 0l-97.163636-104.168728a571.112727 571.112727 0 0 1-140.101818 56.48291l44.916363 132.212363c7.284364 21.573818-3.072 45.381818-23.156363 53.248-20.107636 7.842909-42.309818-3.258182-49.617455-24.832l-49.570909-146.338909a567.575273 567.575273 0 0 1-122.135273 0.488727l-49.547636 145.850182c-7.307636 21.550545-29.509818 32.674909-49.617454 24.832-20.084364-7.842909-30.440727-31.674182-23.133091-53.248l44.590545-131.025454a574.976 574.976 0 0 1-141.428364-55.924364l-95.534545 102.4a36.864 36.864 0 0 1-54.714182-1.000727 43.752727 43.752727 0 0 1 0-57.716364l82.059637-88.017454a623.429818 623.429818 0 0 1-107.613091-103.656728c-13.777455-17.524364-11.706182-43.729455 4.608-58.507636 15.895273-14.382545 39.517091-12.753455 53.527272 3.700364 99.793455 122.368 244.014545 192.465455 395.566546 192.256 155.810909 0 300.567273-73.076364 399.965091-197.655273 13.893818-17.454545 38.330182-19.479273 54.574545-4.584727z" fill="#8a8a8a" p-id="1415"></path> | ||
</svg> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Preview from 'src/component/Preview'; | ||
import md from '@uiw/react-native/lib/LoginPage/README.md'; | ||
|
||
const DEMO = () => <Preview {...md} path="/packages/core/src/LoginPage/README.md" />; | ||
export default DEMO; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters