Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial forms components #299

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/lib/components/forms/files-input.svelte
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing Storybook stories, if you need any help let me know!

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script>
let files = null;

$: () => {
if (files) {
console.log(files);
for (const file of files) {
console.log(`${file.name}: ${file.size} bytes`);
}
}
};
Comment on lines +4 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to remove when you're done :)

</script>

<div class="flex items-center space-x-4">
<label
for="file-upload"
class="muted-red cursor-pointer rounded-lg px-4 py-2 text-white hover:bg-red-600"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The button differs a bit currently from the mockups:
image
We should add the red background color to the button and maybe make that color a bit darker on hover?

>
Selecionar ficheiro
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an input to the component so that we can place whatever text here!

</label>

<input id="file-upload" multiple type="file" bind:files class="hidden" />

{#if files}
{#each Array.from(files) as file}
<div class="rounded-lg bg-taupe-200 px-4 py-2 text-rose-950">
<p>{file.name}</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it would be useful if each file could have a little X to remove just that file, would that be doable?

</div>
{/each}
{/if}
</div>

Check warning on line 31 in src/lib/components/forms/files-input.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/files-input.svelte#L2-L31

Added lines #L2 - L31 were not covered by tests
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import LabelInput from './label-input.svelte';

export default {
title: 'Atoms/LabelInput',
title: 'Atoms/Forms/Label Input',

Check warning on line 4 in src/lib/components/forms/label-input.stories.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/label-input.stories.ts#L4

Added line #L4 was not covered by tests
component: LabelInput,
argTypes: {
label: { control: 'text' },
Expand Down
18 changes: 18 additions & 0 deletions src/lib/components/forms/picture-input.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import PictureInput from './picture-input.svelte';

export default {
title: 'Atoms/Forms',
component: PictureInput,
argTypes: {
text: { control: 'text' }
},
parameters: {
layout: 'centered'
}
};

export const Picture_Input = {
args: {
text: 'Adicionar logo'
}
};

Check warning on line 18 in src/lib/components/forms/picture-input.stories.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/picture-input.stories.ts#L2-L18

Added lines #L2 - L18 were not covered by tests
53 changes: 53 additions & 0 deletions src/lib/components/forms/picture-input.svelte
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also try to see if you can line up the text with the *, it looks a bit off-center currently!
image

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<script lang="ts">
import Icon from '$lib/components/icons/icon.svelte';
import Icons from '$lib/components/icons/icons';

Check warning on line 4 in src/lib/components/forms/picture-input.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/picture-input.svelte#L2-L4

Added lines #L2 - L4 were not covered by tests
export let text: string;
let avatar: string;
let fileinput: HTMLInputElement;

const onFileSelected = (e) => {
let image = e.target.files[0];
let reader = new FileReader();
reader.readAsDataURL(image);
reader.onload = (e) => {
if (e.target?.result) {
avatar = e.target.result.toString();
}
};
};
</script>

Check warning on line 20 in src/lib/components/forms/picture-input.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/picture-input.svelte#L6-L20

Added lines #L6 - L20 were not covered by tests
<div id="app" class="flex flex-col items-center justify-center">
<div
class="relative flex h-[200px] w-[200px] items-center justify-center rounded-md bg-muted-red-400 text-center"
>

Check warning on line 24 in src/lib/components/forms/picture-input.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/picture-input.svelte#L23-L24

Added lines #L23 - L24 were not covered by tests
{#if avatar}
<img class="h-[200px] w-[200px] object-cover" src={avatar} alt="Avatar" />
{:else}

Check warning on line 27 in src/lib/components/forms/picture-input.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/picture-input.svelte#L26-L27

Added lines #L26 - L27 were not covered by tests
<p class="font-medium text-white">{text}<span class="text-4xl">*</span></p>
{/if}

Check warning on line 29 in src/lib/components/forms/picture-input.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/picture-input.svelte#L29

Added line #L29 was not covered by tests
<button
type="button"
aria-label="Change Avatar"
class="absolute bottom-0 right-0 m-2 flex h-[15%] w-[15%] cursor-pointer items-center justify-center rounded-md bg-rose-950"
on:click={() => {
fileinput.click();
}}
on:keydown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
fileinput.click();
}
}}
>
<Icon src={Icons.Edit} color="white" size="60%" />
</button>

Check warning on line 44 in src/lib/components/forms/picture-input.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/picture-input.svelte#L31-L44

Added lines #L31 - L44 were not covered by tests
<input
style="display:none"
type="file"
accept=".jpg, .jpeg, .png"

Check warning on line 48 in src/lib/components/forms/picture-input.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/picture-input.svelte#L46-L48

Added lines #L46 - L48 were not covered by tests
on:change={(e) => onFileSelected(e)}
bind:this={fileinput}
/>
</div>
</div>

Check warning on line 53 in src/lib/components/forms/picture-input.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/picture-input.svelte#L51-L53

Added lines #L51 - L53 were not covered by tests
18 changes: 18 additions & 0 deletions src/lib/components/forms/radio-buttons.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import RadioButtons from './radio-buttons.svelte';

export default {
title: 'Atoms/Forms',
component: RadioButtons,
argTypes: {
options: { control: 'array' }
},
parameters: {
layout: 'centered'
}
};

export const Radio_Button = {
args: {
options: ['English', 'Spanish']
}
};

Check warning on line 18 in src/lib/components/forms/radio-buttons.stories.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/radio-buttons.stories.ts#L2-L18

Added lines #L2 - L18 were not covered by tests
29 changes: 29 additions & 0 deletions src/lib/components/forms/radio-buttons.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script lang="ts">
export let options: string[];
let selectedOption: string;
</script>

Check warning on line 5 in src/lib/components/forms/radio-buttons.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/radio-buttons.svelte#L3-L5

Added lines #L3 - L5 were not covered by tests
<fieldset>
{#each options as option}
<input
id="radio-{option}"
class="radio-button hidden text-center"
type="radio"

Check warning on line 11 in src/lib/components/forms/radio-buttons.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/radio-buttons.svelte#L10-L11

Added lines #L10 - L11 were not covered by tests
bind:group={selectedOption}
value={option}
/>

Check warning on line 14 in src/lib/components/forms/radio-buttons.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/radio-buttons.svelte#L14

Added line #L14 was not covered by tests
<label
class="m-1 justify-self-start rounded-lg bg-taupe-200 px-5 py-1 text-rose-950"

Check warning on line 16 in src/lib/components/forms/radio-buttons.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/radio-buttons.svelte#L16

Added line #L16 was not covered by tests
for="radio-{option}"
>

Check warning on line 18 in src/lib/components/forms/radio-buttons.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/radio-buttons.svelte#L18

Added line #L18 was not covered by tests
tomas-sucena marked this conversation as resolved.
Show resolved Hide resolved
{option}
</label>
{/each}
</fieldset>

<style>
input:checked + label {
background-color: theme('colors.muted-red.400');
color: theme('colors.taupe.100');
}
</style>

Check warning on line 29 in src/lib/components/forms/radio-buttons.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/components/forms/radio-buttons.svelte#L20-L29

Added lines #L20 - L29 were not covered by tests
4 changes: 3 additions & 1 deletion src/lib/components/icons/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
} from 'svelte-icons-pack/fa';
import { BiMap } from 'svelte-icons-pack/bi';
import { IoMail, IoClose, IoEye, IoEyeOff } from 'svelte-icons-pack/io';
import { FiEdit2 } from 'svelte-icons-pack/fi';

Check warning on line 13 in src/lib/components/icons/icons.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/components/icons/icons.ts#L13

Added line #L13 was not covered by tests

const Icons = {
Instagram: FaBrandsInstagram,
Expand All @@ -24,7 +25,8 @@
Globe: FaSolidGlobe,
Pin: BiMap,
Visible: IoEye,
Hidden: IoEyeOff
Hidden: IoEyeOff,
Edit: FiEdit2

Check warning on line 29 in src/lib/components/icons/icons.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/components/icons/icons.ts#L28-L29

Added lines #L28 - L29 were not covered by tests
};

export default Icons;
2 changes: 1 addition & 1 deletion src/routes/(app)/contacts/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { Icon } from 'svelte-icons-pack';
import Graph from './_components/graph.svelte';
import LabelInput from '@/lib/components/icons/label-input.svelte';
import LabelInput from '@/lib/components/forms/label-input.svelte';

Check warning on line 4 in src/routes/(app)/contacts/+page.svelte

View check run for this annotation

Codecov / codecov/patch

src/routes/(app)/contacts/+page.svelte#L4

Added line #L4 was not covered by tests
import Icons from '$lib/components/icons/icons';
</script>

Expand Down
Loading