dolibarr 24.0.0-beta
badges.inc.php
1<?php
2/* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 */
5if (!defined('ISLOADEDBYSTEELSHEET')) {
6 die('Must be called by steelsheet');
7}
8
9// From theme_vars.inc, must be included by steelsheet
21'
22@phan-var-force string $badgePrimary
23@phan-var-force string $badgeSecondary
24@phan-var-force string $badgeSuccess
25@phan-var-force string $badgeDanger
26@phan-var-force string $badgeWarning
27@phan-var-force string $badgeInfo
28@phan-var-force string $badgeLight
29@phan-var-force string $badgeDark
30@phan-var-force string $colorblind_deuteranopes_badgeWarning
31';
32?>
33
34/* IDE Hack <style type="text/css"> */
35
36/* Badge style is based on bootstrap framework */
37
38.badge {
39 display: inline-block;
40 padding: .1em .35em;
41 font-size: 80%;
42 font-weight: 700 !important;
43 line-height: 1;
44 text-align: center;
45 white-space: nowrap;
46 vertical-align: baseline;
47 border-radius: .25rem;
48 transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
49 border-width: 2px;
50 border-style: solid;
51 border-color: rgba(255,255,255,0);
52 box-sizing: border-box;
53}
54
55.badge-text {
56 padding: 3px;
57 padding-left: 5px;
58 padding-right: 5px;
59 border-radius: 5px;
60}
61
62.badge-status {
63 font-size: 0.95em;
64 padding: .19em .35em; /* more than 0.19 generate a change into height of lines */
65}
66.tabBar .arearef .statusref .badge-status, .tabBar .arearefnobottom .statusref .badge-status {
67 font-size: 1.1em;
68 padding: .4em .4em .3em .4em;
69}
70/* Force values for small screen 767 */
71@media only screen and (max-width: 767px)
72{
73 .tabBar .arearef .statusref .badge-status, .tabBar .arearefnobottom .statusref .badge-status {
74 font-size: 0.95em;
75 padding: .3em .2em;
76 }
77}
78
79.tabs .badge {
80 padding-right: .5em;
81 padding-left: .5em;
82 border-radius: 0.25rem;
83}
84
85.badge-pill{
86 /* Use the .badge-pill modifier class to make badges more rounded (with a larger border-radius and additional horizontal padding). */
87 padding-right: .8em;
88 padding-left: 0.8em;
89 border-radius: 0.5rem;
90}
91
92.badge-dot {
93 padding: 0;
94 border-radius: 50%;
95 padding: 0.45em;
96 vertical-align: text-top;
97}
98
99a.badge:focus, a.badge:hover {
100 text-decoration: none;
101}
102
103.liste_titre .badge:not(.nochangebackground) {
104 background-color: <?php print $badgeSecondary; ?>;
105 color: #fff;
106}
107
108span.badgeneutral {
109 padding: 2px 7px 2px 7px;
110 background-color: #e4e4e4;
111 color: #666;
112 border-radius: 10px;
113 white-space: nowrap;
114}
115span.badgeliketopmenu {
116 padding: 2px 7px 2px 7px;
117 background-color: var(--colorbackhmenu1);
118 color: var(--colorbackvmenu1);
119 border-radius: 10px;
120 white-space: nowrap;
121}
122
123/* PRIMARY */
124.badge-primary{
125 color: #fff !important;
126 background-color: <?php print $badgePrimary; ?>;
127}
128a.badge-primary.focus, a.badge-primary:focus {
129 outline: 0;
130 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgePrimary, 0.5); ?>;
131}
132a.badge-primary:focus, a.badge-primary:hover {
133 color: #fff !important;
134 background-color: <?php print colorDarker($badgePrimary, 10); ?>;
135}
136
137/* SECONDARY */
138.badge-secondary, .tabs .badge {
139 color: #fff !important;
140 background-color: <?php print $badgeSecondary; ?>;
141}
142a.badge-secondary.focus, a.badge-secondary:focus {
143 outline: 0;
144 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSecondary, 0.5); ?>;
145}
146a.badge-secondary:focus, a.badge-secondary:hover {
147 color: #fff !important;
148 background-color: <?php print colorDarker($badgeSecondary, 10); ?>;
149}
150
151/* SUCCESS */
152.badge-success {
153 color: #fff !important;
154 background-color: <?php print $badgeSuccess; ?>;
155}
156a.badge-success.focus, a.badge-success:focus {
157 outline: 0;
158 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSuccess, 0.5); ?>;
159}
160a.badge-success:focus, a.badge-success:hover {
161 color: #fff !important;
162 background-color: <?php print colorDarker($badgeSuccess, 10); ?>;
163}
164
165/* DANGER */
166.badge-danger {
167 color: #fff !important;
168 background-color: <?php print $badgeDanger; ?>;
169}
170a.badge-danger.focus, a.badge-danger:focus {
171 outline: 0;
172 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDanger, 0.5); ?>;
173}
174a.badge-danger:focus, a.badge-danger:hover {
175 color: #fff !important;
176 background-color: <?php print colorDarker($badgeDanger, 10); ?>;
177}
178
179/* WARNING */
180.badge-warning {
181 color: #fff !important;
182 background-color: <?php print $badgeWarning; ?>;
183}
184a.badge-warning.focus, a.badge-warning:focus {
185 outline: 0;
186 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeWarning, 0.5); ?>;
187}
188a.badge-warning:focus, a.badge-warning:hover {
189 color: #212529 !important;
190 background-color: <?php print colorDarker($badgeWarning, 10); ?>;
191}
192
193/* WARNING colorblind */
194body[class*="colorblind-"] .badge-warning {
195 background-color: <?php print $colorblind_deuteranopes_badgeWarning; ?>;
196 }
197body[class*="colorblind-"] a.badge-warning.focus,body[class^="colorblind-"] a.badge-warning:focus {
198 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($colorblind_deuteranopes_badgeWarning, 0.5); ?>;
199}
200body[class*="colorblind-"] a.badge-warning:focus, a.badge-warning:hover {
201 background-color: <?php print colorDarker($colorblind_deuteranopes_badgeWarning, 10); ?>;
202}
203
204/* INFO */
205.badge-info {
206 color: #fff !important;
207 background-color: <?php print $badgeInfo; ?>;
208}
209a.badge-info.focus, a.badge-info:focus {
210 outline: 0;
211 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeInfo, 0.5); ?>;
212}
213a.badge-info:focus, a.badge-info:hover {
214 color: #fff !important;
215 background-color: <?php print colorDarker($badgeInfo, 10); ?>;
216}
217
218/* LIGHT */
219.badge-light {
220 color: #212529 !important;
221 background-color: <?php print $badgeLight; ?>;
222}
223a.badge-light.focus, a.badge-light:focus {
224 outline: 0;
225 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeLight, 0.5); ?>;
226}
227a.badge-light:focus, a.badge-light:hover {
228 color: #212529 !important;
229 background-color: <?php print colorDarker($badgeLight, 10); ?>;
230}
231
232/* DARK */
233.badge-dark {
234 color: #fff !important;
235 background-color: <?php print $badgeDark; ?>;
236}
237a.badge-dark.focus, a.badge-dark:focus {
238 outline: 0;
239 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDark, 0.5); ?>;
240}
241a.badge-dark:focus, a.badge-dark:hover {
242 color: #fff !important;
243 background-color: <?php print colorDarker($badgeDark, 10); ?>;
244}
245
246
247@media only screen and (max-width: 570px)
248{
249 span.badge.badge-status {
250 overflow: hidden;
251 max-width: 130px;
252 text-overflow: ellipsis;
253 }
254}
255
256
257/* STATUS BADGES */
258<?php
259for ($i = 0; $i <= 10; $i++) {
260 /* Default Status */
261 _createStatusBadgeCss((string) $i, '', "STATUS".$i);
262
263 // create status for accessibility
264 _createStatusBadgeCss((string) $i, 'colorblind_deuteranopes_', "COLORBLIND STATUS".$i, 'body[class*="colorblind-"] ');
265}
266
267_createStatusBadgeCss('1b', '', "STATUS1b");
268_createStatusBadgeCss('4b', '', "STATUS4b");
269
270
282function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentLabel = '', $cssPrefix = '')
283{
284 global ${$statusVarNamePrefix.'badgeStatus'.$statusName}, ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName};
285
286 if (!empty(${$statusVarNamePrefix.'badgeStatus'.$statusName})) {
287 print "\n/* ".strtoupper($commentLabel)." - ".$statusName." */\n";
288
289 $thisBadgeBackgroundColor = $thisBadgeBorderColor = ${$statusVarNamePrefix.'badgeStatus'.$statusName};
290
291 $TBadgeBorderOnly = array('0', '1b', '3', '4b', '5', '7', '10');
292 $thisBadgeTextColor = colorIsLight(${$statusVarNamePrefix.'badgeStatus'.$statusName}) ? '#212529' : '#ffffff';
293
294 if (!empty(${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName})) {
295 $thisBadgeTextColor = ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName};
296 }
297
298 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
299 $thisBadgeTextColor = '#9c850b';
300 $thisBadgeBackgroundColor = "hsl(0, 0%, 0%, 0)";
301 }
302
303 if (in_array((string) $statusName, array('4b', '7'))) {
304 $thisBadgeTextColor = '#25a580';
305 }
306 if (in_array((string) $statusName, array('0', '5', '9', '10'))) {
307 $thisBadgeTextColor = '#999999';
308 }
309 if (in_array((string) $statusName, array('6'))) {
310 $thisBadgeTextColor = '#777777';
311 }
312
313 // badge-statusX
314 print $cssPrefix.".badge-status".$statusName." {\n";
315 print " color: ".$thisBadgeTextColor." !important;\n";
316 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
317 print " border-color: ".$thisBadgeBorderColor." !important;\n";
318 }
319 if ($thisBadgeBackgroundColor != '') {
320 print " background-color: ".$thisBadgeBackgroundColor." !important;\n";
321 }
322 print "}\n";
323
324 print $cssPrefix.".font-status".$statusName." {\n";
325 if ($thisBadgeBackgroundColor != '') {
326 print " color: ".$thisBadgeBackgroundColor." !important;\n";
327 }
328 print "}\n";
329
330 // badge-statusX:focus
331
332 print $cssPrefix.".badge-status".$statusName.".focus, ".$cssPrefix.".badge-status".$statusName.":focus {\n";
333 print " outline: 0;\n";
334 print " box-shadow: 0 0 0 0.2rem ".colorHexToRgb($thisBadgeBackgroundColor, 0.5)." !important;\n";
335 print "}\n";
336
337 print $cssPrefix.".badge-status".$statusName.":focus, ".$cssPrefix.".badge-status".$statusName.":hover {\n";
338 print " color: ".$thisBadgeTextColor." !important;\n";
339 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
340 print " border-color: ".colorDarker($thisBadgeBorderColor, 10)." !important;\n";
341 }
342 print "}\n";
343 }
344}
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:168
colorHexToRgb($hex, $alpha=false, $returnArray=false)
colorDarker($hex, $percent)