From 5ce2af315b978294376f1a1658a4e42b1869fe8b Mon Sep 17 00:00:00 2001 From: merceyz Date: Thu, 2 May 2019 15:07:37 +0200 Subject: [PATCH 01/17] [styles] Update type definition to let CSS properties be functions --- packages/material-ui-styles/src/styled/styled.d.ts | 4 +++- .../src/withStyles/withStyles.d.ts | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/material-ui-styles/src/styled/styled.d.ts b/packages/material-ui-styles/src/styled/styled.d.ts index 73068b41f70ab6..a25974b8dc0472 100644 --- a/packages/material-ui-styles/src/styled/styled.d.ts +++ b/packages/material-ui-styles/src/styled/styled.d.ts @@ -10,7 +10,9 @@ import * as React from 'react'; * @internal */ export type ComponentCreator = ( - styles: CSSProperties | (({ theme, ...props }: { theme: Theme } & Props) => CSSProperties), + styles: + | CSSProperties + | (({ theme, ...props }: { theme: Theme } & Props) => CSSProperties), options?: WithStylesOptions, ) => React.ComponentType< Omit>, 'classes' | 'className'> & diff --git a/packages/material-ui-styles/src/withStyles/withStyles.d.ts b/packages/material-ui-styles/src/withStyles/withStyles.d.ts index a491421267be14..3bb01bd6630ca0 100644 --- a/packages/material-ui-styles/src/withStyles/withStyles.d.ts +++ b/packages/material-ui-styles/src/withStyles/withStyles.d.ts @@ -3,9 +3,15 @@ import { PropInjector } from '@material-ui/types'; import * as CSS from 'csstype'; import * as JSS from 'jss'; -export interface CSSProperties extends CSS.Properties { +export type BaseCSSProperties = { + [P in keyof CSS.Properties]: + | CSS.Properties[P] + | ((props: Props) => CSS.Properties[P]) +}; + +export interface CSSProperties extends BaseCSSProperties { // Allow pseudo selectors and media queries - [k: string]: CSS.Properties[keyof CSS.Properties] | CSSProperties; + [k: string]: BaseCSSProperties[keyof BaseCSSProperties] | CSSProperties; } /** @@ -18,7 +24,7 @@ export interface CSSProperties extends CSS.Properties { */ export type StyleRules = Record< ClassKey, - CSSProperties | ((props: Props) => CSSProperties) + CSSProperties | ((props: Props) => CSSProperties) >; /** From ae8ca12a266df89c6d48dc4edc001a720157481a Mon Sep 17 00:00:00 2001 From: merceyz Date: Thu, 2 May 2019 15:08:01 +0200 Subject: [PATCH 02/17] Restore AdaptingHook --- .../pages/css-in-js/basics/AdaptingHook.tsx | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docs/src/pages/css-in-js/basics/AdaptingHook.tsx diff --git a/docs/src/pages/css-in-js/basics/AdaptingHook.tsx b/docs/src/pages/css-in-js/basics/AdaptingHook.tsx new file mode 100644 index 00000000000000..afb9d880d6ddc9 --- /dev/null +++ b/docs/src/pages/css-in-js/basics/AdaptingHook.tsx @@ -0,0 +1,49 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { makeStyles } from '@material-ui/styles'; +import Button, { ButtonProps } from '@material-ui/core/Button'; + +type Omit = Pick>; +interface Props { + color: string; +} + +const useStyles = makeStyles({ + root: { + background: (props: Props) => + props.color === 'red' + ? 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)' + : 'linear-gradient(45deg, #2196F3 30%, #21CBF3 90%)', + border: 0, + borderRadius: 3, + boxShadow: (props: Props) => + props.color === 'red' + ? '0 3px 5px 2px rgba(255, 105, 135, .3)' + : '0 3px 5px 2px rgba(33, 203, 243, .3)', + color: 'white', + height: 48, + padding: '0 30px', + margin: 8, + }, +}); + +function MyButton(props: Props & Omit) { + const { color, ...other } = props; + const classes = useStyles(props); + return