1
0
Fork 0
mirror of synced 2024-10-04 20:13:35 +13:00
budibase/packages/builder/src/components/common/Input.svelte

54 lines
1.2 KiB
Svelte
Raw Normal View History

2020-01-31 05:22:19 +13:00
<script>
2020-06-02 03:31:58 +12:00
import {onMount} from "svelte"
import { buildStyle } from "../../helpers.js"
2020-02-03 22:50:30 +13:00
export let value = ""
export let textAlign = "left"
export let width = "160px"
export let placeholder = ""
export let suffix = ""
export let onChange = val => {}
2020-06-02 03:31:58 +12:00
let centerPlaceholder = textAlign === "center"
2020-05-08 01:30:04 +12:00
let style = buildStyle({ width, textAlign })
function handleChange(val) {
value = val
let _value = suffix ? value + suffix : value
onChange(_value)
}
$: displayValue = suffix && value.endsWith(suffix) ? value.replace(new RegExp(`${suffix}$`), "") : value
2020-01-31 05:22:19 +13:00
</script>
<input class:centerPlaceholder type="text" value={displayValue} {placeholder} {style} on:change={e => handleChange(e.target.value)} />
2020-02-03 22:50:30 +13:00
2020-01-31 05:22:19 +13:00
<style>
2020-06-02 03:31:58 +12:00
input {
/* width: 32px; */
height: 32px;
font-size: 12px;
font-weight: 700;
margin: 0px 0px 0px 1px;
color: var(--ink);
opacity: 0.7;
padding: 0px 4px;
2020-01-31 05:22:19 +13:00
line-height: 1.3;
/* padding: 12px; */
width: 164px;
2020-01-31 05:22:19 +13:00
box-sizing: border-box;
border: 1px solid var(--grey);
border-radius: 2px;
outline: none;
}
2020-06-02 03:31:58 +12:00
input::placeholder {
text-align: left;
}
.centerPlaceholder::placeholder {
text-align: center;
2020-01-31 05:22:19 +13:00
}
</style>