@defra/interactive-map 0.0.42-alpha → 0.0.43-fmp-experimental

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.
@@ -2,6 +2,7 @@ import { KeySvgPattern } from './KeySvgPattern.jsx'
2
2
  import { KeySvgSymbol } from './KeySvgSymbol.jsx'
3
3
  import { KeySvgLine } from './KeySvgLine.jsx'
4
4
  import { KeySvgRect } from './KeySvgRect.jsx'
5
+ import { KeySvgRamp } from './KeySvgRamp.jsx'
5
6
  import { symbolRegistry } from '../../registry/index.js'
6
7
 
7
8
  // Pure derivation of keyDefinition — computed directly during render (see KeyItem.jsx for why:
@@ -10,7 +11,10 @@ const getSymbolShape = (keyDefinition) => {
10
11
  if (!keyDefinition) {
11
12
  return { symbolShape: null, symbolDef: null }
12
13
  }
13
- const { hasSymbol, hasPattern, style } = keyDefinition
14
+ const { hasSymbol, hasPattern, hasRampStyleKey, style } = keyDefinition
15
+ if (hasRampStyleKey) {
16
+ return { symbolShape: 'ramp', symbolDef: null }
17
+ }
14
18
  if (hasSymbol) {
15
19
  const symbolDef = symbolRegistry.getSymbolDef(style)
16
20
  return { symbolShape: symbolDef ? 'symbol' : 'rect', symbolDef }
@@ -35,6 +39,8 @@ export const KeySvg = ({ keyDefinition, mapStyle }) => {
35
39
  return <KeySvgPattern mapStyle={mapStyle} keyDefinition={keyDefinition} />
36
40
  } else if (symbolShape === 'line') {
37
41
  return <KeySvgLine mapStyle={mapStyle} keyDefinition={keyDefinition} />
42
+ } else if (symbolShape === 'ramp') {
43
+ return <KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} />
38
44
  } else {
39
45
  return <KeySvgRect mapStyle={mapStyle} keyDefinition={keyDefinition} />
40
46
  }
@@ -21,6 +21,10 @@ jest.mock('./KeySvgRect.jsx', () => ({
21
21
  KeySvgRect: () => <svg data-testid='key-svg-rect' />
22
22
  }))
23
23
 
24
+ jest.mock('./KeySvgRamp.jsx', () => ({
25
+ KeySvgRamp: () => <svg data-testid='key-svg-ramp' />
26
+ }))
27
+
24
28
  const baseKeyDefinition = {
25
29
  hasSymbol: false,
26
30
  hasPattern: false,
@@ -86,4 +90,9 @@ describe('KeySvg', () => {
86
90
  const { container } = render(<KeySvg {...baseProps} keyDefinition={null} />)
87
91
  expect(container.firstChild).toBeNull()
88
92
  })
93
+
94
+ it('renders KeySvgRamp when hasRampStyleKey is true', () => {
95
+ const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, hasRampStyleKey: true }} />)
96
+ expect(getByTestId('key-svg-ramp')).toBeTruthy()
97
+ })
89
98
  })
@@ -0,0 +1,13 @@
1
+ import { getValueForStyle } from '../../../../../src/utils/getValueForStyle.js'
2
+
3
+ export const KeySvgRamp = ({ mapStyle, keyDefinition }) => {
4
+ const { style } = keyDefinition
5
+ const fill = getValueForStyle(style.fill, mapStyle.id)
6
+ const stroke = getValueForStyle(style.fill, mapStyle.id)
7
+
8
+ return (
9
+ <svg viewBox='0 0 5 5' preserveAspectRatio='none' fill={fill} stroke={stroke} strokeWidth='1'>
10
+ <path d='M0 0h5v5H0z' />
11
+ </svg>
12
+ )
13
+ }
@@ -0,0 +1,43 @@
1
+ import { render } from '@testing-library/react'
2
+ import { KeySvgRamp } from './KeySvgRamp'
3
+ import { getValueForStyle } from '../../../../../src/utils/getValueForStyle.js'
4
+
5
+ jest.mock('../../../../../src/utils/getValueForStyle.js', () => ({
6
+ getValueForStyle: jest.fn()
7
+ }))
8
+
9
+ const mapStyle = { id: 'outdoor' }
10
+ const keyDefinition = { style: { fill: { outdoor: '#3d9', dark: '#1a5' } } }
11
+
12
+ beforeEach(() => {
13
+ getValueForStyle.mockImplementation((value) =>
14
+ typeof value === 'object' ? value.outdoor : value
15
+ )
16
+ })
17
+
18
+ describe('KeySvgRamp', () => {
19
+ it('renders an svg element', () => {
20
+ const { container } = render(<KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} />)
21
+ expect(container.querySelector('svg')).toBeTruthy()
22
+ })
23
+
24
+ it('passes the resolved fill to the svg', () => {
25
+ const { container } = render(<KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} />)
26
+ expect(container.querySelector('svg').getAttribute('fill')).toBe('#3d9')
27
+ })
28
+
29
+ it('passes the resolved stroke to the svg', () => {
30
+ const { container } = render(<KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} />)
31
+ expect(container.querySelector('svg').getAttribute('stroke')).toBe('#3d9')
32
+ })
33
+
34
+ it('uses preserveAspectRatio none', () => {
35
+ const { container } = render(<KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} />)
36
+ expect(container.querySelector('svg').getAttribute('preserveAspectRatio')).toBe('none')
37
+ })
38
+
39
+ it('renders a path child', () => {
40
+ const { container } = render(<KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} />)
41
+ expect(container.querySelector('path')).toBeTruthy()
42
+ })
43
+ })
@@ -7,7 +7,7 @@ export const svgProps = {
7
7
  width: SVG_SIZE,
8
8
  height: SVG_SIZE,
9
9
  viewBox: `0 0 ${SVG_SIZE} ${SVG_SIZE}`,
10
- className: 'am-c-map-key-symbol',
10
+ className: 'im-c-map-key-symbol',
11
11
  'aria-hidden': 'true',
12
12
  focusable: 'false'
13
13
  }
@@ -16,5 +16,5 @@ export const svgSymbolProps = {
16
16
  ...svgProps,
17
17
  width: SVG_SYMBOL_SIZE,
18
18
  height: SVG_SYMBOL_SIZE,
19
- className: 'am-c-map-key-symbol am-c-map-key-symbol--point'
19
+ className: 'im-c-map-key-symbol im-c-map-key-symbol--point'
20
20
  }
@@ -25,7 +25,7 @@ describe('svgProps', () => {
25
25
  })
26
26
 
27
27
  it('has the correct className', () => {
28
- expect(svgProps.className).toBe('am-c-map-key-symbol')
28
+ expect(svgProps.className).toBe('im-c-map-key-symbol')
29
29
  })
30
30
 
31
31
  it('is aria-hidden', () => {
@@ -55,7 +55,7 @@ describe('svgSymbolProps', () => {
55
55
  })
56
56
 
57
57
  it('className includes the base class and a modifier', () => {
58
- expect(svgSymbolProps.className).toContain('am-c-map-key-symbol')
58
+ expect(svgSymbolProps.className).toContain('im-c-map-key-symbol')
59
59
  expect(svgSymbolProps.className).toContain('--point')
60
60
  })
61
61
  })