Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hig/slider

Package Overview
Dependencies
Maintainers
4
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hig/slider - npm Package Compare versions

Comparing version 0.2.0-alpha.fbb1eed0 to 1.0.0

CHANGELOG.md

595

build/index.es.js
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { css } from 'emotion';
import ThemeContext from '@hig/theme-context';
import { ControlBehavior } from '@hig/behaviors';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function stylesheet(props, trackValueRatio, themeData) {
var disabled = props.disabled,
activeStates = _objectWithoutProperties(props, ["disabled"]);
var hasFocus = activeStates.hasFocus,
hasHover = activeStates.hasHover,
isPressed = activeStates.isPressed;
var thumbPseudoElements = {
microsoft: "::-ms-thumb",
mozilla: "::-moz-range-thumb",
webkit: "::-webkit-slider-thumb"
};
var trackPseudoElements = {
microsoft: "::-ms-track",
mozilla: "::-moz-range-track",
webkit: "::-webkit-slider-runnable-track"
};
var trackProgressPseudoElements = {
// WebKit does not have a pseudo element to target this styling, so we achieve it with fancy styling on track
// ::-webkit-slider-runnable-track
microsoft: "::-ms-fill-lower",
mozilla: "::-moz-range-progress"
};
function browserSpecificPseudoElementRules(browserPseudoElements, rules, singleBrowserInclusions) {
var styles = {};
Object.entries(browserPseudoElements).forEach(function (browserPseudoElement) {
var pseudoElementRules = rules;
var browser = browserPseudoElement[0];
var pseudoElement = browserPseudoElement[1];
if (singleBrowserInclusions && singleBrowserInclusions[browser]) {
pseudoElementRules = _extends({}, rules, singleBrowserInclusions[browser]);
}
styles["&" + pseudoElement] = pseudoElementRules;
});
return styles;
}
var baseRules = {
WebkitAppearance: "none" /* Hides platform-native styling */
, width: "100%" /* Specific width is required for Firefox. */
, backgroundColor: "transparent" /* Otherwise white in Chrome */
, boxSizing: "content-box",
height: "20px",
margin: 0,
position: "relative",
outline: "none",
"&::-ms-tooltip": {
display: "none"
},
"&::-moz-focus-outer": {
border: 0
}
};
var thumbDisabledRules = disabled ? {
opacity: themeData["component.disabled.opacity"]
} : {};
var thumbStateRules = function thumbStateRules() {
var isInActiveState = Object.values(activeStates).every(function (stateValue) {
return !stateValue;
});
if (disabled || isInActiveState) {
return {};
}
var stateKey = void 0;
if (hasFocus) stateKey = "focused";
if (hasHover) stateKey = "hover";
if (isPressed) stateKey = "pressed";
return {
backgroundColor: themeData["slider." + stateKey + ".thumb.color"],
boxShadow: "0 0 0 " + themeData["slider." + stateKey + ".halo.width"] + " " + themeData["slider." + stateKey + ".halo.color"]
};
};
var thumbRules = browserSpecificPseudoElementRules(thumbPseudoElements, _extends({
boxSizing: "content-box",
height: themeData["slider.thumb.width"],
width: themeData["slider.thumb.width"],
backgroundColor: themeData["slider.thumb.backgroundColor"],
border: 0,
borderRadius: "50%",
boxShadow: "0 0 0 " + themeData["slider.halo.width"] + " " + themeData["slider.halo.color"],
position: "relative",
top: "50%",
WebkitAppearance: "none" /* Hides platform-native styling */
}, thumbStateRules()), {
mozilla: _extends({}, thumbDisabledRules),
webkit: {
transform: "translateY(-50%)"
}
});
var trackDisabledRules = disabled ? {
opacity: themeData["component.disabled.opacity"]
} : {};
var trackValueWidth = "calc((0.5 * " + themeData["slider.thumb.width"] + ") \n + (" + trackValueRatio + " * (100% - " + themeData["slider.thumb.width"] + ")))";
var trackRules = browserSpecificPseudoElementRules(trackPseudoElements, _extends({
width: "100%",
height: themeData["slider.track.width"],
border: "none",
backgroundColor: themeData["slider.track.color"],
color: "transparent",
outline: "none"
}, trackDisabledRules), {
// WebKit does not have a built-in way to target the progress/lower fill of a slider track.
// This produces the same visual effect.
webkit: {
backgroundColor: themeData["slider.track.color"],
backgroundImage: "linear-gradient(" + themeData["slider.value.color"] + ", " + themeData["slider.value.color"] + ")",
backgroundPosition: 0,
backgroundSize: trackValueWidth + " 100%",
backgroundRepeat: "no-repeat"
}
});
var trackProgressRules = browserSpecificPseudoElementRules(trackProgressPseudoElements, {
border: "none",
backgroundColor: themeData["slider.value.color"]
}, {
mozilla: _extends({}, trackDisabledRules)
});
return {
slider: _extends({}, baseRules, thumbRules, trackRules, trackProgressRules)
};
}
var _extends$1 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _objectWithoutProperties$1(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -15,82 +170,67 @@

var Input = function (_Component) {
_inherits(Input, _Component);
var SliderPresenter = function (_Component) {
_inherits(SliderPresenter, _Component);
function Input() {
_classCallCheck(this, Input);
function SliderPresenter() {
_classCallCheck(this, SliderPresenter);
return _possibleConstructorReturn(this, (Input.__proto__ || Object.getPrototypeOf(Input)).apply(this, arguments));
return _possibleConstructorReturn(this, (SliderPresenter.__proto__ || Object.getPrototypeOf(SliderPresenter)).apply(this, arguments));
}
_createClass(Input, [{
_createClass(SliderPresenter, [{
key: "render",
value: function render() {
var _props = this.props,
disabled = _props.disabled,
hasFocus = _props.hasFocus,
hasHover = _props.hasHover,
isPressed = _props.isPressed,
max = _props.max,
min = _props.min,
max = _props.max,
value = _props.value;
value = _props.value,
otherProps = _objectWithoutProperties$1(_props, ["disabled", "hasFocus", "hasHover", "isPressed", "max", "min", "value"]);
return React.createElement(
ThemeContext.Consumer,
null,
function (_ref) {
var resolvedRoles = _ref.resolvedRoles;
return React.createElement("input", _extends({
className: "hig__slider__input",
type: "range",
"aria-valuemin": min,
"aria-valuemax": max,
"aria-valuenow": value
}, this.props));
var rangeRange = max - min;
var valueRatio = (value - min) / rangeRange;
var styles = stylesheet({ disabled: disabled, hasFocus: hasFocus, hasHover: hasHover, isPressed: isPressed }, valueRatio, resolvedRoles);
return React.createElement("input", _extends$1({
className: css(styles.slider),
disabled: disabled,
type: "range",
"aria-valuemin": min,
"aria-valuemax": max,
"aria-valuenow": value,
max: max,
min: min,
value: value
}, otherProps));
}
);
}
}]);
return Input;
return SliderPresenter;
}(Component);
Input.propTypes = {
/**
* Prevents user actions on the field
*/
SliderPresenter.propTypes = {
disabled: PropTypes.bool,
/**
* HTML ID attribute
*/
id: PropTypes.string,
/**
* Minimum value of the slider
*/
hasFocus: PropTypes.bool,
hasHover: PropTypes.bool,
isPressed: PropTypes.bool,
max: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Maximum value of the slider
*/
max: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Name of the field when submitted with a form
*/
name: PropTypes.string,
/**
* Called when user moves focus from the field
*/
onBlur: PropTypes.func,
/**
* Called after user changes the value of the field
*/
onChange: PropTypes.func,
/**
* Called when user puts focus onto the field
*/
onFocus: PropTypes.func,
/**
* Called as user changes the value of the field
*/
onInput: PropTypes.func,
/**
* The granularity of each step on the slider
*/
step: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Value of the field
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
};
Input.__docgenInfo = {
SliderPresenter.__docgenInfo = {
"description": "",
"displayName": "Input",
"displayName": "SliderPresenter",
"props": {

@@ -102,13 +242,27 @@ "disabled": {

"required": false,
"description": "Prevents user actions on the field"
"description": ""
},
"id": {
"hasFocus": {
"type": {
"name": "string"
"name": "bool"
},
"required": false,
"description": "HTML ID attribute"
"description": ""
},
"min": {
"hasHover": {
"type": {
"name": "bool"
},
"required": false,
"description": ""
},
"isPressed": {
"type": {
"name": "bool"
},
"required": false,
"description": ""
},
"max": {
"type": {
"name": "union",

@@ -122,5 +276,5 @@ "value": [{

"required": false,
"description": "Minimum value of the slider"
"description": ""
},
"max": {
"min": {
"type": {

@@ -135,39 +289,4 @@ "name": "union",

"required": false,
"description": "Maximum value of the slider"
"description": ""
},
"name": {
"type": {
"name": "string"
},
"required": false,
"description": "Name of the field when submitted with a form"
},
"onBlur": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user moves focus from the field"
},
"onChange": {
"type": {
"name": "func"
},
"required": false,
"description": "Called after user changes the value of the field"
},
"onFocus": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user puts focus onto the field"
},
"onInput": {
"type": {
"name": "func"
},
"required": false,
"description": "Called as user changes the value of the field"
},
"step": {

@@ -183,3 +302,3 @@ "type": {

"required": false,
"description": "The granularity of each step on the slider"
"description": ""
},

@@ -196,3 +315,3 @@ "value": {

"required": false,
"description": "Value of the field"
"description": ""
}

@@ -202,4 +321,8 @@ }

var _extends$2 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass$1 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _objectWithoutProperties$2(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -211,6 +334,11 @@

function generatedId() {
return "slider-" + Math.floor(Math.random() * 100000, 5);
}
/**
* @typedef {string|number} Value
*/
/**
* @typedef {Object} State
* @property {Value} value
*/
var Slider = function (_Component) {

@@ -231,77 +359,111 @@ _inherits$1(Slider, _Component);

return _ret = (_temp = (_this = _possibleConstructorReturn$1(this, (_ref = Slider.__proto__ || Object.getPrototypeOf(Slider)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
value: _this.props.defaultValue || _this.props.value
value: _this.props.defaultValue || (_this.props.max - _this.props.min) / 2
}, _this.handleChange = function (event) {
_this.setState({ value: event.target.value });
if (_this.props.onChange) _this.props.onChange(event);
_this.setValue(event.target.value);
}, _temp), _possibleConstructorReturn$1(_this, _ret);
}
/**
* @type {State}
*/
_createClass$1(Slider, [{
key: "getValue",
/**
* @returns {Value}
*/
value: function getValue() {
if (this.isControlled()) {
return this.props.value || 0;
}
return this.state.value;
}
/**
* @param {Value} value
*/
}, {
key: "setValue",
value: function setValue(value) {
var onChange = this.props.onChange;
if (onChange) onChange(Number(value));
if (!this.isControlled()) {
this.setState({ value: value });
}
}
}, {
key: "isControlled",
value: function isControlled() {
return this.props.value !== undefined;
}
/**
* @param {event} Event
*/
}, {
key: "render",
value: function render() {
var _this2 = this;
var _props = this.props,
id = _props.id,
name = _props.name,
label = _props.label,
instructions = _props.instructions,
required = _props.required,
disabled = _props.disabled,
min = _props.min,
max = _props.max,
step = _props.step,
defaultValue = _props.defaultValue,
onBlur = _props.onBlur,
onChange = _props.onChange,
onFocus = _props.onFocus,
onInput = _props.onInput;
var value = this.state.value;
onMouseDown = _props.onMouseDown,
onMouseEnter = _props.onMouseEnter,
onMouseLeave = _props.onMouseLeave,
onMouseUp = _props.onMouseUp,
value = _props.value,
otherProps = _objectWithoutProperties$2(_props, ["defaultValue", "onBlur", "onChange", "onFocus", "onMouseDown", "onMouseEnter", "onMouseLeave", "onMouseUp", "value"]);
var currentValue = this.getValue();
return React.createElement(
"div",
ControlBehavior,
{
className: cx("hig__slider", {
"hig__slider--disabled": disabled,
"hig__slider--required": required
})
onBlur: onBlur,
onFocus: onFocus,
onMouseDown: onMouseDown,
onMouseEnter: onMouseEnter,
onMouseLeave: onMouseLeave,
onMouseUp: onMouseUp
},
React.createElement(
"div",
{
className: "hig__slider__wrapper",
"data-range-min": min,
"data-range-max": max
},
React.createElement(
"span",
{ className: "hig__slider__current-value" },
value
),
React.createElement(Input, {
id: id,
onChange: this.handleChange,
disabled: disabled,
name: name,
min: min,
max: max,
step: step,
value: value,
onBlur: onBlur,
onFocus: onFocus,
onInput: onInput
}),
label && React.createElement(
"label",
{ htmlFor: id, className: "hig__slider__label" },
label
)
),
instructions && React.createElement(
"p",
{ className: "hig__slider__instructions" },
instructions
),
required && React.createElement(
"p",
{ className: "hig__slider__required-notice" },
required
)
function (_ref2) {
var hasFocus = _ref2.hasFocus,
hasHover = _ref2.hasHover,
isPressed = _ref2.isPressed,
handleBlur = _ref2.onBlur,
handleFocus = _ref2.onFocus,
handleMouseDown = _ref2.onMouseDown,
handleMouseEnter = _ref2.onMouseEnter,
handleMouseLeave = _ref2.onMouseLeave,
handleMouseUp = _ref2.onMouseUp;
return React.createElement(
"div",
{ className: css({ display: "block" }) },
React.createElement(SliderPresenter, _extends$2({
hasFocus: hasFocus,
hasHover: hasHover,
isPressed: isPressed,
onBlur: handleBlur,
onChange: _this2.handleChange,
onFocus: handleFocus,
onMouseDown: handleMouseDown,
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave,
onMouseUp: handleMouseUp,
value: currentValue
}, otherProps))
);
}
);

@@ -328,10 +490,6 @@ }

/**
* Instructional text for the field
* Maximum value of the slider
*/
instructions: PropTypes.string,
max: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Text describing what the field represents
*/
label: PropTypes.string,
/**
* Minimum value of the slider

@@ -341,6 +499,2 @@ */

/**
* Maximum value of the slider
*/
max: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Name of the field when submitted with a form

@@ -366,6 +520,18 @@ */

/**
* Text describing why the field is required
* Called when user presses their mouse over the field
*/
required: PropTypes.string,
onMouseDown: PropTypes.func,
/**
* Called when user moves their mouse over the field
*/
onMouseEnter: PropTypes.func,
/**
* Called when user moves their mouse out of the field
*/
onMouseLeave: PropTypes.func,
/**
* Called when user releases their mouse press over the field
*/
onMouseUp: PropTypes.func,
/**
* The granularity of each step on the slider

@@ -380,9 +546,9 @@ */

Slider.defaultProps = {
id: generatedId(),
disabled: false,
max: "100",
min: "0",
max: "100",
step: "1"
};
Slider.__docgenInfo = {
"description": "",
"description": "@typedef {Object} State\n@property {Value} value",
"displayName": "Slider",

@@ -407,16 +573,9 @@ "props": {

"required": false,
"description": "Prevents user actions on the field"
},
"id": {
"type": {
"name": "string"
},
"required": false,
"description": "HTML ID attribute",
"description": "Prevents user actions on the field",
"defaultValue": {
"value": "generatedId()",
"computed": true
"value": "false",
"computed": false
}
},
"instructions": {
"id": {
"type": {

@@ -426,13 +585,6 @@ "name": "string"

"required": false,
"description": "Instructional text for the field"
"description": "HTML ID attribute"
},
"label": {
"max": {
"type": {
"name": "string"
},
"required": false,
"description": "Text describing what the field represents"
},
"min": {
"type": {
"name": "union",

@@ -446,9 +598,9 @@ "value": [{

"required": false,
"description": "Minimum value of the slider",
"description": "Maximum value of the slider",
"defaultValue": {
"value": "\"0\"",
"value": "\"100\"",
"computed": false
}
},
"max": {
"min": {
"type": {

@@ -463,5 +615,5 @@ "name": "union",

"required": false,
"description": "Maximum value of the slider",
"description": "Minimum value of the slider",
"defaultValue": {
"value": "\"100\"",
"value": "\"0\"",
"computed": false

@@ -505,9 +657,30 @@ }

},
"required": {
"onMouseDown": {
"type": {
"name": "string"
"name": "func"
},
"required": false,
"description": "Text describing why the field is required"
"description": "Called when user presses their mouse over the field"
},
"onMouseEnter": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user moves their mouse over the field"
},
"onMouseLeave": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user moves their mouse out of the field"
},
"onMouseUp": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user releases their mouse press over the field"
},
"step": {

@@ -514,0 +687,0 @@ "type": {

@@ -10,8 +10,163 @@ 'use strict';

var PropTypes = _interopDefault(require('prop-types'));
var cx = _interopDefault(require('classnames'));
var emotion = require('emotion');
var ThemeContext = _interopDefault(require('@hig/theme-context'));
var behaviors = require('@hig/behaviors');
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function stylesheet(props, trackValueRatio, themeData) {
var disabled = props.disabled,
activeStates = _objectWithoutProperties(props, ["disabled"]);
var hasFocus = activeStates.hasFocus,
hasHover = activeStates.hasHover,
isPressed = activeStates.isPressed;
var thumbPseudoElements = {
microsoft: "::-ms-thumb",
mozilla: "::-moz-range-thumb",
webkit: "::-webkit-slider-thumb"
};
var trackPseudoElements = {
microsoft: "::-ms-track",
mozilla: "::-moz-range-track",
webkit: "::-webkit-slider-runnable-track"
};
var trackProgressPseudoElements = {
// WebKit does not have a pseudo element to target this styling, so we achieve it with fancy styling on track
// ::-webkit-slider-runnable-track
microsoft: "::-ms-fill-lower",
mozilla: "::-moz-range-progress"
};
function browserSpecificPseudoElementRules(browserPseudoElements, rules, singleBrowserInclusions) {
var styles = {};
Object.entries(browserPseudoElements).forEach(function (browserPseudoElement) {
var pseudoElementRules = rules;
var browser = browserPseudoElement[0];
var pseudoElement = browserPseudoElement[1];
if (singleBrowserInclusions && singleBrowserInclusions[browser]) {
pseudoElementRules = _extends({}, rules, singleBrowserInclusions[browser]);
}
styles["&" + pseudoElement] = pseudoElementRules;
});
return styles;
}
var baseRules = {
WebkitAppearance: "none" /* Hides platform-native styling */
, width: "100%" /* Specific width is required for Firefox. */
, backgroundColor: "transparent" /* Otherwise white in Chrome */
, boxSizing: "content-box",
height: "20px",
margin: 0,
position: "relative",
outline: "none",
"&::-ms-tooltip": {
display: "none"
},
"&::-moz-focus-outer": {
border: 0
}
};
var thumbDisabledRules = disabled ? {
opacity: themeData["component.disabled.opacity"]
} : {};
var thumbStateRules = function thumbStateRules() {
var isInActiveState = Object.values(activeStates).every(function (stateValue) {
return !stateValue;
});
if (disabled || isInActiveState) {
return {};
}
var stateKey = void 0;
if (hasFocus) stateKey = "focused";
if (hasHover) stateKey = "hover";
if (isPressed) stateKey = "pressed";
return {
backgroundColor: themeData["slider." + stateKey + ".thumb.color"],
boxShadow: "0 0 0 " + themeData["slider." + stateKey + ".halo.width"] + " " + themeData["slider." + stateKey + ".halo.color"]
};
};
var thumbRules = browserSpecificPseudoElementRules(thumbPseudoElements, _extends({
boxSizing: "content-box",
height: themeData["slider.thumb.width"],
width: themeData["slider.thumb.width"],
backgroundColor: themeData["slider.thumb.backgroundColor"],
border: 0,
borderRadius: "50%",
boxShadow: "0 0 0 " + themeData["slider.halo.width"] + " " + themeData["slider.halo.color"],
position: "relative",
top: "50%",
WebkitAppearance: "none" /* Hides platform-native styling */
}, thumbStateRules()), {
mozilla: _extends({}, thumbDisabledRules),
webkit: {
transform: "translateY(-50%)"
}
});
var trackDisabledRules = disabled ? {
opacity: themeData["component.disabled.opacity"]
} : {};
var trackValueWidth = "calc((0.5 * " + themeData["slider.thumb.width"] + ") \n + (" + trackValueRatio + " * (100% - " + themeData["slider.thumb.width"] + ")))";
var trackRules = browserSpecificPseudoElementRules(trackPseudoElements, _extends({
width: "100%",
height: themeData["slider.track.width"],
border: "none",
backgroundColor: themeData["slider.track.color"],
color: "transparent",
outline: "none"
}, trackDisabledRules), {
// WebKit does not have a built-in way to target the progress/lower fill of a slider track.
// This produces the same visual effect.
webkit: {
backgroundColor: themeData["slider.track.color"],
backgroundImage: "linear-gradient(" + themeData["slider.value.color"] + ", " + themeData["slider.value.color"] + ")",
backgroundPosition: 0,
backgroundSize: trackValueWidth + " 100%",
backgroundRepeat: "no-repeat"
}
});
var trackProgressRules = browserSpecificPseudoElementRules(trackProgressPseudoElements, {
border: "none",
backgroundColor: themeData["slider.value.color"]
}, {
mozilla: _extends({}, trackDisabledRules)
});
return {
slider: _extends({}, baseRules, thumbRules, trackRules, trackProgressRules)
};
}
var _extends$1 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _objectWithoutProperties$1(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -23,82 +178,67 @@

var Input = function (_Component) {
_inherits(Input, _Component);
var SliderPresenter = function (_Component) {
_inherits(SliderPresenter, _Component);
function Input() {
_classCallCheck(this, Input);
function SliderPresenter() {
_classCallCheck(this, SliderPresenter);
return _possibleConstructorReturn(this, (Input.__proto__ || Object.getPrototypeOf(Input)).apply(this, arguments));
return _possibleConstructorReturn(this, (SliderPresenter.__proto__ || Object.getPrototypeOf(SliderPresenter)).apply(this, arguments));
}
_createClass(Input, [{
_createClass(SliderPresenter, [{
key: "render",
value: function render() {
var _props = this.props,
disabled = _props.disabled,
hasFocus = _props.hasFocus,
hasHover = _props.hasHover,
isPressed = _props.isPressed,
max = _props.max,
min = _props.min,
max = _props.max,
value = _props.value;
value = _props.value,
otherProps = _objectWithoutProperties$1(_props, ["disabled", "hasFocus", "hasHover", "isPressed", "max", "min", "value"]);
return React__default.createElement(
ThemeContext.Consumer,
null,
function (_ref) {
var resolvedRoles = _ref.resolvedRoles;
return React__default.createElement("input", _extends({
className: "hig__slider__input",
type: "range",
"aria-valuemin": min,
"aria-valuemax": max,
"aria-valuenow": value
}, this.props));
var rangeRange = max - min;
var valueRatio = (value - min) / rangeRange;
var styles = stylesheet({ disabled: disabled, hasFocus: hasFocus, hasHover: hasHover, isPressed: isPressed }, valueRatio, resolvedRoles);
return React__default.createElement("input", _extends$1({
className: emotion.css(styles.slider),
disabled: disabled,
type: "range",
"aria-valuemin": min,
"aria-valuemax": max,
"aria-valuenow": value,
max: max,
min: min,
value: value
}, otherProps));
}
);
}
}]);
return Input;
return SliderPresenter;
}(React.Component);
Input.propTypes = {
/**
* Prevents user actions on the field
*/
SliderPresenter.propTypes = {
disabled: PropTypes.bool,
/**
* HTML ID attribute
*/
id: PropTypes.string,
/**
* Minimum value of the slider
*/
hasFocus: PropTypes.bool,
hasHover: PropTypes.bool,
isPressed: PropTypes.bool,
max: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Maximum value of the slider
*/
max: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Name of the field when submitted with a form
*/
name: PropTypes.string,
/**
* Called when user moves focus from the field
*/
onBlur: PropTypes.func,
/**
* Called after user changes the value of the field
*/
onChange: PropTypes.func,
/**
* Called when user puts focus onto the field
*/
onFocus: PropTypes.func,
/**
* Called as user changes the value of the field
*/
onInput: PropTypes.func,
/**
* The granularity of each step on the slider
*/
step: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Value of the field
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
};
Input.__docgenInfo = {
SliderPresenter.__docgenInfo = {
"description": "",
"displayName": "Input",
"displayName": "SliderPresenter",
"props": {

@@ -110,13 +250,27 @@ "disabled": {

"required": false,
"description": "Prevents user actions on the field"
"description": ""
},
"id": {
"hasFocus": {
"type": {
"name": "string"
"name": "bool"
},
"required": false,
"description": "HTML ID attribute"
"description": ""
},
"min": {
"hasHover": {
"type": {
"name": "bool"
},
"required": false,
"description": ""
},
"isPressed": {
"type": {
"name": "bool"
},
"required": false,
"description": ""
},
"max": {
"type": {
"name": "union",

@@ -130,5 +284,5 @@ "value": [{

"required": false,
"description": "Minimum value of the slider"
"description": ""
},
"max": {
"min": {
"type": {

@@ -143,39 +297,4 @@ "name": "union",

"required": false,
"description": "Maximum value of the slider"
"description": ""
},
"name": {
"type": {
"name": "string"
},
"required": false,
"description": "Name of the field when submitted with a form"
},
"onBlur": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user moves focus from the field"
},
"onChange": {
"type": {
"name": "func"
},
"required": false,
"description": "Called after user changes the value of the field"
},
"onFocus": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user puts focus onto the field"
},
"onInput": {
"type": {
"name": "func"
},
"required": false,
"description": "Called as user changes the value of the field"
},
"step": {

@@ -191,3 +310,3 @@ "type": {

"required": false,
"description": "The granularity of each step on the slider"
"description": ""
},

@@ -204,3 +323,3 @@ "value": {

"required": false,
"description": "Value of the field"
"description": ""
}

@@ -210,4 +329,8 @@ }

var _extends$2 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass$1 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _objectWithoutProperties$2(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -219,6 +342,11 @@

function generatedId() {
return "slider-" + Math.floor(Math.random() * 100000, 5);
}
/**
* @typedef {string|number} Value
*/
/**
* @typedef {Object} State
* @property {Value} value
*/
var Slider = function (_Component) {

@@ -239,77 +367,111 @@ _inherits$1(Slider, _Component);

return _ret = (_temp = (_this = _possibleConstructorReturn$1(this, (_ref = Slider.__proto__ || Object.getPrototypeOf(Slider)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
value: _this.props.defaultValue || _this.props.value
value: _this.props.defaultValue || (_this.props.max - _this.props.min) / 2
}, _this.handleChange = function (event) {
_this.setState({ value: event.target.value });
if (_this.props.onChange) _this.props.onChange(event);
_this.setValue(event.target.value);
}, _temp), _possibleConstructorReturn$1(_this, _ret);
}
/**
* @type {State}
*/
_createClass$1(Slider, [{
key: "getValue",
/**
* @returns {Value}
*/
value: function getValue() {
if (this.isControlled()) {
return this.props.value || 0;
}
return this.state.value;
}
/**
* @param {Value} value
*/
}, {
key: "setValue",
value: function setValue(value) {
var onChange = this.props.onChange;
if (onChange) onChange(Number(value));
if (!this.isControlled()) {
this.setState({ value: value });
}
}
}, {
key: "isControlled",
value: function isControlled() {
return this.props.value !== undefined;
}
/**
* @param {event} Event
*/
}, {
key: "render",
value: function render() {
var _this2 = this;
var _props = this.props,
id = _props.id,
name = _props.name,
label = _props.label,
instructions = _props.instructions,
required = _props.required,
disabled = _props.disabled,
min = _props.min,
max = _props.max,
step = _props.step,
defaultValue = _props.defaultValue,
onBlur = _props.onBlur,
onChange = _props.onChange,
onFocus = _props.onFocus,
onInput = _props.onInput;
var value = this.state.value;
onMouseDown = _props.onMouseDown,
onMouseEnter = _props.onMouseEnter,
onMouseLeave = _props.onMouseLeave,
onMouseUp = _props.onMouseUp,
value = _props.value,
otherProps = _objectWithoutProperties$2(_props, ["defaultValue", "onBlur", "onChange", "onFocus", "onMouseDown", "onMouseEnter", "onMouseLeave", "onMouseUp", "value"]);
var currentValue = this.getValue();
return React__default.createElement(
"div",
behaviors.ControlBehavior,
{
className: cx("hig__slider", {
"hig__slider--disabled": disabled,
"hig__slider--required": required
})
onBlur: onBlur,
onFocus: onFocus,
onMouseDown: onMouseDown,
onMouseEnter: onMouseEnter,
onMouseLeave: onMouseLeave,
onMouseUp: onMouseUp
},
React__default.createElement(
"div",
{
className: "hig__slider__wrapper",
"data-range-min": min,
"data-range-max": max
},
React__default.createElement(
"span",
{ className: "hig__slider__current-value" },
value
),
React__default.createElement(Input, {
id: id,
onChange: this.handleChange,
disabled: disabled,
name: name,
min: min,
max: max,
step: step,
value: value,
onBlur: onBlur,
onFocus: onFocus,
onInput: onInput
}),
label && React__default.createElement(
"label",
{ htmlFor: id, className: "hig__slider__label" },
label
)
),
instructions && React__default.createElement(
"p",
{ className: "hig__slider__instructions" },
instructions
),
required && React__default.createElement(
"p",
{ className: "hig__slider__required-notice" },
required
)
function (_ref2) {
var hasFocus = _ref2.hasFocus,
hasHover = _ref2.hasHover,
isPressed = _ref2.isPressed,
handleBlur = _ref2.onBlur,
handleFocus = _ref2.onFocus,
handleMouseDown = _ref2.onMouseDown,
handleMouseEnter = _ref2.onMouseEnter,
handleMouseLeave = _ref2.onMouseLeave,
handleMouseUp = _ref2.onMouseUp;
return React__default.createElement(
"div",
{ className: emotion.css({ display: "block" }) },
React__default.createElement(SliderPresenter, _extends$2({
hasFocus: hasFocus,
hasHover: hasHover,
isPressed: isPressed,
onBlur: handleBlur,
onChange: _this2.handleChange,
onFocus: handleFocus,
onMouseDown: handleMouseDown,
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave,
onMouseUp: handleMouseUp,
value: currentValue
}, otherProps))
);
}
);

@@ -336,10 +498,6 @@ }

/**
* Instructional text for the field
* Maximum value of the slider
*/
instructions: PropTypes.string,
max: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Text describing what the field represents
*/
label: PropTypes.string,
/**
* Minimum value of the slider

@@ -349,6 +507,2 @@ */

/**
* Maximum value of the slider
*/
max: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Name of the field when submitted with a form

@@ -374,6 +528,18 @@ */

/**
* Text describing why the field is required
* Called when user presses their mouse over the field
*/
required: PropTypes.string,
onMouseDown: PropTypes.func,
/**
* Called when user moves their mouse over the field
*/
onMouseEnter: PropTypes.func,
/**
* Called when user moves their mouse out of the field
*/
onMouseLeave: PropTypes.func,
/**
* Called when user releases their mouse press over the field
*/
onMouseUp: PropTypes.func,
/**
* The granularity of each step on the slider

@@ -388,9 +554,9 @@ */

Slider.defaultProps = {
id: generatedId(),
disabled: false,
max: "100",
min: "0",
max: "100",
step: "1"
};
Slider.__docgenInfo = {
"description": "",
"description": "@typedef {Object} State\n@property {Value} value",
"displayName": "Slider",

@@ -415,16 +581,9 @@ "props": {

"required": false,
"description": "Prevents user actions on the field"
},
"id": {
"type": {
"name": "string"
},
"required": false,
"description": "HTML ID attribute",
"description": "Prevents user actions on the field",
"defaultValue": {
"value": "generatedId()",
"computed": true
"value": "false",
"computed": false
}
},
"instructions": {
"id": {
"type": {

@@ -434,13 +593,6 @@ "name": "string"

"required": false,
"description": "Instructional text for the field"
"description": "HTML ID attribute"
},
"label": {
"max": {
"type": {
"name": "string"
},
"required": false,
"description": "Text describing what the field represents"
},
"min": {
"type": {
"name": "union",

@@ -454,9 +606,9 @@ "value": [{

"required": false,
"description": "Minimum value of the slider",
"description": "Maximum value of the slider",
"defaultValue": {
"value": "\"0\"",
"value": "\"100\"",
"computed": false
}
},
"max": {
"min": {
"type": {

@@ -471,5 +623,5 @@ "name": "union",

"required": false,
"description": "Maximum value of the slider",
"description": "Minimum value of the slider",
"defaultValue": {
"value": "\"100\"",
"value": "\"0\"",
"computed": false

@@ -513,9 +665,30 @@ }

},
"required": {
"onMouseDown": {
"type": {
"name": "string"
"name": "func"
},
"required": false,
"description": "Text describing why the field is required"
"description": "Called when user presses their mouse over the field"
},
"onMouseEnter": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user moves their mouse over the field"
},
"onMouseLeave": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user moves their mouse out of the field"
},
"onMouseUp": {
"type": {
"name": "func"
},
"required": false,
"description": "Called when user releases their mouse press over the field"
},
"step": {

@@ -522,0 +695,0 @@ "type": {

{
"name": "@hig/slider",
"version": "0.2.0-alpha.fbb1eed0",
"version": "1.0.0",
"description": "HIG Slider",

@@ -16,3 +16,2 @@ "author": "Autodesk Inc.",

"module": "build/index.es.js",
"style": "build/index.css",
"files": [

@@ -22,3 +21,6 @@ "build/*"

"dependencies": {
"classnames": "^2.2.5",
"@hig/behaviors": "^1.1.1",
"@hig/theme-context": "^2.1.0",
"@hig/utils": "^0.3.0",
"emotion": "^10.0.0",
"prop-types": "^15.6.1"

@@ -30,7 +32,7 @@ },

"devDependencies": {
"@hig/babel-preset": "0.2.0-alpha.fbb1eed0",
"@hig/eslint-config": "0.2.0-alpha.fbb1eed0",
"@hig/scripts": "0.2.0-alpha.fbb1eed0",
"@hig/semantic-release-config": "0.2.0-alpha.fbb1eed0",
"@hig/styles": "^0.1.1"
"@hig/babel-preset": "^0.1.1",
"@hig/eslint-config": "^0.1.0",
"@hig/jest-preset": "^0.1.0",
"@hig/scripts": "^0.1.2",
"@hig/semantic-release-config": "^0.1.0"
},

@@ -40,2 +42,3 @@ "scripts": {

"lint": "hig-scripts-lint",
"test": "hig-scripts-test",
"release": "hig-scripts-release"

@@ -46,2 +49,5 @@ },

},
"jest": {
"preset": "@hig/jest-preset"
},
"release": {

@@ -48,0 +54,0 @@ "extends": "@hig/semantic-release-config"

@@ -15,7 +15,6 @@ # Slider

### Import the component and CSS
### Import the component
```js
import Slider from '@hig/slider';
import '@hig/slider/build/index.css';
```

@@ -27,5 +26,2 @@

<Slider
label="What is your age?"
instructions="You must be 21 or older."
required="Age is required."
min={21}

@@ -32,0 +28,0 @@ max={99}

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc