Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does it support reactjs Typescript? #104

Open
miskeen110 opened this issue Jan 10, 2018 · 4 comments
Open

does it support reactjs Typescript? #104

miskeen110 opened this issue Jan 10, 2018 · 4 comments

Comments

@miskeen110
Copy link

No description provided.

@nihiluis
Copy link

you can create your own type definitions or just ignore types for this lib.

@HeratPatel1
Copy link

HeratPatel1 commented Feb 12, 2018

I used it with typescript. May be it helps you.

`import * as React from 'react';
import Slider from 'react-rangeslider';

interface Props {
min?: number;
max?: number;
step?: number;
value: number;
orientation?: string;
reverse?: boolean;
tooltip?: boolean;
labels?: object;
handleLabel?: boolean;
format?: Function;
};

class SliderComponent extends React.Component<Props, any> {
constructor(props) {
super(props);
this.state = {
sliderValue: 0
};
}

componentWillMount() {
    const { value } = this.props;
    this.setState({
        sliderValue: value
    });        
}

handleOnChange = value => {
    this.setState({
        sliderValue: value,
    });        
}

handleOnChangeStart = value => {

}

handleOnChangeComplete = value => {

}

render() {
    const {
        min,
        max,
        step,
        orientation,
        tooltip,
        reverse,
        labels,
        format,
        handleLabel
    } = this.props;
    let { sliderValue } = this.state;
    return (
        <div>
            <Slider
                min={min ? min : 0}
                max={max ? max : 100}
                step={step ? step : 1}
                value={sliderValue}
                orientation={orientation ? orientation : 'horizontal'}
                reverse={reverse}
                tooltip={tooltip}
                labels={labels ? labels : null}
                handleLabel={handleLabel ? handleLabel : ''}
                format={format ? format : null}
                onChange={this.handleOnChange}
                onChangeStart={this.handleOnChangeStart}
                onChangeComplete={this.handleOnChangeComplete}
                disabled
            />
        </div>
    )
}

}

export default SliderComponent as Slider;`

@aponomy
Copy link

aponomy commented Jul 25, 2018

Try creating a index.d.ts file at /scr/@types/react-rangefinder/ with this content, it should work.

declare module 'react-rangeslider' {

	export interface SliderProps {
		min?: number;
		max?: number;
		step?: number;
		value: number;
		orientation?: string;
		reverse?: boolean;
		tooltip?: boolean;
		labels?: object;
		handleLabel?: boolean;
		format?: Function;
		onChange?(value:number):void;
		onChangeStart?(value:number):void;
		onChangeComplete?(value:number):void;
		disabled?:boolean
	}

	export default class Slider extends React.Component<SliderProps> {
	}
}

@RichieRock
Copy link

FYI, I created types to DefinitelyTyped for this package. Slightly modified @aponomy's types and made a pull request: DefinitelyTyped/DefinitelyTyped#31721

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants