diff --git a/config/postcss.config.js b/config/postcss.config.js index 4de2da6b2..578f539fb 100644 --- a/config/postcss.config.js +++ b/config/postcss.config.js @@ -1,3 +1,6 @@ +// Allow importing typescript files. +require("ts-node/register"); + const precss = require("precss"); const autoprefixer = require("autoprefixer"); const fontMagician = require("postcss-font-magician"); @@ -8,7 +11,7 @@ const flexbugsFixes = require("postcss-flexbugs-fixes"); const paths = require("./paths"); delete require.cache[paths.appThemeVariables]; -const variables = require(paths.appThemeVariables); +const variables = require(paths.appThemeVariables).default; const flatKebabVariables = mapKeys( flat(variables, { delimiter: "-" }), (_, k) => kebabCase(k) diff --git a/src/core/client/stream/components/App.tsx b/src/core/client/stream/components/App.tsx index eb59b588e..1dd3ce496 100644 --- a/src/core/client/stream/components/App.tsx +++ b/src/core/client/stream/components/App.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import { StatelessComponent } from "react"; -import { Center } from "talk-ui/components"; +import { Flex } from "talk-ui/components"; import StreamContainer from "../containers/StreamContainer"; @@ -12,9 +12,9 @@ export interface AppProps { const App: StatelessComponent = props => { if (props.asset) { return ( -
+ -
+ ); } return
Asset not found
; diff --git a/src/core/client/stream/test/__snapshots__/loadMore.spec.tsx.snap b/src/core/client/stream/test/__snapshots__/loadMore.spec.tsx.snap index 8b37696d2..a9a36d747 100644 --- a/src/core/client/stream/test/__snapshots__/loadMore.spec.tsx.snap +++ b/src/core/client/stream/test/__snapshots__/loadMore.spec.tsx.snap @@ -2,7 +2,7 @@ exports[`loads more comments 1`] = `

{ - const props = { + const props: PropTypesOf = { justifyContent: "center", alignItems: "center", + direction: "row", }; const wrapper = shallow( diff --git a/src/core/client/ui/components/Flex/Flex.tsx b/src/core/client/ui/components/Flex/Flex.tsx index b2e0e69ea..3dab50168 100644 --- a/src/core/client/ui/components/Flex/Flex.tsx +++ b/src/core/client/ui/components/Flex/Flex.tsx @@ -15,24 +15,29 @@ interface InnerProps { | "space-between" | "space-evenly"; alignItems?: "flex-start" | "flex-end" | "center" | "baseline" | "stretch"; + direction?: "row" | "column" | "row-reverse" | "column-reverse"; } const Flex: StatelessComponent = props => { - const { justifyContent, alignItems } = props; + const { justifyContent, alignItems, direction, ...rest } = props; const classObject: Record = {}; if (justifyContent) { - classObject[`justify${pascalCase(justifyContent)}`] = true; + classObject[(styles as any)[`justify${pascalCase(justifyContent)}`]] = true; } if (alignItems) { - classObject[`align${pascalCase(alignItems)}`] = true; + classObject[(styles as any)[`align${pascalCase(alignItems)}`]] = true; + } + + if (direction) { + classObject[(styles as any)[`direction${pascalCase(direction)}`]] = true; } const classNames: string = cn(styles.root, classObject); - return
; + return
; }; export default Flex; diff --git a/src/core/client/ui/components/Flex/__snapshots__/Flex.spec.tsx.snap b/src/core/client/ui/components/Flex/__snapshots__/Flex.spec.tsx.snap index e9dd085c5..90ef93c13 100644 --- a/src/core/client/ui/components/Flex/__snapshots__/Flex.spec.tsx.snap +++ b/src/core/client/ui/components/Flex/__snapshots__/Flex.spec.tsx.snap @@ -2,6 +2,10 @@ exports[`renders correctly 1`] = `
+ className="Flex-root Flex-justifyCenter Flex-alignCenter Flex-directionRow" +> +
+ Hello World +
+
`; diff --git a/src/core/client/ui/components/MatchMedia/MatchMedia.spec.tsx b/src/core/client/ui/components/MatchMedia/MatchMedia.spec.tsx index 527e5921f..3c4879015 100644 --- a/src/core/client/ui/components/MatchMedia/MatchMedia.spec.tsx +++ b/src/core/client/ui/components/MatchMedia/MatchMedia.spec.tsx @@ -1,31 +1,27 @@ import { shallow } from "enzyme"; import React from "react"; +import { PropTypesOf } from "talk-ui/types"; + import MatchMedia from "./MatchMedia"; it("renders correctly", () => { - const props = { + const props: PropTypesOf = { minWidth: "xs", maxWidth: "sm", component: "div", screen: true, + children:
Hello World
, }; - const wrapper = shallow( - -
Hello World
-
- ); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); it("map new speech prop to older aural prop", () => { - const props = { + const props: PropTypesOf = { speech: true, + children:
Hello World
, }; - const wrapper = shallow( - -
Hello World
-
- ); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); diff --git a/src/core/client/ui/components/MatchMedia/MediaMedia.tsx b/src/core/client/ui/components/MatchMedia/MatchMedia.tsx similarity index 58% rename from src/core/client/ui/components/MatchMedia/MediaMedia.tsx rename to src/core/client/ui/components/MatchMedia/MatchMedia.tsx index ebd4ed210..80f692ddc 100644 --- a/src/core/client/ui/components/MatchMedia/MediaMedia.tsx +++ b/src/core/client/ui/components/MatchMedia/MatchMedia.tsx @@ -2,9 +2,13 @@ import React from "react"; import { ReactNode, StatelessComponent } from "react"; import Responsive from "react-responsive"; +import theme from "../../theme/variables"; + +type Breakpoints = keyof typeof theme.breakpoints; + interface InnerProps { - minWidth?: string; - maxWidth?: string; + minWidth?: Breakpoints; + maxWidth?: Breakpoints; children: ReactNode; className?: string; component?: @@ -21,8 +25,13 @@ interface InnerProps { const MatchMedia: StatelessComponent = props => { // TODO: Temporarily map newer speech to older aural type until // react-responsive supports the speech prop. - const { speech, ...rest } = props; - return ; + const { speech, minWidth, maxWidth, ...rest } = props; + const mapped = { + aural: speech, + minWidth: minWidth ? theme.breakpoints[minWidth] : undefined, + maxWidth: maxWidth ? theme.breakpoints[maxWidth] : undefined, + }; + return ; }; export default MatchMedia; diff --git a/src/core/client/ui/components/MatchMedia/__snapshots__/MatchMedia.spec.tsx.snap b/src/core/client/ui/components/MatchMedia/__snapshots__/MatchMedia.spec.tsx.snap index 4ce9b2fd8..083e70f5a 100644 --- a/src/core/client/ui/components/MatchMedia/__snapshots__/MatchMedia.spec.tsx.snap +++ b/src/core/client/ui/components/MatchMedia/__snapshots__/MatchMedia.spec.tsx.snap @@ -14,8 +14,8 @@ exports[`map new speech prop to older aural prop 1`] = ` exports[`renders correctly 1`] = ` diff --git a/src/core/client/ui/components/index.ts b/src/core/client/ui/components/index.ts index 54643cb2a..9052f7fee 100644 --- a/src/core/client/ui/components/index.ts +++ b/src/core/client/ui/components/index.ts @@ -2,3 +2,5 @@ export { default as BaseButton } from "./BaseButton"; export { default as Button } from "./Button"; export { default as Center } from "./Center"; export { default as Typography } from "./Typography"; +export { default as Flex } from "./Flex"; +export { default as MatchMedia } from "./MatchMedia"; diff --git a/src/core/client/ui/theme/variables.ts b/src/core/client/ui/theme/variables.ts index 2e9499883..a0966ec9e 100644 --- a/src/core/client/ui/theme/variables.ts +++ b/src/core/client/ui/theme/variables.ts @@ -70,13 +70,12 @@ const variables = { fontWeightMedium: 550, /* Breakpoints */ breakpoints: { - xs: 0, - sm: 320, - md: 640, - lg: 1024, - xl: 1400, - xxl: 1600, + xs: 320, + sm: 640, + md: 1024, + lg: 1400, + xl: 1600, }, }; -module.exports = variables; +export default variables;