@skyscanner/backpack-web 34.16.0-preminor.1 → 34.16.0-preminor.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.
Files changed (37) hide show
  1. package/bpk-component-calendar/src/BpkCalendarContainer.js +0 -1
  2. package/bpk-component-carousel/src/utils.test.js +18 -0
  3. package/bpk-component-close-button/src/BpkCloseButton.d.ts +10 -0
  4. package/bpk-component-close-button/src/BpkCloseButton.js +21 -37
  5. package/bpk-component-input/src/BpkInput.js +1 -1
  6. package/bpk-component-input/src/common-types.d.ts +1 -1
  7. package/bpk-component-loading-button/src/BpkLoadingButton.d.ts +6 -38
  8. package/bpk-component-loading-button/src/BpkLoadingButton.js +13 -44
  9. package/bpk-component-nudger/index.d.ts +1 -2
  10. package/bpk-component-nudger/index.js +1 -2
  11. package/bpk-component-nudger/src/BpkNudger.d.ts +1 -1
  12. package/bpk-component-nudger/src/BpkNudger.js +102 -20
  13. package/bpk-component-nudger/src/BpkNudger.module.css +1 -1
  14. package/bpk-component-nudger/src/common-types.d.ts +7 -5
  15. package/bpk-component-slider/src/BpkSlider.d.ts +4 -1
  16. package/bpk-component-slider/src/BpkSlider.js +51 -3
  17. package/bpk-component-snippet/index.d.ts +3 -0
  18. package/bpk-component-snippet/index.js +21 -0
  19. package/bpk-component-snippet/src/BpkSnippet.d.ts +48 -0
  20. package/bpk-component-snippet/src/BpkSnippet.js +131 -0
  21. package/bpk-component-snippet/src/BpkSnippet.module.css +18 -0
  22. package/bpk-component-spinner/src/BpkExtraLargeSpinner.d.ts +4 -14
  23. package/bpk-component-spinner/src/BpkExtraLargeSpinner.js +5 -16
  24. package/bpk-component-spinner/src/BpkLargeSpinner.d.ts +5 -17
  25. package/bpk-component-spinner/src/BpkLargeSpinner.js +6 -19
  26. package/bpk-component-spinner/src/BpkSpinner.d.ts +5 -17
  27. package/bpk-component-spinner/src/BpkSpinner.js +6 -19
  28. package/bpk-component-split-input/src/BpkInputField.d.ts +21 -0
  29. package/bpk-component-split-input/src/BpkInputField.js +12 -17
  30. package/bpk-component-split-input/src/BpkSplitInput.d.ts +44 -0
  31. package/bpk-component-split-input/src/BpkSplitInput.js +22 -33
  32. package/bpk-react-utils/src/nativeEventHandler.d.ts +1 -1
  33. package/bpk-react-utils/src/nativeEventHandler.js +7 -5
  34. package/bpk-theming/src/BpkThemeProvider.js +19 -30
  35. package/package.json +5 -3
  36. package/bpk-component-nudger/src/BpkConfigurableNudger.d.ts +0 -26
  37. package/bpk-component-nudger/src/BpkConfigurableNudger.js +0 -96
@@ -119,7 +119,6 @@ const withCalendarState = Calendar => {
119
119
  const rawNextSelectedDate = getRawSelectedDate(nextProps.selectionConfiguration);
120
120
  const minDate = startOfDay(nextProps.minDate);
121
121
  const maxDate = startOfDay(nextProps.maxDate);
122
- // @ts-ignore
123
122
  if (focusedDateHasChanged(this.props, nextProps)) {
124
123
  this.setState({
125
124
  focusedDate: dateToBoundaries(rawNextSelectedDate[0], minDate, maxDate)
@@ -1,3 +1,21 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2022 Skyscanner Ltd
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
1
19
  import { renderHook } from '@testing-library/react';
2
20
  import { useScrollToInitialImage } from "./utils";
3
21
  describe('useScrollToInitialImage', () => {
@@ -0,0 +1,10 @@
1
+ import type { SyntheticEvent, FunctionComponent } from 'react';
2
+ type Props = {
3
+ label: string;
4
+ onClick: (event: SyntheticEvent<any>) => any;
5
+ className?: string | null;
6
+ customIcon?: FunctionComponent<any> | null;
7
+ onDark?: Boolean;
8
+ };
9
+ declare const BpkCloseButton: ({ className, customIcon, label, onClick, onDark, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
10
+ export default BpkCloseButton;
@@ -14,53 +14,37 @@
14
14
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
- */import PropTypes from 'prop-types';
17
+ */
18
+
18
19
  import CloseIcon from "../../bpk-component-icon/sm/close";
19
20
  import { cssModules } from "../../bpk-react-utils";
20
21
  import STYLES from "./BpkCloseButton.module.css";
21
22
  import { jsx as _jsx } from "react/jsx-runtime";
22
23
  const getClassName = cssModules(STYLES);
23
- const BpkCloseButton = props => {
24
- const {
25
- className,
26
- customIcon,
27
- label,
28
- onClick,
29
- onDark,
30
- ...rest
31
- } = props;
24
+ const BpkCloseButton = ({
25
+ className = null,
26
+ customIcon = null,
27
+ label,
28
+ onClick,
29
+ onDark = false,
30
+ ...rest
31
+ }) => {
32
32
  const classNames = [onDark ? getClassName('bpk-close-button__onDark') : getClassName('bpk-close-button__default')];
33
33
  const Icon = customIcon || CloseIcon;
34
34
  if (className) {
35
35
  classNames.push(className);
36
36
  }
37
- return (
38
- /*#__PURE__*/
39
- // $FlowFixMe[cannot-spread-inexact] - inexact rest. See decisions/flowfixme.md
40
- _jsx("button", {
41
- type: "button",
42
- title: label,
43
- onClick: onClick,
44
- "aria-label": label,
45
- className: classNames.join(' '),
46
- ...rest,
47
- children: /*#__PURE__*/_jsx("span", {
48
- className: getClassName('bpk-close-button-icon'),
49
- children: /*#__PURE__*/_jsx(Icon, {})
50
- })
37
+ return /*#__PURE__*/_jsx("button", {
38
+ type: "button",
39
+ title: label,
40
+ onClick: onClick,
41
+ "aria-label": label,
42
+ className: classNames.join(' '),
43
+ ...rest,
44
+ children: /*#__PURE__*/_jsx("span", {
45
+ className: getClassName('bpk-close-button-icon'),
46
+ children: /*#__PURE__*/_jsx(Icon, {})
51
47
  })
52
- );
53
- };
54
- BpkCloseButton.propTypes = {
55
- label: PropTypes.string.isRequired,
56
- onClick: PropTypes.func.isRequired,
57
- className: PropTypes.string,
58
- customIcon: PropTypes.func,
59
- onDark: PropTypes.bool
60
- };
61
- BpkCloseButton.defaultProps = {
62
- className: null,
63
- customIcon: null,
64
- onDark: false
48
+ });
65
49
  };
66
50
  export default BpkCloseButton;
@@ -120,7 +120,7 @@ class BpkInput extends Component {
120
120
  };
121
121
  return clearable ? /*#__PURE__*/_jsxs("div", {
122
122
  className: containerClassNames.join(' '),
123
- children: [renderedInput, value.length > 0 && /*#__PURE__*/_jsx("button", {
123
+ children: [renderedInput, `${value}`.length > 0 && /*#__PURE__*/_jsx("button", {
124
124
  type: "button",
125
125
  title: clearButtonLabel || '',
126
126
  "aria-label": clearButtonLabel || '',
@@ -24,7 +24,7 @@ type InputProps = {
24
24
  /**
25
25
  * **Required:** The value attribute of the input.
26
26
  */
27
- value: string;
27
+ value: string | number;
28
28
  type?: (typeof INPUT_TYPES)[keyof typeof INPUT_TYPES];
29
29
  };
30
30
  type BaseProps = InputProps & ComponentProps<'input'> & {
@@ -1,5 +1,5 @@
1
- import PropTypes from 'prop-types';
2
1
  import type { ReactElement, ReactNode } from 'react';
2
+ import type { Props as ButtonProps } from '../../bpk-component-button/src/BpkButtonV2/common-types';
3
3
  export declare const ICON_POSITION: {
4
4
  LEADING: string;
5
5
  TRAILING: string;
@@ -17,44 +17,12 @@ type LoadingProps = {
17
17
  large?: boolean;
18
18
  link?: boolean;
19
19
  linkOnDark?: boolean;
20
- loading: boolean;
21
- iconOnly: boolean;
20
+ loading?: boolean;
21
+ iconOnly?: boolean;
22
22
  icon?: ReactElement<any>;
23
- iconPosition: string;
23
+ iconPosition?: (typeof ICON_POSITION)[keyof typeof ICON_POSITION];
24
24
  iconDisabled?: ReactElement<any>;
25
25
  iconLoading?: ReactElement<any>;
26
- };
27
- declare const BpkLoadingButton: {
28
- (props: LoadingProps): import("react/jsx-runtime").JSX.Element;
29
- propTypes: {
30
- children: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
31
- className: PropTypes.Requireable<string>;
32
- disabled: PropTypes.Requireable<boolean>;
33
- secondary: PropTypes.Requireable<boolean>;
34
- destructive: PropTypes.Requireable<boolean>;
35
- link: PropTypes.Requireable<boolean>;
36
- linkOnDark: PropTypes.Requireable<boolean>;
37
- loading: PropTypes.Requireable<boolean>;
38
- iconOnly: PropTypes.Requireable<boolean>;
39
- icon: PropTypes.Requireable<PropTypes.ReactElementLike>;
40
- iconPosition: PropTypes.Requireable<string>;
41
- iconDisabled: PropTypes.Requireable<PropTypes.ReactElementLike>;
42
- iconLoading: PropTypes.Requireable<PropTypes.ReactElementLike>;
43
- };
44
- defaultProps: {
45
- className: null;
46
- disabled: boolean;
47
- secondary: boolean;
48
- destructive: boolean;
49
- large: boolean;
50
- link: boolean;
51
- linkOnDark: boolean;
52
- loading: boolean;
53
- iconOnly: boolean;
54
- icon: null;
55
- iconPosition: string;
56
- iconDisabled: null;
57
- iconLoading: null;
58
- };
59
- };
26
+ } & ButtonProps;
27
+ declare const BpkLoadingButton: (props: LoadingProps) => import("react/jsx-runtime").JSX.Element;
60
28
  export default BpkLoadingButton;
@@ -16,7 +16,6 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- import PropTypes from 'prop-types';
20
19
  import { BUTTON_TYPES, BpkButtonV2, SIZE_TYPES } from "../../bpk-component-button";
21
20
  import { withButtonAlignment, withLargeButtonAlignment, withRtlSupport } from "../../bpk-component-icon";
22
21
  import ArrowIconLg from "../../bpk-component-icon/lg/long-arrow-right";
@@ -60,22 +59,22 @@ const getLoadingIcon = props => {
60
59
  const BpkLoadingButton = props => {
61
60
  const {
62
61
  children,
63
- destructive,
64
- disabled,
65
- featured,
62
+ destructive = false,
63
+ disabled = false,
64
+ featured = false,
66
65
  icon,
67
66
  iconDisabled,
68
67
  iconLoading,
69
- iconOnly,
70
- iconPosition,
71
- large,
72
- link,
73
- linkOnDark,
74
- loading,
75
- primaryOnDark,
76
- primaryOnLight,
77
- secondary,
78
- secondaryOnDark,
68
+ iconOnly = false,
69
+ iconPosition = ICON_POSITION.TRAILING,
70
+ large = false,
71
+ link = false,
72
+ linkOnDark = false,
73
+ loading = false,
74
+ primaryOnDark = false,
75
+ primaryOnLight = false,
76
+ secondary = false,
77
+ secondaryOnDark = false,
79
78
  ...rest
80
79
  } = props;
81
80
  const showBtnDisabled = disabled || loading;
@@ -127,34 +126,4 @@ const BpkLoadingButton = props => {
127
126
  })
128
127
  });
129
128
  };
130
- BpkLoadingButton.propTypes = {
131
- children: PropTypes.node.isRequired,
132
- className: PropTypes.string,
133
- disabled: PropTypes.bool,
134
- secondary: PropTypes.bool,
135
- destructive: PropTypes.bool,
136
- link: PropTypes.bool,
137
- linkOnDark: PropTypes.bool,
138
- loading: PropTypes.bool,
139
- iconOnly: PropTypes.bool,
140
- icon: PropTypes.element,
141
- iconPosition: PropTypes.oneOf([ICON_POSITION.LEADING, ICON_POSITION.TRAILING]),
142
- iconDisabled: PropTypes.element,
143
- iconLoading: PropTypes.element
144
- };
145
- BpkLoadingButton.defaultProps = {
146
- className: null,
147
- disabled: false,
148
- secondary: false,
149
- destructive: false,
150
- large: false,
151
- link: false,
152
- linkOnDark: false,
153
- loading: false,
154
- iconOnly: false,
155
- icon: null,
156
- iconPosition: ICON_POSITION.TRAILING,
157
- iconDisabled: null,
158
- iconLoading: null
159
- };
160
129
  export default BpkLoadingButton;
@@ -1,5 +1,4 @@
1
- import BpkConfigurableNudger from './src/BpkConfigurableNudger';
2
1
  import BpkNudger from './src/BpkNudger';
3
2
  import themeAttributes from './src/themeAttributes';
4
3
  export default BpkNudger;
5
- export { themeAttributes, BpkConfigurableNudger };
4
+ export { themeAttributes };
@@ -16,8 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- import BpkConfigurableNudger from "./src/BpkConfigurableNudger";
20
19
  import BpkNudger from "./src/BpkNudger";
21
20
  import themeAttributes from "./src/themeAttributes";
22
21
  export default BpkNudger;
23
- export { themeAttributes, BpkConfigurableNudger };
22
+ export { themeAttributes };
@@ -1,3 +1,3 @@
1
1
  import { type CommonProps } from './common-types';
2
- declare const BpkNudger: ({ buttonType, className, icon, id, subtitle, title, ...rest }: CommonProps) => import("react/jsx-runtime").JSX.Element;
2
+ declare const BpkNudger: ({ buttonType, className, decreaseButtonLabel, icon, id, increaseButtonLabel, inputClassName, max, min, name, onValueChange, step, subtitle, title, value, ...rest }: CommonProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default BpkNudger;
@@ -16,30 +16,63 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
+ import { useRef } from 'react';
20
+ import { BpkButtonV2, BUTTON_TYPES } from "../../bpk-component-button";
21
+ import { withButtonAlignment } from "../../bpk-component-icon";
22
+ import MinusIcon from "../../bpk-component-icon/sm/minus";
23
+ import PlusIcon from "../../bpk-component-icon/sm/plus";
19
24
  // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
20
25
  import BpkLabel from "../../bpk-component-label";
21
26
  import BpkText, { TEXT_STYLES } from "../../bpk-component-text";
22
- import { cssModules } from "../../bpk-react-utils";
23
- import BpkConfigurableNudger from "./BpkConfigurableNudger";
27
+ import { cssModules, setNativeValue } from "../../bpk-react-utils";
24
28
  import STYLES from "./BpkNudger.module.css";
25
29
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
26
30
  const getClassName = cssModules(STYLES);
27
31
  const compareValues = (a, b) => a - b;
28
- const incrementValue = currentValue => currentValue + 1;
29
- const decrementValue = currentValue => currentValue - 1;
30
- const formatValue = currentValue => currentValue.toString();
31
32
  const BpkNudger = ({
32
33
  buttonType = 'secondary',
33
34
  className = null,
35
+ decreaseButtonLabel,
34
36
  icon,
35
37
  id,
38
+ increaseButtonLabel,
39
+ inputClassName,
40
+ max,
41
+ min,
42
+ name,
43
+ onValueChange,
44
+ step = 1,
36
45
  subtitle,
37
46
  title,
47
+ value,
38
48
  ...rest
39
49
  }) => {
40
- const classNames = getClassName(title && 'bpk-nudger__container');
50
+ // Ensure that the minimum value is 0 or greater it's not designed to handle negative values.
51
+ const minimum = min < 0 ? 0 : min;
52
+ const containerClassNames = getClassName(title && 'bpk-nudger__container');
53
+ const inputClassNames = getClassName('bpk-nudger__input', 'bpk-nudger__input--numeric', inputClassName && inputClassName, buttonType === 'secondaryOnDark' && 'bpk-nudger__input--secondary-on-dark');
54
+ const nudgerClassNames = getClassName('bpk-nudger', className);
55
+ const maxButtonDisabled = compareValues(value, max) >= 0;
56
+ const minButtonDisabled = compareValues(value, minimum) <= 0;
57
+ const AlignedMinusIcon = withButtonAlignment(MinusIcon);
58
+ const AlignedPlusIcon = withButtonAlignment(PlusIcon);
59
+ const inputRef = useRef(null);
60
+ const incrementValue = currentValue => currentValue + step;
61
+ const decrementValue = currentValue => currentValue - step;
62
+ const valueLimitter = element => {
63
+ if (element.valueAsNumber < minimum) {
64
+ onValueChange(minimum);
65
+ setNativeValue(element, minimum, false);
66
+ } else if (element.valueAsNumber > max) {
67
+ onValueChange(max);
68
+ setNativeValue(element, max, false);
69
+ }
70
+ if (element.valueAsNumber >= minimum && element.valueAsNumber <= max) {
71
+ onValueChange(element.valueAsNumber);
72
+ }
73
+ };
41
74
  return /*#__PURE__*/_jsxs("div", {
42
- className: classNames,
75
+ className: containerClassNames,
43
76
  children: [title && /*#__PURE__*/_jsxs("div", {
44
77
  className: getClassName('bpk-nudger__label'),
45
78
  children: [/*#__PURE__*/_jsx(BpkLabel, {
@@ -60,19 +93,68 @@ const BpkNudger = ({
60
93
  })
61
94
  })]
62
95
  })]
63
- }), /*#__PURE__*/_jsx(BpkConfigurableNudger, {
64
- inputClassName: getClassName('bpk-nudger__input--numeric'),
65
- compareValues: compareValues,
66
- incrementValue: incrementValue,
67
- decrementValue: decrementValue,
68
- formatValue: formatValue
69
- // TODO: className to be removed
70
- // eslint-disable-next-line @skyscanner/rules/forbid-component-props
71
- ,
72
- className: className,
73
- buttonType: buttonType,
74
- id: id,
75
- ...rest
96
+ }), /*#__PURE__*/_jsxs("div", {
97
+ className: nudgerClassNames,
98
+ children: [/*#__PURE__*/_jsx(BpkButtonV2, {
99
+ type: BUTTON_TYPES[buttonType],
100
+ iconOnly: true,
101
+ onClick: () => {
102
+ if (Number.isNaN(value)) {
103
+ onValueChange(minimum);
104
+ inputRef.current && setNativeValue(inputRef.current, minimum);
105
+ return;
106
+ }
107
+ const newValue = decrementValue(value);
108
+ onValueChange(newValue);
109
+ // We want to maintain native input events across our form components. Along with react updating
110
+ // the value attribute we can set it via native handlers and emit a "change" event.
111
+ inputRef.current && setNativeValue(inputRef.current, newValue);
112
+ },
113
+ disabled: minButtonDisabled,
114
+ title: decreaseButtonLabel,
115
+ "aria-controls": id,
116
+ children: /*#__PURE__*/_jsx(AlignedMinusIcon, {})
117
+ }), /*#__PURE__*/_jsx("input", {
118
+ type: "number",
119
+ "aria-live": "polite",
120
+ defaultValue: value,
121
+ id: id,
122
+ ref: inputRef,
123
+ name: name || id,
124
+ step: step,
125
+ onInput: event => {
126
+ const inputElement = event.target;
127
+ if (!inputElement.validity.valid &&
128
+ // allow the removal of a value
129
+ Number.isNaN(inputElement.valueAsNumber)) {
130
+ // set prev value if entry invalid
131
+ onValueChange(value);
132
+ setNativeValue(inputElement, value, false);
133
+ }
134
+ valueLimitter(inputElement);
135
+ },
136
+ className: inputClassNames,
137
+ ...rest
138
+ }), /*#__PURE__*/_jsx(BpkButtonV2, {
139
+ type: BUTTON_TYPES[buttonType],
140
+ iconOnly: true,
141
+ onClick: () => {
142
+ if (Number.isNaN(value)) {
143
+ onValueChange(max);
144
+ inputRef.current && setNativeValue(inputRef.current, max);
145
+ return;
146
+ }
147
+ const newValue = incrementValue(value);
148
+ onValueChange(newValue);
149
+ // We want to maintain native input events across our form components. Along with react updating
150
+ // the value attribute we can set it via native handlers and emit a "change" event.
151
+ inputRef.current && setNativeValue(inputRef.current, newValue);
152
+ },
153
+ disabled: maxButtonDisabled,
154
+ title: increaseButtonLabel,
155
+ "aria-controls": id,
156
+ children: /*#__PURE__*/_jsx(AlignedPlusIcon, {})
157
+ })]
76
158
  })]
77
159
  });
78
160
  };
@@ -15,4 +15,4 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- html[dir=rtl] .bpk-nudger{display:flex;flex-direction:row-reverse}.bpk-nudger__input{display:inline-block;padding:.5rem 0;border:none;color:#161616;text-align:center;vertical-align:middle;margin:0;font-size:1rem;line-height:1.25rem;font-weight:700}.bpk-nudger__input--secondary-on-dark{background-color:rgba(0,0,0,0);color:#fff}.bpk-nudger__input--numeric{width:2.5rem}.bpk-nudger__container{display:flex;justify-content:space-between;align-items:center}.bpk-nudger__label{display:flex;gap:.5rem}.bpk-nudger__label--title-subtitle{display:inline-flex;flex-direction:column;justify-content:space-between}.bpk-nudger__label--subtitle{color:#626971}
18
+ html[dir=rtl] .bpk-nudger{display:flex}.bpk-nudger__input{display:inline-block;padding:.5rem 0;border:none;color:#161616;text-align:center;vertical-align:middle;margin:0;font-size:1rem;line-height:1.25rem;font-weight:700}.bpk-nudger__input::-webkit-outer-spin-button,.bpk-nudger__input::-webkit-inner-spin-button{margin:0;appearance:none}.bpk-nudger__input[type=number]{appearance:textfield}.bpk-nudger__input--secondary-on-dark{background-color:rgba(0,0,0,0);color:#fff}.bpk-nudger__input--numeric{width:2.5rem}.bpk-nudger__container{display:flex;justify-content:space-between;align-items:center}.bpk-nudger__label{display:flex;gap:.5rem}.bpk-nudger__label--title-subtitle{display:inline-flex;flex-direction:column;justify-content:space-between}.bpk-nudger__label--subtitle{color:#626971}
@@ -5,11 +5,12 @@ export declare const BUTTON_TYPES: {
5
5
  };
6
6
  export type CommonProps = {
7
7
  id: string;
8
- min: string | number;
9
- max: string | number;
10
- value: string | number;
11
- onChange: (arg0: any) => void | null;
12
- name?: string | null;
8
+ min: number;
9
+ max: number;
10
+ value: number;
11
+ onValueChange: (arg0: number) => void;
12
+ name?: string | undefined;
13
+ step?: number;
13
14
  className?: string | null;
14
15
  /**
15
16
  * This is the label that will be read out when screen reader users tab to the increase button. Make sure you use a descriptive label.
@@ -18,6 +19,7 @@ export type CommonProps = {
18
19
  * Function that handle the incrementing of the current selected value.
19
20
  */
20
21
  increaseButtonLabel: string;
22
+ inputClassName?: string | undefined;
21
23
  /**
22
24
  * This is the label that will be read out when screen reader users tab to the decrease button. Make sure you use a descriptive label
23
25
  */
@@ -8,7 +8,10 @@ export type Props = {
8
8
  value: number[] | number;
9
9
  ariaLabel: string[];
10
10
  ariaValuetext?: string[];
11
+ inputProps?: [{
12
+ [key: string]: any;
13
+ }];
11
14
  [rest: string]: any;
12
15
  };
13
- declare const BpkSlider: ({ ariaLabel, ariaValuetext, max, min, minDistance, onAfterChange, onChange, step, value, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
16
+ declare const BpkSlider: ({ ariaLabel, ariaValuetext, inputProps, max, min, minDistance, onAfterChange, onChange, step, value, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
14
17
  export default BpkSlider;
@@ -15,15 +15,18 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
-
18
+ import { forwardRef, useRef, useEffect } from 'react';
19
+ import { useComposedRefs } from '@radix-ui/react-compose-refs';
19
20
  import * as Slider from '@radix-ui/react-slider';
20
- import { cssModules, isRTL } from "../../bpk-react-utils";
21
+ import { usePrevious } from '@radix-ui/react-use-previous';
22
+ import { cssModules, isRTL, setNativeValue } from "../../bpk-react-utils";
21
23
  import STYLES from "./BpkSlider.module.css";
22
24
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
23
25
  const getClassName = cssModules(STYLES);
24
26
  const BpkSlider = ({
25
27
  ariaLabel,
26
28
  ariaValuetext,
29
+ inputProps,
27
30
  max,
28
31
  min,
29
32
  minDistance,
@@ -67,8 +70,53 @@ const BpkSlider = ({
67
70
  "aria-label": ariaLabel[index],
68
71
  "aria-valuetext": ariaValuetext ? ariaValuetext[index] : val.toString(),
69
72
  className: getClassName('bpk-slider__thumb'),
70
- "aria-valuenow": currentValue[index]
73
+ "aria-valuenow": currentValue[index],
74
+ asChild: true,
75
+ children: /*#__PURE__*/_jsx("span", {
76
+ children: /*#__PURE__*/_jsx(BubbleInput, {
77
+ value: currentValue[index],
78
+ ...(inputProps && inputProps[index])
79
+ })
80
+ })
71
81
  }, ariaLabel[index]))]
72
82
  });
73
83
  };
84
+
85
+ // Work around until radix-ui/react-slider is updated to accept an inputRef prop https://github.com/radix-ui/primitives/pull/3033
86
+ const BubbleInput = /*#__PURE__*/forwardRef((props, forwardedRef) => {
87
+ const {
88
+ value,
89
+ ...inputProps
90
+ } = props;
91
+ const ref = useRef();
92
+ const composedRefs = useComposedRefs(forwardedRef, ref);
93
+ const prevValue = usePrevious(value);
94
+
95
+ // Bubble value change to parents (e.g form change event)
96
+ useEffect(() => {
97
+ const input = ref.current;
98
+ if (prevValue !== value) {
99
+ setNativeValue(input, `${value}`);
100
+ }
101
+ }, [prevValue, value]);
102
+
103
+ /**
104
+ * We purposefully do not use `type="hidden"` here otherwise forms that
105
+ * wrap it will not be able to access its value via the FormData API.
106
+ *
107
+ * We purposefully do not add the `value` attribute here to allow the value
108
+ * to be set programatically and bubble to any parent form `onChange` event.
109
+ * Adding the `value` will cause React to consider the programatic
110
+ * dispatch a duplicate and it will get swallowed.
111
+ */
112
+ return /*#__PURE__*/_jsx("input", {
113
+ style: {
114
+ display: 'none'
115
+ },
116
+ ...inputProps,
117
+ ref: composedRefs,
118
+ type: "number",
119
+ defaultValue: value
120
+ });
121
+ });
74
122
  export default BpkSlider;
@@ -0,0 +1,3 @@
1
+ import BpkSnippet, { BODY_STYLE, BUTTON_STYLE, DESKTOP_LAYOUT, HEADLINE_STYLE, IMAGE_ORIENTATION } from './src/BpkSnippet';
2
+ export default BpkSnippet;
3
+ export { BODY_STYLE, BUTTON_STYLE, DESKTOP_LAYOUT, HEADLINE_STYLE, IMAGE_ORIENTATION, };
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2016 Skyscanner Ltd
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import BpkSnippet, { BODY_STYLE, BUTTON_STYLE, DESKTOP_LAYOUT, HEADLINE_STYLE, IMAGE_ORIENTATION } from "./src/BpkSnippet";
20
+ export default BpkSnippet;
21
+ export { BODY_STYLE, BUTTON_STYLE, DESKTOP_LAYOUT, HEADLINE_STYLE, IMAGE_ORIENTATION };
@@ -0,0 +1,48 @@
1
+ import type { MouseEvent } from 'react';
2
+ export declare const BODY_STYLE: {
3
+ readonly bodyDefault: "body-default";
4
+ readonly bodyLongform: "body-longform";
5
+ };
6
+ export declare const BUTTON_STYLE: {
7
+ readonly primary: "primary";
8
+ readonly featured: "featured";
9
+ };
10
+ export declare const HEADLINE_STYLE: {
11
+ readonly heading1: "heading-1";
12
+ readonly heading2: "heading-2";
13
+ readonly heading3: "heading-3";
14
+ readonly heading4: "heading-4";
15
+ readonly heading5: "heading-5";
16
+ readonly hero1: "hero-1";
17
+ readonly hero2: "hero-2";
18
+ readonly hero3: "hero-3";
19
+ readonly hero4: "hero-4";
20
+ readonly hero5: "hero-5";
21
+ };
22
+ export declare const DESKTOP_LAYOUT: {
23
+ readonly imageLeft: "imageLeft";
24
+ readonly imageRight: "imageRight";
25
+ readonly vertical: "vertical";
26
+ };
27
+ export declare const IMAGE_ORIENTATION: {
28
+ readonly landscape: "landscape";
29
+ readonly portrait: "portrait";
30
+ readonly square: "square";
31
+ };
32
+ export type Props = {
33
+ src: string;
34
+ altText: string;
35
+ headline?: string | null;
36
+ subheading?: string | null;
37
+ bodyText?: string | null;
38
+ buttonText?: string | null;
39
+ bodyStyle?: (typeof BODY_STYLE)[keyof typeof BODY_STYLE];
40
+ buttonStyle?: (typeof BUTTON_STYLE)[keyof typeof BUTTON_STYLE];
41
+ headlineStyle?: (typeof HEADLINE_STYLE)[keyof typeof HEADLINE_STYLE];
42
+ desktopLayout?: (typeof DESKTOP_LAYOUT)[keyof typeof DESKTOP_LAYOUT];
43
+ imageOrientation?: (typeof IMAGE_ORIENTATION)[keyof typeof IMAGE_ORIENTATION];
44
+ imageRadius?: boolean;
45
+ onClick?: (event: MouseEvent<HTMLButtonElement & HTMLAnchorElement>) => void;
46
+ };
47
+ declare const BpkSnippet: ({ altText, bodyStyle, bodyText, buttonStyle, buttonText, desktopLayout, headline, headlineStyle, imageOrientation, imageRadius, onClick, src, subheading, }: Props) => import("react/jsx-runtime").JSX.Element;
48
+ export default BpkSnippet;