colorTW function

Color? colorTW(
  1. List<String> params
)

Implementation

Color? colorTW(List<String> params) {
  for (var element in params.reversed) {
    // Color name has to start with 'text-'
    if (!element.startsWith('text-')) {
      continue;
    }

    // The input color string
    String input = element.replaceFirst('text-', '');

    // If the color name is not in the tailwindColors map, continue
    String colorName = input.split('-').first;
    if (!tailwindColors.containsKey(colorName)) {
      continue;
    }

    // Return if the color is not a shade
    if (!input.contains('-')) {
      return HexColor.fromHex(tailwindColors[colorName]);
    }

    // Return color with shade
    int colorShade = int.parse(input.split('-').last);
    return HexColor.fromHex(tailwindColors[colorName][colorShade]);
  }

  return null;
}