ISSUE-031 - Almost forgot (I closed issue and merged the branch too early): Here's the important improvement that switches to using a clipped image div for the AngledFlag. There is now a carefully sized "bottom" flag that gives us a simulated parallax look. There is a simple xOffset that should allow us to animate two flags sliding over each other in the future.
Updated the use of "National" to "Country" and renamed some directories. Added a second larger AngledFlag to the Workspace (because changes that affect the larger size might be hidden by a smaller flag).
This commit is contained in:
1 parent
a32e5d656b
commit
b6cac82042
38 files changed
+126
-39
No files matched your search
@@ -1,9 +1,16 @@
|
||||
import { FlagMode } from "../../../../types/state";
|
||||
import { Px } from "../../../../types/style";
|
||||
import { Container, NationalFlag, Slant, Sheen, NationalFlagEdge } from "./styles";
|
||||
import {
|
||||
Container,
|
||||
Slant,
|
||||
Sheen,
|
||||
CountryFlagEdge,
|
||||
CountryFlagDiv,
|
||||
FlagContainer,
|
||||
} from "./styles";
|
||||
|
||||
const flags = require.context("../../../../public/images/flags/angled", true);
|
||||
const logos = require.context("../../../../public/images/logos", true);
|
||||
const countryFlags = require.context("../../../../public/images/countryFlags/angled", true);
|
||||
// const teamLogos = require.context("../../../../public/images/teamLogos", true);
|
||||
|
||||
/**
|
||||
* To look right, country flags need to be 2:1. Additional editing will be
|
||||
@@ -17,24 +24,55 @@ type AngledFlagProps = {
|
||||
flagHeight: Px,
|
||||
};
|
||||
export function AngledFlag({ flagMode, flag, flagHeight }: AngledFlagProps) {
|
||||
const topFlag = flagMode === "country"
|
||||
? (
|
||||
<CountryFlagDiv
|
||||
src={countryFlags(`./${flag}.svg`)}
|
||||
height={flagHeight}
|
||||
width={flagHeight * 2}
|
||||
>
|
||||
<CountryFlagEdge
|
||||
x={flagHeight / 2}
|
||||
height={flagHeight}
|
||||
girth={flagHeight * 0.07}
|
||||
/>
|
||||
</CountryFlagDiv>
|
||||
) : null; // Team flag here
|
||||
|
||||
const bottomFlag = flagMode === "country"
|
||||
? (
|
||||
<CountryFlagDiv
|
||||
src={countryFlags(`./${flag}.svg`)}
|
||||
height={flagHeight}
|
||||
width={flagHeight * 2}
|
||||
xOffset={-flagHeight * 0.005}
|
||||
/>
|
||||
) : null; // Team flag here
|
||||
|
||||
return (
|
||||
<Container width={flagHeight * 6} height={flagHeight * 3}>
|
||||
<Slant x={0} height={flagHeight * 3} girth={flagHeight * 2.4} />
|
||||
{flagMode === "country" ? (
|
||||
<>
|
||||
<NationalFlag
|
||||
alt=""
|
||||
src={flags(`./${flag}.svg`)}
|
||||
height={flagHeight}
|
||||
/>
|
||||
<NationalFlagEdge
|
||||
x={-(flagHeight / 2) + ((flagHeight * 0.07) / 2)}
|
||||
height={flagHeight}
|
||||
girth={flagHeight * 0.07}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
<Sheen x={-10} height={flagHeight * 3} girth={flagHeight * 1.1} />
|
||||
<FlagContainer
|
||||
height={flagHeight}
|
||||
width={flagHeight * 2} // Dynamic width...
|
||||
collapsedWidth={flagHeight * 2}
|
||||
masked
|
||||
>
|
||||
<FlagContainer
|
||||
height={flagHeight}
|
||||
width={flagHeight * 2}
|
||||
collapsedWidth={flagHeight * 2}
|
||||
topFlag
|
||||
>
|
||||
{topFlag}
|
||||
</FlagContainer>
|
||||
{bottomFlag}
|
||||
</FlagContainer>
|
||||
<Sheen
|
||||
x={-flagHeight / 6.4}
|
||||
height={flagHeight * 3}
|
||||
girth={flagHeight * 1.1}
|
||||
/>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import styled from "styled-components";
|
||||
import styled, { css } from "styled-components";
|
||||
import { Px } from "../../../../types/style";
|
||||
|
||||
type ContainerProps = {
|
||||
@@ -26,25 +26,68 @@ export const Container = styled.div<ContainerProps>`
|
||||
`;
|
||||
Container.displayName = "Container";
|
||||
|
||||
type NationalFlagProps = {
|
||||
type FlagContainerProps = {
|
||||
height: Px,
|
||||
width: Px,
|
||||
collapsedWidth: Px,
|
||||
topFlag?: boolean,
|
||||
masked?: boolean,
|
||||
};
|
||||
export const NationalFlag = styled.img<NationalFlagProps>`
|
||||
max-inline-size: unset;
|
||||
export const FlagContainer = styled.div<FlagContainerProps>`
|
||||
position: absolute;
|
||||
height: ${({ height }) => `${height}px`};
|
||||
clip-path: polygon(50% 0, 100% 0, 100% 30%, 66% 100%, 0 100%, 0 100%);
|
||||
mask-image: linear-gradient(
|
||||
60deg,
|
||||
transparent 0%,
|
||||
black 15%,
|
||||
black 85%,
|
||||
transparent 100%
|
||||
);
|
||||
width: ${({ width }) => `${width}px`};
|
||||
${({ masked = false }) => masked && css`
|
||||
mask-image: linear-gradient(
|
||||
60deg,
|
||||
transparent 0%,
|
||||
black 15%,
|
||||
black 85%,
|
||||
transparent 100%
|
||||
);
|
||||
`}
|
||||
|
||||
${({ width, collapsedWidth, topFlag = false }) => topFlag
|
||||
? css`
|
||||
clip-path: polygon(
|
||||
${((collapsedWidth * .5) / width) * 100}% 0,
|
||||
95% 0,
|
||||
${((1 - ((collapsedWidth * .55) / width)) * 100)}% 100%,
|
||||
0 100%
|
||||
);
|
||||
`
|
||||
: css`
|
||||
clip-path: polygon(
|
||||
${((collapsedWidth * .5) / width) * 100}% 0,
|
||||
100% 0,
|
||||
100% 30%,
|
||||
${((1 - ((collapsedWidth * .34) / width)) * 100)}% 100%,
|
||||
0 100%
|
||||
);
|
||||
`}
|
||||
`;
|
||||
NationalFlag.displayName = "NationalFlag";
|
||||
FlagContainer.displayName = "FlagContainer";
|
||||
|
||||
type CountryFlagDivProps = {
|
||||
src: string,
|
||||
height: Px,
|
||||
width: Px,
|
||||
xOffset?: Px,
|
||||
};
|
||||
export const CountryFlagDiv = styled.div<CountryFlagDivProps>`
|
||||
height: ${({ height }) => `${height}px`};
|
||||
width: ${({ width }) => `${width}px`};
|
||||
background-image: url(${({ src }) => src});
|
||||
background-size: ${({ width, height }) => `${width}px ${height}px`};
|
||||
background-repeat: no-repeat;
|
||||
${({ xOffset }) => xOffset == null
|
||||
? css`background-position: center;`
|
||||
: css`background-position-x: ${xOffset}px`}
|
||||
`;
|
||||
CountryFlagDiv.displayName = "CountryFlagDiv";
|
||||
|
||||
type SlashProps = {
|
||||
x: Px,
|
||||
x?: Px,
|
||||
height: Px,
|
||||
girth: Px,
|
||||
};
|
||||
@@ -67,9 +110,9 @@ export const Sheen = styled.div<SlashProps>`
|
||||
box-shadow:
|
||||
0.02em 0 0.005em 0.015em rgba(0, 0, 0, 0.2),
|
||||
1em 0 0 1em rgba(0, 0, 0, 0.5);
|
||||
transform: skew(-45deg, 0deg) translateX(${({ x }) => `${x}px`});
|
||||
transform: skew(-45deg, 0deg) translateX(${({ x = 0 }) => `${x}px`});
|
||||
|
||||
border-left: 0.015em solid rgba(255, 255, 255, 0.25);
|
||||
border-left: 0.015em solid rgba(255, 255, 255, 0.1);
|
||||
`;
|
||||
Sheen.displayName = "Sheen";
|
||||
|
||||
@@ -79,18 +122,18 @@ export const Slant = styled.div<SlashProps>`
|
||||
width: ${({ girth }) => `${girth}px`};
|
||||
|
||||
background: #1a1a28;
|
||||
transform: skewX(-45deg) translateX(${({ x }) => `${x}px`});
|
||||
transform: skewX(-45deg) translateX(${({ x = 0 }) => `${x}px`});
|
||||
`;
|
||||
Slant.displayName = "Slant";
|
||||
|
||||
export const NationalFlagEdge = styled.div<SlashProps>`
|
||||
export const CountryFlagEdge = styled.div<SlashProps>`
|
||||
position: absolute;
|
||||
height: ${({ height }) => `${height}px`};
|
||||
width: ${({ girth }) => `${girth}px`};
|
||||
|
||||
background: ${p => p.theme.colors.lightGrey};
|
||||
opacity: 0.5;
|
||||
transform: skewX(-45deg) translateX(${({ x }) => `${x}px`});
|
||||
transform: skewX(-45deg) translateX(${({ x = 0 }) => `${x}px`});
|
||||
|
||||
mask-image: linear-gradient(
|
||||
to top,
|
||||
@@ -99,3 +142,4 @@ export const NationalFlagEdge = styled.div<SlashProps>`
|
||||
black 100%
|
||||
);
|
||||
`;
|
||||
CountryFlagEdge.displayName = "CountryFlagEdge";
|
||||
@@ -3,12 +3,17 @@ import { BasicBlock } from "./styles";
|
||||
|
||||
export function AngledFlagWorkSpace() {
|
||||
return (
|
||||
<BasicBlock width={400} height={400} color="rgba(30, 30, 30, .7)">
|
||||
<BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)">
|
||||
<AngledFlag
|
||||
flagMode="country"
|
||||
flag="GBR"
|
||||
flagHeight={64}
|
||||
/>
|
||||
<AngledFlag
|
||||
flagMode="country"
|
||||
flag="MEX"
|
||||
flagHeight={128}
|
||||
/>
|
||||
</BasicBlock>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user