Skip to content

Commit f27c836

Browse files
committed
feat(page3): add field label.
1 parent bedcd97 commit f27c836

File tree

11 files changed

+99
-46
lines changed

11 files changed

+99
-46
lines changed

core/src/store.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface RenderStateProps<T extends BlockTagType = 'div'> {
1515
buttons?: Record<string, Buttons | null>;
1616
blocks?: Record<string, Blocks<T> | null>;
1717
extra?: Record<string, React.ReactNode>;
18+
[keyname: string]: any;
1819
}
1920

2021
interface Control<T> {

pages/page3/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const Demo = () => (
5151
<LoginPage>
5252
<Banner style={{ backgroundImage: `url(${defaultBannerImage})` }} />
5353
<Email name="userUserName" />
54-
<Password placeholder="请输入密码" name="userPassword" />
54+
<Password placeholder="请输入密码" label="密码" name="userPassword" />
5555
<Submit>提交</Submit>
5656
<Reset>重置</Reset>
5757
<Welcome>欢迎回来! 登录您的帐户以查看今天的客户:</Welcome>
@@ -103,11 +103,11 @@ const Demo = () => (
103103
<Logo>
104104
<LoginLogo />
105105
</Logo>
106-
<Email index={3} type="text" placeholder="Username" />
106+
<Email index={3} type="text" placeholder="Email" />
107107
<Password index={2} />
108-
<Input name="phone" index={1} placeholder="Phone number">
108+
<Email rename="phone" label="Phone:" type="tel" index={1} placeholder="Phone number">
109109
<div>xx</div>
110-
</Input>
110+
</Email>
111111
<Banner style={{ backgroundImage: `url(${defaultBannerImage})` }} />
112112
<ButtonAfter>
113113
Forgot <a href="#">Username / Password?</a>
@@ -223,7 +223,7 @@ Custom CSS style overrides
223223
Components be provided to modify control properties and perform other related functions.
224224
225225
```jsx
226-
import LoginPage from '@react-login-page/page3';
226+
import Login from '@react-login-page/page3';
227227
// buttons
228228
import { Reset, Submit } from '@react-login-page/page3';
229229
// blocks
@@ -234,24 +234,24 @@ import { Email, Password } from '@react-login-page/page3';
234234
import defaultBannerImage from '@react-login-page/page3/banner-image';
235235

236236
// Basic Components
237-
import { Button, Input } from '@react-login-page/page3';
237+
import { Button } from '@react-login-page/page3';
238238
// or
239-
import { Button, Input } from 'react-login-page';
239+
import { Button } from 'react-login-page';
240240

241-
<LoginPage>
241+
<Login>
242242
<Password index={2} />
243-
</LoginPage>
243+
</Login>
244244

245245
// Define the order of `Password` controls
246246
<Password index={2} />
247247

248248
// Hiding the `Password` control
249249
<Password visible={false} />
250250

251-
// Add input control
252-
<Input name="phone" index={1} placeholder="Phone number">
253-
<svg>...</svg>
254-
</Input>
251+
// Add new input control
252+
<Email rename="phone" label="Phone:" type="tel" index={1} placeholder="Phone number">
253+
<div>xx</div>
254+
</Email>
255255

256256
// Add content after the button
257257
<ButtonAfter>

pages/page3/src/control/Email.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
import { FC } from 'react';
2-
import { Input, InputProps } from 'react-login-page';
1+
import { FC, memo, useEffect } from 'react';
2+
import { Input, InputProps, useStore } from 'react-login-page';
33
import { EmailIcon } from '../icons/email';
44

5-
export interface EmailProps extends InputProps {};
6-
export const Email: FC<EmailProps> = (props) => {
7-
const { name, ...elmProps } = props;
5+
export interface EmailProps extends InputProps {
6+
label?: React.ReactNode;
7+
};
8+
export const Email: FC<EmailProps> = memo((props) => {
9+
const { name, rename, label = 'Email:', ...elmProps } = props;
10+
const { dispatch } = useStore();
811
if (!elmProps.children) {
912
elmProps.children = EmailIcon
1013
}
11-
return <Input placeholder="Email" spellCheck={false} {...elmProps} type="email" name="email" rename={name} />;
12-
};
14+
15+
const nameProps = { name: 'email', rename: name };
16+
if (rename) {
17+
nameProps.name = rename;
18+
}
19+
20+
useEffect(() => dispatch({ [`$${nameProps.name}`]: label }), [label]);
21+
22+
return <Input type="email" placeholder="Email" spellCheck={false} {...elmProps} {...nameProps} />;
23+
});
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
import { FC } from 'react';
2-
import { Input, InputProps } from 'react-login-page';
1+
import { FC, memo, useEffect } from 'react';
2+
import { Input, InputProps, useStore } from 'react-login-page';
33
import { LockIcon } from '../icons/lock';
44

5-
export interface PasswordProps extends InputProps {};
6-
export const Password: FC<PasswordProps> = (props) => {
7-
const { name, ...elmProps } = props;
5+
export interface PasswordProps extends InputProps {
6+
label?: React.ReactNode;
7+
};
8+
export const Password: FC<PasswordProps> = memo((props) => {
9+
const { name, rename, label = 'Password:', ...elmProps } = props;
10+
const { dispatch } = useStore();
811
if (!elmProps.children) {
912
elmProps.children = LockIcon
1013
}
11-
return <Input type="password" placeholder="Password" {...elmProps} name="password" rename={name} />;
12-
};
14+
15+
const nameProps = { name: 'password', rename: name };
16+
if (rename) {
17+
nameProps.name = rename;
18+
}
19+
20+
useEffect(() => dispatch({ [`$${nameProps.name}`]: label }), [label]);
21+
22+
return <Input type="password" placeholder="Password" {...elmProps} {...nameProps} />;
23+
});

pages/page3/src/control/Reset.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export const Reset: FC<Omit<ButtonProps, 'name'>> = (props) => {
66
if (!elmProps.children) {
77
elmProps.children = 'Reset';
88
}
9-
return <Button {...elmProps} name="reset" />;
9+
return <Button type="reset" {...elmProps} name="reset" />;
1010
};

pages/page3/src/index.css

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,22 @@
4444
justify-content: center;
4545
align-items: center;
4646
flex-direction: column;
47-
height: 100%;
47+
min-height: 100%;
4848
}
4949

5050
.login-page3-inner {
5151
background: var(--login-inner-bg);
5252
border-radius: 10px;
53-
overflow: hidden;
5453
--gap: 0.37rem;
5554
display: flex;
5655
flex-wrap: wrap;
57-
align-items: center;
56+
align-items: stretch;
5857
justify-content: space-between;
5958
box-shadow: 0px 2px 6px -1px rgba(0, 0, 0, 0.12);
6059
}
6160

6261
.login-page3-inner > aside {
63-
height: 100%;
62+
height: auto;
6463
overflow: hidden;
6564
}
6665

@@ -148,6 +147,23 @@
148147
outline: 0;
149148
}
150149

150+
.login-page3-label {
151+
position: absolute;
152+
padding: 0 0 0 43px;
153+
transition: all 0.3s ease;
154+
opacity: 0;
155+
font-size: 14px;
156+
}
157+
158+
.login-page3-inner label > input:not(:placeholder-shown) {
159+
padding: 28px 0px 12px 0px;
160+
}
161+
.login-page3-inner label > input:not(:placeholder-shown) + .login-page3-label,
162+
.login-page3-inner label > input:-webkit-autofill:not(:placeholder-shown) + .login-page3-label {
163+
transform: translateY(-12px);
164+
opacity: 0.7;
165+
}
166+
151167
.login-page3-inner input::placeholder {
152168
color: var(--login-input-placeholder);
153169
}

pages/page3/src/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export * from './control/Logo';
2424
export * from './control/Banner';
2525

2626
const RenderLogin = () => {
27-
const { blocks = {}, extra = {}, data } = useStore();
27+
const { blocks = {}, extra = {}, data, ...label } = useStore();
2828
const { fields, buttons } = data || { fields: [] };
2929
return (
3030
<Render>
@@ -40,7 +40,14 @@ const RenderLogin = () => {
4040
</header>
4141
{fields.sort((a, b) => a.index - b.index).map((item, idx) => {
4242
if (!item.children) return null;
43-
return <label key={item.name + idx}>{item.children}{extra[item.name]}</label>
43+
const labelElement = label[`$${item.name}`];
44+
return (
45+
<label key={item.name + idx}>
46+
{item.children}
47+
{labelElement && <span className={`login-page3-label`}>{labelElement}</span>}
48+
{extra[item.name]}
49+
</label>
50+
)
4451
})}
4552
<section>
4653
{buttons.sort((a, b) => a.index - b.index).map((item, idx) => {

website/src/comps/NavMenu.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { mediaStyle } from './DocsLayout';
33
import { ReactComponent as LogoIcon } from '../svg/logo-large.svg';
44
import { NavLink } from "react-router-dom";
55
import { Nav } from "./Nav";
6+
import { FC, PropsWithChildren } from "react";
67

78
const Header = styled.header`
89
border-top: 1px solid var(--color-border-muted);
@@ -16,6 +17,9 @@ const Header = styled.header`
1617
top: 0;
1718
right: 0;
1819
display: flex;
20+
flex-direction: column;
21+
align-items: center;
22+
justify-content: center;
1923
`;
2024

2125
const Inner = styled.div`
@@ -31,9 +35,10 @@ const Logo = styled(LogoIcon)`
3135
display: block;
3236
`;
3337

34-
export const NavMenu = () =>{
38+
export const NavMenu: FC<PropsWithChildren> = ({ children }) =>{
3539
return (
3640
<Header>
41+
{children}
3742
<Inner>
3843
<NavLink to="/">
3944
<Logo height={32} />

website/src/comps/Preview.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const Example = styled.div`
5050
right: 0;
5151
z-index: 9;
5252
height: 100vh;
53+
overflow: auto;
5354
`;
5455

5556

@@ -76,28 +77,34 @@ const PageArrow = styled.div`
7677
height: 28px;
7778
background-color: rgb(255 255 255 / 57%);
7879
margin: 0px auto;
79-
position: relative;
80+
position: absolute;
8081
top: -3rem;
8182
border-radius: 0.51rem;
8283
`;
8384

8485
export const Preview: FC<PropsWithChildren<PreviewProps>> = (props) => {
85-
const { mdData } = useMdData(props.path);
86+
const { mdData, loading } = useMdData(props.path);
8687
return (
8788
<Fragment>
8889
<ScrollRestoration />
8990
{!props.disableNav && <DocsNav />}
9091
{props.disableNav && (
9192
<Example>
9293
{props.children}
94+
</Example>
95+
)}
96+
{props.disableNav && (
97+
<NavMenu>
9398
<PageArrow>
9499
<Arrow />
95100
</PageArrow>
96-
</Example>
101+
</NavMenu>
97102
)}
98-
{props.disableNav && <NavMenu />}
99103
<Wrapper isShowExample={props.disableNav}>
100-
{mdData && (
104+
{loading && (
105+
<div>Loading...</div>
106+
)}
107+
{mdData && !loading && (
101108
<Markdown
102109
source={mdData.source}
103110
rehypeRewrite={(node: Root | RootContent, index: number, parent: Root | Element) => {

website/src/comps/useMdData.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ export const useMdData = (path: MdDataHandle) => {
1111
});
1212
const [loading, setLoading] = useState(false);
1313

14-
useEffect(() => {
15-
const $main = document.getElementsByTagName('main') as HTMLCollectionOf<HTMLDivElement>;
16-
$main[0] && $main[0].scrollTo(0, 0);
17-
}, [path]);
18-
1914
useEffect(() => {
2015
setLoading(() => true);
2116
const getMd = async () => {

0 commit comments

Comments
 (0)