@atlaskit/range 5.1.4 → 6.0.2

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.
@@ -1,257 +1,134 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
 
3
3
  /** @jsx jsx */
4
-
5
- /* eslint-disable no-mixed-operators */
6
- import { forwardRef, useMemo } from 'react';
4
+ import { forwardRef } from 'react';
7
5
  import { css, jsx } from '@emotion/core';
8
- import { N50A, N60A } from '@atlaskit/theme/colors';
9
- import { fontFamily } from '@atlaskit/theme/constants';
10
- const sliderThumbSize = 16;
11
- const sliderThumbBorderThickness = 2;
12
- const sliderLineThickness = 4;
13
- const transitionDuration = '0.2s';
14
- const sliderBorderRadius = sliderLineThickness / 2;
15
- export const overallHeight = 40;
16
-
17
- const getBackgroundGradient = ({
18
- lower,
19
- upper
20
- }) => `
21
- background: linear-gradient(${lower}, ${lower}) 0 / var(--range-inline-width) 100%
22
- no-repeat ${upper};
23
- [dir='rtl'] & {
24
- background-position: right;
25
- }
26
- `;
27
-
28
- const elevationStyle = `var(--ds-shadow-overlay, ${`0 4px 8px -2px ${N50A}, 0 0 1px ${N60A}`})`; // Thumb style
29
-
30
- const sliderThumbStyle = ({
31
- thumb
32
- }) => {
33
- return `
34
- background: ${thumb.default.background};
35
- border: ${sliderThumbBorderThickness}px solid transparent;
36
- border-radius: 50%;
37
- height: ${sliderThumbSize}px;
38
- width: ${sliderThumbSize}px;
39
- box-sizing: border-box;
40
- transition: border-color ${transitionDuration} ease-in-out;
41
- box-shadow: ${elevationStyle}
42
- `;
43
- }; // Track styles
44
-
45
-
46
- const sliderTrackStyle = `
47
- border-radius: ${sliderBorderRadius}px;
48
- border: 0;
49
- cursor: pointer;
50
- height: ${sliderLineThickness}px;
51
- width: 100%;
52
- transition: background-color ${transitionDuration} ease-in-out;
53
- `; // Range input styles
54
-
55
- const chromeRangeInputStyle = tokens => {
56
- return `
57
- &::-webkit-slider-thumb {
58
- -webkit-appearance: none;
59
- margin-top: -${(sliderThumbSize - sliderLineThickness) / 2}px;
60
- ${sliderThumbStyle(tokens)};
61
- }
62
-
63
- &:focus::-webkit-slider-thumb {
64
- border-color: ${tokens.thumb.focus.border};
65
- }
66
-
67
- &:disabled::-webkit-slider-thumb {
68
- cursor: not-allowed;
69
- box-shadow: ${tokens.thumb.disabled.boxShadow};
70
- }
71
-
72
- &::-webkit-slider-runnable-track {
73
- ${sliderTrackStyle};
74
- ${getBackgroundGradient(tokens.track.default)};
75
- }
76
-
77
- &:focus::-webkit-slider-runnable-track {
78
- ${getBackgroundGradient(tokens.track.default)};
79
- }
80
-
81
- &:active::-webkit-slider-runnable-track,
82
- &:hover::-webkit-slider-runnable-track {
83
- ${getBackgroundGradient(tokens.track.hover)};
84
- }
85
-
86
- &:disabled::-webkit-slider-runnable-track {
87
- ${getBackgroundGradient(tokens.track.disabled)}
88
- cursor: not-allowed;
89
- }
90
- `;
6
+ import * as theme from './theme';
7
+ const VAR_THUMB_BORDER_COLOR = '--thumb-border';
8
+ const VAR_THUMB_SHADOW = '--thumb-shadow';
9
+ const VAR_TRACK_BACKGROUND_COLOR = '--track-bg';
10
+ const VAR_TRACK_FOREGROUND_COLOR = '--track-fg';
11
+ const VAR_TRACK_FOREGROUND_WIDTH = '--track-fg-width';
12
+ const sliderThumbStyles = {
13
+ boxSizing: 'border-box',
14
+ width: theme.thumb.size,
15
+ height: theme.thumb.size,
16
+ background: theme.thumb.background,
17
+ border: `${theme.thumb.borderWidth}px solid var(${VAR_THUMB_BORDER_COLOR})`,
18
+ borderRadius: '50%',
19
+ boxShadow: `var(${VAR_THUMB_SHADOW})`,
20
+ cursor: 'pointer',
21
+ // Different implicit behavior across browsers -> making it explicit
22
+ transition: `border-color ${theme.transitionDuration} ease-in-out`
91
23
  };
92
-
93
- const firefoxRangeInputStyle = tokens => {
94
- return `
95
- &::-moz-focus-outer {
96
- border: 0;
97
- }
98
-
99
- &::-moz-range-thumb {
100
- ${sliderThumbStyle(tokens)};
101
- }
102
-
103
- &:focus::-moz-range-thumb {
104
- border-color: ${tokens.thumb.focus.border};
105
- }
106
-
107
- &:disabled::-moz-range-thumb {
108
- cursor: not-allowed;
109
- box-shadow: ${tokens.thumb.disabled.boxShadow};
110
- }
111
-
112
- &::-moz-range-progress {
113
- ${sliderTrackStyle};
114
- background: ${tokens.track.default.lower};
115
- }
116
-
117
- &::-moz-range-track {
118
- ${sliderTrackStyle};
119
- background: ${tokens.track.default.upper};
120
- }
121
-
122
- &:active::-moz-range-progress,
123
- &:hover::-moz-range-progress {
124
- background: ${tokens.track.hover.lower};
125
- }
126
-
127
- &:active::-moz-range-track,
128
- &:hover::-moz-range-track {
129
- background: ${tokens.track.hover.upper};
130
- }
131
-
132
- &:disabled::-moz-range-progress {
133
- background: ${tokens.track.disabled.lower};
134
- cursor: not-allowed;
135
- }
136
-
137
- &:disabled::-moz-range-track {
138
- background: ${tokens.track.disabled.upper};
139
- cursor: not-allowed;
140
- }
141
- `;
142
- };
143
-
144
- const IERangeInputStyle = tokens => {
145
- return `
146
- &::-ms-thumb {
147
- margin-top: 0;
148
- ${sliderThumbStyle(tokens)};
149
- }
150
-
151
- &:focus::-ms-thumb {
152
- border-color: ${tokens.thumb.focus.border};
153
- }
154
-
155
- &:disabled::-ms-thumb {
156
- cursor: not-allowed;
157
- box-shadow: ${tokens.thumb.disabled.boxShadow};
158
- }
159
-
160
- &::-ms-track {
161
- background: transparent;
162
- border-color: transparent;
163
- color: transparent;
164
- cursor: pointer;
165
- height: ${sliderLineThickness}px;
166
- transition: background-color ${transitionDuration} ease-in-out;
167
- width: 100%;
168
- }
169
-
170
- &::-ms-fill-lower {
171
- background: ${tokens.track.default.lower};
172
- border-radius: ${sliderBorderRadius}px;
173
- border: 0;
174
- }
175
-
176
- &::-ms-fill-upper {
177
- background: ${tokens.track.default.upper};
178
- border-radius: ${sliderBorderRadius}px;
179
- border: 0;
180
- }
181
-
182
- &:active::-ms-fill-lower,
183
- &:hover::-ms-fill-lower {
184
- background: ${tokens.track.hover.lower};
185
- }
186
-
187
- &:active::-ms-fill-upper,
188
- &:hover::-ms-fill-upper {
189
- background: ${tokens.track.hover.upper};
190
- }
191
-
192
- &:disabled::-ms-fill-lower {
193
- background: ${tokens.track.disabled.lower};
194
- cursor: not-allowed;
195
- }
196
-
197
- &:disabled::-ms-fill-upper {
198
- background: ${tokens.track.disabled.upper};
199
- cursor: not-allowed;
200
- }
201
- `;
24
+ const sliderTrackStyles = {
25
+ borderRadius: theme.track.borderRadius,
26
+ border: 0,
27
+ cursor: 'pointer',
28
+ height: theme.track.height,
29
+ width: '100%',
30
+ transition: `background-color ${theme.transitionDuration} ease-in-out`
202
31
  }; // Styles are split per browser as they are implemented differently
203
32
  // Cannot consolidate as Chrome & Firefox don't recognise styles if they are grouped
204
33
  // with CSS selectors they don't recognise, e.g. &::-ms-thumb
205
34
 
206
-
207
- export const rangeInputStyle = tokens => {
208
- return css`
209
- -webkit-appearance: none; /* Hides the slider so that custom slider can be made */
210
- background: transparent; /* Otherwise white in Chrome */
211
- height: ${overallHeight}px; /* Otherwise thumb will collide with previous box element */
212
- padding: 0; /* IE11 includes padding, this normalises it */
213
- width: 100%; /* Specific width is required for Firefox. */
214
-
215
- &:focus {
216
- outline: none;
35
+ const browserStyles = {
36
+ webkit: css({
37
+ WebkitAppearance: 'none',
38
+ // Hides the slider so that custom slider can be made
39
+ '::-webkit-slider-thumb': { ...sliderThumbStyles,
40
+ marginTop: -(theme.thumb.size - theme.track.height) / 2,
41
+ WebkitAppearance: 'none'
42
+ },
43
+ '::-webkit-slider-runnable-track': { ...sliderTrackStyles,
44
+
45
+ /**
46
+ * Webkit does not have separate properties for the background/foreground like firefox.
47
+ * Instead we use background layering:
48
+ * - The gray background is a simple background color.
49
+ * - The blue foreground is a 'gradient' (to create a color block) that is sized to the progress.
50
+ *
51
+ * Individual properties have been used over the `background` shorthand for readability.
52
+ */
53
+ backgroundColor: `var(${VAR_TRACK_BACKGROUND_COLOR})`,
54
+ backgroundImage: `linear-gradient(var(${VAR_TRACK_FOREGROUND_COLOR}), var(${VAR_TRACK_FOREGROUND_COLOR}))`,
55
+ backgroundRepeat: 'no-repeat',
56
+ backgroundSize: `var(${VAR_TRACK_FOREGROUND_WIDTH}) 100%`,
57
+ // eslint-disable-next-line @repo/internal/styles/no-nested-styles
58
+ '[dir="rtl"] &': {
59
+ backgroundPosition: 'right'
60
+ }
61
+ },
62
+ ':disabled': {
63
+ '::-webkit-slider-thumb, ::-webkit-slider-runnable-track': {
64
+ cursor: 'not-allowed'
65
+ }
217
66
  }
218
-
219
- &:disabled {
220
- cursor: not-allowed;
67
+ }),
68
+ firefox: css({
69
+ '::-moz-range-thumb': sliderThumbStyles,
70
+ '::-moz-focus-outer': {
71
+ border: 0
72
+ },
73
+ '::-moz-range-progress': { ...sliderTrackStyles,
74
+ background: `var(${VAR_TRACK_FOREGROUND_COLOR})`
75
+ },
76
+ '::-moz-range-track': { ...sliderTrackStyles,
77
+ background: `var(${VAR_TRACK_BACKGROUND_COLOR})`
78
+ },
79
+ ':disabled': {
80
+ '::-moz-range-thumb, ::-moz-range-progress, ::-moz-range-track': {
81
+ cursor: 'not-allowed'
82
+ }
221
83
  }
222
-
223
- ${chromeRangeInputStyle(tokens)}
224
- ${firefoxRangeInputStyle(tokens)}
225
- ${IERangeInputStyle(tokens)};
226
-
227
- font-family: ${fontFamily()};
228
-
229
- background-position: right;
230
- `;
84
+ })
231
85
  };
86
+ const baseStyles = css({
87
+ width: '100%',
88
+ // Has a fixed width by default
89
+ height: theme.input.height,
90
+ // Otherwise thumb will collide with previous box element
91
+ background: 'transparent',
92
+ // Otherwise white
93
+ ':focus': {
94
+ outline: 'none'
95
+ },
96
+ ':disabled': {
97
+ cursor: 'not-allowed'
98
+ }
99
+ });
100
+ const themeStyles = css({
101
+ [VAR_THUMB_BORDER_COLOR]: theme.thumb.borderColor.default,
102
+ [VAR_THUMB_SHADOW]: theme.thumb.boxShadow.default,
103
+ [VAR_TRACK_BACKGROUND_COLOR]: theme.track.background.default,
104
+ [VAR_TRACK_FOREGROUND_COLOR]: theme.track.foreground.default,
105
+ ':active, :hover': {
106
+ [VAR_TRACK_BACKGROUND_COLOR]: theme.track.background.hovered,
107
+ [VAR_TRACK_FOREGROUND_COLOR]: theme.track.foreground.hovered
108
+ },
109
+ ':focus': {
110
+ [VAR_THUMB_BORDER_COLOR]: theme.thumb.borderColor.focused
111
+ },
112
+ ':disabled': {
113
+ [VAR_THUMB_SHADOW]: theme.thumb.boxShadow.disabled,
114
+ [VAR_TRACK_BACKGROUND_COLOR]: theme.track.background.disabled,
115
+ [VAR_TRACK_FOREGROUND_COLOR]: theme.track.foreground.disabled
116
+ }
117
+ });
232
118
  export const Input = /*#__PURE__*/forwardRef((props, ref) => {
233
119
  const {
234
120
  valuePercent,
235
- thumb,
236
- track,
237
121
  style,
238
122
  ...strippedProps
239
- } = props; // Note: emotion will cache unique outputs as their own this
240
- // We are memoizing the creation of this string
241
-
242
- const styles = useMemo(() => rangeInputStyle({
243
- track,
244
- thumb
245
- }), [thumb, track]); // We are creating a css variable to control the "progress" portion of the range input
246
- // This avoids us needing to create a new css class for each new percentage value
247
-
123
+ } = props;
248
124
  return jsx("input", _extends({}, strippedProps, {
249
125
  style: {
250
- '--range-inline-width': `${valuePercent}%`
126
+ // We are creating a css variable to control the "progress" portion of the range input
127
+ // This avoids us needing to create a new css class for each new percentage value
128
+ [VAR_TRACK_FOREGROUND_WIDTH]: `${valuePercent}%`
251
129
  },
252
- ref: ref // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
253
- ,
254
- css: styles
130
+ ref: ref,
131
+ css: [baseStyles, browserStyles.webkit, browserStyles.firefox, themeStyles]
255
132
  }));
256
133
  });
257
134
  Input.displayName = 'InputRange';
@@ -1,32 +1,37 @@
1
1
  import * as colors from '@atlaskit/theme/colors';
2
- import { createTheme } from '@atlaskit/theme/components';
2
+ export const transitionDuration = '0.2s';
3
+ export const input = {
4
+ height: 40
5
+ };
3
6
  export const thumb = {
4
- default: {
5
- background: `var(--ds-surface-raised, ${colors.N0})`
6
- },
7
- disabled: {
8
- boxShadow: `var(--ds-shadow-raised, ${`0 0 1px ${colors.N60A}`})`
7
+ size: 16,
8
+ borderWidth: 2,
9
+ background: `var(--ds-surface-raised, ${colors.N0})`,
10
+ borderColor: {
11
+ default: 'transparent',
12
+ focused: `var(--ds-border-focused, ${colors.B200})`
9
13
  },
10
- focus: {
11
- background: `var(--ds-background-neutral-bold, ${colors.N0})`,
12
- border: `var(--ds-border-focused, ${colors.B200})`
14
+ boxShadow: {
15
+ default: `var(--ds-shadow-overlay, ${`0 4px 8px -2px ${colors.N50A}, 0 0 1px ${colors.N60A}`})`,
16
+ disabled: `var(--ds-shadow-raised, ${`0 0 1px ${colors.N60A}`})`
13
17
  }
14
18
  };
15
19
  export const track = {
16
- default: {
17
- lower: `var(--ds-background-brand-bold, ${colors.B400})`,
18
- upper: `var(--ds-background-neutral, ${colors.N30})`
20
+ height: 4,
21
+
22
+ /**
23
+ * borderRadius >= height / 2 to create a pill shape.
24
+ * Using '50%' creates an ellipse.
25
+ */
26
+ borderRadius: 2,
27
+ background: {
28
+ default: `var(--ds-background-neutral, ${colors.N30})`,
29
+ hovered: `var(--ds-background-neutral-hovered, ${colors.N40})`,
30
+ disabled: `var(--ds-background-disabled, ${colors.N30})`
19
31
  },
20
- disabled: {
21
- lower: `var(--ds-text-disabled, ${colors.N50})`,
22
- upper: `var(--ds-background-disabled, ${colors.N30})`
23
- },
24
- hover: {
25
- lower: `var(--ds-background-brand-bold-hovered, ${colors.B300})`,
26
- upper: `var(--ds-background-neutral-hovered, ${colors.N40})`
32
+ foreground: {
33
+ default: `var(--ds-background-brand-bold, ${colors.B400})`,
34
+ hovered: `var(--ds-background-brand-bold-hovered, ${colors.B300})`,
35
+ disabled: `var(--ds-text-disabled, ${colors.N50})`
27
36
  }
28
- };
29
- export const Theme = createTheme(() => ({
30
- thumb,
31
- track
32
- }));
37
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/range",
3
- "version": "5.1.4",
3
+ "version": "6.0.2",
4
4
  "sideEffects": false
5
5
  }
package/dist/esm/range.js CHANGED
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
- var _excluded = ["isDisabled", "defaultValue", "max", "min", "onChange", "step", "value", "theme", "testId"];
5
+ var _excluded = ["isDisabled", "defaultValue", "max", "min", "onChange", "step", "value", "testId"];
6
6
 
7
7
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
8
 
@@ -10,7 +10,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
10
10
 
11
11
  import React, { forwardRef, useCallback, useState } from 'react';
12
12
  import { Input } from './styled';
13
- import { Theme } from './theme';
14
13
 
15
14
  var snapToStep = function snapToStep(value, min, step) {
16
15
  // Normalise the value to allow for division properly with different min values
@@ -48,7 +47,6 @@ export default /*#__PURE__*/forwardRef(function Range(props, ref) {
48
47
  _props$step = props.step,
49
48
  step = _props$step === void 0 ? 1 : _props$step,
50
49
  propsValue = props.value,
51
- theme = props.theme,
52
50
  testId = props.testId,
53
51
  rest = _objectWithoutProperties(props, _excluded);
54
52
 
@@ -72,16 +70,12 @@ export default /*#__PURE__*/forwardRef(function Range(props, ref) {
72
70
  }, [onChange]);
73
71
  var renderValue = propsValue !== undefined ? propsValue : value;
74
72
  var valuePercent = getRoundedPercentValue(renderValue, min, max, step);
75
- return /*#__PURE__*/React.createElement(Theme.Provider, {
76
- value: theme
77
- }, /*#__PURE__*/React.createElement(Theme.Consumer, null, function (computedTheme) {
78
- return /*#__PURE__*/React.createElement(Input, _extends({
79
- type: "range",
80
- disabled: isDisabled,
81
- onChange: handleChange,
82
- value: renderValue,
83
- valuePercent: valuePercent,
84
- "data-testid": testId
85
- }, computedTheme, spreadProps));
86
- }));
73
+ return /*#__PURE__*/React.createElement(Input, _extends({
74
+ type: "range",
75
+ disabled: isDisabled,
76
+ onChange: handleChange,
77
+ value: renderValue,
78
+ valuePercent: valuePercent,
79
+ "data-testid": testId
80
+ }, spreadProps));
87
81
  });