└── 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 | {Header 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 | 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 | 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 | 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 | 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 | 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 | 350 |
351 |
{children}
352 |
353 | 360 | 367 |
368 |
369 |
370 |
371 |
372 | 373 | ); 374 | }; 375 | 376 | export default Modal; 377 | ``` 378 | --------------------------------------------------------------------------------