mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add type definitions for cxs-css/cxs (#45875)
* Add type definitions for cxs-css/cxs * Address linter/CI issues * Fix importing and reintroduce ts-expect-error * Fix tsconfig * Fix import path in tests * Omit ts-expect-error * Try to fix compile error * Use ts-expect-error instead of $ExpectError * Remove directive in component * Remove error-causing callsites * Prefer interface over props * Turn off export to fix lint error
This commit is contained in:
parent
91a51a80e2
commit
33a94d5028
23
types/cxs/component/index.d.ts
vendored
Normal file
23
types/cxs/component/index.d.ts
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
import * as React from 'react';
|
||||
import { CSSObject } from '../index';
|
||||
|
||||
type ApparentComponentProps<
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>
|
||||
> = C extends React.JSXElementConstructor<infer P>
|
||||
? JSX.LibraryManagedAttributes<C, P>
|
||||
: React.ComponentPropsWithRef<C>;
|
||||
|
||||
declare const cxsComponent: {
|
||||
<
|
||||
Component extends
|
||||
| keyof JSX.IntrinsicElements
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
| React.JSXElementConstructor<any>,
|
||||
PropsType extends object & ApparentComponentProps<Component>
|
||||
>(
|
||||
component: Component,
|
||||
): (arg: CSSObject | ((arg: PropsType) => CSSObject)) => React.JSXElementConstructor<PropsType>;
|
||||
};
|
||||
|
||||
export = cxsComponent;
|
||||
35
types/cxs/cxs-tests.ts
Normal file
35
types/cxs/cxs-tests.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import * as React from 'react';
|
||||
import cxsComponent = require('cxs/component');
|
||||
import cxs = require('cxs');
|
||||
|
||||
/**
|
||||
* Standard calls to cxs to generate classNames
|
||||
*/
|
||||
cxs({
|
||||
color: 'red',
|
||||
':hover': {
|
||||
color: 'green',
|
||||
},
|
||||
});
|
||||
|
||||
cxsComponent('div')({
|
||||
fontSize: 24,
|
||||
});
|
||||
|
||||
/** React component composition */
|
||||
const ComponentA = () => React.createElement('div');
|
||||
|
||||
cxsComponent(ComponentA)({
|
||||
fontSize: 72,
|
||||
});
|
||||
|
||||
/** React composition with props callback */
|
||||
interface Props {
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
const ComponentB = (props: Props) => React.createElement('div');
|
||||
|
||||
cxsComponent(ComponentB)((props: Props) => ({
|
||||
color: props.isActive ? 'blue' : 'purple',
|
||||
}));
|
||||
27
types/cxs/index.d.ts
vendored
Normal file
27
types/cxs/index.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
// Type definitions for cxs 6.2
|
||||
// Project: https://github.com/cxs-css/cxs
|
||||
// Definitions by: Daniel Eden <https://github.com/daneden>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// Minimum TypeScript Version 3.9
|
||||
import * as CSS from 'csstype';
|
||||
|
||||
declare namespace cxs {
|
||||
type CSSProperties = CSS.Properties<string | number>;
|
||||
type CSSPseudos = { [K in CSS.Pseudos]?: CSSObject };
|
||||
|
||||
interface CSSObject extends CSSProperties, CSSPseudos {
|
||||
[key: string]: CSSObject | string | number | undefined;
|
||||
}
|
||||
}
|
||||
|
||||
declare const cxs: {
|
||||
(styles: cxs.CSSObject): string;
|
||||
/** Returns cached CSS as a string for server-side rendering */
|
||||
css: () => string;
|
||||
/** Resets the CSS cache for future renders */
|
||||
reset: () => void;
|
||||
/** Sets a custom className prefix */
|
||||
prefix: (val: string) => void;
|
||||
};
|
||||
|
||||
export = cxs;
|
||||
6
types/cxs/package.json
Normal file
6
types/cxs/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"csstype": "^2.2.0"
|
||||
}
|
||||
}
|
||||
17
types/cxs/tsconfig.json
Normal file
17
types/cxs/tsconfig.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"jsx": "react",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts", "cxs-tests.ts"]
|
||||
}
|
||||
1
types/cxs/tslint.json
Normal file
1
types/cxs/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user