@oanda/labs-widget-common 1.0.203 → 1.0.205

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +1612 -0
  2. package/dist/main/components/TimeUnitSwitch/TimeUnitSelect.js +60 -0
  3. package/dist/main/components/TimeUnitSwitch/TimeUnitSelect.js.map +1 -0
  4. package/dist/main/components/TimeUnitSwitch/TimeUnitSwitch.js +60 -0
  5. package/dist/main/components/TimeUnitSwitch/TimeUnitSwitch.js.map +1 -0
  6. package/dist/main/components/TimeUnitSwitch/index.js +17 -0
  7. package/dist/main/components/TimeUnitSwitch/index.js.map +1 -0
  8. package/dist/main/components/TimeUnitSwitch/types.js +6 -0
  9. package/dist/main/components/TimeUnitSwitch/types.js.map +1 -0
  10. package/dist/main/components/index.js +11 -0
  11. package/dist/main/components/index.js.map +1 -1
  12. package/dist/main/tailwind/colors.js +3 -1
  13. package/dist/main/tailwind/colors.js.map +1 -1
  14. package/dist/module/components/TimeUnitSwitch/TimeUnitSelect.js +53 -0
  15. package/dist/module/components/TimeUnitSwitch/TimeUnitSelect.js.map +1 -0
  16. package/dist/module/components/TimeUnitSwitch/TimeUnitSwitch.js +53 -0
  17. package/dist/module/components/TimeUnitSwitch/TimeUnitSwitch.js.map +1 -0
  18. package/dist/module/components/TimeUnitSwitch/index.js +2 -0
  19. package/dist/module/components/TimeUnitSwitch/index.js.map +1 -0
  20. package/dist/module/components/TimeUnitSwitch/types.js +2 -0
  21. package/dist/module/components/TimeUnitSwitch/types.js.map +1 -0
  22. package/dist/module/components/index.js +1 -0
  23. package/dist/module/components/index.js.map +1 -1
  24. package/dist/module/tailwind/colors.js +3 -1
  25. package/dist/module/tailwind/colors.js.map +1 -1
  26. package/dist/types/components/TimeUnitSwitch/TimeUnitSelect.d.ts +4 -0
  27. package/dist/types/components/TimeUnitSwitch/TimeUnitSwitch.d.ts +4 -0
  28. package/dist/types/components/TimeUnitSwitch/index.d.ts +1 -0
  29. package/dist/types/components/TimeUnitSwitch/types.d.ts +16 -0
  30. package/dist/types/components/index.d.ts +1 -0
  31. package/dist/types/tailwind/colors.d.ts +4 -0
  32. package/package.json +2 -2
  33. package/src/components/TimeUnitSwitch/TimeUnitSelect.tsx +40 -0
  34. package/src/components/TimeUnitSwitch/TimeUnitSwitch.tsx +67 -0
  35. package/src/components/TimeUnitSwitch/index.ts +1 -0
  36. package/src/components/TimeUnitSwitch/types.ts +17 -0
  37. package/src/components/index.ts +1 -0
  38. package/src/tailwind/colors.ts +2 -0
@@ -0,0 +1,67 @@
1
+ import { useLocale } from '@oanda/mono-i18n';
2
+ import React from 'react';
3
+
4
+ import { useLayoutProvider } from '../../providers';
5
+ import { Size } from '../../types';
6
+ import { Button, ButtonSize, ButtonVariant } from '../Button';
7
+ import { TimeUnitSelect } from './TimeUnitSelect';
8
+ import type { TimeUnitSwitchProps } from './types';
9
+
10
+ const TimeUnitSwitch = <T extends string>({
11
+ selected,
12
+ options,
13
+ callback,
14
+ tooltipId,
15
+ }: TimeUnitSwitchProps<T>) => {
16
+ const { lang } = useLocale();
17
+ const { size } = useLayoutProvider();
18
+ const isDesktop = size === Size.DESKTOP;
19
+
20
+ const handleButtonClick = (e: React.SyntheticEvent<HTMLButtonElement>) => {
21
+ callback(e.currentTarget.value as T);
22
+ };
23
+
24
+ return (
25
+ <>
26
+ {isDesktop ? (
27
+ <div
28
+ className="lw-mb-6 lw-flex lw-gap-1 lw-self-end"
29
+ data-testid="time-unit-switch"
30
+ >
31
+ {options.map(({ value, label, tooltipLabel }) => {
32
+ const tooltip = tooltipLabel
33
+ ? lang(tooltipLabel.translationKey, { count: tooltipLabel.count })
34
+ : tooltipLabel;
35
+ const buttonLabel = lang(label);
36
+
37
+ return (
38
+ <Button
39
+ key={value}
40
+ data-tooltip-content={tooltip}
41
+ data-tooltip-id={tooltipId}
42
+ size={ButtonSize.full}
43
+ value={value}
44
+ variant={
45
+ selected === value
46
+ ? ButtonVariant.primary
47
+ : ButtonVariant.secondary
48
+ }
49
+ onClick={handleButtonClick}
50
+ >
51
+ {buttonLabel}
52
+ </Button>
53
+ );
54
+ })}
55
+ </div>
56
+ ) : (
57
+ <TimeUnitSelect
58
+ callback={callback}
59
+ options={options}
60
+ selected={selected}
61
+ />
62
+ )}
63
+ </>
64
+ );
65
+ };
66
+
67
+ export { TimeUnitSwitch };
@@ -0,0 +1 @@
1
+ export * from './TimeUnitSwitch';
@@ -0,0 +1,17 @@
1
+ export interface TimeUnitOption<TimeUnit> {
2
+ value: TimeUnit;
3
+ label: string;
4
+ tooltipLabel?: TooltipLabel;
5
+ }
6
+
7
+ export interface TimeUnitSwitchProps<TimeUnit> {
8
+ selected: TimeUnit;
9
+ options: TimeUnitOption<TimeUnit>[];
10
+ callback: (value: TimeUnit) => void;
11
+ tooltipId?: string;
12
+ }
13
+
14
+ interface TooltipLabel {
15
+ translationKey: string;
16
+ count: number;
17
+ }
@@ -22,6 +22,7 @@ export * from './Table';
22
22
  export * from './TableWidget';
23
23
  export * from './Tabs';
24
24
  export * from './TextInput';
25
+ export * from './TimeUnitSwitch';
25
26
  export * from './Tooltip';
26
27
  export * from './Truncate';
27
28
  export * from './WidgetWrapper';
@@ -26,6 +26,8 @@ export const colorPalette = {
26
26
  grayLight: '#9EA4AC',
27
27
  gray: '#7B8085',
28
28
  darkGray: '#1C1C1C',
29
+ brightBlue: 'rgba(51, 88, 255, 0)',
30
+ brightBlue30: 'rgba(51, 88, 255, 0.3)',
29
31
  };
30
32
 
31
33
  export const twColorPallete = toTwConfigKeys(colorPalette);