1
0
Fork 0
mirror of synced 2024-08-04 04:41:37 +12:00
budibase/packages/standard-components/src/Login.svelte

193 lines
3.8 KiB
Svelte
Raw Normal View History

2019-08-27 18:32:56 +12:00
<script>
import { getContext } from "svelte"
const { authStore, styleable, builderStore } = getContext("sdk")
const component = getContext("component")
2020-10-15 05:06:20 +13:00
export let buttonText = "Log In"
2020-02-03 22:50:30 +13:00
export let logo = ""
export let title = ""
2020-02-03 22:50:30 +13:00
export let buttonClass = ""
export let inputClass = ""
2020-12-05 01:22:45 +13:00
let email = ""
2020-02-03 22:50:30 +13:00
let password = ""
let loading = false
let error = false
2020-02-03 22:50:30 +13:00
let _buttonClass = ""
let _inputClass = ""
$: {
_buttonClass = buttonClass || "default-button"
_inputClass = inputClass || "default-input"
}
const login = async () => {
if ($builderStore.inBuilder) {
return
}
loading = true
2020-12-05 01:22:45 +13:00
await authStore.actions.logIn({ email, password })
loading = false
2020-02-03 22:50:30 +13:00
}
2021-02-07 01:31:12 +13:00
function handleKeydown(evt) {
if (evt.key === "Enter") {
login()
}
2021-02-07 01:31:12 +13:00
}
2019-08-27 18:32:56 +12:00
</script>
2020-06-25 02:41:33 +12:00
2021-02-07 01:31:12 +13:00
<svelte:window on:keydown={handleKeydown} />
<div class="root" use:styleable={$component.styles}>
<div class="content">
{#if logo}
2020-12-05 03:46:21 +13:00
<div class="logo-container"><img src={logo} alt="logo" /></div>
{/if}
{#if title}
2020-10-15 05:06:20 +13:00
<h2 class="header-content">{title}</h2>
{/if}
<div class="form-root">
<div class="control">
<input
2020-12-05 01:22:45 +13:00
bind:value={email}
type="email"
placeholder="Email"
class={_inputClass} />
</div>
<div class="control">
<input
bind:value={password}
type="password"
placeholder="Password"
class={_inputClass} />
</div>
<button disabled={loading} on:click={login} class={_buttonClass}>
2020-10-15 05:06:20 +13:00
{buttonText || 'Log In'}
</button>
2020-02-03 22:50:30 +13:00
</div>
{#if error}
2020-12-05 01:22:45 +13:00
<div class="incorrect-details-panel">Incorrect email or password</div>
{/if}
2020-02-03 22:50:30 +13:00
</div>
2019-08-27 18:32:56 +12:00
</div>
<style>
2020-02-03 22:50:30 +13:00
.root {
2019-08-27 18:32:56 +12:00
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
2020-02-03 22:50:30 +13:00
.content {
display: flex;
flex-direction: column;
2020-10-16 04:37:50 +13:00
align-items: stretch;
justify-content: center;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
2020-02-03 22:50:30 +13:00
.logo-container {
2020-06-04 02:55:42 +12:00
margin-bottom: 10px;
2020-10-16 04:37:50 +13:00
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
2020-02-03 22:50:30 +13:00
.logo-container > img {
2020-10-16 04:37:50 +13:00
max-height: 80px;
2020-06-04 02:55:42 +12:00
max-width: 200px;
2020-10-15 05:06:20 +13:00
margin-bottom: 20px;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
.header-content {
font-family: Inter;
font-weight: 700;
color: #1f1f1f;
2020-10-15 05:06:20 +13:00
font-size: 32px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
font-feature-settings: "case" "rlig" "calt" 0;
2020-10-15 05:06:20 +13:00
margin: 0 0 20px 0;
2020-02-03 22:50:30 +13:00
}
2019-08-27 18:32:56 +12:00
2020-02-03 22:50:30 +13:00
.incorrect-details-panel {
margin-top: 26px;
padding: 10px;
border-style: solid;
border-width: 1px;
border-color: maroon;
border-radius: 4px;
text-align: center;
color: maroon;
background-color: mistyrose;
align-self: stretch;
2020-02-03 22:50:30 +13:00
}
2020-02-03 22:50:30 +13:00
.form-root {
display: flex;
flex-direction: column;
2020-10-16 04:37:50 +13:00
align-items: stretch;
width: 300px;
margin: auto;
gap: 8px;
2020-02-03 22:50:30 +13:00
}
2020-02-03 22:50:30 +13:00
.control {
width: 100%;
2020-02-03 22:50:30 +13:00
}
.default-input {
font-family: Inter;
font-size: 14px;
color: #393c44;
padding: 2px 6px 2px 12px;
2020-02-03 22:50:30 +13:00
margin: 0 0 0.5em 0;
box-sizing: border-box;
border: 0.5px solid #d8d8d8;
border-radius: 4px;
width: 100%;
height: 40px;
transition: border-color 100ms ease-in 0s;
outline-color: #797979;
2020-02-03 22:50:30 +13:00
}
.default-button {
font-family: Inter;
font-size: 16px;
2020-02-03 22:50:30 +13:00
padding: 0.4em;
box-sizing: border-box;
border-radius: 4px;
color: white;
background-color: #393c44;
2020-02-03 22:50:30 +13:00
outline: none;
width: 300px;
height: 40px;
cursor: pointer;
transition: all 0.2s ease 0s;
overflow: hidden;
outline: none;
user-select: none;
white-space: nowrap;
text-align: center;
2020-02-03 22:50:30 +13:00
}
.default-button:hover {
background-color: white;
border-color: #393c44;
color: #393c44;
2020-02-03 22:50:30 +13:00
}
2020-10-16 04:37:50 +13:00
h2 {
text-align: center;
margin-bottom: 10px;
2020-10-16 04:37:50 +13:00
}
2020-02-03 22:50:30 +13:00
</style>