@cdc/filtered-text 4.26.1 → 4.26.3

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,13 @@
1
+ {
2
+ "type": "filtered-text",
3
+ "title": "Filtered Text",
4
+ "theme": "theme-blue",
5
+ "dataUrl": "examples/sex-ageGroup-with-values.json",
6
+ "textColumn": "Text",
7
+ "filters": [
8
+ {
9
+ "columnName": "Sex",
10
+ "columnValue": "Female"
11
+ }
12
+ ]
13
+ }
package/index.html CHANGED
@@ -1,24 +1 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
6
- <style type="text/css">
7
- body {
8
- margin: 0;
9
- border-top: none !important;
10
- }
11
-
12
- /* Add 1rem padding to mimic DFE when editor is not visible */
13
- .cdc-open-viz-module:not(.isEditor) {
14
- padding: 1rem;
15
- }
16
- </style>
17
- <link rel="stylesheet prefetch" href="https://www.cdc.gov/TemplatePackage/5.0/css/app.min.css?_=71669" />
18
- </head>
19
-
20
- <body>
21
- <div class="react-container" data-config="/examples/example-config.json"></div>
22
- <script type="module" src="./src/index.jsx"></script>
23
- </body>
24
- </html>
1
+ <!-- index.html is generated by @cdc/core/generateViteConfig.js using the files in @cdc/core/devTemplate/ -->
package/package.json CHANGED
@@ -1,45 +1,40 @@
1
1
  {
2
2
  "name": "@cdc/filtered-text",
3
- "version": "4.26.1",
3
+ "version": "4.26.3",
4
4
  "description": "React component for adding filtered text on dashboards.",
5
- "moduleName": "CdcFilteredText",
6
- "main": "dist/cdcfilteredtext",
7
- "type": "module",
8
- "scripts": {
9
- "start": "vite --open",
10
- "build": "vite build",
11
- "preview": "vite preview",
12
- "graph": "nx graph",
13
- "prepublishOnly": "lerna run --scope @cdc/filtered-text build",
14
- "test": "vitest run --reporter verbose",
15
- "test-watch": "vitest watch --reporter verbose",
16
- "test-watch:ui": "vitest --ui"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/CDCgov/cdc-open-viz.git"
21
- },
22
- "author": "Adam Doe <rsq2@cdc.gov>",
23
- "bugs": {
24
- "url": "https://github.com/CDCgov/cdc-open-viz/issues"
25
- },
26
5
  "license": "Apache-2.0",
27
- "homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
6
+ "author": "Adam Doe <rsq2@cdc.gov>",
7
+ "bugs": "https://github.com/CDCgov/cdc-open-viz/issues",
28
8
  "dependencies": {
29
- "@cdc/core": "^4.26.1",
30
- "html-react-parser": "5.2.3",
31
- "lodash": "^4.17.21"
32
- },
33
- "peerDependencies": {
34
- "react": "^18.2.0",
35
- "react-dom": "^18.2.0"
9
+ "@cdc/core": "^4.26.3",
10
+ "html-react-parser": "^5.2.3",
11
+ "lodash": "^4.17.23"
36
12
  },
37
13
  "devDependencies": {
38
14
  "@rollup/plugin-dsv": "^3.0.2",
39
- "@vitejs/plugin-react": "^4.3.4",
15
+ "@vitejs/plugin-react": "^5.1.2",
40
16
  "sass": "^1.89.2",
41
17
  "vite-plugin-css-injected-by-js": "^2.4.0",
42
18
  "vite-plugin-svgr": "^4.2.0"
43
19
  },
44
- "gitHead": "7e3b27098c4eb7a24bc9c3654ad53f88d6419f16"
20
+ "gitHead": "d50e45a074fbefa56cac904917e707d57f237737",
21
+ "homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
22
+ "main": "dist/cdcfilteredtext",
23
+ "moduleName": "CdcFilteredText",
24
+ "peerDependencies": {
25
+ "react": "^18.2.0",
26
+ "react-dom": "^18.2.0"
27
+ },
28
+ "repository": "CDCgov/cdc-open-viz.git",
29
+ "scripts": {
30
+ "build": "vite build",
31
+ "graph": "nx graph",
32
+ "prepublishOnly": "lerna run --scope @cdc/filtered-text build",
33
+ "preview": "vite preview",
34
+ "start": "vite --open",
35
+ "test": "vitest run --reporter verbose",
36
+ "test-watch": "vitest watch --reporter verbose",
37
+ "test-watch:ui": "vitest --ui"
38
+ },
39
+ "type": "module"
45
40
  }
@@ -12,9 +12,10 @@ import EditorPanel from './components/EditorPanel'
12
12
 
13
13
  // helpers
14
14
  import DataTransform from '@cdc/core/helpers/DataTransform'
15
+ import fetchRemoteData from '@cdc/core/helpers/fetchRemoteData'
15
16
  import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses'
16
17
  import coveUpdateWorker from '@cdc/core/helpers/coveUpdateWorker'
17
- import Layout from '@cdc/core/components/Layout'
18
+ import { VisualizationContainer, VisualizationContent } from '@cdc/core/components/Layout'
18
19
 
19
20
  // external
20
21
  import parse from 'html-react-parser'
@@ -38,10 +39,6 @@ const CdcFilteredText = ({
38
39
  let { title, filters } = config
39
40
 
40
41
  const { contentClasses, innerContainerClasses } = useDataVizClasses(config)
41
- const { visual } = config
42
-
43
- const shouldApplyTopPadding = visual?.border || visual?.background || (config.title && config.titleStyle === 'legacy')
44
- const shouldApplySidePadding = visual?.border || visual?.accent || visual?.background
45
42
 
46
43
  // Default Functions
47
44
 
@@ -51,9 +48,9 @@ const CdcFilteredText = ({
51
48
  let data = response.formattedData || response.data || {}
52
49
 
53
50
  if (response.dataUrl) {
54
- const dataString = await fetch(response.dataUrl)
55
-
56
- data = await dataString.json()
51
+ const { data: fetchedData, dataMetadata } = await fetchRemoteData(response.dataUrl)
52
+ data = fetchedData
53
+ response.dataMetadata = dataMetadata
57
54
  if (response.dataDescription) {
58
55
  data = transform.autoStandardize(data)
59
56
  data = transform.developerStandardize(data, response.dataDescription)
@@ -122,39 +119,29 @@ const CdcFilteredText = ({
122
119
  let content = <Loading />
123
120
 
124
121
  if (loading === false) {
125
- let body = (
126
- <>
127
- <Layout.Responsive isEditor={isEditor}>
128
- <div className={`cove-component__content no-borders`}>
129
- <Title
130
- classes={[`${config.theme}`, 'mb-0']}
131
- title={title}
132
- titleStyle={config.titleStyle}
133
- config={config}
134
- noContent={!config.textColumn}
135
- />
136
- <div
137
- className={`${contentClasses.join(' ')} body${shouldApplyTopPadding ? ' has-top-padding' : ''}${
138
- shouldApplySidePadding ? ' has-side-padding' : ''
139
- }`}
140
- >
141
- {filterByTextColumn()
142
- .slice(0, 1)
143
- .map((el, i) => (
144
- <p key={i}> {parse(el[config.textColumn] || '')} </p>
145
- ))}
146
- </div>
147
- </div>
148
- </Layout.Responsive>
149
- </>
122
+ const body = (
123
+ <VisualizationContent
124
+ innerClassName={innerContainerClasses.join(' ')}
125
+ bodyClassName={contentClasses.join(' ')}
126
+ header={
127
+ <Title
128
+ classes={[`${config.theme}`, 'mb-0']}
129
+ title={title}
130
+ titleStyle={config.titleStyle}
131
+ config={config}
132
+ noContent={!config.textColumn}
133
+ />
134
+ }
135
+ >
136
+ {filterByTextColumn()
137
+ .slice(0, 1)
138
+ .map((el, i) => (
139
+ <p key={i}> {parse(el[config.textColumn] || '')} </p>
140
+ ))}
141
+ </VisualizationContent>
150
142
  )
151
143
 
152
- content = (
153
- <>
154
- {isEditor && <EditorPanel />}
155
- {body}
156
- </>
157
- )
144
+ content = body
158
145
  }
159
146
  const values = {
160
147
  config,
@@ -169,9 +156,9 @@ const CdcFilteredText = ({
169
156
  return (
170
157
  <ErrorBoundary component='CdcFilteredText'>
171
158
  <ConfigContext.Provider value={values}>
172
- <Layout.VisualizationWrapper config={config} isEditor={isEditor} showEditorPanel={config?.showEditorPanel}>
159
+ <VisualizationContainer config={config} isEditor={isEditor} editorPanel={<EditorPanel />}>
173
160
  {content}
174
- </Layout.VisualizationWrapper>
161
+ </VisualizationContainer>
175
162
  </ConfigContext.Provider>
176
163
  </ErrorBoundary>
177
164
  )
@@ -10,12 +10,13 @@ import { useDataColumns } from '@cdc/core/hooks/useDataColumns'
10
10
 
11
11
  // Components
12
12
  import { EditorPanel as BaseEditorPanel } from '@cdc/core/components/EditorPanel/EditorPanel'
13
- import { TextField, Select, CheckBox } from '@cdc/core/components/EditorPanel/Inputs'
13
+ import { TextField, Select } from '@cdc/core/components/EditorPanel/Inputs'
14
14
  import Button from '@cdc/core/components/elements/Button'
15
15
  import Icon from '@cdc/core/components/ui/Icon'
16
16
  import Tooltip from '@cdc/core/components/ui/Tooltip'
17
17
  import Accordion from '@cdc/core/components/ui/Accordion'
18
- import { VisualSection } from '@cdc/core/components/EditorPanel/sections/VisualSection'
18
+ import StyleTreatmentSection from '@cdc/core/components/EditorPanel/sections/StyleTreatmentSection'
19
+ import { HeaderThemeSelector } from '@cdc/core/components/HeaderThemeSelector'
19
20
 
20
21
  type FilteredTextEditorPanelProps = {
21
22
  // Add any props if needed
@@ -24,6 +25,21 @@ type FilteredTextEditorPanelProps = {
24
25
  const EditorPanel: React.FC<FilteredTextEditorPanelProps> = () => {
25
26
  const { config, updateConfig, loading, stateData: data, setParentConfig, isDashboard } = useContext(ConfigContext)
26
27
  const updateField = updateFieldFactory(config, updateConfig, true)
28
+ const styleTreatment = config?.visual?.tp5Treatment ? 'tp5' : 'legacy'
29
+
30
+ const handleStyleTreatmentChange = (value: string) => {
31
+ const useTp5Treatment = value === 'tp5'
32
+ updateConfig({
33
+ ...config,
34
+ visual: {
35
+ ...config.visual,
36
+ tp5Treatment: useTp5Treatment,
37
+ border: useTp5Treatment ? false : config.visual?.border,
38
+ borderColorTheme: useTp5Treatment ? false : config.visual?.borderColorTheme,
39
+ accent: useTp5Treatment ? false : config.visual?.accent
40
+ }
41
+ })
42
+ }
27
43
 
28
44
  // Filters -------------------------
29
45
  const { addNewFilter, removeFilter, updateFilterProp, getFilterColumnValues } = useFilterManagement(
@@ -78,6 +94,29 @@ const EditorPanel: React.FC<FilteredTextEditorPanelProps> = () => {
78
94
  </Tooltip>
79
95
  }
80
96
  />
97
+ <Select
98
+ value={config.locale}
99
+ fieldName='locale'
100
+ label='Language for dates and numbers'
101
+ updateField={updateField}
102
+ options={[
103
+ { value: 'en-US', label: 'English (en-US)' },
104
+ { value: 'es-MX', label: 'Spanish (es-MX)' }
105
+ ]}
106
+ tooltip={
107
+ <Tooltip style={{ textTransform: 'none' }}>
108
+ <Tooltip.Target>
109
+ <Icon display='question' style={{ marginLeft: '0.5rem' }} />
110
+ </Tooltip.Target>
111
+ <Tooltip.Content>
112
+ <p>
113
+ Change the language (locale) for this visualization to alter the way dates and numbers are
114
+ formatted.
115
+ </p>
116
+ </Tooltip.Content>
117
+ </Tooltip>
118
+ }
119
+ />
81
120
  </Accordion.Section>
82
121
  <Accordion.Section title='Data'>
83
122
  <Select
@@ -149,7 +188,23 @@ const EditorPanel: React.FC<FilteredTextEditorPanelProps> = () => {
149
188
  </Button>
150
189
  </Accordion.Section>
151
190
  <Accordion.Section title='Visual'>
152
- <VisualSection config={config} updateField={updateField} updateConfig={updateConfig} />
191
+ <HeaderThemeSelector
192
+ selectedTheme={config.theme}
193
+ onThemeSelect={theme => updateConfig({ ...config, theme })}
194
+ />
195
+ <StyleTreatmentSection
196
+ styleTreatment={styleTreatment}
197
+ onStyleTreatmentChange={handleStyleTreatmentChange}
198
+ showStyleTreatment={false}
199
+ border={config.visual?.border}
200
+ borderColorTheme={config.visual?.borderColorTheme}
201
+ accent={config.visual?.accent}
202
+ background={config.visual?.background}
203
+ hideBackgroundColor={config.visual?.hideBackgroundColor}
204
+ showBackground
205
+ showHideBackgroundColor
206
+ updateField={updateField}
207
+ />
153
208
  </Accordion.Section>
154
209
  </Accordion>
155
210
  )}
@@ -1,4 +1,6 @@
1
- .cdc-open-viz-module.isEditor {
1
+ @import '@cdc/core/styles/layout/wrapper-padding';
2
+
3
+ .cove-visualization.is-editor {
2
4
  background: transparent;
3
5
  }
4
6
 
@@ -12,23 +14,14 @@
12
14
  }
13
15
  }
14
16
 
15
- .cdc-open-viz-module.type-filtered-text {
17
+ .cove-visualization.type-filtered-text {
18
+ .cove-visualization__body {
19
+ @include cove-visualization-body-padding;
20
+ }
21
+
16
22
  .cove-accordion__panel-section .cove-input__checkbox--small {
17
23
  // float: initial;
18
24
  // display: initial;
19
25
  float: none;
20
26
  }
21
- .cove-component__content.body:not(:empty) {
22
- padding: 0;
23
-
24
- &.has-top-padding {
25
- padding-top: 1rem;
26
- padding-bottom: 1rem;
27
- }
28
-
29
- &.has-side-padding {
30
- padding-left: 1rem;
31
- padding-right: 1rem;
32
- }
33
- }
34
27
  }
@@ -1,11 +1,11 @@
1
- import path from 'path'
1
+ import path from 'node:path'
2
2
  import { testStandaloneBuild } from '@cdc/core/helpers/tests/testStandaloneBuild.ts'
3
3
  import { describe, it, expect } from 'vitest'
4
4
 
5
5
  describe('Filtered Text', () => {
6
6
  it('Can be built in isolation', async () => {
7
7
  const pkgDir = path.join(__dirname, '..')
8
- const result = testStandaloneBuild(pkgDir)
8
+ const result = await testStandaloneBuild(pkgDir)
9
9
  expect(result).toBe(true)
10
10
  }, 300000)
11
11
  })