How put 'fontawesome' inside a react-datepicker in input? Library: react-datepicker. Is it possible? I tried used :after on class react-datepicker__input_container
<DatePicker
selected={this.state.startDate}
onChange={this.handleChange}
showTimeSelect
timeFormat="HH:mm"
timeIntervals={15}
dateFormat="yyyy-MM-dd || HH:mm"
timeCaption="time"
/>
.react-datepicker__input_container:after {
color: red;
content: 'X';
display: inline-block;
padding: 0 5px;
width: 40px;
height: 100%;
position: absolute;
text-align: center;
top: 20%;
right: 0;
}
.react-datepicker__input_container input {
padding-right: 2.5rem;
text-align: center;
color: blue !important;
font-weight: 600 !important;
}
You can pass a custom input to DatePicker as a prop. create a custom input component with FA icon and pass it as a prop.
class CustomInput extends React.Component {
render() {
return (
<div className="wrapper">
<i onClick={this.props.onClick} aria-hidden="true" className="fa fa-calendar"></i>
<input onClick={this.props.onClick} className="dateInput" value={this.props.value} type="text" />
</div>
)
}
}
CSS
.wrapper { position: relative; }
i.fa-calendar { position: absolute; top: 1px; left: 5px; }
.dateInput {
padding-left: 20px;
}
Demo
Example
.wrapper { position: relative; }
i.fa-calendar { position: absolute; top: 1px; left: 5px; }
.dateInput {
padding-left: 20px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.0/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.21.1/babel.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<div id="root"></div>
<script type="text/babel">
class CustomInput extends React.Component {
render() {
return (
<div className="wrapper">
<i onClick={this.props.onClick} aria-hidden="true" className="fa fa-calendar"></i>
<input onClick={this.props.onClick} className="dateInput" value={this.props.value} type="text" />
</div>
)
}
}
ReactDOM.render(
<CustomInput value='19-12-16, 02:00' />,
document.getElementById('root')
);
</script>
Related
I tried to add an className in fontawesome and give a property(width,padding,fontsize, etc)in the sass but it didn't work what I expected.
Is there any syntax give a className or id in the fa react? It works when I give a div+className and using flexbox but you know this is pretty not a good way if we can use className or id. I will leave my code below!
!
or
didn't work...
This is my whole main.js file! I will leave my part of my code(my question part)
import React, { Component } from "react";
import "./Main.scss";
import "./Common.scss";
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
import {
faHeart,
faComment,
faPaperPlane,
faBookmark,
faEllipsisH,
} from "#fortawesome/free-solid-svg-icons";
// import { FaRegComment } from "#fortawesome/free-solid-svg-icons";
// how to impport this faRegComment?
class Main extends Component {
render() {
return (
<>
<div class="main-wrapper">
<div class="nav">
<p class="logo"> Westagram </p>
<input
class="search-box"
type="text"
placeholder=" Search"
/>
{/* ,style="font-family:Arial, FontAwesome */}
<div class="icons">
<img
id="compass"
src="https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/bearu/explore.png"
/>
<img
id="heart"
src="https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/bearu/heart.png"
/>
<img
id="my-page"
src=" https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/bearu/profile.png"
/>
</div>
</div>
<div class="main">
<div class="feeds">
<div class="article">
<div class="identi">
<img class="selfi-identi" src="/images/about.png" />
<span class="name"> Jiwan Jeon </span>
{/* <i id="test" class="fa fa-ellipsis-h" aria-hidden="true"></i> */}
<div class="faEllipsisH">
<FontAwesomeIcon icon={faEllipsisH}></FontAwesomeIcon>
</div>
</div>
<div class="pic">
<img id="feed-pic" src="/images/ucscPic.png" />
</div>
<div class="show-box">
<div class="reaction-icons">
<FontAwesomeIcon icon={faHeart}></FontAwesomeIcon>
<FontAwesomeIcon icon={faComment}></FontAwesomeIcon>
<FontAwesomeIcon icon={faPaperPlane}></FontAwesomeIcon>
<FontAwesomeIcon icon={faBookmark}></FontAwesomeIcon>
</div>
<div class="like-counts">
<span>like 4,000</span>
</div>
<div class="check-comments">
<span>
UC Santa Cruz will continue to offer most courses remotely
or online for spring and summer 2021, providing in-person
instruction for a small
</span>
<a id="space" href="">
expanding
</a>
<br />
Check the all comments
<ul class="feed-comments">
<li>test</li>
</ul>
</div>
</div>
<div class="comment">
<i class="fa fa-smile-o"></i>
<input
class="user-input"
type="text"
placeholder="Add Comment..."
/>
<button class="post">Post</button>
</div>
</div>
</div>
</div>
<div class="main-right">
<div class="top">
<img class="selfi" src="/images/about.png" />
<div class="main-right-name">
<span id="eng-name">JiwanJeon94</span>
<br />
<span id="kr-name">전지완</span>
</div>
Transform
</div>
<div class="middle">
<div class="middle-words">
<span id="recommendation">Suggestions For You</span>
<a href="" id="view-all">
view all
</a>
</div>
<div class="recommendation-people">
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
</div>
</div>
<div class="footer">
<div class="footer-top">
About
Help
press
API
Jobs
Privacy
Terms
Locations
TopAccounts
Hashtags
Language
<br />
<br />
</div>
<span>2021 INSTAGRAM FROM FACEBOOK</span>
</div>
</div>
</div>
</>
);
}
}
export default Main;
This is my fa icons part
<div class="show-box">
<div class="reaction-icons">
<FontAwesomeIcon icon={faHeart}></FontAwesomeIcon>
<FontAwesomeIcon icon={faComment}></FontAwesomeIcon>
<FontAwesomeIcon icon={faPaperPlane}></FontAwesomeIcon>
<FontAwesomeIcon icon={faBookmark}></FontAwesomeIcon>
</div>
I Will leave sass file just in case
#font-face {
font-family: instagramFont;
src: url("./westagram.ttf") format("opentype");
}
#mixin icon-size() {
width: 30px;
height: 30px;
}
#root {
height: 100vh;
.main-wrapper {
margin: 10px 10px 10px 10px;
height: 100%;
.nav {
position: fixed;
display: flex;
flex-direction: row;
justify-content: space-around;
width: 100%;
padding-top: 20px;
padding-bottom: 10px;
border-bottom: solid 1px #dbdbdb;
z-index: 9999;
.logo {
font-family: instagramFont;
padding-right: 100px;
font-size: 2rem;
}
.search-box {
margin-top: 5px;
width: 250px;
// main css파일이랑 똑같이 세팅 했는데 개발자툴이랑 왜 다른지 -해결-
height: 28px;
}
.icons {
margin-left: 100px;
#compass {
#include icon-size();
//30*30 으로 세팅했는데 개발자툴에서는 왜 53*53인지
}
#heart {
#include icon-size();
}
#my-page {
#include icon-size();
}
}
}
.main {
position: relative;
top: 70px;
left: 8px;
width: 100%;
height: 100%;
.feeds {
position: relative;
top: 40px;
right: 5px;
left: 61px;
width: 60%;
.article {
position: absolute;
display: flex;
flex-direction: column;
width: 614px;
height: 954px;
padding-bottom: 10px;
.identi {
position: relative;
display: flex;
flex-direction: row;
align-items: flex-start;
height: 50px;
.selfi-identi {
width: 30px;
height: 30px;
// padding: 15px 20px 20px 20px;
border-radius: 50%;
}
.name {
margin-top: 10px;
margin-left: 5px;
}
#test {
padding-top: 23px;
padding-left: 410px;
}
.faEllipsisH {
padding-top: 10px;
padding-left: 40px;
// padding-bottom: 20px;
}
}
.pic {
#feed-pic {
position: relative;
padding: 3px 3px 3px 3px;
width: 614px;
height: 614px;
padding: 5px 0px 2px 0px;
}
}
.show-box {
position: relative;
display: flex;
flex-direction: column;
justify-content: space-between;
height: 170px;
padding: 5px 0px 20px 0px;
.reation-icons {
#heartShowBox {
padding-left: 10px;
font-size: 30px;
width: 30px;
}
.fa-comment-o {
padding-left: 10px;
padding-right: 5px;
}
.fa-send-o {
padding-left: 10px;
font-size: 30px;
}
.fa-bookmark-o {
padding-left: 450px;
font-size: 30px;
}
}
.like-counts {
margin-top: 10px;
padding-top: 20px;
}
.check-comments {
.space {
padding-top: 400px;
}
}
}
.comment {
position: relative;
// margin-top: 75px;x
.fa-smile-o {
font-size: 30px;
}
.user-input {
width: 530px;
height: 20px;
}
.post {
height: 25px;
border: solid 1px #d3d3d3;
border-radius: 5px;
background-color: #b2dffc;
font-size: 15px;
cursor: pointer;
}
}
}
}
}
.main-right {
position: fixed;
width: 28%;
height: 98%;
top: 11.9%;
right: 4%;
.top {
position: relative;
display: flex;
flex-direction: row;
padding-bottom: 3px;
.selfi {
width: 50px;
height: 50px;
padding: 15px 20px 20px 20px;
border-radius: 50%;
}
.main-right-name {
position: relative;
padding-top: 25px;
#kr-name {
opacity: 0.3;
}
}
a {
margin-left: 40px;
margin-top: 20px;
}
}
.middle {
height: 30%;
padding-bottom: 100px;
.middle-words {
padding-bottom: 25px;
#recommendation {
margin-left: 23px;
}
#view-all {
margin-left: 70px;
}
}
.recommendation-people {
display: flex;
flex-direction: column;
#recommendation-section1 {
#recommendation-people-selfi {
width: 30px;
height: 30px;
margin-top: 13px;
padding: 5px 5px 5px 5px;
border-radius: 50%;
}
span {
position: relative;
right: 5px;
top: -18px;
}
a {
position: absolute;
right: 3px;
font-size: 14px;
}
}
}
}
.footer {
margin-left: 10px;
.footer-top {
.a {
margin: 0px 0px 0px 5px;
opacity: 0.3;
}
}
}
span {
margin-left: 5px;
opacity: 0.3;
}
}
}
}
For the first, replace all class with className.
className work fine with FontAwesomeIcon:
<FontAwesomeIcon icon={faHeart} className="awesome-custom"></FontAwesomeIcon>;
Chech this example: https://codesandbox.io/s/cold-frost-bv362?file=/src/App.js
I'm trying to create this sliding sign in /sign up portal but the original code was on Vanilla JS. The components seems unmounted on the Dom and the program is unable to find the Classlist by its id.I did few attempts on using Component did mount but it is throwing error, later I've found out that I am lacking understanding about Class vs function on react. componentDidMount() seems to be only for Classes. Now I cant seem to find a valid solution for this. Also I might forget, when should I really need to use Classes vs functions in rendering a component? How can I prevent calling an unmounted element in the DOM if I use function instead of class?
This is the raw Html,css,vanilla js code for the portal.
const signUpButton = document.getElementById('signUp');
const signInButton = document.getElementById('signIn');
const container = document.getElementById('container');
signUpButton.addEventListener('click', () => {
container.classList.add("right-panel-active");
});
signInButton.addEventListener('click', () => {
container.classList.remove("right-panel-active");
});
#import url('https://fonts.googleapis.com/css?family=Montserrat:400,800');
* {
box-sizing: border-box;
}
body {
background: #f6f5f7;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
font-family: 'Montserrat', sans-serif;
height: 100vh;
margin: -20px 0 50px;
}
h1 {
font-weight: bold;
margin: 0;
}
h2 {
text-align: center;
}
p {
font-size: 14px;
font-weight: 100;
line-height: 20px;
letter-spacing: 0.5px;
margin: 20px 0 30px;
}
span {
font-size: 12px;
}
a {
color: #333;
font-size: 14px;
text-decoration: none;
margin: 15px 0;
}
button {
border-radius: 20px;
border: 1px solid #FF4B2B;
background-color: #FF4B2B;
color: #FFFFFF;
font-size: 12px;
font-weight: bold;
padding: 12px 45px;
letter-spacing: 1px;
text-transform: uppercase;
transition: transform 80ms ease-in;
}
button:active {
transform: scale(0.95);
}
button:focus {
outline: none;
}
button.ghost {
background-color: transparent;
border-color: #FFFFFF;
}
form {
background-color: #FFFFFF;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 0 50px;
height: 100%;
text-align: center;
}
input {
background-color: #eee;
border: none;
padding: 12px 15px;
margin: 8px 0;
width: 100%;
}
.container {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 14px 28px rgba(0,0,0,0.25),
0 10px 10px rgba(0,0,0,0.22);
position: relative;
overflow: hidden;
width: 768px;
max-width: 100%;
min-height: 480px;
}
.form-container {
position: absolute;
top: 0;
height: 100%;
transition: all 0.6s ease-in-out;
}
.sign-in-container {
left: 0;
width: 50%;
z-index: 2;
}
.container.right-panel-active .sign-in-container {
transform: translateX(100%);
}
.sign-up-container {
left: 0;
width: 50%;
opacity: 0;
z-index: 1;
}
.container.right-panel-active .sign-up-container {
transform: translateX(100%);
opacity: 1;
z-index: 5;
animation: show 0.6s;
}
#keyframes show {
0%, 49.99% {
opacity: 0;
z-index: 1;
}
50%, 100% {
opacity: 1;
z-index: 5;
}
}
.overlay-container {
position: absolute;
top: 0;
left: 50%;
width: 50%;
height: 100%;
overflow: hidden;
transition: transform 0.6s ease-in-out;
z-index: 100;
}
.container.right-panel-active .overlay-container{
transform: translateX(-100%);
}
.overlay {
background: #FF416C;
background: -webkit-linear-gradient(to right, #FF4B2B, #FF416C);
background: linear-gradient(to right, #FF4B2B, #FF416C);
background-repeat: no-repeat;
background-size: cover;
background-position: 0 0;
color: #FFFFFF;
position: relative;
left: -100%;
height: 100%;
width: 200%;
transform: translateX(0);
transition: transform 0.6s ease-in-out;
}
.container.right-panel-active .overlay {
transform: translateX(50%);
}
.overlay-panel {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 0 40px;
text-align: center;
top: 0;
height: 100%;
width: 50%;
transform: translateX(0);
transition: transform 0.6s ease-in-out;
}
.overlay-left {
transform: translateX(-20%);
}
.container.right-panel-active .overlay-left {
transform: translateX(0);
}
.overlay-right {
right: 0;
transform: translateX(0);
}
.container.right-panel-active .overlay-right {
transform: translateX(20%);
}
.social-container {
margin: 20px 0;
}
.social-container a {
border: 1px solid #DDDDDD;
border-radius: 50%;
display: inline-flex;
justify-content: center;
align-items: center;
margin: 0 5px;
height: 40px;
width: 40px;
}
footer {
background-color: #222;
color: #fff;
font-size: 14px;
bottom: 0;
position: fixed;
left: 0;
right: 0;
text-align: center;
z-index: 999;
}
footer p {
margin: 10px 0;
}
footer i {
color: red;
}
footer a {
color: #3c97bf;
text-decoration: none;
}
<div class="container" id="container">
<div class="form-container sign-up-container">
<form action="#">
<h1>Create Account</h1>
<div class="social-container">
<i class="fab fa-facebook-f"></i>
<i class="fab fa-google-plus-g"></i>
<i class="fab fa-linkedin-in"></i>
</div>
<span>or use your email for registration</span>
<input type="text" placeholder="Name" />
<input type="email" placeholder="Email" />
<input type="password" placeholder="Password" />
<button>Sign Up</button>
</form>
</div>
<div class="form-container sign-in-container">
<form action="#">
<h1>Sign in</h1>
<div class="social-container">
<i class="fab fa-facebook-f"></i>
<i class="fab fa-google-plus-g"></i>
<i class="fab fa-linkedin-in"></i>
</div>
<span>or use your account</span>
<input type="email" placeholder="Email" />
<input type="password" placeholder="Password" />
Forgot your password?
<button>Sign In</button>
</form>
</div>
<div class="overlay-container">
<div class="overlay">
<div class="overlay-panel overlay-left">
<h1>Welcome Back!</h1>
<p>To keep connected with us please login with your personal info</p>
<button class="ghost" id="signIn">Sign In</button>
</div>
<div class="overlay-panel overlay-right">
<h1>Hello, Friend!</h1>
<p>Enter your personal details and start journey with us</p>
<button class="ghost" id="signUp">Sign Up</button>
</div>
</div>
</div>
</div>
And this is my current Login.js for my portal on a function.
import React, { useState } from 'react';
import axios from 'axios';
import { setUserSession } from './Utils/Common';
import './Login.css';
function Login(props) {
const [loading, setLoading] = useState(false);
const username = useFormInput('');
const password = useFormInput('');
const [error, setError] = useState(null);
const handleLogin = () => {
setError(null);
setLoading(true);
axios.post('http://localhost:4000/users/signin', { username: username.value, password: password.value }).then(response => {
console.log(username, password);
setLoading(false);
setUserSession(response.data.token, response.data.user);
props.history.push('/dashboard');
}).catch(error => {
setLoading(false);
if (error.response.status === 401) setError(error.response.data.message);
else setError("Something went wrong. Please try again later.");
});
}
const Signup = () => {
setError(null);
setLoading(true);
props.history.push('/Signup');
}
return (
<div className='login-wrapper' >
<div className='user-wrapper'>
<h1>Library Management System</h1>
<br />
<h1>Login</h1>
<br /><br />
<div className="user-details">
<h3>Username</h3>
<img src={userlogo} className="login-logo-user" />
<input type="text" {...username} autoComplete="new-password" />
</div>
<div className="user-details">
<h3>Password</h3>
<img src={passwordlogo} className="login-logo-password"/>
<input type="password" {...password} autoComplete="new-password" />
</div>
{error && <><small style={{ color: 'red' }}>{error}</small><br /></>}<br />
<input type="button" value={loading ? 'Loading...' : 'Login'} onClick={handleLogin} disabled={loading} id='buttons'/>
<input type="button" value={loading ? 'Loading...' : 'Signup'} onClick={Signup} id='buttons'/>
<div className="forgot-password">
<h5>Forgot Password? Click <span id="forgot-password">here</span>.</h5>
</div>
</div>
<div className='logo-wrapper'>
<div className="logo-main">
<img src={librarylogo} id="mainlogo"/>
<h2>Library Management System v1.0</h2>
</div>
</div>
</div>
);
}
const useFormInput = initialValue => {
const [value, setValue] = useState(initialValue);
const handleChange = e => {
setValue(e.target.value);
}
return {
value,
onChange: handleChange
}
}
export default Login;
Is this correct by the way?
I am trying to convert this as well?
from this function.
function login(props) {
const [loading, setLoading] = useState(false);
const username = useFormInput('');
const password = useFormInput('');
const [error, setError] = useState(null);
}
into a class:
class Login extends React.Component{
constructor(props) {
super(props);
this.state = {
loading, setLoading : false,
username : useFormInput(''),
password : useFormInput(''),
error, setError = null
}
}
}
I got it working now. Thanks for all the help.
class Login extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false,
setLoading: false,
email: props.email,
password: props.password,
error: null,
setError: null
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
componentDidMount(){
const signUpButton = document.getElementById('signUp');
const signInButton = document.getElementById('signIn');
const container = document.getElementById('container');
if (container){
console.log('loaded');
signUpButton.addEventListener('click', () => {
container.classList.add("right-panel-active");
});
signInButton.addEventListener('click', () => {
container.classList.remove("right-panel-active");
});
}
}
handleChange(event) {
this.setState({
[event.target.type]: event.target.value
});
}
handleSubmitSignIn(event) {
// alert('A name was submitted: ' + this.state.email + this.state.password);
event.preventDefault();
console.log(this.state.email);
console.log(this.state.password);
}
handleSubmitSignUp(event) {
// alert('A name was submitted: ' + this.state.email + this.state.password);
event.preventDefault();
console.log(this.state.email);
console.log(this.state.password);
}
render() {
return (
<div className="container" id="container">
<div className="form-container sign-up-container">
<form onSubmit={this.handleSubmitSignUp}>
<h1>Create Account</h1>
<div className="social-container">
<i className="fab fa-facebook-f"></i>
<i className="fab fa-google-plus-g"></i>
<i className="fab fa-linkedin-in"></i>
</div>
<span>or use your email for registration</span>
<input type="text" placeholder="Name" autoComplete="new-name" />
<input type="email" placeholder="Email" autoComplete="new-email" />
<input type="password" placeholder="Password" autoComplete="new-password" />
<input type="department" placeholder="Department" autoComplete="new-name" />
<input type="year" placeholder="Year" autoComplete="new-email" />
<input type="schoolId" placeholder="School Id No." autoComplete="new-password" />
<button>Sign Up</button>
</form>
</div>
<div className="form-container sign-in-container">
<form onSubmit={this.handleSubmitSignIn}>
<h1>Sign in</h1>
<div className="social-container">
<i className="fab fa-facebook-f"></i>
<i className="fab fa-google-plus-g"></i>
<i className="fab fa-linkedin-in"></i>
</div>
<span>or use your account</span>
<input type="email" placeholder="Email" value={this.state.email} autoComplete='new-email' onChange={this.handleChange}/>
<input type="password" placeholder="Password" value={this.state.password} autoComplete='new-password' onChange={this.handleChange}/>
Forgot your password?
<button type='submit' >Sign In</button>
</form>
</div>
<div className="overlay-container">
<div className="overlay">
<div className="overlay-panel overlay-left">
<h1>Welcome Back!</h1>
<p>To keep connected with us please login with your personal info</p>
<button className="ghost" id="signIn">Sign In</button>
</div>
<div className="overlay-panel overlay-right">
<h1>Hello</h1>
<p>Enter your personal details and start journey with us</p>
<button className="ghost" id="signUp">Sign Up</button>
</div>
</div>
</div>
</div>
);
}
}
export default Login;
I am trying to get my footer to stick to the bottom and not cover any body elements toward the bottom of the screen and I cannot seem to figure it out. Here is my footer.js
import React from "react";
import './Stylesheets/Footer.css';
import NavbarBrand from 'react-bootstrap/NavbarBrand';
import Navbar from 'react-bootstrap/Navbar';
import Container from 'react-bootstrap/Container';
class Footer extends React.Component {
state = { clicked: false }
handleClick = () => {
this.setState({ clicked: !this.state.clicked })
}
render() {
return (
<footer className="footerItems">
<div className="phantom"></div>
<div>
<Navbar>
<Container>
<NavbarBrand className="wrapper">
<i class="fab fa-2x fa-github"></i>
<i class="fab fa-2x fa-facebook-square"></i>
<i class="fab fa-2x fa-twitter-square"></i>
<i class="fab fa-2x fa-instagram"></i>
</NavbarBrand>
</Container>
</Navbar>
</div>
</footer>
)
}
}
export default Footer
I am trying to use a phantom <div> to force some additional spacing but that is not working. Here is the corresponding css file.
footer {
height: 80px;
margin-top: -200px;
bottom: 0;
z-index: 999;
}
.phantom {
display: 'block';
padding: '20px';
height: '60px';
width: '100%';
}
.footerItems {
position: fixed;
width: 100%;
background: linear-gradient(90deg, rgb(110, 94, 254) 0%, rgba(73, 63, 252, 1) 100%);
display: flex;
justify-content: center;
}
.wrapper {
align-items: center;
height: 100vh;
}
.wrapper i {
padding: 10px;
text-shadow: 0px 6px 8px rgba(0, 0, 0, 0.6);
transition: all ease-in-out 150ms;
}
.wrapper a:nth-child(1) {
color: #080202;
}
.wrapper a:nth-child(2) {
color: white;
}
.wrapper a:nth-child(3) {
color: #1DA1F2;
}
.wrapper a:nth-child(4){
color: #f24f1d;
}
.wrapper i:hover {
margin-top: -3px;
text-shadow: 0px 14px 10px rgba(0, 0, 0, 0.4);
}
Any thoughts or suggestions??
THANK YOU
Here's a solution using position: sticky. The main things to note here is that the main div needs to be at least the height of the page, that way the top property can force it to the bottom. The bottom property then forces it to stay at the bottom even if scrolled past.
This doesn't remove the footer from affecting the height of the page, so it'll all be scrollable without issue.
The other thing to note is that this solution (as written) is based on knowing the height of the footer in advance, so I put a custom css property --footer-height: 60px to set that.
I'm not really sure why the icons and things don't show on the footer as given, but that's a different question
const { NavbarBrand, Navbar, Container } = ReactBootstrap;
class Footer extends React.Component {
state = {
clicked: false,
};
handleClick = () => {
this.setState({
clicked: !this.state.clicked,
});
};
render() {
return (
<footer className="footerItems">
<div className="phantom"> </div>
<div>
<Navbar>
<Container>
<NavbarBrand className="wrapper">
<a href="http://www.github.com" target="_blank">
<i class="fab fa-2x fa-github"> </i>
</a>
<a href="http://www.facebook.com" target="_blank">
<i class="fab fa-2x fa-facebook-square"> </i>
</a>
<a href="http://www.twitter.com" target="_blank">
<i class="fab fa-2x fa-twitter-square"> </i>
</a>
<a href="http://www.instagram.com" target="_blank">
<i class="fab fa-2x fa-instagram"> </i>
</a>
</NavbarBrand>
</Container>
</Navbar>
</div>
</footer>
);
}
}
ReactDOM.render(
<div className="main">
<div className="content">Content!</div> <Footer />
</div>,
document.getElementById('root')
);
.main {
min-height: 100vh;
--footer-height: 60px;
}
.content {
height: 100vh;
background: linear-gradient(0deg, green 0%, white 100%);
}
footer {
height: var(--footer-height);
position: sticky;
top: calc(100vh - var(--footer-height));
bottom: 0;
}
.phantom {
display: block;
padding: 20px;
height: var(--footer-height);
width: 100%;
}
.footerItems {
/*position: fixed;*/
width: 100%;
background: linear-gradient(90deg, rgb(110, 94, 254) 0%, rgba(73, 63, 252, 1) 100%);
display: flex;
justify-content: center;
}
.wrapper {
align-items: center;
/*height: 100vh*/
;
}
.wrapper i {
padding: 10px;
text-shadow: 0px 6px 8px rgba(0, 0, 0, 0.6);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous" />
<script src="https://unpkg.com/react-bootstrap#next/dist/react-bootstrap.min.js" crossorigin></script>
<div id="root" />
Hoping to get some help on an issue I have been having in Next js. I am using Fontawesome-react package for icon imports which is working fine but when I attempt to load in a google font style sheet into the head of my main component, it changes the fonts but makes the font awesome icons disappear. I have tried a couple of different solutions such as loading the font locally and utilizing _document and _app components but none fix the issue I am having. Everything ends up changing the font but still gets rid of all the font awesome icons from every part of my app. I will copy in the Nav component I have and the Layout component that holds everything.
Thank you for any help!
import React from 'react'
import Nav from './nav/Nav'
import Head from 'next/head'
import Footer from './Footer'
type Props = {
title?: string
}
const Layout: React.FC<Props> = ({ children, title = 'Macros' }) => {
return (
<div>
<Head>
<title>{title}</title>
<link
href="https://fonts.googleapis.com/css?family=Darker+Grotesque&display=swap"
rel="stylesheet"
/>
</Head>
<Nav />
<div id="pageContent">{children}</div>
<Footer />
<style jsx global>{`
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
h1,
h2,
h3,
h4,
h5 {
font-weight: lighter;
font-family: 'Darker Grotesque', sans-serif;
}
#pageContent {
padding: 8rem 1rem;
}
`}</style>
</div>
)
}
export default Layout
import React, { useState } from 'react'
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome'
import { faBars, faSearch, faPlus } from '#fortawesome/free-solid-svg-icons'
import Link from 'next/link'
const NavBar: React.FC = () => {
const [navBarStatus, isOpen] = useState<Boolean>(false)
const toggleMenu = () => {
isOpen(navBarStatus ? false : true)
}
return (
<nav id="navContainer">
<div id="mobileNav">
<ul id="navBarTop">
<li>
<button type="button" className="navIcon" onClick={toggleMenu}>
<FontAwesomeIcon icon={faBars} />
</button>
</li>
<li>
<Link href="/">
<a>
<h3>Macro</h3>
</a>
</Link>
</li>
<li>
<button type="button" className="navIcon">
<FontAwesomeIcon icon={faSearch} />
</button>
</li>
</ul>
<ul id="navbarBottom">
<li>Top</li>
<li>New</li>
<li>Protein</li>
<li>Carbs</li>
<li>Fats</li>
</ul>
</div>
<div id="appDrawer">
<ul id="topIcons">
<li>
<button type="button" className="navIcon" onClick={toggleMenu}>
<FontAwesomeIcon icon={faBars} />
</button>
</li>
<li>
<button type="button" className="navIcon">
<FontAwesomeIcon icon={faPlus} />
</button>
</li>
</ul>
<nav>
<ul id="menuList">
<Link href="/">
<a>
<p>Home</p>
</a>
</Link>
<Link href="/">
<a>Favorites</a>
</Link>
<Link href="/">
<a>Notifications</a>
</Link>
<Link href="/">
<a>Login/Sign up</a>
</Link>
</ul>
</nav>
</div>
<style jsx>{`
#navContainer {
background-color: #504761;
color: white;
position: fixed;
width: 100%;
}
#navContainer a {
text-decoration: none;
color: white;
}
#mobileNav {
display: ${navBarStatus ? 'none' : ''};
}
#navBarTop {
color: white;
display: flex;
justify-content: space-between;
list-style: none;
padding: 1rem 1rem 0.5rem 1rem;
font-size: 1.5rem;
}
.navIcon {
color: white;
border: none;
background-color: #504761;
font-size: 1.5rem;
}
#navbarBottom {
display: flex;
list-style: none;
justify-content: space-evenly;
padding: 1rem 0;
}
#appDrawer {
display: ${navBarStatus ? 'block' : 'none'};
background-color: #504761;
height: 100vh;
}
#topIcons {
display: flex;
justify-content: space-between;
list-style: none;
padding: 1rem;
font-size: 1.5rem;
}
#menuList {
padding: 2rem 0 2rem 1rem;
display: flex;
flex-direction: column;
}
#menuList a {
font-size: 2rem;
margin: 1rem 0;
}
`}</style>
</nav>
)
}
export default NavBar
I am trying to conditionally open divs two and three, take a look at following snippet. showThird works correct however, showSecond has no effect? Basically on showSecond div-one shrinks to 50% width and div-two appears in rest 50%. Similar with div-third.
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
showSecond: false,
showThird: false
}
this.showDivTwo = this.showDivTwo.bind(this)
this.showDivThree = this.showDivThree.bind(this)
}
showDivTwo() {
this.setState(prevState => ({showThird: false, showSecond: !prevState.showSecond}))
console.log(this.state)
}
showDivThree() {
this.setState(prevState => ({ showSecond: false, showThird: !prevState.showThird}))
console.log(this.state)
}
render() {
return (
<div className={'wrapper' + (this.state.showSecond ? ' show' : '', this.state.showThird ? ' show' : '')}>
<div className="one">one
{/* Show second */}
<div>
<button onClick={this.showDivTwo}>{this.state.showSecond ? 'hideSecond' : 'showSecond'}</button>
</div>
{/* Show third */}
<div>
<button onClick={this.showDivThree}>{this.state.showThird ? 'hideThird' : 'showThird'}</button>
</div>
</div>
<div className="three">three
<div>
<button onClick={this.showDivThree}>{this.state.showThird ? 'hideThird' : 'showThird'}</button>
</div>
</div>
<div className="two">two
<div>
<button onClick={this.showDivTwo}>{this.state.showSecond ? 'hideSecond' : 'showSecond'}</button>
</div>
</div>
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
.wrapper {
overflow: hidden;
white-space: nowrap;
}
.one, .two, .three {
background: #333;
border: 2px solid #787567;
box-sizing: border-box;
color: #fff;
display: inline-block;
font-family: arial;
overflow: hidden;
padding: 20px;
text-align: center;
transition: border 0.2s, padding 0.2s, width 0.2s;
min-height: 50vh;
}
.one {
width: 100%;
}
.two {
border-width: 2px 0;
padding: 20px 0;
width: 0;
}
.three {
border-width: 2px 0;
padding: 20px 0;
width: 0;
}
.show .one, .show .two, .show .three {
border-width: 2px;
padding: 20px;
width: 50%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"></div>
What am I doing wrong here?
Changes:
1- use this condition:
className={'wrapper' + (this.state.showSecond || this.state.showThird ? ' show' : '')}
2- Use one more class hide, and put the check on className, apply that class if you want to hide the div otherwise apply class two or three.
Check the working code:
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
showSecond: false,
showThird: false
}
this.showDivTwo = this.showDivTwo.bind(this)
this.showDivThree = this.showDivThree.bind(this)
}
showDivTwo() {
this.setState(prevState => ({showThird: false, showSecond: !prevState.showSecond}))
console.log(this.state)
}
showDivThree() {
this.setState(prevState => ({ showSecond: false, showThird: !prevState.showThird}))
console.log(this.state)
}
render() {
return (
<div className={'wrapper' + (this.state.showSecond || this.state.showThird ? ' show' : '')}>
<div className="one">
one
<div>
<button onClick={this.showDivTwo}>{this.state.showSecond ? 'hideSecond' : 'showSecond'}</button>
</div>
<div>
<button onClick={this.showDivThree}>{this.state.showThird ? 'hideThird' : 'showThird'}</button>
</div>
</div>
<div className={this.state.showThird?"three":'hide'}>
three
<div>
<button onClick={this.showDivThree}>{this.state.showThird ? 'hideThird' : 'showThird'}</button>
</div>
</div>
<div className={this.state.showSecond ? "two" : 'hide'}>two
<div>
<button onClick={this.showDivTwo}>{this.state.showSecond ? 'hideSecond' : 'showSecond'}</button>
</div>
</div>
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
.wrapper {
overflow: hidden;
white-space: nowrap;
}
.hide, .one, .two, .three {
background: #333;
border: 2px solid #787567;
box-sizing: border-box;
color: #fff;
display: inline-block;
font-family: arial;
overflow: hidden;
padding: 20px;
text-align: center;
transition: border 0.2s, padding 0.2s, width 0.2s;
min-height: 50vh;
}
.one {
width: 100%;
}
.hide {
border-width: 2px 0;
padding: 20px 0;
width: 0;
}
.show .one, .show .two, .show .three {
border-width: 2px;
padding: 20px;
width: 50%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"></div>