diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d2e8aab98f9..d94862cf842 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7920,3 +7920,130 @@ function roundUpToNextMultiple($n, $x = 5) { return (ceil($n)%$x === 0) ? ceil($n) : round(($n+$x/2)/$x)*$x; } + +/** + * @param string $label label of badge no html : use in alt attribute for accessibility + * @param string $html optional : label of badge with html + * @param string $type type of badge : Primary Secondary Success Danger Warning Info Light Dark status0 status1 status2 status3 status4 status5 status6 status7 status8 status9 + * @param string $mode + * @param array $params + * @return string + */ +function badgeHelper($label, $html='', $type='primary', $mode='', $url='', $params=array()) +{ + + if(empty($html)){ + $html = $label; + } + + $attr=array( + 'class'=>'badge'.(!empty($mode)?' badge-'.$mode:'').(!empty($type)?' badge-'.$type:'') + ,'aria-label'=>$label + ); + + if(!empty($url)){ + $attr['href'] = $url; + } + + if($mode==='dot') + { + $attr['class'].= ' classfortooltip'; + $attr['title'] = $html; + $html=''; + } + + // Override attr + if(!empty($params['attr']) && is_array($params['attr'])){ + foreach($params['attr']as $key => $value){ + $attr[$key] = $value; + } + } + + + // escape all attribute + $attr = array_map('dol_escape_htmltag', $attr); + + $TCompiledAttr = array(); + foreach($attr as $key => $value){ + $TCompiledAttr[] = $key.'="'.$value.'"'; + } + + $compiledAttributes = !empty($TCompiledAttr)?implode(' ',$TCompiledAttr):''; + + $tag = !empty($url)?'a':'span'; + + + return '<'.$tag.' '.$compiledAttributes.'>'.$html.''.$tag.'>'; +} + + +/** + * @param string $statusLabel label of badge no html : use in alt attribute for accessibility + * @param string $html optional : label of badge with html + * @param string $statusType status0 status1 status2 status3 status4 status5 status6 status7 status8 status9 : image name or badge name + * @param int $displayMode for retrocompatibility 0=label only, 1=label + Picto, 2=Picto, 3=Picto + label + * @param string $url + * @param array $params + * @return string + */ +function statusHelper($statusLabel='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array()) +{ + global $conf; + + // image's filename are still in French + $statusImg=array( + 'status0' => 'statut0' + ,'status1' => 'statut1' + ,'status2' => 'statut2' + ,'status3' => 'statut3' + ,'status4' => 'statut4' + ,'status5' => 'statut5' + ,'status6' => 'statut6' + ,'status7' => 'statut7' + ,'status8' => 'statut8' + ,'status9' => 'statut9' + ); + + if($displayMode==0){ + $return = !empty($html)?$html:$statusLabel; + } + // use status with images + elseif(empty($conf->global->MAIN_STATUS_USES_CSS)){ + $return = ''; + $htmlLabel = ''.(!empty($html)?$html:$statusLabel).''; + + if(!empty($statusImg[$statusType])){ + $htmlImg = img_picto($statusLabel, $statusImg[$statusType]); + }else{ + $htmlImg = img_picto($statusLabel, $statusType); + } + + + + if($displayMode===1){ + $return = $htmlLabel .' '. $htmlImg; + } + elseif($displayMode===2){ + $return = $htmlImg; + } + elseif($displayMode===3){ + $return = $htmlImg .' '. $htmlLabel; + } + else{ + $return = !empty($html)?$html:$statusLabel; + } + + + } + + // Use new badge + if(!empty($conf->global->MAIN_STATUS_USES_CSS) && !empty($displayMode)){ + + $mode = 'pill'; + if($displayMode == 2)$mode = 'dot'; + + $return = badgeHelper($statusLabel, $html,$statusType,$mode); + } + + return $return; +} diff --git a/htdocs/theme/eldy/_badges.css.php b/htdocs/theme/eldy/_badges.css.php index e09cff07095..de3411c8b1c 100644 --- a/htdocs/theme/eldy/_badges.css.php +++ b/htdocs/theme/eldy/_badges.css.php @@ -7,7 +7,7 @@ if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?> .badge { display: inline-block; - padding: .2em .35em; + padding: .1em .35em; font-size: 80%; font-weight: 700 !important; line-height: 1; @@ -16,9 +16,10 @@ if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?> vertical-align: baseline; border-radius: .25rem; transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out; - border-width: 3px; + border-width: 2px; border-style: solid; border-color: rgba(255,255,255,0); + box-sizing: border-box; } .badge-pill { @@ -30,7 +31,8 @@ if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?> .badge-dot { padding: 0; border-radius: 50%; - padding: 0.8em; + padding: 0.6em; + vertical-align: middle; } a.badge:focus, a.badge:hover { @@ -161,7 +163,7 @@ a.badge-dark:focus, a.badge-dark:hover {
@@ -6,6 +21,7 @@ + @@ -16,7 +32,7 @@Badges scale to match the size of the immediate parent element by using relative font sizing and em units.
Badges scale to match the size of the immediate parent element by using relative font sizing and em units.
-
+
<h1>Example heading <span class="badge badge-secondary">New</span></h1>
<h2>Example heading <span class="badge badge-secondary">New</span></h2>
<h3>Example heading <span class="badge badge-secondary">New</span></h3>
<h4>Example heading <span class="badge badge-secondary">New</span></h4>
<h5>Example heading <span class="badge badge-secondary">New</span></h5>
<h6>Example heading <span class="badge badge-secondary">New</span></h6>
-
+
+
<button type="button" class="button">
Notifications <span class="badge badge-primary">4</span>
</button>
-
Note that depending on how they are used, badges may be confusing for users of screen readers and similar assistive technologies. While the styling of badges provides a visual cue as to their purpose, these users will simply be presented with the content of the badge. Depending on the specific situation, these badges may seem like random additional words or numbers at the end of a sentence, link, or button.
@@ -71,14 +87,14 @@
-
+
<button type="button" class="btn btn-primary">
Profile <span class="badge badge-light" aria-label="9 unread messages" >9</span>
<span class="sr-only">unread messages</span>
</button>
-
+
-
+
<span class="badge badge-primary">Primary</span>
<span class="badge badge-secondary">Secondary</span>
<span class="badge badge-success">Success</span>
@@ -109,14 +125,14 @@
<span class="badge badge-info">Info</span>
<span class="badge badge-light">Light</span>
<span class="badge badge-dark">Dark</span>
-
+
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .sr-only class.
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .sr-only class.
+
-<span class="badge badge-status-" >status-</span>
+<span class="badge badge-status" >status</span>
-
Use the .badge-pill modifier class to make badges more rounded (with a larger border-radius and additional horizontal padding).
Use the .badge-pill modifier class to make badges more rounded (with a larger border-radius and additional horizontal padding).
-
+
<span class="badge badge-pill badge-primary">Primary</span>
<span class="badge badge-pill badge-secondary">Secondary</span>
<span class="badge badge-pill badge-success">Success</span>
@@ -171,15 +187,15 @@
<span class="badge badge-pill badge-light">Light</span>
<span class="badge badge-pill badge-dark">Dark</span>
-<span class="badge badge-pill badge-status-" >status-</span>
+<span class="badge badge-pill badge-status" >status</span>
- Use the .dot-pill modifier class to make badges circle.
.dot-pill modifier class to make badges circle.
-
-<span class="badge badge-dot badge-primary">Primary</span>
-<span class="badge badge-dot badge-secondary">Secondary</span>
-<span class="badge badge-dot badge-success">Success</span>
-<span class="badge badge-dot badge-danger">Danger</span>
-<span class="badge badge-dot badge-warning">Warning</span>
-<span class="badge badge-dot badge-info">Info</span>
-<span class="badge badge-dot badge-light">Light</span>
-<span class="badge badge-dot badge-dark">Dark</span>
+
+<span class="badge badge-dot badge-primary"></span>
+<span class="badge badge-dot badge-secondary"></span>
+<span class="badge badge-dot badge-success"></span>
+<span class="badge badge-dot badge-danger"></span>
+<span class="badge badge-dot badge-warning"></span>
+<span class="badge badge-dot badge-info"></span>
+<span class="badge badge-dot badge-light"></span>
+<span class="badge badge-dot badge-dark"></span>
-<span class="badge badge-dot badge-status-" >status-</span>
+<span class="badge badge-dot badge-status" ></span>
- Using the contextual .badge-* classes on an <a> element quickly provide actionable badges with hover and focus states.
Using the contextual .badge-* classes on an <a> element quickly provide actionable badges with hover and focus states.
-
+
<a href="#" class="badge badge-primary">Primary</a>
<a href="#" class="badge badge-secondary">Secondary</a>
<a href="#" class="badge badge-success">Success</a>
@@ -254,16 +270,43 @@
<a href="#" class="badge badge-light">Light</a>
<a href="#" class="badge badge-dark">Dark</a>
-<a href="#" class="badge badge-status-" >status-</a>
+<a href="#" class="badge badge-status" >status</a>
-
Using the badgeHelper function provide in core/lib/functions.lib.php. This function is recommended for code uniformisation and easy maintain
+ with html', 'primary') ?> + with html', 'danger', 'pill') ?> + with html', 'warning', 'dot') ?> +
+<?php print badgeHelper('your label for accessibility', ' your label with html', 'primary') ?>
+<?php print badgeHelper('your label for accessibility', ' your label with html', 'danger', 'pill') ?>
+<?php print badgeHelper('your label for accessibility', ' your label with html', 'warning', 'dot') ?>
+ Using the statusHelper function provide in core/lib/functions.lib.php. This function is recommended for code uniformisation and easy maintain
+ global->MAIN_STATUS_USES_CSS; + $conf->global->MAIN_STATUS_USES_CSS = 1; + ?> +with html', 'status4') ?>
+with html', 'status4',1) ?>
+with html', 'status4',2) ?>
+with html', 'status4',3) ?>
+ + global->MAIN_STATUS_USES_CSS = 0; ?> +with html', 'status4') ?>
+with html', 'status4',1) ?>
+with html', 'status4',2) ?>
+with html', 'status4',3) ?>
+ + global->MAIN_STATUS_USES_CSS = $saveGlobalConf; ?>