@cdc/data-bite 4.25.8 → 4.25.10

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.
@@ -1,35 +1,59 @@
1
- import type { Meta, StoryObj } from '@storybook/react'
2
- import DataBite from '../CdcDataBite'
3
- import { Config } from '../types/Config'
4
-
5
- const meta: Meta<typeof DataBite> = {
6
- title: 'Components/Templates/Data Bite',
7
- component: DataBite
8
- }
9
-
10
- type Story = StoryObj<typeof DataBite>
11
-
12
- export const Data_Bite_Circle_Average: Story = {
13
- args: {
14
- configUrl: 'https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/Data_Bite_Circle_Average.json'
15
- }
16
- }
17
-
18
- export const Data_Bite_Text_Max_Pic: Story = {
19
- args: {
20
- configUrl: 'https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/Data_Bite_Text_Max_Pic.json'
21
- }
22
- }
23
-
24
- export const Data_Bite_Circle_Sum: Story = {
25
- args: {
26
- configUrl: 'https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/Data_Bite_Circle_Sum.json'
27
- }
28
- }
29
- export const Data_Bite_Text_Average_Pic: Story = {
30
- args: {
31
- configUrl: 'https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/Data_Bite_Text_Average_Pic.json'
32
- }
33
- }
34
-
35
- export default meta
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import DataBite from '../CdcDataBite'
3
+
4
+ const meta: Meta<typeof DataBite> = {
5
+ title: 'Components/Templates/Data Bite',
6
+ component: DataBite,
7
+ parameters: {
8
+ docs: {
9
+ description: {
10
+ component:
11
+ 'Data Bite component for displaying key statistics and metrics. For comprehensive editor testing, see the "Editor Tests" section below.'
12
+ }
13
+ }
14
+ }
15
+ }
16
+
17
+ export default meta
18
+ type Story = StoryObj<typeof DataBite>
19
+
20
+ // Gallery stories for visual documentation
21
+ export const Data_Bite_Circle_Average: Story = {
22
+ args: {
23
+ configUrl: 'https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/Data_Bite_Circle_Average.json'
24
+ }
25
+ }
26
+
27
+ export const Data_Bite_Text_Max_Pic: Story = {
28
+ args: {
29
+ configUrl: 'https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/Data_Bite_Text_Max_Pic.json'
30
+ }
31
+ }
32
+
33
+ export const Data_Bite_Circle_Sum: Story = {
34
+ args: {
35
+ configUrl: 'https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/Data_Bite_Circle_Sum.json'
36
+ }
37
+ }
38
+
39
+ export const Data_Bite_Text_Average_Pic: Story = {
40
+ args: {
41
+ configUrl: 'https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/Data_Bite_Text_Average_Pic.json'
42
+ }
43
+ }
44
+
45
+ // Simple editor mode story for basic rendering
46
+ export const Editor_Mode_Basic: Story = {
47
+ args: {
48
+ configUrl: '/tests/fixtures/test-config.json',
49
+ isEditor: true
50
+ },
51
+ parameters: {
52
+ docs: {
53
+ description: {
54
+ story:
55
+ 'Basic editor mode rendering. For comprehensive editor testing with interactions, see "Data Bite/Editor Tests" stories.'
56
+ }
57
+ }
58
+ }
59
+ }
@@ -1,4 +1,5 @@
1
- import { memo, useContext, useEffect, useState } from 'react'
1
+ import React, { memo, useContext, useEffect, useState } from 'react'
2
+ import cloneConfig from '@cdc/core/helpers/cloneConfig'
2
3
  import _ from 'lodash'
3
4
  import {
4
5
  Accordion,
@@ -18,6 +19,7 @@ import { BITE_LOCATIONS, DATA_FUNCTIONS, IMAGE_POSITIONS, DATA_OPERATORS, HEADER
18
19
  import Layout from '@cdc/core/components/Layout'
19
20
  import { Select, TextField, CheckBox } from '@cdc/core/components/EditorPanel/Inputs'
20
21
  import Button from '@cdc/core/components/elements/Button'
22
+ import PanelMarkup from '@cdc/core/components/EditorPanel/components/PanelMarkup'
21
23
 
22
24
  const EditorPanel = memo(() => {
23
25
  const { config, updateConfig, loading, data, setParentConfig, isDashboard, isEditor } = useContext(Context)
@@ -51,7 +53,7 @@ const EditorPanel = memo(() => {
51
53
  }
52
54
 
53
55
  const convertStateToConfig = () => {
54
- let strippedState = _.cloneDeep(config)
56
+ let strippedState = cloneConfig(config)
55
57
  //if(false === missingRequiredSections()) {
56
58
  //strippedState.newViz
57
59
  //}
@@ -239,7 +241,8 @@ const EditorPanel = memo(() => {
239
241
  <Tooltip.Content>
240
242
  <p>
241
243
  Enter supporting text to display below the data visualization, if applicable. The following
242
- HTML tags are supported: strong, em, sup, and sub.
244
+ HTML tags are supported: strong, em, sup, and sub. You can also use markup variables like{' '}
245
+ {'{{variable-name}}'} to display dynamic data.
243
246
  </p>
244
247
  </Tooltip.Content>
245
248
  </Tooltip>
@@ -688,6 +691,23 @@ const EditorPanel = memo(() => {
688
691
  </AccordionItemPanel>
689
692
  </AccordionItem>
690
693
  )}
694
+
695
+ <AccordionItem>
696
+ <AccordionItemHeading>
697
+ <AccordionItemButton>Markup Variables</AccordionItemButton>
698
+ </AccordionItemHeading>
699
+ <AccordionItemPanel>
700
+ <PanelMarkup
701
+ name='Markup Variables'
702
+ markupVariables={config.markupVariables || []}
703
+ data={data}
704
+ enableMarkupVariables={config.enableMarkupVariables || false}
705
+ onMarkupVariablesChange={variables => updateField(null, null, 'markupVariables', variables)}
706
+ onToggleEnable={enabled => updateField(null, null, 'enableMarkupVariables', enabled)}
707
+ withAccordion={false}
708
+ />
709
+ </AccordionItemPanel>
710
+ </AccordionItem>
691
711
  </Accordion>
692
712
  </form>
693
713
  </section>
@@ -36,5 +36,7 @@ export default {
36
36
  },
37
37
  general: {
38
38
  isCompactStyle: false
39
- }
39
+ },
40
+ markupVariables: [],
41
+ enableMarkupVariables: false
40
42
  }
package/src/index.jsx CHANGED
@@ -2,7 +2,6 @@ import React from 'react'
2
2
  import ReactDOM from 'react-dom/client'
3
3
 
4
4
  import '@cdc/core/styles/cove-main.scss'
5
- import './coreStyles_databite.scss'
6
5
 
7
6
  import CdcDataBite from './CdcDataBite'
8
7
 
@@ -1,6 +1,11 @@
1
- // Placeholder test until we add them in.
1
+ import path from 'path'
2
+ import { testStandaloneBuild } from '@cdc/core/helpers/tests/testStandaloneBuild.ts'
3
+ import { describe, it, expect } from 'vitest'
4
+
2
5
  describe('Data Bite', () => {
3
- it('has a test.', async () => {
4
- return true
6
+ it('Can be built in isolation', async () => {
7
+ const pkgDir = path.join(__dirname, '..')
8
+ const result = testStandaloneBuild(pkgDir)
9
+ expect(result).toBe(true)
5
10
  })
6
11
  })
@@ -1,4 +1,6 @@
1
1
  import { Version } from '@cdc/core/types/Version'
2
+ import { MarkupConfig } from '@cdc/core/types/MarkupVariable'
3
+ import { VizFilter } from '@cdc/core/types/VizFilter'
2
4
 
3
5
  export type Config = {
4
6
  type: string
@@ -23,7 +25,7 @@ export type Config = {
23
25
  suffix: string
24
26
  }
25
27
  biteStyle: string
26
- filters: Object[]
28
+ filters: VizFilter[]
27
29
  subtext: string
28
30
  title: string
29
31
  theme: string
@@ -40,4 +42,4 @@ export type Config = {
40
42
  isCompactStyle: boolean
41
43
  }
42
44
  version: Version
43
- }
45
+ } & MarkupConfig