Skip to content
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions packages/base/src/formbuilder/objectform/baseform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Dialog } from '@jupyterlab/apputils';
import { Signal } from '@lumino/signaling';
import { deepCopy } from '../../tools';
import { IDict } from '../../types';
import { Slider, SliderLabel } from '@jupyter/react-components';
import { Slider } from '@jupyter/react-components';
import { SourceType } from '@jupytergis/schema';

export interface IBaseFormStates {
Expand Down Expand Up @@ -173,25 +173,66 @@ export class BaseForm extends React.Component<IBaseFormProps, IBaseFormStates> {
if (k === 'opacity') {
uiSchema[k] = {
'ui:field': (props: any) => {
const handleChange = (event: CustomEvent) => {
const [inputValue, setInputValue] = React.useState(
props.formData.toFixed(1)
);

React.useEffect(() => {
setInputValue(props.formData.toFixed(1));
}, [props.formData]);

const handleSliderChange = (event: CustomEvent) => {
const target = event.target as any;
if (target && '_value' in target) {
const value = parseFloat(target._value);
props.onChange(value);
const sliderValue = parseFloat(target._value); // Slider value is in 0–10 range
const normalizedValue = sliderValue / 10; // Normalize to 0.1–1 range
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by the 0.1 choice here? Why not the 0-1 range?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because opacity need to be a multiple of 0.1, as defined in layer schemas - https://github.com/geojupyter/jupytergis/blob/main/packages/schema/src/schema/imageLayer.json#L16

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fundamentally we might want to avoid making a layer fully transparent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with this, but no hard feeling. We can discuss that in an issue after merging this PR :)

props.onChange(normalizedValue);
}
};

const handleInputChange = (
event: React.ChangeEvent<HTMLInputElement>
) => {
const value = event.target.value;
setInputValue(value);

const parsedValue = parseFloat(value);
if (
!isNaN(parsedValue) &&
parsedValue >= 0.1 &&
parsedValue <= 1
) {
props.onChange(parsedValue);
}
};

return (
<Slider
min={0.1}
max={1}
step={0.1}
value={props.formData * 10}
onChange={handleChange}
<div
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
>
<SliderLabel position="0">0%</SliderLabel>
<SliderLabel position="100">100%</SliderLabel>
</Slider>
<Slider
min={1}
max={10}
step={1}
value={props.formData * 10}
onChange={handleSliderChange}
></Slider>
<input
type="number"
value={inputValue}
step={0.1}
min={0.1}
max={1}
onChange={handleInputChange}
style={{
width: '50px',
textAlign: 'center',
border: '1px solid #ccc',
borderRadius: '4px',
padding: '4px'
}}
/>
</div>
);
}
};
Expand Down
Loading