• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geostyler / geostyler / 21512925066

30 Jan 2026 10:37AM UTC coverage: 57.143% (-0.07%) from 57.213%
21512925066

push

github

jansule
feat(TextEditor): introduce placement and repeat fields

923 of 1971 branches covered (46.83%)

Branch coverage included in aggregate %.

8 of 20 new or added lines in 3 files covered. (40.0%)

3 existing lines in 1 file now uncovered.

2097 of 3314 relevant lines covered (63.28%)

23.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.19
/src/Component/ExpressionInput/NumberExpressionInput/NumberExpressionInput.tsx
1
/* Released under the BSD 2-Clause License
2
 *
3
 * Copyright © 2023-present, terrestris GmbH & Co. KG and GeoStyler contributors
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice,
10
 *   this list of conditions and the following disclaimer.
11
 *
12
 * * Redistributions in binary form must reproduce the above copyright notice,
13
 *   this list of conditions and the following disclaimer in the documentation
14
 *   and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
 * POSSIBILITY OF SUCH DAMAGE.
27
 */
28

29
import React, { useEffect, useState } from 'react';
30

31
import {
32
  Button,
33
  Slider,
34
  InputNumber,
35
} from 'antd';
36
import { InputNumberProps } from 'antd/lib/input-number';
37
import { FunctionUI, FunctionUIProps } from '../../FunctionUI/FunctionUI';
38
import {
39
  Expression,
40
  GeoStylerNumberFunction,
41
  isGeoStylerFunction
42
} from 'geostyler-style';
43
import { FunctionOutlined } from '@ant-design/icons';
44

45
import './NumberExpressionInput.css';
46

47
type SliderProps = {
48
  min?: number;
49
  max?: number;
50
  step?: number;
51
};
52
export interface NumberExpressionInputProps {
53
  className?: string;
54
  slider?: boolean;
55
  sliderProps?: SliderProps;
56
  functionUiProps?: FunctionUIProps<GeoStylerNumberFunction>;
57
  inputProps?: Omit<InputNumberProps, 'value' | 'onChange' | 'className'>;
58
  onCancel?: (type: 'number') => void;
59
  onChange?: (newValue: Expression<number> | undefined) => void;
60
  value?: Expression<number>;
61
}
62

63
export const NumberExpressionInput: React.FC<NumberExpressionInputProps> = ({
44✔
64
  slider = false,
298✔
65
  sliderProps = {}, /* more safety */
298✔
66
  onChange,
67
  onCancel,
68
  value,
69
  className,
70
  inputProps = {},  /* more safety */
165✔
71
  functionUiProps
72
}) => {
73
  let finalClassName = 'number-expression-input';
460✔
74
  if (className) {
460✔
75
    finalClassName += ` ${className}`;
454✔
76
  }
77

78
  const [inputValue, setInputValue] = useState<number>(() => {
460✔
79
    return isGeoStylerFunction(value) ? undefined : value;
424✔
80
  });
81

82
  useEffect(() => {
460✔
83
    if (!isGeoStylerFunction(value)) {
426✔
84
      setInputValue(value);
425✔
85
    }
86
  }, [value]);
87

88
  if (isGeoStylerFunction(value)) {
460✔
89
    return (
1✔
90
      <span className={finalClassName}>
91
        <FunctionUI<GeoStylerNumberFunction>
92
          type='number'
93
          value={value}
94
          {...functionUiProps}
95
          onChange={onChange}
96
          onCancel={() => onCancel?.('number')}
×
97
        />
98
      </span>
99
    );
100
  }
101

102
  return (
459✔
103
    <span className={finalClassName}>
104
      {slider ? (
459✔
105
        <div className={'slider-wrapper'}>
106
          <Slider
107
            {...sliderProps}
108
            value={inputValue}
109
            range={false}
110
            onChange={(val) => {
111
              const castVal = val === null ? undefined : Number(val);
×
112
              onChange?.(castVal);
×
UNCOV
113
              setInputValue(castVal);
×
114
            }}
115
          />
116
          <div className={'number-wrapper'}>
117
            <InputNumber
118
              {...sliderProps}
119
              value={inputValue}
120
              onChange={(val) => {
121
                const castVal = val === null ? undefined : Number(val);
12!
122
                onChange?.(castVal);
12✔
123
                setInputValue(castVal);
12✔
124
              }}
125
            />
126
            <Button
127
              icon={<FunctionOutlined />}
128
              onClick={() => {
UNCOV
129
                onChange?.({
×
130
                  name: 'property',
131
                  args: ['']
132
                });
133
              }}
134
            />
135
          </div>
136
        </div>
137
      ) : (
138
        <>
139
          <InputNumber
140
            value={value}
141
            onChange={(val) => {
142
              const castVal = val === null ? undefined : Number(val);
28!
143
              onChange?.(castVal);
28✔
144
            }}
145
            {...inputProps}
146
          />
147
          <Button
148
            icon={<FunctionOutlined />}
149
            onClick={() => {
UNCOV
150
              onChange?.({
×
151
                name: 'property',
152
                args: ['']
153
              });
154
            }}
155
          />
156
        </>
157

158
      )}
159
    </span>
160
  );
161
};
162

163
export default NumberExpressionInput;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc