Skip to content

Commit

Permalink
improve: make vote table columns narrower (#79)
Browse files Browse the repository at this point in the history
* add mocks to vote page story

Signed-off-by: ryanwolhuter <[email protected]>

* add long titles to vote mocks

Signed-off-by: ryanwolhuter <[email protected]>

* use auto table layout

Signed-off-by: ryanwolhuter <[email protected]>

* remove format vote title

Signed-off-by: ryanwolhuter <[email protected]>

* add nowrap to button

Signed-off-by: ryanwolhuter <[email protected]>

* use vw based padding

Signed-off-by: ryanwolhuter <[email protected]>

* use css to truncate vote title

Signed-off-by: ryanwolhuter <[email protected]>

* use clamped values for page padding

Signed-off-by: ryanwolhuter <[email protected]>

Signed-off-by: ryanwolhuter <[email protected]>
  • Loading branch information
ryanwolhuter authored Nov 21, 2022
1 parent 82735fb commit 91ca52e
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 39 deletions.
9 changes: 4 additions & 5 deletions components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mobileAndUnder } from "constant";
import { tabletAndUnder } from "constant";
import { ReactNode } from "react";
import styled from "styled-components";

Expand All @@ -24,10 +24,9 @@ const InnerWrapper = styled.div`
height: var(--banner-height);
display: flex;
align-items: center;
padding-left: 45px;
@media ${mobileAndUnder} {
max-width: unset;
padding: 15px;
padding-left: clamp(10px, 45px, 4vw);
@media ${tabletAndUnder} {
padding: 0;
}
margin-inline: auto;
`;
Expand Down
1 change: 1 addition & 0 deletions components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const __Button = styled.button`
border-radius: var(--border-radius);
font: var(--text-md);
font-size: var(--font-size);
white-space: nowrap;
&:hover {
&:not(:disabled) {
Expand Down
2 changes: 1 addition & 1 deletion components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const OuterWrapper = styled.header``;
const InnerWrapper = styled.div`
max-width: var(--page-width);
height: var(--header-height);
padding-inline: 45px;
padding-inline: clamp(10px, 45px, 4vw);
display: flex;
justify-content: space-between;
align-items: center;
Expand Down
2 changes: 1 addition & 1 deletion components/HowItWorks/HowItWorks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const OuterWrapper = styled.section`
`;

const InnerWrapper = styled.div`
padding-inline: 45px;
padding-inline: clamp(10px, 45px, 4vw);
padding-block: 30px;
max-width: var(--page-width);
margin-inline: auto;
Expand Down
1 change: 0 additions & 1 deletion components/VotesList/VotesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export function VotesList({ headings, rows }: Props) {
}

const Wrapper = styled.table`
table-layout: fixed;
width: 100%;
border-spacing: 0 5px;
Expand Down
71 changes: 56 additions & 15 deletions components/VotesList/VotesListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ export function VotesListItem({
return "transparent";
}

function getTitleMaxWidth() {
if (activityStatus === "upcoming") return "70vw";
if (activityStatus === "active" && phase === "commit")
return "max(35vw, 320px)";
if (
(activityStatus === "active" && phase === "reveal") ||
activityStatus === "past"
)
return "max(400px, 45vw)";
}

function getRelevantTransactionLink(): ReactNode | string {
if (phase === "commit") {
return commitHash ? (
Expand All @@ -200,11 +211,6 @@ export function VotesListItem({
);
}

function formatTitle(title: string) {
if (title.length <= 45) return title;
return `${title.substring(0, 45)}...`;
}

return (
<Wrapper as={isTabletAndUnder ? "div" : "tr"}>
<VoteTitleOuterWrapper as={isTabletAndUnder ? "div" : "td"}>
Expand All @@ -219,7 +225,15 @@ export function VotesListItem({
<Icon />
</VoteIconWrapper>
<VoteDetailsWrapper>
<VoteTitle>{formatTitle(title)}</VoteTitle>
<VoteTitle
style={
{
"--title-max-width": getTitleMaxWidth(),
} as CSSProperties
}
>
{title}
</VoteTitle>
<VoteDetailsInnerWrapper>
{isRolled && !isV1 ? (
<Tooltip label="This vote was included in the previous voting cycle, but did not get enough votes to resolve.">
Expand Down Expand Up @@ -354,17 +368,21 @@ const Wrapper = styled.tr`
`;

const VoteTitleOuterWrapper = styled.td`
width: 100%;
padding-left: 1vw;
padding-right: 2.5vw;
@media ${tabletAndUnder} {
padding: 0;
}
`;

const VoteTitleWrapper = styled.div`
display: flex;
align-items: center;
gap: 20px;
margin-left: 30px;
gap: 1vw;
@media ${tabletAndUnder} {
margin-left: 0;
gap: unset;
padding-bottom: 5px;
border-bottom: 1px solid var(--border-color);
}
Expand All @@ -389,8 +407,16 @@ const VoteIconWrapper = styled.div`

const VoteTitle = styled.h3`
font: var(--header-sm);
max-width: var(--title-max-width);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@media ${tabletAndUnder} {
max-width: unset;
white-space: unset;
overflow: unset;
text-overflow: unset;
margin-bottom: 5px;
}
`;
Expand All @@ -400,21 +426,33 @@ const VoteOrigin = styled.h4`
color: var(--black-opacity-50);
`;

const VoteInput = styled.td``;
const VoteInput = styled.td`
min-width: calc(240px + 2.5vw);
padding-right: 2.5vw;
@media ${tabletAndUnder} {
padding: 0;
min-width: unset;
}
`;

const VoteOutputText = styled.td`
font: var(--text-md);
min-width: calc(80px + 2.5vw);
padding-right: 2.5vw;
@media ${tabletAndUnder} {
display: flex;
justify-content: space-between;
}
`;

const YourVote = styled(VoteOutputText)``;
const YourVote = styled(VoteOutputText)`
white-space: nowrap;
`;

const CorrectVote = styled(VoteOutputText)`
padding-left: 30px;
white-space: nowrap;
@media ${tabletAndUnder} {
padding-left: 0;
Expand All @@ -431,6 +469,7 @@ const VoteLabel = styled.span`

const VoteStatusWrapper = styled.td`
font: var(--text-md);
padding-right: 2.5vw;
@media ${tabletAndUnder} {
display: flex;
Expand All @@ -442,14 +481,17 @@ const VoteStatus = styled.div`
display: flex;
align-items: center;
gap: 10px;
margin-left: 30px;
min-width: max-content;
white-space: nowrap;
@media ${tabletAndUnder} {
margin-left: 0;
}
`;

const MoreDetailsWrapper = styled.td`
padding-right: 2.5vw;
@media ${tabletAndUnder} {
padding-top: 10px;
border-top: 1px solid var(--border-color);
Expand All @@ -459,7 +501,6 @@ const MoreDetailsWrapper = styled.td`
const MoreDetails = styled.div`
width: fit-content;
margin-left: auto;
margin-right: 30px;
@media ${tabletAndUnder} {
margin-left: unset;
Expand Down
10 changes: 0 additions & 10 deletions components/VotesList/VotesTableHeadings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,4 @@ const Wrapper = styled.tr``;
const Heading = styled.th`
text-align: left;
font: var(--text-sm);
&:first-child {
width: 45%;
padding-left: 30px;
}
&:nth-child(2) {
width: 240px;
}
&:nth-child(3) {
padding-left: 30px;
}
`;
2 changes: 1 addition & 1 deletion components/pages/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const PageOuterWrapper = styled.div`

export const PageInnerWrapper = styled.div`
max-width: var(--page-width);
padding-inline: 45px;
padding-inline: clamp(10px, 45px, 4vw);
padding-block: 45px;
margin-inline: auto;
Expand Down
96 changes: 92 additions & 4 deletions stories/Pages/VotePage/VotePage.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,99 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { Meta, Story } from "@storybook/react";
import {
defaultVotesContextState,
defaultVoteTimingContextState,
VotesContext,
VoteTimingContext,
} from "contexts";
import VotePage from "pages";
import {
voteCommitted,
voteCommittedButNotRevealed,
voteRevealed,
voteWithCorrectVoteWithoutUserVote,
voteWithCorrectVoteWithUserVote,
voteWithoutUserVote,
} from "stories/mocks/votes";
import { ActivityStatusT, VoteT } from "types";

interface StoryProps {
phase: "commit" | "reveal";
activeVotes: VoteT[];
upcomingVotes: VoteT[];
pastVotes: VoteT[];
activityStatus: ActivityStatusT;
}

export default {
title: "Pages/Vote Page/VotePage",
component: VotePage,
} as ComponentMeta<typeof VotePage>;
} as Meta<StoryProps>;

const Template: Story<StoryProps> = (args) => {
const mockVoteTimingContextState = {
...defaultVoteTimingContextState,
phase: args.phase ?? "commit",
roundId: 1,
};

const mockVotesContextState = {
...defaultVotesContextState,
getActiveVotes: () => args.activeVotes ?? [],
getUpcomingVotes: () => args.upcomingVotes ?? [],
getPastVotes: () => args.pastVotes ?? [],
getActivityStatus: () => args.activityStatus ?? "past",
};

return (
<VoteTimingContext.Provider value={mockVoteTimingContextState}>
<VotesContext.Provider value={mockVotesContextState}>
<VotePage />
</VotesContext.Provider>
</VoteTimingContext.Provider>
);
};

export const ActiveCommit = Template.bind({});
ActiveCommit.args = {
activityStatus: "active",
phase: "commit",
activeVotes: [
voteWithoutUserVote,
voteCommitted,
voteWithoutUserVote,
voteCommitted,
],
};

export const ActiveReveal = Template.bind({});
ActiveReveal.args = {
activityStatus: "active",
phase: "reveal",
activeVotes: [
voteCommittedButNotRevealed,
voteRevealed,
voteCommittedButNotRevealed,
voteRevealed,
],
};

const Template: ComponentStory<typeof VotePage> = () => <VotePage />;
export const Upcoming = Template.bind({});
Upcoming.args = {
activityStatus: "upcoming",
upcomingVotes: [
voteWithoutUserVote,
voteWithoutUserVote,
voteWithoutUserVote,
],
};

export const Default = Template.bind({});
export const Past = Template.bind({});
Past.args = {
activityStatus: "past",
pastVotes: [
voteWithCorrectVoteWithUserVote,
voteWithCorrectVoteWithoutUserVote,
voteWithCorrectVoteWithUserVote,
voteWithCorrectVoteWithoutUserVote,
],
};
3 changes: 2 additions & 1 deletion stories/mocks/votes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const voteWithoutUserVote = {
isCommitted: false,
commitHash: undefined,
isRolled: false,
title: "SuperUMAn DAO KPI Options funding proposal",
title:
"SuperUMAn DAO KPI Options funding proposal and a bunch of extra text that will presumably trigger an overflow",
origin: "UMA" as const,
description: "Some description",
transactionHash: "0x1234567890",
Expand Down

0 comments on commit 91ca52e

Please sign in to comment.