Utility Sass @ 0.1.0-alpha.4
    Preparing search index...

    Class FeatureCheck<T_CustomCheckerSlug, T_CustomChecker>

    Utility class that uses client-side JS to test for JS and CSS feature compaibility. Updates root element class names accordingly.

    This class is meant to be used client-side to assess local CSS & JS compatibility.

    The simplest way to use this class is by importing:

    import { FeatureCheck } from '@maddimathon/utility-sass';
    

    and running one line:

    // run the checks and update class names
    new FeatureCheck().check();

    The check can also be customized — this customization can mark some features as never available and add on custom feature checks:

    const opts: Partial<FeatureCheck.CheckerOpts> = {

    // this skips the test and always disables this feature
    whereSelector: false,
    };

    const customChecks: FeatureCheck.CustomChecker[] = [
    {
    slug: 'backgroundGradient',
    test: () => FeatureCheck.supportsCSS(
    'background: linear-gradient( to right, red, blue )'
    ),
    },
    {
    slug: 'exampleFeature',
    test: false,
    },
    ];

    // run the checks and update class names
    new FeatureCheck( opts, customChecks ).check();

    0.1.0-pre.0

    Type Parameters

    Index

    Constructors

    Properties

    customChecks: T_CustomChecker[]

    Completed copy of the built-in check options.

    See FeatureCheck.constructor for details.

    Completed copy of the built-in check options.

    See FeatureCheck.CheckerOpts for details.

    root: Element | null

    The root element used for adding and removing feature-check classes.

    See FeatureCheck.constructor for details.

    Accessors

    • get DEFAULT_OPTS(): {
          aspectRatio: true;
          atProperty: true;
          backgroundFixed: true;
          displayContents: true;
          focusVisible: true;
          focusWithin: true;
          hasSelector: true;
          subgrid: true;
          whereSelector: true;
      }

      Default value for FeatureCheck.opts.

      Returns {
          aspectRatio: true;
          atProperty: true;
          backgroundFixed: true;
          displayContents: true;
          focusVisible: true;
          focusWithin: true;
          hasSelector: true;
          subgrid: true;
          whereSelector: true;
      }

    Methods

    • Experimental

      Builds a feature-check class name that represents the result of a compatibility test.

      Type Parameters

      • T_Slug extends string

      Parameters

      • featureSlug: T_Slug

        Feature slug used to conduct the test.

      • value: boolean

        The version of the class to get. If true, class indicates that the feature is enabled; otherwise, class indicates the feature is unavailable.

      Returns string

    • Experimental

      Checks for CSS rule support.

      Parameters

      • supports: string

        A valid test param for the CSS @supports() rule.

      Returns boolean

    • Experimental

      Runs all the checks and sets root element classes accordingly.

      Returns void

    • Experimental

      Checks for aspect-ratio css property support.

      Returns void

          protected aspectRatio() {

      this.setFeature(
      'aspectRatio',
      FeatureCheck.supportsCSS( 'aspect-ratio: 1 / 1' ),
      );
      }
    • Experimental

      Checks for css @property at-rule support.

      Returns void

          protected atProperty() {
      this.setFeature( 'atProperty', !!window.CSSPropertyRule );
      }
    • Experimental

      Checks for background-attachment: fixed css rule support.

      Returns void

          protected backgroundFixed() {

      this.setFeature(
      'backgroundFixed',
      FeatureCheck.supportsCSS( 'background-attachment: fixed' ),
      );
      }
    • Experimental

      Checks for display: contents css rule support.

      Returns void

          protected displayContents() {

      this.setFeature(
      'displayContents',
      FeatureCheck.supportsCSS( 'display: contents' ),
      );
      }
    • Experimental

      Checks for :focus-visible css selector support.

      Returns void

          protected focusVisible() {

      this.setFeature(
      'focusVisible',
      FeatureCheck.supportsCSS( 'selector( a:focus-visible )' ),
      );
      }
    • Experimental

      Checks for :focus-within css selector support.

      Returns void

          protected focusWithin() {

      this.setFeature(
      'focusWithin',
      FeatureCheck.supportsCSS( 'selector( a:focus-within )' ),
      );
      }
    • Experimental

      Checks for :has() css selector support.

      Returns void

          protected hasSelector() {

      this.setFeature(
      'hasSelector',
      FeatureCheck.supportsCSS( 'selector( :has( a ) )' ),
      );
      }
    • Experimental

      Set a feature slug's class names on the FeatureCheck.root element.

      Parameters

      • featureSlug: T_CustomCheckerSlug | Checker | "js"

        Feature result to set.

      • value: boolean

        If true, the feature is marked as available. Otherwise it is marked unavailable.

      • InternalignorePrefix: boolean = false

        Whether to exclude the 'js__' prefix. This is only used to set the 'js' and 'no-js' classes.

      Returns void

    • Experimental

      Checks for grid-template-columns: subgrid css rule support.

      Returns void

          protected subgrid() {

      this.setFeature(
      'subgrid',
      FeatureCheck.supportsCSS( 'grid-template-columns: subgrid' ),
      );
      }
    • Experimental

      Checks for :where() css selector support.

      Returns void

          protected whereSelector() {

      this.setFeature(
      'whereSelector',
      FeatureCheck.supportsCSS( 'selector( :where( a ) )' ),
      );
      }