From cf886f706cdab4d800de86253edcc52e707da3c3 Mon Sep 17 00:00:00 2001 From: Devin Fee Date: Fri, 4 Jan 2019 21:49:17 -0800 Subject: [PATCH] fixed prop inference using 'as' --- docs/stories/grid/tile.story.tsx | 804 +++++++++--------- package.json | 2 +- .../__snapshots__/index.test.ts.snap | 2 - src/base/exotic.ts | 13 +- src/elements/notification/notification.tsx | 1 + src/grid/tiles/__tests__/tile.test.tsx | 25 - src/grid/tiles/tile.tsx | 12 +- 7 files changed, 417 insertions(+), 442 deletions(-) diff --git a/docs/stories/grid/tile.story.tsx b/docs/stories/grid/tile.story.tsx index ad9cdd14..5b63553f 100644 --- a/docs/stories/grid/tile.story.tsx +++ b/docs/stories/grid/tile.story.tsx @@ -1,39 +1,113 @@ import { storiesOf } from "@storybook/react"; import React from "react"; -import { Content, Image, Title } from "src/elements"; +import { Box, Content, Image, Notification, Title } from "src/elements"; import { Tile } from "src/grid"; import { Section } from "src/layout"; -storiesOf("Grid/Tiles", module).add("Default", () => ( -
- - - - - - Vertical... - Top tile +storiesOf("Grid/Tiles", module) + .add("Default", () => ( +
+ + + + + + Vertical... + Top tile + + + Tiles... + Bottom Tile... + - - Tiles... - Bottom Tile... + + + Middle Tile... + With an image + + + + - - Middle Tile... - With an image - - - + + Wide tile + Aligned with the right tile + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin + ornare magna eros, eu pellentesque tortor vestibulum ut. + Maecenas non massa sem. Etiam finibus odio quis feugiat + facilisis. +

+
- - Wide tile - Aligned with the right tile + + + Tall tile + With even more content + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam + semper diam at erat pulvinar, at pulvinar felis blandit. + Vestibulum volutpat tellus diam, consequat gravida libero + rhoncus ut. Morbi maximus, leo sit amet vehicula eleifend, + nunc dui porta orci, quis semper odio felis ut quam. +

+

+ Suspendisse varius ligula in molestie lacinia. Maecenas varius + eget ligula a sagittis. Pellentesque interdum, nisl nec + interdum maximus, augue diam porttitor lorem, et sollicitudin + felis neque sit amet erat. Maecenas imperdiet felis nisi, + fringilla luctus felis hendrerit sit amet. Aenean vitae + gravida diam, finibus dignissim turpis. Sed eget varius + ligula, at volutpat tortor. +

+

+ Integer sollicitudin, tortor a mattis commodo, velit urna + rhoncus erat, vitae congue lectus dolor consequat libero. + Donec leo ligula, maximus et pellentesque sed, gravida a + metus. Cras ullamcorper a nunc ac porta. Aliquam ut aliquet + lacus, quis faucibus libero. Quisque non semper leo. +

+
+
+
+
+
+
+ )) + // tslint:disable-next-line: max-func-body-length + .add("3 columns", () => ( +
+ + + + Hello world + + What is up? + + + + + + Foo + + Bar + + + + + + Third column + + With some content +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin @@ -45,392 +119,320 @@ storiesOf("Grid/Tiles", module).add("Default", () => ( - - - - Tall tile - With even more content + + + + + + Vertical titles + + Top box + + + + Vertical titles + + Bottom box + + + + + + Middle box + + With an image + + + + + + + + + + Wide column + + Aligned with the right column + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin + ornare magna eros, eu pellentesque tortor vestibulum ut. + Maecenas non massa sem. Etiam finibus odio quis feugiat + facilisis. +

+
+
+
+
+ + + + Tall column + + With even more content + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam + semper diam at erat pulvinar, at pulvinar felis blandit. + Vestibulum volutpat tellus diam, consequat gravida libero + rhoncus ut. Morbi maximus, leo sit amet vehicula eleifend, + nunc dui porta orci, quis semper odio felis ut quam. +

+

+ Suspendisse varius ligula in molestie lacinia. Maecenas varius + eget ligula a sagittis. Pellentesque interdum, nisl nec + interdum maximus, augue diam porttitor lorem, et sollicitudin + felis neque sit amet erat. Maecenas imperdiet felis nisi, + fringilla luctus felis hendrerit sit amet. Aenean vitae + gravida diam, finibus dignissim turpis. Sed eget varius + ligula, at volutpat tortor. +

+

+ Integer sollicitudin, tortor a mattis commodo, velit urna + rhoncus erat, vitae congue lectus dolor consequat libero. + Donec leo ligula, maximus et pellentesque sed, gravida a + metus. Cras ullamcorper a nunc ac porta. Aliquam ut aliquet + lacus, quis faucibus libero. Quisque non semper leo. +

+
+
+
+
+ + + + + Side column + + With some content +

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam - semper diam at erat pulvinar, at pulvinar felis blandit. - Vestibulum volutpat tellus diam, consequat gravida libero - rhoncus ut. Morbi maximus, leo sit amet vehicula eleifend, nunc - dui porta orci, quis semper odio felis ut quam. -

-

- Suspendisse varius ligula in molestie lacinia. Maecenas varius - eget ligula a sagittis. Pellentesque interdum, nisl nec interdum - maximus, augue diam porttitor lorem, et sollicitudin felis neque - sit amet erat. Maecenas imperdiet felis nisi, fringilla luctus - felis hendrerit sit amet. Aenean vitae gravida diam, finibus - dignissim turpis. Sed eget varius ligula, at volutpat tortor. + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin + ornare magna eros, eu pellentesque tortor vestibulum ut. + Maecenas non massa sem. Etiam finibus odio quis feugiat + facilisis.

+
+
+
+ + + Main column + + With some content + +

- Integer sollicitudin, tortor a mattis commodo, velit urna - rhoncus erat, vitae congue lectus dolor consequat libero. Donec - leo ligula, maximus et pellentesque sed, gravida a metus. Cras - ullamcorper a nunc ac porta. Aliquam ut aliquet lacus, quis - faucibus libero. Quisque non semper leo. + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin + ornare magna eros, eu pellentesque tortor vestibulum ut. + Maecenas non massa sem. Etiam finibus odio quis feugiat + facilisis.

- +
+
+
+
+ )) + // tslint:disable-next-line: max-func-body-length + .add("4 columns", () => ( +
+ + + + One + + Subtitle + + + + + + Two + + Subtitle + + + + + + Three + + Subtitle + + + + + + Four + + Subtitle + + - -
-)); -// // tslint:disable-next-line: max-func-body-length -// .add("3 columns", () => ( -//
-// -// -// -// Hello world -// -// What is up? -// -// -// -// -// -// Foo -// -// Bar -// -// -// -// -// -// Third column -// -// With some content -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin -// ornare magna eros, eu pellentesque tortor vestibulum ut. -// Maecenas non massa sem. Etiam finibus odio quis feugiat -// facilisis. -//

-//
-//
-//
-//
-// -// -// -// -// -// Vertical titles -// -// Top box -// -// -// -// Vertical titles -// -// Bottom box -// -// -// -// -// -// Middle box -// -// With an image -// -// -// -// -// -// -// -// -// -// Wide column -// -// Aligned with the right column -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin -// ornare magna eros, eu pellentesque tortor vestibulum ut. -// Maecenas non massa sem. Etiam finibus odio quis feugiat -// facilisis. -//

-//
-//
-//
-//
-// -// -// -// Tall column -// -// With even more content -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam -// semper diam at erat pulvinar, at pulvinar felis blandit. -// Vestibulum volutpat tellus diam, consequat gravida libero -// rhoncus ut. Morbi maximus, leo sit amet vehicula eleifend, -// nunc dui porta orci, quis semper odio felis ut quam. -//

-//

-// Suspendisse varius ligula in molestie lacinia. Maecenas varius -// eget ligula a sagittis. Pellentesque interdum, nisl nec -// interdum maximus, augue diam porttitor lorem, et sollicitudin -// felis neque sit amet erat. Maecenas imperdiet felis nisi, -// fringilla luctus felis hendrerit sit amet. Aenean vitae -// gravida diam, finibus dignissim turpis. Sed eget varius -// ligula, at volutpat tortor. -//

-//

-// Integer sollicitudin, tortor a mattis commodo, velit urna -// rhoncus erat, vitae congue lectus dolor consequat libero. -// Donec leo ligula, maximus et pellentesque sed, gravida a -// metus. Cras ullamcorper a nunc ac porta. Aliquam ut aliquet -// lacus, quis faucibus libero. Quisque non semper leo. -//

-//
-//
-//
-//
-//
-// -// -// -// Side column -// -// With some content -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin -// ornare magna eros, eu pellentesque tortor vestibulum ut. -// Maecenas non massa sem. Etiam finibus odio quis feugiat -// facilisis. -//

-//
-//
-//
-// -// -// Main column -// -// With some content -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin -// ornare magna eros, eu pellentesque tortor vestibulum ut. -// Maecenas non massa sem. Etiam finibus odio quis feugiat -// facilisis. -//

-//
-//
-//
-//
-//
-// )) -// // tslint:disable-next-line: max-func-body-length -// .add("4 columns", () => ( -//
-// -// -// -// One -// -// Subtitle -// -// -// -// -// -// Two -// -// Subtitle -// -// -// -// -// -// Three -// -// Subtitle -// -// -// -// -// -// Four -// -// Subtitle -// -// -// -// -// -// -// -// -// -// Five -// -// Subtitle -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. -// Etiam semper diam at erat pulvinar, at pulvinar felis -// blandit. Vestibulum volutpat tellus diam, consequat gravida -// libero rhoncus ut. Morbi maximus, leo sit amet vehicula -// eleifend, nunc dui porta orci, quis semper odio felis ut -// quam. -//

-//
-//
-//
-// -// -// -// -// Six -// -// Subtitle -// -// -// -// -// -// Seven -// -// Subtitle -// -// -// -// -// -// -// Eight -// -// Subtitle -// -// -// -// -//
-// -// -// -// Nine -// -// Subtitle -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. -// Proin ornare magna eros, eu pellentesque tortor vestibulum -// ut. Maecenas non massa sem. Etiam finibus odio quis feugiat -// facilisis. -//

-//
-//
-//
-// -// -// Ten -// -// Subtitle -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. -// Proin ornare magna eros, eu pellentesque tortor vestibulum -// ut. Maecenas non massa sem. Etiam finibus odio quis feugiat -// facilisis. -//

-//
-//
-//
-//
-//
-// -// -// -// Eleven -// -// Subtitle -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam -// semper diam at erat pulvinar, at pulvinar felis blandit. -// Vestibulum volutpat tellus diam, consequat gravida libero -// rhoncus ut. Morbi maximus, leo sit amet vehicula eleifend, -// nunc dui porta orci, quis semper odio felis ut quam. -//

-//

-// Integer sollicitudin, tortor a mattis commodo, velit urna -// rhoncus erat, vitae congue lectus dolor consequat libero. -// Donec leo ligula, maximus et pellentesque sed, gravida a -// metus. Cras ullamcorper a nunc ac porta. Aliquam ut aliquet -// lacus, quis faucibus libero. Quisque non semper leo. -//

-//
-//
-//
-//
-//
+ + + + + + Five + + Subtitle + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Etiam semper diam at erat pulvinar, at pulvinar felis + blandit. Vestibulum volutpat tellus diam, consequat gravida + libero rhoncus ut. Morbi maximus, leo sit amet vehicula + eleifend, nunc dui porta orci, quis semper odio felis ut + quam. +

+
+
+
+ + + + + Six + + Subtitle + + + + + + Seven + + Subtitle + + + + + + + Eight + + Subtitle + + + + +
+ + + + Nine + + Subtitle + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Proin ornare magna eros, eu pellentesque tortor vestibulum + ut. Maecenas non massa sem. Etiam finibus odio quis feugiat + facilisis. +

+
+
+
+ + + Ten + + Subtitle + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Proin ornare magna eros, eu pellentesque tortor vestibulum + ut. Maecenas non massa sem. Etiam finibus odio quis feugiat + facilisis. +

+
+
+
+
+
+ + + + Eleven + + Subtitle + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam + semper diam at erat pulvinar, at pulvinar felis blandit. + Vestibulum volutpat tellus diam, consequat gravida libero + rhoncus ut. Morbi maximus, leo sit amet vehicula eleifend, + nunc dui porta orci, quis semper odio felis ut quam. +

+

+ Integer sollicitudin, tortor a mattis commodo, velit urna + rhoncus erat, vitae congue lectus dolor consequat libero. + Donec leo ligula, maximus et pellentesque sed, gravida a + metus. Cras ullamcorper a nunc ac porta. Aliquam ut aliquet + lacus, quis faucibus libero. Quisque non semper leo. +

+
+
+
+
+
-// -// -// -// Twelve -// -// Subtitle -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin -// ornare magna eros, eu pellentesque tortor vestibulum ut. -//

-//
-//
-//
-// -// -// Thirteen -// -// Subtitle -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin -// ornare magna eros, eu pellentesque tortor vestibulum ut. -// Maecenas non massa sem. Etiam finibus odio quis feugiat -// facilisis. -//

-//
-//
-//
-// -// -// Fourteen -// -// Subtitle -// -// -//

-// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin -// ornare magna eros, eu pellentesque tortor vestibulum ut. -//

-//
-//
-//
-//
-//
-// )); + + + + Twelve + + Subtitle + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin + ornare magna eros, eu pellentesque tortor vestibulum ut. +

+
+
+
+ + + Thirteen + + Subtitle + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin + ornare magna eros, eu pellentesque tortor vestibulum ut. + Maecenas non massa sem. Etiam finibus odio quis feugiat + facilisis. +

+
+
+
+ + + Fourteen + + Subtitle + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin + ornare magna eros, eu pellentesque tortor vestibulum ut. +

+
+
+
+
+
+ )); diff --git a/package.json b/package.json index fc1753a0..3d173e4d 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "docs:storybook:build": "build-storybook -c docs/stories/.config -o docs/build/stories", "docs:storybook:dev": "start-storybook -p 9001 -c docs/stories/.config", "lint": "tslint --project .", - "test:cov": "tslint --project . && jest --coverage", + "test:cov": "npm run lint && jest --coverage", "test": "jest", "watch": "rollup -cw" }, diff --git a/src/__tests__/__snapshots__/index.test.ts.snap b/src/__tests__/__snapshots__/index.test.ts.snap index 3335fc6a..561a77c0 100644 --- a/src/__tests__/__snapshots__/index.test.ts.snap +++ b/src/__tests__/__snapshots__/index.test.ts.snap @@ -1147,9 +1147,7 @@ Object { "as": "div", }, "propTypes": Object { - "color": [Function], "kind": [Function], - "notification": [Function], "size": [Function], "vertical": [Function], }, diff --git a/src/base/exotic.ts b/src/base/exotic.ts index 50c03838..dba1959e 100644 --- a/src/base/exotic.ts +++ b/src/base/exotic.ts @@ -10,11 +10,20 @@ export interface ForwardRefAsExoticComponent< React.ForwardRefExoticComponent, keyof React.ForwardRefExoticComponent > { - ( + < + TAsComponent extends + | React.ReactType + // tslint:disable-next-line: no-any + | ForwardRefAsExoticComponent = TDefaultComponent + >( props: Prefer< // tslint:disable-next-line:no-reserved-keywords React.PropsWithoutRef, - React.ComponentPropsWithRef + // React.ComponentPropsWithRef + // tslint:disable-next-line: no-any + TAsComponent extends ForwardRefAsExoticComponent + ? P + : React.ComponentPropsWithRef >, ): JSX.Element | null; } diff --git a/src/elements/notification/notification.tsx b/src/elements/notification/notification.tsx index 0a745b53..aaac93bd 100644 --- a/src/elements/notification/notification.tsx +++ b/src/elements/notification/notification.tsx @@ -7,6 +7,7 @@ import { Colors, COLORS } from "src/base/helpers"; export type NotificationModifierProps = Partial<{ color: Colors; + other: boolean; }>; export type NotificationProps = HelpersProps & NotificationModifierProps; diff --git a/src/grid/tiles/__tests__/tile.test.tsx b/src/grid/tiles/__tests__/tile.test.tsx index b5cb6709..87ae1f60 100644 --- a/src/grid/tiles/__tests__/tile.test.tsx +++ b/src/grid/tiles/__tests__/tile.test.tsx @@ -1,4 +1,3 @@ -import { COLORS } from "src/base/helpers"; import { Tile, TILE_KINDS, TILE_SIZES } from "src/grid/tiles/tile"; import { @@ -35,18 +34,6 @@ describe(`${COMPONENT_NAME} component`, () => { describe("props", () => { const { propTypes } = COMPONENT; - describe("color", () => { - validateOneOfPropType(propTypes, "color", COLORS); - - COLORS.map(color => { - it(`should be ${color}`, () => { - const node = makeNode({ color }); - const wrapper = makeGenericHOCShallowWrapperInContextConsumer(node); - expect(wrapper.hasClass(`is-${color}`)).toBe(true); - }); - }); - }); - describe("kind", () => { validateOneOfPropType(propTypes, "kind", TILE_KINDS); @@ -59,18 +46,6 @@ describe(`${COMPONENT_NAME} component`, () => { }); }); - describe("notification", () => { - validateBoolPropType(propTypes, "notification"); - - [false, true].map(notification => { - it(`should ${notification ? "" : "not "}be notification`, () => { - const node = makeNode({ notification }); - const wrapper = makeGenericHOCShallowWrapperInContextConsumer(node); - expect(wrapper.hasClass("notification")).toBe(notification); - }); - }); - }); - describe("size", () => { validateOneOfPropType(propTypes, "size", TILE_SIZES); diff --git a/src/grid/tiles/tile.tsx b/src/grid/tiles/tile.tsx index 253d2328..e3bb08ed 100644 --- a/src/grid/tiles/tile.tsx +++ b/src/grid/tiles/tile.tsx @@ -3,7 +3,6 @@ import * as PropTypes from "prop-types"; import * as React from "react"; import { forwardRefAs, Generic, HelpersProps } from "src/base"; -import { Colors, COLORS } from "src/base/helpers"; import { tuple } from "src/utils"; export const TILE_KINDS = tuple("ancestor", "parent", "child"); @@ -13,9 +12,7 @@ export const TILE_SIZES = tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); export type TileSizes = (typeof TILE_SIZES)[number]; export type TileModifierProps = Partial<{ - color: Colors; kind: TileKinds; - notification: boolean; size: TileSizes; vertical: boolean; }>; @@ -23,28 +20,21 @@ export type TileModifierProps = Partial<{ export type TileProps = HelpersProps & TileModifierProps; const propTypes = { - color: PropTypes.oneOf(COLORS), kind: PropTypes.oneOf(TILE_KINDS), - notification: PropTypes.bool, size: PropTypes.oneOf(TILE_SIZES), vertical: PropTypes.bool, }; export const Tile = Object.assign( forwardRefAs( - ( - { className, color, kind, notification, size, vertical, ...rest }, - ref, - ) => ( + ({ className, kind, size, vertical, ...rest }, ref) => (