Colours and Tailwind
Colours Helper
The Colours class provides helper methods for color manipulation and generation.
Namespace: Medialight\Textstem\Helpers
getColourSetFromStr
Generates a background and foreground color set from a string.
public static function getColourSetFromStr($str = 'undefined'): array
Parameters:
$str(string): The string to generate colors from. Default is 'undefined'.
Returns:
- (array): An array containing the background color and foreground color.
colourFromStr
Generates a color from a string.
public static function colourFromStr($str): string
Parameters:
$str(string): The string to generate a color from.
Returns:
- (string): The generated color in hexadecimal format.
getContrastColor
Determines the best contrast color (black or white) for a given background color.
public static function getContrastColor($hexcolor): string
Parameters:
$hexcolor(string): The hexadecimal color to find a contrast for.
Returns:
- (string): Either 'black' or 'white' depending on which provides better contrast.
hsl2rgb
Converts HSL (Hue, Saturation, Lightness) color values to RGB hexadecimal format.
public static function hsl2rgb($H, $S, $V): string
Parameters:
$H(float): The hue value (0-1).$S(float): The saturation value (0-1).$V(float): The lightness/value (0-1).
Returns:
- (string): The color in hexadecimal RGB format.
hueFromStr
Generates a hue value from a string using a hash function.
public static function hueFromStr($tstr): int
Parameters:
$tstr(string): The string to generate a hue from.
Returns:
- (int): The generated hue value.
colourSet
Returns a predefined set of colors.
public static function colourSet(): array
Returns:
- (array): An array of hexadecimal color values.
textColor
Determines the best text color (black or white) based on RGB values.
public static function textColor($r, $g, $b): string
Parameters:
$r(int): The red component (0-255).$g(int): The green component (0-255).$b(int): The blue component (0-255).
Returns:
- (string): Either '#000' (black) or '#FFF' (white) depending on which provides better contrast.
TailwindGenerator Helper
The TailwindGenerator class provides helper methods for generating Tailwind CSS classes.
Namespace: Medialight\Textstem\Helpers
widthClasses
Generates a string of tailwind CSS classes for column widths based on the given widths and prefixes.
public static function widthClasses(...$widths)
Parameters:
$widths(int): The column widths for which the CSS classes should be generated. Multiple widths can be specified as separate arguments.
Returns:
- (string): The generated CSS classes as a space-separated string.
spanClasses
Generates a string of tailwind CSS classes for column spans based on the given widths.
public static function spanClasses(...$widths)
Parameters:
$widths(int): The column widths for which the CSS classes should be generated. Multiple widths can be specified as separate arguments.
Returns:
- (string): The generated CSS classes as a space-separated string.
colSpanToWidth
Converts a column span value to a corresponding tailwind width class. Eg colspan of "12" corresponds to "w-full".
public static function colSpanToWidth($span, $prefix = '')
Parameters:
$span(int): The column span value to be converted.$prefix(string): Optional prefix to be prepended to the CSS width class.
Returns:
- (string): The CSS width class corresponding to the given column span value.
formatForSelectOptions
Formats an array for select options.
public function formatForSelectOptions($arr)
Parameters:
$arr(array): The array to format.
Returns:
- (array): The formatted array.