Skip to content

add icon as background image #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/ImageEventItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import styled from 'styled-components';
import Image from 'gatsby-image';
import { Link } from 'gatsby';
import fileImg from '../images/cdl_logo.png'

const ImageEventContainer = styled(Link)`
display: flex;
Expand Down Expand Up @@ -50,11 +51,17 @@ const EventLabel = styled.p`
}
`;

const ImageEvent = ({ url, image, text, eventName, boldText, openInNewTab }) => {
const IconBackground = styled.div`
background-image: ${(props) => (props.iconImg ? `url(${props.iconImg})` : `url(${fileImg})`)};
background-size: 100% 100%;
`;

const ImageEvent = ({ url, image, text, eventName, boldText, openInNewTab,iconImg }) => {

return (
<ImageEventContainer boldtext={boldText.toString()} to={url || '/'} target={openInNewTab ? '_blank' : '_self'}>
{eventName ? <EventLabel >{eventName}</EventLabel> : null}
{image ? <Image fluid={image} /> : <div />} <p>{text}</p>
{image ? <Image fluid={image} /> : iconImg? <IconBackground iconImg={iconImg} />: <div/>} <p>{text}</p>
</ImageEventContainer>
);
};
Expand Down
8 changes: 8 additions & 0 deletions src/images/icons/blog.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/images/icons/guidebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/images/icons/publishedpaper.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/images/icons/report.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/images/icons/workingpaper.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion src/pages/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import useFixedScroll from '../hooks/useFixedScroll';
import StandardGrid from '../styles/StandardGrid';
import { SocialLinks } from '../components/Contact';
import Select from 'react-select';
import blogImg from '../images/icons/blog.svg'
import guideImg from '../images/icons/guidebook.svg'
import publishedImg from '../images/icons/publishedpaper.svg'
import reportImg from '../images/icons/report.svg'
import workingImg from '../images/icons/workingpaper.svg'


export const TitleContainer = styled.div`
padding: 0;
Expand Down Expand Up @@ -167,6 +173,14 @@ const Resources = ({ data }) => {

useFixedScroll(leftContainerRef, rightContainerRef);

const imgIcon = {
'Working Paper': workingImg,
'Reports' : reportImg,
'Blog' : blogImg,
'Published Papers' : publishedImg,
'Guidebook' : guideImg
}

return (
<Layout>
<Seo title="Our Event" />
Expand All @@ -184,7 +198,7 @@ const Resources = ({ data }) => {
<EventsContainer>
{filteredResources.length > 0
? filteredResources.map((res) => (
<ImageEventItem boldText url={res.link} text={res.title} eventName={res.sector} openInNewTab/>
<ImageEventItem boldText iconImg={imgIcon[res.type]} url={res.link} text={res.title} eventName={res.sector} openInNewTab/>
))
:
<div>
Expand Down