refactor(card): rework
This commit is contained in:
@@ -3,59 +3,58 @@ import { Link as GatsbyLink } from "gatsby";
|
|||||||
import Img from "gatsby-image";
|
import Img from "gatsby-image";
|
||||||
import styled from "@emotion/styled";
|
import styled from "@emotion/styled";
|
||||||
|
|
||||||
const Container = styled.div`
|
const Media = styled.div`
|
||||||
|
transition: transform 0.15s ease-in;
|
||||||
|
`;
|
||||||
|
const Heading = styled.div``;
|
||||||
|
const Body = styled.div``;
|
||||||
|
|
||||||
|
const Content = styled.div`
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
flex-direction: column;
|
||||||
margin: 0 calc(var(--spacing-x-xs) * -1) var(--spacing-y-sm);
|
justify-content: space-between;
|
||||||
|
padding: var(--spacing-y-sm) var(--spacing-x-xs);
|
||||||
|
color: var(--color-white);
|
||||||
|
text-align: center;
|
||||||
|
background-color: rgba(0, 0, 0, 0.25);
|
||||||
|
transform: translate3d(0, calc(100% - 58px), 0);
|
||||||
|
transition: transform 0.15s ease-in, background-color 0.3s ease-in;
|
||||||
|
`;
|
||||||
|
|
||||||
@media (max-width: 30em) {
|
const Container = styled.div`
|
||||||
&:nth-of-type(even) {
|
position: relative;
|
||||||
flex-direction: row-reverse;
|
overflow: hidden;
|
||||||
}
|
&:hover ${Content} {
|
||||||
|
background-color: rgba(0, 0, 0, 0.65);
|
||||||
|
transform: translate3d(0, 0, 0);
|
||||||
|
}
|
||||||
|
&:hover ${Media} {
|
||||||
|
transform: scale(1.05);
|
||||||
}
|
}
|
||||||
`;
|
|
||||||
|
|
||||||
const Media = styled.span`
|
|
||||||
padding: 0 var(--spacing-x-xs);
|
|
||||||
transition: transform 0.15s ease-in, filter 0.15s ease-in;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const Content = styled.span`
|
|
||||||
padding: 0 var(--spacing-x-xs);
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Link = styled(GatsbyLink)`
|
const Link = styled(GatsbyLink)`
|
||||||
outline: 0;
|
outline: 0;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: var(--color-black);
|
|
||||||
|
|
||||||
&:hover ${Media} {
|
|
||||||
transform: scale(1.1);
|
|
||||||
filter: brightness(110%) contrast(110%);
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 30em) {
|
|
||||||
&:nth-of-type(even) ${Container} {
|
|
||||||
flex-direction: row-reverse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default function Card({ image, children, to }) {
|
export default function Card({ image, heading, children, to }) {
|
||||||
const render = () => (
|
const render = () => (
|
||||||
<Container>
|
<Container>
|
||||||
{image && (
|
{image && (
|
||||||
<Media>
|
<Media>
|
||||||
<Img
|
<Img fluid={image} />
|
||||||
style={{
|
|
||||||
display: "block",
|
|
||||||
borderRadius: "5px"
|
|
||||||
}}
|
|
||||||
fixed={image}
|
|
||||||
/>
|
|
||||||
</Media>
|
</Media>
|
||||||
)}
|
)}
|
||||||
<Content>{children}</Content>
|
<Content>
|
||||||
|
{heading && <Heading>{heading}</Heading>}
|
||||||
|
<Body>{children}</Body>
|
||||||
|
</Content>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
return to ? <Link to={to}>{render()}</Link> : render();
|
return to ? <Link to={to}>{render()}</Link> : render();
|
||||||
|
|||||||
@@ -19,14 +19,20 @@ const Content = styled.div`
|
|||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const Head = styled.div`
|
||||||
|
text-align: center;
|
||||||
|
`;
|
||||||
|
|
||||||
const Body = styled.div`
|
const Body = styled.div`
|
||||||
${props =>
|
${props =>
|
||||||
props.grid > 0 &&
|
props.grid > 0 &&
|
||||||
css`
|
css`
|
||||||
|
display: grid;
|
||||||
|
gap: var(--spacing-x-sm) 0;
|
||||||
|
|
||||||
@media (min-width: ${props.breakpoint}) {
|
@media (min-width: ${props.breakpoint}) {
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(${props.grid}, 1fr);
|
grid-template-columns: repeat(${props.grid}, 1fr);
|
||||||
gap: var(--spacing-x-xs);
|
gap: var(--spacing-x-md);
|
||||||
}
|
}
|
||||||
`}
|
`}
|
||||||
`;
|
`;
|
||||||
@@ -42,7 +48,11 @@ export default function Section({
|
|||||||
return (
|
return (
|
||||||
<Container variant={variant}>
|
<Container variant={variant}>
|
||||||
<Content>
|
<Content>
|
||||||
{heading && <Heading el={headingElement}>{heading}</Heading>}
|
{heading && (
|
||||||
|
<Head>
|
||||||
|
<Heading el={headingElement}>{heading}</Heading>
|
||||||
|
</Head>
|
||||||
|
)}
|
||||||
<Body grid={grid} breakpoint={breakpoint}>
|
<Body grid={grid} breakpoint={breakpoint}>
|
||||||
{children}
|
{children}
|
||||||
</Body>
|
</Body>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
CustomSlick,
|
CustomSlick,
|
||||||
Header,
|
Header,
|
||||||
HeaderLogo,
|
HeaderLogo,
|
||||||
|
Heading,
|
||||||
ReviewSummary,
|
ReviewSummary,
|
||||||
Section,
|
Section,
|
||||||
Text
|
Text
|
||||||
@@ -20,27 +21,31 @@ export default function Index({ data }) {
|
|||||||
<Section grid={2} heading="What we do">
|
<Section grid={2} heading="What we do">
|
||||||
<Card
|
<Card
|
||||||
to="/services/bathrooms"
|
to="/services/bathrooms"
|
||||||
image={data.bathroomImage.childImageSharp.fixed}
|
image={data.bathroomImage.childImageSharp.fluid}
|
||||||
|
heading={<Heading el="h3">Bathrooms</Heading>}
|
||||||
>
|
>
|
||||||
Bathrooms
|
Fully accredited bathroom refurbishment service
|
||||||
</Card>
|
</Card>
|
||||||
<Card
|
<Card
|
||||||
to="/services/tiling"
|
to="/services/tiling"
|
||||||
image={data.tilingImage.childImageSharp.fixed}
|
image={data.tilingImage.childImageSharp.fluid}
|
||||||
|
heading={<Heading el="h3">Tiling</Heading>}
|
||||||
>
|
>
|
||||||
Tiling
|
Our tiling is primo!
|
||||||
</Card>
|
</Card>
|
||||||
<Card
|
<Card
|
||||||
to="/services/electrics"
|
to="/services/electrics"
|
||||||
image={data.electricsImage.childImageSharp.fixed}
|
image={data.electricsImage.childImageSharp.fluid}
|
||||||
|
heading={<Heading el="h3">Electrics</Heading>}
|
||||||
>
|
>
|
||||||
Electrics
|
Bring some light to your next project
|
||||||
</Card>
|
</Card>
|
||||||
<Card
|
<Card
|
||||||
to="/services/carpentry"
|
to="/services/carpentry"
|
||||||
image={data.carpentryImage.childImageSharp.fixed}
|
image={data.carpentryImage.childImageSharp.fluid}
|
||||||
|
heading={<Heading el="h3">Carpentry</Heading>}
|
||||||
>
|
>
|
||||||
Carpentry
|
Our woodworking is sharp!
|
||||||
</Card>
|
</Card>
|
||||||
</Section>
|
</Section>
|
||||||
<Section variant="primary">
|
<Section variant="primary">
|
||||||
@@ -65,29 +70,29 @@ export const query = graphql`
|
|||||||
}
|
}
|
||||||
bathroomImage: file(relativePath: { eq: "service_bathroom.png" }) {
|
bathroomImage: file(relativePath: { eq: "service_bathroom.png" }) {
|
||||||
childImageSharp {
|
childImageSharp {
|
||||||
fixed(width: 96, height: 54, quality: 100) {
|
fluid(maxWidth: 480, quality: 100) {
|
||||||
...GatsbyImageSharpFixed_withWebp
|
...GatsbyImageSharpFluid_withWebp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tilingImage: file(relativePath: { eq: "service_tiling.png" }) {
|
tilingImage: file(relativePath: { eq: "service_tiling.png" }) {
|
||||||
childImageSharp {
|
childImageSharp {
|
||||||
fixed(width: 96, height: 54, quality: 100) {
|
fluid(maxWidth: 480, quality: 100) {
|
||||||
...GatsbyImageSharpFixed_withWebp
|
...GatsbyImageSharpFluid_withWebp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
electricsImage: file(relativePath: { eq: "service_electrics.png" }) {
|
electricsImage: file(relativePath: { eq: "service_electrics.png" }) {
|
||||||
childImageSharp {
|
childImageSharp {
|
||||||
fixed(width: 96, height: 54, quality: 100) {
|
fluid(maxWidth: 480, quality: 100) {
|
||||||
...GatsbyImageSharpFixed_withWebp
|
...GatsbyImageSharpFluid_withWebp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
carpentryImage: file(relativePath: { eq: "service_carpentry.png" }) {
|
carpentryImage: file(relativePath: { eq: "service_carpentry.png" }) {
|
||||||
childImageSharp {
|
childImageSharp {
|
||||||
fixed(width: 96, height: 54, quality: 100) {
|
fluid(maxWidth: 480, quality: 100) {
|
||||||
...GatsbyImageSharpFixed_withWebp
|
...GatsbyImageSharpFluid_withWebp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user