1717Getting Started
1818===
1919
20- Some ` react ` login pages, which can be used quickly after installation .
20+ Encapsulated login page components based on ` react-login-page ` basic components are provided for quick installation and use. These components help streamline the process of creating login pages and offer flexible APIs for modifying and packaging these components .
2121
2222## React Login Page
2323
24- Current components are used to quickly develop more ` login ` pages
24+ This component is designed to facilitate the development of additional login pages and offers a highly flexible API for modifying packaged login page components.
2525
2626### Install
2727
@@ -53,8 +53,8 @@ const Demo = () => {
5353 );
5454 }}
5555 < / Render>
56- < Login .Block name= " logo" > ⚛️< / Login .Block >
57- < Login .Block name= " title" > Login< / Login .Block >
56+ < Login .Block name= " logo" tagName = " span " > ⚛️< / Login .Block >
57+ < Login .Block name= " title" tagName = " span " > Login< / Login .Block >
5858 < Login .Input name= " username" placeholder= " Please input Username" / >
5959 < Login .Input name= " password" placeholder= " please enter password" / >
6060 < Login .Button name= " submit" type= " submit" > Submit< / Login .Button >
@@ -65,49 +65,105 @@ const Demo = () => {
6565export default Demo ;
6666```
6767
68+ Change the control order by using ` index ` , Provide more flexible API encapsulation.
69+
70+ ``` jsx mdx:preview
71+ import React from ' react' ;
72+ import Login , { Render } from ' react-login-page' ;
73+
74+ const Demo = () => {
75+ return (
76+ < Login>
77+ < Render>
78+ {({ blocks }, { fields, buttons }) => {
79+ return (
80+ < div>
81+ < header> {blocks .logo } {blocks .title }< / header>
82+ {fields .sort ((a , b ) => a .index - b .index ).map ((item , idx ) => {
83+ return < label key= {item .name + idx}> {item .children }< / label>
84+ })}
85+ < div>
86+ {buttons .sort ((a , b ) => a .index - b .index ).map ((item , idx ) => {
87+ return React .cloneElement (item .children , {
88+ ... item .props ,
89+ key: item .name + idx,
90+ })
91+ })}
92+ < / div>
93+ < / div>
94+ );
95+ }}
96+ < / Render>
97+ < Login .Block name= " logo" tagName= " span" > ⚛️< / Login .Block >
98+ < Login .Block name= " title" tagName= " span" > Login< / Login .Block >
99+ < Login .Input name= " username" index= {1 } placeholder= " Please input Username" / >
100+ < Login .Input name= " password" index= {0 } placeholder= " please enter password" / >
101+ < Login .Button name= " submit" index= {1 } type= " submit" > Submit< / Login .Button >
102+ < Login .Button name= " reset" index= {0 } type= " reset" > Reset< / Login .Button >
103+ < / Login>
104+ );
105+ }
106+ export default Demo ;
107+ ```
108+
68109### ` Login.Block `
69110
70111``` jsx
71112< Login .Block name= " title" > Login< / Login .Block >
72113```
73114
74115``` jsx
75- import { FC , PropsWithChildren } from " react" ;
76- export interface BlockProps extends React .HTMLAttributes < HTMLDivElement > {
116+ import { PropsWithChildren } from ' react' ;
117+ import { BlockTagType } from ' react-login-page' ;
118+ export interface BlockProps < Tag extends BlockTagType = ' div' > extends React .ReactElement < Tag > {
77119 name ?: string ;
120+ /** Can be shown or hidden with controls */
78121 visible ?: boolean ;
122+ /** "index" refers to the use of indexes to control the order of controls, which can provide more flexible API encapsulation. */
123+ index ?: number ;
124+ /** custom created element */
125+ tagName ?: Tag ;
79126}
80- export declare const Block: FC <PropsWithChildren <BlockProps >>;
127+ export declare const Block: {
128+ <Tag extends keyof JSX .IntrinsicElements = " div" > (props: PropsWithChildren< Partial< BlockProps< Tag>>> ): null ;
129+ displayName: string;
130+ };
81131```
82132
83133### ` Login.Input `
84134
85135``` jsx
86- < Login .Block name = " title " > Login < / Login . Block >
136+ < Login .Input type = " password " placeholder = " Password " / >
87137```
88138
89139``` tsx
90- import React , { FC , PropsWithChildren } from " react" ;
140+ import React , { FC , PropsWithChildren } from ' react' ;
91141export interface InputProps extends React .InputHTMLAttributes <HTMLInputElement > {
92142 name? : string ;
93143 /** Used to define the name of form controls */
94144 rename? : string ;
145+ /** Can be shown or hidden with controls */
95146 visible? : boolean ;
147+ /** "index" refers to the use of indexes to control the order of controls, which can provide more flexible API encapsulation. */
148+ index? : number ;
96149}
97150export declare const Input: FC <PropsWithChildren <InputProps >>;
98151```
99152
100153### ` Login.Button `
101154
102155``` jsx
103- < Login .Block name= " title " > Login < / Login . Block >
156+ < Login .Button name= " submit " type = " submit " / >
104157```
105158
106159``` jsx
107- import { FC , PropsWithChildren } from " react" ;
160+ import { FC , PropsWithChildren } from ' react' ;
108161export interface ButtonProps extends React .ButtonHTMLAttributes < HTMLButtonElement > {
109162 name ?: string ;
163+ /** Can be shown or hidden with controls */
110164 visible ?: boolean ;
165+ /** "index" refers to the use of indexes to control the order of controls, which can provide more flexible API encapsulation. */
166+ index ?: number ;
111167}
112168export declare const Button: FC <PropsWithChildren <ButtonProps >>;
113169```
@@ -134,10 +190,48 @@ import { Render } from 'react-login-page';
134190< / Render>
135191```
136192
193+ ``` tsx
194+ import { FC } from ' react' ;
195+ import { RenderStateProps , InitialState } from ' react-login-page' ;
196+ export type RenderChildren = {
197+ children? : (props : Required <RenderStateProps >, data : InitialState [' data' ]) => React .ReactNode ;
198+ } | {
199+ children? : React .ReactNode ;
200+ };
201+ export declare const Render: FC <RenderChildren >;
202+ ```
203+
204+ ` index ` refers to the use of indexes to control the order of controls
205+
206+ ``` tsx
207+ <Render >
208+ { ({ blocks }, { fields , buttons }) => {
209+ return (
210+ <div >
211+ <header >{ blocks .logo } { blocks .title } </header >
212+ { fields .sort ((a , b ) => a .index - b .index ).map ((item , idx ) => {
213+ return <label key = { item .name + idx } >{ item .children } </label >
214+ })}
215+ <div >
216+ { buttons .sort ((a , b ) => a .index - b .index ).map ((item , idx ) => {
217+ const child = item .children ;
218+ if (! isValidElement (child )) return null ;
219+ return cloneElement (child , {
220+ ... child .props ,
221+ key: item .name + idx ,
222+ })
223+ })}
224+ </div >
225+ </div >
226+ );
227+ }}
228+ </Render >
229+ ```
230+
137231### ` useStore `
138232
139233``` jsx mdx:preview
140- import React , { Fragment } from ' react' ;
234+ import React from ' react' ;
141235import Login , { Render , Provider , Container , useStore } from ' react-login-page' ;
142236
143237const RenderLoginPage = () => {
@@ -161,8 +255,8 @@ const Demo = () => {
161255 < Container>
162256 < RenderLoginPage / >
163257 < / Container>
164- < Login .Block name= " logo" > ⚛️< / Login .Block >
165- < Login .Block name= " title" > Login< / Login .Block >
258+ < Login .Block name= " logo" tagName = " span " > ⚛️< / Login .Block >
259+ < Login .Block name= " title" tagName = " span " > Login< / Login .Block >
166260 < Login .Input name= " username" placeholder= " Please input Username" / >
167261 < Login .Input name= " password" placeholder= " please enter password" / >
168262 < Login .Button name= " submit" type= " submit" > Submit< / Login .Button >
@@ -174,6 +268,54 @@ const Demo = () => {
174268export default Demo ;
175269```
176270
271+ ` index ` refers to the use of indexes to control the order of controls
272+
273+ ``` jsx mdx:preview
274+ import React , { isValidElement , cloneElement } from ' react' ;
275+ import Login , { Render , Provider , Container , useStore } from ' react-login-page' ;
276+
277+ const RenderLoginPage = () => {
278+ const { blocks , data } = useStore ();
279+ const { fields , buttons } = data;
280+ return (
281+ < Render>
282+ < header> {blocks .logo } {blocks .title }< / header>
283+ {fields .sort ((a , b ) => a .index - b .index ).map ((item , idx ) => {
284+ return < label key= {item .name + idx}> {item .children }< / label>
285+ })}
286+ < div>
287+ {buttons .sort ((a , b ) => a .index - b .index ).map ((item , idx ) => {
288+ const child = item .children ;
289+ if (! isValidElement (child)) return null ;
290+ return cloneElement (child, {
291+ ... child .props ,
292+ key: item .name + idx,
293+ })
294+ })}
295+ < / div>
296+ < / Render>
297+ );
298+ }
299+
300+ const Demo = () => {
301+ return (
302+ < Provider>
303+ < Container>
304+ < RenderLoginPage / >
305+ < / Container>
306+ < Login .Block name= " logo" tagName= " span" > ⚛️< / Login .Block >
307+ < Login .Block name= " title" tagName= " span" > Login< / Login .Block >
308+ < Login .Input name= " username" index= {1 } placeholder= " Please input Username" / >
309+ < Login .Input name= " password" placeholder= " please enter password" / >
310+ < Login .Button name= " submit" index= {1 } type= " submit" > Submit< / Login .Button >
311+ < Login .Button name= " reset" type= " reset" > Reset< / Login .Button >
312+ < / Provider>
313+ );
314+ }
315+
316+ export default Demo ;
317+ ```
318+
177319## Contributors
178320
179321As always, thanks to our amazing contributors!
0 commit comments