@cdc/data-bite 4.25.10 → 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.10",
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.10",
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",
@@ -41,9 +41,9 @@
41
41
  "devDependencies": {
42
42
  "@rollup/plugin-dsv": "^3.0.2",
43
43
  "@vitejs/plugin-react": "^4.3.4",
44
- "vite": "^4.4.11",
44
+ "sass": "^1.89.2",
45
45
  "vite-plugin-css-injected-by-js": "^2.4.0",
46
- "vite-plugin-svgr": "^2.4.0"
46
+ "vite-plugin-svgr": "^4.2.0"
47
47
  },
48
- "gitHead": "c2db758e74ab9b9ca1667a6f9cb41dd0dccf985d"
48
+ "gitHead": "7e3b27098c4eb7a24bc9c3654ad53f88d6419f16"
49
49
  }
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState, useCallback, useReducer } from 'react'
1
+ import { useEffect, useCallback, useReducer } from 'react'
2
2
  import { Fragment } from 'react'
3
3
 
4
4
  // contexts & initial state
@@ -31,20 +31,21 @@ import cacheBustingString from '@cdc/core/helpers/cacheBustingString'
31
31
  import coveUpdateWorker from '@cdc/core/helpers/coveUpdateWorker'
32
32
  import { Config } from './types/Config'
33
33
  import dataBiteReducer from './store/db.reducer'
34
+ import { IMAGE_POSITION_LEFT, IMAGE_POSITION_RIGHT, IMAGE_POSITION_TOP, IMAGE_POSITION_BOTTOM } from './constants'
35
+
36
+ // images
37
+ import CalloutFlag from './images/callout-flag.svg?url'
38
+
34
39
  import {
35
40
  DATA_FUNCTION_COUNT,
36
41
  DATA_FUNCTION_MAX,
37
42
  DATA_FUNCTION_MEAN,
38
43
  DATA_FUNCTION_MEDIAN,
39
- DATA_FUNCTION_MIN,
40
44
  DATA_FUNCTION_MODE,
45
+ DATA_FUNCTION_MIN,
41
46
  DATA_FUNCTION_RANGE,
42
- DATA_FUNCTION_SUM,
43
- IMAGE_POSITION_LEFT,
44
- IMAGE_POSITION_RIGHT,
45
- IMAGE_POSITION_TOP,
46
- IMAGE_POSITION_BOTTOM
47
- } from './constants'
47
+ DATA_FUNCTION_SUM
48
+ } from '@cdc/core/helpers/constants'
48
49
 
49
50
  // styles
50
51
  import './scss/main.scss'
@@ -597,70 +598,113 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
597
598
  <>
598
599
  {isEditor && <EditorPanel />}
599
600
  <Layout.Responsive isEditor={isEditor}>
600
- <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
+ >
601
610
  {!config.newViz && config.runtime && config.runtime.editorErrorMessage && <Error />}
602
611
  {(!config.dataColumn || !config.dataFunction) && <Confirm />}
603
- <Title
604
- showTitle={config.visual?.showTitle}
605
- config={config}
606
- title={processContentWithMarkup(title)}
607
- isDashboard={isDashboard}
608
- classes={['bite-header', `${config.theme}`]}
609
- />
610
- <div className={`bite ${biteClasses.join(' ')}`}>
611
- <div className={`bite-content-container ${contentClasses.join(' ')}`}>
612
- {showBite && 'graphic' === biteStyle && isTop && (
613
- <CircleCallout
614
- theme={config.theme}
615
- text={calculateDataBite()}
616
- biteFontSize={biteFontSize}
617
- dataFormat={dataFormat}
618
- />
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' />
619
621
  )}
620
- {isTop && <DataImage />}
621
- <div className={`bite-content`}>
622
- {showBite && 'title' === biteStyle && (
623
- <div className='bite-value' style={{ fontSize: biteFontSize + 'px' }}>
624
- {calculateDataBite()}
625
- </div>
626
- )}
627
- {showBite && 'split' === biteStyle && (
628
- <div className='bite-value' style={{ fontSize: biteFontSize + 'px' }}>
629
- {calculateDataBite()}
630
- </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>
631
631
  )}
632
- <Fragment>
633
- <div className='bite-content__text-wrap'>
634
- <p className='bite-text'>
635
- {showBite && 'body' === biteStyle && (
636
- <span className='bite-value data-bite-body' style={{ fontSize: biteFontSize + 'px' }}>
637
- {calculateDataBite()}
638
- </span>
639
- )}
640
- {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))}
641
637
  </p>
642
- {showBite && 'end' === biteStyle && (
643
- <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' }}>
644
666
  {calculateDataBite()}
645
- </span>
667
+ </div>
646
668
  )}
647
- {subtext && !config.general.isCompactStyle && (
648
- <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>
649
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>
650
694
  </div>
651
- </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>
652
705
  </div>
653
- {isBottom && <DataImage />}
654
- {showBite && 'graphic' === biteStyle && !isTop && (
655
- <CircleCallout
656
- theme={config.theme}
657
- text={calculateDataBite()}
658
- biteFontSize={biteFontSize}
659
- dataFormat={dataFormat}
660
- />
661
- )}
662
- </div>
663
- </div>
706
+ </>
707
+ )}
664
708
  </div>
665
709
  {link && link}
666
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: {