Skip to content

Commit 9230992

Browse files
[progress-bar] Add progress_background
1 parent 77080d9 commit 9230992

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

docs/components-progress-bar.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,37 @@ Progress Bars has been implemented to simplify the use of the Progress Bar, with
117117
], {height: '20px'}) }}
118118
```
119119

120+
## Progress Background
121+
122+
### Parameters
123+
`progress_background()` macro, waits for 1 parameter:
124+
125+
| Parameter | Description | Type | Default |
126+
|:---------:|:------------------------------|:--------:|:-------:|
127+
| options | [Options](#Option) object | `object` | `{}` |
128+
129+
#### Option
130+
| Parameter | Description | Type | Default |
131+
|:---------:|-----------------------------------------------------------|:--------:|:--------------:|
132+
| color | Color of the progress (red, blue, ...) | `string` | `primary-lt` |
133+
| width | Width in percent of the progress (10, 15, 55) | `number` | `0` |
134+
| text | Text of the progress | `string` | *empty string* |
135+
| value | Value text displayed | `string` | *empty string* |
136+
| attr | Additional raw HTML attributes (`data-*`, `aria-*`, etc.) | object | `{}` |
137+
138+
139+
### Usage
140+
141+
```twig
142+
{% from '@Tabler/components/progress_bar.html.twig' import progress_background %}
143+
144+
{{ progress_background({width : 65, text: 'Poland'}) }}
145+
{{ progress_background({width : 35, text: 'Germany'}) }}
146+
{{ progress_background({width : 28, text: 'United Stated'}) }}
147+
{{ progress_background({width : 20, text: 'United Kingdom'}) }}
148+
{{ progress_background({width : 15, text: 'France'}) }}
149+
```
150+
120151
## Next steps
121152

122153
Please go back to the [Tabler bundle documentation](index.md) to find out more about using the theme.

templates/components/progress_bar.html.twig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,34 @@
163163
</div>
164164
</div>
165165
{%- endmacro %}
166+
167+
{% macro progress_background(options = {}) -%}
168+
{% from '@Tabler/includes/utils.html.twig' import attr_to_html %}
169+
170+
{% set _color = options.color ?? 'primary-lt' %}
171+
{% set _width = options.width ?? 0 %}
172+
{% set _text = options.text ?? '' %}
173+
{% set _value = options.value|default(_width ~ '%') %}
174+
{% set _attr = options.attr ?? {} %}
175+
176+
{% set progressBarClasses = ['progress-bar'] %}
177+
178+
{% if _color is not empty %}
179+
{% set progressBarClasses = progressBarClasses|merge(['bg-' ~ _color]) %}
180+
{% endif %}
181+
182+
<div
183+
class="progressbg"
184+
{{ attr_to_html(_attr) }}
185+
>
186+
<div class="progress progressbg-progress">
187+
<div class="{{ progressBarClasses|join(' ') }}" style="width: {{ _width }}%"></div>
188+
</div>
189+
{% if _text is not empty %}
190+
<div class="progressbg-text">{{ _text }}</div>
191+
{% endif %}
192+
{% if _value is not empty %}
193+
<div class="progressbg-value">{{ _value }}</div>
194+
{% endif %}
195+
</div>
196+
{%- endmacro %}

0 commit comments

Comments
 (0)