CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-unocss--preset-attributify

Attributify preset for UnoCSS that enables using utility classes as HTML attributes rather than class names.

Pending
Overview
Eval results
Files

preset-configuration.mddocs/

Preset Configuration

Core preset function that sets up attributify mode with comprehensive configuration options for UnoCSS.

Capabilities

Main Preset Function

Creates and configures the UnoCSS preset for attributify mode.

/**
 * Creates a UnoCSS preset that enables attributify mode
 * @param options - Configuration options for the preset
 * @returns UnoCSS preset configuration object
 */
function presetAttributify(options: AttributifyOptions = {}): Preset;

/**
 * Default export - same as presetAttributify
 */
const presetAttributify: (options: AttributifyOptions = {}) => Preset;

Usage Examples:

import { defineConfig } from 'unocss'
import { presetAttributify } from '@unocss/preset-attributify'

// Basic usage with defaults
export default defineConfig({
  presets: [
    presetAttributify()
  ]
})

// With custom options
export default defineConfig({
  presets: [
    presetAttributify({
      prefix: 'ui-',
      prefixedOnly: true,
      strict: false,
      nonValuedAttribute: true,
      ignoreAttributes: ['placeholder', 'alt'],
      trueToNonValued: false
    })
  ]
})

Configuration Options

All configuration options for customizing attributify behavior.

interface AttributifyOptions extends PresetOptions {
  /**
   * Only generate CSS for attributify or class
   * When true, utilities will only be generated from attributify syntax, not regular classes
   * @default false
   */
  strict?: boolean;

  /**
   * Prefix for attribute names
   * All attributify attributes must start with this prefix
   * @default 'un-'
   */
  prefix?: string;

  /**
   * Only match for prefixed attributes
   * When true, only attributes starting with the prefix will be processed
   * @default false
   */
  prefixedOnly?: boolean;

  /**
   * Support matching non-valued attributes
   * Allows attributes without values (e.g., <div mt-2 />)
   * @default true
   */
  nonValuedAttribute?: boolean;

  /**
   * A list of attributes to be ignored from extracting
   * These attributes will not be processed as utilities
   */
  ignoreAttributes?: string[];

  /**
   * Non-valued attributes will also match if the actual value represented in DOM is true
   * This option exists for supporting frameworks that encode non-valued attributes as true
   * Enabling this option will break rules that end with 'true'
   * @default false
   */
  trueToNonValued?: boolean;
}

Configuration Examples:

// Strict mode - only process attributify, not regular classes
presetAttributify({
  strict: true
})

// Custom prefix
presetAttributify({
  prefix: 'tw-',
  prefixedOnly: true  // Only process attributes starting with 'tw-'
})

// Custom ignored attributes
presetAttributify({
  ignoreAttributes: ['placeholder', 'fill', 'opacity', 'data-testid']
})

// Framework compatibility
presetAttributify({
  trueToNonValued: true  // For frameworks that set boolean attributes to "true"
})

Default Values

The preset applies these default values in the main preset function:

// Applied by the main preset function
const PRESET_DEFAULTS = {
  strict: false,
  prefix: 'un-',
  prefixedOnly: false,
  nonValuedAttribute: true,
  ignoreAttributes: defaultIgnoreAttributes
  // Note: trueToNonValued has no default in preset function,
  // but individual functions default it to false
}

Preset Return Value

The preset function returns a complete UnoCSS preset configuration:

interface Preset {
  name: '@unocss/preset-attributify';
  enforce: 'post';
  variants: VariantObject[];
  extractors: Extractor[];
  options: AttributifyOptions;
  autocomplete: {
    extractors: AutoCompleteExtractor[];
  };
  extractorDefault?: false;
}

Example Return Structure:

{
  name: '@unocss/preset-attributify',
  enforce: 'post',
  variants: [variantAttributify(options)],
  extractors: [extractorAttributify(options)],
  options: resolvedOptions,
  autocomplete: {
    extractors: [autocompleteExtractorAttributify(options)]
  },
  extractorDefault: options.strict ? false : undefined
}

Install with Tessl CLI

npx tessl i tessl/npm-unocss--preset-attributify

docs

autocomplete-support.md

html-extraction.md

index.md

preset-configuration.md

typescript-definitions.md

variant-processing.md

tile.json