I have a button with send and on clicking, I want to move it, (this is just for asking) can you tell me why it is not working
This is the jsx
import React from 'react'
import './home.css'
import sound from './sound.mp3'
import video from './A.mp4';
import img1 from './home1.jpeg';
import img2 from './home4.jpeg';
import img3 from './home3.jpeg';
import { useRef } from 'react';
return (
<>
<div className="form" onClick={prevent} >
<form action="" className='contact_form'>
<div className="heading_contact">
Get in touch with me
</div>
<input className="info_contact" placeholder='Your Name' ></input>
<input className="info_contact" placeholder='Your Email' ></input>
<textarea className='info_contact' name="" id="" cols="27" rows="10" placeholder='You message'></textarea>
<button id='delivery' className="submit" >
<i class="fa-solid fa-truck" ></i>
</button>
</form>
<div className='alternates' >
Or contact me through
</div>
</div>
</>
)
}
And this is the CSS for the animation
#delivery:active {
position: relative;
animation-name: delivery;
animation-duration: 15s;
animation-iteration-count: 5;
#keyframes delivery{
from {
margin-right: 0px;
}
to {
margin-right: 100px;
}
}
}
I also tried to bring the keyframes section out of the :active selector but it still won't work.
Related
Buefy has a Field.vue component that looks as shown below
<template>
<div class="field" :class="rootClasses">
<div
v-if="horizontal"
class="field-label"
:class="[customClass, fieldLabelSize]">
<label
v-if="hasLabel"
:for="labelFor"
:class="customClass"
class="label" >
<slot v-if="$slots.label" name="label"/>
<template v-else>{{ label }}</template>
</label>
</div>
<template v-else>
<label
v-if="hasLabel"
:for="labelFor"
:class="customClass"
class="label">
<slot v-if="$slots.label" name="label"/>
<template v-else>{{ label }}</template>
</label>
</template>
<b-field-body
v-if="horizontal"
:message="newMessage ? formattedMessage : ''"
:type="newType">
<slot/>
</b-field-body>
<div v-else-if="hasInnerField" class="field-body">
<b-field
:addons="false"
:type="newType"
:class="innerFieldClasses">
<slot/>
</b-field>
</div>
<template v-else>
<slot/>
</template>
<p
v-if="hasMessage && !horizontal"
class="help"
:class="newType"
>
<slot v-if="$slots.message" name="message"/>
<template v-else>
<template v-for="(mess, i) in formattedMessage">
{{ mess }}
<br :key="i" v-if="(i + 1) < formattedMessage.length">
</template>
</template>
</p>
</div>
</template>
Full code for the above is right HERE
I want to add a transition the paragraph with class help so that it doesn't abruptly appear and disappear. How do I achieve this?
Because Bulma field just fill the <p> tag with text and add the respective class like .is-danger you can play with animations of these class
.help.is-danger {
transition: all 300ms;
animation: reveal 1s;
}
#keyframes reveal {
from {
opacity: 0;
transform: translateX(-30px);
}
to {
opacity: 1;
transform: translateX(0px);
}
}
const example = {
data() {
return {
hasError: true
};
}
};
const app = new Vue(example);
app.$mount("#app");
.help {
height: 0px;
transition: all 300ms;
}
.help.is-danger {
height: 18px;
animation: reveal 1s;
}
#keyframes reveal {
from {
transform: scale(0);
opacity: 0;
transform: translateX(-30px);
}
to {
opacity: 1;
transform: translateX(0px);
}
}
<link href="https://unpkg.com/buefy/dist/buefy.min.css" rel="stylesheet" />
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<script src="https://unpkg.com/buefy/dist/buefy.min.js"></script>
<div id="app" class="container">
<section>
<b-checkbox v-model="hasError">Show errors</b-checkbox>
<b-field label="Username" :type="{ 'is-danger': hasError }" :message="{ 'Username is not available': hasError }">
<b-input value="johnsilver" maxlength="30"></b-input>
</b-field>
<b-field label="Password" :type="{ 'is-danger': hasError }" :message="[
{ 'Password is too short': hasError },
{ 'Password must have at least 8 characters': hasError }
]">
<b-input value="123" type="password" maxlength="30"></b-input>
</b-field>
</section>
</div>
I am using react in an application.
I am trying to show cards (not by using bootstrap or other CSS Library). I using my own CSS to show Cards.
Now I want to show a left and Right Arrow on Each Card when each card 'll have some images related to it.
When user hover the mouse on each card and if there are some images then card 'll show left and right arrows and then user can click on left and right arrow to see more images.
I am using this example for this purpose and trying to implement though ReactJs.
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow
Please see tried code below
------------------------------------------card.js-------------------------------
import React, { Component } from 'react';
import ReactDOM from "react-dom";
import Button from '../Button';
import Stats from '../Stats';
import { loadData } from '../../actions';
import './examplecard.css';
class ExampleCard extends Component {
componentDidMount() {
this.props.loadData();
}
componentWillUnmount(){
}
render() {
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(/*n*/) {
//var i;
return
(<div className="w3-content w3-display-container">
{/* var x = document.getElementsByClassName("mySlides"); */}
{/* if (n > x.length) {slideIndex = 1} */}
{/* var slideIndex = 1; */}
{/* if (n < 1) {slideIndex = x.length} */}
{/* for (i = 0; i < x.length; i++) { */}
{/* x[i].style.display = "none"; */}
<img className="mySlides imageHide" src="img_snowtops.jpg" />
<img className="mySlides imageHide" src="img_lights.jpg" />
<img className="mySlides imageHide" src="img_mountains.jpg" />
<img className="mySlides imageHide" src="img_forest.jpg" />
{/* } */}
{/* x[slideIndex-1].style.display = "block"; */}
<img className="mySlides imageShow" src={"img_forest.jpg"} />
<button className="w3-button w3-black w3-display-left" onClick={() => plusDivs(-1)}>❮</button>
<button className="w3-button w3-black w3-display-right" onClick={() =>plusDivs(1)}>❯</button>
</div>)
}
return (
<div>
<div className="row">
<section className="">
{data.map(image => (
<div
key={image.id}
className="c"
>
<Stats stats={imageStats[image.id]} />
<div className="cad">
<showDivs />
<img className="none"
src={image.urls.small}
alt={image.user.username}
/>
<span>Description</span>
{/* <div class="w3-content w3-display-container">
<img class="mySlides" src="img_snowtops.jpg" style="width:100%" />
<img class="mySlides" src="img_lights.jpg" style="width:100%" />
<img class="mySlides" src="img_mountains.jpg" style="width:100%" />
<img class="mySlides" src="img_forest.jpg" style="width:100%" />
<button class="w3-button w3-black w3-display-left" onclick="plusDivs(-1)">❮</button>
<button class="w3-button w3-black w3-display-right" onclick="plusDivs(1)">❯</button>
</div> */}
</div>
</div>
))}
</section>
</div>
</div>
</div>
);
}
}
-------------------------examplecard.css-----------------------------------
.c {
float: left;
width: 20%;
padding: 0 10px;
}
.c {
float: left;
width: 20%;
padding: 0 10px;
}
.row {margin: 0 -5px;}
cad {
padding: 6px;
max-width: 100%;
margin: 0 auto;
}
.w3-content,.w3-auto{margin-left:auto;margin-right:auto}.w3-content{max-width:980px}.w3-auto{max-width:1140px}
.w3-display-container{position:relative}.w3-tooltip .w3-text{display:none}.w3-tooltip:hover .w3-text{display:inline-block}
.w3-display-container:hover .w3-display-hover{display:block}.w3-display-container:hover span.w3-display-hover{display:inline-block}.w3-display-hover{display:none}
.mySlides {display:none;}
.w3-button{border:none;display:inline-block;padding:8px 16px;vertical-align:middle;overflow:hidden;text-decoration:none;color:inherit;background-color:inherit;text-align:center;cursor:pointer;white-space:nowrap}
.w3-button{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}
.w3-button:disabled{cursor:not-allowed;opacity:0.3}.w3-disabled *,:disabled *{pointer-events:none}
.w3-button:first-child,.w3-dropdown-click:hover > .w3-button:first-child{background-color:#ccc;color:#000}
.w3-button,.w3-bar-block .w3-dropdown-click .w3-button{width:100%;text-align:left;padding:8px 16px}
.w3-button{white-space:normal}
.w3-button,.w3-dropdown-click.w3-mobile,.w3-dropdown-click.w3-mobile .w3-btn,.w3-dropdown-click.w3-mobile .w3-button{width:100%}
.w3-button:hover{color:#000!important;background-color:#ccc!important}
.w3-black,.w3-hover-black:hover{color:#fff!important;background-color:#000!important}
.w3-display-left{position:absolute;top:50%;left:0%;transform:translate(0%,-50%);-ms-transform:translate(-0%,-50%)}
.w3-display-right{position:absolute;top:50%;right:0%;transform:translate(0%,-50%);-ms-transform:translate(0%,-50%)}
.imageHide
{
width:'100%';display:'none';
}
.imageShow
{
display:'block';
}
I am trying to implement the same code as in w3schools but found some issues.
What should I do to fix in code?
Application built with
{
"react": "16.13.0",
"react-dom": "^16.13.0",
"react-redux": "^7.2.0",
"redux": "^4.0.4"
"#material-ui/core": "^4.9.5"
}
I am facing these error message .
./src/components/Cards/ExampleCard.js
Line 43:17: Expected an assignment or function call and instead saw an expression no-unused-expressions
Search for the keywords to learn more about each error.
I have this piece of code for my mega menu:
<button mat-button [matMenuTriggerFor]="objectmenu">Objects</button>
<mat-menu #objectmenu="matMenu" >
<div class="menu-content" [style.backgroundColor]="getUnSelectedRandomColor()" style="height: 550px;">
<div fxFlex="100" fxFlex.gt-sm="30" fxFlex.sm="45" class="dropdown-menu-items">
<div class="dropdown-menu-btns" *ngFor="let parent of (objectList$ | async)"
(mouseover)="openCategory($event,
parent)"
[style.background-color] = "this.selectedColor === (parent.categoryId * 100) ? getSelectedRandomColor() : getUnSelectedRandomColor()"
>{{parent.name}}</div>
</div>
<div class="theme-container">
<div class="theme-container" style=" padding-bottom: 0px !important; padding-top: 7px !important;">
<div fxLayout="column" fxLayout.gt-sm="row wrap" fxLayoutAlign="center center" class="content border-lighter">
<div fxFlex="100" fxFlex.gt-sm="100" fxLayout="column" fxLayoutAlign="center center">
<h2 *ngIf="this.selectedCategory" class="uppercase">{{this.selectedCategory.name}}</h2>
</div>
</div>
<div class="content border-lighter" [style.backgroundColor]="getSelectedRandomColor()" style="height: 380px;">
<div fxLayout="row wrap" fxLayoutAlign="space-between">
<div fxFlex="100" fxFlex.gt-sm="70" fxFlex.sm="45" style="column-count: 2;">
<ul class="ht-dropdown megamenu-two d-flex"
*ngFor="let parent of (childCategories$ | async)" style="list-style: none;">
<label [routerLink]="['/products']" [queryParams]="{categories: parent.categoryId}"
routerLinkActive="router-link-active">{{parent.name}}</label>
<li *ngFor="let child of parent.childrenCategories"
[routerLink]="['/products']" [queryParams]="{categories: child.categoryId}"
routerLinkActive="router-link-active">
{{child.name}}
</li>
</ul>
</div>
<div fxFlex="100" fxFlex.gt-sm="30" ngClass.lt-md="pt-5" style="background-size: contain !important;"
[style.background]="selectedCategoryUrl">
</div>
</div>
</div>
</div>
<div fxLayout="row" fxLayout.xs="column" fxLayoutAlign="space-between center" >
<img *ngFor="let brand of (relatedBrandsList$ | async)" [src]=" brand.thumbnail | safeHtml" style="width: 110px; height: 110px; border-radius: 50%;"/>
</div>
</div>
</div>
</mat-menu>
and it gives me the following style:
As shown in the picture, the top and the bottom edges of the menu panel are not taking the dynamic background color which I generate in my angular code by getUnSelectedRandomColor() method.
The getUnSelectedRandomColor() method is as follow:
openCategory(evt, category: Category) {
this.selectedCategory = category;
this.selectedCategoryUrl = `url('../../assets/categories/${category.categoryId}.webp')`;
this.childCategories$ = this.store.pipe(select(getChildCategories(category.categoryId)));
this.relatedBrandsList$ = this.store.pipe(select(getRelatedBrands(category.categoryId)));
this.selectedColor = category.categoryId * 100;
}
getSelectedRandomColor() {
const color = 'hsl(' + this.selectedColor + ', 30%, 75%)';
return color;
}
getUnSelectedRandomColor() {
const color = 'hsl(' + this.selectedColor + ', 30%, 86%)';
return color;
}
How can I do this?
Angular 9
What happens is that you are not affecting the menu panel item, you must get the panelId which is a property of MatMenu, with the panel id you get the element and then change the value of the attribute you want, to achieve this you can use property decorator that configures a view query ViewChild and the service Renderer2.
Here I show you an example in which I dynamically change the background of the panel according to the menu item that emits the mouseover stackblitz
import { Component, ViewChild, Renderer2 } from '#angular/core';
import { MatMenu } from '#angular/material/menu/';
#Component({
selector: 'my-app',
template: './app.component.html',
})
export class AppComponent {
#ViewChild('menu', {static: true}) menu: MatMenu
constructor(private _renderer2: Renderer2) {
}
changeBackgroundPanel(colorValue: string) {
const el = document.getElementById(this.menu.panelId);
this._renderer2.setStyle(el, 'background', colorValue);
}
}
<button mat-raised-button [matMenuTriggerFor]="menu" color="primary">Open Menu</button>
<mat-menu #menu="matMenu">
<button mat-menu-item (mouseover)="changeBackgroundPanel('blue')">Blue</button>
<button mat-menu-item (mouseover)="changeBackgroundPanel('orange')">Orange</button>
<button mat-menu-item (mouseover)="changeBackgroundPanel('red')">Red</button>
</mat-menu>
[Solution for Angular 8]
See the example working here: stackblitz
Component:
import { Component, Renderer2 } from '#angular/core';
#Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.scss' ]
})
export class AppComponent {
constructor(private _renderer2: Renderer2) {
}
changeBackgroundPanel(colorValue: string) {
const el = document.getElementById('myPanelId');
this._renderer2.setStyle(el, 'background', colorValue);
}
}
Html:
<button mat-raised-button [matMenuTriggerFor]="menu" color="primary">Open Menu</button>
<mat-menu #menu="matMenu">
<div id="myPanelId" class="menu-panel">
<button mat-menu-item (mouseover)="changeBackgroundPanel('blue')">Blue</button>
<button mat-menu-item (mouseover)="changeBackgroundPanel('orange')">Orange</button>
<button mat-menu-item (mouseover)="changeBackgroundPanel('red')">Red</button>
</div>
</mat-menu>
CSS:
.menu-panel {
margin: -8px 0;
padding: 8px 0;
}
Finally I found the answer:
::ng-deep .mat-menu-content{
padding-top: 0px !important;
padding-bottom: 0px !important;
}
I removed the paddings using the above style and then the white gaps were removed
Edit: CodeSandbox link: https://codesandbox.io/s/strange-dawn-q9zow
I'm creating a React app that I want to have a collapsible sidebar. I'm using the transition collapse utility from React-Bootstrap. Since this is for a sidebar, I'm using dimension="width". I've tried adding a transition to a few elements including the .width class as it says in the React-Bootstrap documentation, but the animation is still really choppy/not smooth. Am I missing a class, or is there something additional I need to do with the CSS?
JSX:
import React, {useState} from 'react';
import Button from 'react-bootstrap/Button';
import Collapse from 'react-bootstrap/Collapse';
import {
BrowserRouter as Router,
Switch,
Route,
Link,
Redirect,
useHistory,
useLocation
} from "react-router-dom";
import '../../custom_styles/sidebar.css';
function Visualizer() {
const [open, setOpen] = useState(false);
return (
<Router>
<div className="container-fluid h-100 p-0">
<div className="row h-100 no-gutters">
<Collapse id="sidebar" dimension="width" in={open}>
<div className="col-4 bg-dark text-white" id="example-collapse-text">
<h2>Palette</h2>
</div>
</Collapse>
<div className="col-8">
<Button
className="float-left ml-n1"
variant="dark"
onClick={() => setOpen(!open)}
aria-controls="example-collapse-text"
aria-expanded={open}
>
<div id="collapse-btn-text">Toggle Sidebar</div>
</Button>
</div>
</div>
</div>
</Router>
)
}
export default Visualizer;
CSS:
#sidebar {
transition: width 2s;
}
.width {
transition: width 2s;
}
.show {
transition: width 2s;
}
You can try to use this css
#sidebar {
transition: width 2s ease;
display: block;
width: 0;
}
#sidebar.yourActiveClass {
width: auto;
}
But first when you click on
<div id="collapse-btn-text">Toggle Sidebar</div>
button you shoule add "yourActiveClass" in
<Collapse id="sidebar" dimension="width" className={true ? "collapse width yourActiveClass" : "collapse width"} in={open}>
true means your Click function if true
using this you can more smooth your section.
In Search.tsx:
import { SearchInput } from Search.styles.ts
<SearchInput
onChange={handleChange}
value={values["searchValue"]}
placeholder="Search"
type="text"
name="searchValue"
/>
Output html:
<div class="1">
<div class="2">
<div class="3">
<span class="InputWrapper">
<input placeholder="Search" name="searchValue" class="Input input normalVariant" formnovalidate="" type="text" value="" >
</span>
</div>
</div>
</div>
In Search.styles.ts:
import * as Toolkit from "#some_repo/toolkit";
export const SearchInput = styled(Toolkit.Input)`
InputWrapper: 100%
`
I want set InputWrapper: width 100%, what is the correct way to do it?
It works just like css.
import * as Toolkit from "#some_repo/toolkit";
export const SearchInput = styled(Toolkit.Input)`
.InputWrapper {
width: 100%;
};
import * as Toolkit from "#some_repo/toolkit";
export const SearchInput = styled(Toolkit.Input)`
width: 100%;
`