This library provides a set of utilities extending the csstype
package to help you write typed CSS in TypeScript.
Currently, there's basic support for the following W3C standards:
- CSS Conditionals Level 3 (
css-conditional-3
): Editor's Draft, CRS - CSS Media Queries Level 5 (
mediaqueries-5
): Editor's Draft, WD
npm install @neoncitylights/css-types
Auto-generated API documentation is available.
Note: The public API below is an excerpt and shows the main symbols that a developer is likely to use.
fn
: # cssSupports(property, value): boolean • source, docsfn
: # matchMediaFeature(mediaFeature, value): MediaQueryList • source, docsT
: # cssSupports.CSSProperty • source, docsT
: # cssSupports.CSSPropertyValue • source, docsT
: # matchMedia.MqFeature • source, docsT
: # matchMedia.MqFeatureValue • source, docsI
: # matchMedia.MediaQueries • source, docs
Using TypeScript, you can receive type intelliSense, which provides autocomplete suggestions for:
- CSS property names and values (through
csstype
) - Media feature names (e.g
prefers-color-scheme
,aspect-ratio
)
import { matchMediaFeature, cssSupports } from '@neoncitylights/css-types';
// equivalent to window.matchMedia('(prefers-color-scheme: dark)');
const userPrefersDark: MediaQueryList = matchMediaFeature('prefers-color-scheme', 'dark');
// TypeScript support, which provides strongly typed CSS property
// names and values using the `csstype` package
const supportsGrid: boolean = cssSupports('display', 'grid');
const supportsFlex: boolean = cssSupports('display', 'flex');
This library is licensed under the MIT License.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.