βββ Readme.md
/Readme.md:
--------------------------------------------------------------------------------
1 | # Bootstrap Helpers
2 |
3 | These are my own versions of components that I use for my React Applications, where these snippets might help me by reducing the repetitive stuff that I need to do. All these components are based out of **Bootstrap 4 version** and they might need an upgrade.
4 |
5 | ## Card Element
6 |
7 | This creates a card element.
8 |
9 | ```react
10 | import React from "react";
11 |
12 | const Card = ({
13 | Image,
14 | ImgAlign,
15 | Header,
16 | TextHeader,
17 | Title,
18 | Text,
19 | children,
20 | Footer,
21 | className
22 | }) => {
23 | return (
24 |
25 | {Image && (
26 |
31 | )}
32 | {Header &&
33 | (TextHeader ? (
34 |
{Header}
35 | ) : (
36 |
{Header}
37 | ))}
38 | {(Title || Text || children) && (
39 |
40 | {Title &&
{Title} }
41 | {Text &&
{Text}
}
42 | {children}
43 |
44 | )}
45 | {Footer &&
{Footer}
}
46 |
47 | );
48 | };
49 |
50 | export default Card;
51 | ```
52 |
53 | ## Containers
54 |
55 | ### Container with a Single Row
56 |
57 | This creates a container with a row.
58 |
59 | ```react
60 | import React from "react";
61 |
62 | const ContainerRow = ({ fluid, className, children }) => {
63 | return (
64 | 0 ? " " + className : "")
69 | }
70 | >
71 |
{children}
72 |
73 | );
74 | };
75 |
76 | export default ContainerRow;
77 | ```
78 |
79 | ### Container Element
80 |
81 | This creates a generic container element.
82 |
83 | ```react
84 | import React from "react";
85 |
86 | const Container = ({ fluid, className, children }) => {
87 | return (
88 | 0 ? " " + className : "")
93 | }
94 | >
95 | {children}
96 |
97 | );
98 | };
99 |
100 | export default Container;
101 | ```
102 |
103 | ## Headers
104 |
105 | ```react
106 | import React from "react";
107 |
108 | const Header = ({ dark, children, className, to, Link }) => {
109 | dark = !!dark ? "dark" : "light";
110 | return (
111 |
116 | {to ? (
117 |
118 | {children}
119 |
120 | ) : (
121 | {children}
122 | )}
123 |
124 | );
125 | };
126 |
127 | export default Header;
128 | ```
129 |
130 | ### Headers with Links
131 |
132 | ```react
133 | import React from "react";
134 |
135 | const Header = ({ dark, children, className, pages, to, Link }) => {
136 | dark = !!dark ? "dark" : "light";
137 | return (
138 |
145 | {to ? (
146 |
147 | {children}
148 |
149 | ) : (
150 | {children}
151 | )}
152 | {pages && pages.length > 0 && (
153 |
154 |
155 | {pages
156 | .filter(a => !a.DontShow)
157 | .map((item, key) => (
158 |
159 |
160 | {item.Name}
161 |
162 |
163 | ))}
164 |
165 |
166 | )}
167 |
168 | );
169 | };
170 |
171 | export default Header;
172 | ```
173 |
174 | ### Headers with Items
175 |
176 | Possibly send a button with an `onClick` handler.
177 |
178 | ```react
179 | import React from "react";
180 |
181 | const Header = ({ dark, children, className, items, to, Link }) => {
182 | dark = !!dark ? "dark" : "light";
183 | return (
184 |
191 | {to ? (
192 |
193 | {children}
194 |
195 | ) : (
196 | {children}
197 | )}
198 | {items && items.length > 0 && (
199 |
200 |
201 | {items.map((item, key) => (
202 |
203 | {item}
204 |
205 | ))}
206 |
207 |
208 | )}
209 |
210 | );
211 | };
212 |
213 | export default Header;
214 | ```
215 |
216 | For a right aligned buttons, use this...
217 |
218 | ```react
219 | import React from "react";
220 |
221 | const Header = ({ dark, children, className, items, to, Link }) => {
222 | dark = !!dark ? "dark" : "light";
223 | return (
224 |
231 | {to ? (
232 |
233 | {children}
234 |
235 | ) : (
236 | {children}
237 | )}
238 | {items && items.length > 0 && (
239 |
240 |
241 | {items.map((item, key) => (
242 |
243 | {item}
244 |
245 | ))}
246 |
247 |
248 | )}
249 |
250 | );
251 | };
252 |
253 | export default Header;
254 | ```
255 |
256 | ## Forms
257 |
258 | ### Form Group
259 |
260 | For all the ` ` based elements, we have a `FormGroup` component here.
261 |
262 | ```react
263 | import React from "react";
264 |
265 | const FormGroup = ({
266 | Id,
267 | Label,
268 | Type,
269 | onChange,
270 | Value,
271 | defaultValue,
272 | Checked,
273 | defaultChecked,
274 | Placeholder,
275 | Desc
276 | }) => {
277 | return (
278 |
279 | {Label}
280 |
293 | {Desc && (
294 |
295 | {Desc}
296 |
297 | )}
298 |
299 | );
300 | };
301 |
302 | export default FormGroup;
303 | ```
304 |
305 | ## Modal Window & Utilities
306 |
307 | ### Cancelling Propagation
308 |
309 | Itβs noted that Modal Windows have multiple layers and some of the events need to be cancelled. I created a generic `CancelPropagation` to combat this problem. This can be currently stored inside the `utils` directory as `GenUtils.js` and it has been exposed and exported.
310 |
311 | ```javascript
312 | export const CancelPropagation = (e, next) => {
313 | e.stopPropagation();
314 | if (next && typeof next === "function") next();
315 | };
316 | ```
317 |
318 | ### Modal
319 |
320 | ```react
321 | import { CancelPropagation } from "../../utils/GenUtils";
322 |
323 | const Modal = ({
324 | children,
325 | Confirm,
326 | Cancel,
327 | Title,
328 | CancelButton,
329 | ConfirmButton
330 | }) => {
331 | return (
332 | <>
333 |
334 |
339 |
340 |
341 |
{Title}
342 |
348 | ×
349 |
350 |
351 |
{children}
352 |
353 |
358 | {CancelButton}
359 |
360 |
365 | {ConfirmButton}
366 |
367 |
368 |
369 |
370 |
371 |
372 | >
373 | );
374 | };
375 |
376 | export default Modal;
377 | ```
378 |
--------------------------------------------------------------------------------