renderAttributes method

String renderAttributes({
  1. String? style,
})

---------------- Helper ---------------- Converts ID + directives + optional style to HTML attributes

Implementation

String renderAttributes({String? style}) {
  final attrs = <String>[];

  // Always include ID
  if (id.isNotEmpty) attrs.add('id="$id"');

  // Include all Alpine-style directives
  directives.forEach((key, value) {
    if (value.isEmpty) {
      attrs.add(key);
    } else {
      attrs.add('$key="$value"');
    }
  });

  // Include inline style if provided
  if (style != null && style.isNotEmpty) {
    attrs.add('style="$style"');
  }

  return attrs.join(' ');
}