Tailwind docs say that we should not pass dynamic pieces of class name as props because it will not work, and well it does not.
There are other options. One of them is to predefine object with actual tailwind classes and then passing a prop to pick a set of classes eg:
const colorVariants = {
blue: 'bg-blue-600 hover:bg-blue-500',
red: 'bg-red-600 hover:bg-red-500',
}
But that is not as flexible as I would like it to be so I came up with falling back to inline styles like so:
const props = defineProps({
headerPadding: {
type: String,
required: false,
default: '10px'
},
contentPadding: {
type: String,
required: false,
default: '10px'
},
});
const styles = computed(() => {
return {header: `padding: ${props.headerPadding}`};
});
And then I do
<div :style="styles.header" class="flex">Header</div>
Now this works perfectly fine. I am just wondering if there is anything super bad about this approach or if there is a good reason to avoid it?