gov-gui
Version:
Gov UI Component Library Typscript Build
145 lines (143 loc) • 6.34 kB
JavaScript
import { html } from "lit-html";
import "../../global/animate.min.css";
/**
* The `gov-upload` component provides an interface for users to upload files via drag-and-drop or file input.
* It supports multiple file types, handles file upload status (loading, done, warning, failed), and allows customization of allowed file types.
*/
export default {
title: 'Components/Upload',
tags: ['autodocs'],
parameters: {
actions: {
handles: ['click', 'dragover', 'drop'], // Track drag and click actions
},
},
argTypes: {
allowedFileTypes: {
control: { type: 'array' },
description: 'The file types allowed for upload.',
table: {
type: { summary: 'string[]' },
defaultValue: { summary: ['pdf', 'xls', 'png', 'jpeg'] },
category: 'Attributes',
},
},
required: {
control: 'boolean',
description: 'Dictates if the property is required.',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: false },
category: 'Attributes',
},
},
animation: {
control: 'select',
options: ["",
"bounce", "flash", "pulse", "rubberBand", "shakeX", "shakeY", "headShake", "swing", "tada", "wobble", "jello", "heartBeat",
"backInDown", "backInLeft", "backInRight", "backInUp",
"backOutDown", "backOutLeft", "backOutRight", "backOutUp",
"bounceIn", "bounceInDown", "bounceInLeft", "bounceInRight", "bounceInUp",
"bounceOut", "bounceOutDown", "bounceOutLeft", "bounceOutRight", "bounceOutUp",
"fadeIn", "fadeInDown", "fadeInDownBig", "fadeInLeft", "fadeInLeftBig", "fadeInRight", "fadeInRightBig", "fadeInUp", "fadeInUpBig", "fadeInTopLeft", "fadeInTopRight", "fadeInBottomLeft", "fadeInBottomRight",
"fadeOut", "fadeOutDown", "fadeOutDownBig", "fadeOutLeft", "fadeOutLeftBig", "fadeOutRight", "fadeOutRightBig", "fadeOutUp", "fadeOutUpBig", "fadeOutTopLeft", "fadeOutTopRight", "fadeOutBottomRight", "fadeOutBottomLeft",
"flip", "flipInX", "flipInY", "flipOutX", "flipOutY",
"lightSpeedInRight", "lightSpeedInLeft", "lightSpeedOutRight", "lightSpeedOutLeft",
"rotateIn", "rotateInDownLeft", "rotateInDownRight", "rotateInUpLeft", "rotateInUpRight",
"rotateOut", "rotateOutDownLeft", "rotateOutDownRight", "rotateOutUpLeft", "rotateOutUpRight",
"hinge", "jackInTheBox", "rollIn", "rollOut",
"zoomIn", "zoomInDown", "zoomInLeft", "zoomInRight", "zoomInUp",
"zoomOut", "zoomOutDown", "zoomOutLeft", "zoomOutRight", "zoomOutUp",
"slideInDown", "slideInLeft", "slideInRight", "slideInUp",
"slideOutDown", "slideOutLeft", "slideOutRight", "slideOutUp"
],
description: 'Selects the animation effect to apply to the component.',
table: {
type: { summary: 'string' },
defaultValue: { summary: '' },
category: 'Animations',
},
},
animationDelay: {
control: 'select',
options: ["2s", "3s", "4s", "5s"],
description: 'Sets the delay before the animation begins (in seconds).',
table: {
type: { summary: 'string' },
defaultValue: { summary: '2s' },
category: 'Animations',
},
},
animationSpeed: {
control: 'select',
options: ["slow", "slower", "fast", "faster"],
description: 'Controls how quickly the animation plays.',
table: {
type: { summary: 'string' },
defaultValue: { summary: '' },
category: 'Animations',
},
},
status: {
control: { type: 'select', options: ['loading', 'done', 'warning', 'failed', null] },
description: 'The status of the file upload process.',
table: {
type: { summary: `'loading' | 'done' | 'warning' | 'failed' | null` },
defaultValue: { summary: 'null' },
category: 'State',
},
},
fileNameValue: {
control: 'fileNameValue',
description: 'Property designed to extract the uploadedfile name e.g: comp.fileNameValue',
table: {
type: { summary: 'string' },
defaultValue: { summary: '' },
category: 'Interaction',
},
},
setUploadUrl: {
control: 'setUploadUrl',
description: 'Method to set the URL that the uploaded files will be sent to, e.g: comp.setUploadUrl("https://1gov.gov.bw/"). URL can return String of true or false , or a JSON with a success key. Null/Empty response will also be taken as successfull ',
table: {
type: { summary: 'string' },
defaultValue: { summary: '' },
category: 'Interaction',
},
},
validate: {
control: 'validate',
description: 'Method to validate the component\'s value, e.g: comp.validate()',
table: {
type: { summary: 'string' },
defaultValue: { summary: '' },
category: 'Interaction',
},
},
},
};
const Template = (args) => html `
<gov-upload
id="uploadComponent"
.allowedFileTypes="${args.allowedFileTypes}"
?required="${args.required}"
animation-delay="${args.animationDelay}"
animation="${args.animation}"
animation-speed="${args.animationSpeed}"
></gov-upload>
<script>
document.addEventListener('DOMContentLoaded', () => {
const uploadComponent = document.getElementById('uploadComponent');
uploadComponent.setUploadUrl('/');
});
</script>
`;
export const Upload = Template.bind({});
Upload.args = {
allowedFileTypes: ['pdf', 'xls', 'png', 'jpeg'],
required: false,
animation: '',
animationDelay: '',
animationSpeed: '',
};
//# sourceMappingURL=gov-upload.stories.js.map