Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

AnimationStyleset

AnimationStyleset: Styleset & { +?: IStyleRule | IStyleRule[] }

Defines an object containing style properties for an animation frame. Stylesets for keyframes allow custom properties (via "--") but don't allow dependent rules (because dependent rules are actually separate CSS rules). Animation styleset can extend other style rules; however, any dependent rules will be ignored.

CombinedClassStyleset

CombinedClassStyleset: CombinedStyleset & { ++?: ParentClassType | ParentClassType[] }

Extends the CombinedStyleset type with the "++" property, which allows combining multiple class rules. Note that the "+" (single plus) property allows deriving from any base style rules (not necessarily classes) and the style properties from the base rules are simply copied to the new rule. Additionally, even if class rules were among the base rules, the names of the base classes are lost.

The "++" (double plus) property is different and it only applies to class rules and only allows deriving from class rules. The style properties from the base classes are not copied to the new rule; instead, the name of the new class becomes a concatenation of the new rule name and the names of all base classes.

class MyStyles extends css.StyleDefinition
{
redFG = this.$class({ color: "red" })
whiteBG = this.$class({ backgroundColor: "white" })

emphasized = this.$class({
"++": [this.redFG, this.whiteBG],
fontWeight: 700
})
}

This will translate to the following CSS (in reality, class names are auto-generated):

.redFG { color: red; }
.whiteBG { backgroundColor: white; }
.emphasized.redFG.whiteBG { fontWeight: 700; }

Note that when the MyStyles is activated and the emphasized property is applied to an element, the class name will be not just "emphasized", but "emphasized redFG whiteBG". That is, the following rendering function

let styles = css.activate(MyStyles);
render()
{
return <div className={styles.emphasized.name}>Important stuff</div>
}

will generate the following HTML:

<div className="emphasized redFG whiteBG">Important stuff</div>

CombinedStyleset

The CombinedStyleset type extends the Styleset type with certain properties that provide additional meaning to the styleset and allow building dependent style rules:

  • The "+" property specifies one or more parent style rules. This allows specifying parent rules using a convenient style-property-like notation.
  • Properties with pseudo class names (e.g. :hover) or pseudo element names (e.g. ::after). These properties define a styleset that will be assigned to the selector obtained by using the original styleset's owner followed by the given pseudo class or pseudo element.
  • Properties with names of parameterized pseudo classes (e.g. :nth-child) or parameterized pseudo elements (e.g. ::slotted). These properties contain a tuple, where the first element is the parameter for the selector and the second element is the styleset. These properties define a styleset that will be assigned to the selector obtained by using the original styleset's owner followed by the given pseudo class or pseudo element.
  • Properties with the ampersand symbol (&) that contain arrays of two-element tuples each defining a selector and a style corresponding to this selector. Selectors can use the ampersand symbol to refer to the parent style selector. If the ampersand symbol is not used, the selector will be simply appended to the parent selector.

Functions that return style rules (e.g. $class) accept the CombinedStyleset as a parameter, for example:

class MyStyles extends css.StyleDefinition
{
class1 = this.$class({})
class2 = this.$class({
backgroundColor: "white",
":hover" : { backgroundColor: "grey" },
"&": [
[ "li > &", { backgroundColor: "yellow" } ],
[ this.class1, { backgroundColor: "orange" } ]
]
})
}

This will translate to the following CSS (in reality, class names are auto-generated):

.class2 { backgroundColor: white; }
.class2:hover { backgroundColor: grey; }
li > .class2 { backgroundColor: yellow; }
.class2.class1 { backgroundColor: orange; }

CustomVar_StyleType

CustomVar_StyleType<K>: [IVarRule<K>, ExtendedVarValue<K>] | [string, K, ExtendedVarValue<K>] | IStyleDefinitionClass | IStyleDefinition

The CustomVar_StyleType type represents a custom CSS property name and value that are used to define custom properties in a Styleset. This object is used in conjunction with the "--"" property of the Styleset type.

CustomVar_StyleType objects should be mostly used to override custom properties that have previously been defined at the top-level using the $var function. That way you can have a "global" value of a custom property and assign a different value to it under a certain CSS selector.

The values of the type can be specified as either a two-item or a three-item tuple or as style definition class or style definition object.

The two-item tuple is used with a previously defined custom CSS property represented by an IVarRule object:

  • The first item is the IVarRule object.
  • The second item is the value

The three-item array allows explicitly specifying the custom CSS property name:

  • The first item is a string - the name of the custom CSS property. If the name is not prefixed with two dashes they will be added automatically.
  • The second item is the name of a non-custom CSS property whose type determines the type of the custom property value.
  • The third item is the value

If a style definition class or style definition object are specified, then all custom properties defined in this style definition with their values are inserted into the styleset. If the style definition is not processed yet, it is processed right away.

Use the CustomVar_StyleType type in the following manner:

class MyStyles extends css.StyleDefinition
{
// define global custom CSS property and re-define its value under "brown" class.
mainColor = this.$var( "color", "black");
brown = this.$class({ "--": [ [this.mainColor, "brown"] ] })

// define custom CSS property with the given name under "blue" class.
blue = this.$class({ "--": [ ["different-color", "color", "blue"] ] })

// take all custom CSS properties from the given theme.
yellow = this.$class({ "--": [ YellowTheme ] })
}

class YellowTheme extends css.StyleDefinition
{
bg = this.$var( "color", "yellow");
fg = this.$var( "color", "brown");
link = this.$var( "color", "orange");
}

This is equivalent to the following CSS:

:root { --MyStyles_mainColor: black; }
.brown { --MyStyles_mainColor: brown; }
.blue { --different-color: blue; }
.yellow
{
--bg: yellow;
--fg: brown;
--link: orange;
}

Type parameters

ExtendedIStyleset

ExtendedIStyleset: { [ K in keyof IStyleset]?: ExtendedProp<IStyleset[K]> }

The ExtendedBaseStyleset type maps all CSS properties defined in the IStyleset interface to the "extended" versions of their types. These extended types are defined by adding basic keywords (e.g. "unset", "initial", etc.) as well as [[StringProxy]] and ICustomVar to the type that is defined in the IStyleset interface.

ExtendedVarValue

ExtendedVarValue<K>: ExtendedProp<VarValue<K>>

The VarValueType generic type defines the type of the value that can be assigned to the custom CSS property using the generic type K as its template.

Type parameters

MappedSyntaxTypes

MappedSyntaxTypes<T>: { [ i in keyof T]: T[i] extends SyntaxKey ? ISyntaxTypeStyleset[T[i]] : never }

Type that maps a tuple type with syntax keys to a tuple type with corresponding syntax types. For example, it will map type ["<color>", "<length>"] to type [CssColor, CssLength]. This type is used when defining parameters for the paint CSS function.

Type parameters

ParentClassType

ParentClassType: string | IClassRule | IClassNameRule

Represents types that can be used to inherit from an already defined CSS class. This type is used in the "++" property of the CombinedClassStyleset type, which allows CSS classes to include definitions of other CSS classes.

StringStyleset

StringStyleset: {}

The StringStyleset type maps CSS properties including custom properties to the string values.

Type declaration

  • [K: string]: string | null | undefined

Styleset

Styleset: ExtendedIStyleset & { --?: CustomVar_StyleType[] }

Type representing a collection of style properties and their values. In addition to the properties representing the standard CSS styles, this type also includes the "--" property, which is an array of CustomVar_StyleType objects each specifying a value for a single custom property.

SyntaxKey

SyntaxKey: keyof ISyntaxTypeStyleset & string

Helper type describing keys of the ISyntaxTypeStyleset interface.

VarTemplateName

VarTemplateName: keyof IVarTemplateStyleset

The VarTemplateName type defines the keys (strings) that can be used as templates for defining custom CSS properties using the $var function.

VarValue

VarValue<K>: IVarTemplateStyleset[K]

The VarValueType generic type defines the type of the value that can be assigned to the custom CSS property using the generic type K as its template.

Type parameters