clsx 0.1.1 copy "clsx: ^0.1.1" to clipboard
clsx: ^0.1.1 copied to clipboard

An unofficial Dart port of the popular JavaScript utility 'clsx' for constructing className strings conditionally.

clsx for dart #

Build Pub License GitHub stars style: very good analysis

An unofficial Dart port of the popular JavaScript utility clsx for constructing className strings conditionally.

Features #

This Dart package replicates the core functionality of the JavaScript clsx library, allowing you to:

  • Conditionally join strings as CSS class names.
  • Support nested lists and maps for dynamic class application.
  • Ignore null or empty values.

Usage #

Here's a simple example of how to use clsx in Dart:

import 'package:clsx/clsx.dart';

void main() {
  String activeClass = 'active';
  bool isDisabled = false;

  final buttonClasses = clsx([
    'btn',
    activeClass,
    {'btn-disabled': isDisabled},
    ['extra-class', null],
    {'another-class': true},
  ]);

  print(buttonClasses); // Output: 'btn active extra-class another-class'
}

Additional information #

This package is an unofficial port of the JavaScript clsx library developed by Luke Edwards. The goal is to provide a similar, convenient utility for Dart developers.

For more information about the original JavaScript library, please refer to its repository. Contributions, bug reports, and feature requests for this Dart port are welcome. Please file issues on the project's repository.

0
likes
155
points
36
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

An unofficial Dart port of the popular JavaScript utility 'clsx' for constructing className strings conditionally.

Repository (GitHub)
View/report issues

Topics

#web #css #classes #clsx #utility

License

MIT (license)

More

Packages that depend on clsx