-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypescript-example.ts
More file actions
171 lines (145 loc) · 4.53 KB
/
Copy pathtypescript-example.ts
File metadata and controls
171 lines (145 loc) · 4.53 KB
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
/**
* TypeScript Usage Example for Bodystyle
* This file demonstrates how to use Bodystyle with TypeScript
*/
// Import the main Bodystyle API
import BS from './src/types/index';
// Import specific modules
import { Waves } from './src/types/Waves';
import { slideUp, slideDown } from './src/types/Animaciones';
import { Coleccion } from './src/types/Colecciones';
// ==================== Example 1: Using Waves ====================
function initializeWaves(): void {
// Initialize waves effect
Waves.iniciar();
// Later, destroy if needed
// Waves.destroy();
}
// ==================== Example 2: Using Animations ====================
function animateElement(): void {
const element = document.querySelector('.my-element') as HTMLElement;
if (element) {
// Slide down with custom duration and callback
slideDown(element, 500, () => {
console.log('Animation complete!');
});
// Slide up after 2 seconds
setTimeout(() => {
slideUp(element, 300);
}, 2000);
}
}
// ==================== Example 3: Using Collections ====================
function setupCollection(): void {
const coleccion = new Coleccion();
coleccion.iniciar({
contexto: 'mi-lista',
colorFondo: 'fd-blanco',
colorTexto: 'c-negro',
colorFlechas: '#333'
});
}
// ==================== Example 4: Using BS Global API ====================
function initializeComponents(): void {
// Initialize tooltips
BS.ToolTipsInit();
// Initialize modal
BS.ModalInit();
// Show a toast notification
BS.Toast({
mensaje: 'Welcome to Bodystyle with TypeScript!',
duracion: 3000,
color: 'bg-success',
posicion: 'top'
});
// Initialize ScrollSpy with configuration
BS.ScrollSpyInit({
ancho: '250px',
tamFuente: '14px',
colorBorde: 'fd-primary',
alturaBorde: '3px',
separacion: '100px',
colorSeleccionado: '#007bff',
colorNoSeleccionado: '#6c757d'
});
}
// ==================== Example 5: Code Syntax Highlighting ====================
function initializeCodeHighlighting(): void {
// Initialize all code highlighting modules
BS.CodeAutoInit({
tema: 'dark',
lineNumbers: true
});
// Or initialize specific languages
BS.CodeJsInit({ tema: 'light' });
BS.CodeHtmlInit({ tema: 'dark' });
}
// ==================== Example 6: Navigation ====================
function setupNavigation(): void {
// Initialize navigation
BS.NavigationInit('main-nav', true);
// Setup sidebar dropdown
BS.SidebarDropInit({
idNav: 'main-nav',
idSidebar: 'main-sidebar'
});
}
// ==================== Example 7: Dynamic Elements ====================
function setupDynamicElements(): void {
// Initialize all dynamic elements at once
BS.DynamicsAutoInit();
// Or initialize individually
BS.DropDownInit();
BS.ToolTipsInit();
BS.ComentariosInit();
// Custom dynamic element
BS.PersonalizadoInit({
ori: '.trigger-element',
ele: '.dynamic-content'
});
}
// ==================== Example 8: Tabs ====================
function setupTabs(): void {
const tabs = BS.TabInit();
tabs.iniciar({
contexto: 'my-tabs'
});
}
// ==================== Example 9: Select ====================
function setupCustomSelect(): void {
const select = BS.SelectInit();
select.iniciar({
contexto: 'my-select'
});
}
// ==================== Example 10: Type Safety ====================
// TypeScript will catch errors at compile time
function demonstrateTypeSafety(): void {
// ✅ Correct usage
BS.Toast({
mensaje: 'Hello',
duracion: 3000,
posicion: 'top' // TypeScript knows this must be 'top' or 'bottom'
});
// ❌ TypeScript will show an error for invalid values
// BS.Toast({
// posicion: 'middle' // Error: Type '"middle"' is not assignable to type '"top" | "bottom"'
// });
}
// Initialize everything on DOM ready
document.addEventListener('DOMContentLoaded', () => {
initializeWaves();
initializeComponents();
setupNavigation();
});
export {
initializeWaves,
animateElement,
setupCollection,
initializeComponents,
initializeCodeHighlighting,
setupNavigation,
setupDynamicElements,
setupTabs,
setupCustomSelect
};