mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[styled-system] Make N a generic on style and add typedef for scale (#35556)
* Add generic for N and typedef for scale * Make style scale generic with a default
This commit is contained in:
parent
4550017146
commit
19639a0aaf
21
types/styled-system/index.d.ts
vendored
21
types/styled-system/index.d.ts
vendored
@ -36,17 +36,20 @@ export interface styleFn {
|
||||
propTypes?: string[];
|
||||
}
|
||||
|
||||
export interface LowLevelStylefunctionArguments {
|
||||
prop: string;
|
||||
cssProperty?: string;
|
||||
alias?: string;
|
||||
key?: string;
|
||||
transformValue?: (n: string | number, scale: Array<string | number>) => any;
|
||||
scale?: Array<string | number>;
|
||||
export type Scale = object | Array<string | number>;
|
||||
|
||||
export interface LowLevelStylefunctionArguments<N, S> {
|
||||
prop: string;
|
||||
cssProperty?: string;
|
||||
alias?: string;
|
||||
key?: string;
|
||||
transformValue?: (n: N, scale?: S) => any;
|
||||
scale?: S;
|
||||
}
|
||||
|
||||
export function style(
|
||||
args: LowLevelStylefunctionArguments
|
||||
export function style<N = string | number, S = Scale>(
|
||||
// tslint:disable-next-line no-unnecessary-generics
|
||||
args: LowLevelStylefunctionArguments<N, S>
|
||||
): { [cssProp: string]: string };
|
||||
|
||||
export function compose(
|
||||
|
||||
@ -694,6 +694,24 @@ const customFontSize = style({
|
||||
scale: [8, 16, 32]
|
||||
});
|
||||
|
||||
const centerWithGenerics = style<boolean>({
|
||||
prop: 'center',
|
||||
cssProperty: 'justify-content',
|
||||
transformValue: shouldCenter => shouldCenter ? 'center' : 'flex-start'
|
||||
});
|
||||
|
||||
const buttonSizes = {
|
||||
sm: '8px',
|
||||
md: '12px',
|
||||
lg: '24px',
|
||||
};
|
||||
|
||||
const buttonSizeWithGeneric = style<keyof typeof buttonSizes, typeof buttonSizes>({
|
||||
prop: 'size',
|
||||
cssProperty: 'font-size',
|
||||
transformValue: (size, sizes) => sizes && sizes[size]
|
||||
});
|
||||
|
||||
// All Style Functions contain `propTypes`
|
||||
export const alignContentPropTypes = alignContent.propTypes;
|
||||
export const alignItemsPropTypes = alignItems.propTypes;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user