-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Also: - adds some missing Bootstrap variables/configs, needed for a more complex form such as the Settings page - adds a LOT of options to Linput - affixes, size, fullWidth, help prop/slot, and plainText (see bestguy/sveltestrap#582)
- Loading branch information
1 parent
402133e
commit 49a43e1
Showing
8 changed files
with
159 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
<script> | ||
import { Input, Label } from 'sveltestrap' | ||
import { FormGroup, FormText, Input, InputGroup, InputGroupText, Label } from 'sveltestrap' | ||
export let value = '' | ||
export let label = '' | ||
export let id = 'input-'+(Math.random() * 1_000_000) | ||
export let value = '' | ||
export let label = '' | ||
export let prefix = '' | ||
export let suffix = '' | ||
export let help = '' | ||
export let id = 'input-' + (Math.random() * 1_000_000) | ||
export let plainText = false | ||
export let fullWidth = false | ||
export let size = '' | ||
//FIXME use class:fullWidth and etc instead of that mess | ||
let classes = `${$$props.class || ''} ${(fullWidth ? '' : 'w-auto')}` | ||
if (size == 'sm' || size == 'lg') { | ||
classes += ` form-control-${size}` | ||
} | ||
</script> | ||
|
||
{#if label}<Label for={id}>{label}</Label>{/if} | ||
<Input bind:value={value} {...$$props} {id}/> | ||
<FormGroup> | ||
{#if label}<Label for={id} disabled={$$props.disabled}>{label}</Label>{/if} | ||
<InputGroup> | ||
{#if prefix}<InputGroupText>{prefix}</InputGroupText>{/if} | ||
{#if plainText} <!-- https://github.com/bestguy/sveltestrap/issues/582 --> | ||
<input on:input on:change bind:value={value} {...$$restProps} {id} class={`form-control-plaintext ${classes}`} readonly/> | ||
{:else} | ||
<Input on:input on:change bind:value={value} {...$$restProps} {id} class={classes}/> | ||
{/if} | ||
{#if suffix}<InputGroupText>{suffix}</InputGroupText>{/if} | ||
</InputGroup> | ||
{#if $$slots.help} | ||
<FormText disabled={$$props.disabled}><slot name="help"/></FormText> | ||
{:else if help} | ||
<FormText disabled={$$props.disabled}>{help}</FormText> | ||
{/if} | ||
</FormGroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import Model from './Model' | ||
|
||
/** | ||
* @property {boolean} hideMoney | ||
*/ | ||
export default class Settings extends Model { | ||
|
||
hideMoney = true | ||
currency = 'USD' | ||
hourlyRate = 1 | ||
exchange = { | ||
rate: 1, | ||
fee : 0, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<script> | ||
import { Card, CardBody, CardHeader, CardTitle, Col, FormGroup, Input, Label, Row } from 'sveltestrap' | ||
import { _store } from '$data/_store' | ||
import Linput from '$cmp/Linput.svelte' | ||
import { mfd2, moneyLong } from '$lib/fmt' | ||
import { writable } from 'svelte/store' | ||
import Title from '$cmp/Title.svelte' | ||
const settings = _store.settings | ||
let rate = writable(mfd2($settings.exchange.rate)) | ||
function changeRate() { | ||
$settings.exchange.rate = parseFloat($rate) //saves the raw number... | ||
$rate = mfd2($rate) //...but displays the leading zero | ||
} | ||
$: disableEx = $settings.currency == 'USD' | ||
$: actualRate = moneyLong($settings.exchange.rate * (1 - ($settings.exchange.fee / 100))) | ||
</script> | ||
|
||
<Title page="Settings"/> | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>💰 Cash</CardTitle> | ||
</CardHeader> | ||
<CardBody> | ||
<Linput label="Your hourly rate, in dollars" prefix="$" type="number" bind:value={$settings.hourlyRate} required/> | ||
<FormGroup> | ||
<Label>Your local currency</Label> | ||
<Input type="select" bind:value={$settings.currency} required class="w-auto"> | ||
<option value="USD">🇺🇸 USD</option> | ||
<option value="BRL">🇧🇷 BRL</option> | ||
<option value="EUR">🇪🇺 EUR</option> | ||
<option value="GBP">🇬🇧 GBP</option> | ||
</Input> | ||
</FormGroup> | ||
<Row> | ||
<Col sm="12" md="5"> | ||
<Linput label="Exchange rate" disabled={disableEx} | ||
prefix={disableEx? '' : `1 USD = ${$settings.currency}`} type="number" | ||
bind:value={$rate} on:change={changeRate} required step="0.01" | ||
help="This is the market rate - you can get it from Google, for instance."/> | ||
</Col> | ||
<Col sm="12" md="5"> | ||
<Linput label="Exchange fee" disabled={disableEx} suffix="%" type="number" | ||
bind:value={$settings.exchange.fee} required step="0.01" | ||
help='Also known as "spread" - in finance, that is difference between the market rate and the rate you actually get.'/> | ||
</Col> | ||
{#key disableEx} | ||
<Col sm="12" md="2" class="mb-n3 {disableEx? 'invisible' : 'visible'}"> | ||
<!-- n3 counteracts FormGroup's margin, since it's at the bottom of a Column, not a CardBody --> | ||
<Linput label="💱 Actual rate" value={actualRate} plainText sizing="lg" class="fw-bold"/> | ||
</Col> | ||
{/key} | ||
</Row> | ||
</CardBody> | ||
</Card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters