|
1 | 1 | import React from 'react'; |
2 | 2 | import styled from 'styled-components'; |
3 | 3 |
|
4 | | -const TagGroup = styled.div` |
| 4 | +const Container = styled.div<{ $displayMode: 'tag' | 'text' }>` |
| 5 | + display: flex; |
| 6 | + align-items: ${props => props.$displayMode === 'tag' ? 'center' : 'flex-start'}; |
| 7 | + flex-direction: ${props => props.$displayMode === 'tag' ? 'row' : 'column'}; |
| 8 | + gap: ${props => props.$displayMode === 'tag' ? '0' : '0.3rem'}; |
| 9 | +`; |
| 10 | + |
| 11 | +const SourceLabel = styled.div<{ $displayMode: 'tag' | 'text' }>` |
| 12 | + margin: 0; |
| 13 | + font-size: ${props => props.$displayMode === 'tag' ? '0.75rem' : ''}; |
| 14 | +`; |
| 15 | + |
| 16 | +const TagsContainer = styled.div` |
5 | 17 | display: flex; |
6 | 18 | align-items: center; |
| 19 | +`; |
| 20 | + |
| 21 | +const TextContainer = styled.div` |
| 22 | + display: flex; |
| 23 | + flex-direction: column; |
7 | 24 | gap: 0.5rem; |
8 | 25 | `; |
9 | 26 |
|
@@ -40,31 +57,40 @@ const SOURCES_DETAILS: Record<string, { label: string; html: string }> = { |
40 | 57 |
|
41 | 58 | interface ChartDataSourceProps { |
42 | 59 | sources: (keyof typeof SOURCES_DETAILS)[]; |
43 | | - chartId: string; |
| 60 | + displayMode?: 'tag' | 'text'; |
44 | 61 | } |
45 | 62 |
|
46 | | -const ChartDataSource: React.FC<ChartDataSourceProps> = ({ sources, chartId }) => { |
| 63 | +const ChartDataSource: React.FC<ChartDataSourceProps> = ({ sources, displayMode = 'tag' }) => { |
47 | 64 | if (!sources || sources.length === 0) return null; |
48 | 65 | return ( |
49 | | - <div style={{ display: 'flex', alignItems: 'center' }}> |
50 | | - <span className="fr-text--xs fr-mb-0 fr-mr-1w">Source de données :</span> |
51 | | - <TagGroup> |
52 | | - {sources.map((src) => { |
53 | | - const source = SOURCES_DETAILS[src]; |
54 | | - if (!source) return null; |
55 | | - const tooltipId = `tooltip-${chartId}-${src}`; |
56 | | - const tagId = `tag-${chartId}-${src}`; |
57 | | - return ( |
58 | | - <React.Fragment key={src}> |
59 | | - <span className="fr-tag fr-tag--sm fr-tag--blue fr-text--bold" role="button" id={tagId} aria-describedby={tooltipId} tabIndex={0}> |
60 | | - {source.label} |
| 66 | + <Container $displayMode={displayMode}> |
| 67 | + <SourceLabel as={displayMode === 'text' ? 'h6' : 'span'} $displayMode={displayMode}> |
| 68 | + Source de données : |
| 69 | + </SourceLabel> |
| 70 | + {displayMode === 'text' ? ( |
| 71 | + <TextContainer> |
| 72 | + {sources.map((src) => { |
| 73 | + const source = SOURCES_DETAILS[src]; |
| 74 | + if (!source) return null; |
| 75 | + return ( |
| 76 | + <p key={src} className="fr-text--xs fr-mb-0" dangerouslySetInnerHTML={{ __html: source.html }} /> |
| 77 | + ); |
| 78 | + })} |
| 79 | + </TextContainer> |
| 80 | + ) : ( |
| 81 | + <TagsContainer> |
| 82 | + {sources.map((src) => { |
| 83 | + const source = SOURCES_DETAILS[src]; |
| 84 | + if (!source) return null; |
| 85 | + return ( |
| 86 | + <span key={src} className="fr-tag fr-tag--sm fr-tag--blue fr-text--bold fr-ml-1w"> |
| 87 | + {source.label} |
61 | 88 | </span> |
62 | | - <span className="fr-tooltip fr-placement" id={tooltipId} role="tooltip" aria-hidden="true" dangerouslySetInnerHTML={{ __html: source.html }} /> |
63 | | - </React.Fragment> |
64 | | - ); |
65 | | - })} |
66 | | - </TagGroup> |
67 | | - </div> |
| 89 | + ); |
| 90 | + })} |
| 91 | + </TagsContainer> |
| 92 | + )} |
| 93 | + </Container> |
68 | 94 | ); |
69 | 95 | }; |
70 | 96 |
|
|
0 commit comments