Using TailwindCSS with LitElement

  Рет қаралды 3,001

A shot of code

A shot of code

Күн бұрын

Using TailwindCSS with LitElement is something that takes a little bit of configuration. The issues arise firstly due to ShadowDom which means any Tailwind CSS styles specified in the encompassing projects will not pass through this boundary into our LitElement. So we need to add the Tailwind classes explicitly into our LitElement, and in particualr into the 'Styles' property. This property uses Constructable Style Sheets under the hood and so is the best place for us to place our Tailwindwind classes as any duplication issues are taken care for us.
In the method outlined in this video we use an NPM package 'TWLit' that transforms the standard Tailwind generated CSS file into an importable JS equivalent. This way we can simply import the generated classes into our component and also have them updated in realtime whenever they are updated.
Link to TWLit:
www.npmjs.com/package/twlit
Link to working example:
github.com/MarkJamesHoward/TW...
00:00 Intro
01:50 Create Standard TailwindCSS Setup
03:00 Update Package.JSON
03:15 Add TailwindCSS to Package.JSON
04:00 Add TWLit to Package.JSON
05:00 NPM install TWLit
06:00 Run our Setup
06:50 Update LitElement with TWLit import
07:10 Update LitElement with Static Styles of TWLit

Пікірлер: 22
@LordFunzo
@LordFunzo Жыл бұрын
Thank you for this. Haven taken a freshly generated open-wc project, I was able to use the commands you provided and append them to the existing 'npm start' and it works like a charm. I have to say, 'utility class' libraries, which I do consider to be the best way to build the vast majority of websites, are not in keeping with the web-component 'encapsulation' ethos so doing this is a little bit backwards. What you want is that only the styles used by that component included in that component but this approach makes all TW styles used anywhere available to every component (which is not a problem since no TW styles clash). There is also a problem in you wanting to have some styling exposed to the lightDOM like a reset CSS, you need to find some solution of doing this without including the styling twice, once in plain CSS and again in JS.
@bedirhangul9964
@bedirhangul9964 Жыл бұрын
thank you for this video :)
@Ashotofcode
@Ashotofcode 11 ай бұрын
No problem 😊 Cheers Mark
@zeusjean
@zeusjean 3 ай бұрын
Hi, first to say that is an excellent job, thank you very much for sharing, just passing by to ask you if there was a possibility to remove all the background that Tailwind generates the 500 lines of CSS that will inherit each component, because each component that is rendered brings with it the style tag with all that tailwind code.
@Ashotofcode
@Ashotofcode 3 ай бұрын
Possibly - if you remove the tailwind layers then we should not have any boilerplate code created. So these directives here: @tailwind base; @tailwind components; @tailwind utilities;
@kyonas6047
@kyonas6047 Жыл бұрын
for me I am using elm(the programming language that compiles to Javascript and its main job is doing UI ) So I added Tailwind and Daisy UI and just turned off the shadow dom and now its like a normal html tag I am using Lit to do things that need Javascript mostly Web Api(like indexdb and local storage) so yeah I am loving it im using post css but without the lit postcss its somehow working so that's cool
@Ashotofcode
@Ashotofcode Жыл бұрын
Nice I like it! 🙂
@jlo214
@jlo214 Жыл бұрын
Thanks for the demo. Does that mean that each component carries all other components' styles? Or I'm missing something?
@Ashotofcode
@Ashotofcode 11 ай бұрын
Should be no duplication in this case - the constructable style sheets provide this for us. Cheers Mark
@AndrejDaiker
@AndrejDaiker Жыл бұрын
Has anyone got it working with vite js yet?
@Ashotofcode
@Ashotofcode 11 ай бұрын
I need to get my head around Vite - might give it a try! Cheers Mark
@MrJIPO1
@MrJIPO1 6 ай бұрын
There is a new version called twlitme that works for me using vite
@aram5642
@aram5642 Жыл бұрын
I'm doing a similar thing by creating style-only components, and import their static styles into my presentational components, as in: static styles = [AlertStyles.styles, FormStyles.styles, css`...`].
@Ashotofcode
@Ashotofcode Жыл бұрын
Nice I like it 🙂
@davidmaxwaterman
@davidmaxwaterman Жыл бұрын
Very useful, though demonstrates why I hate build tools 😉
@Ashotofcode
@Ashotofcode Жыл бұрын
fair point 🙂
@martinp7841
@martinp7841 Жыл бұрын
Vanilla CSS...off with the training wheels!
@Ashotofcode
@Ashotofcode Жыл бұрын
fair point :-)
@LordFunzo
@LordFunzo Жыл бұрын
Utility class libraries are not training wheels, they are all you need almost every time and you can still write CSS if needed. Build tools which only include what you use keeps down your CSS payload to a minimum and documentation is fantastic.
@stanzy237
@stanzy237 Жыл бұрын
i will use pretty useful but you need some Readme
@Ashotofcode
@Ashotofcode 11 ай бұрын
Will check it out, cheers Mark
@ameperdue6953
@ameperdue6953 9 ай бұрын
Your solution is just way too *KLUNKY* . Why not use *ONLY* global stylesheets. All css is in one place !
How to create a Web Component using Vanilla JS
17:45
A shot of code
Рет қаралды 66 М.
Lit Labs: Context
14:40
Lit: Simple. Fast. Web Components.
Рет қаралды 7 М.
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 78 МЛН
Женская драка в Кызылорде
00:53
AIRAN
Рет қаралды 353 М.
Git Rebase Visualized
10:46
A shot of code
Рет қаралды 5 М.
Declarative Shadow DOM  - Lit & Astro
7:30
A shot of code
Рет қаралды 1,3 М.
Javascript Interview Question | Microtask vs Macrotask Queues
2:45
How to build a carousel in Lit
15:08
Lit: Simple. Fast. Web Components.
Рет қаралды 10 М.
Web Component Properties and Attributes
16:14
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 7 М.
Git Fetch Visualized
7:22
A shot of code
Рет қаралды 1,4 М.
Git Detach Explained
7:18
A shot of code
Рет қаралды 1,7 М.
Creating a Modern Webpack 5, TypeScript, and TailwindCSS Web Project
20:20
Learn Lit and Web Components with Elliott Marquez
1:26:04
Kelvin Omereshone
Рет қаралды 3,3 М.
LA  CINTA NUESTRA HISTORIA
0:59
Santi
Рет қаралды 8 МЛН
Funny Escalator #katebrush #shorts
0:11
Kate Brush
Рет қаралды 3,8 МЛН
Amazing! Taiwanese Giant Watermelon Juice - Fruit Cutting Skills
0:47
Foodie Camp 푸디캠프
Рет қаралды 56 МЛН
ОРЕЛ который 20 ЛЕТ летал с GPS трекером 😱 #Shorts
0:28
Когда вода попадает в нос при плавании
0:35
Silver Swim - Школа плавания
Рет қаралды 2,9 МЛН
Не уступила место беременной и начались роды 😮
0:49
Фильмы I Сериалы
Рет қаралды 1,1 МЛН