@carto/ps-react-ui 4.12.2 → 4.13.0
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/components.js +706 -658
- package/dist/components.js.map +1 -1
- package/dist/legend/stores.js +20 -0
- package/dist/legend/stores.js.map +1 -0
- package/dist/legend.js +1536 -0
- package/dist/legend.js.map +1 -0
- package/dist/selectors-DwHj6mE2.js +388 -0
- package/dist/selectors-DwHj6mE2.js.map +1 -0
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/responsive-drawer/responsive-drawer.d.ts +35 -3
- package/dist/types/legend/components/contexts.d.ts +20 -0
- package/dist/types/legend/components/icons.d.ts +12 -0
- package/dist/types/legend/components/index.d.ts +26 -0
- package/dist/types/legend/components/legend-actions/legend-actions.d.ts +24 -0
- package/dist/types/legend/components/legend-actions/styles.d.ts +7 -0
- package/dist/types/legend/components/legend-category/legend-category-ui.d.ts +13 -0
- package/dist/types/legend/components/legend-category/styles.d.ts +52 -0
- package/dist/types/legend/components/legend-config-select/legend-config-select.d.ts +14 -0
- package/dist/types/legend/components/legend-config-select/styles.d.ts +44 -0
- package/dist/types/legend/components/legend-group/legend-group.d.ts +21 -0
- package/dist/types/legend/components/legend-group/styles.d.ts +63 -0
- package/dist/types/legend/components/legend-icon/legend-icon-ui.d.ts +10 -0
- package/dist/types/legend/components/legend-icon/styles.d.ts +52 -0
- package/dist/types/legend/components/legend-item/legend-item-ui.d.ts +14 -0
- package/dist/types/legend/components/legend-item/legend-item.d.ts +10 -0
- package/dist/types/legend/components/legend-item/styles.d.ts +7 -0
- package/dist/types/legend/components/legend-opacity/legend-opacity.d.ts +32 -0
- package/dist/types/legend/components/legend-opacity/styles.d.ts +23 -0
- package/dist/types/legend/components/legend-proportion/legend-proportion-ui.d.ts +16 -0
- package/dist/types/legend/components/legend-proportion/styles.d.ts +37 -0
- package/dist/types/legend/components/legend-ramp/legend-ramp-ui.d.ts +20 -0
- package/dist/types/legend/components/legend-ramp/styles.d.ts +53 -0
- package/dist/types/legend/components/legend-row/legend-row.d.ts +23 -0
- package/dist/types/legend/components/legend-row/styles.d.ts +77 -0
- package/dist/types/legend/components/legend-row-menu/legend-row-menu.d.ts +18 -0
- package/dist/types/legend/components/legend-row-menu/legend-zoom-to.d.ts +15 -0
- package/dist/types/legend/components/legend-swatch/legend-swatch.d.ts +26 -0
- package/dist/types/legend/components/legend-visibility-toggle/legend-visibility-toggle.d.ts +35 -0
- package/dist/types/legend/index.d.ts +88 -0
- package/dist/types/legend/provider/index.d.ts +6 -0
- package/dist/types/legend/provider/labels.d.ts +27 -0
- package/dist/types/legend/provider/legend-config-context.d.ts +7 -0
- package/dist/types/legend/provider/legend-provider.d.ts +38 -0
- package/dist/types/legend/stores/index.d.ts +5 -0
- package/dist/types/legend/stores/legend-context.d.ts +4 -0
- package/dist/types/legend/stores/legend-store-registry.d.ts +39 -0
- package/dist/types/legend/stores/legend-store.test.d.ts +1 -0
- package/dist/types/legend/stores/selectors.d.ts +33 -0
- package/dist/types/legend/stores/types.d.ts +275 -0
- package/package.json +11 -3
- package/src/components/geolocation-controls/geolocation-controls.test.tsx +15 -0
- package/src/components/geolocation-controls/geolocation-controls.tsx +19 -3
- package/src/components/index.ts +2 -0
- package/src/components/responsive-drawer/responsive-drawer.test.tsx +129 -25
- package/src/components/responsive-drawer/responsive-drawer.tsx +149 -16
- package/src/legend/components/contexts.ts +32 -0
- package/src/legend/components/icons.tsx +22 -0
- package/src/legend/components/index.ts +39 -0
- package/src/legend/components/legend-actions/legend-actions.tsx +57 -0
- package/src/legend/components/legend-actions/styles.ts +9 -0
- package/src/legend/components/legend-category/legend-category-ui.tsx +91 -0
- package/src/legend/components/legend-category/styles.ts +61 -0
- package/src/legend/components/legend-config-select/legend-config-select.tsx +96 -0
- package/src/legend/components/legend-config-select/styles.ts +48 -0
- package/src/legend/components/legend-group/legend-group.test.tsx +115 -0
- package/src/legend/components/legend-group/legend-group.tsx +88 -0
- package/src/legend/components/legend-group/styles.ts +82 -0
- package/src/legend/components/legend-icon/legend-icon-ui.tsx +56 -0
- package/src/legend/components/legend-icon/styles.ts +56 -0
- package/src/legend/components/legend-item/legend-item-ui.test.tsx +362 -0
- package/src/legend/components/legend-item/legend-item-ui.tsx +43 -0
- package/src/legend/components/legend-item/legend-item.tsx +34 -0
- package/src/legend/components/legend-item/styles.ts +11 -0
- package/src/legend/components/legend-opacity/legend-opacity.tsx +179 -0
- package/src/legend/components/legend-opacity/styles.ts +28 -0
- package/src/legend/components/legend-proportion/legend-proportion-ui.tsx +122 -0
- package/src/legend/components/legend-proportion/styles.ts +43 -0
- package/src/legend/components/legend-ramp/legend-ramp-ui.tsx +159 -0
- package/src/legend/components/legend-ramp/styles.ts +62 -0
- package/src/legend/components/legend-row/legend-row.test.tsx +498 -0
- package/src/legend/components/legend-row/legend-row.tsx +129 -0
- package/src/legend/components/legend-row/styles.ts +111 -0
- package/src/legend/components/legend-row-menu/legend-row-menu.tsx +68 -0
- package/src/legend/components/legend-row-menu/legend-zoom-to.tsx +35 -0
- package/src/legend/components/legend-swatch/legend-swatch.test.tsx +109 -0
- package/src/legend/components/legend-swatch/legend-swatch.tsx +237 -0
- package/src/legend/components/legend-visibility-toggle/legend-visibility-toggle.tsx +127 -0
- package/src/legend/index.ts +121 -0
- package/src/legend/provider/index.ts +6 -0
- package/src/legend/provider/labels.ts +59 -0
- package/src/legend/provider/legend-config-context.ts +15 -0
- package/src/legend/provider/legend-provider.tsx +102 -0
- package/src/legend/stores/index.ts +46 -0
- package/src/legend/stores/legend-context.ts +17 -0
- package/src/legend/stores/legend-store-registry.ts +639 -0
- package/src/legend/stores/legend-store.test.ts +457 -0
- package/src/legend/stores/selectors.ts +65 -0
- package/src/legend/stores/types.ts +347 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// ─── Internal imports (used to assemble the curated `Legend` const) ─────────
|
|
2
|
+
import { LegendProvider } from './provider/legend-provider'
|
|
3
|
+
import { LegendGroup } from './components/legend-group/legend-group'
|
|
4
|
+
import { LegendRow } from './components/legend-row/legend-row'
|
|
5
|
+
import { LegendActions } from './components/legend-actions/legend-actions'
|
|
6
|
+
import { LegendVisibilityToggle } from './components/legend-visibility-toggle/legend-visibility-toggle'
|
|
7
|
+
import { LegendRowMenu } from './components/legend-row-menu/legend-row-menu'
|
|
8
|
+
import { LegendZoomTo } from './components/legend-row-menu/legend-zoom-to'
|
|
9
|
+
import { LegendOpacity } from './components/legend-opacity/legend-opacity'
|
|
10
|
+
import { LegendConfigSelect } from './components/legend-config-select/legend-config-select'
|
|
11
|
+
import { LegendItem } from './components/legend-item/legend-item'
|
|
12
|
+
import { LegendItemUI } from './components/legend-item/legend-item-ui'
|
|
13
|
+
import { LegendSwatch } from './components/legend-swatch/legend-swatch'
|
|
14
|
+
import { LegendCategoryUI } from './components/legend-category/legend-category-ui'
|
|
15
|
+
import { LegendRampUI } from './components/legend-ramp/legend-ramp-ui'
|
|
16
|
+
import { LegendProportionUI } from './components/legend-proportion/legend-proportion-ui'
|
|
17
|
+
import { LegendIconUI } from './components/legend-icon/legend-icon-ui'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Curated namespace export — the entry point to the legend module.
|
|
21
|
+
*
|
|
22
|
+
* Composable, widgets-v2 style: the lib ships wrapper shells + standalone
|
|
23
|
+
* store-connected actions, and the **app mounts the legend** in its own
|
|
24
|
+
* chrome (panel/drawer/sidebar). `Legend.Row`/`Legend.Group` partition their
|
|
25
|
+
* children — `<Legend.Actions>` renders in the sticky header (hover-fade),
|
|
26
|
+
* everything else in the collapsible body.
|
|
27
|
+
*
|
|
28
|
+
* ```tsx
|
|
29
|
+
* import { Legend } from '@carto/ps-react-ui/legend'
|
|
30
|
+
*
|
|
31
|
+
* <Legend.Provider id='map-legend' layers={layers} groups={groups}>
|
|
32
|
+
* <Legend.Group groupId='demographics'>
|
|
33
|
+
* <Legend.Actions>
|
|
34
|
+
* <Legend.VisibilityToggle /> // tri-state group eye
|
|
35
|
+
* </Legend.Actions>
|
|
36
|
+
* <Legend.Row layerId='income'>
|
|
37
|
+
* // Actions read L→R: options · opacity · visibility
|
|
38
|
+
* <Legend.Actions>
|
|
39
|
+
* <Legend.RowMenu>
|
|
40
|
+
* <Legend.ZoomTo onZoomTo={zoomTo} />
|
|
41
|
+
* </Legend.RowMenu>
|
|
42
|
+
* <Legend.Opacity.Trigger />
|
|
43
|
+
* <Legend.VisibilityToggle /> // layer eye
|
|
44
|
+
* </Legend.Actions>
|
|
45
|
+
* <Legend.ConfigSelect />
|
|
46
|
+
* <Legend.Item />
|
|
47
|
+
* <Legend.Opacity.Popover /> // anchors to the row header
|
|
48
|
+
* </Legend.Row>
|
|
49
|
+
* </Legend.Group>
|
|
50
|
+
* </Legend.Provider>
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @experimental This API is new and may change in a future release.
|
|
54
|
+
*/
|
|
55
|
+
export const Legend = {
|
|
56
|
+
// Composition shell
|
|
57
|
+
Provider: LegendProvider,
|
|
58
|
+
Group: LegendGroup,
|
|
59
|
+
Row: LegendRow,
|
|
60
|
+
Actions: LegendActions,
|
|
61
|
+
|
|
62
|
+
// Store-connected actions & controls (context-driven)
|
|
63
|
+
VisibilityToggle: LegendVisibilityToggle,
|
|
64
|
+
RowMenu: LegendRowMenu,
|
|
65
|
+
ZoomTo: LegendZoomTo,
|
|
66
|
+
Opacity: LegendOpacity,
|
|
67
|
+
ConfigSelect: LegendConfigSelect,
|
|
68
|
+
Item: LegendItem,
|
|
69
|
+
|
|
70
|
+
// Pure UI
|
|
71
|
+
ItemUI: LegendItemUI,
|
|
72
|
+
Swatch: LegendSwatch,
|
|
73
|
+
CategoryUI: LegendCategoryUI,
|
|
74
|
+
RampUI: LegendRampUI,
|
|
75
|
+
ProportionUI: LegendProportionUI,
|
|
76
|
+
IconUI: LegendIconUI,
|
|
77
|
+
} as const
|
|
78
|
+
|
|
79
|
+
// ─── Labels ────────────────────────────────────────────────────────────────
|
|
80
|
+
// Exported separately so consumers can build customized label sets via spread.
|
|
81
|
+
export { DEFAULT_LEGEND_LABELS } from './provider'
|
|
82
|
+
|
|
83
|
+
// ─── Types ─────────────────────────────────────────────────────────────────
|
|
84
|
+
export type { LegendProviderProps, LegendLabels } from './provider'
|
|
85
|
+
export type { LegendGroupProps } from './components/legend-group/legend-group'
|
|
86
|
+
export type { LegendRowProps } from './components/legend-row/legend-row'
|
|
87
|
+
export type { LegendActionsProps } from './components/legend-actions/legend-actions'
|
|
88
|
+
export type { LegendVisibilityToggleProps } from './components/legend-visibility-toggle/legend-visibility-toggle'
|
|
89
|
+
export type { LegendRowMenuProps } from './components/legend-row-menu/legend-row-menu'
|
|
90
|
+
export type { LegendZoomToProps } from './components/legend-row-menu/legend-zoom-to'
|
|
91
|
+
export type { LegendRowContextValue } from './components/contexts'
|
|
92
|
+
export type { LegendItemUIProps } from './components/legend-item/legend-item-ui'
|
|
93
|
+
export type { LegendSwatchProps } from './components/legend-swatch/legend-swatch'
|
|
94
|
+
export type { LegendCategoryUIProps } from './components/legend-category/legend-category-ui'
|
|
95
|
+
export type { LegendRampUIProps } from './components/legend-ramp/legend-ramp-ui'
|
|
96
|
+
export type { LegendProportionUIProps } from './components/legend-proportion/legend-proportion-ui'
|
|
97
|
+
export type { LegendIconUIProps } from './components/legend-icon/legend-icon-ui'
|
|
98
|
+
|
|
99
|
+
// Store entity & variable types (re-exported for convenience; full store API
|
|
100
|
+
// lives at `@carto/ps-react-ui/legend/stores`).
|
|
101
|
+
export type {
|
|
102
|
+
LegendPosition,
|
|
103
|
+
LegendVisibility,
|
|
104
|
+
LegendOrientation,
|
|
105
|
+
LegendSwatchShape,
|
|
106
|
+
LegendFillPattern,
|
|
107
|
+
LegendStrokeStyle,
|
|
108
|
+
LegendVariable,
|
|
109
|
+
LegendCategoryItem,
|
|
110
|
+
LegendCategoryVariable,
|
|
111
|
+
LegendRampStop,
|
|
112
|
+
LegendRampVariable,
|
|
113
|
+
LegendProportionVariable,
|
|
114
|
+
LegendIconItem,
|
|
115
|
+
LegendIconVariable,
|
|
116
|
+
LegendConfigSection,
|
|
117
|
+
LegendLayer,
|
|
118
|
+
LegendGroup as LegendGroupModel,
|
|
119
|
+
LegendLayerInput,
|
|
120
|
+
LegendGroupInput,
|
|
121
|
+
} from './stores'
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { LegendProvider } from './legend-provider'
|
|
2
|
+
export type { LegendProviderProps } from './legend-provider'
|
|
3
|
+
export { LegendConfigContext, useLegendConfig } from './legend-config-context'
|
|
4
|
+
export type { LegendConfig } from './legend-config-context'
|
|
5
|
+
export { DEFAULT_LEGEND_LABELS } from './labels'
|
|
6
|
+
export type { LegendLabels } from './labels'
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every user-facing string in the legend module. Override any subset via
|
|
3
|
+
* `<Legend.Provider labels={{ … }}>` — pure `*UI` components also accept a
|
|
4
|
+
* `labels` prop directly for store-free composition.
|
|
5
|
+
*/
|
|
6
|
+
export interface LegendLabels {
|
|
7
|
+
// Layer row
|
|
8
|
+
expandLayer: string
|
|
9
|
+
collapseLayer: string
|
|
10
|
+
hideLayer: string
|
|
11
|
+
showLayer: string
|
|
12
|
+
|
|
13
|
+
// Row overflow menu
|
|
14
|
+
layerOptions: string
|
|
15
|
+
zoomTo: string
|
|
16
|
+
|
|
17
|
+
// Group
|
|
18
|
+
hideGroup: string
|
|
19
|
+
showGroup: string
|
|
20
|
+
expandGroup: string
|
|
21
|
+
collapseGroup: string
|
|
22
|
+
|
|
23
|
+
// Row controls
|
|
24
|
+
opacity: string
|
|
25
|
+
attribute: string
|
|
26
|
+
|
|
27
|
+
// Item renderers
|
|
28
|
+
radiusRangeBy: string
|
|
29
|
+
colorBasedOn: string
|
|
30
|
+
colorGradient: string
|
|
31
|
+
/** Prefix for the largest proportion break, e.g. `"MAX: "`. */
|
|
32
|
+
maxPrefix: string
|
|
33
|
+
/** Prefix for the smallest proportion break, e.g. `"MIN: "`. */
|
|
34
|
+
minPrefix: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const DEFAULT_LEGEND_LABELS: LegendLabels = {
|
|
38
|
+
expandLayer: 'Expand layer',
|
|
39
|
+
collapseLayer: 'Collapse layer',
|
|
40
|
+
hideLayer: 'Hide layer',
|
|
41
|
+
showLayer: 'Show layer',
|
|
42
|
+
|
|
43
|
+
layerOptions: 'Layer options',
|
|
44
|
+
zoomTo: 'Zoom to',
|
|
45
|
+
|
|
46
|
+
hideGroup: 'Hide group',
|
|
47
|
+
showGroup: 'Show group',
|
|
48
|
+
expandGroup: 'Expand group',
|
|
49
|
+
collapseGroup: 'Collapse group',
|
|
50
|
+
|
|
51
|
+
opacity: 'Opacity',
|
|
52
|
+
attribute: 'Attribute',
|
|
53
|
+
|
|
54
|
+
radiusRangeBy: 'Radius range by',
|
|
55
|
+
colorBasedOn: 'Color based on',
|
|
56
|
+
colorGradient: 'Color gradient',
|
|
57
|
+
maxPrefix: 'MAX: ',
|
|
58
|
+
minPrefix: 'MIN: ',
|
|
59
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react'
|
|
2
|
+
import { DEFAULT_LEGEND_LABELS, type LegendLabels } from './labels'
|
|
3
|
+
|
|
4
|
+
/** Per-panel configuration delivered by `Legend.Provider` to all containers. */
|
|
5
|
+
export interface LegendConfig {
|
|
6
|
+
labels: LegendLabels
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const LegendConfigContext = createContext<LegendConfig>({
|
|
10
|
+
labels: DEFAULT_LEGEND_LABELS,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export function useLegendConfig(): LegendConfig {
|
|
14
|
+
return useContext(LegendConfigContext)
|
|
15
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useLayoutEffect, useMemo, useState, type ReactNode } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
LegendContext,
|
|
4
|
+
createLegendStore,
|
|
5
|
+
getLegendStore,
|
|
6
|
+
hasLegendStore,
|
|
7
|
+
registerLegendStore,
|
|
8
|
+
setLegendStoreEntry,
|
|
9
|
+
unregisterLegendStore,
|
|
10
|
+
} from '../stores'
|
|
11
|
+
import type {
|
|
12
|
+
LegendGroupInput,
|
|
13
|
+
LegendLayerInput,
|
|
14
|
+
LegendStoreApi,
|
|
15
|
+
} from '../stores'
|
|
16
|
+
import { LegendConfigContext, type LegendConfig } from './legend-config-context'
|
|
17
|
+
import { DEFAULT_LEGEND_LABELS, type LegendLabels } from './labels'
|
|
18
|
+
|
|
19
|
+
export interface LegendProviderProps {
|
|
20
|
+
/** Unique id for this legend panel — keys its store. */
|
|
21
|
+
id: string
|
|
22
|
+
/**
|
|
23
|
+
* Layer definitions. Interactive fields (visible/opacity/…) are seeded.
|
|
24
|
+
* Pass stable references — `layers`, `groups`, and each layer's `variables`
|
|
25
|
+
* should be memoized or module constants (same contract as widgets-v2
|
|
26
|
+
* `data`); the store bails out of unchanged syncs by reference.
|
|
27
|
+
*/
|
|
28
|
+
layers: LegendLayerInput[]
|
|
29
|
+
/** Optional group definitions for grouping layers. */
|
|
30
|
+
groups?: LegendGroupInput[]
|
|
31
|
+
/** Override any subset of the legend's user-facing strings. */
|
|
32
|
+
labels?: Partial<LegendLabels>
|
|
33
|
+
/**
|
|
34
|
+
* When `true` (the default), the per-panel store survives unmount so
|
|
35
|
+
* visibility/opacity/order are preserved across remounts — the common case
|
|
36
|
+
* for a legend that toggles in and out of view. Consumers must call
|
|
37
|
+
* `deleteLegendStore(id)` when the legend is permanently removed. Set to
|
|
38
|
+
* `false` to tear the store down on unmount.
|
|
39
|
+
*/
|
|
40
|
+
keepAlive?: boolean
|
|
41
|
+
children: ReactNode
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Legend panel shell. Creates a per-panel Zustand store keyed by `id`, syncs
|
|
46
|
+
* the consumer's `layers`/`groups` definitions onto it (preserving interactive
|
|
47
|
+
* state), and exposes the `id` via `LegendContext` so descendants resolve their
|
|
48
|
+
* store with `useLegendId()`. Labels are surfaced via `LegendConfigContext`.
|
|
49
|
+
*
|
|
50
|
+
* Modeled on the widgets-v2 `Widget.Provider`.
|
|
51
|
+
*
|
|
52
|
+
* @experimental This API is new and may change in a future release.
|
|
53
|
+
*/
|
|
54
|
+
export function LegendProvider({
|
|
55
|
+
id,
|
|
56
|
+
layers,
|
|
57
|
+
groups,
|
|
58
|
+
labels,
|
|
59
|
+
keepAlive = true,
|
|
60
|
+
children,
|
|
61
|
+
}: LegendProviderProps) {
|
|
62
|
+
// Lazy init — reuse an existing keepAlive store, otherwise create one and
|
|
63
|
+
// synchronously place it in the registry so descendants can call
|
|
64
|
+
// useLegendStore(id, ...) on first render.
|
|
65
|
+
const [store] = useState<LegendStoreApi>(() => {
|
|
66
|
+
if (hasLegendStore(id)) return getLegendStore(id)
|
|
67
|
+
const created = createLegendStore(id, { layers, groups })
|
|
68
|
+
setLegendStoreEntry(id, created)
|
|
69
|
+
return created
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
useLayoutEffect(() => {
|
|
73
|
+
registerLegendStore(id, store)
|
|
74
|
+
return () => {
|
|
75
|
+
unregisterLegendStore(id, { keepAlive })
|
|
76
|
+
}
|
|
77
|
+
}, [id, store, keepAlive])
|
|
78
|
+
|
|
79
|
+
// Sync definitions in. The store's `_sync` preserves interactive state of
|
|
80
|
+
// known layers/groups and bails out (no state change) when the merged result
|
|
81
|
+
// is reference-identical, so stable props are a no-op.
|
|
82
|
+
useLayoutEffect(() => {
|
|
83
|
+
store.getState()._sync(layers, groups ?? [])
|
|
84
|
+
}, [store, layers, groups])
|
|
85
|
+
|
|
86
|
+
const config = useMemo<LegendConfig>(
|
|
87
|
+
() => ({
|
|
88
|
+
labels: labels
|
|
89
|
+
? { ...DEFAULT_LEGEND_LABELS, ...labels }
|
|
90
|
+
: DEFAULT_LEGEND_LABELS,
|
|
91
|
+
}),
|
|
92
|
+
[labels],
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<LegendContext.Provider value={id}>
|
|
97
|
+
<LegendConfigContext.Provider value={config}>
|
|
98
|
+
{children}
|
|
99
|
+
</LegendConfigContext.Provider>
|
|
100
|
+
</LegendContext.Provider>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
LegendPosition,
|
|
3
|
+
LegendOrientation,
|
|
4
|
+
LegendSwatchShape,
|
|
5
|
+
LegendFillPattern,
|
|
6
|
+
LegendStrokeStyle,
|
|
7
|
+
LegendCategoryItem,
|
|
8
|
+
LegendCategoryVariable,
|
|
9
|
+
LegendRampStop,
|
|
10
|
+
LegendRampVariable,
|
|
11
|
+
LegendProportionVariable,
|
|
12
|
+
LegendIconItem,
|
|
13
|
+
LegendIconVariable,
|
|
14
|
+
LegendVariable,
|
|
15
|
+
LegendConfigSection,
|
|
16
|
+
LegendLayer,
|
|
17
|
+
LegendGroup,
|
|
18
|
+
LegendLayerInput,
|
|
19
|
+
LegendGroupInput,
|
|
20
|
+
LegendState,
|
|
21
|
+
LegendStoreApi,
|
|
22
|
+
LegendInit,
|
|
23
|
+
} from './types'
|
|
24
|
+
|
|
25
|
+
export { LegendContext, useLegendId } from './legend-context'
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
createLegendStore,
|
|
29
|
+
getLegendStore,
|
|
30
|
+
hasLegendStore,
|
|
31
|
+
deleteLegendStore,
|
|
32
|
+
clearAllLegendStores,
|
|
33
|
+
setLegendStoreEntry,
|
|
34
|
+
registerLegendStore,
|
|
35
|
+
unregisterLegendStore,
|
|
36
|
+
useLegendStore,
|
|
37
|
+
useLegendShallow,
|
|
38
|
+
} from './legend-store-registry'
|
|
39
|
+
|
|
40
|
+
export type { LegendVisibility } from './selectors'
|
|
41
|
+
export {
|
|
42
|
+
selectOrderedGroups,
|
|
43
|
+
selectLayersByGroup,
|
|
44
|
+
selectOrderedLayers,
|
|
45
|
+
selectGroupVisibility,
|
|
46
|
+
} from './selectors'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
/** @experimental This API is new and may change in a future release. */
|
|
4
|
+
export const LegendContext = createContext<string | null>(null)
|
|
5
|
+
|
|
6
|
+
/** @experimental This API is new and may change in a future release. */
|
|
7
|
+
export function useLegendId(): string {
|
|
8
|
+
const id = useContext(LegendContext)
|
|
9
|
+
if (id == null) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
'useLegendId() must be called inside <Legend.Provider>. ' +
|
|
12
|
+
'If you are calling from outside the Provider tree, use the hooks ' +
|
|
13
|
+
'(useLegendStore, useLegendShallow) directly with an explicit id.',
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
return id
|
|
17
|
+
}
|