@cdc/markup-include 4.24.3 → 4.24.5
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/dist/cdcmarkupinclude.js +8997 -4945
- package/index.html +6 -5
- package/package.json +3 -3
- package/src/CdcMarkupInclude.tsx +92 -36
- package/src/ConfigContext.ts +16 -0
- package/src/_stories/MarkupInclude.stories.tsx +44 -5
- package/src/_stories/_mock/button-and-text.json +69 -0
- package/src/_stories/_mock/icon-no-text.json +59 -0
- package/src/_stories/_mock/image-with-text.json +59 -0
- package/src/_stories/_mock/no-conditions.json +61 -0
- package/src/_stories/_mock/primary.json +23 -0
- package/src/_stories/_mock/with-conditions.json +49 -0
- package/src/cdcMarkupInclude.style.css +39 -0
- package/src/components/Conditions.tsx +99 -0
- package/src/components/EditorPanel.tsx +201 -0
- package/src/components/Variables.tsx +171 -0
- package/src/components/editorPanel.style.css +17 -0
- package/src/data/initial-state.js +13 -4
- package/src/scss/main.scss +30 -2
- package/src/store/{mi.actions.ts → markupInclude.actions.ts} +2 -2
- package/src/store/{mi.reducer.ts → markupInclude.reducer.ts} +3 -3
- package/src/types/Condition.ts +5 -0
- package/src/types/Config.ts +18 -6
- package/src/types/Variable.ts +7 -0
- package/examples/example-config.json +0 -7
- package/examples/gallery/button-and-text.json +0 -31
- package/examples/gallery/icon-no-text.json +0 -31
- package/examples/gallery/image-with-text.json +0 -31
- package/src/ConfigContext.jsx +0 -5
- package/src/components/EditorPanel.jsx +0 -167
package/src/types/Config.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Runtime } from '@cdc/core/types/Runtime'
|
|
2
|
+
import { Variable } from './Variable'
|
|
3
|
+
|
|
3
4
|
export type Config = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
contentEditor: {
|
|
6
|
+
// Changing the base config object creates an infinite loop, nesting it is a workaround
|
|
7
|
+
inlineHTML: string
|
|
8
|
+
markupVariables: Variable[]
|
|
9
|
+
showHeader: boolean
|
|
10
|
+
srcUrl: string
|
|
11
|
+
title: string
|
|
12
|
+
useInlineHTML: boolean
|
|
13
|
+
}
|
|
14
|
+
data?: Object[]
|
|
15
|
+
legend: {}
|
|
16
|
+
newViz?: boolean
|
|
17
|
+
runtime?: Runtime
|
|
8
18
|
theme: any
|
|
19
|
+
type: string
|
|
20
|
+
showEditorPanel?: boolean
|
|
9
21
|
visual: {
|
|
10
22
|
border: boolean
|
|
11
23
|
accent: boolean
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"title": "",
|
|
3
|
-
"showHeader": false,
|
|
4
|
-
"type": "markup-include",
|
|
5
|
-
"srcUrl": "https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/Markup-Include-Button-and-Text.html",
|
|
6
|
-
"theme": "theme-blue",
|
|
7
|
-
"data": [
|
|
8
|
-
{
|
|
9
|
-
"Race": "Hispanic or Latino",
|
|
10
|
-
"Age-adjusted rate": "644.2"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"Race": "Non-Hispanic American Indian",
|
|
14
|
-
"Age-adjusted rate": "636.1"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"Race": "Non-Hispanic Black",
|
|
18
|
-
"Age-adjusted rate": "563.7"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"Race": "Non-Hispanic Asian or Pacific Islander",
|
|
22
|
-
"Age-adjusted rate": "202.5"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"Race": "Non-Hispanic White",
|
|
26
|
-
"Age-adjusted rate": "183.6"
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"dataFileName": "valid-data-chart.csv",
|
|
30
|
-
"dataFileSourceType": "file"
|
|
31
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"title": "",
|
|
3
|
-
"showHeader": false,
|
|
4
|
-
"type": "markup-include",
|
|
5
|
-
"srcUrl": "https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/examples/SSI-Example-Markup-Include.html",
|
|
6
|
-
"theme": "theme-blue",
|
|
7
|
-
"data": [
|
|
8
|
-
{
|
|
9
|
-
"Race": "Hispanic or Latino",
|
|
10
|
-
"Age-adjusted rate": "644.2"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"Race": "Non-Hispanic American Indian",
|
|
14
|
-
"Age-adjusted rate": "636.1"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"Race": "Non-Hispanic Black",
|
|
18
|
-
"Age-adjusted rate": "563.7"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"Race": "Non-Hispanic Asian or Pacific Islander",
|
|
22
|
-
"Age-adjusted rate": "202.5"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"Race": "Non-Hispanic White",
|
|
26
|
-
"Age-adjusted rate": "183.6"
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"dataFileName": "valid-data-chart.csv",
|
|
30
|
-
"dataFileSourceType": "file"
|
|
31
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"title": "<strong>Markup Include</strong> - Image with Text",
|
|
3
|
-
"showHeader": false,
|
|
4
|
-
"type": "markup-include",
|
|
5
|
-
"srcUrl": "/wcms/4.0/cdc-wp/data-presentation/examples/SSI-Image-With-Text.html",
|
|
6
|
-
"theme": "theme-slate",
|
|
7
|
-
"data": [
|
|
8
|
-
{
|
|
9
|
-
"Race": "Hispanic or Latino",
|
|
10
|
-
"Age-adjusted rate": "644.2"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"Race": "Non-Hispanic American Indian",
|
|
14
|
-
"Age-adjusted rate": "636.1"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"Race": "Non-Hispanic Black",
|
|
18
|
-
"Age-adjusted rate": "563.7"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"Race": "Non-Hispanic Asian or Pacific Islander",
|
|
22
|
-
"Age-adjusted rate": "202.5"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"Race": "Non-Hispanic White",
|
|
26
|
-
"Age-adjusted rate": "183.6"
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"dataFileName": "valid-data-chart.csv",
|
|
30
|
-
"dataFileSourceType": "file"
|
|
31
|
-
}
|
package/src/ConfigContext.jsx
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, memo, useContext } from 'react'
|
|
2
|
-
|
|
3
|
-
import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
|
|
4
|
-
|
|
5
|
-
import ConfigContext from '../ConfigContext'
|
|
6
|
-
|
|
7
|
-
import Accordion from '@cdc/core/components/ui/Accordion'
|
|
8
|
-
import InputText from '@cdc/core/components/inputs/InputText'
|
|
9
|
-
import { updateFieldFactory } from '@cdc/core/helpers/updateFieldFactory'
|
|
10
|
-
|
|
11
|
-
import '@cdc/core/styles/v2/components/editor.scss'
|
|
12
|
-
|
|
13
|
-
const headerColors = ['theme-blue', 'theme-purple', 'theme-brown', 'theme-teal', 'theme-pink', 'theme-orange', 'theme-slate', 'theme-indigo', 'theme-cyan', 'theme-green', 'theme-amber']
|
|
14
|
-
|
|
15
|
-
const EditorPanel = memo(props => {
|
|
16
|
-
const { config, updateConfig, loading, data, setParentConfig, isDashboard } = useContext(ConfigContext)
|
|
17
|
-
|
|
18
|
-
const [displayPanel, setDisplayPanel] = useState(true)
|
|
19
|
-
const [showConfigConfirm, setShowConfigConfirm] = useState(false)
|
|
20
|
-
|
|
21
|
-
const updateField = updateFieldFactory(config, updateConfig, true)
|
|
22
|
-
|
|
23
|
-
const missingRequiredSections = () => {
|
|
24
|
-
return false
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
// Pass up to Editor if needed
|
|
29
|
-
if (setParentConfig) {
|
|
30
|
-
const newConfig = convertStateToConfig()
|
|
31
|
-
|
|
32
|
-
setParentConfig(newConfig)
|
|
33
|
-
}
|
|
34
|
-
}, [config])
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (!showConfigConfirm) {
|
|
38
|
-
let newConfig = { ...config }
|
|
39
|
-
delete newConfig.newViz
|
|
40
|
-
updateConfig(newConfig)
|
|
41
|
-
}
|
|
42
|
-
}, [])
|
|
43
|
-
|
|
44
|
-
const onBackClick = () => {
|
|
45
|
-
setDisplayPanel(!displayPanel)
|
|
46
|
-
|
|
47
|
-
// if (isDashboard) {
|
|
48
|
-
// updateConfig({ ...config, editing: false })
|
|
49
|
-
// } else {
|
|
50
|
-
// setDisplayPanel(!displayPanel)
|
|
51
|
-
// }
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const Error = () => {
|
|
55
|
-
return (
|
|
56
|
-
<section className='waiting'>
|
|
57
|
-
<section className='waiting-container'>
|
|
58
|
-
<h3>Error With Configuration</h3>
|
|
59
|
-
<p>{config.runtime.editorErrorMessage}</p>
|
|
60
|
-
</section>
|
|
61
|
-
</section>
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const Confirm = () => {
|
|
66
|
-
const confirmDone = e => {
|
|
67
|
-
e.preventDefault()
|
|
68
|
-
let newConfig = { ...config }
|
|
69
|
-
delete newConfig.newViz
|
|
70
|
-
updateConfig(newConfig)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<section className='waiting'>
|
|
75
|
-
<section className='waiting-container'>
|
|
76
|
-
<h3>Finish Configuring</h3>
|
|
77
|
-
<p>Set all required options to the left and confirm below to display a preview of the markup.</p>
|
|
78
|
-
<button className='btn' style={{ margin: '1em auto' }} onClick={confirmDone}>
|
|
79
|
-
I'm Done
|
|
80
|
-
</button>
|
|
81
|
-
</section>
|
|
82
|
-
</section>
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const convertStateToConfig = () => {
|
|
87
|
-
let strippedState = JSON.parse(JSON.stringify(config))
|
|
88
|
-
delete strippedState.newViz
|
|
89
|
-
delete strippedState.runtime
|
|
90
|
-
|
|
91
|
-
return strippedState
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const CheckBox = memo(({ label, value, fieldName, section = null, subsection = null, tooltip, updateField, ...attributes }) => (
|
|
95
|
-
<label className='checkbox'>
|
|
96
|
-
<input
|
|
97
|
-
type='checkbox'
|
|
98
|
-
name={fieldName}
|
|
99
|
-
checked={value}
|
|
100
|
-
onChange={() => {
|
|
101
|
-
updateField(section, subsection, fieldName, !value)
|
|
102
|
-
}}
|
|
103
|
-
{...attributes}
|
|
104
|
-
/>
|
|
105
|
-
<span className='edit-label column-heading'>{label}</span>
|
|
106
|
-
<span className='cove-icon'>{tooltip}</span>
|
|
107
|
-
</label>
|
|
108
|
-
))
|
|
109
|
-
|
|
110
|
-
const editorContent = (
|
|
111
|
-
<Accordion>
|
|
112
|
-
<Accordion.Section title='General'>
|
|
113
|
-
<InputText value={config.title || ''} fieldName='title' label='Title' placeholder='Markup Include Title' updateField={updateField} />
|
|
114
|
-
|
|
115
|
-
<InputText value={config.srcUrl || ''} fieldName='srcUrl' label='Source URL' placeholder='https://www.example.com/file.html' updateField={updateField} />
|
|
116
|
-
</Accordion.Section>
|
|
117
|
-
<Accordion.Section title='Visual'>
|
|
118
|
-
<div className='input-group'>
|
|
119
|
-
<label>Theme</label>
|
|
120
|
-
<ul className='color-palette'>
|
|
121
|
-
{headerColors.map(palette => (
|
|
122
|
-
<li
|
|
123
|
-
title={palette}
|
|
124
|
-
key={palette}
|
|
125
|
-
onClick={() => {
|
|
126
|
-
updateConfig({ ...config, theme: palette })
|
|
127
|
-
}}
|
|
128
|
-
className={config.theme === palette ? 'selected ' + palette : palette}
|
|
129
|
-
></li>
|
|
130
|
-
))}
|
|
131
|
-
</ul>
|
|
132
|
-
</div>
|
|
133
|
-
|
|
134
|
-
<div className='cove-accordion__panel-section checkbox-group'>
|
|
135
|
-
<CheckBox value={config.visual.border} section='visual' fieldName='border' label='Display Border' updateField={updateField} />
|
|
136
|
-
<CheckBox value={config.visual.borderColorTheme} section='visual' fieldName='borderColorTheme' label='Use Border Color Theme' updateField={updateField} />
|
|
137
|
-
<CheckBox value={config.visual.accent} section='visual' fieldName='accent' label='Use Accent Style' updateField={updateField} />
|
|
138
|
-
<CheckBox value={config.visual.background} section='visual' fieldName='background' label='Use Theme Background Color' updateField={updateField} />
|
|
139
|
-
<CheckBox value={config.visual.hideBackgroundColor} section='visual' fieldName='hideBackgroundColor' label='Hide Background Color' updateField={updateField} />
|
|
140
|
-
</div>
|
|
141
|
-
</Accordion.Section>
|
|
142
|
-
</Accordion>
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
if (loading) return null
|
|
146
|
-
|
|
147
|
-
return (
|
|
148
|
-
<ErrorBoundary component='EditorPanel'>
|
|
149
|
-
<div className='cove-editor'>
|
|
150
|
-
{!config.newViz && config.runtime && config.runtime.editorErrorMessage && <Error />}
|
|
151
|
-
{config.newViz && showConfigConfirm && <Confirm />}
|
|
152
|
-
<button className={`cove-editor--toggle` + (!displayPanel ? ` collapsed` : ``)} title={displayPanel ? `Collapse Editor` : `Expand Editor`} onClick={onBackClick} />
|
|
153
|
-
<section className={`cove-editor__panel` + (displayPanel ? `` : ' hidden')}>
|
|
154
|
-
<div className='cove-editor__panel-container'>
|
|
155
|
-
<h2 className='cove-editor__heading'>Configure Markup Include</h2>
|
|
156
|
-
<section className='cove-editor__content'>{editorContent}</section>
|
|
157
|
-
</div>
|
|
158
|
-
</section>
|
|
159
|
-
<div className='cove-editor__content'>
|
|
160
|
-
<div className='cove-editor__content-wrap'>{props.children}</div>
|
|
161
|
-
</div>
|
|
162
|
-
</div>
|
|
163
|
-
</ErrorBoundary>
|
|
164
|
-
)
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
export default EditorPanel
|