- Customizable: Easily adjust colors, text, and behaviors via props.
- Event Handling: Emit events for sign-in actions to integrate with parent components.
- Responsive Design: Adapts to different screen sizes for seamless user interaction.
npm i login-lit-component
yarn add login-lit-component
This repository contains a reusable login component built with Lit Element, designed to be easily integrated into various JavaScript frameworks.
-
Type:
string
- Description: Specifies the URL of the background image for the login screen.
-
Default:
''
(empty string)
-
Type:
string
- Description: Sets the background color of the login screen.
-
Default:
''
(empty string)
-
Type:
string
- Description: Error message displayed for invalid credentials or other errors.
-
Default:
''
(empty string)
-
Type:
boolean
- Description: Flag indicating whether credentials entered are invalid.
-
Default:
false
-
Type:
string
- Description: Color of the sign-in button.
-
Default:
'#3f51b5'
-
Type:
string
- Description: Title displayed above the login form.
-
Default:
'Sign In'
-
Type:
string
- Description: Text displayed on the sign-in button.
-
Default:
'Sign In'
-
Type:
string
- Description: Label text for the email input field.
-
Default:
'Email'
-
Type:
string
- Description: Label text for the password input field.
-
Default:
'Password'
-
Type:
boolean
- Description: Flag indicating whether to show or hide the password field.
-
Default:
true
-
Type:
Function
- Description: Callback function triggered when the user attempts to sign in.
-
Default: Empty arrow function
() => {}
import login-lit-component
<script type="module">
import 'login-lit-component'
</script>
<login-component
id="login"
errorMessage="Invalid username or password!!"
></login-component>
Bind Event
<script>
const loginScreen = document.querySelector('#login')
loginScreen.addEventListener('signin', handleSignIn)
function handleSignIn(event) {
const { email, password } = event.detail
if (email === 'test@gmail.com' && password === 'Test@123') {
loginScreen.invalidCredentials = false
console.log('Authentication successful')
} else {
loginScreen.invalidCredentials = true
}
}
</script>
import { LoginComponent } from 'login-lit-component'
import { createComponent, EventName } from '@lit/react'
export const MyLoginComponent = createComponent({
tagName: 'login-component',
elementClass: LoginComponent,
react: React,
events: {
onSignIn: 'signin' as EventName<MouseEvent>,
},
})
function App() {
const handleSignIn = () => {
console.log('Signin event')
}
return (
<MyLoginComponent
onSignIn={handleSignIn}
loginTitle="Hello"
></MyLoginComponent>
)
}
app.component.ts
export class AppComponent {
invalidCredentials: boolean
handleSignIn(event){
const { email, password } = event.detail
if (email === 'test@gmail.com' && password === 'Test@123') {
loginScreen.invalidCredentials = false
console.log('Authentication successful')
} else {
loginScreen.invalidCredentials = true
}
}
}
app.component.html
<login-component
[invalidCredentials]="invalidCredentials"
(signin)="handleSignIn($event)"
errorMessage="Invalid username and password"
>
</login-component>