Replies: 2 comments 6 replies
-
What styles would these variants to have? Would |
Beta Was this translation helpful? Give feedback.
5 replies
-
After some testing , i find the second way won't work (set the css custom variable) and first way won’t ideal. turn out i have do something like that (Angular in example): In tailwind.css.config const colors = require('tailwindcss/colors');
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
colors: {
warning: {
main: colors.orange['700'],
},
},
}
}; In my style.css @tailwind base;
@tailwind components;
@tailwind utilities;
:root {
--colors-warning: theme(colors.warning.main);
} In my Angular service import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class RootCssVariablesService {
rootStyles: CSSStyleDeclaration
constructor() {
this.rootStyles = getComputedStyle(document.documentElement)
}
getVariable(name: string) {
return this.rootStyles.getPropertyValue(`--${name}`)
}
} In my component import 'wired-elements/lib/wired-card';
import { Component, Attribute, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import {RootCssVariablesService} from "../root-css-variables.service"
@Component({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
selector: 'ngx-card',
standalone: true,
providers: [RootCssVariablesService],
imports: [CommonModule],
template: `
<wired-card [attr.fill]="fill">
<ng-content></ng-content>
</wired-card>
`,
})
export class CardComponent {
constructor(public rootCssVariablesService:RootCssVariablesService) {}
get fill() {
return this.rootCssVariablesService.getVariable("colors-warning")
}
} this way i can resolve tailwind theme value without extra bundle size. and provide to a way to library consumer customise theme by extend tailwind css theme |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Recently , i want to use tailwind CSS to theme my component library backed some web components
So far it make me easily and simple coz i don't have to mange my styled component name / handle CSS conflict
But i got a problems there, it the web components it have one of component that not support styling with normal CSS
To be specific, it was
wired-card
from wired-componentyou can check my storybook here
as you can see in order to set background (let say i want set to red), it need thing like
so my question is, how do i make fill attributes integrated with tailwindcss ? so i can use thing like
theme(red.500)
instead of hardcode color.the only way i can get on documentation was referencing in javascript
but the ideally what i want was thing like
and under my react component, i just dynamic set style according to variant.
Beta Was this translation helpful? Give feedback.
All reactions