Skip to content

Commit

Permalink
Reorganize input components
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Apr 3, 2024
1 parent 47e895c commit fe8f22b
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!-- @component
Field is a presentational component for displaying inputs.
It has a slot for displaying styled "help" text,
for providing more instruction on a field's purpose or meaning.
-->

<script lang="ts">
import Flex from "$lib/components/common/Flex.svelte";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<!-- @component
FieldLabel is a presentational component for giving title and details about a field.
It has props for whether the field is required or exclusive to premium account holders.
-->

<script lang="ts">
import PremiumBadge from "@/premium-credits/PremiumBadge.svelte";
import Flex from "$lib/components/common/Flex.svelte";
import Flex from "./Flex.svelte";
export let required = false;
export let premium = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script context="module" lang="ts">
import { Template, Story } from "@storybook/addon-svelte-csf";
import FieldLabel from "../FieldLabel.svelte";
import FieldLabel from "..//FieldLabel.svelte";
import { Infinity16 } from "svelte-octicons";
export const meta = {
title: "Components / Forms / Inputs / Field Label",
title: "Components / Common / Field Label",
component: FieldLabel,
tags: ["autodocs"],
parameters: { layout: "centered" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script context="module" lang="ts">
import { Story } from "@storybook/addon-svelte-csf";
import PageToolbar from "../PageToolbar.svelte";
import Checkbox from "../Checkbox.svelte";
import Checkbox from "../../inputs/Checkbox.svelte";
import Paginator from "@/common/Paginator.svelte";
export const meta = {
Expand Down
29 changes: 15 additions & 14 deletions src/lib/components/forms/DocumentUpload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import { _ } from "svelte-i18n";
import { File16, File24, Upload16, XCircleFill24 } from "svelte-octicons";
import AccessLevel from "./AccessLevel.svelte";
import Button from "../common/Button.svelte";
import Dropzone from "./Dropzone.svelte";
import Empty from "../common/Empty.svelte";
import Field from "./Field.svelte";
import FieldLabel from "./FieldLabel.svelte";
import Flex from "$lib/components/common/Flex.svelte";
import InputFile from "./InputFile.svelte";
import InputSelect from "./InputSelect.svelte";
import InputText from "./InputText.svelte";
import Field from "../common/Field.svelte";
import FieldLabel from "../common/FieldLabel.svelte";
import Flex from "../common/Flex.svelte";
import Premium from "../common/Premium.svelte";
import Switch from "$lib/components/common/Switch.svelte";
import AccessLevel from "../inputs/AccessLevel.svelte";
import Dropzone from "../inputs/Dropzone.svelte";
import FileInput from "../inputs/File.svelte";
import Select from "../inputs/Select.svelte";
import Switch from "../inputs/Switch.svelte";
import Text from "../inputs/Text.svelte";
import { DOCUMENT_TYPES } from "@/config/config.js";
import { removeUnsupportedTypes } from "@/lib/utils/validateFiles";
Expand Down Expand Up @@ -107,7 +108,7 @@
{formatFileType(file.type)} / {filesize(file.size)}
</p>
<div class="title">
<InputText name="title" bind:value={file.name} />
<Text name="title" bind:value={file.name} />
</div>
<button
class="fileRemove"
Expand Down Expand Up @@ -135,8 +136,8 @@
<p class="drop-instructions">Drag and drop files here</p>
<Flex align="center" justify="center">
<span class="drop-instructions-or">or</span>
<InputFile multiple onFileSelect={addFiles}
><File16 /> Select Files</InputFile
<FileInput multiple onFileSelect={addFiles}
><File16 /> Select Files</FileInput
>
</Flex>
</div>
Expand All @@ -151,12 +152,12 @@
</Field>
<Field>
<FieldLabel>Projects</FieldLabel>
<InputSelect name="projects" multiple items={projectOptions} />
<Select name="projects" multiple items={projectOptions} />
</Field>
<hr class="divider" />
<Field>
<FieldLabel>OCR Engine</FieldLabel>
<InputSelect
<Select
name="ocr_engine"
items={ocrEngineOptions}
bind:value={ocrEngine}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,38 @@
interface Level {
value: access;
name: string;
title: string;
description: string;
icon: typeof SvgComponent;
}
const levels: Level[] = [
{
value: "private",
name: "Private",
title: "Private",
description: "Documents will only be visible to you",
icon: Lock24,
},
{
value: "organization",
name: "Organization",
title: "Organization",
description: "Documents will only be visible to your organization",
icon: Organization24,
},
{
value: "public",
name: "Public",
title: "Public",
description: "Documents will be publicly visible to everyone",
icon: Globe24,
},
];
export let name: string;
export let selected: access = levels[0].value;
export let direction: "column" | "row" = "column";
</script>

<Flex direction="column" gap={0.5}>
<Flex {direction} gap={0.5}>
{#each levels as level}
<div class="option" class:selected={level.value === selected}>
<input
Expand All @@ -55,7 +56,7 @@
<Flex gap={0.5}>
<svelte:component this={level.icon} />
<Flex direction="column" gap={0.125}>
<p class="name">{level.name}</p>
<p class="title">{level.title}</p>
<p class="description">{level.description}</p>
</Flex>
</Flex>
Expand All @@ -66,6 +67,7 @@

<style>
.option {
flex: 1 1 0;
padding: 0.5rem;
border-radius: 0.25rem;
border: 1px solid var(--gray-2, #d8dee2);
Expand All @@ -83,7 +85,7 @@
.detail {
cursor: pointer;
}
.name {
.title {
font-weight: var(--font-semibold);
}
.description {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!-- @component
The File input provides a styled wrapper around `<input type="file" />`.
It mimics the way our common `Button` component handles displaying children.
-->

<script lang="ts">
import type { ComponentProps } from "svelte";
import { DOCUMENT_TYPES } from "@/config/config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- InputSelect.svelte
<!-- @component
`svelte-select` provides a flexible, customizable basis for the InputSelect component.
- https://github.com/rob-balfre/svelte-select
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<!-- @component
The Text input provides styling to the default `<input type="text" … />`.
-->

<script lang="ts">
export let name: string = null;
export let placeholder = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import AccessLevel from "../AccessLevel.svelte";
export const meta = {
title: "Components / Documents / Access Level",
title: "Components / Inputs / Access Level",
component: AccessLevel,
tags: ["autodocs"],
parameters: { layout: "centered" },
Expand All @@ -21,3 +21,4 @@
<Story name="Private" {args} />
<Story name="Organization" args={{ ...args, level: "organization" }} />
<Story name="Public" args={{ ...args, level: "public" }} />
<Story name="Row" args={{ ...args, direction: "row" }} />
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Checkbox from "../Checkbox.svelte";
export const meta = {
title: "Components / Common / Checkbox",
title: "Components / Inputs / Checkbox",
component: Checkbox,
tags: ["autodocs"],
parameters: { layout: "centered" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
};
export const meta = {
title: "Components / Forms / Dropzone",
title: "Components / Inputs / Dropzone",
component: Dropzone,
tags: ["autodocs"],
parameters: { layout: "centered" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script context="module" lang="ts">
import { Template, Story } from "@storybook/addon-svelte-csf";
import { action } from "@storybook/addon-actions";
import InputFile from "../InputFile.svelte";
import File from "../File.svelte";
export const meta = {
title: "Components / Forms / Inputs / File",
component: InputFile,
title: "Components / Inputs / File",
component: File,
tags: ["autodocs"],
};
Expand All @@ -17,7 +17,7 @@
</script>

<Template let:args>
<InputFile {...args}>Select Files</InputFile>
<File {...args}>Select Files</File>
</Template>

<Story name="Default" {args} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script context="module" lang="ts">
import { Template, Story } from "@storybook/addon-svelte-csf";
import InputSelect from "../InputSelect.svelte";
import Select from "../Select.svelte";
export const meta = {
title: "Components / Forms / Inputs / Select",
component: InputSelect,
title: "Components / Inputs / Select",
component: Select,
tags: ["autodocs"],
};
Expand All @@ -22,7 +22,7 @@
</script>

<Template let:args>
<InputSelect {...args} />
<Select {...args} />
</Template>

<Story name="Empty" {args} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Switch from "../Switch.svelte";
export const meta = {
title: "Components / Common / Inputs / Switch",
title: "Components / Inputs / Switch",
component: Switch,
tags: ["autodocs"],
parameters: { layout: "centered" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script context="module" lang="ts">
import { Template, Story } from "@storybook/addon-svelte-csf";
import InputText from "../InputText.svelte";
import Text from "../Text.svelte";
export const meta = {
title: "Components / Forms / Inputs / Text",
component: InputText,
title: "Components / Inputs / Text",
component: Text,
tags: ["autodocs"],
parameters: { layout: "centered" },
};
Expand All @@ -15,7 +15,7 @@
</script>

<Template let:args>
<InputText {...args} />
<Text {...args} />
</Template>

<Story name="Empty" {args} />
Expand Down

0 comments on commit fe8f22b

Please sign in to comment.