how to apply bootstrap active class to an onclick - html

How do you apply a bootstrap class like nav-link active to a onlick(). I've been having hard time implementing this. I thought it would have just been as simple as.
<a
onClick={() => this.props.onUpdateSelectedProbe(probe)}
className="dropdown-item nav-link active"
>
But this however just makes all list items/anchor tags active.
return (
<div style={{ alignSelf: "center" }}>
<ul className="nav nav-pills">
<li className="nav-item dropdown ">
<div
className="dropdown-menu show"
x-placement="bottom-start"
style={{
position: "relative",
willChange: "transform",
top: "5px",
overflowY: "scroll",
maxHeight: "200px"
}}
>
{this.props.searchState.isActive === false
? probes.map(probe => (
<a
onClick={() => this.props.onUpdateSelectedProbe(probe)}
className="dropdown-item"
>
<div
className="dropdown-divider"
style={{ backgroundColor: "black" }}
></div>
{probe.companyPN}: {probe.description}
</a>
))
: filteredProbes.map(filterprobe => (
<a
onClick={() =>
this.props.onUpdateSelectedProbe(filterprobe)
}
className="dropdown-item"
>
<div className="dropdown-divider"></div>
{filterprobe.companyPN}: {filterprobe.description}
</a>
))}
</div>
</li>
</ul>
</div>
);

This is a basic example of adding items to a list and conditionally showing a "selected" class
.selected {
background: red;
}
function App() {
const [people] = useState([
{ id: 0, name: "Mario" },
{ id: 1, name: "Luigi" },
{ id: 2, name: "Peach" }
]);
const [selected, setSelected] = useState({});
return (
<div>
{people.map(({ id, name }) => (
<div
className={selected[id] ? "selected" : ""}
key={id}
onClick={() => setSelected({ ...selected, [id]: true })}
>
{name}
</div>
))}
</div>
);
}
https://codesandbox.io/s/funny-nobel-e6x6e

Related

Smooth scroll when clicking a nav link - react js - react three fiber

so what I'm trying to achieve is a smooth scroll effect to a particular div on the page when I click a navbar div. I'm currently doing development with react-three-fiber and am using a custom scroll rig component . I am not too sure how to approach this. below can be found my code.
export default function App() {
const [loading, setLoading] = useState(false)
const [background, setBackground] = useState("base")
const phone = useRef()
useEffect(() => {
setTimeout(() => {
setLoading(true)
}, 2600)
}, [])
return (
<>
<Header />
{!loading ? <></> :
<Suspense>
<Canvas id={background} className="canvas-primary" camera={{ position: [0, 0, 5] }} gl={{ powerPreference: "high-performance", alpha: true, antialias: true, stencil: false, depth: true }} shadows >
<ambientLight intensity={0.5} />
<ScrollControls className='scroll-container' pages={15} >
<fog color="#161616" attach="fog" near={8} far={30} />
<BackgroundContext.Provider value={{ background, setBackground }}>
<Scene phone={phone} />
<MouseTracker phone={phone} />
<Physics allowSleep={false} iterations={15} gravity={[0, -200, 0]}>
{/* <Lamp position={[-3, 5, 0]} /> */}
</Physics>
</BackgroundContext.Provider>
<ContactShadows position={[0, -3.1, 0]} scale={10} blur={1.5} far={10} rotation={[Math.PI / 2, 0, 0]} />
<EffectComposer multisampling={15} disableNormalPass={true} >
<DepthOfField focusDistance={0} focalLength={0.02} bokehScae={2} height={480} />
<Bloom luminanceThreshold={0} luminanceSmoothing={10} height={300} opacity={1} />
</EffectComposer>
</ScrollControls>
<Html className="content"><Content /></Html>
</Canvas>
</Suspense>
}
</>
);
}
export default function Header() {
return (
<header className="primary-header">
<div className="middle">
<h1>SYMPHONY</h1>
</div>
<nav className='primary-navigation'>
<ul className="nav-area" >
<li className="item"><div id="About-us" className="link" onClick={() => handleClick(1)}>About Us</div></li>
<li className="item"><div id="D2C" className="link" onClick={() => handleClick(2)}>D2C Marketing</div></li>
<li className="item"><div id="B2B" className="link" onClick={() => handleClick("B2B")}>B2B Marketing</div></li>
<li className="item"><div id="Team" className="link" onClick={() => handleClick(4)}>Our Team</div></li>
</ul>
</nav>
<div id="et_mobile_nav_menu">
<div className="mobile_nav hidden">
<span className="select_page">Select Page</span>
<span className="mobile_menu_bar mobile_menu_bar_toggle"></span>
<ul id="mobile_menu" className="et_mobile_menu" style={{ display: "none" }}><li id="menu-item-377" className="menu-item menu-item-type-post_type menu-item-object-page menu-item-377 et_first_mobile_item">Marketing</li>
<li id="menu-item-376" className="menu-item menu-item-type-post_type menu-item-object-page menu-item-376">Web Design</li>
<li id="menu-item-374" className="menu-item menu-item-type-post_type menu-item-object-page menu-item-374">Resume</li>
<li id="menu-item-378" className="menu-item menu-item-type-post_type menu-item-object-page menu-item-378">Contact</li>
</ul>
</div>
</div>
</header >)
}
function handleClick(link) {
$("#B2B").on('click', function () { //id of the link which is being clicked
console.log(document.getElementsById('ID09'))
$('*').animate({
scrollTop: $("#ID09").offset().top //id of div to be scrolled
}, 1000);
});
}
export default function Content() {
return (
<div className="content">
<div id={"ID00"} >
<div className="Landing-page-content">
<div className="Landing-page-content-inner">
<h1>Your Marketing To The Next Generation</h1>
<h3> 5,000,000+ viewers</h3>
</div>
</div>
</div>
<div id={"ID01"} />
<div id={"ID02"} />
<div id={"ID03"} />
<div id={"ID04"} />
<div id={"ID05"} />
<div id={"ID06"} />
<div id={"ID07"} />
<div id={"ID08"} />
<div id={"ID09"} />
<div id={"ID010"} />
<div id={"ID011"} />
<div id={"ID012"} />
<div id={"ID013"} />
<div id={"ID014"} />
<div id={"ID015"} />
</div>
)
}
So, I have tried multiple approaches to this, the content component is a child to the main canvas which has an in build scrolling, However I am unsure how to manipulate the scroll bar of this particular component through vanilla js or jquery.

How to change value inside select tag when clicking on Next and Previous buttons?

I have a page where I am rendering data that is paginated. The Next and Previous button work fine but when I click on next and previous buttons, the Page number value inside the select tag does not update. Can someone tell me a fix for the same?
Here is the function that renders next and previous and current page.
`
const renderShowMore = () => {
return (
<tr>
<td colSpan={5}>
<div
style={{
display: 'flex',
justifyContent: 'space-around',
alignItems: 'center',
}}
>
<div
role={'presentation'}
style={
pagination.page > 0
? {
color: '#fff',
cursor: 'pointer',
}
: {}
}
onClick={() => {
if (pagination.page > 0) {
fetchData(pagination.page - 1);
}
}}
>
<i className="fa fa-chevron-left"></i>
Previous
</div>
<div className="btn" role={'presentation'}>
<select
className="form__select"
onChange={e => fetchData(parseFloat(e.target.value))}
>
{[...Array(pagination.totalPages).fill(10)].map((_, index) => {
return (
<option key={`Page ${index}`} value={index}>
Page {index + 1}
</option>
);
})}
</select>
</div>
<div
role={'presentation'}
style={
pagination.page < pagination.totalPages - 1
? {
color: '#fff',
cursor: 'pointer',
}
: {}
}
onClick={() => {
if (pagination.page < pagination.totalPages - 1) {
fetchData(pagination.page + 1);
}
}}
>
Next
<i className="fa fa-chevron-right"></i>
</div>
</div>
</td>
</tr>
);
};
`
Here is the fetchData function:
`
const fetchData = page => {
dispatch(
groupActions.showMore({
search: search,
page: page,
limit: pagination.limit,
}),
);
};
`
I need to make the select tag controlled but how do I do that?

Show/Hide Submenu by click

I have this part of my code in sidebar.component.html :
<ul class="nav">
<li routerLinkActive="active" *ngFor="let menuItem of menuItems" class="{{menuItem.class}} nav-item">
<a class="nav-link" [routerLink]="[menuItem.path]">
<i class="material-icons">{{menuItem.icon}}</i>
<p>{{menuItem.title}}</p>
</a>
<ng-container *ngIf="menuItem.children && menuItem.children.length > 0">
<ul class="nav">
<li routerLinkActive="active" *ngFor="let childmenu of menuItem.children"
class="{{menuItem.class}}">
<a class="nav-link" [routerLink]="[childmenu.path]">
<p>{{childmenu.title}}</p>
</a>
</li>
</ul>
</ng-container>
</li>
</ul>
and this is my code in sidebar.component.css :
export const ROUTES: RouteInfo[] = [
{ path: '/dashboard', title: 'dashbord', icon: 'dashboard', class: '', children: '' },
{
path: '/user-List', title: 'Parent', icon: 'apps', class: '', children: [
{ path: '#', title: 'Child Menu 1', icon: 'dashboard', class: '' },
{ path: '#', title: 'Child Menu 2', icon: 'add_shopping_cart', class: '' },
{ path: '#', title: 'Child Menu 3', icon: 'sports_soccer', class: '' },
]
}
];
can you help me please to show/hide submenu by click ?
In your parent component ts file create a property to store the submenu state:
showSubMenu: boolean = false;
In you parent template give your sub-menu an *ngIf and a button to toggle it:
<button (click)="showSubMenu = !showSubMenu">Toggle Sub Menu</button>
<sub-menu *ngIf="showSubMenu"></sub-menu>

React js : Change img on Div whith onMouseOver

I need your help :) (but first, sorry for my aproximate english ...).
I would like to change the 'img src' in the 'div-img' when I pass the mouse over one of the 'a' balise ... I try onMouseOver, but i failled :(
There is an image by 'a' which replaces the one in 'div-img'
EDIT : Okay, here is the almost complete code, to really see the problem :
#observer
export default class Home extends React.Component {
static readonly language = "language";
private static readonly en = "en";
private static readonly fr = "fr";
#observable private static selectLanguage = false;
public render(): ReactElement {
if (Home.selectLanguage) {
return (
<div style={{ height: '100vh', width: '100vw', overflow: 'hidden'}}>
<MyHead />
<body style={{backgroundColor: 'rgb(51, 63, 72)'}}>
<div style={{
maxWidth: '1150px',
height: '300px',
margin: 'auto',
}}>
<div style={{ display: 'flex', maxWidth: '450px'}}>
<img style={{
maxWidth: '100%',
margin: 'auto'
}}
src='/images/***.png'/>
</div>
</div>
<div style={{
display: 'flex',
flexWrap: 'wrap',
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
zIndex: 1,
}}>
<a href="/fr/" onClick={_ => { localStorage.setItem(Home.language, Home.fr); }} >
<span className= 'shadow'>
<div style={{ margin: '0 15px', padding: '75px', backgroundColor: 'rgb(175, 39, 47)', clipPath: 'polygon(0 0, 100% 8%, 100% 92%, 0 100%)'}} >
<h2>Français</h2>
</div>
</span>
</a>
<a href="/en/" onClick={_ => {localStorage.setItem(Home.language, Home.en);}}>
<span className= 'shadow'>
<div style={{ margin: '0 15px', padding: '75px', backgroundColor: 'rgb(175, 39, 47)', clipPath: 'polygon(0 8%, 100% 0, 100% 100%, 0 92%)'}}>
<h2>English</h2>
</div>
</span>
</a>
</div>
<main style={{filter: 'blur(4px)'}}>
<component1 />
<component2 />
</main>
</body>
</div>
)
}
Thank you very much in advance !
I have made a few changes to your code, first of all, I am using mouseOnEnter instead of mouseOnHover and I have also added mouseOnLeave to reset the image(because in the question you have mentioned that you want to change the image when you pass over the (Link) tag.
My solution uses the useState react hook, onMouseEnter for the div sets a random image using
https://i.picsum.photos/id/${Math.floor(Math.random() * 1084)}/50/50.jpg
https://i.picsum.photos/id/{image_id}/{width}/{height}.jpg
https://i.picsum.photos/id/50/50/50.jpg
OnMouseEnter the state is updated to the images src / location and is reset to '' onMouseLeave. Also, I have added
style={{ width: '50px', height: '50px' }}
to the div so as to keep the divs from moving around when hovering over links in the sample code. 50px is also the height of the image.
import React, { useState } from 'react'
const testCode = () => {
const [image, setImage] = useState('')
return (
<>
<div className="div-img" style={{ width: '50px', height: '50px' }}>
<img src={image} />
</div>
<div>
<a href="/fr/" onMouseEnter={() => setImage(`https://i.picsum.photos/id/${Math.floor(Math.random() * 1084)}/50/50.jpg`)} onMouseLeave={() => setImage('')}>
<span className="shadow">
<div>
<h2>Lorem</h2>
</div>
</span>
</a>
<a href="/en/" onMouseEnter={() => setImage(`https://i.picsum.photos/id/${Math.floor(Math.random() * 1084)}/50/50.jpg`)} onMouseLeave={() => setImage('')}>
<span className="shadow">
<div>
<h2>Lorem</h2>
</div>
</span>
</a>
</div>
</>
)
}
export default testCode
Updated: Using React Class
import React, { Component } from 'react'
class sampleCode extends Component {
constructor(props) {
super(props);
this.state = { image: '' };
}
setImage = (imagePath) => {
this.setState({ image : imagePath })
}
render() {
return (
<>
<div className="div-img" style={{ width: '50px', height: '50px' }}>
<img src={this.state.image}/>
</div>
<div>
<a href="/fr/"
onMouseEnter={() => this.setImage(`https://i.picsum.photos/id/${Math.floor(Math.random() * 1084)}/50/50.jpg`)}
onMouseLeave={() => this.setImage('')}>
<span className="shadow">
<div>
<h2>Lorem</h2>
</div>
</span>
</a>
<a href="/en/"
onMouseEnter={() => this.setImage(`https://i.picsum.photos/id/${Math.floor(Math.random() * 1084)}/50/50.jpg`)}
onMouseLeave={() => this.setImage('')}>
<span className="shadow">
<div>
<h2>Lorem</h2>
</div>
</span>
</a>
</div>
</>
)
}
}
export default sampleCode
Hope this helps :)

Angular Ui-Grid Columns not showing

The following webpage is a container with three different tabs: Uploaded Datasets, Bought Datasets and Integrated Datasets:
1st Tab
each tab content is a UI-Grid that I call through an angular directive as follows:
<div class="form-top">
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-uploaded" role="tab" aria-controls="nav-uploaded" aria-selected="true">
Uploaded Datasets
</a>
<a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-bought" role="tab" aria-controls="nav-bought" aria-selected="false" >
Bought Datasets
</a>
<a class="nav-item nav-link" id="nav-contact-tab" data-toggle="tab" href="#nav-integrated" role="tab" aria-controls="nav-integrated" aria-selected="false">
Integrated Datasets
</a>
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-uploaded" role="tabpanel">
<uploaded-grid></uploaded-grid>
<!-- <div id="grid1" ui-grid="uploadedGridOptions" ui-grid-selection ui-grid-exporter class="grid"></div> -->
</div>
<div class="tab-pane fade" id="nav-bought" role="tabpanel">
<bought-grid></bought-grid>
</div>
<div class="tab-pane fade" id="nav-integrated" role="tabpanel">
<integrated-grid></integrated-grid>
</div>
</div>
</div>
and each directive contains the following Html code:
<div id="grid2" ui-grid="integratedGridOptions" ui-grid-selection ui-grid-exporter class="grid"></div>
and linked with a specific controller:
var app = angular.module("integratedGridCtrl",[]);
app.controller('integratedGridCtrl', ['$http','$scope','$uibModal', function($http, $scope,$uibModal){
var data = [
{
id: "Cox",
title: "Carney",
creationDate: "22/22/2019",
description: "description"
},
{
id: "Lorraine",
title: "Wise",
creationDate: "22/22/2019",
description: "description"
},
{
id: "Nancy",
title: "Waters",
creationDate: "22/22/2019",
description: "description"
}
];
$scope.integratedGridOptions = {
showGridFooter: true,
showColumnFooter: true,
enableFiltering: true,
columnDefs: [
{ field: 'id', width: '*', minWidth: 60},
{ name: 'title', field: 'title', width: '*', minWidth: 60, displayName: 'title' },
{ field: 'creationDate', width: '*',displayName: 'creation Date', minWidth: 60, cellFilter: 'date' },
{ field: 'description', width: '*', minWidth: 60 },
],
onRegisterApi: function(gridApi) {
$scope.gridApi = gridApi;
},
rowTemplate: '<div ng-click=\"grid.appScope.detailPopup(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name\" class=\"ui-grid-cell\" ui-grid-cell style="cursor: pointer"></div>',
enableGridMenu: true,
enableSelectAll: true,
exporterCsvFilename: 'myFile.csv',
exporterPdfDefaultStyle: {fontSize: 9},
exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
exporterPdfFooter: function ( currentPage, pageCount ) {
return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
},
exporterPdfCustomFormatter: function ( docDefinition ) {
docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
return docDefinition;
},
exporterPdfOrientation: 'portrait',
exporterPdfPageSize: 'LETTER',
exporterPdfMaxGridWidth: 500,
exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
exporterExcelFilename: 'myFile.xlsx',
exporterExcelSheetName: 'Sheet1'
}
$scope.integratedGridOptions.data = data;
}]);
The first two tabs are well displayed, but the 3rd tab doesn't show the columns from the first click until I refresh again.
3rd Tab
Try ui-grid-auto-resize directive for the grid as follows:
<div id="grid2" ui-grid="integratedGridOptions" ui-grid-selection ui-grid-auto-resize
ui-grid-exporter class="grid"></div>