@cdc/data-bite 4.23.1 → 4.23.2

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.
@@ -19,6 +19,6 @@
19
19
  <!-- <div class="react-container" data-config="/examples/gallery/max-value.json"></div> -->
20
20
  <!-- <div class="react-container" data-config="/examples/gallery/sum-of-data.json"></div> -->
21
21
 
22
- <noscript>You need to enable JavaScript to run this app.</noscript>
22
+ <script type="module" src="./src/index.jsx"></script>
23
23
  </body>
24
24
  </html>
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@cdc/data-bite",
3
- "version": "4.23.1",
3
+ "version": "4.23.2",
4
4
  "description": "React component for displaying a single piece of data in a card module",
5
+ "moduleName": "CdcDataBite",
5
6
  "main": "dist/cdcdatabite",
7
+ "type": "module",
6
8
  "scripts": {
7
- "start": "npx webpack serve --mode development -c ../../webpack.config.js",
8
- "build": "npx webpack --mode production --env packageName=CdcDataBite --env folderName=data-bite -c ../../webpack.config.js",
9
+ "start": "vite --open",
10
+ "build": "vite build",
11
+ "preview": "vite preview",
12
+ "graph": "nx graph",
9
13
  "prepublishOnly": "lerna run --scope @cdc/data-bite build"
10
14
  },
11
15
  "repository": {
@@ -20,24 +24,18 @@
20
24
  "license": "Apache-2.0",
21
25
  "homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
22
26
  "dependencies": {
23
- "@cdc/core": "^4.23.1",
27
+ "@cdc/core": "^4.23.2",
24
28
  "chroma": "0.0.1",
25
29
  "chroma-js": "^2.1.0",
26
- "html-react-parser": "1.4.9",
30
+ "html-react-parser": "^3.0.8",
27
31
  "papaparse": "^5.3.0",
28
32
  "react-accessible-accordion": "^3.3.4",
29
33
  "react-beautiful-dnd": "^13.0.0",
30
- "react-select": "^3.0.8",
31
- "react-tooltip": "4.2.8",
32
- "use-debounce": "^6.0.1",
33
34
  "whatwg-fetch": "^3.6.2"
34
35
  },
35
36
  "peerDependencies": {
36
- "react": "^17.0.2",
37
- "react-dom": ">=16"
37
+ "react": "^18.2.0",
38
+ "react-dom": "^18.2.0"
38
39
  },
39
- "resolutions": {
40
- "@types/react": "17.x"
41
- },
42
- "gitHead": "58163844cc9ce2c379235413b19f49679eab4bef"
40
+ "gitHead": "cd4216f47b1c41bfbc1de3b704f70c52cc7293c2"
43
41
  }
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState, useCallback, FC, memo } from 'react'
1
+ import React, { useEffect, useState, useCallback } from 'react'
2
2
  import EditorPanel from './components/EditorPanel'
3
3
  import defaults from './data/initial-state'
4
4
  import Loading from '@cdc/core/components/Loading'
@@ -18,21 +18,11 @@ import { publish } from '@cdc/core/helpers/events'
18
18
  import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses'
19
19
  import cacheBustingString from '@cdc/core/helpers/cacheBustingString'
20
20
 
21
- type DefaultsType = typeof defaults
22
- interface Props {
23
- configUrl?: string
24
- config?: any
25
- isDashboard?: boolean
26
- isEditor?: boolean
27
- setConfig?: any
28
- link?: any
29
- }
30
-
31
- const CdcDataBite: FC<Props> = props => {
21
+ const CdcDataBite = props => {
32
22
  const { configUrl, config: configObj, isDashboard = false, isEditor = false, setConfig: setParentConfig, link } = props
33
23
 
34
- const [config, setConfig] = useState<DefaultsType>({ ...defaults })
35
- const [loading, setLoading] = useState<Boolean>(true)
24
+ const [config, setConfig] = useState({ ...defaults })
25
+ const [loading, setLoading] = useState(true)
36
26
 
37
27
  const {
38
28
  title,
@@ -52,7 +42,7 @@ const CdcDataBite: FC<Props> = props => {
52
42
 
53
43
  const transform = new DataTransform()
54
44
 
55
- const [currentViewport, setCurrentViewport] = useState<String>('lg')
45
+ const [currentViewport, setCurrentViewport] = useState('lg')
56
46
 
57
47
  const [coveLoadedHasRan, setCoveLoadedHasRan] = useState(false)
58
48
 
@@ -83,6 +73,7 @@ const CdcDataBite: FC<Props> = props => {
83
73
  setConfig(newConfig)
84
74
  }
85
75
 
76
+ //@ts-ignore
86
77
  const loadConfig = async () => {
87
78
  let response = configObj || (await (await fetch(configUrl)).json())
88
79
 
@@ -110,13 +101,13 @@ const CdcDataBite: FC<Props> = props => {
110
101
  setLoading(false)
111
102
  }
112
103
 
113
- const calculateDataBite = (includePrefixSuffix: boolean = true): string | number => {
104
+ const calculateDataBite = (includePrefixSuffix= true) => {
114
105
  //If either the column or function aren't set, do not calculate
115
106
  if (!dataColumn || !dataFunction) {
116
107
  return ''
117
108
  }
118
109
 
119
- const applyPrecision = (value: number | string): string => {
110
+ const applyPrecision = (value) => {
120
111
  // first validation
121
112
  if (value === undefined || value === null) {
122
113
  console.error('Enter correct value to "applyPrecision()" function ')
@@ -127,7 +118,7 @@ const CdcDataBite: FC<Props> = props => {
127
118
  console.error(' Argunment isNaN, "applyPrecision()" function ')
128
119
  return
129
120
  }
130
- let result: number | string = value
121
+ let result = value
131
122
  let roundToPlace = Number(config.dataFormat.roundToPlace) // default equals to 0
132
123
  // ROUND FIELD going -1,-2,-3 numbers
133
124
  if (roundToPlace < 0) {
@@ -141,7 +132,7 @@ const CdcDataBite: FC<Props> = props => {
141
132
  }
142
133
 
143
134
  // filter null and 0 out from count data
144
- const getColumnCount = (arr: (string | number)[]) => {
135
+ const getColumnCount = (arr) => {
145
136
  if (config.dataFormat.ignoreZeros) {
146
137
  numericalData = numericalData.filter(item => item && item)
147
138
  return numericalData.length
@@ -150,7 +141,7 @@ const CdcDataBite: FC<Props> = props => {
150
141
  }
151
142
  }
152
143
 
153
- const getColumnSum = (arr: (string | number)[]) => {
144
+ const getColumnSum = (arr) => {
154
145
  // first validation
155
146
  if (arr === undefined || arr === null) {
156
147
  console.error('Enter valid value for getColumnSum function ')
@@ -162,17 +153,17 @@ const CdcDataBite: FC<Props> = props => {
162
153
  console.error('Arguments are not valid getColumnSum function ')
163
154
  return
164
155
  }
165
- let sum: number = 0
156
+ let sum = 0
166
157
  if (arr.length > 1) {
167
158
  /// first convert each element to number then add using reduce method to escape string concatination.
168
- sum = arr.map(el => Number(el)).reduce((sum: number, x: number) => sum + x)
159
+ sum = arr.map(el => Number(el)).reduce((sum, x) => sum + x)
169
160
  } else {
170
161
  sum = Number(arr[0])
171
162
  }
172
163
  return applyPrecision(sum)
173
164
  }
174
165
 
175
- const getColumnMean = (arr: (string | number)[]) => {
166
+ const getColumnMean = (arr) => {
176
167
  // add default params to escape errors on runtime
177
168
  // first validation
178
169
  if (arr === undefined || arr === null || !Array.isArray(arr)) {
@@ -184,7 +175,7 @@ const CdcDataBite: FC<Props> = props => {
184
175
  arr = arr.filter(num => num !== 0)
185
176
  }
186
177
 
187
- let mean: number = 0
178
+ let mean = 0
188
179
  if (arr.length > 1) {
189
180
  /// first convert each element to number then add using reduce method to escape string concatination.
190
181
  mean = arr.map(el => Number(el)).reduce((a, b) => a + b) / arr.length
@@ -194,7 +185,7 @@ const CdcDataBite: FC<Props> = props => {
194
185
  return applyPrecision(mean)
195
186
  }
196
187
 
197
- const getMode = (arr: any[] = []): string[] => {
188
+ const getMode = (arr = []) => {
198
189
  // add default params to escape errors on runtime
199
190
  // this function accepts any array and returns array of strings
200
191
  let freq = {}
@@ -229,7 +220,7 @@ const CdcDataBite: FC<Props> = props => {
229
220
  return applyPrecision(value)
230
221
  }
231
222
 
232
- const applyLocaleString = (value: string): string => {
223
+ const applyLocaleString = (value) => {
233
224
  if (value === undefined || value === null) return
234
225
  if (Number.isNaN(value) || typeof value === 'number') {
235
226
  value = String(value)
@@ -248,7 +239,7 @@ const CdcDataBite: FC<Props> = props => {
248
239
  return formattedValue
249
240
  }
250
241
 
251
- let dataBite: string | number = ''
242
+ let dataBite = ''
252
243
 
253
244
  //Optionally filter the data based on the user's filter
254
245
  let filteredData = config.data
@@ -263,7 +254,7 @@ const CdcDataBite: FC<Props> = props => {
263
254
  }
264
255
  })
265
256
 
266
- let numericalData: any[] = []
257
+ let numericalData = []
267
258
  // Get the column's data
268
259
  if (filteredData.length) {
269
260
  filteredData.forEach(row => {
@@ -297,8 +288,8 @@ const CdcDataBite: FC<Props> = props => {
297
288
  dataBite = getMode(numericalData).join('')
298
289
  break
299
290
  case DATA_FUNCTION_RANGE:
300
- let rangeMin: number | string = Math.min(...numericalData)
301
- let rangeMax: number | string = Math.max(...numericalData)
291
+ let rangeMin = Math.min(...numericalData)
292
+ let rangeMax = Math.max(...numericalData)
302
293
  rangeMin = applyPrecision(rangeMin)
303
294
  rangeMax = applyPrecision(rangeMax)
304
295
  if (config.dataFormat.commas) {
package/src/index.jsx ADDED
@@ -0,0 +1,14 @@
1
+ import React from 'react'
2
+ import ReactDOM from 'react-dom/client'
3
+
4
+ import CdcDataBite from './CdcDataBite'
5
+
6
+ let isEditor = window.location.href.includes('editor=true')
7
+
8
+ let domContainer = document.getElementsByClassName('react-container')[0]
9
+
10
+ ReactDOM.createRoot(domContainer).render(
11
+ <React.StrictMode>
12
+ <CdcDataBite configUrl={domContainer.attributes['data-config']?.value} isEditor={isEditor} />
13
+ </React.StrictMode>,
14
+ )
@@ -1,6 +1,6 @@
1
- @import '~@cdc/core/styles/base';
2
- @import '~@cdc/core/styles/heading-colors';
3
- @import '~@cdc/core/styles/v2/themes/color-definitions';
1
+ @import '@cdc/core/styles/base';
2
+ @import '@cdc/core/styles/heading-colors';
3
+ @import '@cdc/core/styles/v2/themes/color-definitions';
4
4
  @import 'variables';
5
5
 
6
6
  .cdc-open-viz-module.type-data-bite {
package/vite.config.js ADDED
@@ -0,0 +1,4 @@
1
+ import GenerateViteConfig from '../../generateViteConfig.js'
2
+ import { moduleName } from './package.json'
3
+
4
+ export default GenerateViteConfig(moduleName)