Skip to content

Commit

Permalink
[React] Remove string index fallback for CSS properties (#24911)
Browse files Browse the repository at this point in the history
* [React] Remove string index fallback for CSS properties (resolves #24568)

* Require a minimum version of 2.2 for csstype

* Fix aphrodite types

* Fix react-confirm test

* Use Omit

* Fix react-geosuggest types

* Fix victory test

* Make customStyle and customStyleOnEditCell into functions
  • Loading branch information
pelotom authored and johnnyreilly committed Apr 11, 2018
1 parent 40c7baa commit fe3fcd7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 27 deletions.
37 changes: 23 additions & 14 deletions types/aphrodite/index.d.ts
Expand Up @@ -4,27 +4,36 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6

import * as React from "react";
import * as CSS from "csstype";

type BaseCSSProperties = CSS.Properties<number | string>;

type FontFamily =
| React.CSSProperties['fontFamily']
| Pick<React.CSSProperties,
| 'fontFamily'
| 'fontStyle'
| 'fontWeight'
| 'src'
>
| BaseCSSProperties['fontFamily']
| CSS.FontFace;

// Replace with Exclude once on 2.8+
type Diff<T extends string, U extends string> = (
& { [P in T]: P }
& { [P in U]: never }
& { [x: string]: never }
)[T];
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;

type CSSProperties = Omit<BaseCSSProperties, 'fontFamily'> & {
fontFamily?: FontFamily | FontFamily[];
};

// For pseudo selectors and media queries
interface OpenCSSProperties extends CSSProperties {
[k: string]: CSSProperties[keyof CSSProperties] | CSSProperties;
}

/**
* Aphrodite style declaration
*/
export interface StyleDeclaration {
[key: string]: Pick<React.CSSProperties, (
& React.CSSProperties
& { fontFamily: never }
)[keyof React.CSSProperties]> & {
fontFamily?: FontFamily | FontFamily[];
};
[key: string]: OpenCSSProperties;
}

interface StyleSheetStatic {
Expand Down
6 changes: 6 additions & 0 deletions types/aphrodite/package.json
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"csstype": "^2.2.0"
}
}
4 changes: 2 additions & 2 deletions types/react-bootstrap-table/index.d.ts
Expand Up @@ -1857,15 +1857,15 @@ export interface KeyboardNavigation {
/**
* Return a style object which will be applied on the navigating cell.
*/
customStyle?: CSSProperties;
customStyle?(cell: any, row: any): CSSProperties;
/**
* Set to false to disable click to navigate, usually user wants to click to select row instead of navigation.
*/
clickToNav?: boolean;
/**
* Return a style object which will be applied on the both of navigating and editing cell.
*/
customStyleOnEditCell?: CSSProperties;
customStyleOnEditCell?(cell: any, row: any): CSSProperties;
/**
* When set to true, pressing ENTER will begin to edit the cell if cellEdit is also enabled.
*/
Expand Down
6 changes: 3 additions & 3 deletions types/react-confirm/react-confirm-tests.tsx
Expand Up @@ -6,13 +6,13 @@ interface CustomModalProps {
}

class CustomModal extends React.Component<CustomModalProps & ReactConfirmProps> {
modalStyle(): string {
return this.props.show ? "display: none;" : "";
modalStyle() {
return this.props.show ? { display: 'none' } : undefined;
}

render() {
return (
<div style={this.modalStyle}>
<div style={this.modalStyle()}>
<h1>{this.props.title}</h1>

<div>
Expand Down
10 changes: 9 additions & 1 deletion types/react-geosuggest/index.d.ts
Expand Up @@ -16,7 +16,15 @@ export default class Geosuggest extends Component<GeosuggestProps> {
selectSuggest(value?: Suggest): void;
}

export interface GeosuggestProps extends InputHTMLAttributes<HTMLInputElement> {
// Replace with Exclude once on 2.8+
export type Diff<T extends string, U extends string> = (
& { [P in T]: P }
& { [P in U]: never }
& { [x: string]: never }
)[T];
export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;

export interface GeosuggestProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'style'> {
placeholder?: string;
initialValue?: string;
className?: string;
Expand Down
6 changes: 1 addition & 5 deletions types/react/index.d.ts
Expand Up @@ -897,11 +897,7 @@ declare namespace React {
onTransitionEndCapture?: TransitionEventHandler<T>;
}

export interface CSSProperties extends CSS.Properties<string | number> {
// The string index signature fallback is needed at least until csstype
// provides SVG CSS properties: https://github.com/frenic/csstype/issues/4
[propertyName: string]: any;
}
export interface CSSProperties extends CSS.Properties<string | number> {}

interface HTMLAttributes<T> extends DOMAttributes<T> {
// React-specific Attributes
Expand Down
2 changes: 1 addition & 1 deletion types/react/package.json
@@ -1,6 +1,6 @@
{
"private": true,
"dependencies": {
"csstype": "^2.0.0"
"csstype": "^2.2.0"
}
}
2 changes: 1 addition & 1 deletion types/victory/victory-tests.tsx
Expand Up @@ -158,7 +158,7 @@ test = (
grid: {strokeWidth: 2},
ticks: {stroke: "red"},
tickLabels: {fontSize: 12},
axisLabel: {fontsize: 16}
axisLabel: {fontSize: 16}
}}
label="Planets"
tickValues={[
Expand Down

0 comments on commit fe3fcd7

Please sign in to comment.