-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: develop
Are you sure you want to change the base?
Changes from all commits
33dbd18
87169e2
c323102
cb3e5aa
e40cb21
bb30692
7b82b79
ad8e815
4289ef1
cf3b9f7
ddd6197
d8fb00a
d14c25c
43fb97a
21caa45
b993c57
0e020cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
> | ||
Selecionar ficheiro | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
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' | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
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'; | ||
|
||
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> | ||
|
||
<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" | ||
> | ||
{#if avatar} | ||
<img class="h-[200px] w-[200px] object-cover" src={avatar} alt="Avatar" /> | ||
{:else} | ||
<p class="font-medium text-white">{text}<span class="text-4xl">*</span></p> | ||
{/if} | ||
<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> | ||
<input | ||
style="display:none" | ||
type="file" | ||
accept=".jpg, .jpeg, .png" | ||
on:change={(e) => onFileSelected(e)} | ||
bind:this={fileinput} | ||
/> | ||
</div> | ||
</div> | ||
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'] | ||
} | ||
}; | ||
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> | ||
|
||
<fieldset> | ||
{#each options as option} | ||
<input | ||
id="radio-{option}" | ||
class="radio-button hidden text-center" | ||
type="radio" | ||
bind:group={selectedOption} | ||
value={option} | ||
/> | ||
<label | ||
class="m-1 justify-self-start rounded-lg bg-taupe-200 px-5 py-1 text-rose-950" | ||
for="radio-{option}" | ||
> | ||
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> | ||
There was a problem hiding this comment.
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!