dolibarr 25.0.0-alpha
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
123span.badge-oppstatus {
124 color: #fff !important;
125 background-color: #776666;
126}
127
128
129/* PRIMARY */
130.badge-primary{
131 color: #fff !important;
132 background-color: <?php print $badgePrimary; ?>;
133}
134a.badge-primary.focus, a.badge-primary:focus {
135 outline: 0;
136 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgePrimary, 0.5); ?>;
137}
138a.badge-primary:focus, a.badge-primary:hover {
139 color: #fff !important;
140 background-color: <?php print colorDarker($badgePrimary, 10); ?>;
141}
142
143/* SECONDARY */
144.badge-secondary, .tabs .badge {
145 color: #fff !important;
146 background-color: <?php print $badgeSecondary; ?>;
147}
148a.badge-secondary.focus, a.badge-secondary:focus {
149 outline: 0;
150 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSecondary, 0.5); ?>;
151}
152a.badge-secondary:focus, a.badge-secondary:hover {
153 color: #fff !important;
154 background-color: <?php print colorDarker($badgeSecondary, 10); ?>;
155}
156
157/* SUCCESS */
158.badge-success {
159 color: #fff !important;
160 background-color: <?php print $badgeSuccess; ?>;
161}
162a.badge-success.focus, a.badge-success:focus {
163 outline: 0;
164 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSuccess, 0.5); ?>;
165}
166a.badge-success:focus, a.badge-success:hover {
167 color: #fff !important;
168 background-color: <?php print colorDarker($badgeSuccess, 10); ?>;
169}
170
171/* DANGER */
172.badge-danger {
173 color: #fff !important;
174 background-color: <?php print $badgeDanger; ?>;
175}
176a.badge-danger.focus, a.badge-danger:focus {
177 outline: 0;
178 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDanger, 0.5); ?>;
179}
180a.badge-danger:focus, a.badge-danger:hover {
181 color: #fff !important;
182 background-color: <?php print colorDarker($badgeDanger, 10); ?>;
183}
184
185/* WARNING */
186.badge-warning {
187 color: #fff !important;
188 background-color: <?php print $badgeWarning; ?>;
189}
190a.badge-warning.focus, a.badge-warning:focus {
191 outline: 0;
192 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeWarning, 0.5); ?>;
193}
194a.badge-warning:focus, a.badge-warning:hover {
195 color: #212529 !important;
196 background-color: <?php print colorDarker($badgeWarning, 10); ?>;
197}
198
199/* WARNING colorblind */
200body[class*="colorblind-"] .badge-warning {
201 background-color: <?php print $colorblind_deuteranopes_badgeWarning; ?>;
202 }
203body[class*="colorblind-"] a.badge-warning.focus,body[class^="colorblind-"] a.badge-warning:focus {
204 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($colorblind_deuteranopes_badgeWarning, 0.5); ?>;
205}
206body[class*="colorblind-"] a.badge-warning:focus, a.badge-warning:hover {
207 background-color: <?php print colorDarker($colorblind_deuteranopes_badgeWarning, 10); ?>;
208}
209
210/* INFO */
211.badge-info {
212 color: #fff !important;
213 background-color: <?php print $badgeInfo; ?>;
214}
215a.badge-info.focus, a.badge-info:focus {
216 outline: 0;
217 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeInfo, 0.5); ?>;
218}
219a.badge-info:focus, a.badge-info:hover {
220 color: #fff !important;
221 background-color: <?php print colorDarker($badgeInfo, 10); ?>;
222}
223
224/* LIGHT */
225.badge-light {
226 color: #212529 !important;
227 background-color: <?php print $badgeLight; ?>;
228}
229a.badge-light.focus, a.badge-light:focus {
230 outline: 0;
231 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeLight, 0.5); ?>;
232}
233a.badge-light:focus, a.badge-light:hover {
234 color: #212529 !important;
235 background-color: <?php print colorDarker($badgeLight, 10); ?>;
236}
237
238/* DARK */
239.badge-dark {
240 color: #fff !important;
241 background-color: <?php print $badgeDark; ?>;
242}
243a.badge-dark.focus, a.badge-dark:focus {
244 outline: 0;
245 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDark, 0.5); ?>;
246}
247a.badge-dark:focus, a.badge-dark:hover {
248 color: #fff !important;
249 background-color: <?php print colorDarker($badgeDark, 10); ?>;
250}
251
252
253@media only screen and (max-width: 570px)
254{
255 span.badge.badge-status {
256 overflow: hidden;
257 max-width: 130px;
258 text-overflow: ellipsis;
259 }
260}
261
262
263/* STATUS BADGES */
264<?php
265for ($i = 0; $i <= 10; $i++) {
266 /* Default Status */
267 _createStatusBadgeCss((string) $i, '', "STATUS".$i);
268
269 // create status for accessibility
270 _createStatusBadgeCss((string) $i, 'colorblind_deuteranopes_', "COLORBLIND STATUS".$i, 'body[class*="colorblind-"] ');
271}
272
273_createStatusBadgeCss('1b', '', "STATUS1b");
274_createStatusBadgeCss('4b', '', "STATUS4b");
275
276
288function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentLabel = '', $cssPrefix = '')
289{
290 global ${$statusVarNamePrefix.'badgeStatus'.$statusName}, ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName};
291
292 if (!empty(${$statusVarNamePrefix.'badgeStatus'.$statusName})) {
293 print "\n/* ".strtoupper($commentLabel)." - ".$statusName." */\n";
294
295 $thisBadgeBackgroundColor = $thisBadgeBorderColor = ${$statusVarNamePrefix.'badgeStatus'.$statusName};
296
297 $TBadgeBorderOnly = array('0', '1b', '3', '4b', '5', '7', '10');
298 $thisBadgeTextColor = colorIsLight(${$statusVarNamePrefix.'badgeStatus'.$statusName}) ? '#212529' : '#ffffff';
299
300 if (!empty(${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName})) {
301 $thisBadgeTextColor = ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName};
302 }
303
304 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
305 $thisBadgeTextColor = '#9c850b';
306 $thisBadgeBackgroundColor = "hsl(0, 0%, 0%, 0)";
307 }
308
309 if (in_array((string) $statusName, array('4b', '7'))) {
310 $thisBadgeTextColor = '#25a580';
311 }
312 if (in_array((string) $statusName, array('0', '5', '9', '10'))) {
313 $thisBadgeTextColor = '#999999';
314 }
315 if (in_array((string) $statusName, array('6'))) {
316 $thisBadgeTextColor = '#777777';
317 }
318
319 // badge-statusX
320 print $cssPrefix.".badge-status".$statusName." {\n";
321 print " color: ".$thisBadgeTextColor." !important;\n";
322 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
323 print " border-color: ".$thisBadgeBorderColor." !important;\n";
324 }
325 if ($thisBadgeBackgroundColor != '') {
326 print " background-color: ".$thisBadgeBackgroundColor." !important;\n";
327 }
328 print "}\n";
329
330 print $cssPrefix.".font-status".$statusName." {\n";
331 if ($thisBadgeBackgroundColor != '') {
332 print " color: ".$thisBadgeBackgroundColor." !important;\n";
333 }
334 print "}\n";
335
336 // badge-statusX:focus
337
338 print $cssPrefix.".badge-status".$statusName.".focus, ".$cssPrefix.".badge-status".$statusName.":focus {\n";
339 print " outline: 0;\n";
340 print " box-shadow: 0 0 0 0.2rem ".colorHexToRgb($thisBadgeBackgroundColor, 0.5)." !important;\n";
341 print "}\n";
342
343 print $cssPrefix.".badge-status".$statusName.":focus, ".$cssPrefix.".badge-status".$statusName.":hover {\n";
344 print " color: ".$thisBadgeTextColor." !important;\n";
345 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
346 print " border-color: ".colorDarker($thisBadgeBorderColor, 10)." !important;\n";
347 }
348 print "}\n";
349 }
350}
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:169
colorHexToRgb($hex, $alpha=false, $returnArray=false)
colorDarker($hex, $percent)
colorIsLight($stringcolor)
Return true if the color is light.