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