Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: rewrite react-ui-components in TypeScript #2128

Merged
merged 19 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TASK: resolve //TODOs
  • Loading branch information
JamesAlias committed Sep 18, 2018
commit 6e806a7b92176e2ee808f91e0a78abae620f309f
9 changes: 5 additions & 4 deletions packages/react-ui-components/src/Button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mergeClassNames from 'classnames';
import React from 'react';

import {PickDefaultProps} from '../../types';
import {Omit, PickDefaultProps} from '../../types';
import {makeFocusNode} from '../_lib/focusNode';

export type ButtonStyle = 'clean' | 'brand' | 'lighter' | 'transparent' | 'warn';
Expand All @@ -14,15 +14,13 @@ interface ButtonTheme {
readonly 'btn--lighter': string;
readonly 'btn--transparent': string;
readonly 'btn--brand': string;
readonly 'btn--brandActive': string;
readonly 'btn--brandHover': string;
readonly 'btn--cleanHover': string;
readonly 'btn--isPressed': string;
readonly 'btn--darkenHover': string;
readonly [key: string]: string; // TODO: this should be removed and be replaced with the actual css class override
}

type Diff<T, U> = T extends U ? never : T;
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;
// We omit the standard HTML button style attribute,
// so we have no collision with the Button component's style property,
// while still enjoying the intellisense and type checking for the rest of the HTML button attributes
Expand Down Expand Up @@ -133,8 +131,11 @@ class Button extends React.PureComponent<ButtonProps> {
const effectiveHoverStyle = isActive ? 'brand' : hoverStyle;
const finalClassName = mergeClassNames(
theme!.btn,
// @ts-ignore implizit any because ButtonTheme has no index signature
theme![`btn--size-${size}`],
// @ts-ignore implizit any because ButtonTheme has no index signature
theme![`btn--${effectiveStyle!}`],
// @ts-ignore implizit any because ButtonTheme has no index signature
theme![`btn--${effectiveHoverStyle!}Hover`],
{
[theme!['btn--brandActive']]: isActive,
Expand Down
22 changes: 13 additions & 9 deletions packages/react-ui-components/src/CheckBox/checkBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ class CheckBox extends PureComponent<CheckBoxProps> {
theme,
...rest
} = this.props;
const finalClassName = mergeClassNames({
[className!]: className && className.length,
[theme.checkbox]: true,
[theme.checkbox__disabled]: isDisabled
});
const mirrorClassNames = mergeClassNames({
[theme.checkbox__inputMirror]: true,
[theme['checkbox__inputMirror--active']]: isChecked
});
const finalClassName = mergeClassNames(
className,
theme.checkbox,
{
[theme.checkbox__disabled]: isDisabled,
}
);
const mirrorClassNames = mergeClassNames(
theme.checkbox__inputMirror,
{
[theme['checkbox__inputMirror--active']]: isChecked,
}
);

return (
<div className={finalClassName}>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui-components/src/Headline/headline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Headline extends PureComponent<HeadlineProps> {
className,
children,
theme,
style, // TODO: not used
style, // TODO: Discuss what this style prop should do.
...rest
} = this.props;
const classNames = mergeClassNames(theme!.heading, theme!['heading--h1'], className);
Expand Down
4 changes: 3 additions & 1 deletion packages/react-ui-components/src/Icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ interface IconTheme {
readonly 'icon--paddedLeft': string;
readonly 'icon--paddedRight': string;
readonly 'icon--spin': string;
readonly [key: string]: string;
readonly 'icon--color-warn': string;
readonly 'icon--color-error': string;
readonly 'icon--color-primaryBlue': string;
}

export interface IconProps {
Expand Down
3 changes: 2 additions & 1 deletion packages/react-ui-components/src/IconButton/iconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IconProps} from '../Icon/icon';

interface IconButtonTheme {
readonly 'iconButton': string;
readonly [key: string]: string;
readonly 'iconButton--disabled': string;
}

interface IconButtonProps {
Expand Down Expand Up @@ -74,6 +74,7 @@ class IconButton extends PureComponent<IconButtonProps> {
const finalClassName = mergeClassNames(
className,
theme!.iconButton,
// @ts-ignore implizit any because IconButtonTheme has no index signature
theme![`size-${size}`],
{
[theme!['iconButton--disabled']]: disabled
Expand Down
1 change: 0 additions & 1 deletion packages/react-ui-components/src/IconButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import injectProps from './../_lib/injectProps';
import Icon from './../Icon';
import Button from './../Button';

// TODO why?
export default injectProps({
IconComponent: Icon,
ButtonComponent: Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, {PureComponent} from 'react';
type DropDownItemId = string;

interface DropDownItemProps {
// TODO: think about declaring currying the function with the id in the parent component/container
/**
* The handler to call when clicking on the item of the DropDown.
*/
Expand Down Expand Up @@ -31,7 +30,7 @@ class DropDownItem extends PureComponent<DropDownItemProps> {
{...rest}
role="button"
onClick={this.handleClick}
>
>
{children}
</a>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IconButtonDropDownTheme {
readonly 'wrapper__dropDown': string;
readonly 'wrapper__dropDown--isOpen': string;
readonly 'wrapper__dropDownItem': string;
readonly [key: string]: string; // TODO should this be more restrictive?
readonly 'wrapper__btnIcon': string;
}

interface IconButtonDropDownProps {
Expand All @@ -24,7 +24,6 @@ interface IconButtonDropDownProps {
*/
readonly icon: string;

// TODO: be more specific or use children as a function
/**
* Children to be rendered inside the DropDown.
*/
Expand Down Expand Up @@ -59,8 +58,6 @@ interface IconButtonDropDownProps {
*/
readonly theme?: IconButtonDropDownTheme;

// TODO: This feels strange. We should just import the component classes here.
// also those interfaces should be exposed (export interface ...)
/**
* Static component dependencies which are injected from the outside (index.js)
*/
Expand Down Expand Up @@ -100,7 +97,6 @@ interface IconButtonDropDownState {
}

export default class IconButtonDropDown extends PureComponent<IconButtonDropDownProps, IconButtonDropDownState> {
// here we have to disable the tslint rule
// tslint:disable:readonly-keyword
private _timeouts: {
hold?: number,
Expand Down Expand Up @@ -171,7 +167,7 @@ export default class IconButtonDropDown extends PureComponent<IconButtonDropDown
className={theme!.wrapper__dropDownItem}
onClick={this.handleItemSelected}
id={child.props.dropDownId}
>
>
{child}
</DropDownItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import IconButtonDropDown from './iconButtonDropDown';

const ThemedIconButtonDropDown = themr(identifiers.iconButtonDropDown, style)(IconButtonDropDown);

// TODO: why here?
//
// Dependency injection
//
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui-components/src/SideBar/sideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface SideBarProps {
/**
* The children to render within the div node.
*/
readonly children: any; // TODO
readonly children: React.ReactNode;

/**
* An optional css theme to be injected.
Expand Down
13 changes: 0 additions & 13 deletions packages/react-ui-components/src/_lib/focusNode.js

This file was deleted.

5 changes: 5 additions & 0 deletions packages/react-ui-components/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@
export type PickDefaultProps<Props, defaultPropsKeys extends keyof Props> = Readonly<Required<{
[P in defaultPropsKeys]: Props[P]
}>>;


export type Diff<T, U> = T extends U ? never : T;

export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;