Skip to content

Commit

Permalink
chore(web): Slider fixes (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
jashanbhullar committed Nov 8, 2023
1 parent 6d53607 commit 801396d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 7 additions & 3 deletions web/src/beta/components/fields/SliderField/index.stories.tsx
Expand Up @@ -17,7 +17,12 @@ type Story = StoryObj<typeof SliderField>;
export const Default: Story = (args: Props) => {
const [_, updateArgs] = useArgs();

const handleChange = useCallback((value: number) => updateArgs({ value: value }), [updateArgs]);
const handleChange = useCallback(
(value: number) => {
updateArgs({ value: value });
},
[updateArgs],
);

return (
<Wrapper>
Expand Down Expand Up @@ -50,8 +55,7 @@ const Wrapper = styled.div`
display: flex;
flex-direction: column;
gap: 10%;
margin-left: 2rem;
margin-top: 2rem;
margin: 2rem;
height: 300px;
`;

Expand Down
19 changes: 17 additions & 2 deletions web/src/beta/components/fields/SliderField/index.tsx
@@ -1,3 +1,5 @@
import { useCallback, useEffect, useState } from "react";

import Property from "@reearth/beta/components/fields";
import Slider, { Props as SliderProps } from "@reearth/beta/components/Slider";

Expand All @@ -6,10 +8,23 @@ export type Props = {
description?: string;
} & SliderProps;

const SliderField: React.FC<Props> = ({ name, description, ...args }: Props) => {
const SliderField: React.FC<Props> = ({ name, description, value, onChange, ...args }: Props) => {
const [internalState, setInternalState] = useState(value);

const handleChange = useCallback(
(value: number) => {
setInternalState(value);
},
[setInternalState],
);

useEffect(() => {
setInternalState(value);
}, [value]);

return (
<Property name={name} description={description}>
<Slider {...args} />
<Slider value={internalState} onChange={handleChange} onAfterChange={onChange} {...args} />
</Property>
);
};
Expand Down

0 comments on commit 801396d

Please sign in to comment.