Add disabled and busy states to Button component

This commit is contained in:
Dallas Hoffman 2023-09-24 23:45:55 -04:00
parent 222c718509
commit a09e630739
2 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,8 @@
export let secondary: boolean = false; export let secondary: boolean = false;
export let icon: boolean = false; export let icon: boolean = false;
export let plain: boolean = false; export let plain: boolean = false;
export let disabled: boolean = false;
export let busy: boolean = false;
export let size: 'sm' | 'md' | 'lg' = 'md'; export let size: 'sm' | 'md' | 'lg' = 'md';
export let label: string | null = null; export let label: string | null = null;
export let tooltipPlacement: 'top' | 'bottom' | 'left' | 'right' | null = 'top'; export let tooltipPlacement: 'top' | 'bottom' | 'left' | 'right' | null = 'top';
@ -21,6 +23,8 @@
class:app-button--plain={plain} class:app-button--plain={plain}
class:app-button--icon={icon} class:app-button--icon={icon}
style:--size={fontSizes[size]} style:--size={fontSizes[size]}
disabled={disabled ? true : null}
aria-busy={busy ? true : null}
aria-label={label} aria-label={label}
data-tooltip={tooltipPlacement ? label : null} data-tooltip={tooltipPlacement ? label : null}
data-placement={tooltipPlacement} data-placement={tooltipPlacement}

View File

@ -5,13 +5,17 @@
export let open: boolean; export let open: boolean;
let submitting: boolean = false;
async function submit(event: SubmitEvent) { async function submit(event: SubmitEvent) {
submitting = true;
const form = event.target as HTMLFormElement; const form = event.target as HTMLFormElement;
const formData = new FormData(form); const formData = new FormData(form);
const [dbFile] = formData.getAll('dbFile') as File[]; const [dbFile] = formData.getAll('dbFile') as File[];
if (!dbFile || dbFile.name === '') { if (!dbFile || dbFile.name === '') {
// TODO: message that no file was selected // TODO: message that no file was selected
submitting = false;
return; return;
} }
@ -23,6 +27,8 @@
} else { } else {
// TODO: message that import failed // TODO: message that import failed
} }
submitting = false;
} }
</script> </script>
@ -34,7 +40,7 @@
This will overwrite all of your current notes. This will overwrite all of your current notes.
</p> </p>
<input type="file" name="dbFile" accept=".db" /> <input type="file" name="dbFile" accept=".db" />
<Button type="submit">Import</Button> <Button type="submit" busy={submitting}>Import</Button>
</form> </form>
</Modal> </Modal>