dolibarr 24.0.0-beta
badges.inc.php
1<?php
2/* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
3 * Copyright (C) 2025 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: 1em;
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;
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.badge-pill, .tabs .badge {
80 padding-right: .5em;
81 padding-left: .5em;
82 border-radius: 0.25rem;
83}
84
85.badge-dot {
86 padding: 0;
87 border-radius: 50%;
88 padding: 0.45em;
89 vertical-align: unset;
90}
91
92a.badge:focus, a.badge:hover {
93 text-decoration: none;
94}
95
96.liste_titre .badge:not(.nochangebackground) {
97 background-color: <?php print $badgeSecondary; ?>;
98 color: #fff;
99}
100
101span.badgeneutral {
102 padding: 2px 7px 2px 7px;
103 background-color: #e4e4e4;
104 color: #666;
105 border-radius: 10px;
106 white-space: nowrap;
107}
108span.badgeliketopmenu {
109 padding: 2px 7px 2px 7px;
110 background-color: var(--colorbackhmenu1);
111 color: var(--colorbackvmenu1);
112 border-radius: 10px;
113 white-space: nowrap;
114}
115
116/* PRIMARY */
117.badge-primary{
118 color: #fff !important;
119 background-color: <?php print $badgePrimary; ?>;
120}
121a.badge-primary.focus, a.badge-primary:focus {
122 outline: 0;
123 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgePrimary, 0.5); ?>;
124}
125a.badge-primary:focus, a.badge-primary:hover {
126 color: #fff !important;
127 background-color: <?php print colorDarker($badgePrimary, 10); ?>;
128}
129
130/* SECONDARY */
131.badge-secondary, .tabs .badge {
132 color: #fff !important;
133 background-color: <?php print $badgeSecondary; ?>;
134}
135a.badge-secondary.focus, a.badge-secondary:focus {
136 outline: 0;
137 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSecondary, 0.5); ?>;
138}
139a.badge-secondary:focus, a.badge-secondary:hover {
140 color: #fff !important;
141 background-color: <?php print colorDarker($badgeSecondary, 10); ?>;
142}
143
144/* SUCCESS */
145.badge-success {
146 color: #fff !important;
147 background-color: <?php print $badgeSuccess; ?>;
148}
149a.badge-success.focus, a.badge-success:focus {
150 outline: 0;
151 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSuccess, 0.5); ?>;
152}
153a.badge-success:focus, a.badge-success:hover {
154 color: #fff !important;
155 background-color: <?php print colorDarker($badgeSuccess, 10); ?>;
156}
157
158/* DANGER */
159.badge-danger {
160 color: #fff !important;
161 background-color: <?php print $badgeDanger; ?>;
162}
163a.badge-danger.focus, a.badge-danger:focus {
164 outline: 0;
165 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDanger, 0.5); ?>;
166}
167a.badge-danger:focus, a.badge-danger:hover {
168 color: #fff !important;
169 background-color: <?php print colorDarker($badgeDanger, 10); ?>;
170}
171
172/* WARNING */
173.badge-warning {
174 color: #fff !important;
175 background-color: <?php print $badgeWarning; ?>;
176}
177a.badge-warning.focus, a.badge-warning:focus {
178 outline: 0;
179 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeWarning, 0.5); ?>;
180}
181a.badge-warning:focus, a.badge-warning:hover {
182 color: #212529 !important;
183 background-color: <?php print colorDarker($badgeWarning, 10); ?>;
184}
185
186/* WARNING colorblind */
187body[class*="colorblind-"] .badge-warning {
188 background-color: <?php print $colorblind_deuteranopes_badgeWarning; ?>;
189 }
190body[class*="colorblind-"] a.badge-warning.focus,body[class^="colorblind-"] a.badge-warning:focus {
191 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($colorblind_deuteranopes_badgeWarning, 0.5); ?>;
192}
193body[class*="colorblind-"] a.badge-warning:focus, a.badge-warning:hover {
194 background-color: <?php print colorDarker($colorblind_deuteranopes_badgeWarning, 10); ?>;
195}
196
197/* INFO */
198.badge-info {
199 color: #fff !important;
200 background-color: <?php print $badgeInfo; ?>;
201}
202a.badge-info.focus, a.badge-info:focus {
203 outline: 0;
204 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeInfo, 0.5); ?>;
205}
206a.badge-info:focus, a.badge-info:hover {
207 color: #fff !important;
208 background-color: <?php print colorDarker($badgeInfo, 10); ?>;
209}
210
211/* LIGHT */
212.badge-light {
213 color: #212529 !important;
214 background-color: <?php print $badgeLight; ?>;
215}
216a.badge-light.focus, a.badge-light:focus {
217 outline: 0;
218 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeLight, 0.5); ?>;
219}
220a.badge-light:focus, a.badge-light:hover {
221 color: #212529 !important;
222 background-color: <?php print colorDarker($badgeLight, 10); ?>;
223}
224
225/* DARK */
226.badge-dark {
227 color: #fff !important;
228 background-color: <?php print $badgeDark; ?>;
229}
230a.badge-dark.focus, a.badge-dark:focus {
231 outline: 0;
232 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDark, 0.5); ?>;
233}
234a.badge-dark:focus, a.badge-dark:hover {
235 color: #fff !important;
236 background-color: <?php print colorDarker($badgeDark, 10); ?>;
237}
238
239
240@media only screen and (max-width: 570px)
241{
242 span.badge.badge-status {
243 overflow: hidden;
244 max-width: 130px;
245 text-overflow: ellipsis;
246 }
247}
248
249
250/* STATUS BADGES */
251<?php
252for ($i = 0; $i <= 10; $i++) {
253 /* Default Status */
254 _createStatusBadgeCss((string) $i, '', "STATUS".$i);
255
256 // create status for accessibility
257 _createStatusBadgeCss((string) $i, 'colorblind_deuteranopes_', "COLORBLIND STATUS".$i, 'body[class*="colorblind-"] ');
258}
259
260_createStatusBadgeCss('1b', '', "STATUS1b");
261_createStatusBadgeCss('4b', '', "STATUS4b");
262
274function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentLabel = '', $cssPrefix = '')
275{
276 global ${$statusVarNamePrefix.'badgeStatus'.$statusName}, ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName};
277
278 if (!empty(${$statusVarNamePrefix.'badgeStatus'.$statusName})) {
279 print "\n/* ".strtoupper($commentLabel)." - ".$statusName." */\n";
280
281 $thisBadgeBackgroundColor = $thisBadgeBorderColor = ${$statusVarNamePrefix.'badgeStatus'.$statusName};
282
283
284 $TBadgeBorderOnly = array('0', '1b', '3', '4b', '5', '7', '10');
285 $varname = $statusVarNamePrefix.'badgeStatus'.$statusName;
286 $thisBadgeTextColor = colorIsLight(${$varname}) ? '#212529' : '#ffffff';
287
288 if (!empty(${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName})) {
289 $varname = $statusVarNamePrefix.'badgeStatus_textColor'.$statusName;
290 $thisBadgeTextColor = ${$varname};
291 }
292
293 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
294 $thisBadgeTextColor = '#9c850b';
295 $thisBadgeBackgroundColor = "#fff";
296 }
297
298 if (in_array((string) $statusName, array('4b'))) {
299 $thisBadgeTextColor = '#25a580';
300 }
301 if (in_array((string) $statusName, array('7'))) {
302 $thisBadgeTextColor = '#277d1e';
303 }
304 if (in_array((string) $statusName, array('0', '5', '9', '10'))) {
305 $thisBadgeTextColor = '#999999';
306 }
307 if (in_array((string) $statusName, array('6'))) {
308 $thisBadgeTextColor = '#777777';
309 }
310
311 // badge-statusX
312 print $cssPrefix.".badge-status".$statusName." {\n";
313 print " color: ".$thisBadgeTextColor." !important;\n";
314 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
315 print " border-color: ".$thisBadgeBorderColor." !important;\n";
316 }
317 if ($thisBadgeBackgroundColor != '') {
318 print " background-color: ".$thisBadgeBackgroundColor." !important;\n";
319 }
320 print "}\n";
321
322 print $cssPrefix.".font-status".$statusName." {\n";
323 if ($thisBadgeBackgroundColor != '') {
324 print " color: ".$thisBadgeBackgroundColor." !important;\n";
325 }
326 print "}\n";
327
328 // badge-statusX:focus
329
330 print $cssPrefix.".badge-status".$statusName.".focus, ".$cssPrefix.".badge-status".$statusName.":focus {\n";
331 print " outline: 0;\n";
332 print " box-shadow: 0 0 0 0.2rem ".colorHexToRgb($thisBadgeBackgroundColor, 0.5)." !important;\n";
333 print "}\n";
334
335 print $cssPrefix.".badge-status".$statusName.":focus, ".$cssPrefix.".badge-status".$statusName.":hover {\n";
336 print " color: ".$thisBadgeTextColor." !important;\n";
337 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
338 print " border-color: ".colorDarker($thisBadgeBorderColor, 10)." !important;\n";
339 }
340 print "}\n";
341 }
342}
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)