ISSUE-035 - Styled the Team flags individually.

Went through a lot of trouble to style the team flags to be wider than the country flags. This called for a troubling amount of ternary statements in the angled flag components.
I'm content with the results.
This commit is contained in:
Kyle Geib committed 2022-02-01 18:24:48 -05:00
1 parent bd1892ab17
commit b39d005e23
8 files changed
+168 -79

No files matched your search

@@ -15,6 +15,9 @@ import {
const countryFlags = require.context("../../../../public/images/countryFlags/angled", true);
const teamLogos = require.context("../../../../public/images/logos/team", true);
const FLAG_WIDTH_TEAM = 2.4;
const FLAG_WIDTH_COUNTRY = 2;
/**
* To look right, country flags need to be 2:1. Additional editing will be
* necessary for some flags to not cut off prominent elements. Ex: China's flag
@@ -42,7 +45,7 @@ export function AngledFlag(props: AngledFlagProps) {
<CountryFlagDiv
src={countryFlags(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
width={flagHeight * FLAG_WIDTH_COUNTRY}
>
<FlagEdge
x={flagHeight / 2}
@@ -55,7 +58,7 @@ export function AngledFlag(props: AngledFlagProps) {
<CountryFlagDiv
src={countryFlags(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
width={flagHeight * FLAG_WIDTH_COUNTRY}
xOffset={-flagHeight * 0.005}
/>
);
@@ -64,13 +67,13 @@ export function AngledFlag(props: AngledFlagProps) {
<TeamFlagDiv
src={teamLogos(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
width={flagHeight * FLAG_WIDTH_TEAM}
style={getTeamFlagStyle(flagProps.flag)}
>
<FlagEdge
x={flagHeight / 2}
height={flagHeight}
girth={flagHeight * 0.07}
girth={flagHeight * 0.04}
/>
</TeamFlagDiv>
);
@@ -78,26 +81,31 @@ export function AngledFlag(props: AngledFlagProps) {
<TeamFlagDiv
src={teamLogos(`./${flagProps.flag}.svg`)}
height={flagHeight}
width={flagHeight * 2}
width={flagHeight * FLAG_WIDTH_TEAM}
style={getTeamFlagStyle(flagProps.flag)}
bottomFlag
/>
);
}
const flagModeWidth = flagProps.flagMode === "team" ? FLAG_WIDTH_TEAM : FLAG_WIDTH_COUNTRY;
return (
<Container width={flagHeight * 6} height={flagHeight * 3}>
<Slant x={0} height={flagHeight * 3} girth={flagHeight * 2.4} />
<FlagContainer
height={flagHeight}
width={flagHeight * 2} // Dynamic width...
collapsedWidth={flagHeight * 2}
width={flagHeight * flagModeWidth} // Dynamic width...
collapsedWidth={flagHeight * flagModeWidth}
masked
teamFlag={flagProps.flagMode === "team"}
>
<FlagContainer
height={flagHeight}
width={flagHeight * 2}
collapsedWidth={flagHeight * 2}
width={flagHeight * flagModeWidth}
collapsedWidth={flagHeight * flagModeWidth}
topFlag
teamFlag={flagProps.flagMode === "team"}
>
{topFlag}
</FlagContainer>
@@ -33,6 +33,7 @@ type FlagContainerProps = {
collapsedWidth: Px,
topFlag?: boolean,
masked?: boolean,
teamFlag?: boolean,
};
export const FlagContainer = styled.div<FlagContainerProps>`
position: absolute;
@@ -40,28 +41,28 @@ export const FlagContainer = styled.div<FlagContainerProps>`
width: ${({ width }) => `${width}px`};
${({ masked = false }) => masked && css`
mask-image: linear-gradient(
60deg,
to right,
transparent 0%,
black 15%,
black 85%,
transparent 100%
black 70%,
transparent 95%
);
`}
${({ width, collapsedWidth, topFlag = false }) => topFlag
${({ width, collapsedWidth, topFlag = false, teamFlag = false }) => topFlag
? css`
clip-path: polygon(
${((collapsedWidth * .5) / width) * 100}% 0,
95% 0,
${((collapsedWidth * (teamFlag ? .415 : .5)) / width) * 100}% 0,
${teamFlag ? 87.7 : 95}% 0,
${((1 - ((collapsedWidth * .55) / width)) * 100)}% 100%,
0 100%
);
`
: css`
clip-path: polygon(
${((collapsedWidth * .5) / width) * 100}% 0,
100% 0,
100% 30%,
${((collapsedWidth * (teamFlag ? .415 : .5)) / width) * 100}% 0,
${teamFlag ? 90 : 95}% 0,
${teamFlag ? 90 : 95}% 40%,
${((1 - ((collapsedWidth * .34) / width)) * 100)}% 100%,
0 100%
);
@@ -77,6 +78,7 @@ type FlagDivBaseProps = {
const FlagDivBase = styled.div<FlagDivBaseProps>`
height: ${({ height }) => `${height}px`};
width: ${({ width }) => `${width}px`};
background-color: white;
background-image: url(${({ src }) => src});
background-repeat: no-repeat;
`;
@@ -94,21 +96,36 @@ CountryFlagDiv.displayName = "CountryFlagDiv";
type TeamFlagDivProps = {
style: TeamFlagStyle,
bottomFlag?: boolean,
};
export const TeamFlagDiv = styled(FlagDivBase) <TeamFlagDivProps>`
height: ${({ height }) => `${height}px`};
width: ${({ width }) => `${width}px`};
background-image: url(${({ src }) => src})
${({ style: { backgroundImage } }) => backgroundImage
&& `, background-image: ${backgroundImage}`};
background-size: ${({ style: { imageSize } }) => `${imageSize}%`};
background-position: ${({ style: { imagePos: { x, y } } }) => `${x}% ${y}%`};
background-image: url(${({ src }) => src});
${({ style: { backgroundColor } }) => css`background-color: ${backgroundColor};`}
${({ style: { backgroundColor } }) => backgroundColor &&
css`background-color: ${backgroundColor};`}
${({ style: { backgroundImage } }) => backgroundImage &&
css`background-image: ${backgroundImage};`}
${({
bottomFlag,
height,
width,
style: {
imageSize,
imagePos: { x, y },
subFlagModifier: { x: subX, y: subY, scale: subScale },
},
}) => bottomFlag
? css`
background-size: ${imageSize * subScale}%;
background-position:
${`${width * (x === 0 ? .1 : x) * subX}px
${height * (y === 0 ? .1 : y) * subY}px`};
`
: css`
background-size: ${imageSize}%;
background-position:
${`${width * x}px ${height * y}px`};
`}
`;
type SlashProps = {
@@ -13,7 +13,7 @@ export function AngledFlagWorkSpace({ flagMode }: AngledFlagWorkSpaceProps) {
const { prototypeState } = useSelector(workspaceSelector);
if (flagMode === "none") return null;
const defaultTeam: TeamId = "alpine";
const defaultTeam: TeamId = "alfaRomeo";
return (
<BasicBlock width={750} height={450} color="rgba(30, 30, 30, .7)">
@@ -13,10 +13,13 @@ const countries = [
"CAN", "RUS", "RAF", "AUS", "ESP", "ITA",
];
const teams: Array<TeamId> = [
"alpine", "alfaRomeo", "alphaTauri", "astonMartin", "haas", "ferrari",
"alfaRomeo", "alphaTauri", "alpine", "astonMartin", "ferrari", "haas",
"mclaren", "mercedes", "redBull", "williams",
];
const DEFAULT_COUNTRY = "GBR";
const DEFAULT_TEAM: TeamId = "alfaRomeo";
type AngledFlagPrototypeControlsProps = {
flagMode: FlagMode,
};
@@ -29,15 +32,23 @@ export function AngledFlagPrototypeControls({ flagMode }: AngledFlagPrototypeCon
if (flagMode === "country") {
dispatch(setPrototypeState({
angledFlagCountry: {
flagA: flag === "flagA" ? countries[index] : prototypeState?.angledFlagCountry?.flagA ?? "GBR",
flagB: flag === "flagB" ? countries[index] : prototypeState?.angledFlagCountry?.flagB ?? "GBR",
flagA: flag === "flagA"
? countries[index]
: prototypeState?.angledFlagCountry?.flagA ?? DEFAULT_COUNTRY,
flagB: flag === "flagB"
? countries[index]
: prototypeState?.angledFlagCountry?.flagB ?? DEFAULT_COUNTRY,
},
}));
} else if (flagMode === "team") {
dispatch(setPrototypeState({
angledFlagTeam: {
flagA: flag === "flagA" ? teams[index] : prototypeState?.angledFlagTeam?.flagA ?? "alpine",
flagB: flag === "flagB" ? teams[index] : prototypeState?.angledFlagTeam?.flagB ?? "alpine",
flagA: flag === "flagA"
? teams[index]
: prototypeState?.angledFlagTeam?.flagA ?? DEFAULT_TEAM,
flagB: flag === "flagB"
? teams[index]
: prototypeState?.angledFlagTeam?.flagB ?? DEFAULT_TEAM,
},
}));