Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 
1441 ariadna 61
### Subtle buttons
62
 
63
{{< example >}}
64
<button type="button" class="btn btn-subtle-secondary">Subtle Secondary</button>
65
<button type="button" class="btn btn-subtle-success">Subtle Succcess</button>
66
<button type="button" class="btn btn-sm btn-subtle-success">Subtle Succcess Small</button>
67
{{< /example >}}
68
 
69
The subtle class is designed to create buttons that offer a balance between the visual prominence of standard buttons and the minimalism of outline buttons. This class aims to provide a softer, more understated appearance compared to regular buttons while still maintaining more visual presence than outline buttons.
70
 
71
### Icon buttons
72
 
73
{{< example >}}
74
<button type="button" class="btn btn-icon">
75
    <i class="icon fa fa-ellipsis-vertical fa-fw" title="Edit" role="img"></i>
76
</button>
77
<button type="button" class="btn btn-icon text-bg-danger">
78
    <i class="icon fa fa-trash-can fa-fw" title="Delete" role="img"></i>
79
</button>
80
<button type="button" class="btn btn-icon icon-size-4">
81
    <i class="icon fa fa-user fa-fw" title="User" role="img"></i>
82
</button>
83
<button type="button" class="btn btn-icon icon-size-5">
84
    <i class="icon fa fa-user fa-fw" title="User" role="img"></i>
85
</button>
86
{{< /example >}}
87
 
88
The `.btn-icon` class styles buttons that contain only an icon, providing a visually appealing and compact design for icon-only buttons. This class is ideal for creating minimalistic, icon-based interactions within your UI.
89
 
90
The `.btn-icon` class standardizes icon button styles using the `$btn-icon-border-radius` variable in variables.scss. While this ensures consistency, the `.rounded-circle` Bootstrap class can still be used for legacy support, though it's discouraged for new designs.
91
 
1 efrain 92
## Adding buttons to a page
93
 
94
### Using the single_select renderer
95
 
96
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.
97
 
98
{{< php >}}
99
    $url = new moodle_url("$CFG->wwwroot/my/index.php", $params);
100
    $button = $OUTPUT->single_button($url, $editstring);
101
    $PAGE->set_button($resetbutton . $button);
102
{{< / php >}}
103
 
104
<iframe src="../../../../examples/singlebuttons.php" style="overflow:hidden;height:50px;width:100%;border:0" title="Single button examples"></iframe>
105
 
106
### Button links
107
 
108
Links can be style to look like buttons, the action for this button is to simply navigate to some other page
109
 
110
{{< example >}}
111
<a href="#next" class="btn btn-secondary">Next Page</a>
112
{{< /example >}}
113
 
114
### Action buttons
115
 
116
Action buttons have a data-action and are usually linked to a JavaScript eventlistener that will do something on button click.
117
 
118
{{< example >}}
119
<button data-action="show-fun-thing" class="btn btn-secondary">Click me</button>
120
{{< /example >}}
121
 
122
 
123
### UX tips
124
 
125
Primary buttons have a higher visual weight and attracts most attention it should be used for the default action on a page.
126
 
127
Use primary buttons for the positive action on the page, for example "Save" or "Submit" when working on an assignment
128
 
129
{{< example >}}
130
<div class="row">
131
    <div class="col-5">
132
        <div class="card mb-2">
133
            <div class="card-body">
134
                <strong>Save Changes?</strong>
135
                <div class="d-flex">
1441 ariadna 136
                    <button type="button" class="btn btn-secondary me-1">Cancel</button>
137
                    <button type="button" class="btn btn-primary me-1">Save</button>
1 efrain 138
                </div>
139
            </div>
140
        </div>
141
    </div>
142
    <div class="col-5">
143
        <div class="card mb-2">
144
            <div class="card-body">
145
                <strong>Delete profile</strong>
146
                <div class="d-flex">
1441 ariadna 147
                    <button type="button" class="btn btn-primary me-1">Cancel</button>
1 efrain 148
                    <button type="button" class="btn btn-secondary">Delete</button>
149
                </div>
150
            </div>
151
        </div>
152
    </div>
153
</div>
154
{{< /example >}}
155
 
156
In case of more dangerous actions, like deleting something the having stiling the Cancel button as the primary button could be a good choice
157
 
158
Bootstrap classes are used to style Buttons, the most used styles are:
159
 
160
{{< example >}}
161
<button type="button" class="btn btn-primary">Primary buttons</button>
162
<button type="button" class="btn btn-secondary">Secondary buttons</button>
163
{{< /example >}}
164
 
165
### Button text
166
 
167
The meaning of buttons must be very clear.
168
 
169
{{< example show_markup="false">}}
170
<div class="row">
171
    <div class="col-5">
172
        <div class="card mb-2">
173
            <div class="card-body">
174
                <strong>Save Changes?</strong>
175
                <p>Would you like to not save your changes before exiting?</p>
176
                <div class="d-flex">
1441 ariadna 177
                    <button type="button" class="btn btn-primary me-1">Yes</button>
1 efrain 178
                    <button type="button" class="btn btn-secondary">No</button>
179
                </div>
180
            </div>
181
        </div>
182
        <div class="alert alert-warning">Avoid generic 'OK' or 'Yes', avoid confusing phrases</div>
183
    </div>
184
    <div class="col-5">
185
        <div class="card mb-2">
186
            <div class="card-body">
187
                <strong>Save Changes</strong>
188
                <p>Would you like to save your changes before exiting?</p>
189
                <div class="d-flex">
1441 ariadna 190
                    <button type="button" class="btn btn-primary me-1">Save</button>
1 efrain 191
                    <button type="button" class="btn btn-secondary">Discard</button>
192
                </div>
193
            </div>
194
        </div>
195
        <div class="alert alert-success">Avoid generic 'OK' or 'Yes', avoid confusing phrases</div>
196
    </div>
197
</div>
198
{{< /example >}}