Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust flow types to handle function calls (#1188)
* Adjust flow types to handle function calls * Add optional props to classnames * Add changeset * Update packages/react/src/styled/__tests__/types.test.js.flow Co-authored-by: Monica <molejniczak@atlassian.com> * Split classnames function decl for CSS * Test conditional logical expressions in styled Co-authored-by: Monica <molejniczak@atlassian.com>
- Loading branch information
1 parent
c4ce8a4
commit ad4d257
Showing
37 changed files
with
383 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@compiled/css': patch | ||
'@compiled/jest': patch | ||
'@compiled/react': patch | ||
'@compiled/webpack-loader': patch | ||
--- | ||
|
||
Update TypeScript and Flow types to support function calls and resolve incorrect typing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
declare var layers: { | ||
modal: () => number, | ||
}; | ||
|
||
declare type Tokens = typeof tokens; | ||
declare type CSSTokenMap = { | ||
'elevation.surface': 'var(--ds-surface)', | ||
}; | ||
declare var tokens: { | ||
+'elevation.surface': '--ds-surface', | ||
}; | ||
declare type CSSToken = $ElementType<CSSTokenMap, $Keys<CSSTokenMap>>; | ||
declare function token<T: $Keys<Tokens>>(path: T, fallback?: string): $ElementType<CSSTokenMap, T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,54 @@ | ||
/** | ||
* Flowtype definitions for index | ||
* Generated by Flowgen from a Typescript Definition | ||
* Flowgen v1.15.0 | ||
* Flowgen v1.17.0 | ||
* @flow | ||
*/ | ||
import type { Node } from 'react'; | ||
import type { BasicTemplateInterpolations, CssFunction } from '../types'; | ||
export type Interpolations = (BasicTemplateInterpolations | CssFunction<> | CssFunction<>[])[]; | ||
export interface ClassNamesProps { | ||
import type { CssType, CssFunction } from '../types'; | ||
export type ObjectInterpolation<TProps> = CssType<TProps> | CssType<TProps>[]; | ||
export type TemplateStringsInterpolation<TProps> = CssFunction<TProps> | CssFunction<TProps>[]; | ||
declare interface CssSignature<TProps> { | ||
(...interpolations: ObjectInterpolation<TProps>[]): string; | ||
( | ||
template: $ReadOnlyArray<string>, | ||
...interpolations: TemplateStringsInterpolation<TProps>[] | ||
): string; | ||
} | ||
export interface ClassNamesProps<TProps> { | ||
children: (opts: { | ||
css: (css: CssFunction<> | CssFunction<>[], ...interpolations: Interpolations) => string, | ||
style: { | ||
[key: string]: string, | ||
... | ||
}, | ||
css: CssSignature<TProps>, | ||
style: $Shape<CSSStyleDeclaration>, | ||
... | ||
}) => Node; | ||
} | ||
/** | ||
* Use a component where styles are not necessarily tied to an element. | ||
* ## Class names | ||
* | ||
* ``` | ||
* // Object CSS | ||
* Use a component where styles are not necessarily used on a JSX element. | ||
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-class-names). | ||
* | ||
* ### Style with objects | ||
* @example ``` | ||
* <ClassNames> | ||
* {({ css, style }) => children({ className: css({ fontSize: 12 }) })} | ||
* </ClassNames> | ||
* ``` | ||
* | ||
* // Template literal CSS | ||
* ### Style with template literals | ||
* @example ``` | ||
* <ClassNames> | ||
* {({ css, style }) => children({ className: css`font-size: 12px;` })} | ||
* </ClassNames> | ||
* ``` | ||
* | ||
* // Array CSS | ||
* ### Compose styles with arrays | ||
* @example ``` | ||
* <ClassNames> | ||
* {({ css, style }) => | ||
* children({ className: css([{ fontSize: 12 }, `font-size: 12px`]) })} | ||
* children({ className: css([{ fontSize: 12 }, css`font-size: 12px`]) })} | ||
* </ClassNames> | ||
* ``` | ||
* | ||
* For more help, read the docs: | ||
* https://compiledcssinjs.com/docs/api-class-names | ||
* @param props | ||
*/ | ||
declare export function ClassNames(_: ClassNamesProps): React$Node; | ||
declare export function ClassNames<TProps>(x: ClassNamesProps<TProps>): React$Node; | ||
declare export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
/** | ||
* Flowtype definitions for index | ||
* Generated by Flowgen from a Typescript Definition | ||
* Flowgen v1.15.0 | ||
* Flowgen v1.17.0 | ||
* @flow | ||
*/ | ||
import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types'; | ||
import type { CSSProps, CssObject, CssFunction } from '../types'; | ||
/** | ||
* Create styles that can be re-used between components with a template literal. | ||
* ## CSS | ||
* | ||
* ``` | ||
* css`color: red;`; | ||
* ``` | ||
* Define styles that are statically typed and useable with other Compiled APIs. | ||
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-css). | ||
* | ||
* For more help, read the docs: | ||
* https://compiledcssinjs.com/docs/api-css | ||
* @param css | ||
* @param values | ||
*/ | ||
declare export default function css<T>( | ||
_css: $ReadOnlyArray<string>, | ||
..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[] | ||
): CSSProps; | ||
/** | ||
* Create styles that can be re-used between components with an object | ||
* ### Style with objects | ||
* @example ``` | ||
* const redText = css({ | ||
* color: 'red', | ||
* }); | ||
* | ||
* <div css={redText} /> | ||
* ``` | ||
* css({ color: 'red' }); | ||
* ``` | ||
* | ||
* For more help, read the docs: | ||
* https://compiledcssinjs.com/docs/api-css | ||
* @param css | ||
* ### Style with template literals | ||
* @example ``` | ||
* const redText = css` | ||
* color: red; | ||
* `; | ||
* | ||
* <div css={redText} /> | ||
* ``` | ||
*/ | ||
declare export default function css(_css: CSSProps): CSSProps; | ||
declare export default function css<TProps>( | ||
styles: $ReadOnlyArray<string>, | ||
...interpolations: CssFunction<TProps>[] | ||
): CSSProps<TProps>; | ||
declare export default function css<T>(styles: CssObject<T> | CssObject<T>[]): CSSProps<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
/** | ||
* THIS IS A MANUALLY CURATED FLOW FILE. | ||
* | ||
* Flowtype definitions for runtime | ||
* Flowtype definitions for index | ||
* Generated by Flowgen from a Typescript Definition | ||
* Flowgen v1.15.0 | ||
* Flowgen v1.17.0 | ||
* @flow | ||
*/ | ||
import type { CSSProps, CssFunction } from './types'; | ||
import type { CssFunction, CSSProps, CssType } from './types'; | ||
export type { CSSProps, CssFunction, CssType }; | ||
declare export { keyframes } from './keyframes'; | ||
declare export { styled } from './styled'; | ||
declare export { ClassNames } from './class-names'; | ||
declare export { default as css } from './css'; | ||
export type { CssFunction, CSSProps }; | ||
export type { CssObject } from './styled'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.