Tasklist widget
The Tasklist widget is a component that displays a list of tasks.
Each task can be marked as done. The widget can render existing tasks and allows for adding new tasks, as well as deleting or editing previously created tasks. It operates entirely on the client side and can integrate with any backend service.
This widget is licensed under the MIT license.
Quick start
First steps
To start with the widget, you need to add the necessary package to your project first.
npm install @svar-ui/vue-core
npm install @svar-ui/vue-tasklist
or
yarn add @svar-ui/vue-core
yarn add @svar-ui/vue-tasklist
Now, you can import the widget into your project.
<script setup>
import { Willow } from '@svar-ui/vue-core';
import { Tasklist } from '@svar-ui/vue-tasklist';
</script>
<template>
<Willow>
<Tasklist />
</Willow>
</template>
The Willow component is a default theme wrapper that will add necessary styles for all SVAR widgets. The Tasklist component may work without it, but it will not have any styles, and it will be your task to add them. It is a common approach when the Willow tag is added once at the top level of your application.
Full init code
To see the widget in action, you need to provide some tasks to the widget.
Init tasklist widget with data
<script setup>
import { Tasklist, Willow } from '@svar-ui/vue-tasklist';
import { Willow } from '@svar-ui/vue-core';
const value = [
{
id: 7,
content: "Optimize performance in Vue applications",
status: 1,
},
{
id: 8,
content:
"Work with API requests and data handling in Vue applications",
status: 0,
}
];
</script>
<template>
<Willow>
<Tasklist :value="value" />
</Willow>
</template>
Make sure you apply a theme if you use the Tasklist component standalone. Please, refer to applying a theme for more information.
Visual themes
The widget is provided in two visual styles - Light and Dark, which are controlled by the theme tag.
<script setup>
import { Willow, WillowDark } from "@svar-ui/vue-core";
</script>
<template>
<!-- Light -->
<Willow>
<Tasklist />
</Willow>
<!-- Dark -->
<WillowDark>
<Tasklist />
</WillowDark>
</template>
Initialization
The tasklist widget can be initialized in various ways depending on the requirements. It supports loading tasks dynamically from an API, starting with an empty list, or initializing with predefined data. Below are the detailed options for setting up the widget.
Initializing the widget and loading Tasks dynamically
<script setup>
import { ref, onMounted } from 'vue';
import { Tasklist } from '@svar-ui/vue-tasklist';
const value = ref([]);
onMounted(() => {
fetch('/api/tasks')
.then(r => r.json())
.then(x => value.value = x);
});
</script>
<template>
<Tasklist :value="value" />
</template>
This method is used when tasks need to be fetched from a backend server or API. The fetch function retrieves the task data in JSON format and assigns it to the value ref. The Tasklist widget is rendered once the data is loaded. This approach is ideal for applications where the task list is stored in a database or provided by an external service. The reactive ref ensures proper rendering when the data arrives.