@cdc/map 4.23.3 → 4.23.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/cdcmap.js +25301 -29100
- package/examples/custom-map-layers.json +764 -0
- package/examples/default-county.json +169 -155
- package/examples/example-city-state.json +34 -12
- package/examples/testing-layer-2.json +1 -0
- package/examples/testing-layer.json +96 -0
- package/index.html +6 -5
- package/package.json +3 -3
- package/src/CdcMap.jsx +201 -105
- package/src/components/CountyMap.jsx +31 -6
- package/src/components/DataTable.jsx +185 -218
- package/src/components/EditorPanel.jsx +293 -162
- package/src/components/UsaMap.jsx +17 -11
- package/src/data/initial-state.js +16 -8
- package/src/hooks/useMapLayers.jsx +243 -0
- package/src/index.jsx +4 -8
- package/src/scss/editor-panel.scss +97 -97
- package/src/scss/filters.scss +0 -2
- package/src/scss/main.scss +25 -26
- package/src/components/Filters.jsx +0 -113
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import React, { useState, useContext } from 'react'
|
|
2
|
-
import Context from './../context'
|
|
3
|
-
import Button from '@cdc/core/components/elements/Button'
|
|
4
|
-
|
|
5
|
-
// TODO: Combine Charts/Maps Filters.js files
|
|
6
|
-
const useFilters = () => {
|
|
7
|
-
const { state: config, setState: setConfig, runtimeFilters, setRuntimeFilters } = useContext(Context)
|
|
8
|
-
const [showApplyButton, setShowApplyButton] = useState(false)
|
|
9
|
-
|
|
10
|
-
const sortAsc = (a, b) => {
|
|
11
|
-
return a.toString().localeCompare(b.toString(), 'en', { numeric: true })
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const sortDesc = (a, b) => {
|
|
15
|
-
return b.toString().localeCompare(a.toString(), 'en', { numeric: true })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const announceChange = text => { }
|
|
19
|
-
|
|
20
|
-
const changeFilterActive = (index, value) => {
|
|
21
|
-
let newFilters = config.filters
|
|
22
|
-
newFilters[index].active = value
|
|
23
|
-
setRuntimeFilters(newFilters)
|
|
24
|
-
setShowApplyButton(true)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const handleApplyButton = () => {
|
|
28
|
-
setConfig({ ...config, filters: runtimeFilters })
|
|
29
|
-
setShowApplyButton(false)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const handleReset = (e) => {
|
|
33
|
-
e.preventDefault()
|
|
34
|
-
let newFilters = runtimeFilters
|
|
35
|
-
|
|
36
|
-
// reset to first item in values array.
|
|
37
|
-
newFilters.map(filter => {
|
|
38
|
-
filter.active = filter.values[0]
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
setConfig({ ...config, filters: newFilters })
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return { announceChange, sortAsc, sortDesc, changeFilterActive, showApplyButton, handleReset, handleApplyButton }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const Filters = () => {
|
|
48
|
-
const { runtimeFilters, state: config } = useContext(Context)
|
|
49
|
-
const { handleApplyButton, changeFilterActive, announceChange, sortAsc, sortDesc, showApplyButton, handleReset } = useFilters()
|
|
50
|
-
|
|
51
|
-
const buttonText = 'Apply Filters'
|
|
52
|
-
const resetText = 'Reset All'
|
|
53
|
-
|
|
54
|
-
const { filters } = config
|
|
55
|
-
|
|
56
|
-
if (filters.length === 0) return false
|
|
57
|
-
|
|
58
|
-
const FilterList = ({ filters: runtimeFilters }) => {
|
|
59
|
-
if (runtimeFilters) {
|
|
60
|
-
return runtimeFilters.map((singleFilter, idx) => {
|
|
61
|
-
const values = []
|
|
62
|
-
|
|
63
|
-
if (undefined === singleFilter.active) return null
|
|
64
|
-
|
|
65
|
-
singleFilter.values.forEach((filterOption, idx) => {
|
|
66
|
-
values.push(
|
|
67
|
-
<option key={idx} value={filterOption}>
|
|
68
|
-
{filterOption}
|
|
69
|
-
</option>
|
|
70
|
-
)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<section className='filter-col single-filter' key={idx}>
|
|
75
|
-
{singleFilter.label?.length > 0 && <label htmlFor={`filter-${idx}`}>{singleFilter.label}</label>}
|
|
76
|
-
<select
|
|
77
|
-
id={`filter-${idx}`}
|
|
78
|
-
className='filter-select'
|
|
79
|
-
aria-label='select filter'
|
|
80
|
-
value={singleFilter.active}
|
|
81
|
-
onChange={e => {
|
|
82
|
-
changeFilterActive(idx, e.target.value)
|
|
83
|
-
announceChange(`Filter ${singleFilter.label} value has been changed to ${e.target.value}, please reference the data table to see updated values.`)
|
|
84
|
-
}}
|
|
85
|
-
>
|
|
86
|
-
{values}
|
|
87
|
-
</select>
|
|
88
|
-
</section>
|
|
89
|
-
)
|
|
90
|
-
})
|
|
91
|
-
} else {
|
|
92
|
-
return null
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<section className={`filters-section`} style={{ display: 'block', width: '100%' }}>
|
|
98
|
-
<div className='filters-section__wrapper' style={{ flexWrap: 'wrap', display: 'flex', gap: '7px 15px', marginTop: '15px' }}>
|
|
99
|
-
<FilterList filters={runtimeFilters} />
|
|
100
|
-
<div className='filter-section__buttons' style={{ width: '100%' }}>
|
|
101
|
-
<Button onClick={handleApplyButton} disabled={!showApplyButton} style={{ marginRight: '10px' }}>
|
|
102
|
-
{buttonText}
|
|
103
|
-
</Button>
|
|
104
|
-
<a href='#!' role='button' onClick={handleReset}>
|
|
105
|
-
{resetText}
|
|
106
|
-
</a>
|
|
107
|
-
</div>
|
|
108
|
-
</div>
|
|
109
|
-
</section>
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export default Filters
|