Skip to content

Commit

Permalink
add tooltip to facet with description
Browse files Browse the repository at this point in the history
  • Loading branch information
protitude committed Jun 26, 2024
1 parent 8b38dd8 commit 3595543
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
9 changes: 9 additions & 0 deletions components/01-atoms/popover/_popover.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:popover-open {
width: 200px;
height: 100px;
position: absolute;
inset: unset;
bottom: 5px;
right: 5px;
margin: 0;
}
12 changes: 12 additions & 0 deletions components/01-atoms/popover/popover.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

import popovers from './popover.twig';

/**
* Storybook Definition.
*/
export default { title: 'Atoms/popover ' };

export const popover = () => (
<div dangerouslySetInnerHTML={{ __html: popovers({}) }} />
);
4 changes: 4 additions & 0 deletions components/01-atoms/popover/popover.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p style="margin-top: 100px;">
<button popovertarget="my-popover">Open Popover</button>
<div popover id="my-popover">Greetings, one and all!</div>
</p>
6 changes: 5 additions & 1 deletion dingo.theme
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ function dingo_preprocess_facets_result_item(&$variables) {
$facet = $variables['facet'];
$term_id = $variables['raw_value'];

$term_description = \Drupal\taxonomy\Entity\Term::load($term_id)->get('description')->value;
if($facet->getFieldIdentifier() == 'field_oda_population') {
if ( \Drupal\taxonomy\Entity\Term::load($term_id) ) {
$term_description = \Drupal\taxonomy\Entity\Term::load($term_id)->get('description')->value;
}
}

if(isset($term_description)) {
$variables['term_description'] = rtrim(strip_tags($term_description));
Expand Down
29 changes: 29 additions & 0 deletions templates/form/facets-result-item.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{#
/**
* @file
* Default theme implementation of a facet result item.
*
* Available variables:
* - value: The item value.
* - raw_value: The raw item value.
* - show_count: If this facet provides count.
* - count: The amount of results.
* - is_active: The item is active.
* - facet: The facet for this result item.
* - id: the machine name for the facet.
* - label: The facet label.
*
* @ingroup themeable
*/
#}
{% if is_active %}
<span class="facet-item__status js-facet-deactivate">(-)</span>
{% endif %}
{% if term_description %}
<span class="facet-item__value tooltip" data-tooltip="{{ term_description }}">{{ value }}</span>
{% else %}
<span class="facet-item__value">{{ value }}</span>
{% endif %}
{% if show_count %}
<span class="facet-item__count">({{ count }})</span>
{% endif %}

0 comments on commit 3595543

Please sign in to comment.