@transferwise/components 46.160.1 → 46.160.3
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/build/Calendar/Calendar.js +9 -3
- package/build/Calendar/Calendar.js.map +1 -1
- package/build/Calendar/Calendar.mjs +9 -3
- package/build/Calendar/Calendar.mjs.map +1 -1
- package/build/Carousel/Carousel.js +17 -10
- package/build/Carousel/Carousel.js.map +1 -1
- package/build/Carousel/Carousel.mjs +17 -10
- package/build/Carousel/Carousel.mjs.map +1 -1
- package/build/Inputs/SelectInput/Options/SelectInputOptions.js +33 -5
- package/build/Inputs/SelectInput/Options/SelectInputOptions.js.map +1 -1
- package/build/Inputs/SelectInput/Options/SelectInputOptions.mjs +34 -6
- package/build/Inputs/SelectInput/Options/SelectInputOptions.mjs.map +1 -1
- package/build/Inputs/SelectInput/SelectInput.js +28 -4
- package/build/Inputs/SelectInput/SelectInput.js.map +1 -1
- package/build/Inputs/SelectInput/SelectInput.mjs +29 -5
- package/build/Inputs/SelectInput/SelectInput.mjs.map +1 -1
- package/build/Inputs/SelectInput/SelectInput.utils.js +0 -2
- package/build/Inputs/SelectInput/SelectInput.utils.js.map +1 -1
- package/build/Inputs/SelectInput/SelectInput.utils.mjs +1 -2
- package/build/Inputs/SelectInput/SelectInput.utils.mjs.map +1 -1
- package/build/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js +5 -1
- package/build/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js.map +1 -1
- package/build/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs +5 -1
- package/build/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs.map +1 -1
- package/build/Inputs/SelectInput/constants.js +8 -0
- package/build/Inputs/SelectInput/constants.js.map +1 -0
- package/build/Inputs/SelectInput/constants.mjs +5 -0
- package/build/Inputs/SelectInput/constants.mjs.map +1 -0
- package/build/Inputs/SelectInput/hooks/useTypeahead.js +57 -0
- package/build/Inputs/SelectInput/hooks/useTypeahead.js.map +1 -0
- package/build/Inputs/SelectInput/hooks/useTypeahead.mjs +54 -0
- package/build/Inputs/SelectInput/hooks/useTypeahead.mjs.map +1 -0
- package/build/SegmentedControl/SegmentedControl.js +9 -2
- package/build/SegmentedControl/SegmentedControl.js.map +1 -1
- package/build/SegmentedControl/SegmentedControl.mjs +9 -2
- package/build/SegmentedControl/SegmentedControl.mjs.map +1 -1
- package/build/Tooltip/Tooltip.js +6 -1
- package/build/Tooltip/Tooltip.js.map +1 -1
- package/build/Tooltip/Tooltip.mjs +6 -1
- package/build/Tooltip/Tooltip.mjs.map +1 -1
- package/build/i18n/ja.json +1 -1
- package/build/i18n/ja.json.js +1 -1
- package/build/i18n/ja.json.mjs +1 -1
- package/build/i18n/tr.json +5 -0
- package/build/i18n/tr.json.js +5 -0
- package/build/i18n/tr.json.js.map +1 -1
- package/build/i18n/tr.json.mjs +5 -0
- package/build/i18n/tr.json.mjs.map +1 -1
- package/build/i18n/zh-CN.json +5 -0
- package/build/i18n/zh-CN.json.js +5 -0
- package/build/i18n/zh-CN.json.js.map +1 -1
- package/build/i18n/zh-CN.json.mjs +5 -0
- package/build/i18n/zh-CN.json.mjs.map +1 -1
- package/build/main.css +34 -22
- package/build/styles/AvatarLayout/AvatarLayout.css +26 -9
- package/build/styles/SegmentedControl/SegmentedControl.css +2 -1
- package/build/styles/Tooltip/Tooltip.css +0 -6
- package/build/styles/common/Panel/Panel.css +6 -6
- package/build/styles/main.css +34 -22
- package/build/types/Calendar/Calendar.d.ts.map +1 -1
- package/build/types/Carousel/Carousel.d.ts.map +1 -1
- package/build/types/Carousel/_stories/constants.d.ts +3 -0
- package/build/types/Carousel/_stories/constants.d.ts.map +1 -0
- package/build/types/Inputs/SelectInput/Options/SelectInputOptions.d.ts +3 -1
- package/build/types/Inputs/SelectInput/Options/SelectInputOptions.d.ts.map +1 -1
- package/build/types/Inputs/SelectInput/SelectInput.d.ts.map +1 -1
- package/build/types/Inputs/SelectInput/SelectInput.utils.d.ts +0 -1
- package/build/types/Inputs/SelectInput/SelectInput.utils.d.ts.map +1 -1
- package/build/types/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts.map +1 -1
- package/build/types/Inputs/SelectInput/constants.d.ts +3 -0
- package/build/types/Inputs/SelectInput/constants.d.ts.map +1 -0
- package/build/types/Inputs/SelectInput/hooks/useTypeahead.d.ts +8 -0
- package/build/types/Inputs/SelectInput/hooks/useTypeahead.d.ts.map +1 -0
- package/build/types/SegmentedControl/SegmentedControl.d.ts.map +1 -1
- package/build/types/Tooltip/Tooltip.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/AvatarLayout/AvatarLayout.css +26 -9
- package/src/AvatarLayout/AvatarLayout.less +46 -22
- package/src/AvatarLayout/_stories/AvatarLayout.test.story.tsx +17 -42
- package/src/Calendar/Calendar.test.tsx +82 -0
- package/src/Calendar/Calendar.tsx +6 -3
- package/src/Carousel/Carousel.test.tsx +50 -2
- package/src/Carousel/Carousel.tsx +13 -10
- package/src/Carousel/_stories/Carousel.story.tsx +12 -52
- package/src/Carousel/_stories/Carousel.test.story.tsx +7 -43
- package/src/Carousel/_stories/constants.tsx +46 -0
- package/src/DateLookup/_stories/DateLookup.rtl.test.story.tsx +59 -48
- package/src/Field/_stories/Field.test.story.tsx +48 -37
- package/src/FlowNavigation/_stories/FlowNavigation.rtl.test.story.tsx +78 -0
- package/src/FlowNavigation/_stories/FlowNavigation.test.story.tsx +0 -44
- package/src/Inputs/SelectInput/Options/SelectInputOptions.tsx +36 -6
- package/src/Inputs/SelectInput/SelectInput.test.tsx +143 -0
- package/src/Inputs/SelectInput/SelectInput.tsx +31 -5
- package/src/Inputs/SelectInput/SelectInput.utils.ts +0 -2
- package/src/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx +3 -0
- package/src/Inputs/SelectInput/constants.ts +3 -0
- package/src/Inputs/SelectInput/hooks/useTypeahead.ts +82 -0
- package/src/Label/_stories/Label.test.story.tsx +35 -22
- package/src/Popover/_stories/Popover.rtl.test.story.tsx +40 -50
- package/src/SegmentedControl/SegmentedControl.css +2 -1
- package/src/SegmentedControl/SegmentedControl.less +4 -2
- package/src/SegmentedControl/SegmentedControl.tsx +8 -2
- package/src/SegmentedControl/_stories/SegmentedControl.test.story.tsx +16 -8
- package/src/Tooltip/Tooltip.css +0 -6
- package/src/Tooltip/Tooltip.less +0 -12
- package/src/Tooltip/Tooltip.test.tsx +51 -0
- package/src/Tooltip/Tooltip.tsx +11 -1
- package/src/Tooltip/_stories/Tooltip.rtl.test.story.tsx +16 -34
- package/src/common/Panel/Panel.css +6 -6
- package/src/common/Panel/Panel.less +6 -6
- package/src/i18n/ja.json +1 -1
- package/src/i18n/tr.json +5 -0
- package/src/i18n/zh-CN.json +5 -0
- package/src/main.css +34 -22
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var constants = require('../constants.js');
|
|
5
|
+
var SelectInput_utils = require('../SelectInput.utils.js');
|
|
6
|
+
|
|
7
|
+
const resetsTypeaheadQuery = key => key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End' || key === 'PageDown' || key === 'PageUp';
|
|
8
|
+
const isTypingKey = (event, query = '') => !event.metaKey && !event.ctrlKey && !event.nativeEvent.isComposing && /^.$/u.test(event.key) && (event.key !== ' ' || query !== '');
|
|
9
|
+
function useTypeahead({
|
|
10
|
+
disabled = false,
|
|
11
|
+
onMatch
|
|
12
|
+
} = {}) {
|
|
13
|
+
const queryRef = React.useRef('');
|
|
14
|
+
const timeoutRef = React.useRef(null);
|
|
15
|
+
const resetQuery = React.useCallback(() => {
|
|
16
|
+
queryRef.current = '';
|
|
17
|
+
if (timeoutRef.current != null) {
|
|
18
|
+
clearTimeout(timeoutRef.current);
|
|
19
|
+
timeoutRef.current = null;
|
|
20
|
+
}
|
|
21
|
+
}, []);
|
|
22
|
+
React.useEffect(() => resetQuery, [resetQuery]);
|
|
23
|
+
return React.useCallback(event => {
|
|
24
|
+
if (disabled || !isTypingKey(event, queryRef.current)) {
|
|
25
|
+
if (resetsTypeaheadQuery(event.key)) {
|
|
26
|
+
resetQuery();
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
event.stopPropagation();
|
|
32
|
+
queryRef.current += event.key;
|
|
33
|
+
const needle = SelectInput_utils.searchableString(queryRef.current);
|
|
34
|
+
if (timeoutRef.current != null) {
|
|
35
|
+
clearTimeout(timeoutRef.current);
|
|
36
|
+
}
|
|
37
|
+
timeoutRef.current = setTimeout(resetQuery, constants.TYPEAHEAD_QUERY_RESET_TIMEOUT_MS);
|
|
38
|
+
const options = Array.from(event.currentTarget.querySelectorAll('[role="option"]:not([aria-disabled="true"])'));
|
|
39
|
+
const optionLabels = options.map(option => SelectInput_utils.searchableString(option.textContent ?? ''));
|
|
40
|
+
const matchingIndex = optionLabels.findIndex(label => label.startsWith(needle));
|
|
41
|
+
const closestIndex = matchingIndex === -1 ? optionLabels.findIndex(label => label.includes(needle)) : matchingIndex;
|
|
42
|
+
if (closestIndex === -1) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
options[closestIndex].focus({
|
|
46
|
+
preventScroll: true
|
|
47
|
+
});
|
|
48
|
+
event.currentTarget.focus({
|
|
49
|
+
preventScroll: true
|
|
50
|
+
});
|
|
51
|
+
onMatch?.();
|
|
52
|
+
}, [disabled, onMatch, resetQuery]);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.isTypingKey = isTypingKey;
|
|
56
|
+
exports.useTypeahead = useTypeahead;
|
|
57
|
+
//# sourceMappingURL=useTypeahead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTypeahead.js","sources":["../../../../src/Inputs/SelectInput/hooks/useTypeahead.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nimport { TYPEAHEAD_QUERY_RESET_TIMEOUT_MS } from '../constants';\nimport { searchableString } from '../SelectInput.utils';\n\nconst resetsTypeaheadQuery = (key: string) =>\n key === 'ArrowDown' ||\n key === 'ArrowUp' ||\n key === 'Home' ||\n key === 'End' ||\n key === 'PageDown' ||\n key === 'PageUp';\n\nexport const isTypingKey = (event: React.KeyboardEvent, query = '') =>\n !event.metaKey &&\n !event.ctrlKey &&\n !event.nativeEvent.isComposing &&\n /^.$/u.test(event.key) &&\n (event.key !== ' ' || query !== '');\n\ninterface UseTypeaheadParams {\n disabled?: boolean;\n onMatch?: () => void;\n}\n\nexport function useTypeahead({ disabled = false, onMatch }: UseTypeaheadParams = {}) {\n const queryRef = useRef('');\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const resetQuery = useCallback(() => {\n queryRef.current = '';\n if (timeoutRef.current != null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n }, []);\n\n useEffect(() => resetQuery, [resetQuery]);\n\n return useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (disabled || !isTypingKey(event, queryRef.current)) {\n if (resetsTypeaheadQuery(event.key)) {\n resetQuery();\n }\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n queryRef.current += event.key;\n const needle = searchableString(queryRef.current);\n\n if (timeoutRef.current != null) {\n clearTimeout(timeoutRef.current);\n }\n timeoutRef.current = setTimeout(resetQuery, TYPEAHEAD_QUERY_RESET_TIMEOUT_MS);\n\n const options = Array.from(\n event.currentTarget.querySelectorAll<HTMLElement>(\n '[role=\"option\"]:not([aria-disabled=\"true\"])',\n ),\n );\n const optionLabels = options.map((option) => searchableString(option.textContent ?? ''));\n const matchingIndex = optionLabels.findIndex((label) => label.startsWith(needle));\n const closestIndex =\n matchingIndex === -1\n ? optionLabels.findIndex((label) => label.includes(needle))\n : matchingIndex;\n\n if (closestIndex === -1) {\n return;\n }\n\n options[closestIndex].focus({ preventScroll: true });\n event.currentTarget.focus({ preventScroll: true });\n onMatch?.();\n },\n [disabled, onMatch, resetQuery],\n );\n}\n"],"names":["resetsTypeaheadQuery","key","isTypingKey","event","query","metaKey","ctrlKey","nativeEvent","isComposing","test","useTypeahead","disabled","onMatch","queryRef","useRef","timeoutRef","resetQuery","useCallback","current","clearTimeout","useEffect","preventDefault","stopPropagation","needle","searchableString","setTimeout","TYPEAHEAD_QUERY_RESET_TIMEOUT_MS","options","Array","from","currentTarget","querySelectorAll","optionLabels","map","option","textContent","matchingIndex","findIndex","label","startsWith","closestIndex","includes","focus","preventScroll"],"mappings":";;;;;;AAKA,MAAMA,oBAAoB,GAAIC,GAAW,IACvCA,GAAG,KAAK,WAAW,IACnBA,GAAG,KAAK,SAAS,IACjBA,GAAG,KAAK,MAAM,IACdA,GAAG,KAAK,KAAK,IACbA,GAAG,KAAK,UAAU,IAClBA,GAAG,KAAK,QAAQ;AAEX,MAAMC,WAAW,GAAGA,CAACC,KAA0B,EAAEC,KAAK,GAAG,EAAE,KAChE,CAACD,KAAK,CAACE,OAAO,IACd,CAACF,KAAK,CAACG,OAAO,IACd,CAACH,KAAK,CAACI,WAAW,CAACC,WAAW,IAC9B,MAAM,CAACC,IAAI,CAACN,KAAK,CAACF,GAAG,CAAC,KACrBE,KAAK,CAACF,GAAG,KAAK,GAAG,IAAIG,KAAK,KAAK,EAAE;AAO9B,SAAUM,YAAYA,CAAC;AAAEC,EAAAA,QAAQ,GAAG,KAAK;AAAEC,EAAAA;AAAO,CAAA,GAAyB,EAAE,EAAA;AACjF,EAAA,MAAMC,QAAQ,GAAGC,YAAM,CAAC,EAAE,CAAC;AAC3B,EAAA,MAAMC,UAAU,GAAGD,YAAM,CAAuC,IAAI,CAAC;AAErE,EAAA,MAAME,UAAU,GAAGC,iBAAW,CAAC,MAAK;IAClCJ,QAAQ,CAACK,OAAO,GAAG,EAAE;AACrB,IAAA,IAAIH,UAAU,CAACG,OAAO,IAAI,IAAI,EAAE;AAC9BC,MAAAA,YAAY,CAACJ,UAAU,CAACG,OAAO,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ACK,SAAS,CAAEC,KAAK,IAAKA,KAAK,CAACG,QAAQ,CAAClB,MAAM,CAAC,CAAC,GACzDa,aAAa;AAEnB,IAAA,IAAII,YAAY,KAAK,EAAE,EAAE;AACvB,MAAA;AACF,IAAA;AAEAb,IAAAA,OAAO,CAACa,YAAY,CAAC,CAACE,KAAK,CAAC;AAAEC,MAAAA,aAAa,EAAE;AAAI,KAAE,CAAC;AACpDxC,IAAAA,KAAK,CAAC2B,aAAa,CAACY,KAAK,CAAC;AAAEC,MAAAA,aAAa,EAAE;AAAI,KAAE,CAAC;AAClD/B,IAAAA,OAAO,IAAI;EACb,CAAC,EACD,CAACD,QAAQ,EAAEC,OAAO,EAAEI,UAAU,CAAC,CAChC;AACH;;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
2
|
+
import { TYPEAHEAD_QUERY_RESET_TIMEOUT_MS } from '../constants.mjs';
|
|
3
|
+
import { searchableString } from '../SelectInput.utils.mjs';
|
|
4
|
+
|
|
5
|
+
const resetsTypeaheadQuery = key => key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End' || key === 'PageDown' || key === 'PageUp';
|
|
6
|
+
const isTypingKey = (event, query = '') => !event.metaKey && !event.ctrlKey && !event.nativeEvent.isComposing && /^.$/u.test(event.key) && (event.key !== ' ' || query !== '');
|
|
7
|
+
function useTypeahead({
|
|
8
|
+
disabled = false,
|
|
9
|
+
onMatch
|
|
10
|
+
} = {}) {
|
|
11
|
+
const queryRef = useRef('');
|
|
12
|
+
const timeoutRef = useRef(null);
|
|
13
|
+
const resetQuery = useCallback(() => {
|
|
14
|
+
queryRef.current = '';
|
|
15
|
+
if (timeoutRef.current != null) {
|
|
16
|
+
clearTimeout(timeoutRef.current);
|
|
17
|
+
timeoutRef.current = null;
|
|
18
|
+
}
|
|
19
|
+
}, []);
|
|
20
|
+
useEffect(() => resetQuery, [resetQuery]);
|
|
21
|
+
return useCallback(event => {
|
|
22
|
+
if (disabled || !isTypingKey(event, queryRef.current)) {
|
|
23
|
+
if (resetsTypeaheadQuery(event.key)) {
|
|
24
|
+
resetQuery();
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
event.stopPropagation();
|
|
30
|
+
queryRef.current += event.key;
|
|
31
|
+
const needle = searchableString(queryRef.current);
|
|
32
|
+
if (timeoutRef.current != null) {
|
|
33
|
+
clearTimeout(timeoutRef.current);
|
|
34
|
+
}
|
|
35
|
+
timeoutRef.current = setTimeout(resetQuery, TYPEAHEAD_QUERY_RESET_TIMEOUT_MS);
|
|
36
|
+
const options = Array.from(event.currentTarget.querySelectorAll('[role="option"]:not([aria-disabled="true"])'));
|
|
37
|
+
const optionLabels = options.map(option => searchableString(option.textContent ?? ''));
|
|
38
|
+
const matchingIndex = optionLabels.findIndex(label => label.startsWith(needle));
|
|
39
|
+
const closestIndex = matchingIndex === -1 ? optionLabels.findIndex(label => label.includes(needle)) : matchingIndex;
|
|
40
|
+
if (closestIndex === -1) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
options[closestIndex].focus({
|
|
44
|
+
preventScroll: true
|
|
45
|
+
});
|
|
46
|
+
event.currentTarget.focus({
|
|
47
|
+
preventScroll: true
|
|
48
|
+
});
|
|
49
|
+
onMatch?.();
|
|
50
|
+
}, [disabled, onMatch, resetQuery]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { isTypingKey, useTypeahead };
|
|
54
|
+
//# sourceMappingURL=useTypeahead.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTypeahead.mjs","sources":["../../../../src/Inputs/SelectInput/hooks/useTypeahead.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nimport { TYPEAHEAD_QUERY_RESET_TIMEOUT_MS } from '../constants';\nimport { searchableString } from '../SelectInput.utils';\n\nconst resetsTypeaheadQuery = (key: string) =>\n key === 'ArrowDown' ||\n key === 'ArrowUp' ||\n key === 'Home' ||\n key === 'End' ||\n key === 'PageDown' ||\n key === 'PageUp';\n\nexport const isTypingKey = (event: React.KeyboardEvent, query = '') =>\n !event.metaKey &&\n !event.ctrlKey &&\n !event.nativeEvent.isComposing &&\n /^.$/u.test(event.key) &&\n (event.key !== ' ' || query !== '');\n\ninterface UseTypeaheadParams {\n disabled?: boolean;\n onMatch?: () => void;\n}\n\nexport function useTypeahead({ disabled = false, onMatch }: UseTypeaheadParams = {}) {\n const queryRef = useRef('');\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const resetQuery = useCallback(() => {\n queryRef.current = '';\n if (timeoutRef.current != null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n }, []);\n\n useEffect(() => resetQuery, [resetQuery]);\n\n return useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (disabled || !isTypingKey(event, queryRef.current)) {\n if (resetsTypeaheadQuery(event.key)) {\n resetQuery();\n }\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n queryRef.current += event.key;\n const needle = searchableString(queryRef.current);\n\n if (timeoutRef.current != null) {\n clearTimeout(timeoutRef.current);\n }\n timeoutRef.current = setTimeout(resetQuery, TYPEAHEAD_QUERY_RESET_TIMEOUT_MS);\n\n const options = Array.from(\n event.currentTarget.querySelectorAll<HTMLElement>(\n '[role=\"option\"]:not([aria-disabled=\"true\"])',\n ),\n );\n const optionLabels = options.map((option) => searchableString(option.textContent ?? ''));\n const matchingIndex = optionLabels.findIndex((label) => label.startsWith(needle));\n const closestIndex =\n matchingIndex === -1\n ? optionLabels.findIndex((label) => label.includes(needle))\n : matchingIndex;\n\n if (closestIndex === -1) {\n return;\n }\n\n options[closestIndex].focus({ preventScroll: true });\n event.currentTarget.focus({ preventScroll: true });\n onMatch?.();\n },\n [disabled, onMatch, resetQuery],\n );\n}\n"],"names":["resetsTypeaheadQuery","key","isTypingKey","event","query","metaKey","ctrlKey","nativeEvent","isComposing","test","useTypeahead","disabled","onMatch","queryRef","useRef","timeoutRef","resetQuery","useCallback","current","clearTimeout","useEffect","preventDefault","stopPropagation","needle","searchableString","setTimeout","TYPEAHEAD_QUERY_RESET_TIMEOUT_MS","options","Array","from","currentTarget","querySelectorAll","optionLabels","map","option","textContent","matchingIndex","findIndex","label","startsWith","closestIndex","includes","focus","preventScroll"],"mappings":";;;;AAKA,MAAMA,oBAAoB,GAAIC,GAAW,IACvCA,GAAG,KAAK,WAAW,IACnBA,GAAG,KAAK,SAAS,IACjBA,GAAG,KAAK,MAAM,IACdA,GAAG,KAAK,KAAK,IACbA,GAAG,KAAK,UAAU,IAClBA,GAAG,KAAK,QAAQ;AAEX,MAAMC,WAAW,GAAGA,CAACC,KAA0B,EAAEC,KAAK,GAAG,EAAE,KAChE,CAACD,KAAK,CAACE,OAAO,IACd,CAACF,KAAK,CAACG,OAAO,IACd,CAACH,KAAK,CAACI,WAAW,CAACC,WAAW,IAC9B,MAAM,CAACC,IAAI,CAACN,KAAK,CAACF,GAAG,CAAC,KACrBE,KAAK,CAACF,GAAG,KAAK,GAAG,IAAIG,KAAK,KAAK,EAAE;AAO9B,SAAUM,YAAYA,CAAC;AAAEC,EAAAA,QAAQ,GAAG,KAAK;AAAEC,EAAAA;AAAO,CAAA,GAAyB,EAAE,EAAA;AACjF,EAAA,MAAMC,QAAQ,GAAGC,MAAM,CAAC,EAAE,CAAC;AAC3B,EAAA,MAAMC,UAAU,GAAGD,MAAM,CAAuC,IAAI,CAAC;AAErE,EAAA,MAAME,UAAU,GAAGC,WAAW,CAAC,MAAK;IAClCJ,QAAQ,CAACK,OAAO,GAAG,EAAE;AACrB,IAAA,IAAIH,UAAU,CAACG,OAAO,IAAI,IAAI,EAAE;AAC9BC,MAAAA,YAAY,CAACJ,UAAU,CAACG,OAAO,CAAC;MAChCH,UAAU,CAACG,OAAO,GAAG,IAAI;AAC3B,IAAA;EACF,CAAC,EAAE,EAAE,CAAC;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;AAEnB,IAAA,IAAII,YAAY,KAAK,EAAE,EAAE;AACvB,MAAA;AACF,IAAA;AAEAb,IAAAA,OAAO,CAACa,YAAY,CAAC,CAACE,KAAK,CAAC;AAAEC,MAAAA,aAAa,EAAE;AAAI,KAAE,CAAC;AACpDxC,IAAAA,KAAK,CAAC2B,aAAa,CAACY,KAAK,CAAC;AAAEC,MAAAA,aAAa,EAAE;AAAI,KAAE,CAAC;AAClD/B,IAAAA,OAAO,IAAI;EACb,CAAC,EACD,CAACD,QAAQ,EAAEC,OAAO,EAAEI,UAAU,CAAC,CAChC;AACH;;;;"}
|
|
@@ -29,6 +29,8 @@ require('@transferwise/icons');
|
|
|
29
29
|
require('react-intl');
|
|
30
30
|
require('../common/CloseButton/CloseButton.messages.js');
|
|
31
31
|
var jsxRuntime = require('react/jsx-runtime');
|
|
32
|
+
require('@transferwise/neptune-validation');
|
|
33
|
+
var useDirection = require('../common/hooks/useDirection/useDirection.js');
|
|
32
34
|
|
|
33
35
|
const SegmentedControl = ({
|
|
34
36
|
name,
|
|
@@ -39,6 +41,9 @@ const SegmentedControl = ({
|
|
|
39
41
|
}) => {
|
|
40
42
|
const isMountedRef = React.useRef(false);
|
|
41
43
|
const [animate, setAnimate] = React.useState(false);
|
|
44
|
+
const {
|
|
45
|
+
isRTL
|
|
46
|
+
} = useDirection.useDirection();
|
|
42
47
|
const segmentsRef = React.useRef(null);
|
|
43
48
|
if (segments.length > 3) {
|
|
44
49
|
throw new Error('SegmentedControl only supports up to 3 segments. Please refer to: https://docs.wise.design/components/segmented-control');
|
|
@@ -56,8 +61,10 @@ const SegmentedControl = ({
|
|
|
56
61
|
const {
|
|
57
62
|
style
|
|
58
63
|
} = segmentsRef.current;
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
const segment = selectedSegmentRef.current;
|
|
65
|
+
const inlineOffset = isRTL ? segmentsRef.current.offsetWidth - segment.offsetLeft - segment.offsetWidth : segment.offsetLeft;
|
|
66
|
+
style.setProperty('--segment-highlight-width', `${segment.offsetWidth}px`);
|
|
67
|
+
style.setProperty('--segment-highlight-x', `${inlineOffset}px`);
|
|
61
68
|
}
|
|
62
69
|
};
|
|
63
70
|
React.useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.js","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { createRef, useEffect, useRef, useState } from 'react';\n\nimport Body from '../Body';\nimport { Typography } from '../common';\n\ntype SegmentBase = { id: string; label: string; value: string };\n\ntype Segment = SegmentBase & { controls?: never };\ntype SegmentWithControls = SegmentBase & { controls: string };\n\nexport type Segments = readonly Segment[] | readonly SegmentWithControls[];\n\ntype SegmentedControlPropsBase = {\n name: string;\n value: string;\n mode: 'input' | 'view';\n onChange: (value: string) => void;\n};\n\ntype SegmentedControlViewProps = {\n mode: 'view';\n segments: readonly SegmentWithControls[];\n};\n\ntype SegmentedControlInputProps = {\n mode: 'input';\n segments: readonly Segment[];\n};\n\nexport type SegmentedControlProps = SegmentedControlPropsBase &\n (SegmentedControlViewProps | SegmentedControlInputProps);\n\nconst SegmentedControl = ({\n name,\n value,\n mode = 'input',\n segments,\n onChange,\n}: SegmentedControlProps) => {\n const isMountedRef = useRef(false);\n const [animate, setAnimate] = useState(false);\n\n const segmentsRef = useRef<HTMLDivElement>(null);\n\n if (segments.length > 3) {\n throw new Error(\n 'SegmentedControl only supports up to 3 segments. Please refer to: https://docs.wise.design/components/segmented-control',\n );\n }\n\n const segmentsWithRefs = segments.map((segment) => ({\n ...segment,\n ref: createRef<HTMLLabelElement | HTMLButtonElement>(),\n }));\n\n const updateSegmentPosition = () => {\n const selectedSegmentRef = segmentsWithRefs.find((segment) => segment.value === value)?.ref;\n\n // We grab the active segments style object from the ref\n // and set the css variables to the selected segments width and x position.\n // This is so we can animate the highlight to the selected segment\n if (selectedSegmentRef?.current && segmentsRef.current) {\n const { style } = segmentsRef.current;\n style.setProperty('--segment-highlight-width', `${selectedSegmentRef.current.offsetWidth}px`);\n style.setProperty('--segment-highlight-x', `${selectedSegmentRef.current.offsetLeft}px`);\n }\n };\n\n useEffect(() => {\n if (isMountedRef.current) {\n setAnimate(true);\n } else {\n isMountedRef.current = true;\n }\n\n updateSegmentPosition();\n\n const handleWindowSizeChange = () => {\n setAnimate(false);\n updateSegmentPosition();\n };\n\n window.addEventListener('resize', handleWindowSizeChange);\n return () => {\n window.removeEventListener('resize', handleWindowSizeChange);\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [segmentsWithRefs, value]);\n\n return (\n <div\n ref={segmentsRef}\n data-testid=\"segmented-control\"\n className={clsx('segmented-control', {\n 'segmented-control--input': mode === 'input',\n })}\n >\n <div\n className={clsx('segmented-control__segments', {\n 'segmented-control__segments--no-animate': !animate,\n })}\n role={mode !== 'input' ? 'tablist' : undefined}\n >\n {segmentsWithRefs.map((segment) => {\n const onSelect = () => {\n setAnimate(true);\n onChange(segment.value);\n };\n return mode === 'input' ? (\n <label\n ref={segment.ref as React.MutableRefObject<HTMLLabelElement | null>}\n key={segment.id}\n htmlFor={segment.id}\n className={clsx('segmented-control__segment', {\n 'segmented-control__selected-segment': value === segment.value,\n })}\n >\n <input\n type=\"radio\"\n className=\"segmented-control__radio-input\"\n id={segment.id}\n name={name}\n value={segment.value}\n checked={value === segment.value}\n onChange={onSelect}\n />\n <Body\n className=\"segmented-control__text\"\n as=\"span\"\n type={\n value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT\n }\n >\n {segment.label}\n </Body>\n </label>\n ) : (\n <button\n ref={segment.ref as React.MutableRefObject<HTMLButtonElement | null>}\n key={segment.id}\n type=\"button\"\n role=\"tab\"\n id={segment.id}\n aria-controls={segment.controls}\n aria-selected={value === segment.value}\n className={clsx('segmented-control__segment', 'segmented-control__button', {\n 'segmented-control__selected-segment': value === segment.value,\n })}\n onClick={onSelect}\n >\n <Body\n as=\"span\"\n className=\"segmented-control__text\"\n type={\n value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT\n }\n >\n {segment.label}\n </Body>\n </button>\n );\n })}\n </div>\n </div>\n );\n};\n\nexport default SegmentedControl;\n"],"names":["SegmentedControl","name","value","mode","segments","onChange","isMountedRef","useRef","animate","setAnimate","useState","segmentsRef","length","Error","segmentsWithRefs","map","segment","ref","createRef","updateSegmentPosition","selectedSegmentRef","find","current","style","setProperty","offsetWidth","offsetLeft","useEffect","handleWindowSizeChange","window","addEventListener","removeEventListener","_jsx","className","clsx","children","role","undefined","onSelect","_jsxs","htmlFor","id","type","checked","Body","as","Typography","BODY_DEFAULT_BOLD","BODY_DEFAULT","label","controls","onClick"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAMA,gBAAgB,GAAGA,CAAC;EACxBC,IAAI;EACJC,KAAK;AACLC,EAAAA,IAAI,GAAG,OAAO;EACdC,QAAQ;AACRC,EAAAA;AAAQ,CACc,KAAI;AAC1B,EAAA,MAAMC,YAAY,GAAGC,YAAM,CAAC,KAAK,CAAC;EAClC,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;AAE7C,EAAA,MAAMC,WAAW,GAAGJ,YAAM,CAAiB,IAAI,CAAC;AAEhD,EAAA,IAAIH,QAAQ,CAACQ,MAAM,GAAG,CAAC,EAAE;AACvB,IAAA,MAAM,IAAIC,KAAK,CACb,yHAAyH,CAC1H;AACH,EAAA;AAEA,EAAA,MAAMC,gBAAgB,GAAGV,QAAQ,CAACW,GAAG,CAAEC,OAAO,KAAM;AAClD,IAAA,GAAGA,OAAO;IACVC,GAAG,eAAEC,eAAS;AACf,GAAA,CAAC,CAAC;EAEH,MAAMC,qBAAqB,GAAGA,MAAK;AACjC,IAAA,MAAMC,kBAAkB,GAAGN,gBAAgB,CAACO,IAAI,CAAEL,OAAO,IAAKA,OAAO,CAACd,KAAK,KAAKA,KAAK,CAAC,EAAEe,GA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E,YACrE;YAAAb,QAAA,EAEAnB,OAAO,CAACiC;AAAK,WACV,CACR;AAAA,SAAA,EAxBOjC,OAAO,CAACyB,EAwBR,CAAC,gBAERT,cAAA,CAAA,QAAA,EAAA;UACEf,GAAG,EAAED,OAAO,CAACC,GAAwD;AAErEyB,UAAAA,IAAI,EAAC,QAAQ;AACbN,UAAAA,IAAI,EAAC,KAAK;UACVK,EAAE,EAAEzB,OAAO,CAACyB,EAAG;UACf,eAAA,EAAezB,OAAO,CAACkC,QAAS;AAChC,UAAA,eAAA,EAAehD,KAAK,KAAKc,OAAO,CAACd,KAAM;AACvC+B,UAAAA,SAAS,EAAEC,SAAI,CAAC,4BAA4B,EAAE,2BAA2B,EAAE;AACzE,YAAA,qCAAqC,EAAEhC,KAAK,KAAKc,OAAO,CAACd;AAC1D,WAAA,CAAE;AACHiD,UAAAA,OAAO,EAAEb,QAAS;UAAAH,QAAA,eAElBH,cAAA,CAACY,YAAI,EAAA;AACHC,YAAAA,EAAE,EAAC,MAAM;AACTZ,YAAAA,SAAS,EAAC,yBAAyB;AACnCS,YAAAA,IAAI,EACFxC,KAAK,KAAKc,OAAO,CAACd,KAAK,GAAG4C,qBAAU,CAACC,iBAAiB,GAAGD,qBAAU,CAACE,YACrE;YAAAb,QAAA,EAEAnB,OAAO,CAACiC;WACL;SACR,EApBOjC,OAAO,CAACyB,EAoBP,CACT;MACH,CAAC;KACE;AACP,GAAK,CAAC;AAEV;;;;"}
|
|
1
|
+
{"version":3,"file":"SegmentedControl.js","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { createRef, useEffect, useRef, useState } from 'react';\n\nimport Body from '../Body';\nimport { Typography } from '../common';\nimport { useDirection } from '../common/hooks';\n\ntype SegmentBase = { id: string; label: string; value: string };\n\ntype Segment = SegmentBase & { controls?: never };\ntype SegmentWithControls = SegmentBase & { controls: string };\n\nexport type Segments = readonly Segment[] | readonly SegmentWithControls[];\n\ntype SegmentedControlPropsBase = {\n name: string;\n value: string;\n mode: 'input' | 'view';\n onChange: (value: string) => void;\n};\n\ntype SegmentedControlViewProps = {\n mode: 'view';\n segments: readonly SegmentWithControls[];\n};\n\ntype SegmentedControlInputProps = {\n mode: 'input';\n segments: readonly Segment[];\n};\n\nexport type SegmentedControlProps = SegmentedControlPropsBase &\n (SegmentedControlViewProps | SegmentedControlInputProps);\n\nconst SegmentedControl = ({\n name,\n value,\n mode = 'input',\n segments,\n onChange,\n}: SegmentedControlProps) => {\n const isMountedRef = useRef(false);\n const [animate, setAnimate] = useState(false);\n const { isRTL } = useDirection();\n\n const segmentsRef = useRef<HTMLDivElement>(null);\n\n if (segments.length > 3) {\n throw new Error(\n 'SegmentedControl only supports up to 3 segments. Please refer to: https://docs.wise.design/components/segmented-control',\n );\n }\n\n const segmentsWithRefs = segments.map((segment) => ({\n ...segment,\n ref: createRef<HTMLLabelElement | HTMLButtonElement>(),\n }));\n\n const updateSegmentPosition = () => {\n const selectedSegmentRef = segmentsWithRefs.find((segment) => segment.value === value)?.ref;\n\n // We grab the active segments style object from the ref\n // and set the css variables to the selected segments width and x position.\n // This is so we can animate the highlight to the selected segment\n if (selectedSegmentRef?.current && segmentsRef.current) {\n const { style } = segmentsRef.current;\n const segment = selectedSegmentRef.current;\n const inlineOffset = isRTL\n ? segmentsRef.current.offsetWidth - segment.offsetLeft - segment.offsetWidth\n : segment.offsetLeft;\n style.setProperty('--segment-highlight-width', `${segment.offsetWidth}px`);\n style.setProperty('--segment-highlight-x', `${inlineOffset}px`);\n }\n };\n\n useEffect(() => {\n if (isMountedRef.current) {\n setAnimate(true);\n } else {\n isMountedRef.current = true;\n }\n\n updateSegmentPosition();\n\n const handleWindowSizeChange = () => {\n setAnimate(false);\n updateSegmentPosition();\n };\n\n window.addEventListener('resize', handleWindowSizeChange);\n return () => {\n window.removeEventListener('resize', handleWindowSizeChange);\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [segmentsWithRefs, value]);\n\n return (\n <div\n ref={segmentsRef}\n data-testid=\"segmented-control\"\n className={clsx('segmented-control', {\n 'segmented-control--input': mode === 'input',\n })}\n >\n <div\n className={clsx('segmented-control__segments', {\n 'segmented-control__segments--no-animate': !animate,\n })}\n role={mode !== 'input' ? 'tablist' : undefined}\n >\n {segmentsWithRefs.map((segment) => {\n const onSelect = () => {\n setAnimate(true);\n onChange(segment.value);\n };\n return mode === 'input' ? (\n <label\n ref={segment.ref as React.MutableRefObject<HTMLLabelElement | null>}\n key={segment.id}\n htmlFor={segment.id}\n className={clsx('segmented-control__segment', {\n 'segmented-control__selected-segment': value === segment.value,\n })}\n >\n <input\n type=\"radio\"\n className=\"segmented-control__radio-input\"\n id={segment.id}\n name={name}\n value={segment.value}\n checked={value === segment.value}\n onChange={onSelect}\n />\n <Body\n className=\"segmented-control__text\"\n as=\"span\"\n type={\n value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT\n }\n >\n {segment.label}\n </Body>\n </label>\n ) : (\n <button\n ref={segment.ref as React.MutableRefObject<HTMLButtonElement | null>}\n key={segment.id}\n type=\"button\"\n role=\"tab\"\n id={segment.id}\n aria-controls={segment.controls}\n aria-selected={value === segment.value}\n className={clsx('segmented-control__segment', 'segmented-control__button', {\n 'segmented-control__selected-segment': value === segment.value,\n })}\n onClick={onSelect}\n >\n <Body\n as=\"span\"\n className=\"segmented-control__text\"\n type={\n value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT\n }\n >\n {segment.label}\n </Body>\n </button>\n );\n })}\n </div>\n </div>\n );\n};\n\nexport default SegmentedControl;\n"],"names":["SegmentedControl","name","value","mode","segments","onChange","isMountedRef","useRef","animate","setAnimate","useState","isRTL","useDirection","segmentsRef","length","Error","segmentsWithRefs","map","segment","ref","createRef","updateSegmentPosition","selectedSegmentRef","find","current","style","inlineOffset","offsetWidth","offsetLeft","setProperty","useEffect","handleWindowSizeChange","window","addEventListener","removeEventListener","_jsx","className","clsx","children","role","undefined","onSelect","_jsxs","htmlFor","id","type","checked","Body","as","Typography","BODY_DEFAULT_BOLD","BODY_DEFAULT","label","controls","onClick"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAMA,gBAAgB,GAAGA,CAAC;EACxBC,IAAI;EACJC,KAAK;AACLC,EAAAA,IAAI,GAAG,OAAO;EACdC,QAAQ;AACRC,EAAAA;AAAQ,CACc,KAAI;AAC1B,EAAA,MAAMC,YAAY,GAAGC,YAAM,CAAC,KAAK,CAAC;EAClC,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;EAC7C,MAAM;AAAEC,IAAAA;GAAO,GAAGC,yBAAY,EAAE;AAEhC,EAAA,MAAMC,WAAW,GAAGN,YAAM,CAAiB,IAAI,CAAC;AAEhD,EAAA,IAAIH,QAAQ,CAACU,MAAM,GAAG,CAAC,EAAE;AACvB,IAAA,MAAM,IAAIC,KAAK,CACb,yHAAyH,CAC1H;AACH,EAAA;AAEA,EAAA,MAAMC,gBAAgB,GAAGZ,QAAQ,CAACa,GAAG,CAAEC,OAAO,KAAM;AAClD,IAAA,GAAGA,OAAO;IACVC,GAAG,eAAEC,eAAS;AACf,GAAA,CAAC,CAAC;EAEH,MAAMC,qBAAqB,GAAGA,MAAK;AACjC,IAAA,MAAMC,kBAAkB,GAAGN,gBAAgB,CAACO,IAAI,CAAEL,OAAO,IAAKA,OAAO,CAAChB,KAAK,KAAKA,KAAK,CAAC,EAAEiB,GAAG;AAE3F;AACA;AACA;AACA,IAAA,IAAIG,kBAAkB,EAAEE,OAAO,IAAIX,WAAW,CAACW,OAAO,EAAE;MACtD,MAAM;AAAEC,QAAAA;OAAO,GAAGZ,WAAW,CAACW,OAAO;AACrC,MAAA,MAAMN,OAAO,GAAGI,kBAAkB,CAACE,OAAO;MAC1C,MAAME,YAAY,GAAGf,KAAK,GACtBE,WAAW,CAACW,OAAO,CAACG,WAAW,GAAGT,OA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GAAG,EAAED,OAAO,CAACC,GAAwD;AAErE0B,UAAAA,IAAI,EAAC,QAAQ;AACbN,UAAAA,IAAI,EAAC,KAAK;UACVK,EAAE,EAAE1B,OAAO,CAAC0B,EAAG;UACf,eAAA,EAAe1B,OAAO,CAACmC,QAAS;AAChC,UAAA,eAAA,EAAenD,KAAK,KAAKgB,OAAO,CAAChB,KAAM;AACvCkC,UAAAA,SAAS,EAAEC,SAAI,CAAC,4BAA4B,EAAE,2BAA2B,EAAE;AACzE,YAAA,qCAAqC,EAAEnC,KAAK,KAAKgB,OAAO,CAAChB;AAC1D,WAAA,CAAE;AACHoD,UAAAA,OAAO,EAAEb,QAAS;UAAAH,QAAA,eAElBH,cAAA,CAACY,YAAI,EAAA;AACHC,YAAAA,EAAE,EAAC,MAAM;AACTZ,YAAAA,SAAS,EAAC,yBAAyB;AACnCS,YAAAA,IAAI,EACF3C,KAAK,KAAKgB,OAAO,CAAChB,KAAK,GAAG+C,qBAAU,CAACC,iBAAiB,GAAGD,qBAAU,CAACE,YACrE;YAAAb,QAAA,EAEApB,OAAO,CAACkC;WACL;SACR,EApBOlC,OAAO,CAAC0B,EAoBP,CACT;MACH,CAAC;KACE;AACP,GAAK,CAAC;AAEV;;;;"}
|
|
@@ -25,6 +25,8 @@ import '@transferwise/icons';
|
|
|
25
25
|
import 'react-intl';
|
|
26
26
|
import '../common/CloseButton/CloseButton.messages.mjs';
|
|
27
27
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
28
|
+
import '@transferwise/neptune-validation';
|
|
29
|
+
import { useDirection } from '../common/hooks/useDirection/useDirection.mjs';
|
|
28
30
|
|
|
29
31
|
const SegmentedControl = ({
|
|
30
32
|
name,
|
|
@@ -35,6 +37,9 @@ const SegmentedControl = ({
|
|
|
35
37
|
}) => {
|
|
36
38
|
const isMountedRef = useRef(false);
|
|
37
39
|
const [animate, setAnimate] = useState(false);
|
|
40
|
+
const {
|
|
41
|
+
isRTL
|
|
42
|
+
} = useDirection();
|
|
38
43
|
const segmentsRef = useRef(null);
|
|
39
44
|
if (segments.length > 3) {
|
|
40
45
|
throw new Error('SegmentedControl only supports up to 3 segments. Please refer to: https://docs.wise.design/components/segmented-control');
|
|
@@ -52,8 +57,10 @@ const SegmentedControl = ({
|
|
|
52
57
|
const {
|
|
53
58
|
style
|
|
54
59
|
} = segmentsRef.current;
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
const segment = selectedSegmentRef.current;
|
|
61
|
+
const inlineOffset = isRTL ? segmentsRef.current.offsetWidth - segment.offsetLeft - segment.offsetWidth : segment.offsetLeft;
|
|
62
|
+
style.setProperty('--segment-highlight-width', `${segment.offsetWidth}px`);
|
|
63
|
+
style.setProperty('--segment-highlight-x', `${inlineOffset}px`);
|
|
57
64
|
}
|
|
58
65
|
};
|
|
59
66
|
useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.mjs","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { createRef, useEffect, useRef, useState } from 'react';\n\nimport Body from '../Body';\nimport { Typography } from '../common';\n\ntype SegmentBase = { id: string; label: string; value: string };\n\ntype Segment = SegmentBase & { controls?: never };\ntype SegmentWithControls = SegmentBase & { controls: string };\n\nexport type Segments = readonly Segment[] | readonly SegmentWithControls[];\n\ntype SegmentedControlPropsBase = {\n name: string;\n value: string;\n mode: 'input' | 'view';\n onChange: (value: string) => void;\n};\n\ntype SegmentedControlViewProps = {\n mode: 'view';\n segments: readonly SegmentWithControls[];\n};\n\ntype SegmentedControlInputProps = {\n mode: 'input';\n segments: readonly Segment[];\n};\n\nexport type SegmentedControlProps = SegmentedControlPropsBase &\n (SegmentedControlViewProps | SegmentedControlInputProps);\n\nconst SegmentedControl = ({\n name,\n value,\n mode = 'input',\n segments,\n onChange,\n}: SegmentedControlProps) => {\n const isMountedRef = useRef(false);\n const [animate, setAnimate] = useState(false);\n\n const segmentsRef = useRef<HTMLDivElement>(null);\n\n if (segments.length > 3) {\n throw new Error(\n 'SegmentedControl only supports up to 3 segments. Please refer to: https://docs.wise.design/components/segmented-control',\n );\n }\n\n const segmentsWithRefs = segments.map((segment) => ({\n ...segment,\n ref: createRef<HTMLLabelElement | HTMLButtonElement>(),\n }));\n\n const updateSegmentPosition = () => {\n const selectedSegmentRef = segmentsWithRefs.find((segment) => segment.value === value)?.ref;\n\n // We grab the active segments style object from the ref\n // and set the css variables to the selected segments width and x position.\n // This is so we can animate the highlight to the selected segment\n if (selectedSegmentRef?.current && segmentsRef.current) {\n const { style } = segmentsRef.current;\n style.setProperty('--segment-highlight-width', `${selectedSegmentRef.current.offsetWidth}px`);\n style.setProperty('--segment-highlight-x', `${selectedSegmentRef.current.offsetLeft}px`);\n }\n };\n\n useEffect(() => {\n if (isMountedRef.current) {\n setAnimate(true);\n } else {\n isMountedRef.current = true;\n }\n\n updateSegmentPosition();\n\n const handleWindowSizeChange = () => {\n setAnimate(false);\n updateSegmentPosition();\n };\n\n window.addEventListener('resize', handleWindowSizeChange);\n return () => {\n window.removeEventListener('resize', handleWindowSizeChange);\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [segmentsWithRefs, value]);\n\n return (\n <div\n ref={segmentsRef}\n data-testid=\"segmented-control\"\n className={clsx('segmented-control', {\n 'segmented-control--input': mode === 'input',\n })}\n >\n <div\n className={clsx('segmented-control__segments', {\n 'segmented-control__segments--no-animate': !animate,\n })}\n role={mode !== 'input' ? 'tablist' : undefined}\n >\n {segmentsWithRefs.map((segment) => {\n const onSelect = () => {\n setAnimate(true);\n onChange(segment.value);\n };\n return mode === 'input' ? (\n <label\n ref={segment.ref as React.MutableRefObject<HTMLLabelElement | null>}\n key={segment.id}\n htmlFor={segment.id}\n className={clsx('segmented-control__segment', {\n 'segmented-control__selected-segment': value === segment.value,\n })}\n >\n <input\n type=\"radio\"\n className=\"segmented-control__radio-input\"\n id={segment.id}\n name={name}\n value={segment.value}\n checked={value === segment.value}\n onChange={onSelect}\n />\n <Body\n className=\"segmented-control__text\"\n as=\"span\"\n type={\n value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT\n }\n >\n {segment.label}\n </Body>\n </label>\n ) : (\n <button\n ref={segment.ref as React.MutableRefObject<HTMLButtonElement | null>}\n key={segment.id}\n type=\"button\"\n role=\"tab\"\n id={segment.id}\n aria-controls={segment.controls}\n aria-selected={value === segment.value}\n className={clsx('segmented-control__segment', 'segmented-control__button', {\n 'segmented-control__selected-segment': value === segment.value,\n })}\n onClick={onSelect}\n >\n <Body\n as=\"span\"\n className=\"segmented-control__text\"\n type={\n value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT\n }\n >\n {segment.label}\n </Body>\n </button>\n );\n })}\n </div>\n </div>\n );\n};\n\nexport default SegmentedControl;\n"],"names":["SegmentedControl","name","value","mode","segments","onChange","isMountedRef","useRef","animate","setAnimate","useState","segmentsRef","length","Error","segmentsWithRefs","map","segment","ref","createRef","updateSegmentPosition","selectedSegmentRef","find","current","style","setProperty","offsetWidth","offsetLeft","useEffect","handleWindowSizeChange","window","addEventListener","removeEventListener","_jsx","className","clsx","children","role","undefined","onSelect","_jsxs","htmlFor","id","type","checked","Body","as","Typography","BODY_DEFAULT_BOLD","BODY_DEFAULT","label","controls","onClick"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAMA,gBAAgB,GAAGA,CAAC;EACxBC,IAAI;EACJC,KAAK;AACLC,EAAAA,IAAI,GAAG,OAAO;EACdC,QAAQ;AACRC,EAAAA;AAAQ,CACc,KAAI;AAC1B,EAAA,MAAMC,YAAY,GAAGC,MAAM,CAAC,KAAK,CAAC;EAClC,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;AAE7C,EAAA,MAAMC,WAAW,GAAGJ,MAAM,CAAiB,IAAI,CAAC;AAEhD,EAAA,IAAIH,QAAQ,CAACQ,MAAM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,CACT;MACH,CAAC;KACE;AACP,GAAK,CAAC;AAEV;;;;"}
|
|
1
|
+
{"version":3,"file":"SegmentedControl.mjs","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { createRef, useEffect, useRef, useState } from 'react';\n\nimport Body from '../Body';\nimport { Typography } from '../common';\nimport { useDirection } from '../common/hooks';\n\ntype SegmentBase = { id: string; label: string; value: string };\n\ntype Segment = SegmentBase & { controls?: never };\ntype SegmentWithControls = SegmentBase & { controls: string };\n\nexport type Segments = readonly Segment[] | readonly SegmentWithControls[];\n\ntype SegmentedControlPropsBase = {\n name: string;\n value: string;\n mode: 'input' | 'view';\n onChange: (value: string) => void;\n};\n\ntype SegmentedControlViewProps = {\n mode: 'view';\n segments: readonly SegmentWithControls[];\n};\n\ntype SegmentedControlInputProps = {\n mode: 'input';\n segments: readonly Segment[];\n};\n\nexport type SegmentedControlProps = SegmentedControlPropsBase &\n (SegmentedControlViewProps | SegmentedControlInputProps);\n\nconst SegmentedControl = ({\n name,\n value,\n mode = 'input',\n segments,\n onChange,\n}: SegmentedControlProps) => {\n const isMountedRef = useRef(false);\n const [animate, setAnimate] = useState(false);\n const { isRTL } = useDirection();\n\n const segmentsRef = useRef<HTMLDivElement>(null);\n\n if (segments.length > 3) {\n throw new Error(\n 'SegmentedControl only supports up to 3 segments. Please refer to: https://docs.wise.design/components/segmented-control',\n );\n }\n\n const segmentsWithRefs = segments.map((segment) => ({\n ...segment,\n ref: createRef<HTMLLabelElement | HTMLButtonElement>(),\n }));\n\n const updateSegmentPosition = () => {\n const selectedSegmentRef = segmentsWithRefs.find((segment) => segment.value === value)?.ref;\n\n // We grab the active segments style object from the ref\n // and set the css variables to the selected segments width and x position.\n // This is so we can animate the highlight to the selected segment\n if (selectedSegmentRef?.current && segmentsRef.current) {\n const { style } = segmentsRef.current;\n const segment = selectedSegmentRef.current;\n const inlineOffset = isRTL\n ? segmentsRef.current.offsetWidth - segment.offsetLeft - segment.offsetWidth\n : segment.offsetLeft;\n style.setProperty('--segment-highlight-width', `${segment.offsetWidth}px`);\n style.setProperty('--segment-highlight-x', `${inlineOffset}px`);\n }\n };\n\n useEffect(() => {\n if (isMountedRef.current) {\n setAnimate(true);\n } else {\n isMountedRef.current = true;\n }\n\n updateSegmentPosition();\n\n const handleWindowSizeChange = () => {\n setAnimate(false);\n updateSegmentPosition();\n };\n\n window.addEventListener('resize', handleWindowSizeChange);\n return () => {\n window.removeEventListener('resize', handleWindowSizeChange);\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [segmentsWithRefs, value]);\n\n return (\n <div\n ref={segmentsRef}\n data-testid=\"segmented-control\"\n className={clsx('segmented-control', {\n 'segmented-control--input': mode === 'input',\n })}\n >\n <div\n className={clsx('segmented-control__segments', {\n 'segmented-control__segments--no-animate': !animate,\n })}\n role={mode !== 'input' ? 'tablist' : undefined}\n >\n {segmentsWithRefs.map((segment) => {\n const onSelect = () => {\n setAnimate(true);\n onChange(segment.value);\n };\n return mode === 'input' ? (\n <label\n ref={segment.ref as React.MutableRefObject<HTMLLabelElement | null>}\n key={segment.id}\n htmlFor={segment.id}\n className={clsx('segmented-control__segment', {\n 'segmented-control__selected-segment': value === segment.value,\n })}\n >\n <input\n type=\"radio\"\n className=\"segmented-control__radio-input\"\n id={segment.id}\n name={name}\n value={segment.value}\n checked={value === segment.value}\n onChange={onSelect}\n />\n <Body\n className=\"segmented-control__text\"\n as=\"span\"\n type={\n value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT\n }\n >\n {segment.label}\n </Body>\n </label>\n ) : (\n <button\n ref={segment.ref as React.MutableRefObject<HTMLButtonElement | null>}\n key={segment.id}\n type=\"button\"\n role=\"tab\"\n id={segment.id}\n aria-controls={segment.controls}\n aria-selected={value === segment.value}\n className={clsx('segmented-control__segment', 'segmented-control__button', {\n 'segmented-control__selected-segment': value === segment.value,\n })}\n onClick={onSelect}\n >\n <Body\n as=\"span\"\n className=\"segmented-control__text\"\n type={\n value === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT\n }\n >\n {segment.label}\n </Body>\n </button>\n );\n })}\n </div>\n </div>\n );\n};\n\nexport default SegmentedControl;\n"],"names":["SegmentedControl","name","value","mode","segments","onChange","isMountedRef","useRef","animate","setAnimate","useState","isRTL","useDirection","segmentsRef","length","Error","segmentsWithRefs","map","segment","ref","createRef","updateSegmentPosition","selectedSegmentRef","find","current","style","inlineOffset","offsetWidth","offsetLeft","setProperty","useEffect","handleWindowSizeChange","window","addEventListener","removeEventListener","_jsx","className","clsx","children","role","undefined","onSelect","_jsxs","htmlFor","id","type","checked","Body","as","Typography","BODY_DEFAULT_BOLD","BODY_DEFAULT","label","controls","onClick"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAMA,gBAAgB,GAAGA,CAAC;EACxBC,IAAI;EACJC,KAAK;AACLC,EAAAA,IAAI,GAAG,OAAO;EACdC,QAAQ;AACRC,EAAAA;AAAQ,CACc,KAAI;AAC1B,EAAA,MAAMC,YAAY,GAAGC,MAAM,CAAC,KAAK,CAAC;EAClC,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;EAC7C,MAAM;AAAEC,IAAAA;GAAO,GAAGC,YAAY,EAAE;AAEhC,EAAA,MAAMC,WAAW,GAAGN,MAAM,CAAiB,IAAI,CAAC;AAEhD,EAAA,IAAIH,QAAQ,CAACU,MAAM,GAAG,CAAC,EAAE;AACvB,IAAA,MAAM,IAAIC,KAAK,CACb,yHAAyH,CAC1H;AACH,EAAA;AAEA,EAAA,MAAMC,gBAAgB,GAAGZ,QAAQ,CAACa,GAAG,CAAEC,OAAO,KAAM;AAClD,IAAA,GAAGA,OAAO;IACVC,GAAG,eAAEC,SAAS;AACf,GAAA,CAAC,CAAC;EAEH,MAAMC,qBAAqB,GAAGA,MAAK;AACjC,IAAA,MAAMC,kBAAkB,GA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EAAEoC;AAAS,WAAA,CAErB,eAAAN,GAAA,CAACY,IAAI,EAAA;AACHX,YAAAA,SAAS,EAAC,yBAAyB;AACnCY,YAAAA,EAAE,EAAC,MAAM;AACTH,YAAAA,IAAI,EACF3C,KAAK,KAAKgB,OAAO,CAAChB,KAAK,GAAG+C,UAAU,CAACC,iBAAiB,GAAGD,UAAU,CAACE,YACrE;YAAAb,QAAA,EAEApB,OAAO,CAACkC;AAAK,WACV,CACR;AAAA,SAAA,EAxBOlC,OAAO,CAAC0B,EAwBR,CAAC,gBAERT,GAAA,CAAA,QAAA,EAAA;UACEhB,GAAG,EAAED,OAAO,CAACC,GAAwD;AAErE0B,UAAAA,IAAI,EAAC,QAAQ;AACbN,UAAAA,IAAI,EAAC,KAAK;UACVK,EAAE,EAAE1B,OAAO,CAAC0B,EAAG;UACf,eAAA,EAAe1B,OAAO,CAACmC,QAAS;AAChC,UAAA,eAAA,EAAenD,KAAK,KAAKgB,OAAO,CAAChB,KAAM;AACvCkC,UAAAA,SAAS,EAAEC,IAAI,CAAC,4BAA4B,EAAE,2BAA2B,EAAE;AACzE,YAAA,qCAAqC,EAAEnC,KAAK,KAAKgB,OAAO,CAAChB;AAC1D,WAAA,CAAE;AACHoD,UAAAA,OAAO,EAAEb,QAAS;UAAAH,QAAA,eAElBH,GAAA,CAACY,IAAI,EAAA;AACHC,YAAAA,EAAE,EAAC,MAAM;AACTZ,YAAAA,SAAS,EAAC,yBAAyB;AACnCS,YAAAA,IAAI,EACF3C,KAAK,KAAKgB,OAAO,CAAChB,KAAK,GAAG+C,UAAU,CAACC,iBAAiB,GAAGD,UAAU,CAACE,YACrE;YAAAb,QAAA,EAEApB,OAAO,CAACkC;WACL;SACR,EApBOlC,OAAO,CAAC0B,EAoBP,CACT;MACH,CAAC;KACE;AACP,GAAK,CAAC;AAEV;;;;"}
|
package/build/Tooltip/Tooltip.js
CHANGED
|
@@ -29,6 +29,7 @@ require('@transferwise/icons');
|
|
|
29
29
|
require('react-intl');
|
|
30
30
|
require('../common/CloseButton/CloseButton.messages.js');
|
|
31
31
|
var jsxRuntime = require('react/jsx-runtime');
|
|
32
|
+
var useDirection = require('../common/hooks/useDirection/useDirection.js');
|
|
32
33
|
|
|
33
34
|
const Tooltip = ({
|
|
34
35
|
position: position$1 = position.Position.TOP,
|
|
@@ -39,6 +40,10 @@ const Tooltip = ({
|
|
|
39
40
|
}) => {
|
|
40
41
|
const [open, setOpen] = React.useState(false);
|
|
41
42
|
const arrowRef = React.useRef(null);
|
|
43
|
+
const {
|
|
44
|
+
isRTL
|
|
45
|
+
} = useDirection.useDirection();
|
|
46
|
+
const resolvedPosition = isRTL ? position$1 === 'left' ? 'right' : position$1 === 'right' ? 'left' : position$1 : position$1;
|
|
42
47
|
const fallbackId = React.useId();
|
|
43
48
|
const tooltipId = id ?? fallbackId;
|
|
44
49
|
const {
|
|
@@ -47,7 +52,7 @@ const Tooltip = ({
|
|
|
47
52
|
placement,
|
|
48
53
|
middlewareData
|
|
49
54
|
} = react.useFloating({
|
|
50
|
-
placement:
|
|
55
|
+
placement: resolvedPosition,
|
|
51
56
|
middleware: [react.offset(16), react.flip({
|
|
52
57
|
fallbackPlacements: [position.Position.TOP]
|
|
53
58
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","sources":["../../src/Tooltip/Tooltip.tsx"],"sourcesContent":["import {\n arrow as arrowMiddleware,\n autoUpdate,\n flip,\n offset,\n useFloating,\n} from '@floating-ui/react';\nimport { clsx } from 'clsx';\nimport {\n AriaAttributes,\n CSSProperties,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n cloneElement,\n useId,\n useRef,\n useState,\n} from 'react';\n\nimport { CommonProps, Position } from '../common';\nimport {\n PositionBottom,\n PositionLeft,\n PositionRight,\n PositionTop,\n} from '../common/PropsValues/position';\n\nexport type TooltipProps = PropsWithChildren<{\n position?: PositionTop | PositionRight | PositionBottom | PositionLeft;\n label: ReactNode;\n id?: string;\n}> &\n CommonProps;\n\nconst Tooltip = ({\n position = Position.TOP,\n children = undefined,\n label,\n id,\n className,\n}: TooltipProps) => {\n const [open, setOpen] = useState(false);\n const arrowRef = useRef<HTMLDivElement | null>(null);\n\n const fallbackId = useId();\n const tooltipId = id ?? fallbackId;\n\n const { refs, floatingStyles, placement, middlewareData } = useFloating({\n placement:
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sources":["../../src/Tooltip/Tooltip.tsx"],"sourcesContent":["import {\n arrow as arrowMiddleware,\n autoUpdate,\n flip,\n offset,\n useFloating,\n} from '@floating-ui/react';\nimport { clsx } from 'clsx';\nimport {\n AriaAttributes,\n CSSProperties,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n cloneElement,\n useId,\n useRef,\n useState,\n} from 'react';\n\nimport { CommonProps, Position } from '../common';\nimport useDirection from '../common/hooks/useDirection';\nimport {\n PositionBottom,\n PositionLeft,\n PositionRight,\n PositionTop,\n} from '../common/PropsValues/position';\n\nexport type TooltipProps = PropsWithChildren<{\n position?: PositionTop | PositionRight | PositionBottom | PositionLeft;\n label: ReactNode;\n id?: string;\n}> &\n CommonProps;\n\nconst Tooltip = ({\n position = Position.TOP,\n children = undefined,\n label,\n id,\n className,\n}: TooltipProps) => {\n const [open, setOpen] = useState(false);\n const arrowRef = useRef<HTMLDivElement | null>(null);\n const { isRTL } = useDirection();\n\n const resolvedPosition = isRTL\n ? position === 'left'\n ? 'right'\n : position === 'right'\n ? 'left'\n : position\n : position;\n\n const fallbackId = useId();\n const tooltipId = id ?? fallbackId;\n\n const { refs, floatingStyles, placement, middlewareData } = useFloating({\n placement: resolvedPosition,\n middleware: [\n offset(16),\n flip({ fallbackPlacements: [Position.TOP] }),\n // eslint-disable-next-line react-hooks/refs -- arrowRef is passed to floating-ui middleware, legitimate API usage\n arrowMiddleware({ element: arrowRef, padding: 8 }),\n ],\n whileElementsMounted: open ? autoUpdate : undefined,\n open,\n });\n\n const arrowStyle: CSSProperties = {\n ...(middlewareData.arrow?.x != null ? { left: middlewareData.arrow.x } : {}),\n ...(middlewareData.arrow?.y != null ? { top: middlewareData.arrow.y } : {}),\n };\n\n return (\n /* eslint-disable react-hooks/refs -- setReference and setFloating are callback refs from floating-ui, safe to pass during render */\n <span\n ref={refs.setReference}\n className=\"tw-tooltip-container\"\n onMouseOver={() => setOpen(true)}\n onFocus={() => setOpen(true)}\n onMouseOut={() => setOpen(false)}\n onBlur={() => setOpen(false)}\n >\n {children\n ? cloneElement(children as ReactElement<Pick<AriaAttributes, 'aria-describedby'>>, {\n 'aria-describedby': `${tooltipId}-tooltip`,\n })\n : null}\n <div\n ref={refs.setFloating}\n className={clsx(\n 'np-tooltip',\n 'np-panel',\n open ? `np-panel--open np-tooltip--open` : null,\n className,\n )}\n style={floatingStyles}\n data-popper-placement={placement}\n aria-hidden={!open}\n role=\"tooltip\"\n id={`${tooltipId}-tooltip`}\n >\n <div className=\"np-panel__content tooltip-inner\">\n {label}\n <div ref={arrowRef} className={clsx('np-panel__arrow')} style={arrowStyle} />\n </div>\n </div>\n </span>\n /* eslint-enable react-hooks/refs */\n );\n};\n\nexport default Tooltip;\n"],"names":["Tooltip","position","Position","TOP","children","undefined","label","id","className","open","setOpen","useState","arrowRef","useRef","isRTL","useDirection","resolvedPosition","fallbackId","useId","tooltipId","refs","floatingStyles","placement","middlewareData","useFloating","middleware","offset","flip","fallbackPlacements","arrowMiddleware","element","padding","whileElementsMounted","autoUpdate","arrowStyle","arrow","x","left","y","top","_jsxs","ref","setReference","onMouseOver","onFocus","onMouseOut","onBlur","cloneElement","_jsx","setFloating","clsx","style","role"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAMA,OAAO,GAAGA,CAAC;YACfC,UAAQ,GAAGC,iBAAQ,CAACC,GAAG;AACvBC,EAAAA,QAAQ,GAAGC,SAAS;EACpBC,KAAK;EACLC,EAAE;AACFC,EAAAA;AAAS,CACI,KAAI;EACjB,MAAM,CAACC,IAAI,EAAEC,OAAO,CAA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 -25,6 +25,7 @@ import '@transferwise/icons';
|
|
|
25
25
|
import 'react-intl';
|
|
26
26
|
import '../common/CloseButton/CloseButton.messages.mjs';
|
|
27
27
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
28
|
+
import { useDirection } from '../common/hooks/useDirection/useDirection.mjs';
|
|
28
29
|
|
|
29
30
|
const Tooltip = ({
|
|
30
31
|
position = Position.TOP,
|
|
@@ -35,6 +36,10 @@ const Tooltip = ({
|
|
|
35
36
|
}) => {
|
|
36
37
|
const [open, setOpen] = useState(false);
|
|
37
38
|
const arrowRef = useRef(null);
|
|
39
|
+
const {
|
|
40
|
+
isRTL
|
|
41
|
+
} = useDirection();
|
|
42
|
+
const resolvedPosition = isRTL ? position === 'left' ? 'right' : position === 'right' ? 'left' : position : position;
|
|
38
43
|
const fallbackId = useId();
|
|
39
44
|
const tooltipId = id ?? fallbackId;
|
|
40
45
|
const {
|
|
@@ -43,7 +48,7 @@ const Tooltip = ({
|
|
|
43
48
|
placement,
|
|
44
49
|
middlewareData
|
|
45
50
|
} = useFloating({
|
|
46
|
-
placement:
|
|
51
|
+
placement: resolvedPosition,
|
|
47
52
|
middleware: [offset(16), flip({
|
|
48
53
|
fallbackPlacements: [Position.TOP]
|
|
49
54
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.mjs","sources":["../../src/Tooltip/Tooltip.tsx"],"sourcesContent":["import {\n arrow as arrowMiddleware,\n autoUpdate,\n flip,\n offset,\n useFloating,\n} from '@floating-ui/react';\nimport { clsx } from 'clsx';\nimport {\n AriaAttributes,\n CSSProperties,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n cloneElement,\n useId,\n useRef,\n useState,\n} from 'react';\n\nimport { CommonProps, Position } from '../common';\nimport {\n PositionBottom,\n PositionLeft,\n PositionRight,\n PositionTop,\n} from '../common/PropsValues/position';\n\nexport type TooltipProps = PropsWithChildren<{\n position?: PositionTop | PositionRight | PositionBottom | PositionLeft;\n label: ReactNode;\n id?: string;\n}> &\n CommonProps;\n\nconst Tooltip = ({\n position = Position.TOP,\n children = undefined,\n label,\n id,\n className,\n}: TooltipProps) => {\n const [open, setOpen] = useState(false);\n const arrowRef = useRef<HTMLDivElement | null>(null);\n\n const fallbackId = useId();\n const tooltipId = id ?? fallbackId;\n\n const { refs, floatingStyles, placement, middlewareData } = useFloating({\n placement:
|
|
1
|
+
{"version":3,"file":"Tooltip.mjs","sources":["../../src/Tooltip/Tooltip.tsx"],"sourcesContent":["import {\n arrow as arrowMiddleware,\n autoUpdate,\n flip,\n offset,\n useFloating,\n} from '@floating-ui/react';\nimport { clsx } from 'clsx';\nimport {\n AriaAttributes,\n CSSProperties,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n cloneElement,\n useId,\n useRef,\n useState,\n} from 'react';\n\nimport { CommonProps, Position } from '../common';\nimport useDirection from '../common/hooks/useDirection';\nimport {\n PositionBottom,\n PositionLeft,\n PositionRight,\n PositionTop,\n} from '../common/PropsValues/position';\n\nexport type TooltipProps = PropsWithChildren<{\n position?: PositionTop | PositionRight | PositionBottom | PositionLeft;\n label: ReactNode;\n id?: string;\n}> &\n CommonProps;\n\nconst Tooltip = ({\n position = Position.TOP,\n children = undefined,\n label,\n id,\n className,\n}: TooltipProps) => {\n const [open, setOpen] = useState(false);\n const arrowRef = useRef<HTMLDivElement | null>(null);\n const { isRTL } = useDirection();\n\n const resolvedPosition = isRTL\n ? position === 'left'\n ? 'right'\n : position === 'right'\n ? 'left'\n : position\n : position;\n\n const fallbackId = useId();\n const tooltipId = id ?? fallbackId;\n\n const { refs, floatingStyles, placement, middlewareData } = useFloating({\n placement: resolvedPosition,\n middleware: [\n offset(16),\n flip({ fallbackPlacements: [Position.TOP] }),\n // eslint-disable-next-line react-hooks/refs -- arrowRef is passed to floating-ui middleware, legitimate API usage\n arrowMiddleware({ element: arrowRef, padding: 8 }),\n ],\n whileElementsMounted: open ? autoUpdate : undefined,\n open,\n });\n\n const arrowStyle: CSSProperties = {\n ...(middlewareData.arrow?.x != null ? { left: middlewareData.arrow.x } : {}),\n ...(middlewareData.arrow?.y != null ? { top: middlewareData.arrow.y } : {}),\n };\n\n return (\n /* eslint-disable react-hooks/refs -- setReference and setFloating are callback refs from floating-ui, safe to pass during render */\n <span\n ref={refs.setReference}\n className=\"tw-tooltip-container\"\n onMouseOver={() => setOpen(true)}\n onFocus={() => setOpen(true)}\n onMouseOut={() => setOpen(false)}\n onBlur={() => setOpen(false)}\n >\n {children\n ? cloneElement(children as ReactElement<Pick<AriaAttributes, 'aria-describedby'>>, {\n 'aria-describedby': `${tooltipId}-tooltip`,\n })\n : null}\n <div\n ref={refs.setFloating}\n className={clsx(\n 'np-tooltip',\n 'np-panel',\n open ? `np-panel--open np-tooltip--open` : null,\n className,\n )}\n style={floatingStyles}\n data-popper-placement={placement}\n aria-hidden={!open}\n role=\"tooltip\"\n id={`${tooltipId}-tooltip`}\n >\n <div className=\"np-panel__content tooltip-inner\">\n {label}\n <div ref={arrowRef} className={clsx('np-panel__arrow')} style={arrowStyle} />\n </div>\n </div>\n </span>\n /* eslint-enable react-hooks/refs */\n );\n};\n\nexport default Tooltip;\n"],"names":["Tooltip","position","Position","TOP","children","undefined","label","id","className","open","setOpen","useState","arrowRef","useRef","isRTL","useDirection","resolvedPosition","fallbackId","useId","tooltipId","refs","floatingStyles","placement","middlewareData","useFloating","middleware","offset","flip","fallbackPlacements","arrowMiddleware","element","padding","whileElementsMounted","autoUpdate","arrowStyle","arrow","x","left","y","top","_jsxs","ref","setReference","onMouseOver","onFocus","onMouseOut","onBlur","cloneElement","_jsx","setFloating","clsx","style","role"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAMA,OAAO,GAAGA,CAAC;EACfC,QAAQ,GAAGC,QAAQ,CAACC,GAAG;AACvBC,EAAAA,QAAQ,GAAGC,SAAS;EACpBC,KAAK;EACLC,EAAE;AACFC,EAAAA;AAAS,CACI,KAAI;EACjB,MAAM,CAACC,IA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;;;"}
|
package/build/i18n/ja.json
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"neptune.Table.loaded": "テーブルデータが読み込まれました",
|
|
51
51
|
"neptune.Table.loading": "テーブルデータを読み込み中です",
|
|
52
52
|
"neptune.Table.refreshPage": "ページを更新する",
|
|
53
|
-
"neptune.Typeahead.suggestionsLabel": "
|
|
53
|
+
"neptune.Typeahead.suggestionsLabel": "提案",
|
|
54
54
|
"neptune.Upload.csButtonText": "別のファイルをアップロードしますか?",
|
|
55
55
|
"neptune.Upload.csFailureText": "アップロードに失敗しました。もう一度やり直してください。",
|
|
56
56
|
"neptune.Upload.csSuccessText": "アップロードが完了しました。",
|
package/build/i18n/ja.json.js
CHANGED
|
@@ -54,7 +54,7 @@ var ja = {
|
|
|
54
54
|
"neptune.Table.loaded": "テーブルデータが読み込まれました",
|
|
55
55
|
"neptune.Table.loading": "テーブルデータを読み込み中です",
|
|
56
56
|
"neptune.Table.refreshPage": "ページを更新する",
|
|
57
|
-
"neptune.Typeahead.suggestionsLabel": "
|
|
57
|
+
"neptune.Typeahead.suggestionsLabel": "提案",
|
|
58
58
|
"neptune.Upload.csButtonText": "別のファイルをアップロードしますか?",
|
|
59
59
|
"neptune.Upload.csFailureText": "アップロードに失敗しました。もう一度やり直してください。",
|
|
60
60
|
"neptune.Upload.csSuccessText": "アップロードが完了しました。",
|
package/build/i18n/ja.json.mjs
CHANGED
|
@@ -50,7 +50,7 @@ var ja = {
|
|
|
50
50
|
"neptune.Table.loaded": "テーブルデータが読み込まれました",
|
|
51
51
|
"neptune.Table.loading": "テーブルデータを読み込み中です",
|
|
52
52
|
"neptune.Table.refreshPage": "ページを更新する",
|
|
53
|
-
"neptune.Typeahead.suggestionsLabel": "
|
|
53
|
+
"neptune.Typeahead.suggestionsLabel": "提案",
|
|
54
54
|
"neptune.Upload.csButtonText": "別のファイルをアップロードしますか?",
|
|
55
55
|
"neptune.Upload.csFailureText": "アップロードに失敗しました。もう一度やり直してください。",
|
|
56
56
|
"neptune.Upload.csSuccessText": "アップロードが完了しました。",
|
package/build/i18n/tr.json
CHANGED
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"neptune.DateLookup.goTo20YearView": "20 yıl görünümüne git",
|
|
13
13
|
"neptune.DateLookup.month": "ay",
|
|
14
14
|
"neptune.DateLookup.next": "devam et",
|
|
15
|
+
"neptune.DateLookup.notAvailable": "kullanılamaz",
|
|
16
|
+
"neptune.DateLookup.outOfRangeAfter": "Lütfen {min} veya daha sonraki bir tarih girin.",
|
|
17
|
+
"neptune.DateLookup.outOfRangeBefore": "Lütfen {max} veya daha önceki bir tarih girin.",
|
|
18
|
+
"neptune.DateLookup.outOfRangeBetween": "Lütfen {min} ile {max} arasında bir tarih girin.",
|
|
15
19
|
"neptune.DateLookup.previous": "önceki",
|
|
16
20
|
"neptune.DateLookup.selected": "seçili",
|
|
17
21
|
"neptune.DateLookup.twentyYears": "20 yıl",
|
|
@@ -46,6 +50,7 @@
|
|
|
46
50
|
"neptune.Table.loaded": "Tablo verileri yüklendi",
|
|
47
51
|
"neptune.Table.loading": "Tablo verileri yükleniyor",
|
|
48
52
|
"neptune.Table.refreshPage": "Sayfayı yenile",
|
|
53
|
+
"neptune.Typeahead.suggestionsLabel": "Öneriler",
|
|
49
54
|
"neptune.Upload.csButtonText": "Başka bir dosya yükleyin?",
|
|
50
55
|
"neptune.Upload.csFailureText": "Yükleme başarısız. Lütfen yine deneyin",
|
|
51
56
|
"neptune.Upload.csSuccessText": "Yükleme tamamlandı!",
|
package/build/i18n/tr.json.js
CHANGED
|
@@ -16,6 +16,10 @@ var tr = {
|
|
|
16
16
|
"neptune.DateLookup.goTo20YearView": "20 yıl görünümüne git",
|
|
17
17
|
"neptune.DateLookup.month": "ay",
|
|
18
18
|
"neptune.DateLookup.next": "devam et",
|
|
19
|
+
"neptune.DateLookup.notAvailable": "kullanılamaz",
|
|
20
|
+
"neptune.DateLookup.outOfRangeAfter": "Lütfen {min} veya daha sonraki bir tarih girin.",
|
|
21
|
+
"neptune.DateLookup.outOfRangeBefore": "Lütfen {max} veya daha önceki bir tarih girin.",
|
|
22
|
+
"neptune.DateLookup.outOfRangeBetween": "Lütfen {min} ile {max} arasında bir tarih girin.",
|
|
19
23
|
"neptune.DateLookup.previous": "önceki",
|
|
20
24
|
"neptune.DateLookup.selected": "seçili",
|
|
21
25
|
"neptune.DateLookup.twentyYears": "20 yıl",
|
|
@@ -50,6 +54,7 @@ var tr = {
|
|
|
50
54
|
"neptune.Table.loaded": "Tablo verileri yüklendi",
|
|
51
55
|
"neptune.Table.loading": "Tablo verileri yükleniyor",
|
|
52
56
|
"neptune.Table.refreshPage": "Sayfayı yenile",
|
|
57
|
+
"neptune.Typeahead.suggestionsLabel": "Öneriler",
|
|
53
58
|
"neptune.Upload.csButtonText": "Başka bir dosya yükleyin?",
|
|
54
59
|
"neptune.Upload.csFailureText": "Yükleme başarısız. Lütfen yine deneyin",
|
|
55
60
|
"neptune.Upload.csSuccessText": "Yükleme tamamlandı!",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tr.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tr.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/build/i18n/tr.json.mjs
CHANGED
|
@@ -12,6 +12,10 @@ var tr = {
|
|
|
12
12
|
"neptune.DateLookup.goTo20YearView": "20 yıl görünümüne git",
|
|
13
13
|
"neptune.DateLookup.month": "ay",
|
|
14
14
|
"neptune.DateLookup.next": "devam et",
|
|
15
|
+
"neptune.DateLookup.notAvailable": "kullanılamaz",
|
|
16
|
+
"neptune.DateLookup.outOfRangeAfter": "Lütfen {min} veya daha sonraki bir tarih girin.",
|
|
17
|
+
"neptune.DateLookup.outOfRangeBefore": "Lütfen {max} veya daha önceki bir tarih girin.",
|
|
18
|
+
"neptune.DateLookup.outOfRangeBetween": "Lütfen {min} ile {max} arasında bir tarih girin.",
|
|
15
19
|
"neptune.DateLookup.previous": "önceki",
|
|
16
20
|
"neptune.DateLookup.selected": "seçili",
|
|
17
21
|
"neptune.DateLookup.twentyYears": "20 yıl",
|
|
@@ -46,6 +50,7 @@ var tr = {
|
|
|
46
50
|
"neptune.Table.loaded": "Tablo verileri yüklendi",
|
|
47
51
|
"neptune.Table.loading": "Tablo verileri yükleniyor",
|
|
48
52
|
"neptune.Table.refreshPage": "Sayfayı yenile",
|
|
53
|
+
"neptune.Typeahead.suggestionsLabel": "Öneriler",
|
|
49
54
|
"neptune.Upload.csButtonText": "Başka bir dosya yükleyin?",
|
|
50
55
|
"neptune.Upload.csFailureText": "Yükleme başarısız. Lütfen yine deneyin",
|
|
51
56
|
"neptune.Upload.csSuccessText": "Yükleme tamamlandı!",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tr.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tr.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/build/i18n/zh-CN.json
CHANGED
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"neptune.DateLookup.goTo20YearView": "转到 20 年视图",
|
|
13
13
|
"neptune.DateLookup.month": "月",
|
|
14
14
|
"neptune.DateLookup.next": "下一页",
|
|
15
|
+
"neptune.DateLookup.notAvailable": "不可用",
|
|
16
|
+
"neptune.DateLookup.outOfRangeAfter": "请输入 {min}或之后的日期。",
|
|
17
|
+
"neptune.DateLookup.outOfRangeBefore": "请输入 {max}或之前的日期。",
|
|
18
|
+
"neptune.DateLookup.outOfRangeBetween": "请输入 {min}与 {max}之间的日期。",
|
|
15
19
|
"neptune.DateLookup.previous": "上一页",
|
|
16
20
|
"neptune.DateLookup.selected": "已选",
|
|
17
21
|
"neptune.DateLookup.twentyYears": "20 年",
|
|
@@ -46,6 +50,7 @@
|
|
|
46
50
|
"neptune.Table.loaded": "表数据已加载",
|
|
47
51
|
"neptune.Table.loading": "表数据正在加载",
|
|
48
52
|
"neptune.Table.refreshPage": "刷新页面",
|
|
53
|
+
"neptune.Typeahead.suggestionsLabel": "建议",
|
|
49
54
|
"neptune.Upload.csButtonText": "上传另一个文件?",
|
|
50
55
|
"neptune.Upload.csFailureText": "上传失败。请重试",
|
|
51
56
|
"neptune.Upload.csSuccessText": "上传完毕!",
|
package/build/i18n/zh-CN.json.js
CHANGED
|
@@ -16,6 +16,10 @@ var zhCN = {
|
|
|
16
16
|
"neptune.DateLookup.goTo20YearView": "转到 20 年视图",
|
|
17
17
|
"neptune.DateLookup.month": "月",
|
|
18
18
|
"neptune.DateLookup.next": "下一页",
|
|
19
|
+
"neptune.DateLookup.notAvailable": "不可用",
|
|
20
|
+
"neptune.DateLookup.outOfRangeAfter": "请输入 {min}或之后的日期。",
|
|
21
|
+
"neptune.DateLookup.outOfRangeBefore": "请输入 {max}或之前的日期。",
|
|
22
|
+
"neptune.DateLookup.outOfRangeBetween": "请输入 {min}与 {max}之间的日期。",
|
|
19
23
|
"neptune.DateLookup.previous": "上一页",
|
|
20
24
|
"neptune.DateLookup.selected": "已选",
|
|
21
25
|
"neptune.DateLookup.twentyYears": "20 年",
|
|
@@ -50,6 +54,7 @@ var zhCN = {
|
|
|
50
54
|
"neptune.Table.loaded": "表数据已加载",
|
|
51
55
|
"neptune.Table.loading": "表数据正在加载",
|
|
52
56
|
"neptune.Table.refreshPage": "刷新页面",
|
|
57
|
+
"neptune.Typeahead.suggestionsLabel": "建议",
|
|
53
58
|
"neptune.Upload.csButtonText": "上传另一个文件?",
|
|
54
59
|
"neptune.Upload.csFailureText": "上传失败。请重试",
|
|
55
60
|
"neptune.Upload.csSuccessText": "上传完毕!",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zh-CN.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zh-CN.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -12,6 +12,10 @@ var zhCN = {
|
|
|
12
12
|
"neptune.DateLookup.goTo20YearView": "转到 20 年视图",
|
|
13
13
|
"neptune.DateLookup.month": "月",
|
|
14
14
|
"neptune.DateLookup.next": "下一页",
|
|
15
|
+
"neptune.DateLookup.notAvailable": "不可用",
|
|
16
|
+
"neptune.DateLookup.outOfRangeAfter": "请输入 {min}或之后的日期。",
|
|
17
|
+
"neptune.DateLookup.outOfRangeBefore": "请输入 {max}或之前的日期。",
|
|
18
|
+
"neptune.DateLookup.outOfRangeBetween": "请输入 {min}与 {max}之间的日期。",
|
|
15
19
|
"neptune.DateLookup.previous": "上一页",
|
|
16
20
|
"neptune.DateLookup.selected": "已选",
|
|
17
21
|
"neptune.DateLookup.twentyYears": "20 年",
|
|
@@ -46,6 +50,7 @@ var zhCN = {
|
|
|
46
50
|
"neptune.Table.loaded": "表数据已加载",
|
|
47
51
|
"neptune.Table.loading": "表数据正在加载",
|
|
48
52
|
"neptune.Table.refreshPage": "刷新页面",
|
|
53
|
+
"neptune.Typeahead.suggestionsLabel": "建议",
|
|
49
54
|
"neptune.Upload.csButtonText": "上传另一个文件?",
|
|
50
55
|
"neptune.Upload.csFailureText": "上传失败。请重试",
|
|
51
56
|
"neptune.Upload.csSuccessText": "上传完毕!",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zh-CN.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zh-CN.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|