DEV Community

FSCSS tutorial
FSCSS tutorial

Posted on • Edited on

πŸ”₯ New in FSCSS: Conditional @event + Debug exec()

πŸ”₯ New in FSCSS: Conditional @event + Debug exec()

Now you can add logic in CSS & debug values live!
num() used to change string to numbers for calculation.
@event for defining a function.

@event scaleSize(e) {
  if e >= 8 { 
    return| num(8*2)em 
    exec(_log, ">=8: Scaling to 16em for optimal readability")
    /* Caps at 16em for larger inputs */
  }
  el-if e < 8 { 
    return| num(8/5*8)em  
    exec(_log, "<8: Scaling to ~10.24em for compact views");
    /* Scales down to ~10.24em for smaller inputs */
  }
  el { 
    return| num(8)em
    exec(_warn, "No match: Using default 8em – check your input value");
      /* Default fallback */
  }
}

.card {
  width: @event.scaleSize(8);   /* Outputs 16em */
  height: @event.scaleSize(7);  /* Outputs ~10.24em */
  transition: all 0.3s ease;    /* Smooth it out */
}
Enter fullscreen mode Exit fullscreen mode

Compile

βœ… Conditions: ==, >=, <=, >, <
βœ… Debug: _log, _warn, _info, _error
Example: Logging a variable during stylesheet processing or event triggers.

$greetings: Hello, World!;  /* Define a string var */

/* Basic logging */
exec(_log, $greetings);       /* Outputs: Hello, World! to console */

/* With context */
exec(_info, "Var value:  $greetings");  /* Outputs: Var value: Hello, World! */

/* Warning for potential issues */
exec(_warn, "Deprecated var used:  $greetings");  /* Yellow warning in console */

/* Error for critical failures */
exec(_error, "Failed to compute: $greetings");   /* Red error in console */
Enter fullscreen mode Exit fullscreen mode

Compile

Browser Support: Works in modern browsers with the FSCSS JS loader (e.g., <script src="https://cdn.jsdelivr.net/npm/fscss@1.1.7/e/exec.min.js" async></script>). Check the console after page load or event fire.
For production:
Compile to normal css via fscss npm package:

npm intall -g fscss
fscss yourfile.fscss yourfile.css 
Enter fullscreen mode Exit fullscreen mode

CSS is evolving, and with FSCSS, you're not just stylingβ€”you're engineering. Got questions, bugs, or cool use cases? Hit up the DEV Community thread or Xβ€”let's iterate together! πŸ”§πŸ’»

Top comments (0)