zds-pickers 4.0.21 → 4.0.22

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.
@@ -32,38 +32,20 @@ const RESPONSE_CURVE_4 = 4;
32
32
  const RESPONSE_CURVE_5 = 5;
33
33
  const RESPONSE_CURVE_6 = 6;
34
34
  const RESPONSE_CURVE_7 = 7;
35
- const responseCurves = [
36
- {
37
- value: RESPONSE_CURVE_7,
38
- label: 'Always maxed out.',
39
- },
40
- {
41
- value: RESPONSE_CURVE_6,
42
- label: 'Most sensitive.',
43
- },
44
- {
45
- value: RESPONSE_CURVE_5,
46
- label: 'Moderately sensitive.',
47
- },
48
- {
49
- value: RESPONSE_CURVE_4,
50
- label: 'A little sensitive.',
51
- },
52
- {
53
- value: RESPONSE_CURVE_0,
54
- label: 'Linear, no change.',
55
- },
56
- {
57
- value: RESPONSE_CURVE_1,
58
- label: 'A little less sensitive.',
59
- },
60
- {
61
- value: RESPONSE_CURVE_2,
62
- label: 'Even less sensitive.',
63
- },
64
- {
65
- value: RESPONSE_CURVE_3,
66
- label: 'Least sensitive.',
67
- },
68
- ];
69
- export { combineStatusWithChannel, extractStatusAndChannel, getStatusLabel, MASK_CHANNEL, MASK_STATUS, responseCurves, Statuses, statusOptions, };
35
+ const ResponseCurveLabels = {
36
+ [RESPONSE_CURVE_0]: 'Linear, no change',
37
+ [RESPONSE_CURVE_1]: 'A little less sensitive',
38
+ [RESPONSE_CURVE_2]: 'Even less sensitive',
39
+ [RESPONSE_CURVE_3]: 'Least sensitive',
40
+ [RESPONSE_CURVE_4]: 'A little sensitive',
41
+ [RESPONSE_CURVE_5]: 'Moderately sensitive',
42
+ [RESPONSE_CURVE_6]: 'Most sensitive',
43
+ [RESPONSE_CURVE_7]: 'Always maxed out',
44
+ };
45
+ const responseCurves = Object.keys(ResponseCurveLabels)
46
+ .map(Number)
47
+ .map(key => ({
48
+ value: key,
49
+ label: ResponseCurveLabels[key],
50
+ }));
51
+ export { combineStatusWithChannel, extractStatusAndChannel, getStatusLabel, MASK_CHANNEL, MASK_STATUS, responseCurves, ResponseCurveLabels, Statuses, statusOptions, };
@@ -1,8 +1,8 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import cl from 'classnames';
3
3
  import { forwardRef, useCallback, useEffect, useState } from 'react';
4
4
  import { arraySequence } from '../utils';
5
- import { Select } from './Select';
5
+ import { Select, noSelection } from './Select';
6
6
  const defaultOptions = arraySequence(16).map(value => ({
7
7
  value,
8
8
  label: value,
@@ -16,7 +16,7 @@ const ChannelMappingPicker = forwardRef(({ channels, className, ...rest }, ref)
16
16
  if (typeof value !== 'number')
17
17
  return null;
18
18
  const mapping = channels[value];
19
- return mapping ? (_jsxs("span", { className: "mapping-entry", children: [_jsxs("b", { children: [value + 1, context === 'value' && ' -'] }), _jsx("span", { className: "mapping-entry-label", children: mapping.label })] })) : (_jsxs("span", { className: "mapping-entry empty-mapping-entry", children: [_jsxs("b", { children: [value + 1, context === 'value' && ' -'] }), _jsx("span", { className: "mapping-entry-label", children: "no mapping" })] }));
19
+ return mapping ? (_jsxs("span", { className: "mapping-entry", children: [_jsx("b", { children: value !== noSelection && (_jsxs(_Fragment, { children: [value + 1, context === 'value' && ' -'] })) }), _jsx("span", { className: "mapping-entry-label", children: mapping.label })] })) : (_jsxs("span", { className: "mapping-entry empty-mapping-entry", children: [_jsx("b", { children: value !== noSelection && (_jsxs(_Fragment, { children: [value + 1, context === 'value' && ' -'] })) }), _jsx("span", { className: "mapping-entry-label", children: "no mapping" })] }));
20
20
  }, [channels]);
21
21
  useEffect(() => {
22
22
  const result = defaultOptions.sort((a, b) => {
@@ -37,7 +37,8 @@ const ChannelMappingPicker = forwardRef(({ channels, className, ...rest }, ref)
37
37
  }
38
38
  return 0;
39
39
  });
40
- const numFilled = result.filter(({ value }) => typeof value === 'number' && !!channels[value]).length;
40
+ const numFilled = result.filter(({ value }) => (typeof value === 'number' && !!channels[value]) ||
41
+ value === noSelection).length;
41
42
  const separatorExists = result.some(({ value }) => value === 'separator');
42
43
  if (numFilled && numFilled < 16 && !separatorExists) {
43
44
  // insert a separator after the count of filled items
@@ -1,13 +1,13 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import cl from 'classnames';
3
- import { forwardRef } from 'react';
3
+ import { forwardRef, useCallback } from 'react';
4
4
  import { arraySequence } from '../utils';
5
5
  import { Select } from './Select';
6
+ import { noSelection } from './Select';
6
7
  const options = arraySequence(16).map(value => ({
7
8
  value: value,
8
9
  label: `Channel ${value + 1}`,
9
10
  }));
10
- const formatOptionLabel = (option, { context }) => context === 'value' ? option.label : Number.parseInt(String(option.value)) + 1; // menu, e.g. the list of options
11
11
  const filterOptions = (option, input) => {
12
12
  // console.log(option, input)
13
13
  if (input) {
@@ -15,9 +15,15 @@ const filterOptions = (option, input) => {
15
15
  }
16
16
  return true;
17
17
  };
18
- const ChannelPicker = forwardRef(({ className, value = undefined, ...rest }, ref) => {
19
- return (_jsx(Select, { ...rest, className: cl(className, 'channel-picker'), filterOptions: filterOptions, formatOptionLabel: formatOptionLabel, options: value === undefined
20
- ? [...options, { value: undefined, label: '--' }]
21
- : options, value: value, ref: ref }));
18
+ const ChannelPicker = forwardRef(({ className, value = noSelection, ...rest }, ref) => {
19
+ const formatOptionLabel = useCallback((option, { context }) => {
20
+ if (value === undefined) {
21
+ return '--';
22
+ }
23
+ return context === 'value'
24
+ ? option.label
25
+ : Number.parseInt(String(option.value)) + 1; // menu, e.g. the list of options
26
+ }, [value]);
27
+ return (_jsx(Select, { ...rest, className: cl(className, 'channel-picker'), filterOptions: filterOptions, formatOptionLabel: formatOptionLabel, options: options, value: value, ref: ref }));
22
28
  });
23
29
  export { ChannelPicker };
@@ -34,48 +34,48 @@ const ResponseCurve = (props) => {
34
34
  let labelX = xMid;
35
35
  let labelY = yMid;
36
36
  switch (value) {
37
- case responseCurves[0].value:
37
+ case 0:
38
38
  c1 = xMid;
39
39
  c2 = yMid;
40
40
  labelY += 3;
41
41
  break;
42
- case responseCurves[1].value:
42
+ case 1:
43
43
  c1 = inverted ? xMid + width * 0.13 : xMid - width * 0.13;
44
44
  c2 = yMid - height * 0.13;
45
45
  labelX = inverted ? xMid + width * 0.1 : xMid - width * 0.1;
46
46
  labelY = yMid - height * 0.09;
47
47
  break;
48
- case responseCurves[2].value:
48
+ case 2:
49
49
  c1 = inverted ? xMid + width * 0.25 : xMid - width * 0.25;
50
50
  c2 = yMid - height * 0.25;
51
51
  labelX = inverted ? xMid + width * 0.2 : xMid - width * 0.2;
52
52
  labelY = yMid - height * 0.17;
53
53
  break;
54
- case responseCurves[3].value:
54
+ case 3:
55
55
  c1 = inverted ? xMid + width * 0.35 : xMid - width * 0.35;
56
56
  c2 = yMid - height * 0.35;
57
57
  labelX = inverted ? xMid + width * 0.28 : xMid - width * 0.28;
58
58
  labelY = yMid - height * 0.25;
59
59
  break;
60
- case responseCurves[4].value:
60
+ case 4:
61
61
  c1 = inverted ? xMid - width * 0.13 : xMid + width * 0.13;
62
62
  c2 = yMid + height * 0.13;
63
63
  labelX = inverted ? xMid - width * 0.1 : xMid + width * 0.1;
64
64
  labelY = yMid + height * 0.1;
65
65
  break;
66
- case responseCurves[5].value:
66
+ case 5:
67
67
  c1 = inverted ? xMid - width * 0.25 : xMid + width * 0.25;
68
68
  c2 = yMid + height * 0.25;
69
69
  labelX = inverted ? xMid - width * 0.2 : xMid + width * 0.2;
70
70
  labelY = yMid + height * 0.18;
71
71
  break;
72
- case responseCurves[6].value:
72
+ case 6:
73
73
  c1 = inverted ? xMid - width * 0.35 : xMid + width * 0.35;
74
74
  c2 = yMid + height * 0.35;
75
75
  labelX = inverted ? xMid - width * 0.28 : xMid + width * 0.28;
76
76
  labelY = yMid + height * 0.25;
77
77
  break;
78
- case responseCurves[7].value:
78
+ case 7:
79
79
  x1 = inverted ? axisX1 : axisX2;
80
80
  y1 = axisY1;
81
81
  x2 = x1;
@@ -7,7 +7,10 @@ import { ResponseCurve } from './ResponseCurve';
7
7
  import { Select } from './Select';
8
8
  const ResponseCurvePicker = forwardRef((props, ref) => {
9
9
  const { Tooltip = DefaultTooltip, inverted = false, onChange, value, ...rest } = props;
10
- const Placeholder = useCallback(() => (_jsx("div", { className: "singleValue", children: findObj('value', value)(responseCurves)?.label })), [value]);
10
+ const Placeholder = useCallback(() => {
11
+ const option = findObj('value', value)(responseCurves);
12
+ return option ? (_jsx("div", { className: "singleValue", children: option.label })) : (_jsx("div", { className: "zds-pickers__placeholder", children: "Select..." }));
13
+ }, [value]);
11
14
  const MenuList = useCallback(({ setValue }) => (_jsx(ResponseCurve, { autosize: true, inverted: inverted, onChange: ({ target: { value: v } }) => {
12
15
  setValue(v);
13
16
  onChange(v);
@@ -2,7 +2,12 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Children, forwardRef, isValidElement, useCallback, useMemo, } from 'react';
3
3
  import ReactSelect, { components as originalComponents, } from 'react-select';
4
4
  import { omit } from '../utils';
5
+ const noSelection = 255;
5
6
  const { IndicatorsContainer, Placeholder, ValueContainer } = originalComponents;
7
+ const noSelectionOption = {
8
+ label: '--',
9
+ value: noSelection,
10
+ };
6
11
  const CustomIndicatorsContainer = (props) => {
7
12
  const { children, ...rest } = props;
8
13
  const actionButton = rest.selectProps?.actionButton;
@@ -77,4 +82,4 @@ const Select = forwardRef((props, ref) => {
77
82
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
78
83
  ref: ref, styles: styles, value: selectedOption })] }));
79
84
  });
80
- export { Select };
85
+ export { noSelection, noSelectionOption, Select };
@@ -1,4 +1,4 @@
1
- import type { Option } from 'lib/pickers/Select';
1
+ import type { Option, noSelection } from 'lib/pickers/Select';
2
2
  declare const Statuses: {
3
3
  readonly noteOff: 8;
4
4
  readonly noteOn: 9;
@@ -18,15 +18,17 @@ declare const extractStatusAndChannel: (status: number) => {
18
18
  status: Status;
19
19
  channel: number;
20
20
  };
21
- declare const RESPONSE_CURVE_0 = 0;
22
- declare const RESPONSE_CURVE_1 = 1;
23
- declare const RESPONSE_CURVE_2 = 2;
24
- declare const RESPONSE_CURVE_3 = 3;
25
- declare const RESPONSE_CURVE_4 = 4;
26
- declare const RESPONSE_CURVE_5 = 5;
27
- declare const RESPONSE_CURVE_6 = 6;
28
- declare const RESPONSE_CURVE_7 = 7;
29
- type Curve = typeof RESPONSE_CURVE_0 | typeof RESPONSE_CURVE_1 | typeof RESPONSE_CURVE_2 | typeof RESPONSE_CURVE_3 | typeof RESPONSE_CURVE_4 | typeof RESPONSE_CURVE_5 | typeof RESPONSE_CURVE_6 | typeof RESPONSE_CURVE_7;
21
+ declare const ResponseCurveLabels: {
22
+ readonly 0: "Linear, no change";
23
+ readonly 1: "A little less sensitive";
24
+ readonly 2: "Even less sensitive";
25
+ readonly 3: "Least sensitive";
26
+ readonly 4: "A little sensitive";
27
+ readonly 5: "Moderately sensitive";
28
+ readonly 6: "Most sensitive";
29
+ readonly 7: "Always maxed out";
30
+ };
31
+ type Curve = keyof typeof ResponseCurveLabels | typeof noSelection;
30
32
  declare const responseCurves: Option<Curve>[];
31
- export { combineStatusWithChannel, extractStatusAndChannel, getStatusLabel, MASK_CHANNEL, MASK_STATUS, responseCurves, Statuses, statusOptions, };
33
+ export { combineStatusWithChannel, extractStatusAndChannel, getStatusLabel, MASK_CHANNEL, MASK_STATUS, responseCurves, ResponseCurveLabels, Statuses, statusOptions, };
32
34
  export type { Curve, Status };
@@ -1,6 +1,6 @@
1
1
  import type { GroupBase, SelectInstance } from 'react-select';
2
- import type { Option, SelectProps } from './Select';
3
- type Channel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | undefined;
2
+ import { type Option, type SelectProps, noSelection } from './Select';
3
+ type Channel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | typeof noSelection;
4
4
  type ChannelPickerProps = Omit<SelectProps<Channel>, 'options'>;
5
5
  type ChannelPickerRef = SelectInstance<Option<Channel>, false, GroupBase<Option<Channel>>>;
6
6
  declare const ChannelPicker: import("react").ForwardRefExoticComponent<ChannelPickerProps & import("react").RefAttributes<SelectInstance<Option<Channel>, false, GroupBase<Option<Channel>>>>>;
@@ -1,6 +1,6 @@
1
1
  import type { GroupBase, SelectInstance } from 'react-select';
2
- import type { Option, SelectProps } from './Select';
3
- type Polarity = 0 | 1;
2
+ import type { Option, SelectProps, noSelection } from './Select';
3
+ type Polarity = 0 | 1 | typeof noSelection;
4
4
  type PolarityPickerProps = Omit<SelectProps<Polarity>, 'options'> & {
5
5
  labelOff?: string;
6
6
  labelOn?: string;
@@ -1,5 +1,6 @@
1
1
  import { type JSX } from 'react';
2
2
  import { type GroupBase, type SelectComponentsConfig, type SelectInstance } from 'react-select';
3
+ declare const noSelection = 255;
3
4
  type PassedSelectProps = {
4
5
  actionButton?: React.ReactNode;
5
6
  inputValue?: string;
@@ -9,6 +10,7 @@ type Option<T> = {
9
10
  label: React.ReactNode;
10
11
  value: T;
11
12
  };
13
+ declare const noSelectionOption: Option<number>;
12
14
  type SelectProps<T> = SelectComponentsConfig<Option<T>, false, GroupBase<Option<T>>> & {
13
15
  actionButton?: React.ReactNode;
14
16
  className?: string;
@@ -35,5 +37,5 @@ type SelectProps<T> = SelectComponentsConfig<Option<T>, false, GroupBase<Option<
35
37
  declare const Select: <T>(props: SelectProps<T> & {
36
38
  ref?: React.ForwardedRef<SelectInstance<Option<T>, false, GroupBase<Option<T>>>>;
37
39
  }) => JSX.Element;
38
- export { Select };
40
+ export { noSelection, noSelectionOption, Select };
39
41
  export type { Option, SelectProps };
@@ -1,4 +1,4 @@
1
- import type { Option } from 'lib/pickers/Select'
1
+ import type { Option, noSelection } from 'lib/pickers/Select'
2
2
 
3
3
  const Statuses = {
4
4
  noteOff: 8, // 1000
@@ -51,50 +51,27 @@ const RESPONSE_CURVE_5 = 5
51
51
  const RESPONSE_CURVE_6 = 6
52
52
  const RESPONSE_CURVE_7 = 7
53
53
 
54
- type Curve =
55
- | typeof RESPONSE_CURVE_0
56
- | typeof RESPONSE_CURVE_1
57
- | typeof RESPONSE_CURVE_2
58
- | typeof RESPONSE_CURVE_3
59
- | typeof RESPONSE_CURVE_4
60
- | typeof RESPONSE_CURVE_5
61
- | typeof RESPONSE_CURVE_6
62
- | typeof RESPONSE_CURVE_7
54
+ const ResponseCurveLabels = {
55
+ [RESPONSE_CURVE_0]: 'Linear, no change',
56
+ [RESPONSE_CURVE_1]: 'A little less sensitive',
57
+ [RESPONSE_CURVE_2]: 'Even less sensitive',
58
+ [RESPONSE_CURVE_3]: 'Least sensitive',
59
+ [RESPONSE_CURVE_4]: 'A little sensitive',
60
+ [RESPONSE_CURVE_5]: 'Moderately sensitive',
61
+ [RESPONSE_CURVE_6]: 'Most sensitive',
62
+ [RESPONSE_CURVE_7]: 'Always maxed out',
63
+ } as const
63
64
 
64
- const responseCurves: Option<Curve>[] = [
65
- {
66
- value: RESPONSE_CURVE_7,
67
- label: 'Always maxed out.',
68
- },
69
- {
70
- value: RESPONSE_CURVE_6,
71
- label: 'Most sensitive.',
72
- },
73
- {
74
- value: RESPONSE_CURVE_5,
75
- label: 'Moderately sensitive.',
76
- },
77
- {
78
- value: RESPONSE_CURVE_4,
79
- label: 'A little sensitive.',
80
- },
81
- {
82
- value: RESPONSE_CURVE_0,
83
- label: 'Linear, no change.',
84
- },
85
- {
86
- value: RESPONSE_CURVE_1,
87
- label: 'A little less sensitive.',
88
- },
89
- {
90
- value: RESPONSE_CURVE_2,
91
- label: 'Even less sensitive.',
92
- },
93
- {
94
- value: RESPONSE_CURVE_3,
95
- label: 'Least sensitive.',
96
- },
97
- ]
65
+ // type Curve = (typeof Items)[keyof typeof Items]
66
+
67
+ type Curve = keyof typeof ResponseCurveLabels | typeof noSelection
68
+
69
+ const responseCurves: Option<Curve>[] = Object.keys(ResponseCurveLabels)
70
+ .map(Number)
71
+ .map(key => ({
72
+ value: key as Curve,
73
+ label: ResponseCurveLabels[key as keyof typeof ResponseCurveLabels],
74
+ }))
98
75
 
99
76
  export {
100
77
  combineStatusWithChannel,
@@ -103,6 +80,7 @@ export {
103
80
  MASK_CHANNEL,
104
81
  MASK_STATUS,
105
82
  responseCurves,
83
+ ResponseCurveLabels,
106
84
  Statuses,
107
85
  statusOptions,
108
86
  }
@@ -2,7 +2,7 @@ import cl from 'classnames'
2
2
  import { forwardRef, useCallback, useEffect, useState } from 'react'
3
3
  import type { GroupBase, SelectInstance } from 'react-select'
4
4
  import { arraySequence } from '../utils'
5
- import { Select } from './Select'
5
+ import { Select, noSelection } from './Select'
6
6
  import type { Option, SelectProps } from './Select'
7
7
 
8
8
  type InternalValue = number | 'separator'
@@ -60,16 +60,24 @@ const ChannelMappingPicker = forwardRef<
60
60
  return mapping ? (
61
61
  <span className="mapping-entry">
62
62
  <b>
63
- {value + 1}
64
- {context === 'value' && ' -'}
63
+ {value !== noSelection && (
64
+ <>
65
+ {value + 1}
66
+ {context === 'value' && ' -'}
67
+ </>
68
+ )}
65
69
  </b>
66
70
  <span className="mapping-entry-label">{mapping.label}</span>
67
71
  </span>
68
72
  ) : (
69
73
  <span className="mapping-entry empty-mapping-entry">
70
74
  <b>
71
- {value + 1}
72
- {context === 'value' && ' -'}
75
+ {value !== noSelection && (
76
+ <>
77
+ {value + 1}
78
+ {context === 'value' && ' -'}
79
+ </>
80
+ )}
73
81
  </b>
74
82
  <span className="mapping-entry-label">no mapping</span>
75
83
  </span>
@@ -107,7 +115,9 @@ const ChannelMappingPicker = forwardRef<
107
115
  )
108
116
 
109
117
  const numFilled = result.filter(
110
- ({ value }) => typeof value === 'number' && !!channels[value],
118
+ ({ value }) =>
119
+ (typeof value === 'number' && !!channels[value]) ||
120
+ value === noSelection,
111
121
  ).length
112
122
 
113
123
  const separatorExists = result.some(({ value }) => value === 'separator')
@@ -1,9 +1,9 @@
1
1
  import cl from 'classnames'
2
- import { forwardRef } from 'react'
2
+ import { forwardRef, useCallback } from 'react'
3
3
  import type { GroupBase, SelectInstance } from 'react-select'
4
4
  import { arraySequence } from '../utils'
5
5
  import { Select } from './Select'
6
- import type { Option, SelectProps } from './Select'
6
+ import { type Option, type SelectProps, noSelection } from './Select'
7
7
 
8
8
  type Channel =
9
9
  | 0
@@ -22,7 +22,7 @@ type Channel =
22
22
  | 13
23
23
  | 14
24
24
  | 15
25
- | undefined
25
+ | typeof noSelection
26
26
 
27
27
  interface FormatOptionLabelContext {
28
28
  context: 'menu' | 'value'
@@ -41,12 +41,6 @@ const options: Option<Channel>[] = arraySequence(16).map(value => ({
41
41
  label: `Channel ${value + 1}`,
42
42
  }))
43
43
 
44
- const formatOptionLabel = (
45
- option: Option<unknown>,
46
- { context }: FormatOptionLabelContext,
47
- ) =>
48
- context === 'value' ? option.label : Number.parseInt(String(option.value)) + 1 // menu, e.g. the list of options
49
-
50
44
  const filterOptions = (option: Option<Channel>, input: string) => {
51
45
  // console.log(option, input)
52
46
 
@@ -59,18 +53,26 @@ const filterOptions = (option: Option<Channel>, input: string) => {
59
53
  const ChannelPicker = forwardRef<
60
54
  SelectInstance<Option<Channel>, false, GroupBase<Option<Channel>>>,
61
55
  ChannelPickerProps
62
- >(({ className, value = undefined, ...rest }, ref) => {
56
+ >(({ className, value = noSelection, ...rest }, ref) => {
57
+ const formatOptionLabel = useCallback(
58
+ (option: Option<unknown>, { context }: FormatOptionLabelContext) => {
59
+ if (value === undefined) {
60
+ return '--'
61
+ }
62
+ return context === 'value'
63
+ ? option.label
64
+ : Number.parseInt(String(option.value)) + 1 // menu, e.g. the list of options
65
+ },
66
+ [value],
67
+ )
68
+
63
69
  return (
64
70
  <Select
65
71
  {...rest}
66
72
  className={cl(className, 'channel-picker')}
67
73
  filterOptions={filterOptions}
68
74
  formatOptionLabel={formatOptionLabel}
69
- options={
70
- value === undefined
71
- ? [...options, { value: undefined, label: '--' }]
72
- : options
73
- }
75
+ options={options}
74
76
  value={value}
75
77
  ref={ref}
76
78
  />
@@ -1,9 +1,9 @@
1
1
  import { forwardRef } from 'react'
2
2
  import type { GroupBase, SelectInstance } from 'react-select'
3
3
  import { Select } from './Select'
4
- import type { Option, SelectProps } from './Select'
4
+ import type { Option, SelectProps, noSelection } from './Select'
5
5
 
6
- type Polarity = 0 | 1
6
+ type Polarity = 0 | 1 | typeof noSelection
7
7
 
8
8
  type PolarityPickerProps = Omit<SelectProps<Polarity>, 'options'> & {
9
9
  labelOff?: string
@@ -74,55 +74,55 @@ const ResponseCurve = (props: ResponseCurveProps) => {
74
74
  let labelX = xMid
75
75
  let labelY = yMid
76
76
  switch (value) {
77
- case responseCurves[0].value:
77
+ case 0:
78
78
  c1 = xMid
79
79
  c2 = yMid
80
80
  labelY += 3
81
81
 
82
82
  break
83
- case responseCurves[1].value:
83
+ case 1:
84
84
  c1 = inverted ? xMid + width * 0.13 : xMid - width * 0.13
85
85
  c2 = yMid - height * 0.13
86
86
  labelX = inverted ? xMid + width * 0.1 : xMid - width * 0.1
87
87
  labelY = yMid - height * 0.09
88
88
  break
89
89
 
90
- case responseCurves[2].value:
90
+ case 2:
91
91
  c1 = inverted ? xMid + width * 0.25 : xMid - width * 0.25
92
92
  c2 = yMid - height * 0.25
93
93
  labelX = inverted ? xMid + width * 0.2 : xMid - width * 0.2
94
94
  labelY = yMid - height * 0.17
95
95
  break
96
96
 
97
- case responseCurves[3].value:
97
+ case 3:
98
98
  c1 = inverted ? xMid + width * 0.35 : xMid - width * 0.35
99
99
  c2 = yMid - height * 0.35
100
100
  labelX = inverted ? xMid + width * 0.28 : xMid - width * 0.28
101
101
  labelY = yMid - height * 0.25
102
102
  break
103
103
 
104
- case responseCurves[4].value:
104
+ case 4:
105
105
  c1 = inverted ? xMid - width * 0.13 : xMid + width * 0.13
106
106
  c2 = yMid + height * 0.13
107
107
  labelX = inverted ? xMid - width * 0.1 : xMid + width * 0.1
108
108
  labelY = yMid + height * 0.1
109
109
  break
110
110
 
111
- case responseCurves[5].value:
111
+ case 5:
112
112
  c1 = inverted ? xMid - width * 0.25 : xMid + width * 0.25
113
113
  c2 = yMid + height * 0.25
114
114
  labelX = inverted ? xMid - width * 0.2 : xMid + width * 0.2
115
115
  labelY = yMid + height * 0.18
116
116
  break
117
117
 
118
- case responseCurves[6].value:
118
+ case 6:
119
119
  c1 = inverted ? xMid - width * 0.35 : xMid + width * 0.35
120
120
  c2 = yMid + height * 0.35
121
121
  labelX = inverted ? xMid - width * 0.28 : xMid + width * 0.28
122
122
  labelY = yMid + height * 0.25
123
123
  break
124
124
 
125
- case responseCurves[7].value:
125
+ case 7:
126
126
  x1 = inverted ? axisX1 : axisX2
127
127
  y1 = axisY1
128
128
  x2 = x1
@@ -30,14 +30,14 @@ const ResponseCurvePicker = forwardRef<
30
30
  ...rest
31
31
  } = props
32
32
 
33
- const Placeholder = useCallback(
34
- () => (
35
- <div className="singleValue">
36
- {(findObj('value', value)(responseCurves) as Option<Curve>)?.label}
37
- </div>
38
- ),
39
- [value],
40
- )
33
+ const Placeholder = useCallback(() => {
34
+ const option = findObj('value', value)(responseCurves) as Option<Curve>
35
+ return option ? (
36
+ <div className="singleValue">{option.label}</div>
37
+ ) : (
38
+ <div className="zds-pickers__placeholder">Select...</div>
39
+ )
40
+ }, [value])
41
41
 
42
42
  const MenuList = useCallback(
43
43
  ({ setValue }: { setValue: (v: Curve) => void }) => (
@@ -19,6 +19,8 @@ import ReactSelect, {
19
19
  } from 'react-select'
20
20
  import { omit } from '../utils'
21
21
 
22
+ const noSelection = 255
23
+
22
24
  const { IndicatorsContainer, Placeholder, ValueContainer } = originalComponents
23
25
 
24
26
  type PassedSelectProps = {
@@ -32,6 +34,11 @@ type Option<T> = {
32
34
  value: T
33
35
  }
34
36
 
37
+ const noSelectionOption: Option<number> = {
38
+ label: '--',
39
+ value: noSelection,
40
+ }
41
+
35
42
  interface CustomIndicatorsContainerProps<T>
36
43
  extends Omit<IndicatorsContainerProps<Option<T>, false>, 'selectProps'> {
37
44
  children: React.ReactNode
@@ -256,6 +263,6 @@ const Select = forwardRef(
256
263
  },
257
264
  ) => JSX.Element
258
265
 
259
- export { Select }
266
+ export { noSelection, noSelectionOption, Select }
260
267
 
261
268
  export type { Option, SelectProps }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zds-pickers",
3
- "version": "4.0.21",
3
+ "version": "4.0.22",
4
4
  "main": "./dist/index.cjs.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "types": "./dist/types/index.d.ts",