I have made a custom component that displays the theme colors and the named colors defined in Tailwind as a fun experiment.
I build a list of colors in the transformHook handler (see below). The color names are currently hard coded, but I was wondering if there is a way to get the theme colors from the rw object?
const transformHook = (rw) => {
const themeColors = ['Brand', 'Accent', 'Surface', 'Text'];
const namedColors = [
'Red', 'Orange', 'Amber', 'Yellow', 'Lime', 'Green', 'Emerald',
'Teal', 'Cyan', 'Sky', 'Blue', 'Indigo', 'Violet', 'Purple',
'Fuchsia', 'Pink', 'Rose', 'Slate', 'Gray', 'Zinc', 'Neutral'
];
const brightness = ['50','100','200','300','400','500','600','700','800','900','950'];
let selectedColors = [];
let separatorPos = -1;
if (rw.props.themeColors) selectedColors = selectedColors.concat(themeColors);
if (rw.props.namedColors) selectedColors = selectedColors.concat(namedColors);
if (rw.props.themeColors && rw.props.namedColors) separatorPos = themeColors.length;
const colorGroups = [];
let pos = 0;
selectedColors.forEach((colorName) => {
const swatches = [];
brightness.forEach((variant) => {
swatches.push(`bg-${colorName.toLowerCase()}-${variant}`);
});
colorGroups.push({title: colorName, swatches: swatches, separator: pos === separatorPos});
pos++;
});
rw.setProps({
hasColors: colorGroups.length > 0,
colorGroups: colorGroups,
brightness: brightness
});
}
exports.transformHook = transformHook;
My test project is here: elementsapp://downloadDocument/kfGvJNvF8Csi
