Merge pull request #24050 from DefinitelyTyped/revert-23116-jss-improve-typings

Revert "[jss] Add more granular style typings"
This commit is contained in:
Daniel Rosenwasser
2018-03-03 10:44:34 -08:00
committed by GitHub
5 changed files with 43 additions and 222 deletions
-130
View File
@@ -1,130 +0,0 @@
// These CSS typings adapted from TypeStyle: https://github.com/typestyle/typestyle
import { Observable } from './observable'
import * as csstype from 'csstype'
export type ObservableProperties<P> = {
[K in keyof P]: P[K] | Observable<P[K]>
}
export type CSSProperties =
& ObservableProperties<csstype.Properties>
& ObservableProperties<csstype.PropertiesHyphen>;
export interface JssProps {
'@global'?: CSSProperties;
extend?: string;
composes?: string | string[];
}
export interface JssExpand {
animation:
| {
delay: CSSProperties['animationDelay'];
direction: CSSProperties['animationDirection'];
duration: CSSProperties['animationDuration'];
iterationCount: CSSProperties['animationIterationCount'];
name: CSSProperties['animationName'];
playState: CSSProperties['animationPlayState'];
timingFunction: any;
}
| CSSProperties['animation'];
background:
| {
attachment: CSSProperties['backgroundAttachment'];
color: CSSProperties['backgroundColor'];
image: CSSProperties['backgroundImage'];
position: CSSProperties['backgroundPosition'] | number[]; // Can be written using array e.g. `[0 0]`
repeat: CSSProperties['backgroundRepeat'];
size: Array<CSSProperties['backgroundSize'] | CSSProperties['backgroundSize']>; // Can be written using array e.g. `['center' 'center']`
}
| CSSProperties['background'];
border:
| {
color: CSSProperties['borderColor'];
style: CSSProperties['borderStyle'];
width: CSSProperties['borderWidth'];
}
| CSSProperties['border'];
boxShadow:
| {
x: any;
y: any;
blur: any;
spread: any;
color: CSSProperties['color'];
inset?: 'inset'; // If you want to add inset you need to write "inset: 'inset'"
}
| CSSProperties['boxShadow'];
flex:
| {
basis: CSSProperties['flexBasis'];
direction: CSSProperties['flexDirection'];
flow: CSSProperties['flexFlow'];
grow: CSSProperties['flexGrow'];
shrink: CSSProperties['flexShrink'];
wrap: CSSProperties['flexWrap'];
}
| CSSProperties['flex'];
font:
| {
family: CSSProperties['fontFamily'];
size: CSSProperties['fontSize'];
stretch: CSSProperties['fontStretch'];
style: CSSProperties['fontStyle'];
variant: CSSProperties['fontVariant'];
weight: CSSProperties['fontWeight'];
}
| CSSProperties['font'];
listStyle:
| {
image: CSSProperties['listStyleImage'];
position: CSSProperties['listStylePosition'];
type: CSSProperties['listStyleType'];
}
| CSSProperties['listStyle'];
margin:
| {
bottom: CSSProperties['marginBottom'];
left: CSSProperties['marginLeft'];
right: CSSProperties['marginRight'];
top: CSSProperties['marginTop'];
}
| CSSProperties['margin'];
padding:
| {
bottom: CSSProperties['paddingBottom'];
left: CSSProperties['paddingLeft'];
right: CSSProperties['paddingRight'];
top: CSSProperties['paddingTop'];
}
| CSSProperties['padding'];
outline:
| {
color: CSSProperties['outlineColor'];
style: 'none' | 'hidden' | 'dotted' | 'dashed' | 'solid' | 'double' | 'groove' | 'ridge' | 'inset' | 'outset';
width: any;
}
| CSSProperties['outline'];
textShadow:
| {
x: any;
y: any;
blur: any;
color: CSSProperties['color'];
}
| CSSProperties['textShadow'];
transition:
| {
delay: CSSProperties['transitionDelay'];
duration: CSSProperties['transitionDuration'];
property: CSSProperties['transitionProperty'];
timingFunction: CSSProperties['transitionTimingFunction'];
}
| CSSProperties['transition'];
}
export type JssExpandArr = { [k in keyof JssExpand]?: JssExpand[k] | Array<JssExpand[k]> };
export type SimpleStyle = CSSProperties & JssProps & JssExpandArr;
export type Style = SimpleStyle | Observable<csstype.PropertiesHyphen>;
+40 -43
View File
@@ -1,15 +1,9 @@
// Type definitions for jss 9.5
// Type definitions for jss 9.3
// Project: https://github.com/cssinjs/jss#readme
// Definitions by: Brenton Simpson <https://github.com/appsforartists>
// Oleg Slobodskoi <https://github.com/kof>
// Thomas Crockett <https://github.com/pelotom>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { Style } from './css';
export type Styles<Name extends string = any> = Record<Name, Style>;
export type Classes<Name extends string = any> = Record<Name, string>;
// TypeScript Version: 2.2
export interface Rule {
className: string;
@@ -19,12 +13,13 @@ export interface Rule {
prop(key: string, value: any): this;
toJSON(): string;
}
export interface StyleSheet<Name extends string = any> {
export interface StyleSheet<T> {
// Gives auto-completion on the rules declared in `createStyleSheet` without
// causing errors for rules added dynamically after creation.
classes: Classes<Name>;
options: RuleOptions;
classes: {
[K in keyof T]: string;
} & { [key: string]: string };
options: any;
linked: boolean;
attached: boolean;
/**
@@ -40,21 +35,21 @@ export interface StyleSheet<Name extends string = any> {
* Will insert a rule also after the stylesheet has been rendered first time.
*/
addRule(style: Style, options?: Partial<RuleOptions>): Rule;
addRule(name: Name, style: Style, options?: Partial<RuleOptions>): Rule;
addRule(name: string, style: Style, options?: Partial<RuleOptions>): Rule;
/**
* Create and add rules.
* Will render also after Style Sheet was rendered the first time.
*/
addRules(styles: Partial<Styles<Name>>, options?: Partial<RuleOptions>): Rule[];
addRules(styles: { [key: string]: Style }, options?: Partial<RuleOptions>): Rule[];
/**
* Get a rule by name.
*/
getRule(name: Name): Rule;
getRule(name: string): Rule;
/**
* Delete a rule by name.
* Returns `true`: if rule has been deleted from the DOM.
*/
deleteRule(name: Name): boolean;
deleteRule(name: string): boolean;
/**
* Get index of a rule.
*/
@@ -63,37 +58,39 @@ export interface StyleSheet<Name extends string = any> {
* Update the function values with a new data.
*/
update(data?: {}): this;
update(name: Name, data: {}): this;
update(name: string, data: {}): this;
/**
* Convert rules to a CSS string.
*/
toString(options?: { indent?: number }): string;
}
export type GenerateClassName<Name extends string = any> = (rule: Rule, sheet?: StyleSheet<Name>) => string;
export type GenerateClassName<T> = (rule: Rule, sheet?: StyleSheet<T>) => string;
export interface Style {
[key: string]: any;
}
export interface JSSPlugin {
[key: string]: () => Partial<{
onCreateRule(name: string, style: Style, options: RuleOptions): Rule;
onProcessRule(rule: Rule, sheet: StyleSheet): void;
onProcessStyle(style: Style, rule: Rule, sheet: StyleSheet): Style;
onProcessSheet(sheet: StyleSheet): void;
onChangeValue(value: any, prop: string, rule: Rule): any;
onUpdate(data: {}, rule: Rule, sheet: StyleSheet): void;
onCreateRule(name: string, style: Style, options: RuleOptions): Rule,
onProcessRule(rule: Rule, sheet: StyleSheet<any>): void,
onProcessStyle(style: Style, rule: Rule, sheet: StyleSheet<any>): Style,
onProcessSheet(sheet: StyleSheet<any>): void,
onChangeValue(value: any, prop: string, rule: Rule): any,
onUpdate(data: {}, rule: Rule, sheet: StyleSheet<any>): void,
}>;
}
export interface JSSOptions {
createGenerateClassName(): GenerateClassName;
createGenerateClassName(): GenerateClassName<any>;
plugins: ReadonlyArray<JSSPlugin>;
virtual: boolean;
insertionPoint: string | HTMLElement;
}
export interface RuleFactoryOptions<Name extends string = any> {
export interface RuleFactoryOptions {
selector: string;
classes: Classes<Name>;
sheet: StyleSheet<Name>;
classes: { [key: string]: string };
sheet: StyleSheet<any>;
index: number;
jss: JSS;
generateClassName: GenerateClassName<Name>;
generateClassName: GenerateClassName<any>;
}
export interface RuleOptions {
index: number;
@@ -101,23 +98,23 @@ export interface RuleOptions {
}
declare class JSS {
constructor(options?: Partial<JSSOptions>);
createStyleSheet<Name extends string>(
styles: Partial<Styles<Name>>,
createStyleSheet<T>(
styles: T,
options?: Partial<{
media: string;
meta: string;
link: boolean;
element: HTMLStyleElement;
index: number;
generateClassName: GenerateClassName<Name>;
classNamePrefix: string;
media: string,
meta: string,
link: boolean,
element: HTMLStyleElement,
index: number,
generateClassName: GenerateClassName<T>,
classNamePrefix: string,
}>,
): StyleSheet<Name>;
removeStyleSheet(sheet: StyleSheet): this;
): StyleSheet<T>;
removeStyleSheet(sheet: StyleSheet<any>): this;
setup(options?: Partial<JSSOptions>): this;
use(plugin: JSSPlugin): this;
createRule(style: Style, options?: RuleFactoryOptions): Rule;
createRule<Name extends string>(name: Name, style: Style, options?: RuleFactoryOptions<Name>): Rule;
createRule(style: Style, options?: Partial<RuleFactoryOptions>): Rule;
createRule(name: string, style: Style, options?: Partial<RuleFactoryOptions>): Rule;
}
/**
* Creates a new instance of JSS.
+3 -26
View File
@@ -7,25 +7,13 @@ import {
const jss = createJSS().setup({});
const styleSheet = jss.createStyleSheet<string>(
const styleSheet = jss.createStyleSheet(
{
ruleWithMockObservable: {
subscribe: observer => {
const next = typeof observer === 'function' ? observer : observer.next;
next({ background: 'blue', display: 'flex' });
next({ invalidKey: 'blueish' }); // $ExpectError
// only kebab case allowed in observables
next({ 'align-items': 'center' });
next({ alignItems: 'center' }); // $ExpectError
return {
unsubscribe() {}
};
}
subscribe() {}
},
container: {
display: 'flex',
'align-items': 'center',
width: 100,
opacity: .5,
},
@@ -65,21 +53,10 @@ styleSheet.addRules({
},
});
styleSheet.addRule('badProperty', {
thisIsNotAValidProperty: 'blah', // $ExpectError
});
styleSheet.addRule('badValue', { // $ExpectError
'align-items': 'thisIsNotAValidValue',
});
styleSheet.detach();
const styleSheet2 = sharedInstance.createStyleSheet({
sharedInstance.createStyleSheet({
container: {
background: '#000099',
}
});
styleSheet2.classes.container; // $ExpectType string
styleSheet2.classes.notAValidKey; // $ExpectError
-17
View File
@@ -1,17 +0,0 @@
// Copied from https://github.com/cssinjs/jss/blob/6ed7963786d5ef899075e95f81efc9530342154f/src/types.js
export type Observable<T> = {
subscribe(observerOrNext: ObserverOrNext<T>): Subscription
}
export type Observer<T> = {
next: NextChannel<T>
}
export type NextChannel<T> = (value: T) => void
export type ObserverOrNext<T> = Observer<T> | NextChannel<T>
export type Unsubscribe = () => void
export type Subscription = {
unsubscribe: Unsubscribe
}
-6
View File
@@ -1,6 +0,0 @@
{
"private": true,
"dependencies": {
"csstype": "^1.6.0"
}
}