load a component every half second - vuejs3

In a vuejs app, I have a component that is loaded while waiting for reply from the api.
It contains a simple blurred line (no props or events). I want to load that same component every half second additionnaly, i.e. it starts with one line, half a second later a second line, after another half second the third line and so on.
<TheLoadingLine />
TheLoadingLine contains:
<template>
<div class="flex flex-row justify-between md:mb-4 blur-sm ">
<div class="grow flex flex-col md:flex-row justify-between text-bleulfdm pl-6 pr-4 p-1 mb-1 shadow-md xl:rounded-full shadow-bleutresclair text-sm xl:text-lg">
<div class="flex flex-row w-full">
<span class="basis-12 md:basis-24">2 janv</span>
<span class="md:basis-72 ">intitule</span>
<span class="inline-block">catégorie</span>
</div>
<div>
<div class="flex flex-row justify-between" >
<div></div>
<div class="font-bold lg:font-normal">10€</div>
</div>
</div>
</div>
</div>
</template>
I thought of a function with a setInterval, something like:
let timer = setInterval(load_component_function, 500)
But I have no real clue of what to put in such a function and how to implement that.

It is simple. To show component in Vue you use v-if or v-show so you just need a proper condition.
<TheLoadingLine v-if="counter > 0" />
<TheLoadingLine v-if="counter > 1" />
<TheLoadingLine v-if="counter > 2" />
Just increase a counter by one in a setInterval callback
You can also use a v-for:
<TheLoadingLine v-for="c in counter" :key="c" />

Related

Animating grid elements to start from a common point and end up in its respective position

I am using framer motion, tailwind CSS ad react to try to animate grid elements in such a way that it starts from the first grid element's position and then moves on to its respective position in the grid
<div
className="
mx-auto
p-7 mt-10 md:mt-5
grid
grid-cols-1
sm:grid-cols-2
md:grid-cols-3
lg:grid-cols-4
gap-y-16
gap-x-14
">
{/* add button */}
<motion.div
className="
p-5
border-2 border-[#6e3820] rounded-3xl
hidden
max-w-[13rem]
max-h-[13rem]
cursor-pointer
active:bg-[#c37f37]
hover:bg-[#f9cdc0]
md:flex justify-center
"
onClick={formOpen}
variants={button}
whileHover="hover"
whileTap="pressed"
>
<div className="border-2 rounded-3xl border-dashed border-[#dfb589] flex items-center justify-center sm:p-5 md:p-10 lg:p-10 xl:p-14">
<button className="">
<motion.img
src="https://img.icons8.com/ios/50/dfb589/plus-math--v1.png"
whileHover={{ rotate: 45 }}
transition={{ duration: 0.6 }}
variants={plus}
/>
</button>
</div>
</motion.div>
{
usersContent.map((item)=>{
return(
<NoteCard
key = {item.id}
id = {item.id}
companion = {item.companion}
title = {item.title}
content={item.content}
deleteNote={deleteNote}
/>
)
})
}
</div>
Here I want the other notecards to start from the same position the add button is in and then go to its default location. If not with framer motion is it possible any other way?

how to automatically break line in tailwind

I am making a html based tag filter based on tailwind.
<div class="p-3 border-b">
<div class="flex flex-col space-y-2 mt-2">
<div class="flex flex-row space-x-2 text-sm" v-for="(filter,index) in filters" :key="index">
<div class="w-16 text-base text-gray-700"> {{ filter.label }} </div>
<div class=" flex flex-row space-x-5 text-gray-500 leading-6">
<span class="cursor-pointer"> {{ categoryItem.name }} </span>
</div>
</div>
</div>
</div>
filters:[
{
name:'type',
label:'Type',
category:[
{'name':'All'},
{'name':'Animals, Plants & Land'},
{'name':'Maintenance, Service & Repair'},
{'name':'Management & Planning'},
{'name':'Medical Technology'},
{'name':'Transport'},
{'name':'Storage, Dispatching & Delivery'},
{'name':'Retail Sales & Customer Service'},
{'name':'Medical Technologyy'},
....
]
}
],
However since the number of category list is more than 30 items, the actual html page looks very wired since the tag list grows horizontally instead of breaking space into multiple lines.
how to deal with this?
You can check out the Tailwind CSS line clamp package to solve this problem.
Here is a link on how to use it.

How to balance 2 components by element regardless of surrounding content in React/CSS/Tailwind?

I am stuck with a design challenge where I have a reusable component in React, which is a button surrounded by text content above and below. I am trying to figure out a way to balance these side by side by their center element (a button). I am using Tailwind as my CSS solution.
I have included above an illustration of this, where the red box denotes the button.
My code so far:
<div className="flex flex-row gap-8 justify-center items-center w-full">
<Component top={< />} bottom={< />} />
<Component top={< />} bottom={< />} />
</div>
The component:
<Card
className="flex flex-1 justify-center content-center items-center w-full h-full border-none shadow-none"
{...otherProps}
>
{top}
<Button
className="w-full"
>
title
</Button>
{bottom}
</Card>
This works until narrow screens force text content onto new lines and I cannot figure out a way to achieve this.
Any help appreciated!

How to focus a div tag with a tailwind?

I'm using tailwind and Vue to make some reusable toggle component. Border of component is gray color, but plan is when I click on component, border will be red like on a image below (I'm using/trying using focus).
Problem is because I can use focus just on input and button, but I need focus on div tag
I have one div, inside is two paragraph and one input (type:checkbox). I tried with tabindex and it doesn't work, when I click in checkbox or input field (gray button) it doesn't focus. Only focuses when I click inside a component but not in checkbox field.
Code is
<template>
<div>
<div tabindex="1"
class="relative border border-gray-300 px-10 max-w-md mx-auto my-2 cursor-pointer rounded-lg px-5 py-4 rounded-lg border bg-white transition duration-150
ease-in-out placeholder:text-zinc-400 hover:bg-zinc-100 focus:border-transparent
focus:outline-none focus:ring disabled:opacity-50 motion-reduce:transition-none
dark:bg-zinc-900 dark:placeholder:text-zinc-500 dark:hover:bg-zinc-800" :class="[ error
? 'border-red-500 caret-red-500 focus:ring-red-500/50'
: 'border-zinc-300 caret-primary focus:ring-primary/50 dark:border-zinc-600 dark:focus:border-transparent',
]"
>
<div class="flex justify-between">
<div>
<h1 class="text-md font-semibold text-black">
{{ titleToggle }}
</h1>
<p class="inline text-md text-gray-500">
{{ subtitleToggle }}
</p>
</div>
<label class="switch my-auto">
<input
:value="toggleSwitch"
v-bind="$attrs" type="checkbox"
class="rounded-lg " :class="[
error
? 'border-red-500 caret-red-500 focus:ring-red-500/50'
: 'border-zinc-300 caret-primary focus:ring-primary/50
dark:border-zinc-600 dark:focus:border-transparent',]" #click="updateInput"
>
<span :class="[toggleSwitch ? 'bg-red-500 border-red-500' : 'bg-gray-300 border-gray-300',
]" class="slider round absolute cursor-pointer inset-0 border rounded-full"
/>
</label>
</div>
</div>
</div>
</template>
Is anyone have advice, or maybe different way how to do it ?
I don't really understand your question, but you may have a look at this from the tailwind documentation :
focus-within (:focus-within) : Style an element when it or one of its descendants has focus using the focus-within modifier:
<div class="focus-within:shadow-lg ...">
<input type="text" />
</div>
https://tailwindcss.com/docs/hover-focus-and-other-states#focus

Bootstrap grid system doesn't work properly

I am using Bootstrap to design my React project and all of a sudden the grid system doesn't work properly.Basically I need to have the first div with the className of row above the Card components, and centered.I have added more code but nothing that had to do with that particular main page or styling.I have pasted below my code.Does anyone know why this could've happened and how to fix it?
return (
<div>
<section id="service">
<div className='container'>
<div className='row'>
<div className='col-12'>
<h3 className='fs-5 text-center mb-0'>Our Services</h3>
<h1 className='display-6 text-center mb-4'>Our <b>Awesome</b> Services</h1>
<hr className='w-25 mx-auto'/>
</div>
</div>
<div className='row'>
<div className='col-md-4'>
<Card font = {'fa fa-cogs fa-4x mb-4 text-primary'} title='Easy Usage' content='Access your assigned task with only one click and start testing your code right now.'/>
</div>
<div className='col-md-4'>
<Card font = {'fa fa-cogs fa-4x mb-4 text-primary'} title='Instant Feedback' content='Run your solution using only one submit button with the help of our online compiler.'/>
</div>
<div className='col-md-4'>
<Card font = {'fa fa-cogs fa-4x mb-4 text-primary'} title='Optimize your time' content='Reduce your time spending on uploading assignments with our easy dashboard method.'/>
</div>
</div>
</div>
</section>
</div>
)

Resources