-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
index.html
1090 lines (998 loc) 路 41.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Quick Start"
date: 2023-03-07T16:00:58+02:00
draft: false
main_title: "Quick Start"
subheading: ""
seo_title: "Install a free Tailwind CSS components library"
description: "Install TW elements via npm, via command line, via CDN or download a free .zip package. Use our open source Tailwind CSS components for free."
image: "https://tecdn.b-cdn.net/img/components-big.jpg"
video: "https://www.youtube.com/watch?v=-GmnyjgI4Jc&ab_channel=Keepcoding"
url: "docs/standard/getting-started/quick-start/"
menu:
gettingstarted:
name: "Quick start"
weight: 1
---
<div class="flex flex-row">
<!-- <div class="basis-7/12"> -->
<div class="w-full">
<a href="https://youtu.be/3rx9VuIry_A">
<img
src="https://mdbootstrap.com/img/tailwind-elements/quick-start/quick-start.webp"
alt=""
class="mb-5 w-[460px] rounded-lg border lg:float-right lg:ml-2 lg:w-[380px]"
/></a>
<p class="mb-2">
TW elements is a plugin that extends the functionality of the library with
many interactive components.
</p>
<p class="mb-2">
In some dynamic components (like dropdowns or modals) we add custom
JavaScript. However, they do not require any additional installation, all
the necessary code is always included in the example and copied to any
Tailwind project - it will work.
</p>
<div
class="mt-5 overflow-hidden rounded-md border-l-[6px] border-solid border-gray-400 bg-gray-100 p-4 dark:border-gray-300 dark:bg-gray-300/30 ">
<strong>Note:</strong> If you need more comprehensive support, we
recommend you our tutorials, which will introduce you step by step to our
library, its entire environment and Tailwind CSS itself.
<div class="mt-3">
<a
href="/learn/te-foundations/basics/introduction/"
class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
Start learning
</a>
</div>
</div>
</div>
<!-- <div class="w-full basis-5/12 p-2">
{{< youtube -GmnyjgI4Jc >}}
</div> -->
</div>
<hr class="my-10" />
<div class="w-full">
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="formats"
data-te-spy-item>
TW elements formats
</h2>
<p class="mb-6">
TW elements, in order to meet the new, modular approach, allows the use of
<code>ES</code> and <code>UMD</code> formats. These formats will differ in
the way components are initialized and will be used in different cases.
</p>
<h3 class="mb-3 font-bold">When to use ES or UMD format?</h3>
<p>If your application:</p>
<ol class="mb-2 ml-8 list-decimal">
<li>is based on <code>modules</code></li>
<li>uses <code>bundler</code> functionality</li>
<li>needs <code>treeshaking</code></li>
</ol>
<p class="mb-6">
the <code>ES</code> format will be most suitable for you, otherwise
<code>UMD</code> is the way to go.
</p>
<h3 class="mb-3 font-bold">
What is the difference between TW elements ES and UMD formats?
</h3>
<p class="mb-6">
In short, the way to initialize components. In order to allow bundlers to
perform proper treeshaking, we have moved component initialization to the
<code>initTE</code> method. TW elements in <code>UMD</code> format will work
without adding more elements, but will lack treeshaking. TW Elements in
<code>ES</code> format, on the other hand, allows components to be used as
separate modules, resulting in the much smaller build size.
</p>
<h3 class="mb-3 font-bold">About the <code>initTE</code> method</h3>
<p>
To use the initTE method, you need to import it from the
<code>tw-elements</code>, same as for components. You can provide a second
argument that will be an object with options that you want to pass to the
init method. The options object can contain the following properties:
</p>
<ul class="mb-6 mt-3 list-disc">
<li class="ml-6">
<code>allowReinits</code> - by default it's value is set to
<code>false</code>. By changing the value to <code>true</code>, the
<code>initTE</code> method won't check if components were already
initialized. It can be helpful for example when using the
<code>TW elements</code> package with frameworks that use routing (for
example Vue SPA)
</li>
<li class="ml-6">
<code>checkOtherImports</code> - by default the value is also set to
<code>false</code>. How does it work? If <code>initTE</code> finds a
component that should be inited but has not been passed as an argument
(for example, it finds a data attribute that would suggest that it should
be initialized automatically), it will display a warning in a console. We
encourage to use it in the last invocation of <code>initTE</code> method
because it shows what inits are lacking at the current moment.
</li>
</ul>
<h3 class="mb-3 font-bold">How to use the <code>initTE</code> method?</h3>
<p class="my-3">
Import the method from the <code>tw-elements</code> package inside your
project <code>js</code> file and call it with the components you want to
initialize.
</p>
{{< twsnippet/wrapper "your-js-file.js" "" "mobile" >}}
<!-- prettier-ignore -->
{{< twsnippet/code active=true lang="js" >}}
import { Datepicker, Input, initTE } from "tw-elements";
initTE({ Datepicker, Input }, { allowReinits: true });
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<hr class="my-10" />
<div class="flex flex-row">
<!-- <div class="w-full basis-7/12"> -->
<div class="w-full">
<a href="https://youtu.be/3rx9VuIry_A">
<img
src="https://mdbootstrap.com/img/tailwind-elements/quick-start/npm.webp"
alt=""
class="mb-5 w-[460px] rounded-lg border lg:float-right lg:ml-2 lg:w-[380px]"
/></a>
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="npm"
data-te-spy-item>
NPM
</h2>
<p class="my-3 overflow-hidden">
NPM is a recommended way to work with <b>TW elements</b> and others
libraries.
</p>
<p class="my-3">
Make sure that you have <code>Node.js</code> installed. In order to verify
that, open a <code>command line</code> and type <code>node -v</code>. If
node is installed you should see it's version in a console.
</p>
</div>
<!-- <div class="w-full basis-5/12 p-2">
{{< youtube LvWh9o5sJmI >}}
</div> -->
</div>
<p class="mb-2" id="download-npm-step-1">
1. Before starting the project make sure to install
<a
href="https://nodejs.org/en/"
target="_blank"
class="text-primary-700 dark:text-primary-400"
>Node.js (LTS)</a
>
and
<a
href="https://tailwindcss.com/"
target="_blank"
class="text-primary-700 dark:text-primary-400"
>TailwindCSS</a
>.
</p>
<p class="mb-2">2. Run the following command to install the package via NPM:</p>
<div class="pt-2" id="download-npm-step-2">
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
npm install tw-elements
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
3. TW elements is a plugin and should be included inside
<code>tailwind.config.js</code>. It is also recommended to extend the
<code>content</code> array with a js files pattern that loads dynamic
component classes. The final version of the config file should look like this:
</p>
<div class="pt-2" id="download-npm-step-3">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "tailwind.config.js" "" "mobile" >}}{{< twsnippet/code active=true lang="JavaScript" >}}
module.exports = {
content: [
"./src/**/*.{html,js}",
"./node_modules/tw-elements/dist/js/**/*.js"
],
plugins: [require("tw-elements/dist/plugin.cjs")],
darkMode: "class"
};
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
4. Include the following JavaScript file before the end of the body element.
Keep in mind that the path to the file may be different depending on the file
structure of your project.
</p>
<div class="pt-2" id="download-npm-step-4">
{{< twsnippet/wrapper "index.html" "" "mobile" >}}
<!-- prettier-ignore -->
{{< twsnippet/code active=true lang="HTML" >}}
<script
type="text/javascript"
src="../node_modules/tw-elements/dist/js/tw-elements.umd.min.js"></script>
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
Now, the library is ready to use and available via the global
<code>te</code> variable.
</p>
<hr class="my-10" />
<div class="flex flex-row">
<!-- <div class="w-full basis-7/12"> -->
<div class="w-full">
<a href="https://youtu.be/ik5pzsA0KOo">
<img
src="https://mdbootstrap.com/img/tailwind-elements/quick-start/mdb-go.webp"
alt=""
class="mb-5 w-[460px] rounded-lg border lg:float-right lg:w-[380px]"
/></a>
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="go"
data-te-spy-item>
MDB GO / CLI
</h2>
<p class="mb-2">
Create, deploy and host anything <u>with a single command.</u>
</p>
</div>
<!-- <div class="w-full basis-5/12">
{{< youtube Ou80DOZCzOg >}}
</div> -->
</div>
<p class="mb-2 mt-4">
1. To start using MDB GO / CLI install it with one command:
</p>
<div class="pt-2" id="download-mdbgo-step-1">
{{< twsnippet/wrapper "terminal" "!bg-[#BB2E3E] !text-white dark:!bg-rose-300 dark:!text-rose-900" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
npm install -g mdb-cli
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-4">2. Log into the CLI using your MDB account:</p>
<div class="pt-2" id="download-mdbgo-step-2">
{{< twsnippet/wrapper "terminal" "!bg-[#4A24AA] !text-white dark:!bg-violet-300 dark:!text-violet-900" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
mdb login
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-4">
3. Initialize a project and choose <strong>TW elements</strong> from the list:
</p>
<div class="pt-2" id="download-mdbgo-step-3">
{{< twsnippet/wrapper "terminal" "!bg-[#4A24AA] !text-white dark:!bg-violet-300 dark:!text-violet-900" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
mdb init tailwind-elements
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-4">
4. Install the dependencies (inside the project directory):
</p>
<div class="pt-2" id="download-mdbgo-step-4">
{{< twsnippet/wrapper "terminal" "!bg-[#BB2E3E] !text-white dark:!bg-rose-300 dark:!text-rose-900" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
npm install
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-4">5. Run the app:</p>
<div class="pt-2" id="download-mdbgo-step-5">
{{< twsnippet/wrapper "terminal" "!bg-[#BB2E3E] !text-white dark:!bg-rose-300 dark:!text-rose-900" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
npm start
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-4">6. Publish when you're ready:</p>
<div class="pt-2" id="download-mdbgo-step-6">
{{< twsnippet/wrapper "terminal" "!bg-[#4A24AA] !text-white dark:!bg-violet-300 dark:!text-violet-900" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
mdb publish
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<hr class="my-10" />
<div class="flex flex-row">
<div class="w-full">
<a href="https://youtu.be/8pFn__ol6rA">
<img
src="https://mdbootstrap.com/img/tailwind-elements/quick-start/vite.webp"
alt=""
class="mb-5 w-[460px] rounded-lg border lg:float-right lg:ml-4 lg:w-[380px]"
/></a>
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="vite"
data-te-spy-item>
Vite
</h2>
<div
class="mb-4 mr-4 overflow-hidden rounded-md border-l-[6px] border-solid border-blue-600 bg-blue-100 p-2.5 dark:text-gray-600">
<strong>Note:</strong> Make sure that you have
<code>Node.js version 16.17.0 + / 18.1.0 +</code> installed. Please update
if your package manager asks for it. If you are expecting issues with
<code>vite.config.js</code> and you don't want to update the npm, try
using the <code>4.3.9</code> version of vite.
</div>
<p class="my-3">
Vite (French word for "fast", pronounced /vit/) is a build tool that aims
to provide a faster and leaner development experience for modern web
projects. <b>TW elements</b> can be imported in Vite applications
according to the following procedure:
</p>
</div>
</div>
<p class="mb-2">
1. Create a new vite project and enter the newly created directory. Pick
<code>Vanilla</code> framework and <code>JavaScript</code> variant. You can
skip this step if you already have it installed.
</p>
<div class="pt-2" id="download-vite-step-1">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
npm create vite@latest my-project
cd my-project
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2">
2. Install tailwind CSS and its dependencies. After that,
<code>init</code> the tailwind with the Tailwind CLI tool to create
<code>tailwind.config.js</code> file.
</p>
<div class="pt-2" id="download-vite-step-2">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
3. Go to the <code>tailwind.config.js</code> file and add paths where your
html files are going to be stored. You can change the
<code>index.html</code> location but make sure to change to
<a
href="https://vitejs.dev/guide/#index-html-and-project-root"
target="_blank"
class="text-primary"
>root folder</a
>
inside the <code>vite.config.js</code> file.
</p>
<div class="pt-2" id="download-vite-step-3">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "tailwind.config.js" "" "mobile" >}}{{< twsnippet/code active=true lang="JavaScript" >}}
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
4. Add the necessary Tailwind directives to your <code>style.css</code> file
to be able to use Tailwind classes on your website. Unless you changed it,
<code>style.css</code> should be in the root directory of your app. You can
also remove the default content of the <code>style.css</code> file if you
want.
</p>
<div class="pt-2" id="download-vite-step-4">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "style.css" "" "mobile" >}}{{< twsnippet/code active=true lang="css" >}}
@import url("https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900&display=swap");
@tailwind base;
@layer base {
html {
@apply text-neutral-800;
}
html.dark {
@apply text-neutral-50;
@apply bg-neutral-800;
}
}
@tailwind components;
@tailwind utilities;
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
5. Link the css file inside the <code>index.html</code>.
</p>
<div class="pt-2" id="download-vite-step-5">
{{< twsnippet/wrapper "index.html" "" "mobile" >}}{{< twsnippet/code active=true lang="HTML" >}}
<head>
...
<link rel="stylesheet" href="style.css" />
...
</head>
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
6. Tailwind should be connected properly to the vite app. If you type the code
bellow, you will see the default vite <code>index.html</code> page (without
any styles if you deleted them from <code>style.css</code>).
</p>
<div class="pt-2" id="download-vite-step-6">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
npm run dev
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">7. Install the <code>tw-elements</code> package.</p>
<div class="pt-2" id="download-vite-step-7">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
npm install tw-elements
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
8. Add js files patterns that loads dynamic component classes to the content
array inside the <code>tailwind.config.js</code>. Extend the default tailwind
classes by adding the <code>TW elements</code> plugin.
</p>
<div class="pt-2" id="download-vite-step-8">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "tailwind.config.js" "" "mobile" >}}{{< twsnippet/code active=true lang="js" >}}
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./index.html",
"./src/**/*.{html,js}",
"./node_modules/tw-elements/dist/js/**/*.js",
],
plugins: [require("tw-elements/dist/plugin.cjs")],
darkMode: "class"
};
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
9. Now you can start working on your app. Since the package.json created by
vite has a type set to <code>module</code>, we are going to use the
<code>ES</code>. Lets try to import some code and see if everything is working
correctly. Don't forget to call the <code>initTE</code> method. The carousel
component should have proper styles, and change the current image after arrow
click or after some delay.
</p>
<div
class="my-4 rounded-md border-l-[6px] border-solid border-blue-600 bg-blue-100 p-2.5 dark:border-white dark:bg-sky-900 ">
<strong>Note:</strong> You can init more than one component at once, for
example:
<code>initTE({ Carousel, Datepicker, Select, Timepicker });</code>
</div>
<div class="pt-2" id="download-vite-step-9">
{{< twsnippet/wrapper "index.html,main.js" "" "mobile" >}}
{{< twsnippet/code active=true lang="html" >}}
<body class="dark:bg-neutral-800">
<div
id="carouselExampleCaptions"
class="relative"
data-te-carousel-init
data-te-carousel-slide>
<div
class="absolute bottom-0 left-0 right-0 z-[2] mx-[15%] mb-4 flex list-none justify-center p-0"
data-te-carousel-indicators>
<button
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide-to="0"
data-te-carousel-active
class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
aria-current="true"
aria-label="Slide 1"></button>
<button
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide-to="1"
class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
aria-label="Slide 2"></button>
<button
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide-to="2"
class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
aria-label="Slide 3"></button>
</div>
<div
class="relative w-full overflow-hidden after:clear-both after:block after:content-['']">
<div
class="relative float-left -mr-[100%] w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
data-te-carousel-active
data-te-carousel-item
style="backface-visibility: hidden">
<img
src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(15).jpg"
class="block w-full"
alt="..." />
<div
class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
<h5 class="text-xl">First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div
class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
data-te-carousel-item
style="backface-visibility: hidden">
<img
src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(22).jpg"
class="block w-full"
alt="..." />
<div
class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
<h5 class="text-xl">Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div
class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
data-te-carousel-item
style="backface-visibility: hidden">
<img
src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(23).jpg"
class="block w-full"
alt="..." />
<div
class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
<h5 class="text-xl">Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button
class="absolute bottom-0 left-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide="prev">
<span class="inline-block h-8 w-8">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.75 19.5L8.25 12l7.5-7.5" />
</svg>
</span>
<span
class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
>Previous</span
>
</button>
<button
class="absolute bottom-0 right-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide="next">
<span class="inline-block h-8 w-8">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M8.25 4.5l7.5 7.5-7.5 7.5" />
</svg>
</span>
<span
class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
>Next</span
>
</button>
</div>
<script type="module" src="/main.js"></script>
</body>
{{< /twsnippet/code >}}
<!-- prettier-ignore -->
{{< twsnippet/code lang="js" >}}
import { Carousel, initTE } from "tw-elements";
initTE({ Carousel }, true ); // set second parameter to true if you want to use a debugger
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<hr class="my-10" />
<div class="flex flex-row">
<div class="w-full">
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="vite-with-bun"
data-te-spy-item>
Vite with Bun
</h2>
<p class="my-3">
Bun is a tool that is designed to replace Node.js in the development of
web applications. The main goal of Bun is to reduce the startup times and
memory usage of created apps. Vite works with a Bun out of the box.
<b>TW Elements</b> can be imported in Vite applications according to the
following procedure:
</p>
</div>
</div>
<p class="mb-2">
1. Make sure to have the
<a
class="text-primary-700 dark:text-primary-400"
href="https://bun.sh/docs/installation"
target="_blank"
>Bun</a
>
installed. You can run the following command to check whether Bun is working
properly:
</p>
<div class="pt-2" id="download-vite-with-bun-step-1">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
bun --version
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="my-2">
If the console is showing the version of Bun it means that the installation
was successful and you can proceed to the next step.
</p>
<p class="mb-2">
2. Create a new vite project and enter the newly created directory. Pick
<code>Vanilla</code> framework and <code>JavaScript</code> variant.
</p>
<div class="pt-2" id="download-vite-with-bun-step-2">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
bun create vite my-project
cd my-project
bun install
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2">
3. Install tailwind CSS and its dependencies. After that,
<code>init</code> the tailwind with the Tailwind CLI tool to create
<code>tailwind.config.js</code> file.
</p>
<div class="pt-2" id="download-vite-with-bun-step-3">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
bun install -D tailwindcss postcss autoprefixer
bunx tailwindcss init -p
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
4. Add the Tailwind directives to your <code>style.css</code> file to be able
to use Tailwind classes on your website.
</p>
<div class="pt-2" id="download-vite-with-bun-step-4">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "style.css" "" "mobile" >}}{{< twsnippet/code active=true lang="css" >}}
@import url("https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900&display=swap");
@tailwind base;
@layer base {
html {
@apply text-neutral-800;
}
html.dark {
@apply text-neutral-50;
@apply bg-neutral-800;
}
}
@tailwind components;
@tailwind utilities;
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
5. Link the css file inside the <code>output.html</code>. We are linking the
<code>output.html</code> file instead of the <code>style.css</code> because
thats where the tailwindcss CLI is going to add the styling classes.
</p>
<div class="pt-2" id="download-vite-with-bun-step-5">
{{< twsnippet/wrapper "index.html" "" "mobile" >}}{{< twsnippet/code active=true lang="HTML" >}}
<head>
...
<link rel="stylesheet" href="output.css" />
...
</head>
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">6. Install the <code>tw-elements</code> package.</p>
<div class="pt-2" id="download-vite-with-bun-step-6">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
bun install tw-elements
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
7. Add js files patterns that loads dynamic component classes to the content
array inside the <code>tailwind.config.js</code>. Extend the default tailwind
classes by adding the <code>TW elements</code> plugin.
</p>
<div class="pt-2" id="download-vite-with-bun-step-7">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "tailwind.config.js" "" "mobile" >}}{{< twsnippet/code active=true lang="js" >}}
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./index.html",
"./src/**/*.{html,js}",
"./node_modules/tw-elements/dist/js/**/*.js",
],
plugins: [require("tw-elements/dist/plugin.cjs")],
darkMode: "class"
};
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
8. Build the <code>output.css</code> file with use of the tailwindcss CLI. You
can also add this command to the <code>package.json</code> file to make it
easier to use.
</p>
<div class="pt-2" id="download-vite-with-bun-step-8">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="plaintext" type="terminal" >}}
bunx tailwindcss -i ./style.css -o ./output.css --watch
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
9. Now you can start working on your app. Copy the code bellow to add a
carousel component to your app. Don't forget to call the
<code>initTE</code> method.
</p>
<div class="pt-2" id="download-vite-with-bun-step-9">
{{< twsnippet/wrapper "index.html,main.js" "" "mobile" >}}
{{< twsnippet/code active=true lang="html" >}}
<body class="dark:bg-neutral-800">
<div
id="carouselExampleCaptions"
class="relative"
data-te-carousel-init
data-te-carousel-slide>
<div
class="absolute bottom-0 left-0 right-0 z-[2] mx-[15%] mb-4 flex list-none justify-center p-0"
data-te-carousel-indicators>
<button
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide-to="0"
data-te-carousel-active
class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
aria-current="true"
aria-label="Slide 1"></button>
<button
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide-to="1"
class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
aria-label="Slide 2"></button>
<button
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide-to="2"
class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
aria-label="Slide 3"></button>
</div>
<div
class="relative w-full overflow-hidden after:clear-both after:block after:content-['']">
<div
class="relative float-left -mr-[100%] w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
data-te-carousel-active
data-te-carousel-item
style="backface-visibility: hidden">
<img
src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(15).jpg"
class="block w-full"
alt="..." />
<div
class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
<h5 class="text-xl">First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div
class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
data-te-carousel-item
style="backface-visibility: hidden">
<img
src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(22).jpg"
class="block w-full"
alt="..." />
<div
class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
<h5 class="text-xl">Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div
class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
data-te-carousel-item
style="backface-visibility: hidden">
<img
src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(23).jpg"
class="block w-full"
alt="..." />
<div
class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
<h5 class="text-xl">Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button
class="absolute bottom-0 left-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide="prev">
<span class="inline-block h-8 w-8">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.75 19.5L8.25 12l7.5-7.5" />
</svg>
</span>
<span
class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
>Previous</span
>
</button>
<button
class="absolute bottom-0 right-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
type="button"
data-te-target="#carouselExampleCaptions"
data-te-slide="next">
<span class="inline-block h-8 w-8">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M8.25 4.5l7.5 7.5-7.5 7.5" />
</svg>
</span>
<span
class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
>Next</span
>
</button>
</div>
<script type="module" src="/main.js"></script>
</body>
{{< /twsnippet/code >}}
<!-- prettier-ignore -->
{{< twsnippet/code lang="js" >}}
import { Carousel, initTE } from "tw-elements";
initTE({ Carousel }, true ); // set second parameter to true if you want to use a debugger
{{< /twsnippet/code >}}
{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
10. Update the scripts inside the <code>package.json</code> file so that the
development server can be started using <code>bunx</code> instead of
<code>node</code>. You can do the same with the <code>build</code> script.
</p>
<div class="pt-2" id="download-vite-with-bun-step-10">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "package.json" "" "mobile" >}}{{< twsnippet/code active=true lang="json" >}}
"scripts": {
"dev": "bunx --bun vite",
"build": "bunx --bun vite build",
},
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<p class="mb-2 mt-6">
11. Tailwind should be connected properly to the vite app with Bun.
</p>
<div class="pt-2" id="download-vite-with-bun-step-11">
<!-- prettier-ignore -->
{{< twsnippet/wrapper "terminal" "" "mobile" >}}{{< twsnippet/code active=true lang="Plaintext" type="terminal" >}}
bun run dev
{{< /twsnippet/code >}}{{< /twsnippet/wrapper >}}
</div>
<hr class="my-10" />
<div class="flex flex-row">
<!-- <div class="w-full basis-7/12"> -->
<div class="w-full">
<a href="https://youtu.be/8veNiCCvXmg">
<img
src="https://mdbootstrap.com/img/tailwind-elements/quick-start/cdn.webp"
alt=""
class="mb-5 w-[460px] rounded-lg border lg:float-right lg:w-[380px]"
/></a>
<h2
class="mb-5 mt-0 text-3xl font-semibold leading-normal"
id="cdn"
data-te-spy-item>
CDN
</h2>