@atlaskit/range 5.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +349 -0
- package/LICENSE +13 -0
- package/README.md +13 -0
- package/__perf__/default.tsx +7 -0
- package/__perf__/range.tsx +42 -0
- package/build/tsconfig.json +17 -0
- package/codemods/4.0.0-lite-mode.ts +92 -0
- package/codemods/__tests__/4.0.0-lite-mode.ts +109 -0
- package/constellation/index/examples.mdx +39 -0
- package/constellation/index/images/range-anatomy.png +0 -0
- package/constellation/index/props.mdx +5 -0
- package/constellation/index/usage.mdx +31 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/range.js +108 -0
- package/dist/cjs/styled.js +94 -0
- package/dist/cjs/theme.js +56 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/range.js +67 -0
- package/dist/es2019/styled.js +255 -0
- package/dist/es2019/theme.js +36 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/range.js +86 -0
- package/dist/esm/styled.js +79 -0
- package/dist/esm/theme.js +38 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/range.d.ts +28 -0
- package/dist/types/styled.d.ts +12 -0
- package/dist/types/theme.d.ts +60 -0
- package/docs/0-intro.tsx +13 -0
- package/extract-react-types/range-props.tsx +5 -0
- package/package.json +80 -0
- package/range/package.json +7 -0
- package/styled/package.json +7 -0
- package/theme/package.json +7 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import core, {
|
|
2
|
+
API,
|
|
3
|
+
ASTPath,
|
|
4
|
+
FileInfo,
|
|
5
|
+
ImportDeclaration,
|
|
6
|
+
JSXAttribute,
|
|
7
|
+
Options,
|
|
8
|
+
} from 'jscodeshift';
|
|
9
|
+
|
|
10
|
+
function getDefaultSpecifier(
|
|
11
|
+
j: core.JSCodeshift,
|
|
12
|
+
source: any,
|
|
13
|
+
specifier: string,
|
|
14
|
+
) {
|
|
15
|
+
const specifiers = source
|
|
16
|
+
.find(j.ImportDeclaration)
|
|
17
|
+
.filter(
|
|
18
|
+
(path: ASTPath<ImportDeclaration>) =>
|
|
19
|
+
path.node.source.value === specifier,
|
|
20
|
+
)
|
|
21
|
+
.find(j.ImportDefaultSpecifier);
|
|
22
|
+
|
|
23
|
+
if (!specifiers.length) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return specifiers.nodes()[0]!.local!.name;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getJSXAttributesByName(
|
|
30
|
+
j: core.JSCodeshift,
|
|
31
|
+
element: ASTPath<any>,
|
|
32
|
+
attributeName: string,
|
|
33
|
+
) {
|
|
34
|
+
return j(element)
|
|
35
|
+
.find(j.JSXOpeningElement)
|
|
36
|
+
.find(j.JSXAttribute)
|
|
37
|
+
.filter((attribute) => {
|
|
38
|
+
const matches = j(attribute)
|
|
39
|
+
.find(j.JSXIdentifier)
|
|
40
|
+
.filter((identifier) => identifier.value.name === attributeName);
|
|
41
|
+
return Boolean(matches.length);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function updateRef(j: core.JSCodeshift, source: any) {
|
|
46
|
+
const defaultSpecifier = getDefaultSpecifier(j, source, '@atlaskit/range');
|
|
47
|
+
|
|
48
|
+
if (!defaultSpecifier) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
source
|
|
53
|
+
.findJSXElements(defaultSpecifier)
|
|
54
|
+
.forEach((element: ASTPath<JSXAttribute>) => {
|
|
55
|
+
getJSXAttributesByName(j, element, 'inputRef').forEach((attribute) => {
|
|
56
|
+
j(attribute).replaceWith(
|
|
57
|
+
j.jsxAttribute(j.jsxIdentifier('ref'), attribute.node.value),
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function hasImportDeclaration(
|
|
64
|
+
j: core.JSCodeshift,
|
|
65
|
+
source: any,
|
|
66
|
+
importPath: string,
|
|
67
|
+
) {
|
|
68
|
+
const imports = source
|
|
69
|
+
.find(j.ImportDeclaration)
|
|
70
|
+
.filter(
|
|
71
|
+
(path: ASTPath<ImportDeclaration>) =>
|
|
72
|
+
path.node.source.value === importPath,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return Boolean(imports.length);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default function transformer(
|
|
79
|
+
fileInfo: FileInfo,
|
|
80
|
+
{ jscodeshift: j }: API,
|
|
81
|
+
options: Options,
|
|
82
|
+
) {
|
|
83
|
+
const source = j(fileInfo.source);
|
|
84
|
+
|
|
85
|
+
if (!hasImportDeclaration(j, source, '@atlaskit/range')) {
|
|
86
|
+
return fileInfo.source;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
updateRef(j, source);
|
|
90
|
+
|
|
91
|
+
return source.toSource(options.printOptions || { quote: 'single' });
|
|
92
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
jest.autoMockOff();
|
|
2
|
+
|
|
3
|
+
import transformer from '../4.0.0-lite-mode';
|
|
4
|
+
|
|
5
|
+
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
6
|
+
|
|
7
|
+
describe('Update ref prop', () => {
|
|
8
|
+
defineInlineTest(
|
|
9
|
+
{ default: transformer, parser: 'tsx' },
|
|
10
|
+
{},
|
|
11
|
+
`
|
|
12
|
+
import React, { useRef } from 'react';
|
|
13
|
+
import Range from '@atlaskit/range';
|
|
14
|
+
|
|
15
|
+
const SimpleRange = () => {
|
|
16
|
+
let ref = useRef();
|
|
17
|
+
|
|
18
|
+
const inputRef = (newRef) => {
|
|
19
|
+
ref = newRef;
|
|
20
|
+
}
|
|
21
|
+
return <Range inputRef={inputRef} />;
|
|
22
|
+
}
|
|
23
|
+
`,
|
|
24
|
+
`
|
|
25
|
+
import React, { useRef } from 'react';
|
|
26
|
+
import Range from '@atlaskit/range';
|
|
27
|
+
|
|
28
|
+
const SimpleRange = () => {
|
|
29
|
+
let ref = useRef();
|
|
30
|
+
|
|
31
|
+
const inputRef = (newRef) => {
|
|
32
|
+
ref = newRef;
|
|
33
|
+
}
|
|
34
|
+
return <Range ref={inputRef} />;
|
|
35
|
+
}
|
|
36
|
+
`,
|
|
37
|
+
'should replace inputRef with ref',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
defineInlineTest(
|
|
41
|
+
{ default: transformer, parser: 'tsx' },
|
|
42
|
+
{},
|
|
43
|
+
`
|
|
44
|
+
import React, { useRef } from 'react';
|
|
45
|
+
import Range from '@atlaskit/range';
|
|
46
|
+
|
|
47
|
+
const SimpleRange = () => {
|
|
48
|
+
let ref = useRef();
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Range
|
|
52
|
+
inputRef={newRef => {
|
|
53
|
+
ref = newRef;
|
|
54
|
+
}}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
`,
|
|
59
|
+
`
|
|
60
|
+
import React, { useRef } from 'react';
|
|
61
|
+
import Range from '@atlaskit/range';
|
|
62
|
+
|
|
63
|
+
const SimpleRange = () => {
|
|
64
|
+
let ref = useRef();
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Range
|
|
68
|
+
ref={newRef => {
|
|
69
|
+
ref = newRef;
|
|
70
|
+
}}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
`,
|
|
75
|
+
'should replace inputRef with ref when defined inline',
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
defineInlineTest(
|
|
79
|
+
{ default: transformer, parser: 'tsx' },
|
|
80
|
+
{},
|
|
81
|
+
`
|
|
82
|
+
import React, { useRef } from 'react';
|
|
83
|
+
import Foo from '@atlaskit/range';
|
|
84
|
+
|
|
85
|
+
const SimpleRange = () => {
|
|
86
|
+
let ref = useRef();
|
|
87
|
+
|
|
88
|
+
const inputRef = (newRef) => {
|
|
89
|
+
ref = newRef;
|
|
90
|
+
}
|
|
91
|
+
return <Foo inputRef={inputRef} />;
|
|
92
|
+
}
|
|
93
|
+
`,
|
|
94
|
+
`
|
|
95
|
+
import React, { useRef } from 'react';
|
|
96
|
+
import Foo from '@atlaskit/range';
|
|
97
|
+
|
|
98
|
+
const SimpleRange = () => {
|
|
99
|
+
let ref = useRef();
|
|
100
|
+
|
|
101
|
+
const inputRef = (newRef) => {
|
|
102
|
+
ref = newRef;
|
|
103
|
+
}
|
|
104
|
+
return <Foo ref={inputRef} />;
|
|
105
|
+
}
|
|
106
|
+
`,
|
|
107
|
+
'should change inputRef with aliased import name',
|
|
108
|
+
);
|
|
109
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
order: 0
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
import RangeDefault from '../../examples/constellation/range-default';
|
|
6
|
+
import RangeForm from '../../examples/constellation/range-form';
|
|
7
|
+
import RangeControlled from '../../examples/constellation/range-controlled';
|
|
8
|
+
import RangeUncontrolled from '../../examples/constellation/range-uncontrolled';
|
|
9
|
+
import RangeDisabled from '../../examples/constellation/range-disabled';
|
|
10
|
+
|
|
11
|
+
## Default
|
|
12
|
+
|
|
13
|
+
The default form of a range.
|
|
14
|
+
|
|
15
|
+
<Example Component={RangeDefault} packageName="@atlaskit/range" />
|
|
16
|
+
|
|
17
|
+
## Form
|
|
18
|
+
|
|
19
|
+
Range used with the [Form](https://atlaskit.atlassian.com/packages/design-system/form) component.
|
|
20
|
+
|
|
21
|
+
<Example Component={RangeForm} packageName="@atlaskit/range" />
|
|
22
|
+
|
|
23
|
+
## Controlled
|
|
24
|
+
|
|
25
|
+
In a controlled range, the state is managed by the React component. Use the `onChange` handler to set the value.
|
|
26
|
+
|
|
27
|
+
<Example Component={RangeControlled} packageName="@atlaskit/range" />
|
|
28
|
+
|
|
29
|
+
## Uncontrolled
|
|
30
|
+
|
|
31
|
+
In an uncontrolled range, the state is managed by the DOM.
|
|
32
|
+
|
|
33
|
+
<Example Component={RangeUncontrolled} packageName="@atlaskit/range" />
|
|
34
|
+
|
|
35
|
+
## Disabled
|
|
36
|
+
|
|
37
|
+
Set `isDisabled` to disable a range when another action has to be completed before the range is usable.
|
|
38
|
+
|
|
39
|
+
<Example Component={RangeDisabled} packageName="@atlaskit/range" />
|
|
Binary file
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import RangeProps from '!!extract-react-types-loader!../../extract-react-types/range-props';
|
|
2
|
+
|
|
3
|
+
<PropsTable heading="" props={RangeProps} />
|
|
4
|
+
|
|
5
|
+
Additional `input` attributes are available. See <a rel="noopener noreferrer" href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range" target="_blank">MDN documentation</a> for more information.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
order: 2
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Use ranges in [forms](/patterns/forms) to let users select a value within a given range of minimum and maximum values.
|
|
8
|
+
|
|
9
|
+
## Anatomy
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
1. **Track:** The track displays the range available for the user to select from.
|
|
14
|
+
2. **Handle:** A position indicator that can be moved along the track to change the value.
|
|
15
|
+
|
|
16
|
+
## Best practices
|
|
17
|
+
|
|
18
|
+
- Place labels directly above the input, and align to the left.
|
|
19
|
+
- Do not use for ranges that are extremely large (for example, 1-1000).
|
|
20
|
+
- Do not use for ranges that are very small (for example, 1-3). The range moves in steps when the range of values is lower.
|
|
21
|
+
- Don't use a range if choosing a *specific* value is important. The slider interaction isn't as precise as explicitly typing or choosing an option from a list.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Content guidelines
|
|
25
|
+
|
|
26
|
+
- Field label text above the range input should be short and concise.
|
|
27
|
+
- If necessary, use helper text to clarify how to use the range.
|
|
28
|
+
|
|
29
|
+
## Related
|
|
30
|
+
|
|
31
|
+
- Ranges are used in [forms](/patterns/forms).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "default", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _range.default;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
var _range = _interopRequireDefault(require("./range"));
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.default = void 0;
|
|
11
|
+
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
+
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
18
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
19
|
+
|
|
20
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
21
|
+
|
|
22
|
+
var _styled = require("./styled");
|
|
23
|
+
|
|
24
|
+
var _theme = require("./theme");
|
|
25
|
+
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
+
|
|
28
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
+
|
|
30
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
+
|
|
32
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
33
|
+
|
|
34
|
+
var snapToStep = function snapToStep(value, min, step) {
|
|
35
|
+
// Normalise the value to allow for division properly with different min values
|
|
36
|
+
var adjustedValue = value - min; // Find the number of steps the value covers
|
|
37
|
+
|
|
38
|
+
var numSteps = Math.round(adjustedValue / step); // Convert numSteps back into original range
|
|
39
|
+
|
|
40
|
+
return numSteps * step + min;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var getRoundedPercentValue = function getRoundedPercentValue(value, min, max, step) {
|
|
44
|
+
var percent = '0';
|
|
45
|
+
|
|
46
|
+
if (min < max && value > min) {
|
|
47
|
+
var snappedValue = snapToStep(value, min, step);
|
|
48
|
+
percent = ((snappedValue - min) / (max - min) * 100).toFixed(2);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return percent;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var noop = function noop() {};
|
|
55
|
+
|
|
56
|
+
var _default = /*#__PURE__*/(0, _react.forwardRef)(function Range(props, ref) {
|
|
57
|
+
var _props$isDisabled = props.isDisabled,
|
|
58
|
+
isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled,
|
|
59
|
+
_props$defaultValue = props.defaultValue,
|
|
60
|
+
defaultValue = _props$defaultValue === void 0 ? 50 : _props$defaultValue,
|
|
61
|
+
_props$max = props.max,
|
|
62
|
+
max = _props$max === void 0 ? 100 : _props$max,
|
|
63
|
+
_props$min = props.min,
|
|
64
|
+
min = _props$min === void 0 ? 0 : _props$min,
|
|
65
|
+
_props$onChange = props.onChange,
|
|
66
|
+
onChange = _props$onChange === void 0 ? noop : _props$onChange,
|
|
67
|
+
_props$step = props.step,
|
|
68
|
+
step = _props$step === void 0 ? 1 : _props$step,
|
|
69
|
+
propsValue = props.value,
|
|
70
|
+
theme = props.theme,
|
|
71
|
+
testId = props.testId,
|
|
72
|
+
rest = (0, _objectWithoutProperties2.default)(props, ["isDisabled", "defaultValue", "max", "min", "onChange", "step", "value", "theme", "testId"]);
|
|
73
|
+
|
|
74
|
+
var spreadProps = _objectSpread({
|
|
75
|
+
max: max,
|
|
76
|
+
min: min,
|
|
77
|
+
step: step,
|
|
78
|
+
ref: ref
|
|
79
|
+
}, rest);
|
|
80
|
+
|
|
81
|
+
var _useState = (0, _react.useState)(propsValue !== undefined ? propsValue : defaultValue),
|
|
82
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
83
|
+
value = _useState2[0],
|
|
84
|
+
setValue = _useState2[1];
|
|
85
|
+
|
|
86
|
+
var handleChange = (0, _react.useCallback)(function (e) {
|
|
87
|
+
var newValue = Number(e.target.value);
|
|
88
|
+
setValue(newValue); // Note use of newValue to ensure up=to-date value is used
|
|
89
|
+
|
|
90
|
+
onChange(newValue);
|
|
91
|
+
}, [onChange]);
|
|
92
|
+
var renderValue = propsValue !== undefined ? propsValue : value;
|
|
93
|
+
var valuePercent = getRoundedPercentValue(renderValue, min, max, step);
|
|
94
|
+
return /*#__PURE__*/_react.default.createElement(_theme.Theme.Provider, {
|
|
95
|
+
value: theme
|
|
96
|
+
}, /*#__PURE__*/_react.default.createElement(_theme.Theme.Consumer, null, function (computedTheme) {
|
|
97
|
+
return /*#__PURE__*/_react.default.createElement(_styled.Input, (0, _extends2.default)({
|
|
98
|
+
type: "range",
|
|
99
|
+
disabled: isDisabled,
|
|
100
|
+
onChange: handleChange,
|
|
101
|
+
value: renderValue,
|
|
102
|
+
valuePercent: valuePercent,
|
|
103
|
+
"data-testid": testId
|
|
104
|
+
}, computedTheme, spreadProps));
|
|
105
|
+
}));
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
exports.default = _default;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Input = exports.rangeInputStyle = exports.overallHeight = void 0;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
|
|
14
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
15
|
+
|
|
16
|
+
var _react = require("react");
|
|
17
|
+
|
|
18
|
+
var _core = require("@emotion/core");
|
|
19
|
+
|
|
20
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
21
|
+
|
|
22
|
+
var _elevation = require("@atlaskit/theme/elevation");
|
|
23
|
+
|
|
24
|
+
var _templateObject;
|
|
25
|
+
|
|
26
|
+
var sliderThumbSize = 16;
|
|
27
|
+
var sliderThumbBorderThickness = 2;
|
|
28
|
+
var sliderLineThickness = 4;
|
|
29
|
+
var transitionDuration = '0.2s';
|
|
30
|
+
var sliderBorderRadius = sliderLineThickness / 2;
|
|
31
|
+
var overallHeight = 40;
|
|
32
|
+
exports.overallHeight = overallHeight;
|
|
33
|
+
|
|
34
|
+
var getBackgroundGradient = function getBackgroundGradient(_ref) {
|
|
35
|
+
var lower = _ref.lower,
|
|
36
|
+
upper = _ref.upper;
|
|
37
|
+
return "\n background: linear-gradient(".concat(lower, ", ").concat(lower, ") 0 / var(--range-inline-width) 100%\n no-repeat ").concat(upper, ";\n [dir='rtl'] & {\n background-position: right;\n }\n ");
|
|
38
|
+
}; // Thumb style
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
var sliderThumbStyle = function sliderThumbStyle(_ref2) {
|
|
42
|
+
var thumb = _ref2.thumb;
|
|
43
|
+
return "\n background: ".concat(thumb.default.background, ";\n border: ").concat(sliderThumbBorderThickness, "px solid transparent;\n border-radius: 50%;\n height: ").concat(sliderThumbSize, "px;\n width: ").concat(sliderThumbSize, "px;\n box-sizing: border-box;\n transition: border-color ").concat(transitionDuration, " ease-in-out;\n ").concat((0, _elevation.e200)(), ";\n ");
|
|
44
|
+
}; // Track styles
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
var sliderTrackStyle = "\n border-radius: ".concat(sliderBorderRadius, "px;\n border: 0;\n cursor: pointer;\n height: ").concat(sliderLineThickness, "px;\n width: 100%;\n transition: background-color ").concat(transitionDuration, " ease-in-out;\n"); // Range input styles
|
|
48
|
+
|
|
49
|
+
var chromeRangeInputStyle = function chromeRangeInputStyle(tokens) {
|
|
50
|
+
return "\n &::-webkit-slider-thumb {\n -webkit-appearance: none;\n margin-top: -".concat((sliderThumbSize - sliderLineThickness) / 2, "px;\n ").concat(sliderThumbStyle(tokens), ";\n }\n\n &:focus::-webkit-slider-thumb {\n border-color: ").concat(tokens.thumb.focus.border, ";\n }\n\n &:disabled::-webkit-slider-thumb {\n cursor: not-allowed;\n box-shadow: 0 0 1px ").concat(tokens.thumb.disabled.boxShadow, ";\n }\n\n &::-webkit-slider-runnable-track {\n ").concat(sliderTrackStyle, ";\n ").concat(getBackgroundGradient(tokens.track.default), ";\n }\n\n &:focus::-webkit-slider-runnable-track {\n ").concat(getBackgroundGradient(tokens.track.default), ";\n }\n\n &:active::-webkit-slider-runnable-track,\n &:hover::-webkit-slider-runnable-track {\n ").concat(getBackgroundGradient(tokens.track.hover), ";\n }\n\n &:disabled::-webkit-slider-runnable-track {\n ").concat(getBackgroundGradient(tokens.track.disabled), "\n cursor: not-allowed;\n }\n ");
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var firefoxRangeInputStyle = function firefoxRangeInputStyle(tokens) {
|
|
54
|
+
return "\n &::-moz-focus-outer {\n border: 0;\n }\n\n &::-moz-range-thumb {\n ".concat(sliderThumbStyle(tokens), ";\n }\n\n &:focus::-moz-range-thumb {\n border-color: ").concat(tokens.thumb.focus.border, ";\n }\n\n &:disabled::-moz-range-thumb {\n cursor: not-allowed;\n box-shadow: 0 0 1px ").concat(tokens.thumb.disabled.boxShadow, ";\n }\n\n &::-moz-range-progress {\n ").concat(sliderTrackStyle, ";\n background: ").concat(tokens.track.default.lower, ";\n }\n\n &::-moz-range-track {\n ").concat(sliderTrackStyle, ";\n background: ").concat(tokens.track.default.upper, ";\n }\n\n &:active::-moz-range-progress,\n &:hover::-moz-range-progress {\n background: ").concat(tokens.track.hover.lower, ";\n }\n\n &:active::-moz-range-track,\n &:hover::-moz-range-track {\n background: ").concat(tokens.track.hover.upper, ";\n }\n\n &:disabled::-moz-range-progress {\n background: ").concat(tokens.track.disabled.lower, ";\n cursor: not-allowed;\n }\n\n &:disabled::-moz-range-track {\n background: ").concat(tokens.track.disabled.upper, ";\n cursor: not-allowed;\n }\n");
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
var IERangeInputStyle = function IERangeInputStyle(tokens) {
|
|
58
|
+
return "\n &::-ms-thumb {\n margin-top: 0;\n ".concat(sliderThumbStyle(tokens), ";\n }\n\n &:focus::-ms-thumb {\n border-color: ").concat(tokens.thumb.focus.border, ";\n }\n\n &:disabled::-ms-thumb {\n cursor: not-allowed;\n box-shadow: 0 0 1px ").concat(tokens.thumb.disabled.boxShadow, ";\n }\n\n &::-ms-track {\n background: transparent;\n border-color: transparent;\n color: transparent;\n cursor: pointer;\n height: ").concat(sliderLineThickness, "px;\n transition: background-color ").concat(transitionDuration, " ease-in-out;\n width: 100%;\n }\n\n &::-ms-fill-lower {\n background: ").concat(tokens.track.default.lower, ";\n border-radius: ").concat(sliderBorderRadius, "px;\n border: 0;\n }\n\n &::-ms-fill-upper {\n background: ").concat(tokens.track.default.upper, ";\n border-radius: ").concat(sliderBorderRadius, "px;\n border: 0;\n }\n\n &:active::-ms-fill-lower,\n &:hover::-ms-fill-lower {\n background: ").concat(tokens.track.hover.lower, ";\n }\n\n &:active::-ms-fill-upper,\n &:hover::-ms-fill-upper {\n background: ").concat(tokens.track.hover.upper, ";\n }\n\n &:disabled::-ms-fill-lower {\n background: ").concat(tokens.track.disabled.lower, ";\n cursor: not-allowed;\n }\n\n &:disabled::-ms-fill-upper {\n background: ").concat(tokens.track.disabled.upper, ";\n cursor: not-allowed;\n }\n");
|
|
59
|
+
}; // Styles are split per browser as they are implemented differently
|
|
60
|
+
// Cannot consolidate as Chrome & Firefox don't recognise styles if they are grouped
|
|
61
|
+
// with CSS selectors they don't recognise, e.g. &::-ms-thumb
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
var rangeInputStyle = function rangeInputStyle(tokens) {
|
|
65
|
+
return (0, _core.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n -webkit-appearance: none; /* Hides the slider so that custom slider can be made */\n background: transparent; /* Otherwise white in Chrome */\n height: ", "px; /* Otherwise thumb will collide with previous box element */\n padding: 0; /* IE11 includes padding, this normalises it */\n width: 100%; /* Specific width is required for Firefox. */\n\n &:focus {\n outline: none;\n }\n\n &:disabled {\n cursor: not-allowed;\n }\n\n ", "\n ", "\n ", ";\n\n font-family: ", ";\n\n background-position: right;\n "])), overallHeight, chromeRangeInputStyle(tokens), firefoxRangeInputStyle(tokens), IERangeInputStyle(tokens), (0, _constants.fontFamily)());
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
exports.rangeInputStyle = rangeInputStyle;
|
|
69
|
+
var Input = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
70
|
+
var valuePercent = props.valuePercent,
|
|
71
|
+
thumb = props.thumb,
|
|
72
|
+
track = props.track,
|
|
73
|
+
style = props.style,
|
|
74
|
+
strippedProps = (0, _objectWithoutProperties2.default)(props, ["valuePercent", "thumb", "track", "style"]); // Note: emotion will cache unique outputs as their own this
|
|
75
|
+
// We are memoizing the creation of this string
|
|
76
|
+
|
|
77
|
+
var styles = (0, _react.useMemo)(function () {
|
|
78
|
+
return rangeInputStyle({
|
|
79
|
+
track: track,
|
|
80
|
+
thumb: thumb
|
|
81
|
+
});
|
|
82
|
+
}, [thumb, track]); // We are creating a css variable to control the "progress" portion of the range input
|
|
83
|
+
// This avoids us needing to create a new css class for each new percentage value
|
|
84
|
+
|
|
85
|
+
return (0, _core.jsx)("input", (0, _extends2.default)({}, strippedProps, {
|
|
86
|
+
style: {
|
|
87
|
+
'--range-inline-width': "".concat(valuePercent, "%")
|
|
88
|
+
},
|
|
89
|
+
ref: ref,
|
|
90
|
+
css: styles
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
exports.Input = Input;
|
|
94
|
+
Input.displayName = 'InputRange';
|