Updated the basic form with boolean and select fix

This commit is contained in:
Joe 2020-06-29 19:54:30 +01:00
parent b7285e0108
commit c015544959
2 changed files with 103 additions and 24 deletions

View File

@ -4,6 +4,12 @@
export let _bb export let _bb
export let model export let model
const TYPE_MAP = {
string: "text",
boolean: "checkbox",
number: "number"
}
let username let username
let password let password
let newModel = { let newModel = {
@ -59,15 +65,23 @@
<form class="form" on:submit|preventDefault> <form class="form" on:submit|preventDefault>
<h1>{modelDef.name} Form</h1> <h1>{modelDef.name} Form</h1>
<hr />
<div class="form-content"> <div class="form-content">
{#each fields as field} {#each fields as field}
<div class="form-item"> <div class="form-item">
<label class="form-label" for="form-stacked-text">{field}</label> <label class="form-label" for="form-stacked-text">{field}</label>
<input {#if schema[field].type === "string" && schema[field].constraints.inclusion}
class="input" <select on:blur={handleInput(field)}>
placeholder={field} {#each schema[field].constraints.inclusion as opt}
type={schema[field].type === 'string' ? 'text' : schema[field].type} <option>{opt}</option>
on:change={handleInput(field)} /> {/each}
</select>
{:else}
<input
class="input"
type={TYPE_MAP[schema[field].type]}
on:change={handleInput(field)} />
{/if}
</div> </div>
<hr /> <hr />
{/each} {/each}
@ -142,9 +156,45 @@
text-align: center; text-align: center;
} }
button:hover {
background-color: white; button:hover {
border-color: #393c44; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
color: #393c44; }
}
input[type=checkbox] {
width: 32px;
height: 32px;
padding: 0;
margin: 0;
vertical-align: bottom;
position: relative;
top: -1px;
*overflow: hidden;
}
select::-ms-expand {
display: none;
}
select {
display: inline-block;
cursor: pointer;
align-items: baseline;
box-sizing: border-box;
padding: 1em 1em;
border: 1px solid #eaeaea;
border-radius: 5px;
font: inherit;
line-height: inherit;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
appearance: none;
background-repeat: no-repeat;
background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
background-position: right 17px top 1.5em, right 10px top 1.5em;
background-size: 7px 7px, 7px 7px;
}
</style> </style>

View File

@ -59,11 +59,18 @@
{#each fields as field} {#each fields as field}
<div class="form-item"> <div class="form-item">
<label class="form-label" for="form-stacked-text">{field}</label> <label class="form-label" for="form-stacked-text">{field}</label>
<input {#if schema[field].type === "string" && schema[field].constraints.inclusion}
class="input" <select on:blur={handleInput(field)}>
placeholder={field} {#each schema[field].constraints.inclusion as opt}
type={TYPE_MAP[schema[field].type]} <option>{opt}</option>
on:change={handleInput(field)} /> {/each}
</select>
{:else}
<input
class="input"
type={TYPE_MAP[schema[field].type]}
on:change={handleInput(field)} />
{/if}
</div> </div>
<hr /> <hr />
{/each} {/each}
@ -84,15 +91,12 @@
margin-bottom: 20px; margin-bottom: 20px;
} }
.input { .input {
height: 40px;
border-radius: 5px; border-radius: 5px;
border: 1px solid #e6e6e6; border: 1px solid #e6e6e6;
padding: 6px 12px 6px 12px; padding: 1em;
font-size: 16px; font-size: 16px;
} }
.input::placeholder {
color: #cccccc;
}
.form-item { .form-item {
display: grid; display: grid;
grid-template-columns: 30% 1fr; grid-template-columns: 30% 1fr;
@ -119,7 +123,7 @@
box-sizing: border-box; box-sizing: border-box;
border-radius: 4px; border-radius: 4px;
color: white; color: white;
background-color: #393c44; background-color: black;
outline: none; outline: none;
height: 40px; height: 40px;
cursor: pointer; cursor: pointer;
@ -130,13 +134,38 @@
white-space: nowrap; white-space: nowrap;
text-align: center; text-align: center;
} }
button:hover {
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); button:hover {
} box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
input[type=checkbox] { input[type=checkbox] {
transform: scale(2); transform: scale(2);
cursor: pointer; cursor: pointer;
} }
select::-ms-expand {
display: none;
}
select {
cursor: pointer;
display: inline-block;
align-items: baseline;
box-sizing: border-box;
padding: 1em 1em;
border: 1px solid #eaeaea;
border-radius: 5px;
font: inherit;
line-height: inherit;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
appearance: none;
background-repeat: no-repeat;
background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
background-position: right 17px top 1.5em, right 10px top 1.5em;
background-size: 7px 7px, 7px 7px;
}
</style> </style>