From 48e18b1b0285deed72397fc412530ce0a0c10e58 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Mon, 24 Apr 2023 16:39:54 +0800 Subject: [PATCH] doc(login-page): update README.md --- core/README.md | 201 +++++++++++++++++++++++++++++++------------------ 1 file changed, 128 insertions(+), 73 deletions(-) diff --git a/core/README.md b/core/README.md index 1afa7ac..77867a1 100644 --- a/core/README.md +++ b/core/README.md @@ -40,8 +40,7 @@ -Getting Started -=== +# Getting Started 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. Welcome to choose from our encapsulated [login pages](https://uiwjs.github.io/react-login-page). We also welcome [recommendations](https://github.com/uiwjs/react-login-page/issues/new/choose) for more cool login pages, which we will turn into React components. @@ -66,10 +65,12 @@ const Demo = () => { return ( - {({ fields, buttons, blocks }) => { + {({ fields, buttons, blocks, $$index }) => { return (
-
{blocks.logo} {blocks.title}
+
+ {blocks.logo} {blocks.title} +
@@ -87,14 +88,20 @@ const Demo = () => { - Login + + Login + - Submit - Reset + + Submit + + + Reset + ); -} +}; export default Demo; ``` @@ -109,24 +116,32 @@ const Demo = () => { return ( - {({ blocks, extra }, { fields, buttons }) => { + {({ blocks, extra, $$index }, { fields, buttons }) => { return (
-
{blocks.logo} {blocks.title}
- {fields.sort((a, b) => a.index - b.index).map((item, idx) => { - return ( -
- -
- ); - })} -
- {buttons.sort((a, b) => a.index - b.index).map((item, idx) => { - return React.cloneElement(item.children, { - ...item.props, - key: item.name + idx, - }) +
+ {blocks.logo} {blocks.title} +
+ {fields + .sort((a, b) => a.index - b.index) + .map((item, idx) => { + return ( +
+ +
+ ); })} +
+ {buttons + .sort((a, b) => a.index - b.index) + .map((item, idx) => { + return React.cloneElement(item.children, { + ...item.props, + key: item.name + idx, + }); + })}
); @@ -135,9 +150,11 @@ const Demo = () => { - Login + + Login + - + @@ -149,11 +166,15 @@ const Demo = () => { - Submit - Reset + + Submit + + + Reset + ); -} +}; export default Demo; ``` @@ -236,7 +257,7 @@ const Demo = () => { return ( - {({ blocks, fields, extra }, data) => { + {({ blocks, fields, $$index, extra }, data) => { return ( ); -} +}; export default Demo; ``` @@ -333,13 +354,15 @@ export declare const Button: FC>; import { Render } from 'react-login-page'; - {({ fields, buttons, blocks, extra }, data) => { + {({ fields, buttons, blocks, extra, $$index }, data) => { // data.blocks => Array // data.buttons => Array // data.fields => Array return (
-
{blocks.logo} {blocks.title}
+
+ {blocks.logo} {blocks.title} +
@@ -349,17 +372,19 @@ import { Render } from 'react-login-page';
); }} - +; ``` ```tsx import { FC } from 'react'; import { RenderStateProps, InitialState } from 'react-login-page'; -export type RenderChildren = { - children?: (props: Required, data: InitialState['data']) => React.ReactNode; -} | { - children?: React.ReactNode; -}; +export type RenderChildren = + | { + children?: (props: Required, data: InitialState['data']) => React.ReactNode; + } + | { + children?: React.ReactNode; + }; export declare const Render: FC; ``` @@ -367,22 +392,28 @@ export declare const Render: FC; ```tsx - {({ blocks, extra }, { fields, buttons }) => { + {({ blocks, extra, $$index }, { fields, buttons }) => { return (
-
{blocks.logo} {blocks.title}
- {fields.sort((a, b) => a.index - b.index).map((item, idx) => { - return - })} -
- {buttons.sort((a, b) => a.index - b.index).map((item, idx) => { - const child = item.children; - if (!isValidElement(child)) return null; - return cloneElement(child, { - ...child.props, - key: item.name + idx, - }) +
+ {blocks.logo} {blocks.title} +
+ {fields + .sort((a, b) => a.index - b.index) + .map((item, idx) => { + return ; })} +
+ {buttons + .sort((a, b) => a.index - b.index) + .map((item, idx) => { + const child = item.children; + if (!isValidElement(child)) return null; + return cloneElement(child, { + ...child.props, + key: item.name + idx, + }); + })}
); @@ -397,10 +428,12 @@ import React from 'react'; import Login, { Render, Provider, Container, useStore } from 'react-login-page'; const RenderLoginPage = () => { - const { fields, extra, buttons, blocks, data } = useStore(); + const { fields, extra, $$index, buttons, blocks, data } = useStore(); return ( -
{blocks.logo} {blocks.title}
+
+ {blocks.logo} {blocks.title} +
@@ -409,7 +442,7 @@ const RenderLoginPage = () => {
); -} +}; const Demo = () => { return ( @@ -417,15 +450,23 @@ const Demo = () => { - ⚛️ - Login + + ⚛️ + + + Login + - Submit - Reset + + Submit + + + Reset + ); -} +}; export default Demo; ``` @@ -437,27 +478,33 @@ import React, { isValidElement, cloneElement } from 'react'; import Login, { Render, Provider, Container, useStore } from 'react-login-page'; const RenderLoginPage = () => { - const { blocks, data, extra } = useStore(); + const { blocks, data, $$index, extra } = useStore(); const { fields, buttons } = data; return ( -
{blocks.logo} {blocks.title}
- {fields.sort((a, b) => a.index - b.index).map((item, idx) => { - return - })} +
+ {blocks.logo} {blocks.title} +
+ {fields + .sort((a, b) => a.index - b.index) + .map((item, idx) => { + return ; + })}
- {buttons.sort((a, b) => a.index - b.index).map((item, idx) => { + {buttons + .sort((a, b) => a.index - b.index) + .map((item, idx) => { const child = item.children; if (!isValidElement(child)) return null; return cloneElement(child, { ...child.props, key: item.name + idx, - }) - })} + }); + })}
); -} +}; const Demo = () => { return ( @@ -465,15 +512,23 @@ const Demo = () => { - ⚛️ - Login + + ⚛️ + + + Login + - Submit - Reset + + Submit + + + Reset + ); -} +}; export default Demo; ```