I have put in a mouseenter and mouseleave on the li tag that i want when a person hovers over it, it will display the price on product.price. However, when i hover over it, it will display the price for all 6 rendered data instead of just the 1 its hovered on. I only want it to display pricing on the specific item its hovered on and not all. The data is being loaded from firebase. Please see below template code and image here for reference.
<div class="relative w-full pb-6 -mb-6 overflow-x-auto scrollbar-hide">
<ul role="list" class="mx-4 inline-flex space-x-0 gap-2 sm:mx-6 lg:mx-0 lg:space-x-0 lg:grid lg:grid-cols-6 lg:gap-x-4">
<li v-if="products.length" v-for="product in products" :key="product.id" #mouseenter="hover = true" #mouseleave="hover = false" class="w-44 inline-flex border hover:border-black rounded-lg p-4 lg:w-auto">
<div class="group relative">
<div class="w-[70%] lg:w-[55%] bg-gray-white overflow-hidden">
<img :src="product.imageSrc" :alt="product.imageAlt" class="w-full h-20 overflow-hidden object-center object-contain" />
</div>
<div class="mt-2">
<h3 class="mt-1 font-rubikreg h-11 overflow-hidden text-xs lg:text-base uppercase text-gray-900">
<a :href="product.href">
<span class="absolute inset-0" />
{{ product.name }}
</a>
</h3>
<p class="mt-3 lg:mt-6 font-rubiklight uppercase text-xs lg:text-sm text-gray-900">
Cheapest At
</p>
<p class="mt-1 font-rubikreg underline-offset-2 underline uppercase text-xs lg:text-sm text-gray-900">
{{ product.cheapestat }}
</p>
<p v-if="hover" class="mt-5 text-2xl uppercase font-rubik text-gray-900">
<span class="text-xs">From</span>
A${{ product.price }}
</p>
</div>
</div>
</li>
</ul>
</div>
script code on firebase data
setup() {
onMounted(() => {
onSnapshot(collection(db, "malesneakers") , (querySnapshot) => {
const maleProducts = [];
querySnapshot.forEach((doc) => {
const mlproducts = {
id: doc.id,
imageSrc: doc.data().imageSrc,
name: doc.data().name,
price: doc.data().price,
cheapestat: doc.data().cheapestat,
svgSrc: doc.data().svgSrc,
href: doc.data().href,
}
maleProducts.push(mlproducts)
});
products.value = maleProducts
});
});
Try with product.id instead of boolean for hover variable:
const { ref } = Vue
const app = Vue.createApp({
setup() {
const products = ref([{id: 1, name: 'aaa', href: '#', cheapestat: 5, price: 7}, {id: 2, name: 'bbb', href: '#', cheapestat: 5, price: 5}])
const hover = ref(null)
return {
products, hover
};
},
})
app.mount('#demo')
<script src="https://unpkg.com/vue#3/dist/vue.global.prod.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" integrity="sha512-wnea99uKIC3TJF7v4eKk4Y+lMz2Mklv18+r4na2Gn1abDRPPOeef95xTzdwGD9e6zXJBteMIhZ1+68QC5byJZw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div id="demo">
<div class="relative w-full pb-6 -mb-6 overflow-x-auto scrollbar-hide">
<ul v-if="products.length" role="list" class="mx-4 inline-flex space-x-0 gap-2 sm:mx-6 lg:mx-0 lg:space-x-0 lg:grid lg:grid-cols-6 lg:gap-x-4">
<!-- 👇 here you set hover to product.id -->
<li v-for="product in products" :key="product.id"
#mouseenter="hover = product.id" #mouseleave="hover = null" class="w-44 inline-flex border hover:border-black rounded-lg p-4 lg:w-auto">
<div class="group relative">
<div class="w-[70%] lg:w-[55%] bg-gray-white overflow-hidden">
<img :src="product.imageSrc" :alt="product.imageAlt" class="w-full h-20 overflow-hidden object-center object-contain" />
</div>
<div class="mt-2">
<h3 class="mt-1 font-rubikreg h-11 overflow-hidden text-xs lg:text-base uppercase text-gray-900">
<a :href="product.href">
<span class="absolute inset-0" />
{{ product.name }}
</a>
</h3>
<p class="mt-3 lg:mt-6 font-rubiklight uppercase text-xs lg:text-sm text-gray-900">
Cheapest At
</p>
<p class="mt-1 font-rubikreg underline-offset-2 underline uppercase text-xs lg:text-sm text-gray-900">
{{ product.cheapestat }}
</p>
<!-- 👇 here you check hover for product.id -->
<p v-if="hover === product.id" class="mt-5 text-2xl uppercase font-rubik text-gray-900">
<span class="text-xs">From</span>
A${{ product.price }}
</p>
</div>
</div>
</li>
</ul>
</div>
</div>
Divide-y serves to add dividers 'in between' stacked elements. When rendering a list with AlpineJS (x-for) and TailwindCSS, however, we find that the template tag is causing the CSS to add a divider there as well, which is an undesired effect.
Is there a Tailwind-way to prevent this?
e.g.
<ul role="list" class="divide-y divide-gray-200" x-data="taskModel()">
<template x-for="task in taskList">
<li class="py-4 flex">
<img class="h-10 w-10 rounded-full" src="https://images.unsplash.com/photo-1491528323818-fdd1faba62cc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="">
<div class="ml-3">
<p class="text-sm font-medium text-gray-900" x-text="task.name"></p>
<p class="text-sm text-gray-500" x-text="task.email"></p>
<p class="text-sm text-gray-500" x-text="task.due"></p>
</div>
</li>
</template>
</ul>
<script>
function taskModel() {
return {
taskList: [
{
name: 'Calvin Hawkins',
email: 'calvin.hawkins#example.com',
due: '2021-08-28'
}
]
};
}
</script>
Thank you!
This is a pretty well documented and accounted for issue. As described in the docs https://tailwindcss.com/docs/upgrading-to-v2#add-hidden-to-any-template-tags-within-space-or-divide-elements All you need to do is add the hidden attribute to your template tag.
In your case the code should be:
<ul role="list" class="divide-y divide-gray-200" x-data="taskModel()">
<!-- Add hidden attribute -->
<template x-for="task in taskList" hidden>
<li class="py-4 flex">
<img class="h-10 w-10 rounded-full" src="https://images.unsplash.com/photo-1491528323818-fdd1faba62cc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="">
<div class="ml-3">
<p class="text-sm font-medium text-gray-900" x-text="task.name"></p>
<p class="text-sm text-gray-500" x-text="task.email"></p>
<p class="text-sm text-gray-500" x-text="task.due"></p>
</div>
</li>
</template>
</ul>
<script>
function taskModel() {
return {
taskList: [
{
name: 'Calvin Hawkins',
email: 'calvin.hawkins#example.com',
due: '2021-08-28'
}
]
};
}
</script>
How can I create dropdown animation when I click to 3 dots and if I click one more time it will toggle the dropdown.
Here is my following code:
const [modalStatus, setModalStatus] = useState(false);
const openModal = () => {
setModalStatus(true);
};
<div className="member-edit" onClick={openModal}>
<Symlink />
</div>
{modalStatus && <TeamStatusModal />}
<div
className="member-avatar"
style={{
backgroundImage: `url(${member.User.picture})`,
}}
/>
<div className="member-description">
<p className="member-name">{member.User.fullname}</p>
<p className="member-date">
Joined on {moment(member.date_joined).format("MMMM Do, YYYY")}
</p>
</div>
Updated add TeamStatusModal.js:
const TeamStatusModal = () => {
return (
<div className="team-status-modal-container">
<div className="status">
<ProfileIcon /> <span>View Profile</span>
<hr />
</div>
<div className="status">
<MessageIcon /> <span>Message Me</span>
<hr />
</div>
<div className="status">
<ReviewIcon /> <span>Leave Review</span>
</div>
</div>
);
};
You should reorganize the logic a bit. Intead of: {modalStatus && <TeamStatusModal />} you can pass the state as a prop like this:
<TeamStatusModal active={modalStatus} />
and then you will use it in the TeamStatusModal component:
const TeamStatusModal = ({ active }) => {
return (
<div className={`team-status-modal-container ${active ? 'ACTIVE_CLASS' : ''}`}>
<div className="status">
<ProfileIcon /> <span>View Profile</span>
<hr />
</div>
<div className="status">
<MessageIcon /> <span>Message Me</span>
<hr />
</div>
<div className="status">
<ReviewIcon /> <span>Leave Review</span>
</div>
</div>
);
};
Another approach is using e.g. Framer Motion library, which allows animate removing elements from DOM.
https://www.framer.com/api/motion/animate-shared-layout/#syncing-layout-animations
I have a problem with my final paper assignment. I have an Angular project with a Login component and was trying not to show the toolbar (another component) when the system does not have a currentUser. Well, I managed to get to the result using <ng-content></ng-content> in the Toolbar, but the Login style changes when I do it this way.
login.component.html
<div class="logo">
<a href="https://www.cedupcriciuma.com.br/" target="_blank"><img class="iconLogo"
src="../../../../assets/LogoCedup.png" alt="Logo"></a>
</div>
<div class="spinnerDiv">
<svg class="spinnerBar" *ngIf="loading" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="42" />
</svg>
</div>
<div class="container">
<div class="containerText">
<h1 class="textImportant">O novo portal do <span>CooperCedup</span>, trazendo ainda mais confiança para seus
alunos!</h1>
<h3 class="textSub">Mais simples, prático e moderno. A cara do nosso CEDUP.</h3>
</div>
<div> <img class="flatImage" src="../../../../assets/imageDocument.svg" alt="Imagem simples de um documento"> </div>
<mat-card>
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<mat-card-content>
<div>
<h1 mat-form-title>
<b class="loginText">Login</b>
</h1>
<br>
<mat-form-field appearance="fill">
<mat-label>MatrÃcula</mat-label>
<input formControlName="login" matInput placeholder="" required maxlength="20">
<button mat-icon-button matSuffix>
<mat-icon>face</mat-icon>
</button>
</mat-form-field>
<br>
<mat-form-field appearance="fill">
<mat-label>Senha</mat-label>
<input formControlName="password" matInput [type]="hide ? 'password' : 'text'" required
maxlength="11">
<button mat-icon-button matSuffix (click)="hide = !hide" [attr.aria-label]="'Hide password'"
[attr.aria-pressed]="hide">
<mat-icon>{{hide ? 'visibility_off' : 'visibility'}}</mat-icon>
</button>
<mat-hint align="end"><u><a href="#" style="text-decoration: none; color: #ffc107;">Esqueci
minha senha</a></u></mat-hint>
</mat-form-field>
<br>
</div>
<br>
</mat-card-content>
<button type="submit" (click)="loadingSpinner()" class="loginButton">Entrar</button>
<!--(click)="Submit()"-->
<mat-card-actions>
</mat-card-actions>
</form>
</mat-card>
</div>
<div class="shape">
<svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120" preserveAspectRatio="none">
<path
d="M0,0V46.29c47.79,22.2,103.59,32.17,158,28,70.36-5.37,136.33-33.31,206.8-37.5C438.64,32.43,512.34,53.67,583,72.05c69.27,18,138.3,24.88,209.4,13.08,36.15-6,69.85-17.84,104.45-29.34C989.49,25,1113-14.29,1200,52.47V0Z"
opacity=".25" class="shape-fill"></path>
<path
d="M0,0V15.81C13,36.92,27.64,56.86,47.69,72.05,99.41,111.27,165,111,224.58,91.58c31.15-10.15,60.09-26.07,89.67-39.8,40.92-19,84.73-46,130.83-49.67,36.26-2.85,70.9,9.42,98.6,31.56,31.77,25.39,62.32,62,103.63,73,40.44,10.79,81.35-6.69,119.13-24.28s75.16-39,116.92-43.05c59.73-5.85,113.28,22.88,168.9,38.84,30.2,8.66,59,6.17,87.09-7.5,22.43-10.89,48-26.93,60.65-49.24V0Z"
opacity=".5" class="shape-fill"></path>
<path
d="M0,0V5.63C149.93,59,314.09,71.32,475.83,42.57c43-7.64,84.23-20.12,127.61-26.46,59-8.63,112.48,12.24,165.56,35.4C827.93,77.22,886,95.24,951.2,90c86.53-7,172.46-45.71,248.8-84.81V0Z"
class="shape-fill"></path>
</svg>
</div>
toolbar-menu.component.html
<div>
<mat-toolbar color="accent" *ngIf = currentUser>
<div fxShow="true" fxHide.gt-sm="true">
<button mat-icon-button (click)="sidenav.toggle()">
<mat-icon>menu</mat-icon>
</button>
</div>
<img fxShow="false" fxHide.gt-sm="true" class="iconLogo" style="width: 5%;" src="../../../../assets/LogoCedupBranca-02.png" alt="Logo">
<a mat-button class="companyName" routerLink="/pages/home">
<span>Cooper Cedup</span>
</a>
<span class="spacer"></span>
<div class="panel-open" fxShow="true" fxHide.lt-md="true">
<a mat-button routerLink="/pages/students">Alunos</a>
<a mat-button routerLink="/pages/accountability">Prestação de Contas</a>
<a mat-button routerLink="/pages/bills">Boletos</a>
<a mat-button routerLink="/pages/charts">Gráficos</a>
<button (click)="encerrarSessao()" class="exitButton" mat-icon-button aria-label="Example icon-button with a heart icon">
<mat-icon>exit_to_app</mat-icon>
</button>
</div>
</mat-toolbar>
<mat-sidenav-container color="primary" fxFlexFill class="container" >
<mat-sidenav color="primary" #sidenav fxLayout="column" mode="over" opened="false" fxHide.gt-sm="true">
<div fxLayout="column">
<a mat-button routerLink="/pages/students" (click)="sidenav.close()" >Alunos</a>
<a mat-button routerLink="/pages/accountability" (click)="sidenav.close()">Prestação de Contas</a>
<a mat-button routerLink="/pages/bills" (click)="sidenav.close()">Boletos</a>
<a mat-button routerLink="/pages/charts" (click)="sidenav.close()">Gráficos</a>
<a mat-raised-button color="warn" routerLink="/login" (click)="encerrarSessao()">Logout</a>
</div>
</mat-sidenav>
<mat-sidenav-content fxFlexFill>
<ng-content></ng-content>
</mat-sidenav-content>
</mat-sidenav-container>
</div>
app.component.html
<app-toolbar-menu >
<router-outlet></router-outlet>
</app-toolbar-menu>
IMAGES OF THE APPLICATION
How it should be
How it is
Thanks for your help!
I understood that You are trying to change the layout based on whether user is logged in or not.
some way to do this is by having two Layouts like follows
BaseLayoutComponent
#Component({
selector: 'app-base-layout',
template: `
<router-outlet></router-outlet>
`
})
export class BaseLayoutComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
SiteLayoutComponent
#Component({
selector: 'app-site-layout',
template: `
<app-header></app-header>
<router-outlet></router-outlet>
`
})
export class SiteLayoutComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
and you change switch them in your app-routing.module.ts like this
const routes: Routes = [{
path: '',
component: SiteLayoutComponent,
children: [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent }
]
},
{
path: '',
component: BaseLayoutComponent,
children: [
{
path: 'auth',
loadChildren: () => import('./auth/auth.module').then(m => m.AuthModule),
canActivate: [NotLoggedInGuard]
}
]
},
];
the NotLoggedInGuard just check if user is not logged in
I have added bulma.css in my Next.js project and all runs well, but navbar toggle doesn't work because need add some pure javascript code and React doesn't provide pure DOM events
Just add React Lifecycle event and put your code.
ORIGINAL example:
import React from "react";
class NavBar extends React.Component {
componentDidMount() {
const $navbarBurgers = Array.prototype.slice.call(
document.querySelectorAll(".navbar-burger"),
0
);
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach(el => {
el.addEventListener("click", () => {
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle("is-active");
$target.classList.toggle("is-active");
});
});
}
}
render() {
return (
<nav className="navbar" role="navigation" aria-label="main navigation">
<div className="navbar-brand">
<a className="navbar-item" href="https://bulma.io">
<img
src="https://bulma.io/images/bulma-logo.png"
width="112"
height="28"
/>
</a>
<a
role="button"
className="navbar-burger burger"
aria-label="menu"
aria-expanded="false"
data-target="navbarBasicExample"
>
<span aria-hidden="true" />
<span aria-hidden="true" />
<span aria-hidden="true" />
</a>
</div>
<div id="navbarBasicExample" className="navbar-menu">
<div className="navbar-start">
<a className="navbar-item">Home</a>
<a className="navbar-item">Documentation</a>
<div className="navbar-item has-dropdown is-hoverable">
<a className="navbar-link">More</a>
<div className="navbar-dropdown">
<a className="navbar-item">About</a>
<a className="navbar-item">Jobs</a>
<a className="navbar-item">Contact</a>
<hr className="navbar-divider" />
<a className="navbar-item">Report an issue</a>
</div>
</div>
</div>
<div className="navbar-end">
<div className="navbar-item">
<div className="buttons">
<a className="button is-primary">
<strong>Sign up</strong>
</a>
<a className="button is-light">Log in</a>
</div>
</div>
</div>
</div>
</nav>
);
}
}
export default NavBar;
I had the same issue and in my case I can resolve it adding in the _app component this line
import 'bulma/css/bulma.css