How to make close effect after clicking on close in Styled-components? - css

I'm trying to make an in and out animation for my comment -
import {
Popup,
Overlay,
NavBarPopupHeader,
NavBarPopupContainer,
NavBarPopupImg,
NavBarPopupClose,
NavBarPopupContent,
NavBarPopupTitle,
NavBarPopupInfo,
NavBarPopupContentImg,
NavBarPopupFooter,
NavBarPopupSignOut,
} from "./styled.js";
function NavBarPopup(props) {
const { isPopupOpen } = props;
return (
<Overlay>
<Popup active={false}>
<NavBarPopupHeader>
<NavBarPopupClose
src="./popup_close.svg"
alt="close"
onClick={() => isPopupOpen(false)}
active={true}
/>
<NavBarPopupContainer>
<NavBarPopupImg />
</NavBarPopupContainer>
</NavBarPopupHeader>
<NavBarPopupContent>
<NavBarPopupTitle>You are logged as</NavBarPopupTitle>
<NavBarPopupInfo>'UserName'</NavBarPopupInfo>
<NavBarPopupInfo>'Email'</NavBarPopupInfo>
<NavBarPopupContentImg src="./popup_img.png" />
</NavBarPopupContent>
<NavBarPopupFooter>
<NavBarPopupSignOut>Sign Out...</NavBarPopupSignOut>
</NavBarPopupFooter>
</Popup>
</Overlay>
);
}
export default NavBarPopup;
I am using styled-components :
import styled, { keyframes, css } from "styled-components";
import { fadeIn, bounceInRight, bounceInLeft } from 'react-animations';
const fader = keyframes`${fadeIn}`;
const bounceIn = keyframes`${bounceInRight}`;
const bounceOut = keyframes`${bounceInLeft}`;
const Popup = styled.div`
position: fixed;
top: 0;
right: 0;
height: 100vh;
width: 400px;
background-color: #ffffff;
transition: ${(active) =>
active
? css`
${bounceIn} 0.5s linear
`
: css`${bounceOut} 0.5s`};
`;
const Overlay = styled.div`
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background-color: rgba(0, 0, 0, 0.8);
animation: 0.2s ${fader};
`;
const NavBarPopupHeader = styled.div`
width: 100%;
height: 15%;
background-color: #000000;
`;
const NavBarPopupContainer = styled.p`
text-align: center;
margin: 0;
padding: 30px 0 0 0;
`;
const NavBarPopupImg = styled.img`
width: 80px;
height: 80px;
border-radius: 50px;
border: none;
background-color: white;
color: black;
font-size: 25px;
`;
const NavBarPopupClose = styled.img`
position: absolute;
top: 5px;
left: 5px;
cursor: pointer;
`;
const NavBarPopupContent = styled.div`
height: 75%;
`;
const NavBarPopupTitle = styled.h3`
margin:0;
padding: 10px 0 10px 0;
text-align: center;
font-size: 30px;
`
const NavBarPopupInfo = styled.h4`
width: 80%;
margin: 10px auto;
padding:5px;
text-align: center;
font-size: 25px;
background-color: black;
color:white;
border-radius: 15px;
`
const NavBarPopupContentImg = styled.img`
width:100%;
margin-top:90px;
`
const NavBarPopupFooter = styled.div`
width: 100%;
height: 10%;
background-color: #000000;
`;
const NavBarPopupSignOut = styled.p`
width:200px;
text-align: center;
margin: 0 auto;
padding: 15px 0 0 0;
font-weight: 700;
font-size: 32px;
color: white;
text-decoration: underline;
cursor: pointer;
`;
export {
Popup,
Overlay,
NavBarPopupHeader,
NavBarPopupContainer,
NavBarPopupImg,
NavBarPopupClose,
NavBarPopupContent,
NavBarPopupTitle,
NavBarPopupInfo,
NavBarPopupContentImg,
NavBarPopupFooter,
NavBarPopupSignOut
};
I want my popup to be animated with $bounceIn when it appears, and disappear with $bounceOut when it closes. I tried to do it by passing an attribute to styled-components but now it only works when my Popup appears. Perhaps I chose the wrong approach, in which case please guide me in the right direction.

Related

How to positioning tooltip always above the children

I am making tooltip with antd library. I wanted to change the basic styles, so I needed to override styles. Here is the code:
import * as Styled from './Tooltip.styles';
type Props = {
title: string;
children: React.ReactNode;
};
export const CustomTooltip = ({ title, children }: Props) => (
<Styled.Tooltip
visible
title={title}
getPopupContainer={(triggerNode) => triggerNode}>
{children}
</Styled.Tooltip>
);
import styled from 'styled-components';
import { Tooltip as TooltipAnt } from 'antd';
export const Tooltip = styled(TooltipAnt)`
.ant-tooltip-content {
position: relative;
overflow-x: hidden;
overflow-y: visible;
padding-bottom: 20px;
display: inline-block;
left: -35px;
top: 25px;
}
.ant-tooltip-arrow {
display: none;
}
.ant-tooltip-inner {
padding: 10px 15px;
background: white;
display: inline-block;
border-radius: 10px;
border: 3px solid #D04A02;
border-bottom-right-radius: 0;
z-index: 2;
max-width: 200px;
color: #000;
box-shadow: none;
}
.ant-tooltip-content:before {
content: '';
position: absolute;
width: 25px;
height: 25px;
background: white;
bottom: 14px;
right: -8px;
transform: rotate(25deg);
border-bottom: 3px solid #D04A02;
}
.ant-tooltip-content:after {
content: '';
width: 3px;
background: #D04A02;
height: 50%;
position: absolute;
right: -0.5px;
bottom: 12px;
}
`;
And component where I would like to call this Tooltip:
import { CustomTooltip } from 'components/Tooltip/Tooltip';
export const SomeComponent = () => {
return (
<div>
<CustomTooltip title="Home">
<p>Home</p>
</CustomTooltip>
</div>
);
};
The problem is, the tooltip is not above the children. How can I fix this?
Codesanbox: https://codesandbox.io/s/stupefied-cohen-sgxr3s?file=/src/App.tsx

Search bar won't stay at top with CSS position: sticky property

I am trying to make a search bar stay at the top of a div with position: sticky but the property doesnt seem to work. Googling it, I see that overflow: hidden and overflow: hidden on a parent element can make it unresponsive if there is no height specified but I have a height specified so I don't think that's it. Here is the relevant CSS:
.container {
background-color: white;
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
border-radius: 1rem;
height: 85vh;
width: 60vw;
overflow-y: scroll;
overflow-x: hidden;
margin: auto;
}
.search-bar {
position: sticky;
top: 0;
margin: 1rem 1rem;
padding: 0.5rem;
font-size: 20px;
width: 100%;
display: block;
outline: 0;
border-width: 0 0 2px;
}
Note that .search-bar is a child element of .container. If needed, here is the JSX file (it's a react app):
import React, { useState, useEffect } from 'react';
import { average } from './utils/util.js';
import Card from './components/Card/Card';
import './App.css';
function App() {
const [loading, setLoading] = useState(true);
const [query, setQuery] = useState({ name: '', tag: '' });
const [users, setUsers] = useState([]);
const [filteredUsers, setFilteredUsers] = useState([]);
return (
<div className='container'>
<input
className='search-bar'
placeholder='Search by name'
onChange={(e) => {
setQuery({ ...query, name: e.target.value });
}}
/>
<input
className='search-bar'
placeholder='Search by tag'
onChange={(e) => {
setQuery({ ...query, tag: e.target.value });
}}
/>
{filteredUsers.map((user) => (
<Card
id={user.id}
pic={user.pic}
name={`${user.firstName} ${user.lastName}`}
email={user.email}
company={user.company}
skill={user.skill}
average={average(user.grades)}
grades={user.grades}
tags={user.tags}
onTagChange={tagChange}
/>
))}
</div>
);
}
export default App;
I tried to reproduce your issue here,
https://codesandbox.io/s/winter-breeze-5spod8?file=/src/styles.css
but it seems to work fine with your code. The only thing I changed was to add two .search-bar classes and height into it, because you have two input elements which you want sticky and they start to overlap on each other when we start scrolling.
.container {
background-color: white;
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
border-radius: 1rem;
height: 85vh;
width: 60vw;
overflow-y: scroll;
overflow-x: hidden;
margin: auto;
}
.search-bar1 {
position: sticky;
top: 0;
margin: 1rem 1rem;
padding: 0.5rem;
font-size: 20px;
width: 100%;
height: 3%;
display: block;
outline: 0;
border-width: 0 0 2px;
}
.search-bar2 {
position: sticky;
top: 5.8%;
margin: 1rem 1rem;
padding: 0.5rem;
font-size: 20px;
width: 100%;
height: 3%;
display: block;
outline: 0;
border-width: 0 0 2px;
}

React js styled component input animation not working

I am trying to create an form with input fields.I am trying to set up the floating labels for the inputs. The floating label works for the second field and not the first field. Please help me understand what am I missing on..
Here is code sandbox link :Please refer to productDetails component..
https://codesandbox.io/s/pensive-water-pojf8?file=/src/StyledComponents/FormInputStyles/index.js:199-1554
Form components
<InputWrapper>
<TextBox />
<LabelText>Product Name</LabelText>
</InputWrapper>
<InputWrapper>
<TextParagraph />
<LabelText1 for="description">Product Name</LabelText1>
</InputWrapper>
styled components: Where I am trying to make the input label floating
export const TextBox = styled.input`
display: flex;
width: 100%;
height: 2em;
border-radius: 5px;
border: none;
background: ${styles.backgroundGradient};
margin-top: ${props => props.marginTop || "1.5em"};
&:focus {
outline: none;
border: 2px solid #6e5dcc;
}
`;
export const LabelText = styled.label`
position: absolute;
top: 1.5em;
left: 0;
font-size: 18px;
line-height: 16px;
pointer-events: none;
transition: 0.5s;
color: ${styles.formContentColor};
${TextBox}:focus ~ &,
${TextBox}:not([value=""]) ~ & {
top: 0;
left: 0;
color: ${styles.formContentColor};
font-size: 16px;
}
`;
export const TextParagraph = styled.input`
display: flex;
width: 100%;
height: 7em;
border-radius: 5px;
border: none;
text-align: left;
appearance: none;
background: ${styles.backgroundGradient};
margin-top: ${props => props.marginTop || "1.5em"};
&:focus {
outline: none;
border: 2px solid #6e5dcc;
}
`;
export const LabelText1 = styled.label`
position: absolute;
top: 1.5em;
left: 0;
font-size: 18px;
line-height: 16px;
pointer-events: none;
transition: 0.5s;
color: ${styles.formContentColor};
${TextParagraph}:focus ~ &,
${TextParagraph}:not([value=""]) ~ & {
top: 0;
left: 0;
color: ${styles.formContentColor};
font-size: 16px;
}
`;

DropDown Positioning absolute element outside of the relative parent container

I'm using ReactJs and Emotion, but I know the problem is related to my CSS
I have a Header structure
main (
sidebar
content
)
That's why I'm having trouble positioning an <ul> tag correctly with position absolute and this error happens:
problem gif:
I know it is related to the position: relative of my components or my page structure I already tried everything and I couldn't solve it
basically i need my <ul> dropdown to be next to my sidebar like this:
My JSX:
const Tags = () => {
const [menuItems, setMenuItems] = useState(SideBarTags);
const showHideDropItem = tag => {
setMenuItems(items =>
items.map(item => ({
...item,
Active:
item.Name === tag.Name ? (tag.Active === true ? false : true) : false
}))
);
};
return (
<SideBar.MenuList>
{menuItems.map((item, index) => (
<SideBar.ListItem>
<SideBar.ListWrap>
<a>
<item.Icon size={24} />
<span className="li-name">{item.Name}</span>
</a>
</SideBar.ListWrap>
{item.DropdownItems && (
<SideBar.ClosedStyled>
{item.DropdownItems.map(item => (
<li className="li-closed" key={item.Name}>
<FaGhost size={18} />
<a onClick={() => console.log(item.Name)}>{item.Name}</a>
</li>
))}
</SideBar.ClosedStyled>
)}
</SideBar.ListItem>
))}
</SideBar.MenuList>
);
};
export default function App() {
return (
<Global.Container>
<Header.NavBar>
<Header.LogoSide>
<img src={Logo} alt="elo Ghost" />
</Header.LogoSide>
<div style={{ width: "100%", background: "#eee" }} />
</Header.NavBar>
<Global.Main>
<SideBar.SideBodyWrap>
<SideBar.DashMenu>
<Tags />
</SideBar.DashMenu>
</SideBar.SideBodyWrap>
<Content>a</Content>
</Global.Main>
</Global.Container>
);
}
my CSS in Js:
import styled from "#emotion/styled/macro";
import { shade } from "polished";
import { css } from "#emotion/core";
// Global Containers
const Container = styled.div`
height: 100%;
`;
const Main = styled.div`
display: flex;
height: calc(100% - 55px);
position: relative;
z-index: 0;
`;
// Global Containers
export const Global = {
Container,
Main
};
// header Nav
export const NavBar = styled.div`
height: 55px;
background: #3c8dbc;
display: flex;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.05), 0 1px 0 rgba(0, 0, 0, 0.05);
position: relative;
z-index: 1;
`;
export const LogoSide = styled.div`
display: flex;
background: red;
justify-content: center;
background: #3c8dbc;
padding: 10px;
width: 100%;
max-width: 250px;
height: 55px;
img {
height: 35px;
transition: all 0.2s ease;
}
`;
// header Nav
export const Header = {
NavBar,
LogoSide
};
// SideBar
const SideBodyWrap = styled.nav`
overflow-y: auto;
height: 100%;
max-width: 250px;
width: 100%;
color: #009688;
background: #3c8dbc;
transition: all 0.2s ease;
::-webkit-scrollbar {
width: 5px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}
::-webkit-scrollbar-thumb {
background: rgba(255, 0, 0, 0.8);
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}
::-webkit-scrollbar-thumb:window-inactive {
background: rgba(255, 0, 0, 0.4);
}
`;
const MenuList = styled.ul`
font-family: "Ubuntu";
font-size: 14px;
font-weight: 300;
text-decoration: none;
color: #fff;
padding-top: 10px;
`;
export const ListItem = styled.li`
display: flex;
flex-direction: column;
justify-content: center;
cursor: pointer;
position: relative;
`;
export const ListWrap = styled.div`
padding: 12px 20px 12px 20px;
display: flex;
transition: all 0.5s cubic-bezier(0, 1, 0, 1);
justify-content: center;
align-items: center;
a {
display: flex;
align-items: center;
svg {
margin-right: 15px;
transition: all 0.5s cubic-bezier(0, 1, 0, 1);
}
}
& .icon-li {
margin-right: 10px;
}
& .down-up_svg,
.li-name {
display: none;
}
`;
export const ClosedStyled = styled.ul`
${ListItem}:hover & {
max-width: 400px !important;
max-height: 400px !important;
}
max-height: 0px !important;
overflow: hidden;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
list-style-type: none;
margin: 0;
padding: 0;
top: 0;
left: 70%;
font-weight: 400;
position: absolute;
padding: 0px;
z-index: 2;
background: ${shade(0.4, "#3c8dbc")};
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
& .li-closed {
white-space: nowrap;
padding: 10px 20px;
:hover > svg {
color: orange;
}
svg {
margin-right: 10px;
}
}
a {
font-family: "Ubuntu";
font-size: 14px;
font-weight: 300;
text-decoration: none;
color: #8aa4af;
}
`;
const DashMenu = styled.div`
display: flex;
flex-direction: column;
`;
export const SideBar = {
SideBodyWrap,
DashMenu,
ClosedStyled,
ListItem,
ListWrap,
MenuList
};
// SideBar
export const Content = styled.div`
height: 100%;
width: 100%;
background: #eee;
`;
example:
https://codesandbox.io/s/cranky-hamilton-oy47v?file=/src/App.js
and :
https://oy47v.csb.app/
If I'm understanding what you're wanting to achieve correctly, I was able to do it by removing overflow-y:auto from .sidebodywrap and changing left:70% to left:100% in .closedstyled

Div passing full width of parent div

Hello I have a daughter div that is passing the full width of the parent div for some reason I still can't find the solution:
like this:
for some reason instead of skipping paragraph it is always horizontal I've tried everything and found no solution.
code:
<Styled.ChatBox>
<Styled.ChatLog>
<Styled.MessageWrapper user={true}>
<Styled.ChatMessage user={true}>{props.children}</Styled.ChatMessage>
</Styled.MessageWrapper>
</Styled.ChatLog>
</Styled.ChatBox>
css:
const messageBot = css`
align-self: flex-start;
background-color: #e0e0e0;
color: black;
border-radius: 8px;
padding: 10px 10px 10px 15px;
font-size: 15px;
font-family: sans-serif;
`;
const messageClient = css`
align-self: flex-end;
background-color: #1a6fe8;
color: white;
border-radius: 8px;
padding: 10px 10px 10px 15px;
font-size: 15px;
font-family: sans-serif;
`;
const ChatBox = styled.div`
display: ${props => (props.widget ? 'none' : 'flex')};
position: absolute;
position: fixed;
right: 20px;
bottom: 20px;
flex-direction: column;
max-width: 22em;
width: 100%;
height: 30em;
border-radius: 6px;
box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 10px 2px;
background: ${props => (props.widget ? 'red' : 'blue')};
`;
const ChatLog = styled.div`
display: flex;
flex-direction: column;
max-height: 400px;
width: 100%;
overflow-y: auto;
flex: 1 100%;
background: red;
padding: 10px 10px 0px 10px;
box-sizing: border-box;
`;
const MessageWrapper = styled.div`
background: yellow;
display: flex;
align-items: center;
flex-direction: row;
box-sizing: border-box;
width: 100%;
justify-content: ${props => (props.user ? 'flex-end' : 'flex-start')};
`;
const ChatMessage = styled.div`
position: relative;
margin: 1ex;
padding: 1ex;
border-radius: 2px;
:before {
content: '';
position: absolute;
top: 50%;
right: ${props => (props.user ? '-5px' : '')};
left: ${props => (props.user ? '' : '1px')};
height: 15px;
width: 15px;
background: ${props => (props.user ? '#1a6fe8' : '#e0e0e0')};
transform: rotate(45deg);
transform-origin: top right;
}
${props => (props.user ? messageClient : messageBot)}
`;
I know that my div that is passing the size is ChatMessage
I believe she is the problem
img:
example on:
https://codesandbox.io/s/cool-water-1dwqx
You need to handle the overflow of the element.
const ChatMessage = styled.div`
...
overflow: hidden;
word-break: break-all;
`;

Resources