From c60c4b3ef8a793ff6fce48411522f52f2a42d28f Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 12 Jul 2018 18:38:49 -0300 Subject: [PATCH] Make design responsive --- src/core/client/stream/components/Comment.css | 10 ---- src/core/client/stream/components/Comment.tsx | 19 +++----- .../stream/components/CommentTimestamp.css | 3 ++ .../stream/components/CommentTimestamp.tsx | 16 +++++++ .../stream/components/CommentTopBar.css | 3 ++ .../stream/components/CommentTopBar.tsx | 32 +++++++++++++ src/core/client/stream/components/Indent.css | 2 +- .../stream/components/PostCommentForm.css | 2 +- .../client/stream/components/ReplyList.tsx | 13 +++-- src/core/client/stream/components/Stream.tsx | 18 ++++--- .../client/stream/components/Username.css | 2 +- .../client/stream/components/Username.tsx | 20 ++++++-- .../stream/containers/ReplyListContainer.tsx | 5 +- src/core/client/ui/components/Flex/Flex.css | 48 +++++++++++++++++++ src/core/client/ui/components/Flex/Flex.tsx | 20 ++++++-- .../ui/components/Typography/Typography.css | 6 ++- .../ui/components/Typography/Typography.tsx | 4 +- src/core/client/ui/shared/typography.css | 9 ++++ src/core/client/ui/theme/variables.css | 4 +- 19 files changed, 190 insertions(+), 46 deletions(-) delete mode 100644 src/core/client/stream/components/Comment.css create mode 100644 src/core/client/stream/components/CommentTimestamp.css create mode 100644 src/core/client/stream/components/CommentTimestamp.tsx create mode 100644 src/core/client/stream/components/CommentTopBar.css create mode 100644 src/core/client/stream/components/CommentTopBar.tsx diff --git a/src/core/client/stream/components/Comment.css b/src/core/client/stream/components/Comment.css deleted file mode 100644 index 77dc9d88d..000000000 --- a/src/core/client/stream/components/Comment.css +++ /dev/null @@ -1,10 +0,0 @@ -.root { -} - -.gutterBottom { - margin-bottom: calc(1px * var(--spacing-unit)); -} - -.topBar { - margin-bottom: calc(0.5px * var(--spacing-unit)); -} diff --git a/src/core/client/stream/components/Comment.tsx b/src/core/client/stream/components/Comment.tsx index dea610494..ab9c0348e 100644 --- a/src/core/client/stream/components/Comment.tsx +++ b/src/core/client/stream/components/Comment.tsx @@ -1,32 +1,27 @@ -import cn from "classnames"; import React from "react"; import { StatelessComponent } from "react"; -import { RelativeTime, Typography } from "talk-ui/components"; +import { Typography } from "talk-ui/components"; -import * as styles from "./Comment.css"; +import CommentTimestamp from "./CommentTimestamp"; +import CommentTopBar from "./CommentTopBar"; import Username from "./Username"; export interface CommentProps { - className?: string; author: { username: string; } | null; body: string | null; createdAt: string; - gutterBottom?: boolean; } const Comment: StatelessComponent = props => { - const rootClassName = cn(styles.root, props.className, { - [styles.gutterBottom]: props.gutterBottom, - }); return ( -
-
+
+ {props.author && {props.author.username}} - -
+ {props.createdAt} + {props.body}
); diff --git a/src/core/client/stream/components/CommentTimestamp.css b/src/core/client/stream/components/CommentTimestamp.css new file mode 100644 index 000000000..f2d263ad4 --- /dev/null +++ b/src/core/client/stream/components/CommentTimestamp.css @@ -0,0 +1,3 @@ +.root { + composes: timestamp from "talk-ui/shared/typography.css"; +} diff --git a/src/core/client/stream/components/CommentTimestamp.tsx b/src/core/client/stream/components/CommentTimestamp.tsx new file mode 100644 index 000000000..bd4ddef17 --- /dev/null +++ b/src/core/client/stream/components/CommentTimestamp.tsx @@ -0,0 +1,16 @@ +import React from "react"; +import { StatelessComponent } from "react"; + +import { RelativeTime } from "talk-ui/components"; + +import * as styles from "./CommentTimestamp.css"; + +export interface CommentTimestampProps { + children: string; +} + +const CommentTimestamp: StatelessComponent = props => ( + +); + +export default CommentTimestamp; diff --git a/src/core/client/stream/components/CommentTopBar.css b/src/core/client/stream/components/CommentTopBar.css new file mode 100644 index 000000000..dff9c8a74 --- /dev/null +++ b/src/core/client/stream/components/CommentTopBar.css @@ -0,0 +1,3 @@ +.root { + margin-bottom: calc(0.5 * var(--spacing-unit)); +} diff --git a/src/core/client/stream/components/CommentTopBar.tsx b/src/core/client/stream/components/CommentTopBar.tsx new file mode 100644 index 000000000..84915ef4c --- /dev/null +++ b/src/core/client/stream/components/CommentTopBar.tsx @@ -0,0 +1,32 @@ +import cn from "classnames"; +import React from "react"; +import { StatelessComponent } from "react"; + +import { Flex, MatchMedia } from "talk-ui/components"; + +import * as styles from "./CommentTopBar.css"; + +export interface CommentTopBarProps { + className?: string; + children: React.ReactNode; +} + +const CommentTopBar: StatelessComponent = props => { + const rootClassName = cn(styles.root, props.className); + return ( + + {matches => ( + + {props.children} + + )} + + ); +}; + +export default CommentTopBar; diff --git a/src/core/client/stream/components/Indent.css b/src/core/client/stream/components/Indent.css index 19100de68..c675b03a6 100644 --- a/src/core/client/stream/components/Indent.css +++ b/src/core/client/stream/components/Indent.css @@ -1,6 +1,6 @@ .root { border-left: 3px solid; - padding-left: calc(1px * var(--spacing-unit)); + padding-left: var(--spacing-unit); } .level0 { diff --git a/src/core/client/stream/components/PostCommentForm.css b/src/core/client/stream/components/PostCommentForm.css index 2e9cdcc9e..df045285d 100644 --- a/src/core/client/stream/components/PostCommentForm.css +++ b/src/core/client/stream/components/PostCommentForm.css @@ -5,7 +5,7 @@ height: 100px; width: 100%; box-sizing: border-box; - margin-bottom: calc(1px * var(--spacing-unit)); + margin-bottom: var(--spacing-unit); } .postButtonContainer { diff --git a/src/core/client/stream/components/ReplyList.tsx b/src/core/client/stream/components/ReplyList.tsx index ec366771c..17ad32ed2 100644 --- a/src/core/client/stream/components/ReplyList.tsx +++ b/src/core/client/stream/components/ReplyList.tsx @@ -2,7 +2,7 @@ import { Localized } from "fluent-react/compat"; import * as React from "react"; import { StatelessComponent } from "react"; -import { Button } from "talk-ui/components"; +import { Button, Flex } from "talk-ui/components"; import CommentContainer from "../containers/CommentContainer"; import Indent from "./Indent"; @@ -18,9 +18,14 @@ export interface ReplyListProps { const ReplyList: StatelessComponent = props => { return ( -
+ {props.comments.map(comment => ( - + ))} {props.hasMore && ( @@ -37,7 +42,7 @@ const ReplyList: StatelessComponent = props => { )} -
+
); }; diff --git a/src/core/client/stream/components/Stream.tsx b/src/core/client/stream/components/Stream.tsx index f6d39940e..da55050f5 100644 --- a/src/core/client/stream/components/Stream.tsx +++ b/src/core/client/stream/components/Stream.tsx @@ -2,7 +2,7 @@ import { Localized } from "fluent-react/compat"; import * as React from "react"; import { StatelessComponent } from "react"; -import { Button } from "talk-ui/components"; +import { Button, Flex } from "talk-ui/components"; import CommentContainer from "../containers/CommentContainer"; import PostCommentFormContainer from "../containers/PostCommentFormContainer"; @@ -24,12 +24,18 @@ const Stream: StatelessComponent = props => {
-
+ {props.comments.map(comment => ( -
- + + -
+
))} {props.hasMore && ( @@ -46,7 +52,7 @@ const Stream: StatelessComponent = props => { )} -
+
); }; diff --git a/src/core/client/stream/components/Username.css b/src/core/client/stream/components/Username.css index 9cb1baa15..e2dd79a8e 100644 --- a/src/core/client/stream/components/Username.css +++ b/src/core/client/stream/components/Username.css @@ -1,3 +1,3 @@ .root { - composes: heading4 from "talk-ui/shared/typography.css"; + line-height: 1; } diff --git a/src/core/client/stream/components/Username.tsx b/src/core/client/stream/components/Username.tsx index 117ebdb3d..ada04c8ec 100644 --- a/src/core/client/stream/components/Username.tsx +++ b/src/core/client/stream/components/Username.tsx @@ -1,14 +1,28 @@ import React from "react"; import { StatelessComponent } from "react"; +import { MatchMedia, Typography } from "talk-ui/components"; + import * as styles from "./Username.css"; -export interface CommentProps { +export interface UsernameProps { children: string; } -const Username: StatelessComponent = props => { - return {props.children}; +const Username: StatelessComponent = props => { + return ( + + {matches => ( + + {props.children} + + )} + + ); }; export default Username; diff --git a/src/core/client/stream/containers/ReplyListContainer.tsx b/src/core/client/stream/containers/ReplyListContainer.tsx index d147edb1c..48db9645a 100644 --- a/src/core/client/stream/containers/ReplyListContainer.tsx +++ b/src/core/client/stream/containers/ReplyListContainer.tsx @@ -22,7 +22,10 @@ export class ReplyListContainer extends React.Component { }; public render() { - if (this.props.comment.replies === null) { + if ( + this.props.comment.replies === null || + this.props.comment.replies.edges.length === 0 + ) { return null; } const comments = this.props.comment.replies.edges.map(edge => edge.node); diff --git a/src/core/client/ui/components/Flex/Flex.css b/src/core/client/ui/components/Flex/Flex.css index 45398843b..13cb05be5 100644 --- a/src/core/client/ui/components/Flex/Flex.css +++ b/src/core/client/ui/components/Flex/Flex.css @@ -2,6 +2,54 @@ display: flex; } +.halfItemGutter { + & > * { + margin: 0 calc(0.5 * var(--spacing-unit)) 0 0; + } + &.directionRowReverse { + & > * { + margin: 0 0 0 calc(0.5 * var(--spacing-unit)); + } + } + &.directionColumn { + & > * { + margin: 0 0 calc(0.5 * var(--spacing-unit)) 0; + } + } + &.directionColumnReverese { + & > * { + margin: calc(0.5 * var(--spacing-unit)) 0 0 0; + } + } + & > *:last-child { + margin: 0; + } +} + +.itemGutter { + & > * { + margin: 0 var(--spacing-unit) 0 0; + } + &.directionRowReverse { + & > * { + margin: 0 0 0 var(--spacing-unit); + } + } + &.directionColumn { + & > * { + margin: 0 0 var(--spacing-unit) 0; + } + } + &.directionColumnReverese { + & > * { + margin: var(--spacing-unit) 0 0 0; + } + } + & > *:last-child { + margin: 0; + } +} + .justifyFlexStart { justify-content: flex-start; } diff --git a/src/core/client/ui/components/Flex/Flex.tsx b/src/core/client/ui/components/Flex/Flex.tsx index 3dab50168..bfba06d05 100644 --- a/src/core/client/ui/components/Flex/Flex.tsx +++ b/src/core/client/ui/components/Flex/Flex.tsx @@ -7,6 +7,8 @@ import { pascalCase } from "talk-common/utils"; import * as styles from "./Flex.css"; interface InnerProps { + id?: string; + role?: string; justifyContent?: | "flex-start" | "flex-end" @@ -16,12 +18,24 @@ interface InnerProps { | "space-evenly"; alignItems?: "flex-start" | "flex-end" | "center" | "baseline" | "stretch"; direction?: "row" | "column" | "row-reverse" | "column-reverse"; + itemGutter?: boolean | "half"; + className?: string; } const Flex: StatelessComponent = props => { - const { justifyContent, alignItems, direction, ...rest } = props; + const { + className, + justifyContent, + alignItems, + direction, + itemGutter, + ...rest + } = props; - const classObject: Record = {}; + const classObject: Record = { + [styles.itemGutter]: itemGutter === true, + [styles.halfItemGutter]: itemGutter === "half", + }; if (justifyContent) { classObject[(styles as any)[`justify${pascalCase(justifyContent)}`]] = true; @@ -35,7 +49,7 @@ const Flex: StatelessComponent = props => { classObject[(styles as any)[`direction${pascalCase(direction)}`]] = true; } - const classNames: string = cn(styles.root, classObject); + const classNames: string = cn(styles.root, className, classObject); return
; }; diff --git a/src/core/client/ui/components/Typography/Typography.css b/src/core/client/ui/components/Typography/Typography.css index da31711e9..a3c19a400 100644 --- a/src/core/client/ui/components/Typography/Typography.css +++ b/src/core/client/ui/components/Typography/Typography.css @@ -43,6 +43,10 @@ composes: overline from "talk-ui/shared/typography.css"; } +.timestamp { + composes: timestamp from "talk-ui/shared/typography.css"; +} + .alignLeft { text-align: left; } @@ -70,7 +74,7 @@ } .paragraph { - margin-bottom: calc(1px * var(--spacing-unit)); + margin-bottom: var(--spacing-unit); } .colorInherit { diff --git a/src/core/client/ui/components/Typography/Typography.tsx b/src/core/client/ui/components/Typography/Typography.tsx index 7292a672f..a5e45912d 100644 --- a/src/core/client/ui/components/Typography/Typography.tsx +++ b/src/core/client/ui/components/Typography/Typography.tsx @@ -16,7 +16,8 @@ type Variant = | "subtitle2" | "body1" | "body2" - | "button"; + | "button" + | "timestamp"; // Based on Typography Component of Material UI. // https://github.com/mui-org/material-ui/blob/303199d39b42a321d28347d8440d69166f872f27/packages/material-ui/src/Typography/Typography.js @@ -129,6 +130,7 @@ Typography.defaultProps = { subtitle2: "h3", body1: "p", body2: "aside", + timestamp: "span", }, noWrap: false, paragraph: false, diff --git a/src/core/client/ui/shared/typography.css b/src/core/client/ui/shared/typography.css index cd94c867d..3cb483cd2 100644 --- a/src/core/client/ui/shared/typography.css +++ b/src/core/client/ui/shared/typography.css @@ -61,3 +61,12 @@ .overline { } + +.timestamp { + color: var(--palette-text-secondary); + font-family: "Source Sans Pro"; + font-weight: var(--font-weight-medium); + font-size: 14px; + line-height: calc(18em / 16); + letter-spacing: calc(0.2em / 16); +} diff --git a/src/core/client/ui/theme/variables.css b/src/core/client/ui/theme/variables.css index 687417bf4..ad0215b77 100644 --- a/src/core/client/ui/theme/variables.css +++ b/src/core/client/ui/theme/variables.css @@ -6,11 +6,11 @@ */ :root { - --spacing-unit: var(--spacing-unit-small); + --spacing-unit: calc(1px * var(--spacing-unit-small)); } @media (min-width: $breakpoints-xs) { :root { - --spacing-unit: var(--spacing-unit-large); + --spacing-unit: calc(1px * var(--spacing-unit-large)); } }