@cdc/data-bite 4.25.11 → 4.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ {
2
+ "type": "data-bite",
3
+ "data": [
4
+ {
5
+ "Category": "Total",
6
+ "Value": 1234
7
+ },
8
+ {
9
+ "Category": "Group A",
10
+ "Value": 5678
11
+ },
12
+ {
13
+ "Category": "Group B",
14
+ "Value": 9012
15
+ },
16
+ {
17
+ "Category": "Group C",
18
+ "Value": 3456
19
+ }
20
+ ],
21
+ "dataBite": "",
22
+ "dataFunction": "Mean (Average)",
23
+ "dataColumn": "Value",
24
+ "bitePosition": "Left",
25
+ "biteFontSize": 36,
26
+ "fontSize": "medium",
27
+ "biteBody": "Highlight a statistic, data point, or key fact about a topic using the relevant layout option:",
28
+ "imageData": {
29
+ "display": "none",
30
+ "url": "",
31
+ "alt": "",
32
+ "options": []
33
+ },
34
+ "dataFormat": {
35
+ "roundToPlace": 0,
36
+ "commas": true,
37
+ "prefix": "",
38
+ "suffix": ""
39
+ },
40
+ "biteStyle": "tp5",
41
+ "filters": [],
42
+ "subtext": "*This is an optional subtext or citation.",
43
+ "title": "Data / Fact",
44
+ "theme": "theme-blue",
45
+ "shadow": false,
46
+ "visual": {
47
+ "border": false,
48
+ "accent": false,
49
+ "background": false,
50
+ "hideBackgroundColor": false,
51
+ "borderColorTheme": false,
52
+ "showTitle": true
53
+ },
54
+ "general": {
55
+ "isCompactStyle": false
56
+ },
57
+ "markupVariables": [],
58
+ "enableMarkupVariables": false
59
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "type": "data-bite",
3
+ "data": [
4
+ {
5
+ "Category": "Total",
6
+ "Value": 1234
7
+ },
8
+ {
9
+ "Category": "Group A",
10
+ "Value": 5678
11
+ },
12
+ {
13
+ "Category": "Group B",
14
+ "Value": 9012
15
+ },
16
+ {
17
+ "Category": "Group C",
18
+ "Value": 3456
19
+ }
20
+ ],
21
+ "dataBite": "",
22
+ "dataFunction": "Mean (Average)",
23
+ "dataColumn": "Value",
24
+ "bitePosition": "Left",
25
+ "biteFontSize": 36,
26
+ "fontSize": "medium",
27
+ "biteBody": "Highlight a statistic, data point, or key fact about a topic using the relevant layout option:",
28
+ "imageData": {
29
+ "display": "none",
30
+ "url": "",
31
+ "alt": "",
32
+ "options": []
33
+ },
34
+ "dataFormat": {
35
+ "roundToPlace": 0,
36
+ "commas": true,
37
+ "prefix": "",
38
+ "suffix": ""
39
+ },
40
+ "biteStyle": "tp5",
41
+ "filters": [],
42
+ "subtext": "*This is an optional subtext or citation.",
43
+ "title": "Data / Fact",
44
+ "theme": "theme-blue",
45
+ "shadow": false,
46
+ "visual": {
47
+ "border": false,
48
+ "accent": false,
49
+ "background": false,
50
+ "hideBackgroundColor": false,
51
+ "borderColorTheme": false,
52
+ "showTitle": true,
53
+ "whiteBackground": true
54
+ },
55
+ "general": {
56
+ "isCompactStyle": false
57
+ },
58
+ "markupVariables": [],
59
+ "enableMarkupVariables": false
60
+ }
package/index.html CHANGED
@@ -9,8 +9,9 @@
9
9
  border-top: none !important;
10
10
  }
11
11
 
12
- .cdc-open-viz-module {
13
- min-height: 100vh;
12
+ /* Add 1rem padding to mimic DFE when editor is not visible */
13
+ .cdc-open-viz-module:not(.isEditor) {
14
+ padding: 1rem;
14
15
  }
15
16
  </style>
16
17
  <link rel="stylesheet prefetch" href="https://www.cdc.gov/TemplatePackage/5.0/css/app.min.css?_=71669" />
@@ -20,11 +21,14 @@
20
21
  <!-- <div class="react-container" data-config="/examples/sankey-example-data.json"></div> -->
21
22
 
22
23
  <!-- DATA PRESENTATION GALLERY: https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/data_bites.html#examples -->
23
- <div class="react-container" data-config="/examples/gallery/calculated-average.json"></div>
24
+ <!-- <div class="react-container" data-config="/examples/gallery/calculated-average.json"></div> -->
24
25
  <!-- <div class="react-container" data-config="/examples/gallery/calculated-with-pic.json"></div> -->
25
- <div class="react-container" data-config="/examples/gallery/max-value.json"></div>
26
+ <!-- <div class="react-container" data-config="/examples/gallery/max-value.json"></div> -->
26
27
  <!-- <div class="react-container" data-config="/examples/gallery/sum-of-data.json"></div> -->
27
28
 
29
+ <!-- TP5 Style Example -->
30
+ <div class="react-container" data-config="/examples/tp5-style.json"></div>
31
+
28
32
  <script type="module" src="./src/index.jsx"></script>
29
33
  </body>
30
34
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdc/data-bite",
3
- "version": "4.25.11",
3
+ "version": "4.26.1",
4
4
  "description": "React component for displaying a single piece of data in a card module",
5
5
  "moduleName": "CdcDataBite",
6
6
  "main": "dist/cdcdatabite",
@@ -27,7 +27,7 @@
27
27
  "license": "Apache-2.0",
28
28
  "homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
29
29
  "dependencies": {
30
- "@cdc/core": "^4.25.11",
30
+ "@cdc/core": "^4.26.1",
31
31
  "chroma-js": "3.1.2",
32
32
  "html-react-parser": "5.2.3",
33
33
  "lodash": "^4.17.21",
@@ -39,10 +39,11 @@
39
39
  "react-dom": "^18.2.0"
40
40
  },
41
41
  "devDependencies": {
42
+ "@rollup/plugin-dsv": "^3.0.2",
42
43
  "@vitejs/plugin-react": "^4.3.4",
43
- "vite": "^4.4.11",
44
+ "sass": "^1.89.2",
44
45
  "vite-plugin-css-injected-by-js": "^2.4.0",
45
- "vite-plugin-svgr": "^2.4.0"
46
+ "vite-plugin-svgr": "^4.2.0"
46
47
  },
47
- "gitHead": "5f09a137c22f454111ab5f4cd7fdf1d2d58e31bd"
48
+ "gitHead": "7e3b27098c4eb7a24bc9c3654ad53f88d6419f16"
48
49
  }
@@ -33,6 +33,9 @@ import { Config } from './types/Config'
33
33
  import dataBiteReducer from './store/db.reducer'
34
34
  import { IMAGE_POSITION_LEFT, IMAGE_POSITION_RIGHT, IMAGE_POSITION_TOP, IMAGE_POSITION_BOTTOM } from './constants'
35
35
 
36
+ // images
37
+ import CalloutFlag from './images/callout-flag.svg?url'
38
+
36
39
  import {
37
40
  DATA_FUNCTION_COUNT,
38
41
  DATA_FUNCTION_MAX,
@@ -595,70 +598,113 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
595
598
  <>
596
599
  {isEditor && <EditorPanel />}
597
600
  <Layout.Responsive isEditor={isEditor}>
598
- <div className={`cove-component__content`}>
601
+ <div
602
+ className={`cove-component__content ${showBite && 'tp5' === biteStyle ? 'bite__style--tp5' : ''} ${
603
+ showBite && 'tp5' === biteStyle && config.visual?.whiteBackground ? 'white-background-style' : ''
604
+ } ${
605
+ showBite && 'tp5' === biteStyle && config.visual?.whiteBackground && config.visual?.border
606
+ ? 'display-border'
607
+ : ''
608
+ }`}
609
+ >
599
610
  {!config.newViz && config.runtime && config.runtime.editorErrorMessage && <Error />}
600
611
  {(!config.dataColumn || !config.dataFunction) && <Confirm />}
601
- <Title
602
- showTitle={config.visual?.showTitle}
603
- config={config}
604
- title={processContentWithMarkup(title)}
605
- isDashboard={isDashboard}
606
- classes={['bite-header', `${config.theme}`]}
607
- />
608
- <div className={`bite ${biteClasses.join(' ')}`}>
609
- <div className={`bite-content-container ${contentClasses.join(' ')}`}>
610
- {showBite && 'graphic' === biteStyle && isTop && (
611
- <CircleCallout
612
- theme={config.theme}
613
- text={calculateDataBite()}
614
- biteFontSize={biteFontSize}
615
- dataFormat={dataFormat}
616
- />
612
+ {showBite && biteStyle === 'tp5' ? (
613
+ <div
614
+ className={`bite-content cdc-callout d-flex flex-column h-100 ${
615
+ !config.visual?.whiteBackground ? 'dfe-block cdc-callout--data' : ''
616
+ }`}
617
+ >
618
+ {/* Icon shows by default, hidden when white background is enabled */}
619
+ {!config.visual?.whiteBackground && (
620
+ <img src={CalloutFlag} alt='' className='cdc-callout__flag' aria-hidden='true' />
617
621
  )}
618
- {isTop && <DataImage />}
619
- <div className={`bite-content`}>
620
- {showBite && 'title' === biteStyle && (
621
- <div className='bite-value' style={{ fontSize: biteFontSize + 'px' }}>
622
- {calculateDataBite()}
623
- </div>
624
- )}
625
- {showBite && 'split' === biteStyle && (
626
- <div className='bite-value' style={{ fontSize: biteFontSize + 'px' }}>
627
- {calculateDataBite()}
628
- </div>
622
+
623
+ {config.visual?.showTitle && title && title.trim() && (
624
+ <h3 className='cdc-callout__heading fw-bold flex-shrink-0 d-flex align-items-start'>
625
+ <span>{parse(processContentWithMarkup(title))}</span>
626
+ </h3>
627
+ )}
628
+ <div className='cdc-callout__body d-flex flex-row align-content-start flex-grow-1'>
629
+ {showBite && (
630
+ <div className='cdc-callout__databite flex-shrink-0 me-3'>{calculateDataBite(true)}</div>
629
631
  )}
630
- <Fragment>
631
- <div className='bite-content__text-wrap'>
632
- <p className='bite-text'>
633
- {showBite && 'body' === biteStyle && (
634
- <span className='bite-value data-bite-body' style={{ fontSize: biteFontSize + 'px' }}>
635
- {calculateDataBite()}
636
- </span>
637
- )}
638
- {parse(processContentWithMarkup(biteBody))}
632
+ <div className='cdc-callout__content flex-grow-1 d-flex flex-column min-w-0'>
633
+ <p className='mb-0'>{parse(processContentWithMarkup(biteBody))}</p>
634
+ {subtext && !config.general.isCompactStyle && (
635
+ <p className='bite-subtext fst-italic flex-shrink-0 mt-3'>
636
+ {parse(processContentWithMarkup(subtext))}
639
637
  </p>
640
- {showBite && 'end' === biteStyle && (
641
- <span className='bite-value data-bite-body' style={{ fontSize: biteFontSize + 'px' }}>
638
+ )}
639
+ </div>
640
+ </div>
641
+ </div>
642
+ ) : (
643
+ <>
644
+ <Title
645
+ showTitle={config.visual?.showTitle}
646
+ titleStyle='legacy'
647
+ config={config}
648
+ title={processContentWithMarkup(title)}
649
+ isDashboard={isDashboard}
650
+ classes={['bite-header', `${config.theme}`]}
651
+ />
652
+ <div className={`bite ${biteClasses.join(' ')}`}>
653
+ <div className={`bite-content-container ${contentClasses.join(' ')}`}>
654
+ {showBite && 'graphic' === biteStyle && isTop && (
655
+ <CircleCallout
656
+ theme={config.theme}
657
+ text={calculateDataBite()}
658
+ biteFontSize={biteFontSize}
659
+ dataFormat={dataFormat}
660
+ />
661
+ )}
662
+ {isTop && <DataImage />}
663
+ <div className={`bite-content`}>
664
+ {showBite && 'title' === biteStyle && (
665
+ <div className='bite-value' style={{ fontSize: biteFontSize + 'px' }}>
642
666
  {calculateDataBite()}
643
- </span>
667
+ </div>
644
668
  )}
645
- {subtext && !config.general.isCompactStyle && (
646
- <p className='bite-subtext'>{parse(processContentWithMarkup(subtext))}</p>
669
+ {showBite && 'split' === biteStyle && (
670
+ <div className='bite-value' style={{ fontSize: biteFontSize + 'px' }}>
671
+ {calculateDataBite()}
672
+ </div>
647
673
  )}
674
+ <Fragment>
675
+ <div className='bite-content__text-wrap'>
676
+ <p className='bite-text'>
677
+ {showBite && 'body' === biteStyle && (
678
+ <span className='bite-value data-bite-body' style={{ fontSize: biteFontSize + 'px' }}>
679
+ {calculateDataBite()}
680
+ </span>
681
+ )}
682
+ {parse(processContentWithMarkup(biteBody))}
683
+ </p>
684
+ {showBite && 'end' === biteStyle && (
685
+ <span className='bite-value data-bite-body' style={{ fontSize: biteFontSize + 'px' }}>
686
+ {calculateDataBite()}
687
+ </span>
688
+ )}
689
+ {subtext && !config.general.isCompactStyle && (
690
+ <p className='bite-subtext'>{parse(processContentWithMarkup(subtext))}</p>
691
+ )}
692
+ </div>
693
+ </Fragment>
648
694
  </div>
649
- </Fragment>
695
+ {isBottom && <DataImage />}
696
+ {showBite && 'graphic' === biteStyle && !isTop && (
697
+ <CircleCallout
698
+ theme={config.theme}
699
+ text={calculateDataBite()}
700
+ biteFontSize={biteFontSize}
701
+ dataFormat={dataFormat}
702
+ />
703
+ )}
704
+ </div>
650
705
  </div>
651
- {isBottom && <DataImage />}
652
- {showBite && 'graphic' === biteStyle && !isTop && (
653
- <CircleCallout
654
- theme={config.theme}
655
- text={calculateDataBite()}
656
- biteFontSize={biteFontSize}
657
- dataFormat={dataFormat}
658
- />
659
- )}
660
- </div>
661
- </div>
706
+ </>
707
+ )}
662
708
  </div>
663
709
  {link && link}
664
710
  </Layout.Responsive>
@@ -56,9 +56,12 @@ export const BasicEditorLoadingTests: Story = {
56
56
  await waitForEditor(canvas)
57
57
 
58
58
  // Verify all three main accordion sections are present
59
- const generalButton = canvas.getByRole('button', { name: /general/i })
60
- const dataButton = canvas.getByRole('button', { name: /data/i })
61
- const visualButton = canvas.getByRole('button', { name: /visual/i })
59
+ // Use waitFor to give VisualSection time to render
60
+ const generalButton = await canvas.findByRole('button', { name: /general/i })
61
+ const dataButton = await canvas.findByRole('button', { name: /data/i })
62
+
63
+ // Find Visual section accordion button
64
+ const visualButton = await canvas.findByRole('button', { name: /visual/i }, { timeout: 5000 })
62
65
 
63
66
  await expect(generalButton).toBeVisible()
64
67
  await expect(dataButton).toBeVisible()
@@ -42,6 +42,34 @@ export const Data_Bite_Text_Average_Pic: Story = {
42
42
  }
43
43
  }
44
44
 
45
+ export const Data_Bite_TP5_Style: Story = {
46
+ args: {
47
+ configUrl: '/packages/data-bite/examples/tp5-style.json'
48
+ },
49
+ parameters: {
50
+ docs: {
51
+ description: {
52
+ story:
53
+ 'TP5 Style - A new layout style that displays the data value and message side by side, centered. The title appears above, and subtext appears below the message. On mobile devices, the message wraps below the data value. This style mimics the CDC Template Package 5.0 callout component design.'
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ export const Data_Bite_TP5_White_Background: Story = {
60
+ args: {
61
+ configUrl: '/packages/data-bite/examples/tp5-white-background.json'
62
+ },
63
+ parameters: {
64
+ docs: {
65
+ description: {
66
+ story:
67
+ 'TP5 Style with White Background - This variant uses a white background with a 1px border and 6px border radius, providing a cleaner look while maintaining the TP5 layout style.'
68
+ }
69
+ }
70
+ }
71
+ }
72
+
45
73
  // Simple editor mode story for basic rendering
46
74
  export const Editor_Mode_Basic: Story = {
47
75
  args: {