1579200548
If you’re new to React or still not really experienced with most aspects of react plus you may need to get more familiar with designing User Interfaces on React so in this tutorial we will go through the process of creating an elegant Login/Register form box on React we will be using create-react-app for easy setup and project configuration so we can quickly get up and running.
You can grab the full source code of the application from this Github Repo.
You may wanna grap the CSS Style files from the Github Repo for easier follow up
If you would like to use SASS in your create-react-app generated application you need to install node sass as a dependency and change the style filename extension to either (.sass|.scss).
npm install node-sass --save-dev
Login and Register boxes are going to be a separate Components so later we can easily manipulate them and decide which one to render or not depending on the application state plus it is going to make it much easier for applying some cool animation while transitioning between states.
So create a components/ folder inside src/ and put inside it the login/ component folder this will hold the login and register standalone components.
/* login.jsx */
import React from "react";
import loginImg from "../../login.svg";
export class Login extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div className="base-container" ref={this.props.containerRef}>
<div className="header">Login</div>
<div className="content">
<div className="image">
<img src={loginImg} />
</div>
<div className="form">
<div className="form-group">
<label htmlFor="username">Username</label>
<input type="text" name="username" placeholder="username" />
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input type="password" name="password" placeholder="password" />
</div>
</div>
</div>
<div className="footer">
<button type="button" className="btn">
Login
</button>
</div>
</div>
);
}
}
Also, make sure to grab the login logo used in this example you can grab it alongside many other open-source SVG Illustrations from undraw
I will be putting it under src/login.svg.
You can use any other structure for adding or either removing useless content from the login form depending on your needs.
For the Login class component, it renders a basic container and a form the style will be contained in login/style.scss
We also need to put the Register.jsx.
/* Register.jsx */
import React from "react";
import loginImg from "../../login.svg";
export class Register extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div className="base-container" ref={this.props.containerRef}>
<div className="header">Register</div>
<div className="content">
<div className="image">
<img src={loginImg} />
</div>
<div className="form">
<div className="form-group">
<label htmlFor="username">Username</label>
<input type="text" name="username" placeholder="username" />
</div>
<div className="form-group">
<label htmlFor="email">Email</label>
<input type="text" name="email" placeholder="email" />
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input type="text" name="password" placeholder="password" />
</div>
</div>
</div>
<div className="footer">
<button type="button" className="btn">
Register
</button>
</div>
</div>
);
}
}
We only needed to add email filed for the registration process.
Now let’s create the style for the login/register components.
.base-container {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
.header {
font-size: 24px;
font-family: "Open Sans", sans-serif;
}
.content {
display: flex;
flex-direction: column;
.image {
width: 21em;
img {
width: 100%;
height: 100%;
}
}
.form {
margin-top: 2em;
display: flex;
flex-direction: column;
align-items: center;
.form-group {
display: flex;
flex-direction: column;
align-items: flex-start;
width: fit-content;
label {
font-size: 20px;
}
input {
margin-top: 6px;
min-width: 18em;
height: 37px;
padding: 0px 10px;
font-size: 16px;
font-family: "Open Sans", sans-serif;
background-color: #f3f3f3;
border: 0;
border-radius: 4px;
margin-bottom: 31px;
transition: all 250ms ease-in-out;
&:hover {
//background-color: #ffffff;
//box-shadow: 0px 0px 14px 0.3px #0e81ce96;
}
&:focus {
outline: none;
box-shadow: 0px 0px 12px 0.8px #3474dbb2;
}
}
}
}
}
.footer {
margin-top: 3em;
}
}
The best thing about SASS or any other pre-processor is you can use nested child elements to make sure only that child element under it’s a specified parent will have the style applied. However, this can also be dangerous if you’re trying to applying custom style names to elements that don’t meet the nested structure.
We also used flex-box for easily aligning children alongside the x and y-axis both vertically and horizontally since we need to fully centre the login box container (base-container children).
Now, let’s try to re-export the Login and Register components using ES6 re-exporting power so we could easily import them from the App.jsx
So simply create index.tsx under login/ and re-export login/register from there.
/* index.tsx */
import "./style.scss";
//Import and Re-export Login/Register Components
export { Login } from "./login";
export { Register } from "./register";
Now under App.jsx we will be rendering the Login/Admin components and we need to tweak the state to apply an animated transition between both components.
/* App.jsx */
import React from "react";
import "./App.scss";
import { Login, Register } from "./components/login/index";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isLogginActive: true
};
}
render() {
const { isLogginActive } = this.state;
const current = isLogginActive ? "Register" : "Login";
return (
<div className="App">
<div className="login">
<div className="container" ref={ref => (this.container = ref)}>
{isLogginActive && (
<Login containerRef={ref => (this.current = ref)} />
)}
{!isLogginActive && (
<Register containerRef={ref => (this.current = ref)} />
)}
</div>
</div>
</div>
);
}
}
We use isLogginActive state to check if we login component is currently being rendered or not (Register component is being rendered) so this way we can transition between login and register components.
We also reference the container div so we can easily use it later to apply some cool transition between moving from login to register and vice-versa.
We need to add the right side component which will allow us to toggle between the two states of login/register components and apply to its cool moving transition.
So let’s create a simple RFC (React Functional Component).
/* App.jsx */
/*We also add custom container ref to pass ref to the App Component so we can easily manipulate the right-side container*/
const RightSide = props => {
return (
<div
className="right-side"
ref={props.containerRef}
onClick={props.onClick}
>
<div className="inner-container">
<div className="text">{props.current}</div>
</div>
</div>
);
};
We pass in the current prop which holds either Login or Register as the next state (Component) we want to transition to.
...
render() {
const { isLogginActive } = this.state;
const current = isLogginActive ? "Register" : "Login";
return (
<div className="App">
<div className="login">
<div className="container" ref={ref => (this.container = ref)}>
{isLogginActive && (
<Login containerRef={ref => (this.current = ref)} />
)}
{!isLogginActive && (
<Register containerRef={ref => (this.current = ref)} />
)}
</div>
<RightSide
current={current}
containerRef={ref => (this.rightSide = ref)}
/>
</div>
</div>
);
}
...
We detect the current (the next component to move to) simply by looking at the isLogginActive.
We also set the containerRef to hold the right-side container ref on the App class.
Now, we need to detect the click event on the right-side container so we could toggle the other component by applying some cool transition.
So add a new method on the App class that will handle the click that occurs on the right side component (make sure to pass the onClick event inside the component otherwise the event listener won’t be registered).
changeState() {
//ES6 Object Destructuring
const { isLogginActive } = this.state;
//We togglet component classes depending on the current active state
if (isLogginActive) {
//Right side for login
this.rightSide.classList.remove("right");
this.rightSide.classList.add("left");
} else {
//Left side for Register
this.rightSide.classList.remove("left");
this.rightSide.classList.add("right");
}
//Of course we need to toggel the isLogginActive by inversing it's previous state
this.setState(prevState => ({ isLogginActive: !prevState.isLogginActive }));
}
We simply check for the current active state which is either loggin is active or register component is active and we apply custom classes so the rightSide component could apply custom styles and transition animations, you can check the App.scss for more information on the applied style.
And most importantly we need to make sure we toggle the current state so we inverse it depending on the previous state value.
Finally, make sure to bind the click event to the current method.
...
<RightSide
current={current}
currentActive={currentActive}
containerRef={ref => (this.rightSide = ref)}
onClick={this.changeState.bind(this)}
/>
...
Make sure to bind the current class context.
and onComponentWillMount hook set a default value.
componentDidMount() {
//Add .right by default
this.rightSide.classList.add("right");
}
Save and reload the page you should get the cool transition playing when toggling between states.
#react-js #web-development #javascript
1598839687
If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?
In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.
Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.
React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.
Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.
Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.
The popularity of React Native comes from its advantages. Some of its advantages are as follows:
Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.
React Native is very close to native. Consider the following aspects as described on the React Native website:
Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.
#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native
1626836644
Integrate google login in react apps; This example tutorial will show you step by step how to implement google login in react apps using javascript SDK.
If you want to integrate google login authentication in your react app. So you will not need any react plugin for this. In this tutorial, you will learn how to add a google login button in react app without any react plugin.
Before you can integrate Google Sign-In into your react app, you must create a client ID, which you need to call the sign-in API.
To create a Google API Console project and client ID, go to the APIs & Services dashboard and then follow the following steps:
Step 1: Visit Google Developer Console. And create a new project as following in below picture:
Step 2: you will see the screen looks like, show here you can set your project name as you want.
Step 3: Now you have successfully created a new project. After that, you need to select the created projects on the top menu. Then click on OAuth consent screen and select the given option according to your requirement:
Step 4: when you will be done above. After that automatically appear below given screen. In this screen, you need to fill your website URL, privacy policy URL, etc.
Step 5: you need to click on left side menu credentials and appear below screen. In this screen, you need to select OAuth client ID.
Step 6: After that, the below form will be apper. Here From different Application type options, you have to select Web application. Once you have select Web application option, then one form will appear on web page. Here you have to define Name and you have also define Authorized redirect URIs field and lastly click on Create button.
Step 7: the pop looks like below in picture automatically appear. Once you have click on the create button, then you can get your Client ID and your client secret key. You have to copy both key for future use for implement Login using Google account using PHP.
Please note that, google client id and secret.
https://www.tutsmake.com/react-google-login-button-example/
#react-google-login component #react-google-login demo #google login with react #add google login button to react
1599277908
Validating inputs is very often required. For example, when you want to make sure two passwords inputs are the same, an email input should in fact be an email or that the input is not too long. This is can be easily done using React Hook From. In this article, I will show you how.
The most simple, yet very common, validation is to make sure that an input component contains input from the user. React Hook Form basic concept is to register input tags to the form by passing register() to the tag’s ref attribute. As we can see here:
#react-native #react #react-hook-form #react-hook
1608042207
#registration form #login form #sign in form #responsive login #html login page
1621064209
Create professional forms for registrations, collecting contact details, or simply receiving feedback. Fynzo’s form builder is cost effective, easy to use, 100% secure with amazing personalization features and can integrate with all your favourite tools.
For more info visit: https://www.fynzo.com/survey/lp/form-builder
#form builder #online form builder #create online forms free #create professional forms