1 |
efrain |
1 |
---
|
|
|
2 |
layout: docs
|
|
|
3 |
title: "Buttons"
|
|
|
4 |
description: "Button types used in Moodle"
|
|
|
5 |
date: 2020-01-14T16:32:24+01:00
|
|
|
6 |
draft: false
|
|
|
7 |
weight: 10
|
|
|
8 |
tags:
|
|
|
9 |
- Available
|
|
|
10 |
---
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
## How to use buttons
|
|
|
14 |
|
|
|
15 |
Button components are available as part of a Moodle form, as a single button functioning as a form submit or triggering a JavaScript action. Buttons used in Moodle are based on the [Bootstrap buttons]({{< docsref "/components/buttons" >}}).
|
|
|
16 |
|
|
|
17 |
The most used buttons types in Moodle are:
|
|
|
18 |
|
|
|
19 |
## Example
|
|
|
20 |
|
|
|
21 |
{{< example >}}
|
|
|
22 |
<button type="button" class="btn btn-primary">Primary Button</button>
|
|
|
23 |
<button type="button" class="btn btn-secondary">Secondary Button</button>
|
|
|
24 |
<button type="button" class="btn btn-danger">Danger Button</button>
|
|
|
25 |
<button type="button" class="btn btn-outline-secondary">Outline Button</button>
|
|
|
26 |
{{< /example >}}
|
|
|
27 |
|
|
|
28 |
### Primary buttons
|
|
|
29 |
|
|
|
30 |
{{< example show_markup="false">}}
|
|
|
31 |
<button type="button" class="btn btn-primary">Primary Button</button>
|
|
|
32 |
{{< /example >}}
|
|
|
33 |
|
|
|
34 |
For the primary/most used action on the page use a primary button.
|
|
|
35 |
For each for or UI component there should only be one primary button.
|
|
|
36 |
|
|
|
37 |
### Secondary buttons
|
|
|
38 |
|
|
|
39 |
{{< example show_markup="false">}}
|
|
|
40 |
<button type="button" class="btn btn-secondary">Primary Button</button>
|
|
|
41 |
{{< /example >}}
|
|
|
42 |
|
|
|
43 |
Secondary buttons are used for the the cancel options on a form or as a button that is always visible (blocks editing on)
|
|
|
44 |
|
|
|
45 |
### Danger buttons.
|
|
|
46 |
|
|
|
47 |
{{< example show_markup="false">}}
|
|
|
48 |
<button type="button" class="btn btn-danger">Primary Button</button>
|
|
|
49 |
{{< /example >}}
|
|
|
50 |
|
|
|
51 |
Use a danger button when the primary action is a potentially dangerous action, like deleting a contact in the messaging interface.
|
|
|
52 |
|
|
|
53 |
### Outline buttons
|
|
|
54 |
|
|
|
55 |
{{< example show_markup="false">}}
|
|
|
56 |
<button type="button" class="btn btn-outline-secondary">Primary Button</button>
|
|
|
57 |
{{< /example >}}
|
|
|
58 |
|
|
|
59 |
Outline buttons are used for buttons that controll part of the user interface, like filters on a table or the display type on the user dashboard. Outline buttons look more subtle than secondary buttons and do not distract the user from the main user interface too much.
|
|
|
60 |
|
|
|
61 |
## Adding buttons to a page
|
|
|
62 |
|
|
|
63 |
### Using the single_select renderer
|
|
|
64 |
|
|
|
65 |
The ```single_button()``` renderer allows you to quickly add a button with an action to a page without having to write a template for the page. Single select buttons are added as miniature forms that can pass custom form data.
|
|
|
66 |
|
|
|
67 |
{{< php >}}
|
|
|
68 |
$url = new moodle_url("$CFG->wwwroot/my/index.php", $params);
|
|
|
69 |
$button = $OUTPUT->single_button($url, $editstring);
|
|
|
70 |
$PAGE->set_button($resetbutton . $button);
|
|
|
71 |
{{< / php >}}
|
|
|
72 |
|
|
|
73 |
<iframe src="../../../../examples/singlebuttons.php" style="overflow:hidden;height:50px;width:100%;border:0" title="Single button examples"></iframe>
|
|
|
74 |
|
|
|
75 |
### Button links
|
|
|
76 |
|
|
|
77 |
Links can be style to look like buttons, the action for this button is to simply navigate to some other page
|
|
|
78 |
|
|
|
79 |
{{< example >}}
|
|
|
80 |
<a href="#next" class="btn btn-secondary">Next Page</a>
|
|
|
81 |
{{< /example >}}
|
|
|
82 |
|
|
|
83 |
### Action buttons
|
|
|
84 |
|
|
|
85 |
Action buttons have a data-action and are usually linked to a JavaScript eventlistener that will do something on button click.
|
|
|
86 |
|
|
|
87 |
{{< example >}}
|
|
|
88 |
<button data-action="show-fun-thing" class="btn btn-secondary">Click me</button>
|
|
|
89 |
{{< /example >}}
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
### UX tips
|
|
|
93 |
|
|
|
94 |
Primary buttons have a higher visual weight and attracts most attention it should be used for the default action on a page.
|
|
|
95 |
|
|
|
96 |
Use primary buttons for the positive action on the page, for example "Save" or "Submit" when working on an assignment
|
|
|
97 |
|
|
|
98 |
{{< example >}}
|
|
|
99 |
<div class="row">
|
|
|
100 |
<div class="col-5">
|
|
|
101 |
<div class="card mb-2">
|
|
|
102 |
<div class="card-body">
|
|
|
103 |
<strong>Save Changes?</strong>
|
|
|
104 |
<div class="d-flex">
|
|
|
105 |
<button type="button" class="btn btn-secondary mr-1">Cancel</button>
|
|
|
106 |
<button type="button" class="btn btn-primary mr-1">Save</button>
|
|
|
107 |
</div>
|
|
|
108 |
</div>
|
|
|
109 |
</div>
|
|
|
110 |
</div>
|
|
|
111 |
<div class="col-5">
|
|
|
112 |
<div class="card mb-2">
|
|
|
113 |
<div class="card-body">
|
|
|
114 |
<strong>Delete profile</strong>
|
|
|
115 |
<div class="d-flex">
|
|
|
116 |
<button type="button" class="btn btn-primary mr-1">Cancel</button>
|
|
|
117 |
<button type="button" class="btn btn-secondary">Delete</button>
|
|
|
118 |
</div>
|
|
|
119 |
</div>
|
|
|
120 |
</div>
|
|
|
121 |
</div>
|
|
|
122 |
</div>
|
|
|
123 |
{{< /example >}}
|
|
|
124 |
|
|
|
125 |
In case of more dangerous actions, like deleting something the having stiling the Cancel button as the primary button could be a good choice
|
|
|
126 |
|
|
|
127 |
Bootstrap classes are used to style Buttons, the most used styles are:
|
|
|
128 |
|
|
|
129 |
{{< example >}}
|
|
|
130 |
<button type="button" class="btn btn-primary">Primary buttons</button>
|
|
|
131 |
<button type="button" class="btn btn-secondary">Secondary buttons</button>
|
|
|
132 |
{{< /example >}}
|
|
|
133 |
|
|
|
134 |
### Button text
|
|
|
135 |
|
|
|
136 |
The meaning of buttons must be very clear.
|
|
|
137 |
|
|
|
138 |
{{< example show_markup="false">}}
|
|
|
139 |
<div class="row">
|
|
|
140 |
<div class="col-5">
|
|
|
141 |
<div class="card mb-2">
|
|
|
142 |
<div class="card-body">
|
|
|
143 |
<strong>Save Changes?</strong>
|
|
|
144 |
<p>Would you like to not save your changes before exiting?</p>
|
|
|
145 |
<div class="d-flex">
|
|
|
146 |
<button type="button" class="btn btn-primary mr-1">Yes</button>
|
|
|
147 |
<button type="button" class="btn btn-secondary">No</button>
|
|
|
148 |
</div>
|
|
|
149 |
</div>
|
|
|
150 |
</div>
|
|
|
151 |
<div class="alert alert-warning">Avoid generic 'OK' or 'Yes', avoid confusing phrases</div>
|
|
|
152 |
</div>
|
|
|
153 |
<div class="col-5">
|
|
|
154 |
<div class="card mb-2">
|
|
|
155 |
<div class="card-body">
|
|
|
156 |
<strong>Save Changes</strong>
|
|
|
157 |
<p>Would you like to save your changes before exiting?</p>
|
|
|
158 |
<div class="d-flex">
|
|
|
159 |
<button type="button" class="btn btn-primary mr-1">Save</button>
|
|
|
160 |
<button type="button" class="btn btn-secondary">Discard</button>
|
|
|
161 |
</div>
|
|
|
162 |
</div>
|
|
|
163 |
</div>
|
|
|
164 |
<div class="alert alert-success">Avoid generic 'OK' or 'Yes', avoid confusing phrases</div>
|
|
|
165 |
</div>
|
|
|
166 |
</div>
|
|
|
167 |
{{< /example >}}
|