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

fix: proposed input file #151

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fa3f4f5
ci: se agrega la rama dev al workflow
alan199912 Mar 6, 2023
696dbcf
fix: se corrige espaciado de icono en boton (#136)
victorianastasi Mar 13, 2023
bbcd007
feat: tooltip (#137)
Jesus1397 Mar 13, 2023
edf59ff
fix: se modifica visualizacion de breadcrumb en storybook, se reempla…
victorianastasi Mar 28, 2023
369da51
feat: alert dismissible (#135)
alan199912 Mar 29, 2023
0ec710f
fix: pagination (#141)
victorianastasi Mar 31, 2023
e991777
Merge branch 'master' into dev
lautarorodriguez96 Apr 4, 2023
bc5e398
feat: Alerta - Tooltip - Paginador - Breadcrumb
lautarorodriguez96 Apr 4, 2023
e4015d7
fix: version actual de manera dinamica
alan199912 Apr 10, 2023
a853d58
feat: navegacion por pestañas (#138)
davisLjr Apr 14, 2023
8c7f677
fix: se modifican nombres, se reemplaza textos secundarios por epigra…
victorianastasi Apr 14, 2023
e014658
Merge branch 'master' dev
lautarorodriguez96 Apr 20, 2023
7b26553
fix: spinner y boton con spinner (#142)
victorianastasi Apr 21, 2023
243573c
fix: barra de progreso (#146)
Jesus1397 Apr 21, 2023
752c852
fix: accesos (#134)
matilope Apr 24, 2023
3abb2f8
fix: se genera propuesta para el componente adjuntar archivo
davisLjr Apr 24, 2023
05c7cc1
fix: se formatea el archivo
davisLjr Apr 25, 2023
4bc7450
fix: se cambian nombres de español a ingles
davisLjr Apr 25, 2023
b994f93
fix: se elimina variable de texto
davisLjr Apr 25, 2023
e94f039
fix: se elimina clase container dentro del contenido
davisLjr Apr 25, 2023
8b65b18
fix: se elimina clase label
davisLjr Apr 25, 2023
1d56139
fix: se elimina props label
davisLjr Apr 25, 2023
f2ba95a
fix: se agregan nuevos espaciados segun comentarios en pr
davisLjr Apr 25, 2023
abc6d5f
fix: se elimina el interface
davisLjr Apr 25, 2023
396a04c
fix: Merge branch 'master' into fix_proposed_input_file
davisLjr May 8, 2023
e332963
fix: actualizacion de componente maquetado y estilos
davisLjr May 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 56 additions & 8 deletions src/form/File.stories.tsx
Copy link
Contributor

Choose a reason for hiding this comment

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

Consultaria sobre el tipo de archivo permitido y el tamaño maximo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Falta detallar

Original file line number Diff line number Diff line change
@@ -1,27 +1,75 @@
// Base
import React from 'react';
import React, { useState } from 'react';
import './Form.stories.scss';

// Addons
import { withA11y } from '@storybook/addon-a11y';
import { InputFile } from '.';

// Configuración general del componente
export default {
title: 'Formulario|Archivo',
decorators: [withA11y]
};

export const SubirUnArchivo = (): JSX.Element => {
export const LoadFile = (): JSX.Element => {
const [files, setFiles] = useState<File[]>([]);

return (
<div className="form-wrapper">
<div className="form-group">
<label htmlFor="file-input">Adjuntar un archivo de ejemplo</label>
<input type="file" className="form-control-file" id="file-input" />
</div>
<div className="form-wrapper-lg">
<InputFile
title="Arrastrá tus archivos acá o hace click para adjuntar"
isMultiple={false}
files={files}
setFiles={setFiles}
/>
</div>
);
};

SubirUnArchivo.story = {
LoadFile.story = {
name: 'Subir un archivo'
};

export const LoadFileMulti = (): JSX.Element => {
const [files, setFiles] = useState<File[]>([]);

return (
<div className="form-wrapper-lg">
<InputFile
title="Arrastrá tus archivos acá o hace click para adjuntar"
isMultiple={true}
files={files}
setFiles={setFiles}
/>
</div>
);
};

LoadFileMulti.story = {
name: 'Subir un archivo multiple'
Copy link
Contributor

Choose a reason for hiding this comment

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

tal vez lo modificaria por Subir múltiples archivos , para que sea más claro

};

export const Example = (): JSX.Element => {
const contenidoUno = 'Este es el contenido del archivo.';
const contenidoDos = 'Este es el contenido del archivo dos.';
const [files, setFiles] = useState<File[]>([
new File([contenidoUno], 'archivo1.txt', { type: 'text/plain' }),
new File([contenidoDos], 'archivo2.txt', { type: 'text/plain' })
]);

return (
<div className="form-wrapper-lg">
<InputFile
title="Arrastrá tus archivos acá o hace click para adjuntar"
isMultiple={true}
files={files}
setFiles={setFiles}
/>
</div>
);
};

Example.story = {
name: 'Archivo cargado'
Copy link
Contributor

Choose a reason for hiding this comment

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

tal vez se podria mencionar como Demo (como en modal)

};
5 changes: 5 additions & 0 deletions src/form/Form.stories.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
max-width: 400px;
width: 100%;
}

.form-wrapper-lg {
max-width: 600px;
width: 100%;
}
91 changes: 91 additions & 0 deletions src/form/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React, { useEffect, useState } from 'react';

export interface InputProps {
title?: string;
isMultiple?: boolean;
files: File[];
setFiles: (value: File[] | ((prevFiles: File[]) => File[])) => void;
}

interface FileItemProps {
file: File;
onRemove: () => void;
}

const FileItem: React.FC<FileItemProps> = ({ file, onRemove }) => {
const fileName = file.name.length > 20 ? `${file.name.slice(0, 20)}...` : file.name;

return (
<div className="file-item">
<label className="file-name">
<div className="file-box">
<i className="bx bx-file"></i>
{fileName}
</div>
</label>
<div>
<button type="button" className="btn btn-outline-danger btn-sm" onClick={onRemove}>
Eliminar
</button>
</div>
</div>
);
};

export const InputFile: React.FC<InputProps> = (props) => {
const { title = 'Arrastrá tus archivos acá o hace click para adjuntar', isMultiple = false, files, setFiles } = props;

const [inputKey, setInputKey] = useState<number>(0);

useEffect(() => {
setInputKey(inputKey + 1);
}, [files]);

const handleAddFiles = (e: React.ChangeEvent<HTMLInputElement>) => {
const fileList = e.target.files;
if (fileList) {
const newFiles = Array.from(fileList);
setFiles((prevFiles: File[]) => {
const updatedFiles = newFiles.map((file: File) => file);
return isMultiple ? [...prevFiles, ...updatedFiles] : updatedFiles;
});
}
};

const handleRemoveFile = (index: number) => {
setFiles((prevFiles: File[]) => prevFiles.filter((_, i) => i !== index));
setInputKey((prevKey) => prevKey + 1);
};

return (
<>
<div className="file-group">
<label htmlFor="file-input" className="input-file-title">
<input
key={inputKey}
type="file"
className="form-control-file custom-file"
id="file-input"
onChange={handleAddFiles}
multiple={isMultiple}
/>
<span className="main-file">
<i className="bx bx-cloud-upload"></i>
{title}
</span>
</label>
</div>
{Boolean(files.length) && (
<div key={inputKey} className={`filename-detail${isMultiple ? ' multiple' : ''}`}>
{files.map((file: File, index: number) => (
<FileItem
key={`${file.lastModified}-${Math.floor(Math.random() * 1000000)}`}
file={file}
onRemove={() => handleRemoveFile(index)}
/>
))}
</div>
)}
</>
);
};
10 changes: 10 additions & 0 deletions src/scss/components/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ a.btn {
}
}
}

//Botón con spinner
&:focus, &.focus, &:hover, &.hover, &:active, &.active {
&:is(.btn-outline-secondary, .btn-outline-success, .btn-outline-danger) {
.spinner-border {
border-color: $white;
border-right-color: $grisulado-300;
}
}
}
}

//
Expand Down
100 changes: 99 additions & 1 deletion src/scss/components/_form.scss
davisLjr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,104 @@ $form-validation-states: (
}
}

.file-group {
davisLjr marked this conversation as resolved.
Show resolved Hide resolved
position: relative;
width: 100%;
min-height: 120px;
text-align: center;
border-radius: $border-radius-lg;

.input-file-title {
width: 100%;
padding: 0rem 0.5rem 0 0.5rem;

input[type='file'] {
width: 100%;
height: 100%;
color: transparent;
cursor: pointer;
}

input::file-selector-button {
opacity: 0;
cursor: pointer;
}

.custom-file {
position: absolute;
left: 0;
top: 0;
height: 100%;
z-index: 99;
opacity: 1;
outline: none;

&:focus {
box-shadow: $input-focus-box-shadow;
border-radius: $border-radius-lg;
}
}

.main-file {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
color: $blue;
display: flex;
flex-direction: column;
padding: 0 0.5rem;
border-style: dashed;
border-width: 2px;
border-color: $grisulado-100;
border-radius: $border-radius-lg;
background: $grisulado-10;
transition: 0.2s ease-in-out;

&:hover {
background: white;
transition: 0.2s ease-in-out;
}

.bx,
.material-symbols-rounded {
font-size: 2.5rem;
margin-top: 1.5rem;
}
}
}
}

.filename-detail {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 1rem;

.file-item {
width: 100%;
display: flex;
justify-content: space-between;
color: $blue;
margin-bottom: 0.5rem;

.file-box {
align-items: center;
display: flex;
.bx,
.material-symbols-rounded {
font-size: 2rem;
margin-right: 0.75rem;
color: $grisulado-900;
}
}
}
&.multiple {
display: block;
}
}

.custom-control-label {
padding: spaceUnits(1);
padding-left: $custom-control-indicator-size + spaceUnits(5);
Expand Down Expand Up @@ -250,7 +348,7 @@ $form-validation-states: (
}
&:checked {
~ .custom-control-label::before {
border-color:$custom-control-indicator-checked-color;
border-color: $custom-control-indicator-checked-color;
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/scss/components/_list-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ a.list-group-item {
padding: $list-group-padding;
display: flex;
backface-visibility: hidden;

@include media-breakpoint-down(xs) {
padding: $list-group-padding-mobile;
}
Expand Down Expand Up @@ -100,7 +99,6 @@ a.list-group-item {
&:last-child {
margin-bottom: 0px;
border-radius: $list-group-border;

&:is(.card-item) {
border-radius: $border-radius-card-item;
}
Expand Down Expand Up @@ -353,7 +351,6 @@ a.list-group-item {
box-shadow: $box-shadow-access-focus;
}
}

.title-option {
padding: $padding-title-option;
@extend .h5;
Expand Down