@skyscanner/backpack-web 42.0.0 → 42.2.0
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/bpk-component-banner-alert/src/BpkBannerAlert.js +0 -7
- package/bpk-component-breakpoint/src/BpkBreakpoint.js +3 -1
- package/bpk-component-button/src/BpkButton.d.ts +1 -1
- package/bpk-component-button/src/BpkButton.js +17 -3
- package/bpk-component-button/src/BpkButton.module.css +1 -1
- package/bpk-component-button/src/common-types.d.ts +2 -0
- package/bpk-component-calendar/src/utils.js +1 -1
- package/bpk-component-card/index.d.ts +4 -1
- package/bpk-component-card/index.js +3 -1
- package/bpk-component-card/src/BpkCardV2/BpkCardV2.d.ts +27 -0
- package/bpk-component-card/src/BpkCardV2/BpkCardV2.js +57 -0
- package/bpk-component-card/src/BpkCardV2/BpkCardV2.module.css +18 -0
- package/bpk-component-card/src/BpkCardV2/common-types.d.ts +124 -0
- package/bpk-component-card/src/BpkCardV2/common-types.js +102 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Body.d.ts +36 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Body.js +65 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Divider.d.ts +13 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Divider.js +37 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Footer.d.ts +24 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Footer.js +60 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Header.d.ts +24 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Header.js +60 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Root.d.ts +28 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Root.js +68 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Section.d.ts +22 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/Section.js +53 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/resolveDirectionalPadding.d.ts +16 -0
- package/bpk-component-card/src/BpkCardV2/subcomponents/resolveDirectionalPadding.js +32 -0
- package/bpk-component-card-list/src/BpkCardList.module.css +1 -1
- package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListCarousel.js +3 -3
- package/bpk-component-chatbot-input/index.d.ts +7 -0
- package/bpk-component-chatbot-input/index.js +23 -0
- package/bpk-component-chatbot-input/src/BpkChatbotInput.d.ts +4 -0
- package/bpk-component-chatbot-input/src/BpkChatbotInput.js +118 -0
- package/bpk-component-chatbot-input/src/BpkChatbotInput.module.css +18 -0
- package/bpk-component-chatbot-input/src/InputField/InputField.d.ts +3 -0
- package/bpk-component-chatbot-input/src/InputField/InputField.js +82 -0
- package/bpk-component-chatbot-input/src/InputField.module.css +18 -0
- package/bpk-component-chatbot-input/src/SendButton/SendButton.d.ts +9 -0
- package/bpk-component-chatbot-input/src/SendButton/SendButton.js +47 -0
- package/bpk-component-chatbot-input/src/TextAreaField/TextAreaField.d.ts +10 -0
- package/bpk-component-chatbot-input/src/TextAreaField/TextAreaField.js +93 -0
- package/bpk-component-chatbot-input/src/TextAreaField.module.css +18 -0
- package/bpk-component-chatbot-input/src/common-types.d.ts +37 -0
- package/bpk-component-chatbot-input/src/common-types.js +23 -0
- package/bpk-component-chatbot-input/src/constants.d.ts +5 -0
- package/bpk-component-chatbot-input/src/constants.js +22 -0
- package/bpk-component-chatbot-input/src/hooks/index.d.ts +4 -0
- package/bpk-component-chatbot-input/src/hooks/index.js +22 -0
- package/bpk-component-chatbot-input/src/hooks/useChatbotInput.d.ts +32 -0
- package/bpk-component-chatbot-input/src/hooks/useChatbotInput.js +111 -0
- package/bpk-component-chatbot-input/src/hooks/useChatbotInputManager.d.ts +20 -0
- package/bpk-component-chatbot-input/src/hooks/useChatbotInputManager.js +83 -0
- package/bpk-component-chatbot-input/src/hooks/useInputHandlers.d.ts +8 -0
- package/bpk-component-chatbot-input/src/hooks/useInputHandlers.js +54 -0
- package/bpk-component-chatbot-input/src/hooks/useTextAreaAutoResize.d.ts +22 -0
- package/bpk-component-chatbot-input/src/hooks/useTextAreaAutoResize.js +137 -0
- package/bpk-component-chatbot-input/src/themeAttributes.d.ts +14 -0
- package/bpk-component-chatbot-input/src/themeAttributes.js +34 -0
- package/bpk-component-checkbox/index.d.ts +7 -1
- package/bpk-component-checkbox/index.js +3 -1
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2.d.ts +9 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2.js +33 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2.module.css +18 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Control.d.ts +6 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Control.js +30 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Description.d.ts +6 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Description.js +32 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2HiddenInput.d.ts +2 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2HiddenInput.js +25 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Indicator.d.ts +2 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Indicator.js +23 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Label.d.ts +6 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Label.js +30 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Root.d.ts +16 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/BpkCheckboxV2Root.js +49 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/themeAttributes.d.ts +2 -0
- package/bpk-component-checkbox/src/BpkCheckboxV2/themeAttributes.js +20 -0
- package/bpk-component-checkbox-card/index.d.ts +3 -0
- package/bpk-component-checkbox-card/index.js +20 -0
- package/bpk-component-checkbox-card/src/BpkCheckboxCard.d.ts +128 -0
- package/bpk-component-checkbox-card/src/BpkCheckboxCard.js +216 -0
- package/bpk-component-checkbox-card/src/BpkCheckboxCard.module.css +18 -0
- package/bpk-component-checkbox-card/src/BpkCheckboxCardRoot.d.ts +95 -0
- package/bpk-component-checkbox-card/src/BpkCheckboxCardRoot.js +101 -0
- package/bpk-component-checkbox-card/src/CheckboxCardContext.d.ts +27 -0
- package/bpk-component-checkbox-card/src/CheckboxCardContext.js +47 -0
- package/bpk-component-checkbox-card/src/common-types.d.ts +27 -0
- package/bpk-component-checkbox-card/src/common-types.js +43 -0
- package/bpk-component-checkbox-card/src/themeAttributes.d.ts +46 -0
- package/bpk-component-checkbox-card/src/themeAttributes.js +87 -0
- package/bpk-component-icon/scripts/generate-figma-connect.js +267 -0
- package/bpk-component-inset-banner/index.d.ts +4 -1
- package/bpk-component-inset-banner/index.js +2 -1
- package/bpk-component-inset-banner/src/BpkInsetBannerV3/BpkInsetBannerV3.d.ts +56 -0
- package/bpk-component-inset-banner/src/BpkInsetBannerV3/BpkInsetBannerV3.js +118 -0
- package/bpk-component-inset-banner/src/BpkInsetBannerV3/BpkInsetBannerV3.module.css +18 -0
- package/bpk-component-layout/src/BpkProvider.d.ts +9 -4
- package/bpk-component-layout/src/BpkProvider.js +87 -8
- package/bpk-component-layout/src/types.d.ts +2 -2
- package/bpk-component-link/src/common-types.d.ts +1 -1
- package/bpk-component-modal/index.d.ts +2 -1
- package/bpk-component-modal/index.js +2 -1
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3.d.ts +14 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3.js +43 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Body/BpkModalV3Body.d.ts +7 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Body/BpkModalV3Body.js +30 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Body.module.css +18 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3CloseTrigger/BpkModalV3CloseTrigger.d.ts +7 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3CloseTrigger/BpkModalV3CloseTrigger.js +49 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3CloseTrigger.module.css +18 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Content/BpkModalV3Content.d.ts +7 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Content/BpkModalV3Content.js +38 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Content.module.css +18 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Context.d.ts +3 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Context.js +22 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Description/BpkModalV3Description.d.ts +7 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Description/BpkModalV3Description.js +28 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Header/BpkModalV3Header.d.ts +7 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Header/BpkModalV3Header.js +34 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Header.module.css +18 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3HeroImage/BpkModalV3HeroImage.d.ts +10 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3HeroImage/BpkModalV3HeroImage.js +44 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3HeroImage.module.css +18 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Portal/BpkModalV3Portal.d.ts +7 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Portal/BpkModalV3Portal.js +26 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Root/BpkModalV3Root.d.ts +13 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Root/BpkModalV3Root.js +44 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Scrim/BpkModalV3Scrim.d.ts +2 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Scrim/BpkModalV3Scrim.js +32 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Scrim.module.css +18 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Title/BpkModalV3Title.d.ts +7 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Title/BpkModalV3Title.js +31 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Title.module.css +18 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Trigger/BpkModalV3Trigger.d.ts +8 -0
- package/bpk-component-modal/src/BpkModalV3/BpkModalV3Trigger/BpkModalV3Trigger.js +30 -0
- package/bpk-component-modal/src/BpkModalV3/common-types.d.ts +1 -0
- package/bpk-component-modal/src/BpkModalV3/common-types.js +1 -0
- package/bpk-component-page-indicator/src/NavButton.d.ts +2 -1
- package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGridList.js +40 -22
- package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGridList.module.css +1 -1
- package/bpk-component-segmented-control/src/BpkSegmentedControlV2/BpkSegmentedControlV2.js +37 -16
- package/bpk-component-skeleton/src/BpkBaseSkeleton.d.d.ts +1 -0
- package/bpk-component-skeleton/src/BpkSkeleton.d.d.ts +1 -0
- package/bpk-component-table/index.d.ts +2 -1
- package/bpk-component-table/index.js +2 -1
- package/bpk-component-table/src/BpkTable.module.css +1 -1
- package/bpk-component-table/src/BpkTableBody.d.ts +4 -1
- package/bpk-component-table/src/BpkTableBody.js +19 -4
- package/bpk-component-table/src/common-types.d.ts +5 -0
- package/bpk-component-table/src/common-types.js +22 -0
- package/bpk-react-utils/src/Portal.d.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,111 @@
|
|
|
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 { useCallback, useRef, useState } from 'react';
|
|
20
|
+
import { CHATBOT_INPUT_TYPES } from "../common-types";
|
|
21
|
+
import { MAX_CHARACTERS } from "../constants";
|
|
22
|
+
import useTextAreaAutoResize from "./useTextAreaAutoResize";
|
|
23
|
+
const useChatbotInput = ({
|
|
24
|
+
inputType = CHATBOT_INPUT_TYPES.COMPOSER,
|
|
25
|
+
inputValue,
|
|
26
|
+
isPolling = false,
|
|
27
|
+
isSending = false,
|
|
28
|
+
maxCharacters = MAX_CHARACTERS,
|
|
29
|
+
onInputBlur,
|
|
30
|
+
onInputChange,
|
|
31
|
+
onInputClick = () => {},
|
|
32
|
+
onInputFocus,
|
|
33
|
+
onKeyDown = () => {},
|
|
34
|
+
onSubmit,
|
|
35
|
+
placeholder
|
|
36
|
+
}) => {
|
|
37
|
+
const isCars = inputType === CHATBOT_INPUT_TYPES.CARS;
|
|
38
|
+
const isMultiLine = inputType === CHATBOT_INPUT_TYPES.CARS_COMPOSER || inputType === CHATBOT_INPUT_TYPES.COMPOSER;
|
|
39
|
+
const inputRef = useRef(null);
|
|
40
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
41
|
+
const isOverLimit = inputValue.length > maxCharacters;
|
|
42
|
+
const isDisabled = isSending || isPolling;
|
|
43
|
+
const {
|
|
44
|
+
containerHeight,
|
|
45
|
+
isCapped,
|
|
46
|
+
isExpanding,
|
|
47
|
+
textareaHeight
|
|
48
|
+
} = useTextAreaAutoResize({
|
|
49
|
+
ref: inputRef,
|
|
50
|
+
value: inputValue,
|
|
51
|
+
enabled: isMultiLine
|
|
52
|
+
});
|
|
53
|
+
const handleSubmit = useCallback(() => {
|
|
54
|
+
if (inputValue.trim() && !isDisabled && !isOverLimit) {
|
|
55
|
+
onSubmit();
|
|
56
|
+
}
|
|
57
|
+
}, [inputValue, onSubmit, isDisabled, isOverLimit]);
|
|
58
|
+
const handleKeyDown = useCallback(e => {
|
|
59
|
+
if (e.key === 'Enter') {
|
|
60
|
+
if (!isMultiLine) {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
e.stopPropagation();
|
|
63
|
+
handleSubmit();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!e.shiftKey) {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
e.stopPropagation();
|
|
69
|
+
handleSubmit();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
onKeyDown?.(e);
|
|
74
|
+
}, [isMultiLine, handleSubmit, onKeyDown]);
|
|
75
|
+
const handleInputFocus = useCallback(() => {
|
|
76
|
+
setIsFocused(true);
|
|
77
|
+
onInputFocus();
|
|
78
|
+
}, [onInputFocus]);
|
|
79
|
+
const handleInputBlur = useCallback(() => {
|
|
80
|
+
setIsFocused(false);
|
|
81
|
+
onInputBlur();
|
|
82
|
+
}, [onInputBlur]);
|
|
83
|
+
const inputProps = {
|
|
84
|
+
value: inputValue,
|
|
85
|
+
placeholder,
|
|
86
|
+
disabled: isDisabled,
|
|
87
|
+
isOverLimit,
|
|
88
|
+
onInputChange,
|
|
89
|
+
onInputFocus: handleInputFocus,
|
|
90
|
+
onInputBlur: handleInputBlur,
|
|
91
|
+
onInputClick,
|
|
92
|
+
onKeyDown: handleKeyDown,
|
|
93
|
+
dataTestId: isMultiLine ? 'bpk-chatbot-textarea-field' : 'bpk-chatbot-input-field'
|
|
94
|
+
};
|
|
95
|
+
const sendButtonDisabled = isCars ? isFocused && !inputValue.trim() || isDisabled || isOverLimit : !inputValue.trim() || isDisabled || isOverLimit;
|
|
96
|
+
return {
|
|
97
|
+
inputRef,
|
|
98
|
+
isFocused,
|
|
99
|
+
isDisabled,
|
|
100
|
+
isOverLimit,
|
|
101
|
+
isExpanding,
|
|
102
|
+
isCars,
|
|
103
|
+
sendButtonDisabled,
|
|
104
|
+
inputProps,
|
|
105
|
+
handleSubmit,
|
|
106
|
+
containerHeight,
|
|
107
|
+
textareaHeight,
|
|
108
|
+
isCapped
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export default useChatbotInput;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface UseChatbotInputManagerOptions {
|
|
2
|
+
isSending?: boolean;
|
|
3
|
+
onSubmit: (value: string) => void;
|
|
4
|
+
sendMessage?: (message: string) => Promise<void>;
|
|
5
|
+
onPromptClick?: (id: string, promptText?: string) => void;
|
|
6
|
+
isModalOpen?: boolean;
|
|
7
|
+
autoClearOnSendingComplete?: boolean;
|
|
8
|
+
autoClearOnModalClose?: boolean;
|
|
9
|
+
autoClearOnClose?: boolean;
|
|
10
|
+
isOpen?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface UseChatbotInputManagerReturn {
|
|
13
|
+
inputValue: string;
|
|
14
|
+
setInputValue: (value: string) => void;
|
|
15
|
+
handleInputChange: (value: string) => void;
|
|
16
|
+
handleSubmit: () => Promise<void> | void;
|
|
17
|
+
handlePromptClick?: (id: string, promptText?: string) => void;
|
|
18
|
+
}
|
|
19
|
+
declare const useChatbotInputManager: ({ autoClearOnClose, autoClearOnModalClose, autoClearOnSendingComplete, isModalOpen, isOpen, isSending, onPromptClick, onSubmit, sendMessage, }: UseChatbotInputManagerOptions) => UseChatbotInputManagerReturn;
|
|
20
|
+
export default useChatbotInputManager;
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { useState, useEffect, useRef, useCallback } from 'react';
|
|
20
|
+
const useChatbotInputManager = ({
|
|
21
|
+
autoClearOnClose = false,
|
|
22
|
+
autoClearOnModalClose = false,
|
|
23
|
+
autoClearOnSendingComplete = false,
|
|
24
|
+
isModalOpen = false,
|
|
25
|
+
isOpen,
|
|
26
|
+
isSending = false,
|
|
27
|
+
onPromptClick,
|
|
28
|
+
onSubmit,
|
|
29
|
+
sendMessage
|
|
30
|
+
}) => {
|
|
31
|
+
const [inputValue, setInputValue] = useState('');
|
|
32
|
+
const previousIsSending = useRef(isSending);
|
|
33
|
+
const previousIsModalOpen = useRef(isModalOpen);
|
|
34
|
+
const previousIsOpen = useRef(isOpen);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (autoClearOnSendingComplete && previousIsSending.current && !isSending) {
|
|
37
|
+
setInputValue('');
|
|
38
|
+
}
|
|
39
|
+
previousIsSending.current = isSending;
|
|
40
|
+
}, [isSending, autoClearOnSendingComplete]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (autoClearOnModalClose && previousIsModalOpen.current && !isModalOpen) {
|
|
43
|
+
setInputValue('');
|
|
44
|
+
}
|
|
45
|
+
previousIsModalOpen.current = isModalOpen;
|
|
46
|
+
}, [isModalOpen, autoClearOnModalClose]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (autoClearOnClose && previousIsOpen.current && !isOpen) {
|
|
49
|
+
setInputValue('');
|
|
50
|
+
}
|
|
51
|
+
previousIsOpen.current = isOpen;
|
|
52
|
+
}, [isOpen, autoClearOnClose]);
|
|
53
|
+
const handleInputChange = useCallback(value => {
|
|
54
|
+
setInputValue(value);
|
|
55
|
+
}, []);
|
|
56
|
+
const handleSubmit = useCallback(async () => {
|
|
57
|
+
const userMessage = inputValue.trim();
|
|
58
|
+
if (!userMessage || isSending) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
setInputValue('');
|
|
62
|
+
onSubmit(userMessage);
|
|
63
|
+
if (sendMessage) {
|
|
64
|
+
await sendMessage(userMessage);
|
|
65
|
+
}
|
|
66
|
+
}, [inputValue, isSending, onSubmit, sendMessage]);
|
|
67
|
+
const handlePromptClick = useCallback((id, promptText) => {
|
|
68
|
+
if (promptText && !isSending && onPromptClick) {
|
|
69
|
+
setInputValue(promptText);
|
|
70
|
+
}
|
|
71
|
+
onPromptClick?.(id, promptText);
|
|
72
|
+
}, [isSending, onPromptClick]);
|
|
73
|
+
return {
|
|
74
|
+
inputValue,
|
|
75
|
+
setInputValue,
|
|
76
|
+
handleInputChange,
|
|
77
|
+
handleSubmit,
|
|
78
|
+
...(onPromptClick && {
|
|
79
|
+
handlePromptClick
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export default useChatbotInputManager;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ChangeEvent, ForwardedRef, MouseEvent, TouchEvent } from 'react';
|
|
2
|
+
declare const useInputHandlers: <T extends HTMLInputElement | HTMLTextAreaElement>(ref: ForwardedRef<T>, onInputChange: (value: string) => void, onInputClick: () => void) => {
|
|
3
|
+
handleInputChange: (e: ChangeEvent<T>) => void;
|
|
4
|
+
handleInputClick: (e: MouseEvent<T>) => void;
|
|
5
|
+
handleTouchStart: (e: TouchEvent<T>) => void;
|
|
6
|
+
handleTouchEnd: (e: TouchEvent<T>) => void;
|
|
7
|
+
};
|
|
8
|
+
export default useInputHandlers;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { useCallback, useRef } from 'react';
|
|
20
|
+
const useInputHandlers = (ref, onInputChange, onInputClick) => {
|
|
21
|
+
const touchStartTargetRef = useRef(null);
|
|
22
|
+
const handleInputChange = useCallback(e => {
|
|
23
|
+
onInputChange(e.target.value);
|
|
24
|
+
}, [onInputChange]);
|
|
25
|
+
const handleInputClick = useCallback(e => {
|
|
26
|
+
e.stopPropagation();
|
|
27
|
+
if (ref && typeof ref !== 'function' && ref.current && !ref.current.disabled) {
|
|
28
|
+
ref.current.focus();
|
|
29
|
+
onInputClick();
|
|
30
|
+
}
|
|
31
|
+
}, [onInputClick, ref]);
|
|
32
|
+
const handleTouchStart = useCallback(e => {
|
|
33
|
+
e.stopPropagation();
|
|
34
|
+
touchStartTargetRef.current = e.target;
|
|
35
|
+
}, []);
|
|
36
|
+
const handleTouchEnd = useCallback(e => {
|
|
37
|
+
e.stopPropagation();
|
|
38
|
+
if (touchStartTargetRef.current === e.target) {
|
|
39
|
+
if (ref && typeof ref !== 'function' && ref.current && !ref.current.disabled) {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
ref.current.focus();
|
|
42
|
+
onInputClick();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
touchStartTargetRef.current = null;
|
|
46
|
+
}, [onInputClick, ref]);
|
|
47
|
+
return {
|
|
48
|
+
handleInputChange,
|
|
49
|
+
handleInputClick,
|
|
50
|
+
handleTouchStart,
|
|
51
|
+
handleTouchEnd
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export default useInputHandlers;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
interface UseTextAreaAutoResizeProps {
|
|
3
|
+
ref: RefObject<HTMLTextAreaElement>;
|
|
4
|
+
value: string;
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface UseTextAreaAutoResizeReturn {
|
|
8
|
+
isExpanding: boolean;
|
|
9
|
+
textareaHeight: number;
|
|
10
|
+
containerHeight: number;
|
|
11
|
+
isCapped: boolean;
|
|
12
|
+
scrollToBottom: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare const LINE_HEIGHT = 24;
|
|
15
|
+
export declare const MIN_INPUT_HEIGHT = 24;
|
|
16
|
+
export declare const MAX_INPUT_HEIGHT_PHASE_1: number;
|
|
17
|
+
export declare const MAX_INPUT_HEIGHT_PHASE_2: number;
|
|
18
|
+
export declare const MIN_CONTAINER_HEIGHT = 24;
|
|
19
|
+
export declare const MAX_CONTAINER_HEIGHT = 96;
|
|
20
|
+
export declare const PARENT_PADDING_TOP = 16;
|
|
21
|
+
declare const useTextAreaAutoResize: ({ enabled, ref, value, }: UseTextAreaAutoResizeProps) => UseTextAreaAutoResizeReturn;
|
|
22
|
+
export default useTextAreaAutoResize;
|
|
@@ -0,0 +1,137 @@
|
|
|
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 { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
20
|
+
export const LINE_HEIGHT = 24;
|
|
21
|
+
export const MIN_INPUT_HEIGHT = LINE_HEIGHT;
|
|
22
|
+
export const MAX_INPUT_HEIGHT_PHASE_1 = LINE_HEIGHT * 4;
|
|
23
|
+
export const MAX_INPUT_HEIGHT_PHASE_2 = LINE_HEIGHT * 5;
|
|
24
|
+
export const MIN_CONTAINER_HEIGHT = 24;
|
|
25
|
+
export const MAX_CONTAINER_HEIGHT = 96;
|
|
26
|
+
export const PARENT_PADDING_TOP = 16;
|
|
27
|
+
const useTextAreaAutoResize = ({
|
|
28
|
+
enabled = true,
|
|
29
|
+
ref,
|
|
30
|
+
value
|
|
31
|
+
}) => {
|
|
32
|
+
const [dimensions, setDimensions] = useState({
|
|
33
|
+
isExpanding: false,
|
|
34
|
+
textareaHeight: MIN_INPUT_HEIGHT,
|
|
35
|
+
containerHeight: MIN_CONTAINER_HEIGHT,
|
|
36
|
+
isCapped: false
|
|
37
|
+
});
|
|
38
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
39
|
+
const measureElementRef = useRef(null);
|
|
40
|
+
const lineHeightRef = useRef(LINE_HEIGHT);
|
|
41
|
+
const previousValueRef = useRef('');
|
|
42
|
+
const shouldScrollRef = useRef(false);
|
|
43
|
+
const isInitialRenderRef = useRef(true);
|
|
44
|
+
const scrollToBottom = useCallback(() => {
|
|
45
|
+
if (ref?.current) {
|
|
46
|
+
const textarea = ref.current;
|
|
47
|
+
requestAnimationFrame(() => {
|
|
48
|
+
textarea.scrollTop = textarea.scrollHeight;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}, [ref]);
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
if (!enabled || !ref?.current) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const textarea = ref.current;
|
|
57
|
+
const computedStyle = getComputedStyle(textarea);
|
|
58
|
+
const parsedLineHeight = parseFloat(computedStyle.lineHeight);
|
|
59
|
+
if (!Number.isNaN(parsedLineHeight) && parsedLineHeight > 0) {
|
|
60
|
+
lineHeightRef.current = parsedLineHeight;
|
|
61
|
+
}
|
|
62
|
+
const tempTextarea = document.createElement('textarea');
|
|
63
|
+
tempTextarea.style.position = 'absolute';
|
|
64
|
+
tempTextarea.style.visibility = 'hidden';
|
|
65
|
+
tempTextarea.style.height = 'auto';
|
|
66
|
+
tempTextarea.style.fontSize = computedStyle.fontSize;
|
|
67
|
+
tempTextarea.style.fontFamily = computedStyle.fontFamily;
|
|
68
|
+
tempTextarea.style.lineHeight = computedStyle.lineHeight;
|
|
69
|
+
tempTextarea.style.padding = computedStyle.padding;
|
|
70
|
+
tempTextarea.style.border = computedStyle.border;
|
|
71
|
+
tempTextarea.style.boxSizing = computedStyle.boxSizing;
|
|
72
|
+
tempTextarea.style.whiteSpace = 'pre-wrap';
|
|
73
|
+
tempTextarea.style.overflowWrap = 'break-word';
|
|
74
|
+
tempTextarea.style.width = `${textarea.offsetWidth}px`;
|
|
75
|
+
tempTextarea.rows = 1;
|
|
76
|
+
document.body.appendChild(tempTextarea);
|
|
77
|
+
measureElementRef.current = tempTextarea;
|
|
78
|
+
const resizeObserver = new ResizeObserver(entries => {
|
|
79
|
+
setContainerWidth(Math.round(entries[0].contentRect.width));
|
|
80
|
+
});
|
|
81
|
+
resizeObserver.observe(textarea);
|
|
82
|
+
return () => {
|
|
83
|
+
if (measureElementRef.current) {
|
|
84
|
+
measureElementRef.current.remove();
|
|
85
|
+
measureElementRef.current = null;
|
|
86
|
+
}
|
|
87
|
+
resizeObserver.disconnect();
|
|
88
|
+
};
|
|
89
|
+
}, [enabled, ref]);
|
|
90
|
+
useLayoutEffect(() => {
|
|
91
|
+
if (!enabled || !ref?.current || !measureElementRef.current) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const textarea = ref.current;
|
|
95
|
+
const measureEl = measureElementRef.current;
|
|
96
|
+
measureEl.style.width = `${textarea.offsetWidth}px`;
|
|
97
|
+
measureEl.value = value || ' ';
|
|
98
|
+
const {
|
|
99
|
+
scrollHeight
|
|
100
|
+
} = measureEl;
|
|
101
|
+
const lines = Math.max(1, Math.ceil(scrollHeight / lineHeightRef.current));
|
|
102
|
+
const isCapped = lines >= 5;
|
|
103
|
+
const maxInputHeight = isCapped ? MAX_INPUT_HEIGHT_PHASE_2 : MAX_INPUT_HEIGHT_PHASE_1;
|
|
104
|
+
const targetInputHeight = Math.max(MIN_INPUT_HEIGHT, Math.min(scrollHeight, maxInputHeight));
|
|
105
|
+
const extraSpace = isCapped ? PARENT_PADDING_TOP : 0;
|
|
106
|
+
const targetContainerHeight = Math.max(MIN_CONTAINER_HEIGHT, Math.min(targetInputHeight - extraSpace, MAX_CONTAINER_HEIGHT));
|
|
107
|
+
setDimensions(prev => {
|
|
108
|
+
const isContentAdded = value.length > previousValueRef.current.length;
|
|
109
|
+
const isAppending = value.startsWith(previousValueRef.current);
|
|
110
|
+
const prevMaxHeight = prev.isCapped ? MAX_INPUT_HEIGHT_PHASE_2 : MAX_INPUT_HEIGHT_PHASE_1;
|
|
111
|
+
const isInitialRender = isInitialRenderRef.current;
|
|
112
|
+
const shouldScroll = isContentAdded && isAppending && textarea.scrollHeight > prevMaxHeight || isInitialRender && scrollHeight > maxInputHeight;
|
|
113
|
+
shouldScrollRef.current = shouldScroll;
|
|
114
|
+
if (isInitialRender) {
|
|
115
|
+
isInitialRenderRef.current = false;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
isExpanding: lines > 1,
|
|
119
|
+
textareaHeight: targetInputHeight,
|
|
120
|
+
containerHeight: targetContainerHeight,
|
|
121
|
+
isCapped
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
previousValueRef.current = value;
|
|
125
|
+
}, [value, ref, enabled, containerWidth]);
|
|
126
|
+
useLayoutEffect(() => {
|
|
127
|
+
if (shouldScrollRef.current) {
|
|
128
|
+
scrollToBottom();
|
|
129
|
+
shouldScrollRef.current = false;
|
|
130
|
+
}
|
|
131
|
+
}, [dimensions, scrollToBottom]);
|
|
132
|
+
return {
|
|
133
|
+
...dimensions,
|
|
134
|
+
scrollToBottom
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export default useTextAreaAutoResize;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme attributes for BpkChatbotInput.
|
|
3
|
+
*
|
|
4
|
+
* Usage with BpkThemeProvider:
|
|
5
|
+
*
|
|
6
|
+
* import BpkThemeProvider from '@skyscanner/backpack-web/bpk-theming';
|
|
7
|
+
* import BpkChatbotInput, { themeAttributes } from '@skyscanner/backpack-web/bpk-component-chatbot-input';
|
|
8
|
+
*
|
|
9
|
+
* <BpkThemeProvider theme={{ chatbotInputBorderRadius: '999px', chatbotInputFocusBorderColor: '#FF6600' }} themeAttributes={themeAttributes}>
|
|
10
|
+
* <BpkChatbotInput ... />
|
|
11
|
+
* </BpkThemeProvider>
|
|
12
|
+
*/
|
|
13
|
+
declare const themeAttributes: string[];
|
|
14
|
+
export default themeAttributes;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
/**
|
|
20
|
+
* Theme attributes for BpkChatbotInput.
|
|
21
|
+
*
|
|
22
|
+
* Usage with BpkThemeProvider:
|
|
23
|
+
*
|
|
24
|
+
* import BpkThemeProvider from '@skyscanner/backpack-web/bpk-theming';
|
|
25
|
+
* import BpkChatbotInput, { themeAttributes } from '@skyscanner/backpack-web/bpk-component-chatbot-input';
|
|
26
|
+
*
|
|
27
|
+
* <BpkThemeProvider theme={{ chatbotInputBorderRadius: '999px', chatbotInputFocusBorderColor: '#FF6600' }} themeAttributes={themeAttributes}>
|
|
28
|
+
* <BpkChatbotInput ... />
|
|
29
|
+
* </BpkThemeProvider>
|
|
30
|
+
*/
|
|
31
|
+
const themeAttributes = [/** Border radius for the input container. Applies to both cars and composer modes. */
|
|
32
|
+
'chatbotInputBorderRadius', /** Border colour for hover and focus states. Only applies to the cars (single-line) mode. */
|
|
33
|
+
'chatbotInputFocusBorderColor'];
|
|
34
|
+
export default themeAttributes;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import BpkCheckbox, { type Props as BpkCheckboxProps } from './src/BpkCheckbox';
|
|
2
2
|
import themeAttributes from './src/themeAttributes';
|
|
3
|
-
export type { BpkCheckboxProps };
|
|
4
3
|
export default BpkCheckbox;
|
|
4
|
+
export type { BpkCheckboxProps };
|
|
5
5
|
export { themeAttributes };
|
|
6
|
+
export { default as BpkCheckboxV2 } from './src/BpkCheckboxV2/BpkCheckboxV2';
|
|
7
|
+
export { checkboxSelectedColorThemeAttributes, checkboxBorderRadiusThemeAttributes, } from './src/BpkCheckboxV2/themeAttributes';
|
|
8
|
+
export type { BpkCheckboxV2RootProps, BpkCheckboxV2CheckedState } from './src/BpkCheckboxV2/BpkCheckboxV2Root';
|
|
9
|
+
export type { BpkCheckboxV2ControlProps } from './src/BpkCheckboxV2/BpkCheckboxV2Control';
|
|
10
|
+
export type { BpkCheckboxV2LabelProps } from './src/BpkCheckboxV2/BpkCheckboxV2Label';
|
|
11
|
+
export type { BpkCheckboxV2DescriptionProps } from './src/BpkCheckboxV2/BpkCheckboxV2Description';
|
|
@@ -19,4 +19,6 @@
|
|
|
19
19
|
import BpkCheckbox from "./src/BpkCheckbox";
|
|
20
20
|
import themeAttributes from "./src/themeAttributes";
|
|
21
21
|
export default BpkCheckbox;
|
|
22
|
-
export { themeAttributes };
|
|
22
|
+
export { themeAttributes };
|
|
23
|
+
export { default as BpkCheckboxV2 } from "./src/BpkCheckboxV2/BpkCheckboxV2";
|
|
24
|
+
export { checkboxSelectedColorThemeAttributes, checkboxBorderRadiusThemeAttributes } from "./src/BpkCheckboxV2/themeAttributes";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const BpkCheckboxV2: {
|
|
2
|
+
Root: ({ checked, children, defaultChecked, disabled, id, invalid, name, onCheckedChange, required, value, }: import("./BpkCheckboxV2Root").BpkCheckboxV2RootProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
Control: ({ children }: import("./BpkCheckboxV2Control").BpkCheckboxV2ControlProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
Indicator: () => null;
|
|
5
|
+
Label: ({ children }: import("./BpkCheckboxV2Label").BpkCheckboxV2LabelProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
Description: ({ children }: import("./BpkCheckboxV2Description").BpkCheckboxV2DescriptionProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
HiddenInput: () => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
};
|
|
9
|
+
export default BpkCheckboxV2;
|
|
@@ -0,0 +1,33 @@
|
|
|
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 BpkCheckboxV2Control from "./BpkCheckboxV2Control";
|
|
20
|
+
import BpkCheckboxV2Description from "./BpkCheckboxV2Description";
|
|
21
|
+
import BpkCheckboxV2HiddenInput from "./BpkCheckboxV2HiddenInput";
|
|
22
|
+
import BpkCheckboxV2Indicator from "./BpkCheckboxV2Indicator";
|
|
23
|
+
import BpkCheckboxV2Label from "./BpkCheckboxV2Label";
|
|
24
|
+
import BpkCheckboxV2Root from "./BpkCheckboxV2Root";
|
|
25
|
+
const BpkCheckboxV2 = {
|
|
26
|
+
Root: BpkCheckboxV2Root,
|
|
27
|
+
Control: BpkCheckboxV2Control,
|
|
28
|
+
Indicator: BpkCheckboxV2Indicator,
|
|
29
|
+
Label: BpkCheckboxV2Label,
|
|
30
|
+
Description: BpkCheckboxV2Description,
|
|
31
|
+
HiddenInput: BpkCheckboxV2HiddenInput
|
|
32
|
+
};
|
|
33
|
+
export default BpkCheckboxV2;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
.bpk-checkbox-v2{display:inline-flex;align-items:flex-start;cursor:pointer;gap:.5rem}.bpk-checkbox-v2[data-disabled]{cursor:not-allowed}.bpk-checkbox-v2__control{position:relative;display:flex;width:1.25rem;height:1.25rem;margin-top:.125rem;justify-content:center;align-items:center;flex-shrink:0;border:.1875rem solid #626971;background-color:#fff;border-radius:.25rem;border-radius:var(--bpk-checkbox-border-radius, 0.25rem)}.bpk-checkbox-v2__control[data-focus-visible]{outline:.125rem solid #0062e3;outline-offset:.125rem}.bpk-checkbox-v2__control[data-state=checked]{border-width:.1875rem;border-color:#0062e3;border-color:var(--bpk-checkbox-selected-color, rgb(0, 98, 227));background-color:#0062e3;background-color:var(--bpk-checkbox-selected-color, rgb(0, 98, 227));background-image:url("data:image/svg+xml,%3Csvg%20width%3D%2213%22%20height%3D%229%22%20viewBox%3D%220%200%2013%209%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M2.35352%203.64648L5.5%207.5L11.5%201.5%22%20stroke%3D%22white%22%20stroke-width%3D%223%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E");background-repeat:no-repeat;background-position:.0625rem center;background-size:calc(100% - .15625rem) auto}.bpk-checkbox-v2__control[data-state=checked]:disabled{background-image:url("data:image/svg+xml,%3Csvg%20width%3D%2213%22%20height%3D%229%22%20viewBox%3D%220%200%2013%209%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M2.35352%203.64648L5.5%207.5L11.5%201.5%22%20stroke%3D%22lightgrey%22%20stroke-width%3D%223%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E")}.bpk-checkbox-v2__control[data-state=indeterminate]{border-width:.1875rem;border-color:#0062e3;border-color:var(--bpk-checkbox-selected-color, rgb(0, 98, 227));background-color:#0062e3;background-color:var(--bpk-checkbox-selected-color, rgb(0, 98, 227))}.bpk-checkbox-v2__control[data-state=indeterminate]::before{content:"";width:.625rem;height:.1875rem;border-radius:2px;background-color:#fff}.bpk-checkbox-v2__control[data-invalid]{border-color:#e70866}.bpk-checkbox-v2__control[data-disabled]{border-color:rgba(0,0,0,.2);background-color:#fff}.bpk-checkbox-v2__control[data-disabled][data-state=checked],.bpk-checkbox-v2__control[data-disabled][data-state=indeterminate]{border-color:rgba(0,0,0,.2);background-color:#fff}.bpk-checkbox-v2__control[data-disabled][data-state=checked]{background-image:url("data:image/svg+xml,%3Csvg%20width%3D%2213%22%20height%3D%229%22%20viewBox%3D%220%200%2013%209%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M2.35352%203.64648L5.5%207.5L11.5%201.5%22%20stroke%3D%22lightgrey%22%20stroke-width%3D%223%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E")}.bpk-checkbox-v2__label{color:#161616;user-select:none;font-size:1rem;line-height:1.5rem;font-weight:400}.bpk-checkbox-v2__label a{color:inherit}[data-disabled] .bpk-checkbox-v2__label{color:rgba(0,0,0,.2)}.bpk-checkbox-v2__description{display:block;margin-top:.25rem;color:#626971;font-size:.875rem;line-height:1.25rem;font-weight:400}[data-disabled] .bpk-checkbox-v2__description{color:rgba(0,0,0,.2)}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type BpkCheckboxV2ControlProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
};
|
|
5
|
+
declare const BpkCheckboxV2Control: ({ children }: BpkCheckboxV2ControlProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export default BpkCheckboxV2Control;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { Checkbox } from '@ark-ui/react';
|
|
20
|
+
import { cssModules } from "../../../bpk-react-utils";
|
|
21
|
+
import STYLES from "./BpkCheckboxV2.module.css";
|
|
22
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
|
+
const getClassName = cssModules(STYLES);
|
|
24
|
+
const BpkCheckboxV2Control = ({
|
|
25
|
+
children
|
|
26
|
+
}) => /*#__PURE__*/_jsx(Checkbox.Control, {
|
|
27
|
+
className: getClassName('bpk-checkbox-v2__control'),
|
|
28
|
+
children: children
|
|
29
|
+
});
|
|
30
|
+
export default BpkCheckboxV2Control;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type BpkCheckboxV2DescriptionProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
};
|
|
5
|
+
declare const BpkCheckboxV2Description: ({ children }: BpkCheckboxV2DescriptionProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export default BpkCheckboxV2Description;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { cssModules } from "../../../bpk-react-utils";
|
|
20
|
+
import STYLES from "./BpkCheckboxV2.module.css";
|
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
+
const getClassName = cssModules(STYLES);
|
|
23
|
+
// Description renders as a <span> inside the Checkbox.Root <label>.
|
|
24
|
+
// Being inside the <label> element means screen readers announce its text
|
|
25
|
+
// as part of the checkbox's accessible name.
|
|
26
|
+
const BpkCheckboxV2Description = ({
|
|
27
|
+
children
|
|
28
|
+
}) => /*#__PURE__*/_jsx("span", {
|
|
29
|
+
className: getClassName('bpk-checkbox-v2__description'),
|
|
30
|
+
children: children
|
|
31
|
+
});
|
|
32
|
+
export default BpkCheckboxV2Description;
|