Is there a way to divide v-progress linear into 4 pieces in Vuejs, or are there alternative design options for achieving this in Vuetify 2?

I have set up a table in Vuetify 2 with a v-progress-linear component to monitor the user's remaining time. Initially, my implementation was simple like this.

https://i.sstatic.net/x373G.png

However, we decided to split it into 4 sections for better visibility of the user's time. In doing so, I aim to apply different colors for values less than or equal to 4, and a single color for values greater than 4. Do you think I should consider using another package for this design? How would I go about implementing it? Your assistance on this matter would be greatly appreciated.

https://i.sstatic.net/vQ6ZL.png

The current setup simply involves extracting data from the store and utilizing it as follows:

<v-progress-linear
    id="remainingTimeOffBar"
    rounded
    color="monochromeGray2"
    background-color="colorYellow"
    :value="60 - item.remainingDuration"
    height="6"
/>

I am hopeful that a solution can be reached for this issue. Despite exploring various options, I have not been able to find a viable one thus far. Would handling this via CSS be feasible, or should I look into an alternative package?

Answer №1

If you're looking to customize the design of v-progress-linear in Vuetify, there are no built-in options for that. However, you can easily create your own custom component with minimal CSS to achieve the desired look. Take a look at this codesandbox example to see how it can be done.

The progress amount determines how much of the bar should be filled/colored, and in the provided example, each segment of the progress bar represents 25% completion. You can modify the styling based on the actual progress passed down as a prop.

<template>
  <div class="progress-container">
    <div v-for="i in 4" :key="i" class="segment" :style="{ background: segmentColor(i) }" />
  </div>
</template>
<script>
export default {
  props: {
    progress: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {};
  },
  methods: {
    segmentColor(i) {
      if (this.progress <= 25) {
        return "rgb(76, 195, 93)"; // green
      } else if (this.progress > 25 && this.progress <= 50) {
        if (i > 1) {
          return "rgb(255, 200, 15)"; // yellow
        }
      } else if (this.progress > 50 && this.progress <= 75) {
        if (i > 2) {
          return "rgb(255, 200, 15)"; // yellow
        }
      } else {
        if (i === 4) {
          return "rgb(245, 130, 67)"; // orange
        }
      }
      return "rgb(217, 217, 217)";
    },
  },
};
</script>

<style>
.progress-container {
  display: flex;
}
.segment {
  width: 2rem;
  height: 0.5rem;
  background: rgb(217, 217, 217);
}
.segment:not(:first-child) {
  margin-left: 2px;
}
.segment:first-child {
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}
.segment:last-child {
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}
</style>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps for converting a tsx file into a js file in React

Currently, I am in the process of a React Project and have numerous tsx files that I aim to convert for utilization as JavaScript within my project. What would be the best approach to achieve this task? ...

Setting key-value pairs in TypeScript objects explained

I encountered an issue with setting key/value pairs on a plain object. type getAObjectFn = <K extends string, V>(k: K, v: V) => Record<K, V> const getAObject: getAObjectFn = (k, v) => { return { [k]: v } } console.log(getAObject ...

In the application I'm developing, I'm utilizing React alongside TypeScript, making use of the useContext and useReducer hooks. However, I've encountered an issue where the dispatch function is not being

Currently, I have implemented a feature where two lists are displayed as cards based on one main list of objects. The goal is to toggle the 'favorite' value for each card item when the star button is clicked. This action should move the favorited ...

Create a grid or flex layout with Bootstrap 4 that features a sticky first row and column

Does anyone have any suggestions on how to make the attached grid/table layout responsive using Bootstrap 4's flex/grid system? The layout should include a sticky first row and column for navigation items. I attempted using w- & h- classes, but it do ...

Exploring the usage of slots in WebComponents without relying on shadow DOM

I am working on developing a WebComponent without utilizing ShadowDOM. So far, everything has been going smoothly. However, I now aim to create a component that wraps other components similar to how it is done in Angular with @ViewChild / @ViewChildren. (I ...

How to refresh a page manually in Angular 2

How can I have a page in Angular reload only once when a user visits it? This is my attempt: In the homepage component, I added the following code: export class HomepageComponent implements OnInit { constructor() { } ngOnInit() { location.relo ...

Guide to creating a dynamic import feature in Nuxt

Within my nuxt component, I am eager to integrate the ace editor: import Ace from "ace-builds/src-noconflict/ace" Upon mounting the component, I execute the following: this.editor = Ace.edit... It is evident that the window is not defined on th ...

The 'Bfrip' button is missing from the DOM

Having some issues with displaying table content using DataTables. Everything seems to be working smoothly except for the Buttons, which are not appearing as expected. <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.1 ...

Text alignment below a div with absolute positioning

Presently, my setup looks something like this: <div class="mycol" id="mycanvas" style="z-index: -1; top:150px;left:240px;width:88%; height:80%; position: absolute;background-color:red;"> </div> <div class="testclass"> He ...

Troubleshooting the issues with implementing cross-browser jscrollpane functionality

Hey there! I've been exploring this tool to customize the default scroll-bar, and here's a fiddle showcasing my experimentation. In the fiddle, I've included the following code snippet <div class="scroll-pane horizontal-only">(located ...

Sass flex order has no effect on elements that are generated

I encountered an issue with the rendering of SVGs in my project. Currently, they are displayed correctly in desktop mode, but in mobile portrait mode, I need to change the order of one specific SVG element within the row. To achieve this, I decided to use ...

Steps to resolve the 'form' variable being assigned a value but never used in axios:

I am encountering an issue with a contact form that utilizes React with axios on the frontend and Express with nodemailer on the backend while running locally. The expected outcome is for me to receive an email when I click the "Submit" button. However, up ...

Is there a way to position the text within an email body at the center using SendGrid?

I've been working on creating an email newsletter template using SendGrid, and I've run into a formatting issue where the content doesn't align properly in the email body. The image below shows how it's appearing incorrectly. Does anyon ...

How can you handle all HTML tags with Regex in a single line of code?

I've developed a PHP script that converts all inline CSS in HTML tags to classes. Visit the following link for more information: https://gist.github.com/iBars/aa52c6119e53908c91ac553aeba229e0 However, it currently only processes tags that are the onl ...

Can anyone share tips on how to ensure that text placed over an image can adapt and respond effectively

I'm facing some difficulty in ensuring that my text remains responsive alongside the image it's paired with, especially on mobile view. This is how the module appears in desktop/tablet view: https://i.sstatic.net/85mik.jpg And here is its appe ...

Testing the Snackbar function with Angular and TypeScript: Unit Testing

I've encountered an issue with a method called onDelete that utilizes a MatSnackBar which is injected in the constructor like so: constructor(private todoListService: TodolistService, private snackBar: MatSnackBar) { } onDelete(todoList: TodoList): v ...

Setting table row styles for odd and even rows, based on user clicks of an <input type="file"> button

I'm currently working on a feature that allows users to upload files to a page using an button. Each file is displayed in a table as a new row. I am looking for a way to set the background color differently for odd and even rows. As of now, I am usin ...

The configuration object is invalid. Webpack has been initialized with a configuration object that does not conform to the API schema

I recently created a basic helloworld react app through an online course, but I encountered the following error: Invalid configuration object. Webpack has been initialized with a configuration object that does not adhere to the API schema. - configur ...

Tips for providing information for AJAX requests in a Vue.js-CLI application

I successfully have a Vue.js CLI project up and running. It's able to retrieve data through AJAX from localhost on port 8080 using Apache as the server. After I build the project and transfer it to a directory served by Apache, everything works smooth ...

I encountered a TypeError when attempting to load MDX in Next.js with the mdx-js/react library

My Goals and Assumptions for the Project Please note that this question has been translated using Deepl Translations. I aim to integrate mdx-js/react into Next.js for loading mdx files. Environment Details: Operating System: macOS Big Sur Node Version: ...