Skip to content
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
dbb20b3
re-organized config to prefab dir
kayakingCellist Jun 4, 2020
abf66c9
Fix config include path
mmore500 Jun 4, 2020
284b94a
added getter method for group_set vector
kayakingCellist Jun 4, 2020
3659db6
added collapsible settings cards
kayakingCellist Jun 5, 2020
29eef50
added css styling to form and dropdown box
kayakingCellist Jun 5, 2020
876b8ab
display appropriate setting descriptions and synchronize form when on…
kayakingCellist Jun 9, 2020
6cd8f95
added glyphs for dropdown bubble and card toggle
kayakingCellist Jun 12, 2020
6f3e0b8
moved styling for config panel to a separate file
kayakingCellist Jun 12, 2020
892a0f9
added prefab module for comment box
kayakingCellist Jun 15, 2020
4d599b3
version of config panel that throws an exception
kayakingCellist Jun 16, 2020
5368237
added card element
kayakingCellist Jun 16, 2020
968ea66
prefab element for font awesome icons
kayakingCellist Jun 16, 2020
6e39c10
add prefab element to add collapibility to web elements
kayakingCellist Jun 16, 2020
d98a221
made card header the collapse link for card
kayakingCellist Jun 18, 2020
598b47e
examples for prefab components
kayakingCellist Jun 18, 2020
58cf96c
can add classes to a widget using SetAttr multiple times
kayakingCellist Jun 19, 2020
b19a89f
AddClass is it's own method now
kayakingCellist Jun 24, 2020
9d93cfa
change namespace to emp::prefab and inherit from web components for s…
kayakingCellist Jun 24, 2020
9a7aacf
change card header color on hover
kayakingCellist Jun 24, 2020
1eb2b57
fixed error in adding settings to card body
kayakingCellist Jun 25, 2020
ad55872
prefab rst documentation
kayakingCellist Jun 25, 2020
a24b6db
update namespace for prefab components
kayakingCellist Jun 25, 2020
30b3754
added CodeBlock element with highlightjs
kayakingCellist Jun 29, 2020
caafe4f
added LoadingIcon and ToggleSwitch elements
kayakingCellist Jun 29, 2020
5924ac9
updated classes
kayakingCellist Jun 29, 2020
0772cea
uncommented trigger js call
kayakingCellist Jun 30, 2020
6413d21
added loading and regular modal tools
kayakingCellist Jul 6, 2020
c0c9f22
adding widget edits back in
kayakingCellist Jul 6, 2020
df0c943
users can now set the default state of checkboxes and toggle switches…
kayakingCellist Jul 7, 2020
54e9222
added purge script for static files
kayakingCellist Jul 7, 2020
e697e1c
added modal and loading modal examples
kayakingCellist Jul 7, 2020
a35d789
removed parameter from toggle switch
kayakingCellist Jul 9, 2020
2d585ab
added notes for users and removed print statements
kayakingCellist Jul 9, 2020
07e89d5
FontAwesomeIcon tests, should fail
kayakingCellist Jul 10, 2020
72db6e6
made card header hover change only on collapsible cards
kayakingCellist Jul 13, 2020
96c4b40
fixed js syntax
kayakingCellist Jul 13, 2020
00bf080
fix up web make file
kayakingCellist Jul 13, 2020
cf148d9
removed commented out sections
kayakingCellist Jul 13, 2020
6e66da7
added method for converting strings to web compatible strings
kayakingCellist Jul 14, 2020
d7b4640
moved web tests from script to makefile
kayakingCellist Jul 14, 2020
4e69233
updated make clean and removed .js extension from karma call
kayakingCellist Jul 15, 2020
49e988b
tests for to_web_safe_string()
kayakingCellist Jul 15, 2020
68e4286
FontAwesomeIcon tests should pass travis tests now
kayakingCellist Jul 15, 2020
b7cbca2
improved grammer and format, updated content
kayakingCellist Jul 17, 2020
cb00fe8
restructured prefab Collapse tool
kayakingCellist Jul 17, 2020
5f99bc8
Strip trailing whitespace
mmore500 Jul 18, 2020
6403171
Move state that should persist to shared info ptr
mmore500 Jul 18, 2020
a3ccba5
added notes for using Docker
kayakingCellist Jul 21, 2020
90d60fd
added LoadingIcon tests and more CodeBlock tests
kayakingCellist Jul 21, 2020
2a65f8f
added scripts for highlightjs
kayakingCellist Jul 22, 2020
a97beed
Revert "Move state that should persist to shared info ptr"
kayakingCellist Jul 22, 2020
1645b7a
provide hilightJS script via CDN
kayakingCellist Jul 24, 2020
d85ca98
print parent ID in error message
kayakingCellist Jul 24, 2020
8b0c9cf
generalized AddClass() to AddAttr()
kayakingCellist Jul 24, 2020
4c5c327
simplified Collapse classes
kayakingCellist Jul 24, 2020
7c57ff9
added ToggleSwitch and Modal web tests
kayakingCellist Jul 24, 2020
2ddbce9
made AddMobileContent() protected and added web tests
kayakingCellist Jul 24, 2020
f655e55
removed ConfigPanel include
kayakingCellist Jul 25, 2020
c240994
Revert "Revert "Move state that should persist to shared info ptr""
kayakingCellist Jul 27, 2020
31a77af
added ConfigPanelInfo class back in
kayakingCellist Jul 27, 2020
198da22
simplified card state parameter to type std::string
kayakingCellist Jul 27, 2020
38a5a42
generalized controller and target be vectors of Widgets
kayakingCellist Jul 27, 2020
4a584b3
added Collapse, LoadingModal, and Card web tests
kayakingCellist Jul 28, 2020
9980f1c
Collapse mocha tests
kayakingCellist Jul 29, 2020
4bbf7a0
improved prefab tools documentation
kayakingCellist Jul 30, 2020
6adf606
second pass for documentation
kayakingCellist Jul 31, 2020
d1a921b
ConfigPanel web tests and framework for future testing of click function
kayakingCellist Jul 31, 2020
bb06cc0
added const to params and notes for testing click()
kayakingCellist Jul 31, 2020
7d463be
added make tests for examples/prefab directory
kayakingCellist Jul 31, 2020
f6f05ee
Fixup cherry-pick flack in ConfigPanel
mmore500 Sep 21, 2020
b082362
Improved C++ styling
kayakingCellist Sep 23, 2020
53f134d
Added dependencies for config panel
kayakingCellist Sep 23, 2020
0de834a
Removed CSS class order dependency in prefab test
kayakingCellist Sep 23, 2020
1e1996c
Switched to LESS CSS
kayakingCellist Sep 28, 2020
9aa56d4
Added single click tests to prefab tools
kayakingCellist Sep 28, 2020
6123fbd
Fixed timing after click in web tests
kayakingCellist Sep 30, 2020
22334e9
Added web test for collapse vector constructor
kayakingCellist Sep 30, 2020
75d89e8
Merge branch 'master' of https://github.com/devosoft/Empirical into f…
kayakingCellist Sep 30, 2020
36314ce
Added LESS cdn script
kayakingCellist Oct 1, 2020
08eebd8
Combined glyph classes into one with LESS
kayakingCellist Oct 1, 2020
7fd04cb
Found a way to click a web element multiple times
kayakingCellist Oct 2, 2020
ee88403
Switched to block comments and added other review suggestions
kayakingCellist Oct 5, 2020
d55a31c
Merge branch 'master' into fresh-prefab
Oct 5, 2020
56fa669
DoUpdateJS() -> RegisterUpdateJS()
kayakingCellist Oct 6, 2020
6d66bf7
Added review edits
kayakingCellist Oct 6, 2020
3d8b30f
Refactored prefab config panel
kayakingCellist Oct 6, 2020
3f10f6b
Revert "Track Emscripten API change"
kayakingCellist Oct 12, 2020
9a2d842
Switched to Emscripten v1.38.48
kayakingCellist Oct 12, 2020
86839f0
Updated config panel tests to reflect simplified html
kayakingCellist Oct 12, 2020
6623f0d
Added documentation
kayakingCellist Oct 12, 2020
e8efb28
Reorganized click demo tests
kayakingCellist Oct 12, 2020
bf6bd3c
Added docker notes
kayakingCellist Oct 12, 2020
af81ea8
Fixed typo
kayakingCellist Oct 12, 2020
f13e214
Fixed null element error in modal test
kayakingCellist Oct 13, 2020
b9e3a0c
Source emcc in web tests Makefile
mmore500 Oct 14, 2020
a3016a2
Use bash shell so we have source command
mmore500 Oct 15, 2020
ce5fd98
Merge branch 'master' into fresh-prefab
mmore500 Oct 16, 2020
fc9c64a
Put source, emcc call in same Make step
mmore500 Oct 16, 2020
585009e
Merge branch 'master' into fresh-prefab
mmore500 Oct 22, 2020
21ac8b6
Removed duplicate join function
kayakingCellist Oct 29, 2020
c2d96cf
Merge remote-tracking branch 'origin/master' into fresh-prefab
mmore500 Dec 1, 2020
1e97aa9
Merge branch 'small-vector' into fresh-prefab
mmore500 Dec 3, 2020
9513e1a
Fix include paths
mmore500 Dec 3, 2020
c52a248
Bugfix: don't initialize strings with NULL
mmore500 Dec 3, 2020
2940d61
Bugfix: separate attrs with space not comma
mmore500 Dec 3, 2020
92ff119
Fixup code readadability
mmore500 Dec 3, 2020
9b42e34
Load prefab assets for web tests
mmore500 Dec 4, 2020
6698181
Fixup include paths
mmore500 Dec 4, 2020
70a0e6d
Don't separate html classes with ,
mmore500 Dec 4, 2020
0e5664a
Fix include path
mmore500 Dec 4, 2020
c92ec17
Fixup examples Makefiles
mmore500 Dec 4, 2020
fc953ae
Use c++17 compliant g++ for web tests
mmore500 Dec 4, 2020
39f03fd
Fix include path
mmore500 Dec 4, 2020
d11e733
Ugly workaround for mysteriously failing gh action
mmore500 Dec 4, 2020
c2764d0
Strip out Makefile cruft
mmore500 Dec 4, 2020
fe305bf
Fixup Makefile whitespace
mmore500 Dec 4, 2020
1d5033b
Revert "Ugly workaround for mysteriously failing gh action"
mmore500 Dec 4, 2020
02f355c
Try reordering Makefiles
mmore500 Dec 4, 2020
c154620
Temporarily disable working tests
mmore500 Dec 4, 2020
2503148
Try hardcoded workaround
mmore500 Dec 4, 2020
b6103dc
Revert "Revert "Ugly workaround for mysteriously failing gh action""
mmore500 Dec 4, 2020
aaf0923
Add missing files to version control
mmore500 Dec 4, 2020
e758cda
Revert "Revert "Revert "Ugly workaround for mysteriously failing gh a…
mmore500 Dec 4, 2020
e25cb77
Revert "Try hardcoded workaround"
mmore500 Dec 4, 2020
15be32b
Revert "Temporarily disable working tests"
mmore500 Dec 4, 2020
e466a43
Fixup .gitignore
mmore500 Dec 4, 2020
f618977
Add assets to version control
mmore500 Dec 4, 2020
75f99d4
Merge branch 'master' into fresh-prefab
mmore500 Dec 4, 2020
3253b2c
Fixup cdn urls source -> include/emp
mmore500 Dec 4, 2020
919cd1f
Update path to prefab stylesheet
mmore500 Dec 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions doc/dev/guide-to-testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,38 @@ This allows for easier debugging of failed tests.

Catch provides several different frameworks for constructing test cases which are detailed within
`their documentation <https://github.com/philsquared/Catch/blob/master/docs/tutorial.md>`_.

Running Tests with Docker
-------------------------

A `devosoft/empirical <https://hub.docker.com/r/devosoft/empirical>`_ Docker image has been set up
to make recreating a development environment on your machine easier.
The first step is to download Docker. https://docs.docker.com/get-docker/

To download and run the Docker image, enter the following commands in the Docker terminal::

docker pull devosoft/empirical:latest
docker run --name emp-tests -dit devosoft/empirical:latest /sbin/init
docker exec -it emp-tests bash -l

To exit Docker containter shell::

CTRL+D

Commands to stop and start the Docker container::

docker start emp-tests
docker stop emp-tests

If you get :code:`error: cannot open display: 99` when running Mocha web tests, try::

Xvfb :99 -ac -screen 0 1024x768x8 &
export DISPLAY=:99

If you get an error prompting you to *check if server X is already running* after
entering :code:`Xvfb :99 -ac -screen 0 1024x768x8 &`, try this to kill the process::

ps -ef | grep Xvfb
kill *pid*

**Note:** Instructions adapted from https://andy-carter.com/blog/setting-up-travis-locally-with-docker-to-test-continuous-integration and https://github.com/karma-runner/karma-firefox-launcher/issues/93#issuecomment-519333245
354 changes: 354 additions & 0 deletions doc/library/prefab/prefab.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
Prefabricated Web Tools (for use with Emscripten)
=================================================

These prefabricated tools were created to help you quickly create interesting web applicications without being overwhelmed with the underlying HTML, CSS, and Bootstrap classes required.
These tools use Empirical's web tools to provide structure for the site, and many of the prefab tools inherit from web tools so you can add your own styling and stream them into other web components in a similar way.

When using these prefab tools be sure to link to the Bootstrap library, jQuery, and the default style stylesheet for this class in the head section of your HTML file.
.. code-block:: html

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet/less" type="text/css" href="https://cdn.jsdelivr.net/gh/devosoft/Empirical/source/prefab/DefaultPrefabStyles.less">
<script src="//cdn.jsdelivr.net/npm/less" ></script>
<script src="jquery-1.11.2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>

You can view these tools in action `here <https://devosoft.github.io/empirical-prefab-demo/empirical-prefab-demo>`_.

Card
~~~~
The Card class allows you to define a Bootstrap style card into your project.
A card that is not collapsible will have its state set to :code:`STATIC`.
Cards are static by default.
A card can be collapsible if its state parameter it set to :code:`INIT_OPEN` or :code:`INIT_CLOSED`.
By default, if a card is collapsible, it will have toggle icons in the header, but this can be overridden by setting the :code:`showGlyphs` parameter to :code:`false`.

Since this class inherits from :code:`web::Div`, you can set styling and attributes with :code:`SetCSS` and :code:`SetAttr` respectively.
You can also stream your Card into other web components with the :code:`<<` operator.

Example:
********
.. code-block:: c++

#include "web/web.h"
#include "prefab/Card.h"

emp::web::Document doc("emp_base");

emp::prefab::Card my_card("STATIC");
doc << my_card;

my_card.AddHeaderContent("Title");
my_card.AddBodyContent("Content for the card's body");
// Web components can also be passed as parameters to AddHeaderContent and AddBodyContent

**Note**: The toggle icons that are avalible for collapsible cards use the `FontAwesome`_ library.
You will need to add the CSS file for this library to the head of your HTML file:

.. code-block:: html

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

CodeBlock
~~~~~~~~~
The CardBlock class provides an interface for the `HighlightJS Library`_ which allows you to display code on web pages with language specific highlighting.
You can find a list of `all languages`_ on their GitHub page.

To use this class, you need to pass the code you want displayed and the programming language to the constructor.

Since this class inherits from :code:`web::Element`, you can stream your CodeBlock into other web components with the :code:`<<` operator.

Example:
********
.. code-block:: c++

#include "web/web.h"
#include "prefab/CodeBlock.h"

emp::web::Document doc("emp_base");

std::string code_str =
R"(
int num = 9;
std::cout << num << " is a square number" << std::endl;
)";
emp::prefab::CodeBlock code_block(code_str, "c++");

doc << code_block;

**Note**: You will also need to add the following code to the bottom of the body section of your HTML file:

.. code-block:: html

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.0/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/devosoft/Empirical/source/prefab/HighlightJS.js"></script>


.. _HighlightJS Library: https://highlightjs.org/
.. _all languages: https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md

Collapse
~~~~~~~~
The CollapseCouple maintains a group of targets and controllers.
When a controller is clicked on a web page, all the associated targets will change state (expand/collapse).

By default, the target element will start off closed, but this can be set to open by passing :code:`true` for the :code:`expanded` parameter.

Since the collapse controller and collapse target element will not necessarily directly neighbor eachother, call :code:`GetControllerDiv()` and :code:`GetTargetDiv()` to obtain a vector of all the asspociated controllers and targets, respectively.
To obtain just one controller or target, pass its index into a get div function call.

Example:
********
.. code-block:: cpp

#include "web/web.h"
#include "web/Div.h"
#include "prefab/CommentBox.h"

#include "prefab/Collapse.h"

emp::web::Document doc("emp_base");

emp::prefab::CommentBox box1;
box1.AddContent("<h3>Box 1</h3>");
emp::web::Div btn1;
btn1.SetAttr("class", "btn btn-info");
btn1 << "Button 1: controls box 1";

emp::prefab::CollapseCoupling collapse1(btn1, box1, true);

doc << collapse1.GetControllerDiv(0);
doc << collapse1.GetTargetDiv(0);

CommentBox
~~~~~~~~~~
A CommentBox is a simple grey comment bubble.
Content can be added to it using :code:`AddContent()`.
If there is data you only want to be visible on mobile devices, use :code:`AddMobileContent()`.

Since this class inherits from :code:`web::Div`, you can set styling and attributes with :code:`SetCSS()` and :code:`SetAttr()` respectively.
You can also stream your CommentBox into other web components with the :code:`<<` operator.

Example:
********
.. code-block:: cpp

#include "web/web.h"
#include "prefab/CommentBox.h"

emp::web::Document doc("emp_base");

emp::prefab::CommentBox my_box;
doc << my_box;

my_box.AddContent("<h1>Content that shows on all screen sizes</h1>");
my_box.AddMobileContent("<hr>Content that only shows on small screens");
// Web components can also be passed as parameters to AddContent and AddMobileContent

ConfigPanel
~~~~~~~~~~~
The ConfigPanel allows developers to easily set up a user interface for their configuration options.
It allows web apps to be interactive and dynamic, allowing users to change configuration settings within the applicaiton and providing a better user experiance.

Using the ConfigPanel class, a configuration panel is constructed when passed a Config file.
It uses other Prefabricated components to add styling and structure to the panel.
Use :code:`GetDiv()` to stream this component into another web component or document.

It is important to note that ConfigPanel instances are destroyed when they go out of scope.
This causes the form to no longer respond to changes made by the user.
You will need to initialize an instance outside of :code:`main()` if you would like the user to be able to interact with the panel.

Example:
********
.. code-block:: cpp

#include "web/web.h"
#include "prefab/ConfigPanel.h"
#include "config/ArgManager.h"

#include "SampleConfig.h" // Config file

emp::web::Document doc("emp_base");
Config cfg;

emp::prefab::ConfigPanel config_panel(cfg);

// apply configuration query params and config files to Config
auto specs = emp::ArgManager::make_builtin_specs(&cfg);
emp::ArgManager am(emp::web::GetUrlParams(), specs);
// cfg.Read("config.cfg");
am.UseCallbacks();
if (am.HasUnused()) std::exit(EXIT_FAILURE);

// setup configuration panel
config_panel.Setup();
doc << config_panel.GetDiv();

FontAwesomeIcon
~~~~~~~~~~~~~~~
`FontAwesome`_ is a free library of icons that can be used in web pages.

To use this class:

1. Find the icon you wish to use in the `FontAwesome library`_
2. Pass :code:`"fa-" + *icon name*` as a parameter to the constructor.
3. Add the following CSS file to the head of your HTML document.

.. code-block:: html

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

Since this class inherits from :code:`web::Element`, you can set styling and attributes with :code:`SetCSS()` and :code:`SetAttr()` respectively.
You can also stream your FontAwesomeIcon into other web components with the :code:`<<` operator.

Example:
********
.. code-block:: cpp

#include "web/web.h"
#include "prefab/FontAwesomeIcon.h"

emp::web::Document doc("emp_base");

emp::prefab::FontAwesomeIcon my_icon("fa-paw");
doc << my_icon;

my_icon.AddClass("custom_class");

.. _FontAwesome: https://fontawesome.com/v4.7.0/
.. _FontAwesome library: https://fontawesome.com/v4.7.0/icons/

LoadingIcon
~~~~~~~~~~~
The LoadingIcon class is used to add an animated loading icon.
One possible use for this icon is to be displayed while the contents of a web page is loading.
The icon is provided by `FontAwesome`_, so you will need to add its CSS to your HTML file to use this class.

.. code-block:: html

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

Since this class inherits from :code:`web::Element`, you can set styling and attributes with :code:`SetCSS()` and :code:`SetAttr()` respectively.
You can also stream your LoadingIcon into other web components with the :code:`<<` operator.

Example:
********
.. code-block:: cpp

#include "web/web.h"
#include "prefab/LoadingIcon.h"

emp::web::Document doc("emp_base");

emp::prefab::LoadingIcon spinner;
doc << spinner;

LoadingModal
~~~~~~~~~~~~
The LoadingModal header file makes adding a loading modal to a web page easy.
It will appear while the content of the page is rendering and will disappear when the page has completed loading.

This header file is slightly different from the other prefab web tools.
To place the loading modal on your web page, you must import the LoadingModal.js script into your HTML file right after the opening body tag.
To close the modal you must call the :code:`CloseLoadingModal()` function in your .cc file after loading the desired content into the doc.

Example:
********
.. code-block:: cpp

// .cc file
#include "web/web.h"
#include "LoadingModal.h"

emp::web::Document doc("emp_base");

// Add elements to the doc a normal

emp::prefab::CloseLoadingModal();

.. code-block:: html

<!-- HTML file -->
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/devosoft/Empirical/source/prefab/DefaultConfigPanelStyle.css">
<script src="jquery-1.11.2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</head>
<body>
<!-- Loading Modal JS -->
<script src="https://cdn.jsdelivr.net/gh/devosoft/Empirical/source/prefab/LoadingModal.js"></script>

<!-- Rest of body section -->
</body>
</html>

Modal
~~~~~
The Modal class can be used to create Bootstrap modals that pops up in the middle of the screen.

Since this class inherits from :code:`web::Div`, you can stream your Modal into other web components with the :code:`<<` operator.
You can also set the background color of the Modal with :code:`SetBackground()` passing it a string with a color name or its hex code value.

Example:
********
.. code-block:: cpp

#include "web/web.h"
#include "web/Button.h"
#include "prefab/Modal.h"

emp::web::Document doc("emp_base");

emp::prefab::Modal modal;
doc << modal;

modal.AddHeaderContent("<h3>Modal Header Section</h3>");
modal.AddBodyContent("This is the content of the modal");

modal.AddFooterContent("Modal Footer Section");
UI::Button close_btn([](){;}, "Close");
close_btn.SetAttr("class", "btn btn-secondary");
modal.AddFooterContent(close_btn);
modal.AddButton(close_btn);

modal.AddClosingX();

UI::Button modal_btn([](){;}, "Show Modal");
doc << modal_btn;
modal_btn.SetAttr("class", "btn btn-info");
modal.AddButton(modal_btn);

ToggleSwitch
~~~~~~~~~~~~
The ToggleSwitch class wraps checkbox input with Bootstrap custom swtich classes.
If you need to add a CSS class to the Input, do it after the creating the ToggleSwitch instance with :code:`AddClass()`.


Since this class inherits from :code:`web::Element`, you can set styling and attributes with :code:`SetCSS()` and :code:`SetAttr()` respectively.
You can also stream your ToggleSwitch into other web components with the :code:`<<` operator.

Example:
********
.. code-block:: cpp

#include "web/web.h"
#include "prefab/ToggleSwitch.h"

emp::prefab::ToggleSwitch on_switch([](std::string val){}, "Switch Defult On", true, "user_defined_switch_id");
doc << on_switch;

doc << "<br>";

emp::prefab::ToggleSwitch off_switch([](std::string val){}, NULL, false);
doc << off_switch;
off_switch.AddLabel("Switch Defult Off");

Add the link to Bootstrap in the head of your HTML file:
.. code-block:: html

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
Loading