From 70465ebd315d995979eb44fd182ecc78f5321f5e Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Wed, 17 Oct 2018 00:00:34 +0200 Subject: [PATCH 1/8] feat: Implement SelectField --- src/core/client/ui/components/Icon/Icon.css | 14 +--- .../components/SelectField/OptGroup.spec.tsx | 14 ++++ .../ui/components/SelectField/OptGroup.tsx | 13 +++ .../ui/components/SelectField/Option.spec.tsx | 16 ++++ .../ui/components/SelectField/Option.tsx | 15 ++++ .../ui/components/SelectField/SelectField.css | 65 +++++++++++++++ .../ui/components/SelectField/SelectField.mdx | 52 ++++++++++++ .../SelectField/SelectField.spec.tsx | 21 +++++ .../ui/components/SelectField/SelectField.tsx | 81 +++++++++++++++++++ .../__snapshots__/OptGroup.spec.tsx.snap | 9 +++ .../__snapshots__/Option.spec.tsx.snap | 11 +++ .../__snapshots__/SelectField.spec.tsx.snap | 31 +++++++ .../client/ui/components/SelectField/index.ts | 3 + src/core/client/ui/components/Steps/steps.mdx | 1 + src/core/client/ui/components/index.ts | 1 + src/core/client/ui/hocs/withKeyboardFocus.tsx | 5 +- src/core/client/ui/shared/icon.css | 37 +++++++++ src/core/client/ui/shared/typography.css | 9 +++ 18 files changed, 381 insertions(+), 17 deletions(-) create mode 100644 src/core/client/ui/components/SelectField/OptGroup.spec.tsx create mode 100644 src/core/client/ui/components/SelectField/OptGroup.tsx create mode 100644 src/core/client/ui/components/SelectField/Option.spec.tsx create mode 100644 src/core/client/ui/components/SelectField/Option.tsx create mode 100644 src/core/client/ui/components/SelectField/SelectField.css create mode 100644 src/core/client/ui/components/SelectField/SelectField.mdx create mode 100644 src/core/client/ui/components/SelectField/SelectField.spec.tsx create mode 100644 src/core/client/ui/components/SelectField/SelectField.tsx create mode 100644 src/core/client/ui/components/SelectField/__snapshots__/OptGroup.spec.tsx.snap create mode 100644 src/core/client/ui/components/SelectField/__snapshots__/Option.spec.tsx.snap create mode 100644 src/core/client/ui/components/SelectField/__snapshots__/SelectField.spec.tsx.snap create mode 100644 src/core/client/ui/components/SelectField/index.ts create mode 100644 src/core/client/ui/shared/icon.css diff --git a/src/core/client/ui/components/Icon/Icon.css b/src/core/client/ui/components/Icon/Icon.css index a34a46bfa..6484d3410 100644 --- a/src/core/client/ui/components/Icon/Icon.css +++ b/src/core/client/ui/components/Icon/Icon.css @@ -1,17 +1,5 @@ -@font-face { - font-family: "Material Icons"; - font-style: normal; - font-weight: 400; - src: local("Material Icons"), local("MaterialIcons-Regular"), - url(material-design-icons/iconfont/MaterialIcons-Regular.woff2) - format("woff2"), - url(material-design-icons/iconfont/MaterialIcons-Regular.woff) - format("woff"), - url(material-design-icons/iconfont/MaterialIcons-Regular.ttf) - format("truetype"); -} - .root { + composes: icon from "talk-ui/shared/icon.css"; font-family: "Material Icons"; speak: none; font-style: normal; diff --git a/src/core/client/ui/components/SelectField/OptGroup.spec.tsx b/src/core/client/ui/components/SelectField/OptGroup.spec.tsx new file mode 100644 index 000000000..0e48da965 --- /dev/null +++ b/src/core/client/ui/components/SelectField/OptGroup.spec.tsx @@ -0,0 +1,14 @@ +import React from "react"; +import TestRenderer from "react-test-renderer"; + +import { PropTypesOf } from "talk-ui/types"; +import OptGroup from "./OptGroup"; + +it("renders correctly", () => { + const props: PropTypesOf = { + label: "mamals", + children: , + }; + const renderer = TestRenderer.create(); + expect(renderer.toJSON()).toMatchSnapshot(); +}); diff --git a/src/core/client/ui/components/SelectField/OptGroup.tsx b/src/core/client/ui/components/SelectField/OptGroup.tsx new file mode 100644 index 000000000..1aaeaf837 --- /dev/null +++ b/src/core/client/ui/components/SelectField/OptGroup.tsx @@ -0,0 +1,13 @@ +import React from "react"; +import { StatelessComponent } from "react"; + +export interface OptGroupProps { + label: string; + children?: React.ReactNode; +} + +const OptionGroup: StatelessComponent = props => { + return ; +}; + +export default OptionGroup; diff --git a/src/core/client/ui/components/SelectField/Option.spec.tsx b/src/core/client/ui/components/SelectField/Option.spec.tsx new file mode 100644 index 000000000..8f7e2919b --- /dev/null +++ b/src/core/client/ui/components/SelectField/Option.spec.tsx @@ -0,0 +1,16 @@ +import React from "react"; +import TestRenderer from "react-test-renderer"; + +import { PropTypesOf } from "talk-ui/types"; +import Option from "./Option"; + +it("renders correctly", () => { + const props: PropTypesOf = { + disabled: false, + hidden: false, + value: "apple", + children: "Apple", + }; + const renderer = TestRenderer.create(