@cdc/data-bite 4.25.10 → 4.25.11

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdc/data-bite",
3
- "version": "4.25.10",
3
+ "version": "4.25.11",
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.25.11",
31
31
  "chroma-js": "3.1.2",
32
32
  "html-react-parser": "5.2.3",
33
33
  "lodash": "^4.17.21",
@@ -39,11 +39,10 @@
39
39
  "react-dom": "^18.2.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@rollup/plugin-dsv": "^3.0.2",
43
42
  "@vitejs/plugin-react": "^4.3.4",
44
43
  "vite": "^4.4.11",
45
44
  "vite-plugin-css-injected-by-js": "^2.4.0",
46
45
  "vite-plugin-svgr": "^2.4.0"
47
46
  },
48
- "gitHead": "c2db758e74ab9b9ca1667a6f9cb41dd0dccf985d"
47
+ "gitHead": "5f09a137c22f454111ab5f4cd7fdf1d2d58e31bd"
49
48
  }
@@ -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,18 @@ 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
+
34
36
  import {
35
37
  DATA_FUNCTION_COUNT,
36
38
  DATA_FUNCTION_MAX,
37
39
  DATA_FUNCTION_MEAN,
38
40
  DATA_FUNCTION_MEDIAN,
39
- DATA_FUNCTION_MIN,
40
41
  DATA_FUNCTION_MODE,
42
+ DATA_FUNCTION_MIN,
41
43
  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'
44
+ DATA_FUNCTION_SUM
45
+ } from '@cdc/core/helpers/constants'
48
46
 
49
47
  // styles
50
48
  import './scss/main.scss'
@@ -1,4 +1,5 @@
1
1
  import React, { memo, useContext, useEffect, useState } from 'react'
2
+ import { DATA_FUNCTIONS, DATA_OPERATORS } from '@cdc/core/helpers/constants'
2
3
  import cloneConfig from '@cdc/core/helpers/cloneConfig'
3
4
  import _ from 'lodash'
4
5
  import {
@@ -9,17 +10,21 @@ import {
9
10
  AccordionItemPanel
10
11
  } from 'react-accessible-accordion'
11
12
 
13
+ import AdvancedEditor from '@cdc/core/components/AdvancedEditor'
12
14
  import Context from '../context'
13
15
  import WarningImage from '@cdc/core/assets/icon-warning-circle.svg'
14
16
  import Tooltip from '@cdc/core/components/ui/Tooltip'
15
17
  import Icon from '@cdc/core/components/ui/Icon'
16
18
  import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
17
19
  import { updateFieldFactory } from '@cdc/core/helpers/updateFieldFactory'
18
- import { BITE_LOCATIONS, DATA_FUNCTIONS, IMAGE_POSITIONS, DATA_OPERATORS, HEADER_COLORS } from './../constants'
20
+ import { BITE_LOCATIONS, IMAGE_POSITIONS } from './../constants'
19
21
  import Layout from '@cdc/core/components/Layout'
20
22
  import { Select, TextField, CheckBox } from '@cdc/core/components/EditorPanel/Inputs'
21
23
  import Button from '@cdc/core/components/elements/Button'
22
24
  import PanelMarkup from '@cdc/core/components/EditorPanel/components/PanelMarkup'
25
+ import { HeaderThemeSelector } from '@cdc/core/components/HeaderThemeSelector'
26
+
27
+ import '@cdc/core/styles/v2/components/editor.scss'
23
28
 
24
29
  const EditorPanel = memo(() => {
25
30
  const { config, updateConfig, loading, data, setParentConfig, isDashboard, isEditor } = useContext(Context)
@@ -285,8 +290,8 @@ const EditorPanel = memo(() => {
285
290
  Array.isArray(DATA_FUNCTIONS)
286
291
  ? DATA_FUNCTIONS
287
292
  : DATA_FUNCTIONS
288
- ? Object.values(DATA_FUNCTIONS)
289
- : []
293
+ ? Object.values(DATA_FUNCTIONS)
294
+ : []
290
295
  }
291
296
  />
292
297
  </li>
@@ -408,7 +413,7 @@ const EditorPanel = memo(() => {
408
413
  <AccordionItemHeading>
409
414
  <AccordionItemButton>Visual</AccordionItemButton>
410
415
  </AccordionItemHeading>
411
- <AccordionItemPanel>
416
+ <AccordionItemPanel className='panel-visual accordion__panel accordion__panel--visual'>
412
417
  <TextField
413
418
  type='number'
414
419
  value={config.biteFontSize}
@@ -462,22 +467,11 @@ const EditorPanel = memo(() => {
462
467
  updateField={updateField}
463
468
  />
464
469
  </div>
465
- <label>
466
- <span className='edit-label'>Theme</span>
467
- <ul className='color-palette'>
468
- {HEADER_COLORS.map(palette => (
469
- <button
470
- title={palette}
471
- key={palette}
472
- onClick={e => {
473
- e.preventDefault()
474
- updateConfig({ ...config, theme: palette })
475
- }}
476
- className={config.theme === palette ? 'selected ' + palette : palette}
477
- />
478
- ))}
479
- </ul>
480
- </label>
470
+ <HeaderThemeSelector
471
+ selectedTheme={config.theme}
472
+ onThemeSelect={theme => updateConfig({ ...config, theme })}
473
+ label='Theme'
474
+ />
481
475
  </AccordionItemPanel>
482
476
  </AccordionItem>
483
477
 
@@ -571,19 +565,14 @@ const EditorPanel = memo(() => {
571
565
  <div className='accordion__panel-row align-center'>
572
566
  <div className='accordion__panel-col flex-auto'>If Value</div>
573
567
  <div className='accordion__panel-col flex-auto'>
574
- <select
568
+ <Select
569
+ label=''
575
570
  value={option.arguments[0]?.operator || ''}
571
+ options={DATA_OPERATORS}
576
572
  onChange={e => {
577
573
  updateDynamicImage('operator', index, 0, e.target.value)
578
574
  }}
579
- >
580
- <option value='' disabled />
581
- {DATA_OPERATORS.map((operator, index) => (
582
- <option value={operator} key={index}>
583
- {operator}
584
- </option>
585
- ))}
586
- </select>
575
+ />
587
576
  </div>
588
577
  <div className='accordion__panel-col flex-grow flex-shrink'>
589
578
  <input
@@ -598,9 +587,13 @@ const EditorPanel = memo(() => {
598
587
 
599
588
  <div className='accordion__panel-row mb-2 align-center'>
600
589
  <div className='accordion__panel-col flex-grow'>
601
- <select
602
- className='border-dashed text-center'
590
+ <Select
591
+ label=''
603
592
  value={option.secondArgument ? 'and' : 'then'}
593
+ options={[
594
+ { value: 'then', label: 'Then' },
595
+ { value: 'and', label: 'And' }
596
+ ]}
604
597
  onChange={e => {
605
598
  if ('then' === e.target.value) {
606
599
  updateDynamicImage('secondArgument', index, null, false)
@@ -610,10 +603,7 @@ const EditorPanel = memo(() => {
610
603
  updateDynamicImage('secondArgument', index, null, true)
611
604
  }
612
605
  }}
613
- >
614
- <option value={'then'}>Then</option>
615
- <option value={'and'}>And</option>
616
- </select>
606
+ />
617
607
  </div>
618
608
  </div>
619
609
 
@@ -622,19 +612,14 @@ const EditorPanel = memo(() => {
622
612
  <div className='accordion__panel-row align-center'>
623
613
  <div className='accordion__panel-col flex-auto'>If Value</div>
624
614
  <div className='accordion__panel-col flex-auto'>
625
- <select
615
+ <Select
616
+ label=''
626
617
  value={option.arguments[1]?.operator || ''}
618
+ options={DATA_OPERATORS}
627
619
  onChange={e => {
628
620
  setDynamicArgument(index, 'operator', e.target.value)
629
621
  }}
630
- >
631
- <option value='' disabled />
632
- {DATA_OPERATORS.map((operator, index) => (
633
- <option value={operator} key={index}>
634
- {operator}
635
- </option>
636
- ))}
637
- </select>
622
+ />
638
623
  </div>
639
624
  <div className='accordion__panel-col flex-grow flex-shrink'>
640
625
  <input
@@ -708,6 +693,7 @@ const EditorPanel = memo(() => {
708
693
  />
709
694
  </AccordionItemPanel>
710
695
  </AccordionItem>
696
+ <AdvancedEditor loadConfig={updateConfig} config={config} convertStateToConfig={convertStateToConfig} />
711
697
  </Accordion>
712
698
  </form>
713
699
  </section>
package/src/constants.ts CHANGED
@@ -1,25 +1,3 @@
1
- export const DATA_FUNCTION_MAX = 'Max'
2
- export const DATA_FUNCTION_COUNT = 'Count'
3
- export const DATA_FUNCTION_MEAN = 'Mean (Average)'
4
- export const DATA_FUNCTION_MEDIAN = 'Median'
5
- export const DATA_FUNCTION_MIN = 'Min'
6
- export const DATA_FUNCTION_MODE = 'Mode'
7
- export const DATA_FUNCTION_RANGE = 'Range'
8
- export const DATA_FUNCTION_SUM = 'Sum'
9
- export const DATA_FUNCTIONS = [
10
- DATA_FUNCTION_COUNT,
11
- DATA_FUNCTION_MAX,
12
- DATA_FUNCTION_MEAN,
13
- DATA_FUNCTION_MEDIAN,
14
- DATA_FUNCTION_MIN,
15
- DATA_FUNCTION_MODE,
16
- DATA_FUNCTION_RANGE,
17
- DATA_FUNCTION_SUM
18
- ]
19
-
20
- export const BITE_LOCATION_TITLE = 'title'
21
- export const BITE_LOCATION_BODY = 'body'
22
- export const BITE_LOCATION_GRAPHIC = 'graphic'
23
1
  export const BITE_LOCATIONS = {
24
2
  graphic: 'Graphic',
25
3
  split: 'Split Graphic and Message',
@@ -34,33 +12,3 @@ export const IMAGE_POSITION_RIGHT = 'Right'
34
12
  export const IMAGE_POSITION_TOP = 'Top'
35
13
  export const IMAGE_POSITION_BOTTOM = 'Bottom'
36
14
  export const IMAGE_POSITIONS = [IMAGE_POSITION_LEFT, IMAGE_POSITION_RIGHT, IMAGE_POSITION_TOP, IMAGE_POSITION_BOTTOM]
37
-
38
- export const DATA_OPERATOR_LESS = '<'
39
- export const DATA_OPERATOR_GREATER = '>'
40
- export const DATA_OPERATOR_LESSEQUAL = '<='
41
- export const DATA_OPERATOR_GREATEREQUAL = '>='
42
- export const DATA_OPERATOR_EQUAL = '='
43
- export const DATA_OPERATOR_NOTEQUAL = '≠'
44
-
45
- export const DATA_OPERATORS = [
46
- DATA_OPERATOR_LESS,
47
- DATA_OPERATOR_GREATER,
48
- DATA_OPERATOR_LESSEQUAL,
49
- DATA_OPERATOR_GREATEREQUAL,
50
- DATA_OPERATOR_EQUAL,
51
- DATA_OPERATOR_NOTEQUAL
52
- ]
53
-
54
- export const HEADER_COLORS = [
55
- 'theme-blue',
56
- 'theme-purple',
57
- 'theme-brown',
58
- 'theme-teal',
59
- 'theme-pink',
60
- 'theme-orange',
61
- 'theme-slate',
62
- 'theme-indigo',
63
- 'theme-cyan',
64
- 'theme-green',
65
- 'theme-amber'
66
- ]
package/src/index.jsx CHANGED
@@ -2,6 +2,7 @@ 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 '@cdc/core/components/EditorPanel/EditorPanel.styles.css'
5
6
 
6
7
  import CdcDataBite from './CdcDataBite'
7
8