├── .gitignore ├── LICENSE ├── README.md ├── examples ├── accordion.html ├── carousel.html ├── clipboard.html ├── collapse.html ├── datepicker.html ├── dial.html ├── dismiss.html ├── drawer.html ├── dropdown.html ├── input-counter.html ├── modal.html ├── popover.html ├── tabs.html └── tooltip.html ├── index.html ├── package-lock.json ├── package.json ├── src ├── accordion.ts ├── carousel.ts ├── clipboard.ts ├── collapse.ts ├── datepicker.ts ├── dial.ts ├── dismiss.ts ├── drawer.ts ├── dropdown.ts ├── index.ts ├── input-counter.ts ├── input.css ├── modal.ts ├── popover.ts ├── tabs.ts └── tooltip.ts ├── tailwind.config.js ├── tsconfig.json └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | lib/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Bergside Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tailwind CSS + TypeScript + Flowbite Starter 2 | 3 | This is a starter repository that you can use to see examples and get started with working with the Tailwind CSS, Flowbite components, and TypeScript. Read this [guide on Flowbite to learn more](https://flowbite.com/docs/getting-started/typescript/) on how this repository works. 4 | 5 | ## Getting started 6 | 7 | Make sure that you have Node.js installed on your project. Run the following command to install all dependencies: 8 | 9 | ``` 10 | npm install 11 | ``` 12 | 13 | Run this command to compile and watch for changes for Tailwind CSS: 14 | 15 | ``` 16 | npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch 17 | ``` 18 | 19 | Run this command to compile and bundle the TypeScript code into `app-bundle.js`: 20 | 21 | ``` 22 | npx webpack --watch 23 | ``` 24 | 25 | Open up the `index.html` file locally and you can see a list of components that are initialised programatically via the TypeScript files that you can find inside the `src/` folder. 26 | 27 | For example, this is the code that creates the modal component inside the `modal.ts` file: 28 | 29 | ``` 30 | import { Modal } from 'flowbite' 31 | import type { ModalOptions, ModalInterface } from 'flowbite' 32 | 33 | const $buttonElement: HTMLElement = document.querySelector('#button'); 34 | const $modalElement: HTMLElement = document.querySelector('#modal'); 35 | 36 | const modalOptions: ModalOptions = { 37 | placement: 'top-right' 38 | } 39 | 40 | if ($modalElement) { 41 | const modal: ModalInterface = new Modal($modalElement, modalOptions); 42 | $buttonElement.addEventListener('click', () => modal.toggle()); 43 | 44 | modal.show(); 45 | } 46 | ``` 47 | 48 | ## License 49 | 50 | This project is open-source under the MIT license. 51 | -------------------------------------------------------------------------------- /examples/accordion.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 |

13 | 17 |

18 | 24 |

25 | 29 |

30 | 36 |

37 | 41 |

42 | 53 |
54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /examples/carousel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 | 54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /examples/clipboard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 |
13 | 14 | 15 | 24 |
25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/collapse.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /examples/datepicker.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 |
13 |
14 | 17 |
18 | 19 |
20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/dial.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 |
13 | 47 | 51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /examples/dismiss.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 | 13 | 14 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/drawer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 |
13 |
Info
14 | 18 |

Supercharge your hiring by taking advantage of our limited-time sale for Flowbite Docs + Job Board. Unlimited access to over 190K top-ranked candidates and the #1 design job board.

19 |
20 | Learn more 21 | Get access 22 |
23 |
24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /examples/dropdown.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 | 13 | 14 | 30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/input-counter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 | 13 |
14 | 19 | 20 | 25 |
26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/modal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 | 13 |
14 | 15 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /examples/popover.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 | 13 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/tabs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 |
13 | 27 |
28 |
29 | 32 | 35 | 38 | 41 |
42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /examples/tooltip.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 | 13 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tailwind CSS + Flowbite + TypeScript Modal 8 | 9 | 10 | 11 |
12 |

Flowbite + Tailwind CSS + TypeScript Starter

13 |
14 | 15 | Accordion 16 | 17 | 18 | Carousel 19 | 20 | 21 | Collapse 22 | 23 | 24 | Speed Dial 25 | 26 | 27 | Dismiss 28 | 29 | 30 | Drawer 31 | 32 | 33 | Dropdown 34 | 35 | 36 | Modal 37 | 38 | 39 | Popover 40 | 41 | 42 | Tabs 43 | 44 | 45 | Tooltip 46 | 47 | 48 | Input Counter 49 | 50 | 51 | Clipboard 52 | 53 | 54 | Datepicker 55 | 56 |
57 |

Learn more about Flowbite + TypeScript here.

58 |
59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tailwind-typescript-starter", 3 | "version": "1.0.0", 4 | "description": "A starter project using Tailwind CSS, TypeScript, and Flowbite to help you get started with your applications.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/themesberg/tailwind-typescript-starter.git" 12 | }, 13 | "keywords": [ 14 | "typescript", 15 | "tailwind", 16 | "tailwind", 17 | "css", 18 | "flowbite" 19 | ], 20 | "author": "Bergside Inc.", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/themesberg/tailwind-typescript-starter/issues" 24 | }, 25 | "homepage": "https://github.com/themesberg/tailwind-typescript-starter#readme", 26 | "devDependencies": { 27 | "tailwindcss": "^3.2.4", 28 | "ts-loader": "^9.4.2", 29 | "typescript": "^4.9.4", 30 | "webpack": "^5.75.0", 31 | "webpack-cli": "^5.0.1" 32 | }, 33 | "dependencies": { 34 | "flowbite": "^2.4.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/accordion.ts: -------------------------------------------------------------------------------- 1 | import { Accordion } from 'flowbite'; 2 | import type { AccordionOptions, AccordionItem, AccordionInterface } from 'flowbite'; 3 | 4 | const accordionElement = document.getElementById('accordion-example'); 5 | 6 | // create an array of objects with the id, trigger element (eg. button), and the content element 7 | const accordionItems: AccordionItem[] = [ 8 | { 9 | id: 'accordion-example-heading-1', 10 | triggerEl: document.querySelector('#accordion-example-heading-1'), 11 | targetEl: document.querySelector('#accordion-example-body-1'), 12 | active: true 13 | }, 14 | { 15 | id: 'accordion-example-heading-2', 16 | triggerEl: document.querySelector('#accordion-example-heading-2'), 17 | targetEl: document.querySelector('#accordion-example-body-2'), 18 | active: false 19 | }, 20 | { 21 | id: 'accordion-example-heading-3', 22 | triggerEl: document.querySelector('#accordion-example-heading-3'), 23 | targetEl: document.querySelector('#accordion-example-body-3'), 24 | active: false 25 | } 26 | ]; 27 | 28 | // options with default values 29 | const options: AccordionOptions = { 30 | alwaysOpen: true, 31 | activeClasses: 'bg-gray-100 dark:bg-gray-800 text-gray-900 dark:text-white', 32 | inactiveClasses: 'text-gray-500 dark:text-gray-400', 33 | onOpen: (item) => { 34 | console.log('accordion item has been shown'); 35 | console.log(item); 36 | }, 37 | onClose: (item) => { 38 | console.log('accordion item has been hidden'); 39 | console.log(item); 40 | }, 41 | onToggle: (item) => { 42 | console.log('accordion item has been toggled'); 43 | console.log(item); 44 | }, 45 | }; 46 | 47 | if (document.querySelector('#accordion-example-heading-1')) { 48 | /* 49 | * accordionItems: array of accordion item objects 50 | * options: optional 51 | */ 52 | const accordion: AccordionInterface = new Accordion(accordionElement, accordionItems, options); 53 | 54 | // open accordion item based on id 55 | accordion.open('accordion-example-heading-2'); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/carousel.ts: -------------------------------------------------------------------------------- 1 | import { Carousel } from 'flowbite'; 2 | import type { CarouselItem, CarouselOptions, CarouselInterface } from 'flowbite'; 3 | 4 | const carouselElement = document.getElementById('carousel-example'); 5 | 6 | const items: CarouselItem[] = [ 7 | { 8 | position: 0, 9 | el: document.getElementById('carousel-item-1') 10 | }, 11 | { 12 | position: 1, 13 | el: document.getElementById('carousel-item-2') 14 | }, 15 | { 16 | position: 2, 17 | el: document.getElementById('carousel-item-3') 18 | }, 19 | { 20 | position: 3, 21 | el: document.getElementById('carousel-item-4') 22 | }, 23 | ]; 24 | 25 | const options: CarouselOptions = { 26 | defaultPosition: 1, 27 | interval: 3000, 28 | 29 | indicators: { 30 | activeClasses: 'bg-white dark:bg-gray-800', 31 | inactiveClasses: 'bg-white/50 dark:bg-gray-800/50 hover:bg-white dark:hover:bg-gray-800', 32 | items: [ 33 | { 34 | position: 0, 35 | el: document.getElementById('carousel-indicator-1') 36 | }, 37 | { 38 | position: 1, 39 | el: document.getElementById('carousel-indicator-2') 40 | }, 41 | { 42 | position: 2, 43 | el: document.getElementById('carousel-indicator-3') 44 | }, 45 | { 46 | position: 3, 47 | el: document.getElementById('carousel-indicator-4') 48 | }, 49 | ] 50 | }, 51 | 52 | // callback functions 53 | onNext: () => { 54 | console.log('next slider item is shown'); 55 | }, 56 | onPrev: ( ) => { 57 | console.log('previous slider item is shown'); 58 | }, 59 | onChange: ( ) => { 60 | console.log('new slider item has been shown'); 61 | } 62 | }; 63 | 64 | if (document.getElementById('carousel-item-1')) { 65 | const carousel: CarouselInterface = new Carousel(carouselElement, items, options); 66 | 67 | carousel.cycle() 68 | 69 | // set event listeners for prev and next buttons 70 | const prevButton = document.getElementById('data-carousel-prev'); 71 | const nextButton = document.getElementById('data-carousel-next'); 72 | 73 | prevButton.addEventListener('click', () => { 74 | carousel.prev(); 75 | }); 76 | 77 | nextButton.addEventListener('click', () => { 78 | carousel.next(); 79 | }); 80 | } 81 | -------------------------------------------------------------------------------- /src/clipboard.ts: -------------------------------------------------------------------------------- 1 | import { CopyClipboard } from 'flowbite'; 2 | import type { CopyClipboardOptions, CopyClipboardInterface } from 'flowbite'; 3 | import type { InstanceOptions } from 'flowbite'; 4 | 5 | // set the trigger element which will be clicked (ie. a button or text) 6 | const $triggerEl: HTMLElement = document.getElementById('copy-clipboard-button') as HTMLElement; 7 | 8 | // set the target element where the text will be copied from (ie. input field, code block) 9 | const $targetEl: HTMLInputElement = document.getElementById('copy-text') as HTMLInputElement; 10 | 11 | // optional options with default values and callback functions 12 | const options: CopyClipboardOptions = { 13 | contentType: 'input', 14 | htmlEntities: false, // infinite 15 | onCopy: () => { 16 | console.log('text copied successfully!'); 17 | } 18 | }; 19 | 20 | // instance options object 21 | const instanceOptions: InstanceOptions = { 22 | id: 'copy-clipboard-example', 23 | override: true 24 | }; 25 | 26 | if ($triggerEl && $targetEl) { 27 | /* 28 | * $triggerEl: required 29 | * $targetEl: required 30 | * options: optional 31 | * instanceOptions: optional 32 | */ 33 | const clipboard: CopyClipboardInterface = new CopyClipboard( 34 | $triggerEl, 35 | $targetEl, 36 | options, 37 | instanceOptions 38 | ); 39 | 40 | // copy the value of the target element 41 | clipboard.copy(); 42 | } 43 | -------------------------------------------------------------------------------- /src/collapse.ts: -------------------------------------------------------------------------------- 1 | import { Collapse } from 'flowbite'; 2 | import type { CollapseOptions, CollapseInterface } from 'flowbite'; 3 | 4 | // set the target element that will be collapsed or expanded (eg. navbar menu) 5 | const $targetEl: HTMLElement = document.getElementById('targetEl'); 6 | 7 | // optionally set a trigger element (eg. a button, hamburger icon) 8 | const $triggerEl: HTMLElement = document.getElementById('triggerEl'); 9 | 10 | // optional options with default values and callback functions 11 | const options: CollapseOptions = { 12 | onCollapse: () => { 13 | console.log('element has been collapsed') 14 | }, 15 | onExpand: () => { 16 | console.log('element has been expanded') 17 | }, 18 | onToggle: () => { 19 | console.log('element has been toggled') 20 | } 21 | }; 22 | 23 | if ($targetEl) { 24 | /* 25 | * targetEl: required 26 | * options: optional 27 | */ 28 | const collapse: CollapseInterface = new Collapse($targetEl, $triggerEl, options); 29 | 30 | // show the target element 31 | collapse.expand(); 32 | } -------------------------------------------------------------------------------- /src/datepicker.ts: -------------------------------------------------------------------------------- 1 | import { Datepicker } from 'flowbite'; 2 | import type { DatepickerOptions, DatepickerInterface } from 'flowbite'; 3 | import type { InstanceOptions } from 'flowbite'; 4 | 5 | // set the target element of the input field or div 6 | const $datepickerEl: HTMLInputElement = document.getElementById('datepicker-custom') as HTMLInputElement; 7 | 8 | // optional options with default values and callback functions 9 | const options: DatepickerOptions = { 10 | defaultDatepickerId: null, 11 | autohide: false, 12 | format: 'mm/dd/yyyy', 13 | maxDate: null, 14 | minDate: null, 15 | orientation: 'bottom', 16 | buttons: false, 17 | autoSelectToday: 0, 18 | title: null, 19 | language: 'en', 20 | rangePicker: false, 21 | onShow: () => {}, 22 | onHide: () => {}, 23 | }; 24 | 25 | // instance options object 26 | const instanceOptions: InstanceOptions = { 27 | id: 'datepicker-custom-example', 28 | override: true 29 | }; 30 | 31 | if ($datepickerEl) { 32 | /* 33 | * $datepickerEl: required 34 | * options: optional 35 | * instanceOptions: optional 36 | */ 37 | const datepicker: DatepickerInterface = new Datepicker( 38 | $datepickerEl, 39 | options, 40 | instanceOptions 41 | ); 42 | } -------------------------------------------------------------------------------- /src/dial.ts: -------------------------------------------------------------------------------- 1 | import { Dial } from 'flowbite'; 2 | import type { DialOptions, DialInterface } from 'flowbite'; 3 | 4 | // parent element wrapping the speed dial 5 | const $parentEl: HTMLElement = document.getElementById('dialParent') 6 | 7 | // the trigger element that can be clicked or hovered 8 | const $triggerEl: HTMLElement = document.getElementById('dialButton'); 9 | 10 | // the content wrapping element of menu items or buttons 11 | const $targetEl: HTMLElement = document.getElementById('dialContent'); 12 | 13 | // options with default values 14 | const options: DialOptions = { 15 | triggerType: 'hover', 16 | onHide: () => { 17 | console.log('speed dial is shown'); 18 | }, 19 | onShow: () => { 20 | console.log('speed dial is hidden'); 21 | }, 22 | onToggle: () => { 23 | console.log('speed dial is toggled') 24 | } 25 | }; 26 | 27 | if ($parentEl) { 28 | /* 29 | * parentEl: required 30 | * targetEl: required 31 | * triggerEl: required 32 | * options: optional 33 | */ 34 | const dial: DialInterface = new Dial($parentEl, $triggerEl, $targetEl, options); 35 | 36 | // show the speed dial 37 | dial.show(); 38 | } -------------------------------------------------------------------------------- /src/dismiss.ts: -------------------------------------------------------------------------------- 1 | import { Dismiss } from 'flowbite'; 2 | import type { DismissOptions, DismissInterface } from 'flowbite'; 3 | 4 | // target element that will be dismissed 5 | const $targetEl: HTMLElement = document.getElementById('targetElement'); 6 | 7 | // optional trigger element 8 | const $triggerEl: HTMLElement = document.getElementById('triggerElement'); 9 | 10 | // options object 11 | const options: DismissOptions = { 12 | transition: 'transition-opacity', 13 | duration: 1000, 14 | timing: 'ease-out', 15 | 16 | // callback functions 17 | onHide: (context, targetEl) => { 18 | console.log('element has been dismissed') 19 | console.log(targetEl) 20 | } 21 | }; 22 | 23 | if ($targetEl) { 24 | /* 25 | * targetEl: required 26 | * triggerEl: optional 27 | * options: optional 28 | */ 29 | const dismiss: DismissInterface = new Dismiss($targetEl, $triggerEl, options); 30 | 31 | // programatically hide it 32 | // dismiss.hide(); 33 | 34 | } -------------------------------------------------------------------------------- /src/drawer.ts: -------------------------------------------------------------------------------- 1 | import { Drawer } from 'flowbite'; 2 | import type { DrawerOptions, DrawerInterface } from 'flowbite'; 3 | 4 | // set the drawer menu element 5 | const $targetEl: HTMLElement = document.getElementById('drawer-js-example'); 6 | 7 | // options with default values 8 | const options: DrawerOptions = { 9 | placement: 'right', 10 | backdrop: true, 11 | bodyScrolling: false, 12 | edge: false, 13 | edgeOffset: '', 14 | backdropClasses: 'bg-gray-900 bg-opacity-50 dark:bg-opacity-80 fixed inset-0 z-30', 15 | onHide: () => { 16 | console.log('drawer is hidden'); 17 | }, 18 | onShow: () => { 19 | console.log('drawer is shown'); 20 | }, 21 | onToggle: () => { 22 | console.log('drawer has been toggled'); 23 | } 24 | }; 25 | 26 | if ($targetEl) { 27 | /* 28 | * targetEl: required 29 | * options: optional 30 | */ 31 | const drawer: DrawerInterface = new Drawer($targetEl, options); 32 | 33 | // show the drawer 34 | drawer.show(); 35 | } -------------------------------------------------------------------------------- /src/dropdown.ts: -------------------------------------------------------------------------------- 1 | import { Dropdown } from 'flowbite'; 2 | import type { DropdownOptions, DropdownInterface } from 'flowbite'; 3 | 4 | // set the dropdown menu element 5 | const $targetEl: HTMLElement = document.getElementById('dropdownMenu'); 6 | 7 | // set the element that trigger the dropdown menu on click 8 | const $triggerEl: HTMLElement = document.getElementById('dropdownButton'); 9 | 10 | // options with default values 11 | const options: DropdownOptions = { 12 | placement: 'bottom', 13 | offsetSkidding: 0, 14 | offsetDistance: 10, 15 | onHide: () => { 16 | console.log('dropdown has been hidden'); 17 | }, 18 | onShow: () => { 19 | console.log('dropdown has been shown'); 20 | } 21 | }; 22 | 23 | if ($targetEl) { 24 | /* 25 | * targetEl: required 26 | * triggerEl: required 27 | * options: optional 28 | */ 29 | const dropdown: DropdownInterface = new Dropdown($targetEl, $triggerEl, options); 30 | 31 | // show the dropdown 32 | dropdown.show(); 33 | } -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import './accordion'; 2 | import './carousel'; 3 | import './collapse'; 4 | import './dial'; 5 | import './dismiss'; 6 | import './drawer'; 7 | import './dropdown'; 8 | import './popover'; 9 | import './tabs'; 10 | import './modal'; 11 | import './tooltip'; 12 | import './input-counter'; 13 | import './clipboard'; 14 | import './datepicker'; -------------------------------------------------------------------------------- /src/input-counter.ts: -------------------------------------------------------------------------------- 1 | import { InputCounter } from 'flowbite'; 2 | import type { InputCounterOptions, InputCounterInterface } from 'flowbite'; 3 | import type { InstanceOptions } from 'flowbite'; 4 | 5 | // set the target element of the input field 6 | const $targetEl: HTMLInputElement = document.getElementById('counter-input-example') as HTMLInputElement; 7 | 8 | // optionally set the increment and decrement elements 9 | const $incrementEl: HTMLElement = document.getElementById('increment-button'); 10 | 11 | const $decrementEl: HTMLElement = document.getElementById('decrement-button'); 12 | 13 | // optional options with default values and callback functions 14 | const options: InputCounterOptions = { 15 | minValue: 0, 16 | maxValue: null, // infinite 17 | onIncrement: () => { 18 | console.log('input field value has been incremented'); 19 | }, 20 | onDecrement: () => { 21 | console.log('input field value has been decremented'); 22 | } 23 | }; 24 | 25 | // instance options object 26 | const instanceOptions: InstanceOptions = { 27 | id: 'counter-input-example', 28 | override: true 29 | }; 30 | 31 | if ($targetEl) { 32 | /* 33 | * $targetEl: required 34 | * $incrementEl: optional 35 | * $decrementEl: optional 36 | * options: optional 37 | * instanceOptions: optional 38 | */ 39 | const counterInput: InputCounterInterface = new InputCounter( 40 | $targetEl, 41 | $incrementEl, 42 | $decrementEl, 43 | options, 44 | instanceOptions 45 | ); 46 | } -------------------------------------------------------------------------------- /src/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /src/modal.ts: -------------------------------------------------------------------------------- 1 | import { Modal } from 'flowbite' 2 | import type { ModalOptions, ModalInterface } from 'flowbite' 3 | 4 | const $buttonElement: HTMLElement = document.querySelector('#button'); 5 | const $modalElement: HTMLElement = document.querySelector('#modal'); 6 | 7 | const modalOptions: ModalOptions = { 8 | backdropClasses: 'bg-gray-900 bg-opacity-50 dark:bg-opacity-80 fixed inset-0 z-40' 9 | } 10 | 11 | if ($modalElement) { 12 | const modal: ModalInterface = new Modal($modalElement, modalOptions); 13 | $buttonElement.addEventListener('click', () => modal.toggle()); 14 | 15 | modal.show(); 16 | } 17 | -------------------------------------------------------------------------------- /src/popover.ts: -------------------------------------------------------------------------------- 1 | import { Popover } from 'flowbite'; 2 | import type { PopoverOptions, PopoverInterface } from 'flowbite'; 3 | 4 | // set the popover content element 5 | const $targetEl: HTMLElement = document.getElementById('popoverContent'); 6 | 7 | // set the element that trigger the popover using hover or click 8 | const $triggerEl: HTMLElement = document.getElementById('popoverButton'); 9 | 10 | // options with default values 11 | const options: PopoverOptions = { 12 | placement: 'top', 13 | triggerType: 'hover', 14 | offset: 10, 15 | onHide: () => { 16 | console.log('popover is shown'); 17 | }, 18 | onShow: () => { 19 | console.log('popover is hidden'); 20 | } 21 | }; 22 | 23 | if ($targetEl) { 24 | /* 25 | * targetEl: required 26 | * triggerEl: required 27 | * options: optional 28 | */ 29 | const popover: PopoverInterface = new Popover($targetEl, $triggerEl, options); 30 | 31 | popover.show(); 32 | } -------------------------------------------------------------------------------- /src/tabs.ts: -------------------------------------------------------------------------------- 1 | import { Tabs } from 'flowbite'; 2 | import type { TabsOptions, TabsInterface, TabItem } from 'flowbite'; 3 | 4 | const tabsElement = document.getElementById('tabs-example'); 5 | 6 | // create an array of objects with the id, trigger element (eg. button), and the content element 7 | const tabElements: TabItem[] = [ 8 | { 9 | id: 'profile', 10 | triggerEl: document.querySelector('#profile-tab-example'), 11 | targetEl: document.querySelector('#profile-example') 12 | }, 13 | { 14 | id: 'dashboard', 15 | triggerEl: document.querySelector('#dashboard-tab-example'), 16 | targetEl: document.querySelector('#dashboard-example') 17 | }, 18 | { 19 | id: 'settings', 20 | triggerEl: document.querySelector('#settings-tab-example'), 21 | targetEl: document.querySelector('#settings-example') 22 | }, 23 | { 24 | id: 'contacts', 25 | triggerEl: document.querySelector('#contacts-tab-example'), 26 | targetEl: document.querySelector('#contacts-example') 27 | } 28 | ]; 29 | 30 | // options with default values 31 | const options: TabsOptions = { 32 | defaultTabId: 'settings', 33 | activeClasses: 'text-blue-600 hover:text-blue-600 dark:text-blue-500 dark:hover:text-blue-400 border-blue-600 dark:border-blue-500', 34 | inactiveClasses: 'text-gray-500 hover:text-gray-600 dark:text-gray-400 border-gray-100 hover:border-gray-300 dark:border-gray-700 dark:hover:text-gray-300', 35 | onShow: () => { 36 | console.log('tab is shown'); 37 | } 38 | }; 39 | 40 | if (document.querySelector('#profile-tab-example')) { 41 | /* 42 | * tabElements: array of tab objects 43 | * options: optional 44 | */ 45 | const tabs: TabsInterface = new Tabs(tabsElement, tabElements, options); 46 | 47 | // open tab item based on id 48 | tabs.show('contacts'); 49 | } -------------------------------------------------------------------------------- /src/tooltip.ts: -------------------------------------------------------------------------------- 1 | import { Tooltip } from 'flowbite'; 2 | import type { TooltipOptions, TooltipInterface } from 'flowbite'; 3 | 4 | // set the tooltip content element 5 | const $targetEl: HTMLElement = document.getElementById('tooltipContent'); 6 | 7 | // set the element that trigger the tooltip using hover or click 8 | const $triggerEl: HTMLElement = document.getElementById('tooltipButton'); 9 | 10 | // options with default values 11 | const options: TooltipOptions = { 12 | placement: 'top', 13 | triggerType: 'hover', 14 | onHide: () => { 15 | console.log('tooltip is shown'); 16 | }, 17 | onShow: () => { 18 | console.log('tooltip is hidden'); 19 | } 20 | }; 21 | 22 | if ($targetEl) { 23 | /* 24 | * targetEl: required 25 | * triggerEl: required 26 | * options: optional 27 | */ 28 | const tooltip: TooltipInterface = new Tooltip($targetEl, $triggerEl, options); 29 | 30 | // show the tooltip 31 | tooltip.show(); 32 | } -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | "./src/**/*.ts", 5 | "./**/*.html", 6 | "./node_modules/flowbite/**/*.js" 7 | ], 8 | theme: { 9 | extend: {}, 10 | }, 11 | plugins: [ 12 | require('flowbite/plugin') 13 | ], 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["dom", "es2015"], 4 | "outDir": "./lib/cjs/", 5 | "sourceMap": true, 6 | "declaration": true, 7 | "noImplicitAny": true, 8 | "module": "commonjs", 9 | "target": "es5", 10 | "allowJs": true, 11 | "moduleResolution": "node" 12 | }, 13 | "include": ["src/**/*.ts*"], 14 | "exclude": ["node_modules", "dist", "lib"] 15 | } -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | //webpack.config.js 2 | const path = require('path'); 3 | 4 | module.exports = { 5 | mode: "development", 6 | devtool: "inline-source-map", 7 | entry: { 8 | main: "./src/index.ts", 9 | }, 10 | output: { 11 | path: path.resolve(__dirname, './dist'), 12 | filename: "app-bundle.js" // <--- Will be compiled to this single file 13 | }, 14 | resolve: { 15 | extensions: [".ts", ".tsx", ".js"], 16 | }, 17 | module: { 18 | rules: [ 19 | { 20 | test: /\.tsx?$/, 21 | loader: "ts-loader" 22 | } 23 | ] 24 | } 25 | }; --------------------------------------------------------------------------------