Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#454 Add ProgressField #483

Merged
merged 9 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ All new SCSS files must be imported before the import of Crudit SCSS.
- [Add a map to a list or to a show](doc/map_config.md)
- [How to export data](doc/export.md)
- [Workflows](doc/workflow.md)
- [ProgressBarField](doc/progressbar_field.md)
- [Markdown](doc/markdown.md)
- [Color list](doc/color_list.md)
- [Twig extensions](doc/twig.md)
Expand Down
36 changes: 36 additions & 0 deletions doc/progressbar_field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Crudit ProgressBar Field

### Usage

To enable the progress bar for a field, you need to set the type:

```php
$value = Field::new("value", ProgressField::class);
```
And it's done !

### Attributs

You can customize your ProgressField with the following options:

- 'barCssClass' => Defines the color of the progress bar with a Bootstrap class,
- 'progressLabel' => Change the label displayed on the progress bar,
- 'progressLabelCssClass' => Defines the Bootstrap class for the label to customize it,
- 'min' => Integer who defines the minimum value,
- 'max' => integer who defines the maximum value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'aimerais bien qu'on puisse avoir ça à partir d'une propriété/méthode dans l'entité.

si l'entité définit son propre maximum, on peut pas avoir une valeur fixe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ce qui est prévu c'est que l'entité calcule le pourcentage, donc le dev peut le faire avec n'importe quelle valeur de maximum. Par défaut, c'est 100 et 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

si c'est un pourcentage le min max ce sera toujours 0 à 100 si jamais

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

donc pas très utile d'avoir ces 2 options

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

effectivement ca n'a que peux d'interet.

- 'isBottomLabelActivate' => activates or deactivates the bottom label with true/false,
- 'bottomLabel' => Change the label under the bar,

### Example:

```php
$nbDeplacement = Field::new('nbDeplacement', ProgressBarField::class)
->setOptions(
[
"barCssClass" => "bg-info",
"progressLabel" => "Example"
"progressLabelCssClass" => "lh-sm fa-sm text-black"
"isBottomLabelActivate" => true,
]
);
```
34 changes: 34 additions & 0 deletions src/Field/ProgressBarField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Lle\CruditBundle\Field;

use Symfony\Component\OptionsResolver\OptionsResolver;

class ProgressBarField extends AbstractField
{
public function support(string $type): bool
{
return (in_array($type, ["progress", self::class]));
}

public function getDefaultTemplate(): ?string
{
return "@LleCrudit/field/progressbar.html.twig";
}

public function configureOptions(OptionsResolver $optionsResolver): void
{
parent::configureOptions($optionsResolver);
$optionsResolver->setDefaults([
"barCssClass" => null,
"progressLabel" => null,
"progressLabelCssClass" => null,
"min" => 0,
"max" => 100,
"isBottomLabelActivate" => false,
"bottomLabel" => null,
]);
}
}
3 changes: 3 additions & 0 deletions src/Resources/config/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ services:
Lle\CruditBundle\Field\UrlField:
arguments: ['@twig']
tags: ['crudit.field']
Lle\CruditBundle\Field\ProgressBarField:
arguments: ['@twig']
tags: ['crudit.field']
30 changes: 30 additions & 0 deletions src/Resources/views/field/progressbar.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="position-relative d-flex">
<div class="progress w-100" role="progressbar" aria-valuenow="{{ value }}"
aria-valuemin="{{ options.min }}" aria-valuemax="{{ options.max }}">
<div class="progress-bar
{% if value > options.max %} bg-danger
{% else %} bg-primary {% endif %}
{% if options.barCssClass %} {{ options.barCssClass }}{% endif %}
progress-bar-animated" style="width: {{ value }}%;">
</div>
</div>
<div class="d-flex position-absolute justify-content-center align-items-center w-100">
<span class="{% if value > options.max %} text-white {% endif %}
{% if options.progressLabelCssClass %} {{ options.progressLabelCssClass }}
{% else %} lh-sm fa-sm {% endif %}">
{% if options.progressLabel %}
{{ options.progressLabel }}
{% else %} {{ value }} % {% endif %}
</span>
</div>
</div>

{% if options.isBottomLabelActivate %}
<div>
<span class="{% if options.progressLabelCssClass %} {{ options.progressLabelCssClass }}
{% else %} lh-sm fa-sm {% endif %}">
{% if options.bottomLabel %} {{ options.bottomLabel }}
{% else %} {{ value }} % {% endif %}
</span>
</div>
{% endif %}
Loading