Include an icon/image inside Ant Design Collapse panel other than expandIcon - reactjs

I'm having issue adding icon in front of the header title as according to the Ant design collapse docs, we can only add expandIcon either on the right or left and I wonder if I can do both. But the icon I want to add is static which won't change when I clicked on panel to expand. Here's the picture to illustrate my CustomCollapse.
Here's my code of my collapse:
//styled
const StyledCollapse = styled(AntCollapse)`
&&& {
border: none;
border-radius: 0 10px 0 0;
box-shadow: none;
background-color: #0e0304;
.ant-collapse-content {
background-color: #0e0304;
color: #b5b5b6;
}
.ant-collapse-header {
color: #b5b5b6;
}
}
`;
_______________________________________________________
<StyledCollapse accordian activeKey={props.show ? key : []} onChange={combineFunc}>
<AntCollapse.Panel
{...props}
header={props.header}
showArrow={false}
bordered={false}
disabled={props.isFollowed}
key={props.panelID}
extra={
<span>
<div className={styles.extraContainer}>
{
!props.show && !props.isFollowed && props.panelID !== "1" && <img src={rewardIcon} alt="" style={{height:'1.2em', marginLRight:'10px', width:'auto', objectFit:'contain'}} /> // show this box
}
{
props.show && !props.isFollowed && <img src={arrowDownIcon} alt="" style={{height:'1.2em', marginRight:'10px', width:'auto', objectFit:'contain'}} /> // show this icon
}
{
props.isFollowed ? <img src={tickIcon} alt="" style={{height:'1.2em', marginLRight:'10px', width:'auto', objectFit:'contain'}} /> : ""
}
</div>
</span>
}
>
{props.children}
</AntCollapse.Panel>
</StyledCollapse>
In the extra API, I have added display of +10. So i'm wondering if I can still add an icon in front of the header title and what API should I use.

Try it:
JSX return
function createMarkup() {
return {__html: '<img src="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a" /> abc'};
}
return (
<Collapse defaultActiveKey={["1"]} onChange={onChange}>
<Panel
header={<div dangerouslySetInnerHTML={createMarkup()} />}
showArrow={false}
key="1"
>
<p>123</p>
</Panel>
</Collapse>
)
result:

Related

How to highlight the selected menu item

I want to highlight the selected menu item, can anyone help?
<div className="scrollmenu" style={{ display: "flex" }}>
{
category.map((item) => (
<div className="menu__wrapper">
<menu
onClick={() => { showCat(item.id); showCatName(item.name); }}
className="mobile-cat-menu"
// style={{ float: "right", cursor: "pointer", paddingLeft: "0px", margin: "0px" }}
>
{item.name}
</menu>
</div>
))}
</div>
You can change the className depending on the selected element, and use CSS to highlight it.
For example, let's assume that you want to highlight a cat called Supercat:
<div className = "scrollmenu" style = {{ display: "flex" }}>
{
category.map((item) => (
<div className = "menu__wrapper">
<menu
onClick = {() => { showCat(item.id); showCatName(item.name); }}
className = "mobile-cat-menu"
>
<div className = { item.name === "Supercat" ? "highlight" : "not__highlight" }>
{item.name}
</div>
</menu>
</div>
))
}
</div>
Then use CSS:
.highlight{
background: red;
}
.not__highlight{
background: transparent;
}

Problems with Styled-Components conditional style rendering. I'm not sure what's wrong

I'm trying to toggle a hamburger menu on and off. I've console logged to check that the boolean values are changing, but the css isn't.
My issue is with 'props.active?' it's working but the '.mobile-menu' class is not changing. I'm not entirely sure what I need to do to get it to work. I've tried to make changes to the style I want to affect because I thought maybe you can't toggle as display, however,f visibility and opacity still aren't changing either.
import { useState } from "react";
import styled from "styled-components";
import logo from "./assets/logo.svg";
const StyledHeader = styled.header`
---
button {
---
span {
---
&:nth-child(even) {
margin: 5px 0;
}
}
}
.mobile-menu {
position: absolute;
right: 100px;
top: 100px;
display: ${(props) => (props.active ? "none" : "block")};
height: 330px;
width: 330px;
background: #e210e2;
color: white;
ul {
----
}
}
`;
const Header = () => {
const [active, setActive] = useState(false);
return (
<StyledHeader>
<img src={logo} alt="sunnyside logo" />
<button onClick={() => setActive(!active)}>
{console.log(active)}
<span></span>
<span></span>
<span></span>
</button>
<nav className="mobile-menu" active>
<ul>
<li>About</li>
<li>Services</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
</StyledHeader>
);
};
export default Header;
Please pass the props in the StyledHeader tag.
Follow the below code:
<StyledHeader active={active}>
....
</StyledHeader>
You're not passing the active prop. You need to pass the active prop to the StyledHeader component to apply the styles like below.
<StyledHeader active={active}>
Updated Code will be like this.
<StyledHeader active={active}>
<img src={logo} alt="sunnyside logo" />
<button onClick={() => setActive(!active)}>
{console.log(active)}
<span></span>
<span></span>
<span></span>
</button>
<nav className="mobile-menu" active>
<ul>
<li>About</li>
<li>Services</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
</StyledHeader>

How can I put the arrows in the center and outside the red border? React-multi-carousel

I'm using react-multi-carousel, What I would like to do is to always have the arrows in the middle and outside the border-box, how can I do that? Is there any trick in css to acomplish this?
I tried to put the react-multiple-carousel__arrow--left and react-multiple-carousel__arrow--righft with position absolute but this will always put the arrows at the top of the page. Below is my code so far...
<CarouselWrapper>
<Carousel
customLeftArrow={<CustomLeftArrow />}
customRightArrow={<CustomRightArrow />}
renderButtonGroupOutside={true}
customButtonGroup={<ButtonGroup />}
responsive={responsive}
arrows={false}
>
<div className="image">1</div>
<div className="image">2</div>
<div className="image">3</div>
<div className="image">4</div>
<div className="image">5</div>
<div className="image">6</div>
</Carousel>
</CarouselWrapper>
css
.image {
height: 150px;
width: 150px;
font-size: 25px;
margin: 10px;
display: inline-block;
line-height: 100px;
border: 3px red solid;
}
function CustomRightArrow({ onClick }) {
return (
<button
onClick={handleClick}
aria-label="Go to next slide"
className="react-multiple-carousel__arrow react-multiple-carousel__arrow--right"
/>
);
}
function CustomLeftArrow({ onClick }) {
return (
<button
onClick={handleClick}
aria-label="Go to previous slide"
className="react-multiple-carousel__arrow react-multiple-carousel__arrow--left"
/>
);
}
const ButtonGroup = ({ next, previous }) => {
return (
<div className="carousel-button-group">
<CustomLeftArrow
onClick={() => previous()}
/>
<CustomRightArrow onClick={() => next()} />
</div>
);
};

Conditionally apply css class to div in React ternary

I'm mapping over a data object in React, and need to be able to conditionally apply a class to a div if item.lead === true for either item.profile or item.noprofile. My current implementation is grabbing user data, but not sure how to apply a class with my current setup:
React Profile
<li key={i} className={classes.member}>
<a href={`mailto:${item.email}`}>
{item.profile ? (
<img
alt={item.name}
className={classes.profile}
src={item.profile}
/>
) : (
<div className={classes.noprofile}>
<span className={classes.initials}>
{item.firstName}
</span>
</div>
)}
<div className={classes.details}>
<div>
{item.firstName} {item.lastName}
</div>
<span>{item.title}</span>
</div>
</a>
</li>
JSS class that needs to be applied if a user is a lead (item.lead)
lead: {
"&:after": {
content: `'LEAD'`,
top: "5px",
position: "relative",
zIndex: "-1",
fontSize: "10px",
padding: "5px 4px 2px 4px",
}
}
You can use like this:
className={classes.profile + (item.lead && ' lead' || '')}
#Bhojendra's logic was close, but I discovered the logic needed to be as follows:
-for profiles with images: (item.lead === true && ${classes.profilelead}) || ""
-for those without: className={classes.noprofile + ((item.lead === true && ${classes.lead}) || "")}

Why are Styled Component props displaying as HTML attributes?

I'm passing down boolean props to Styled Components to change styling based on the props that are passed into the Component, like so:
<Button href="#contact" small elevate={false} display="primary">
CONTACT
</Button>
The output of this JSX is invalid HTML that looks like this:
<a href="#contact" class="Button__ButtonWrapper-fvVzGy gOcROU" display="primary" fluid="0" elevate="0" small="1">
CONTACT
</a>
Any idea how to ensure props won't be displayed as HTML attrs?
Full Button component:
const ButtonWrapper = styled.button`
padding: ${props =>
props.small
? `${rem(6)} ${props.theme.sizes.sm}`
: `${rem(12)} ${props.theme.sizes.med}`};
box-shadow: ${props =>
props.elevate
? `0 10px 15px 0 rgba(0,0,0,0.10)`
: `0 2px 8px 0 rgba(0,0,0,0.10)`};
color: ${props => {
if (props.display === 'primary') return props.theme.buttons.primary.color;
if (props.display === 'secondary')
return props.theme.buttons.secondary.color;
}};
`;
const Button = ({
display,
fluid,
children,
cta,
elevate,
small,
...other
}) => {
<ButtonWrapper
display={display}
fluid={fluid ? 1 : 0}
elevate={elevate ? 1 : 0}
small={small ? 1 : 0}
{...other}
>
{children}
{cta && (
<div className="icon" dangerouslySetInnerHTML={{ __html: CtaIcon }} />
)}
</ButtonWrapper>
};
export default Button;
This documentation page might be helpful: https://www.styled-components.com/docs/basics#passed-props
Basically if you use a non-camelcase prop to do styling, it'll get passed through to the DOM node. We're looking into better alternatives to this pattern.
I have the exact same problem, when I pass width or height props in to a component they are visible on the html, I think that both words (and maybe others) are actually keywords because with the rest of props this doesn't happen.
Example:
<div class="Container-sc-10mm8fh-0 cyDjRF">
<div class="Line-sc-10mm8fh-1 oPRx"></div>
<div height="3rem" class="VSpace-sc-18gziyv-1 kkKpPd"></div>
<div class="Line-sc-10mm8fh-1 oPRx"></div>
<div height="0.4rem" class="VSpace-sc-18gziyv-1 kkKpPd"></div>
<div class="Line-sc-10mm8fh-1 oPRx"></div>
</div>

Resources