Download wp-calypso/client/components/forms/form-range/index.jsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/forms/form-range/index.jsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/components/forms/form-range/index.jsx
-
curl -L -o index.jsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/forms/form-range/index.jsx
1.29 kB
| import clsx from 'clsx'; | |
| import { omit } from 'lodash'; | |
| import PropTypes from 'prop-types'; | |
| import { createRef, Component } from 'react'; | |
| import './style.scss'; | |
| const noop = () => {}; | |
| export default class extends Component { | |
| static displayName = 'FormRange'; | |
| static propTypes = { | |
| onChange: PropTypes.func, | |
| }; | |
| static defaultProps = { | |
| onChange: noop, | |
| }; | |
| rangeRef = createRef(); | |
| componentDidMount() { | |
| if ( this.shouldNormalizeChange() ) { | |
| this.rangeRef.current.addEventListener( 'change', this.onChange ); | |
| } | |
| } | |
| componentWillUnmount() { | |
| this.rangeRef.current.removeEventListener( 'change', this.onChange ); | |
| } | |
| shouldNormalizeChange = () => { | |
| const ua = window.navigator.userAgent; | |
| // Internet Explorer doesn't trigger the normal "input" event as the | |
| // user drags the thumb. Instead, it emits the equivalent event on | |
| // "change", so we watch the change event and emit a simulated event. | |
| return -1 !== ua.indexOf( 'MSIE' ) || -1 !== ua.indexOf( 'Trident/' ); | |
| }; | |
| onChange = ( event ) => { | |
| this.props.onChange( event ); | |
| }; | |
| render() { | |
| const classes = clsx( this.props.className, 'form-range' ); | |
| return ( | |
| <input | |
| ref={ this.rangeRef } | |
| type="range" | |
| className={ classes } | |
| { ...omit( this.props, 'className' ) } | |
| /> | |
| ); | |
| } | |
| } | |