Fontawesome Icon renders more than once after Array sort and display with Svelte #each - font-awesome

So I have a Sapper project where I use Fontawesome as front end Icon pack. I have an array displayed with svelte #each and in the html there is an icon and if I resort the array the position of the elements changes how it should be but now the Icons are rendered more than once next to each other. I think I know why it could be budged but I don't have a clue how to fix it. I think it's that the svelte renderer renders the component again and the fontawesome script just gets the info to render it again.
<script>
import { projectsFilter } from "#lib/store";
export let item;
let colapsed = true;
projectsFilter.subscribe(filter => {
colapsed = colapsed;
});
function changeState() {
colapsed = !colapsed;
}
</script>
<style type="text/scss">
</style>
<div class="card">
<div class="card-image">
<figure class="image is-16by9">
<img src={item.data.background} alt="placeholder" />
</figure>
</div>
<header class="card-header">
<p class="card-header-title">{item.data.name}</p>
<button class="card-header-icon" on:click={changeState}>
{#if !colapsed}
<span class="icon">
<i class="fas fa-angle-down" aria-hidden="true" />
</span>
{:else}
<span class="icon">
<i class="fas fa-angle-up" aria-hidden="true" />
</span>
{/if}
</button>
</header>
{#if !colapsed}
<div class="card-content">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus nec
iaculis mauris.
</div>
</div>
{/if}
<footer class="card-footer">
Save
Edit
Delete
</footer>
</div>
This is the component that's been rendered. Within the #each loop.
The Arrows/angles are the problem
Thanks for the help in advance

You can use the following code and check
<i class={!colapsed ? 'fas fa-angle-down' : 'fas fa-angle-up'}
aria-hidden="true" />
and the whole code below
<script>
import { projectsFilter } from "#lib/store";
export let item;
let colapsed = true;
projectsFilter.subscribe(filter => {
colapsed = colapsed;
});
function changeState() {
colapsed = !colapsed;
}
</script>
<style type="text/scss">
</style>
<div class="card">
<div class="card-image" />
<header class="card-header">
<p class="card-header-title">asdads</p>
<button class="card-header-icon" on:click={changeState}>
<span class="icon">
<i
class={!colapsed ? 'fas fa-angle-down' : 'fas fa-angle-up'}
aria-hidden="true" />
</span>
</button>
</header>
{#if !colapsed}
<div class="card-content">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus nec
iaculis mauris.
</div>
</div>
{/if}
<footer class="card-footer">
Save
Edit
Delete
</footer>
</div>

You have to preload both icons and switch the visibility with aria-hidden=true and aria-hidden=false.
I usually create my own css-classes and add and remove them in a toggle function:
.hidden {
display = none;
}
.shown {
display = block;
}
You can e.g. toggle with two functions like this:
function toggleCollapsed(event) { // event.target might be a better way to catch the element...
document.getElementById('ELEMENT1_ID').classList.remove('hidden');
document.getElementById('ELEMENT1_ID').classList.add('shown');
document.getElementById('ELEMENT2_ID').classList.remove('shown');
document.getElementById('ELEMENT2_ID').classList.add('hidden');
}
function toggleFolded(event) {
document.getElementById('ELEMENT1_ID').classList.remove('shown');
document.getElementById('ELEMENT1_ID').classList.add('hidden');
document.getElementById('ELEMENT2_ID').classList.remove('hidden');
document.getElementById('ELEMENT2_ID').classList.add('shown');
}
Than you can e.g.:
<button class="card-header-icon" on:click={changeState === true ? toggleFolded : toggleCollapsed}>

Related

Showing a popup show what's behind

When I show a popup, the circle used for decoration show up, I don't know how solve that,
Here's the fiddle :
some code
https://jsfiddle.net/MagikMike/pctb9e0n/
Thanks
Give your circles IDs, in this case I added an ID circle0 and circle1 to both circles -
<div class="overlay" id="popup1"><div class="popup" id="popup"></div></div>
<div class="userMonitoringTarget">
<div class="circle1" id="circle0">
<div class="circle2">
<div class="circle3">
</div>
</div>
<div class="rectangle"></div>
</div>
<span class="dot"></span>
<div class="userMonitoring">
<div>
<span>
Date : 00/00/0000
</span>
<div>
<span>
LOREM IPSUM
</span>
</div>
</div>
<div class="userMonitoringAttachement">
<img src="/image/icon/icn-plus.svg" alt="+"
onclick="show_popup(' . $user->getNum() . ',' . $monitorings->id[$i] . ');return false;">
</div>
</div>
</div>
<div class="userMonitoringTarget">
<div id="circle1" class="circle1">
<div class="circle2">
<div class="circle3">
</div>
</div>
<div class="rectangle"></div>
</div>
<span class="dot"></span>
<div class="userMonitoring">
<div>
<span>
Date : 00/00/0000
</span>
<div>
<span>
LOREM IPSUM
</span>
</div>
</div>
<div class="userMonitoringAttachement">
<img src="/image/icon/icn-plus.svg" alt="+"
onclick="show_popup(' . $user->getNum() . ',' . $monitorings->id[$i] . ');return false;">
</div>
</div>
</div>
In your JS, your circles still showed because you didn't target them and set the visibility to hidden; now that we have IDs associated with the two circles you can properly get and set the visibility when the pop up is shown.
function hide_popup()
{
setTimeout(function()
{
document.getElementById('popup1').style.visibility = "hidden";
document.getElementById('popup1').style.opacity = 0;
document.getElementById('popup').innerHTML = "";
}, 100);
}
function show_popup( user, monitoring )
{
document.getElementById('circle0').style.visibility = "hidden";
document.getElementById('circle1').style.visibility = "hidden";
document.getElementById('popup1').style.visibility = "visible";
document.getElementById('popup1').style.opacity = 1;
}
You need to add a z-index for your popup wrapper like so.
#popup1 {
z-index: 999;
}

Can't access classes inside a react-modal

This is my first time using react and I am sure that code given is probably not using react's best practices but I am just playing around with it to understand it for now, my problem is that I am trying to access the divs and paragraphs inside the modal but document querySelector returns null. Any ideas? Thanks
moreInfo(movie) {
const movieModalImg = document.querySelector(".movieModalImg");
const movieModalTitle = document.querySelector(".movieModalTitle");
const movieModalRunTimeNum = document.querySelector(
".movieModalRunTimeNum"
);
}
render() {
return (
<div>
<div id="modal">
<Modal
isOpen={this.state.setIsOpen}
onRequestClose={this.closeModal.bind(this)}
contentLabel="Example Modal"
>
<a className="closeModalBtn" onClick={this.closeModal} href={"#"}>
×
</a>
<div className="modal-wrapper">
<div>
<img src={moviePoster} className="movieModalImg" alt=""></img>
</div>
<p className="movieModalTitle"></p>
<div className="movieModalRunTime">
<h4>Runtime:</h4>
<p className="movieModalRunTimeNum"></p>
<p>Minutes</p>
</div>
<div className="movieModalProductionCountry">
<h4>Production Countries:</h4>
<p className="movieModalProductionCountries"></p>
</div>
<div className="movieModalVoteCount">
<h4>Vote Count:</h4>
<p className="movieModalVoteCountNum"></p>
</div>
<div className="movieModalRevenew">
<h4>Revenew:</h4>
<p className="movieModalRevenewNum"></p>
<p>$</p>
</div>
<div className="movieModalBudget">
<h4>Budget:</h4>
<p className="movieModalBudgetNum"></p>
<p>$</p>
</div>
</div>
</Modal>
</div>
<a
href="#"
className="movieCoverMoreInfo"
onClick={this.moreInfo.bind(this)}
>
<img className="moreInfoIcon" src={info} alt=""></img>
More Info
</a>
</div>
);
}

Close Bootstrap Card Container

I have a card container in my code. I have added a 'close' button that I want to close the card when I click it. I am unsure how to make this work and I've been looking at a lot of articles online.
I have the following code:
<div class="card" style="border: 2px black solid">
<div class="card-header container-fluid" id="newsHeading">
<div class="row">
<div class="col">
<h3>News Items</h3>
</div>
<div class="col">
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
</div>
Is there an html/css method of doing this or will I have to add some JS/JQ logic to make it work?
Any help would be much appreciated! :)
Update:
I added the following code under my html code. It's a quick and simple fix.
<script>
$('.close').click(function(){
$('#newsHeading').parent().fadeOut();
})
</script>
You can use a jquery .click() event with a .hide() or .slideUp() on the id of the header and parent to access that card.
$('.close').click(function(){
$('#newsHeading').parent().slideUp();
})
There are no parent selectors in css, so using child-nodes to alter the display of parents usually requires something else (JavaScript) to work up through the DOM.
This isn't a standard feature of bootstrap, so you need to bind a JS click event to the icon.
$('.close-icon').on('click',function() {
$(this).closest('.card').fadeOut();
})
.close-icon {
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="card card-outline-danger text-center">
<span class="pull-right clickable close-icon" data-effect="fadeOut"><i class="fa fa-times"></i></span>
<div class="card-block">
<blockquote class="card-blockquote">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
<footer>Someone famous in <cite title="Source Title">Source Title</cite></footer>
</blockquote>
</div>
</div>
Possible dublicate of How to add close button to bootstrap card?
To use this close feature without any Js click event please use bootstrap modal with the data-dismiss property

How to make a <p><button class="button">Button</button></p> direct to a link on click

I've been writing some HTML code to develop a website. I want to have some buttons link to other parts of the page. The button is in a "Meet the Team" style. Here is the code:
<div class="column">
<div class="card">
<div class="container">
<img src="button1.png" alt="Button" style="width:100%">
<div class="centered"><h1> Lorem Ipsum </h1></div>
<p class="title">Lorem ipsum dolor sit amet, consectetur adipiscing
elit.</p>
<p><button class="button">Button</a></button></p>
</div>
</div>
I've tried to get it to link to a page but I can't find anything (I'm new to HTML). Maybe one of you can help? Thanks!
This is the best way to link other pages style a tag looks like button:
Click me
Alternatives:
<button onclick="location.href='http://www.example.com'" type="button">
www.example.com
</button>
Or
<form action="http://google.com">
<input type="submit" value="Google" />
</form>
Your button tag is not properly formatted, the </a> will break your html code.
All you have to do is just pass href attribute to button.
<p><button type="button" class="button" href="team-page.html">Button</button></p>
http://www.tizag.com/htmlT/ is a very good starting point.

React.js dynamically injecting html from database (sql) into component not applying css styles?

I'm currently injecting a html string from mysql via http and then displaying it in a component. It's kind of strange but my styling does not get applied to my dynamically injected html. However a few classes do from my other css library. But my bulma.css library styling does not seem to be applied.
I'm currently using, dangerouslySetInnerHTML={this.createMarkup()}
The html is being rendered in the browser successfully.
Here are my relevant files
My React Component file
import React from 'react';
import {connect} from 'react-redux';
import { fetchPost } from '../actions/index';
class Article extends React.Component {
componentWillMount(){
this.props.fetchPost();
}
createMarkup() {
return {__html: this.props.post};
}
renderPosts(){
if(!this.props.post){
return(
<img src="/app/img/loading.svg" alt=""/>
)
}
if(this.props.post){
return(
<div dangerouslySetInnerHTML={this.createMarkup()} />
)
}
}
render(){
return(
<div >{this.renderPosts()}</div>
)
}
}
function mapStateToProps(state){
return {
post: state.posts.post
}
}
export default connect(mapStateToProps, { fetchPost })(Article);
My Index HTML file (blade file using laravel )
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/app/css/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="/app/css/bulma-0.4.1/css/bulma.css">
<link rel="stylesheet" href="/app/css/prism.css">
<link rel="stylesheet" href="/app/css/app-style.css?{{str_random(40)}}">
<title>Development Gems!</title>
</head>
<body>
<div id="root">
</div>
<script src="/app/js/plugins/prism.js"></script>
<script src="/app/js/app.bundle.js?{{str_random(40)}}"></script>
</body>
</html>
My html string
$data = '<div className="container padded-top-di-20">
<div className="columns">
<div className="column">
<p className="title is-1 has-text-centered">How to install Laravel 5 with Xampp (Windows)</p>
</div>
</div>
<p className="title is-3">
Requirements
</p>
<div className="content">
<ul>
<li>Donec blandit a lorem id convallis.</li>
<li>Cras gravida arcu at diam gravida gravida.</li>
<li>Integer in volutpat libero.</li>
<li>Donec a diam tellus.</li>
<li>Aenean nec tortor orci.</li>
<li>Quisque aliquam cursus urna, non bibendum massa viverra eget.</li>
<li>Vivamus maximus ultricies pulvinar.</li>
</ul>
</div>
<p className="title is-3">
Install Xampp
</p>
<p>
First of all, we need Xampp, so we can download it from the official page:
</p>
Download Xampp
<p className="title is-3">
Composer
</p>
<p>
After you\'ve downloaded and installed Xampp, we need to install Composer.
</p>
<p>
Composer is a PHP package manager that is integrated with Laravel Framework. In Windows we can install it easy going to the official page and download the installer.
</p>
<div className="columns">
<div className="column">
<pre className="command-line language-bash" data-user="Thatguyjono94" data-host="localhost"><code className="language-bash">{`cd \/usr\/local\/etc`}</code></pre>
</div>
</div>
<div className="columns">
<div className="column">
<pre className="command-line language-bash" data-user="Thatguyjono94" data-host="localhost"><code className="language-bash">{`cd \/usr\/local\/etc`}</code></pre>
</div>
</div>
<div className="columns">
<div className="column is-half is-offset-one-quarter">
<figure className="image is-128x128 margin-auto-di">
<img src="/app/img/profiles/avatar_icon-1.png" />
</figure>
<p className="title is-2 is-spaced has-text-centered">#Thatguyjono94</p>
<p className="subtitle is-4 has-text-centered">I\'m a DOPE AF web developer that focuses on building disruptive, fast moving and kick ass web applications.</p>
<div className="has-text-centered">
<span className="icon is-medium">
<i className="fa fa-github" aria-hidden="true"></i>
</span>
<span className="icon is-medium">
<i className="fa fa-facebook-official" aria-hidden="true"></i>
</span>
<span className="icon is-medium">
<i className="fa fa-twitter-square" aria-hidden="true"></i>
</span>
</div>
</div>
</div>
</div>';
dangerouslySetInnerHTML expects an HTML string. The string you are providing is formatted as a JSX string because it contains className instead of class. To fix it, convert each instance of className to class.