How to add a bootstrap carousel in a React Project/ - reactjs

I have used bootstrap for my styling in my react project.But when I tried add carousel there was an error here is my code
function Home({user}){
return (<>
<h1 class="greeting">Hey {user.name}! Welcome to JetSet</h1>
<div id="carouselExampleFade" class="carousel slide carousel-fade frame" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ82m6eL2lonNbE-6-MGRl2RN-VUAB8Epse45lpCCdH-k68O8TbEiG1E1V3biNXlHplT5M&usqp=CAU" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="" class="d-block w-100" alt="..."/>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="..."/>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleFade" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleFade" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</>)
}
export default Home;
I inserted the bootstrap in my react component However im getting this error (property) JSX.IntrinsicElements.img: React.DetailedHTMLProps<React.ImgHTMLAttributes, HTMLImageElement>.....this is becuz JSX element 'img' has no corresponding closing tag and when i add the closing tag the carousel dosent work.

if you're using Bootstrap 4, then it requires the Query, Popper.js, and bootstrap 4 JavaScript plugins.
Jquery is another js library, using a library(jQuery) inside a library(react) is not an ideal solution. better you should use react-bootstrap for react project click here

You could use a CDN for that if you don't want to add another module. Just add it in the '/public' where your index is.
https://www.bootstrapcdn.com/
And you can use it by looking into the documentation.

Related

Can Bootstrap Carousel fit the Screen on mobile or can it be mobile friendly?

I am using Bootstrap 5.2 Carousel on ReactJS and new to react, I am not sure why is this happening or is this normal, I want the image to fit the screen on mobile is there any other way to fill the gap in the image below?. My Slider.css is empty btw. Thanks
Code:
import React from 'react';
import help from '../images/help3.jpeg';
import "../styles/slider.css"
function Slider() {
return (
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="false">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src={help} class="d-block w-100" alt="..."/>
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<img src={help} class="d-block w-100" alt="..."/>
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src={help} class="d-block w-100" alt="..."/>
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
);
}
export default Slider;
You can use utilities to set the width and height relative to the viewport. In your case use min-vh-100 .
just change :
<img src={help} class="d-block w-100 " alt="..." />
to :
<img src={help} class="d-block min-vh-100 " alt="..." />

navbar example Bulma is not working on mobile Blazor

I copied this example navbar from the Bulma website in a Blazor website. On the webpage it is working fine but on mobile the navbar-burger does not respond. Am I missing a vital step in the process? Do I need to do something with .css for example?
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="https://bulma.io">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28">
</a>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item">
Home
</a>
<a class="navbar-item">
Documentation
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
More
</a>
<div class="navbar-dropdown">
<a class="navbar-item">
About
</a>
<a class="navbar-item">
Jobs
</a>
<a class="navbar-item">
Contact
</a>
<hr class="navbar-divider">
<a class="navbar-item">
Report an issue
</a>
</div>
</div>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<a class="button is-primary">
<strong>Sign up</strong>
</a>
<a class="button is-light">
Log in
</a>
</div>
</div>
</div>
</div>
</nav>
This is because Bulma doesn't come with any JavaScript, so you need to toggle the class is-active on both the navbar-burger and the targeted navbar-menu.
There is implementation examples in Bulma navbar documentation, personally I'm using the jQuery implementation which works perfectly :
$(document).ready(function() {
// Check for click events on the navbar burger icon
$(".navbar-burger").click(function() {
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
$(".navbar-burger").toggleClass("is-active");
$(".navbar-menu").toggleClass("is-active");
});
});
but there's also a Vanilla Javascript implementation in the docs if you want.
Have you included all scripts and links into index.html? Have you tried hard refresh(Ctrl+F5 or Ctrl+Shirt+R)? Is your Program.cs same as theirs?
If nothing of above worked, can you provide whole codebase? Ideally git or zip.

How to display images in modal bootstrap using AngularJS and ng-repeat derective?

i have simple AngularJS application, i'm trying display images in modal use bootstrap, all photos at page i'm displaying use ng-repeat directive:
<div class="col-md-3" ng-repeat="photo_item in allPhotosOfSingleAlbum">
<img id="myImg" ng-src="../Files/Photos/{{photo_item.link}}" width="250px" height="160px" class="img-rounded" />
</div>
and i have the code of modal:
<div id="imageModal" class="modal">
<span class="close" onclick="document.getElementById('imageModal').style.display='none'">×</span>
<img class="modal-content" id="img01" />
</div>
Tell me please, how i can use it both ng-repeat and modal ?
Thanks for your answers !
Just move your first code where you have ng-repeat in modal and you should be able to show your images there.
<div id="imageModal" class="modal">
<span class="close" onclick="document.getElementById('imageModal').style.display='none'">×</span>
<div class="col-md-3" ng-repeat="photo_item in allPhotosOfSingleAlbum">
<img id="myImg" ng-src="../Files/Photos/{{photo_item.link}}" width="250px" height="160px" class="img-rounded" />
</div>
</div>

How to show default image if profile image is not set in angularjs

I need to set a default image from my local file if profile pic is not set by user and how to set hover to it if the user moves the mouse close to the profile pic field to set the image.
My HTML :
<div class="col-lg-2 vheight1">
<h4>Profile Picture</h4>
<div class="fileinput fileinput-new" onclick='$("#my_profile_pic").click();'>
<div class="fileinput-preview thumbnail" data-provides="fileinput" data-trigger="fileinput" id="profile_pic">
<img ng-if="source" class="thumb" ng-src="{{source}}"/>
</div>
<!-- <div class="hidden-sm hidden-md hidden-lg hidden-xs">
<span>
<span class="fileinput-new" ng-show="!hasFile()">Select image</span>
<span class="fileinput-new" ng-show="hasFile()">Change</span>
</span>
<a href="#" class="btn btn-danger fileinput-new glyphicon glyphicon-trash" data-dismiss="fileinput" ng-show="hasFile()" ng-click="removefile( json, file )" ></a>
</div> -->
</div>
</div>
<input type="file" class="hidden hidden-sm hidden-md hidden-lg hidden-xs" id='my_profile_pic' file-model="photo">
Can anyone please help me.
Replace:
<img ng-if="source" class="thumb" ng-src="{{source}}"/>
with:
<img class="thumb" ng-src="{{source ? source : 'pathtodefault.png'}}"/>
To complete Piyush's answer, you can also do:
<img class="thumb" ng-show="source" ng-src="{{source}}"/>
<img class="thumb" ng-show="!source" src="defaultSrc"/>

How to find dynamically generated data using AngularJS directive

I need to upload an image in my AngularJS, NodeJS application.
I have the following element on my page for selecting an image in a form using the Bootstrap File Input plugin:
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail">
<img src="http://www.placehold.it/512x512/EFEFEF/AAAAAA&text=NO+IMAGE" alt="" class="img-responsive" />
</div>
<div class="fileinput-preview fileinput-exists thumbnail">
</div>
<div>
<span class="btn default btn-file">
<span class="fileinput-new">Select image </span>
<span class="fileinput-exists">Change </span>
<input type="file" name="..." >
</span>
Remove
</div>
</div>
The data inside the following div gets changes once an image has been selected:
<div class="fileinput-preview fileinput-exists thumbnail">
</div>
It becomes to something like following:
<div class="fileinput-preview fileinput-exists thumbnail">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIAAAB7GkOtAAAAA3=...">
</div>
I need the data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIAAAB7GkOtAAAAA3=... data of the selected image for it to upload to a directory on my server using NodeJS.
Could somebody help me with an AngularJS directive to get that data?

Resources