@ssa-ui-kit/core 1.1.6 → 1.1.8

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 (129) hide show
  1. package/dist/components/Charts/BarLineComplexChart/BarLIneComplexChart.context.d.ts +3 -0
  2. package/dist/components/Charts/BarLineComplexChart/BarLineComplexChart.d.ts +2 -0
  3. package/dist/components/Charts/BarLineComplexChart/BarLineComplexChartInternal.d.ts +2 -0
  4. package/dist/components/Charts/BarLineComplexChart/BarLineComplexChartTooltip.d.ts +2 -0
  5. package/dist/components/Charts/BarLineComplexChart/__mock__/data.d.ts +3 -0
  6. package/dist/components/Charts/BarLineComplexChart/colorPalette.d.ts +1 -0
  7. package/dist/components/Charts/BarLineComplexChart/index.d.ts +1 -0
  8. package/dist/components/Charts/BarLineComplexChart/types.d.ts +28 -0
  9. package/dist/components/Charts/BarLineComplexChart/useChartInfo.d.ts +10 -0
  10. package/dist/components/{PieChart → Charts/PieChart}/PieChartLegendMarker.d.ts +1 -1
  11. package/dist/components/{PieChart → Charts/PieChart}/styles.d.ts +1 -1
  12. package/dist/components/{PieChart → Charts/PieChart}/types.d.ts +1 -1
  13. package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/types.d.ts +3 -3
  14. package/dist/components/Charts/hooks/index.d.ts +1 -0
  15. package/dist/components/Charts/hooks/usePlotlyDefaultConfig.d.ts +10 -0
  16. package/dist/components/Charts/index.d.ts +3 -0
  17. package/dist/components/Input/InputStatusError.d.ts +3 -1
  18. package/dist/components/Input/InputStatusSuccess.d.ts +3 -1
  19. package/dist/components/Input/types.d.ts +2 -0
  20. package/dist/components/Pagination/Pagination.d.ts +1 -1
  21. package/dist/components/Pagination/types.d.ts +2 -0
  22. package/dist/components/Tooltip/types.d.ts +5 -3
  23. package/dist/components/WidgetCard/WidgetCard.d.ts +1 -1
  24. package/dist/components/WidgetCard/WidgetCardBase.d.ts +2 -0
  25. package/dist/components/WidgetCard/WithWidgetCard.d.ts +1 -1
  26. package/dist/components/WidgetCard/types.d.ts +2 -0
  27. package/dist/components/index.d.ts +1 -2
  28. package/dist/contexts/Translation/TranslationContext.d.ts +9 -0
  29. package/dist/contexts/Translation/config.d.ts +3 -0
  30. package/dist/contexts/Translation/index.d.ts +2 -0
  31. package/dist/contexts/Translation/types.d.ts +8 -0
  32. package/dist/contexts/index.d.ts +1 -0
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.js +1 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/types/json.d.ts +5 -0
  37. package/jest-setup.ts +3 -0
  38. package/package.json +6 -3
  39. package/src/components/Charts/BarLineComplexChart/BarLIneComplexChart.context.tsx +54 -0
  40. package/src/components/Charts/BarLineComplexChart/BarLineComplexChart.stories.tsx +47 -0
  41. package/src/components/Charts/BarLineComplexChart/BarLineComplexChart.tsx +26 -0
  42. package/src/components/Charts/BarLineComplexChart/BarLineComplexChartInternal.tsx +118 -0
  43. package/src/components/Charts/BarLineComplexChart/BarLineComplexChartTooltip.tsx +43 -0
  44. package/src/components/Charts/BarLineComplexChart/__mock__/data.ts +141 -0
  45. package/src/components/Charts/BarLineComplexChart/colorPalette.ts +23 -0
  46. package/src/components/Charts/BarLineComplexChart/index.ts +1 -0
  47. package/src/components/Charts/BarLineComplexChart/types.ts +36 -0
  48. package/src/components/Charts/BarLineComplexChart/useChartInfo.ts +68 -0
  49. package/src/components/{PieChart → Charts/PieChart}/PieChartBases.tsx +1 -0
  50. package/src/components/{PieChart → Charts/PieChart}/types.ts +1 -1
  51. package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/stories/SegmentedPieChart.stories.tsx +1 -1
  52. package/src/components/Charts/hooks/index.ts +1 -0
  53. package/src/components/Charts/hooks/usePlotlyDefaultConfig.ts +39 -0
  54. package/src/components/Charts/index.ts +3 -0
  55. package/src/components/Input/Input.tsx +8 -2
  56. package/src/components/Input/InputStatusError.tsx +6 -2
  57. package/src/components/Input/InputStatusSuccess.tsx +6 -2
  58. package/src/components/Input/types.ts +2 -0
  59. package/src/components/Pagination/Pagination.stories.tsx +12 -0
  60. package/src/components/Pagination/Pagination.tsx +9 -4
  61. package/src/components/Pagination/components/RowsPerPageDropdown/RowsPerPageDropdown.tsx +1 -1
  62. package/src/components/Pagination/styles.tsx +1 -2
  63. package/src/components/Pagination/types.ts +2 -0
  64. package/src/components/ProgressInfo/ProgressInfo.tsx +1 -1
  65. package/src/components/Tooltip/types.ts +5 -2
  66. package/src/components/Tooltip/useTooltip.tsx +4 -2
  67. package/src/components/WidgetCard/WidgetCard.tsx +5 -1
  68. package/src/components/WidgetCard/WidgetCardBase.tsx +4 -2
  69. package/src/components/WidgetCard/WithWidgetCard.tsx +1 -1
  70. package/src/components/WidgetCard/types.ts +2 -0
  71. package/src/components/index.ts +1 -2
  72. package/src/contexts/Translation/TranslationContext.tsx +53 -0
  73. package/src/contexts/Translation/config.ts +3 -0
  74. package/src/contexts/Translation/index.ts +2 -0
  75. package/src/contexts/Translation/types.ts +9 -0
  76. package/src/contexts/index.ts +1 -0
  77. package/src/index.ts +1 -0
  78. package/src/types/json.ts +7 -0
  79. package/tsbuildcache +1 -1
  80. package/tsconfig.build.json +2 -0
  81. package/tsconfig.json +2 -0
  82. package/webpack.config.js +1 -0
  83. /package/dist/components/{PieChart → Charts/PieChart}/PieChart.d.ts +0 -0
  84. /package/dist/components/{PieChart → Charts/PieChart}/PieChartBases.d.ts +0 -0
  85. /package/dist/components/{PieChart → Charts/PieChart}/PieChartHeader.d.ts +0 -0
  86. /package/dist/components/{PieChart → Charts/PieChart}/PieChartLegend.d.ts +0 -0
  87. /package/dist/components/{PieChart → Charts/PieChart}/PieChartLegendList.d.ts +0 -0
  88. /package/dist/components/{PieChart → Charts/PieChart}/PieChartLegendListItem.d.ts +0 -0
  89. /package/dist/components/{PieChart → Charts/PieChart}/colorPalettes.d.ts +0 -0
  90. /package/dist/components/{PieChart → Charts/PieChart}/index.d.ts +0 -0
  91. /package/dist/components/{PieChart → Charts/PieChart}/stories/fixtures.d.ts +0 -0
  92. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChart.d.ts +0 -0
  93. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChartContext.d.ts +0 -0
  94. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/colorPalettes.d.ts +0 -0
  95. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/ChartTitle.d.ts +0 -0
  96. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/ChartTooltip.d.ts +0 -0
  97. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/LegendItem.d.ts +0 -0
  98. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/index.d.ts +0 -0
  99. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/hooks/index.d.ts +0 -0
  100. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/hooks/useData.d.ts +0 -0
  101. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/index.d.ts +0 -0
  102. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/stories/fixtures.d.ts +0 -0
  103. /package/dist/components/{SegmentedPieChart → Charts/SegmentedPieChart}/utils.d.ts +0 -0
  104. /package/src/components/{PieChart → Charts/PieChart}/PieChart.spec.tsx +0 -0
  105. /package/src/components/{PieChart → Charts/PieChart}/PieChart.stories.tsx +0 -0
  106. /package/src/components/{PieChart → Charts/PieChart}/PieChart.tsx +0 -0
  107. /package/src/components/{PieChart → Charts/PieChart}/PieChartHeader.tsx +0 -0
  108. /package/src/components/{PieChart → Charts/PieChart}/PieChartLegend.tsx +0 -0
  109. /package/src/components/{PieChart → Charts/PieChart}/PieChartLegendList.tsx +0 -0
  110. /package/src/components/{PieChart → Charts/PieChart}/PieChartLegendListItem.tsx +0 -0
  111. /package/src/components/{PieChart → Charts/PieChart}/PieChartLegendMarker.tsx +0 -0
  112. /package/src/components/{PieChart → Charts/PieChart}/colorPalettes.ts +0 -0
  113. /package/src/components/{PieChart → Charts/PieChart}/index.ts +0 -0
  114. /package/src/components/{PieChart → Charts/PieChart}/stories/fixtures.ts +0 -0
  115. /package/src/components/{PieChart → Charts/PieChart}/styles.ts +0 -0
  116. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChart.spec.tsx +0 -0
  117. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChart.tsx +0 -0
  118. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/SegmentedPieChartContext.tsx +0 -0
  119. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/colorPalettes.ts +0 -0
  120. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/ChartTitle.tsx +0 -0
  121. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/ChartTooltip.tsx +0 -0
  122. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/LegendItem.tsx +0 -0
  123. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/components/index.ts +0 -0
  124. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/hooks/index.ts +0 -0
  125. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/hooks/useData.ts +0 -0
  126. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/index.ts +0 -0
  127. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/stories/fixtures.ts +0 -0
  128. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/types.ts +0 -0
  129. /package/src/components/{SegmentedPieChart → Charts/SegmentedPieChart}/utils.ts +0 -0
@@ -27,6 +27,8 @@ const InputInner = (
27
27
  className,
28
28
  wrapperClassName,
29
29
  inputProps = {},
30
+ errorTooltip,
31
+ successTooltip,
30
32
  register,
31
33
  onKeyUp,
32
34
  }: InputProps,
@@ -63,8 +65,12 @@ const InputInner = (
63
65
  ref={useMergeRefs([registerResult?.ref, inputRef])}
64
66
  />
65
67
 
66
- {status === 'error' && showStatusIcon() ? <InputStatusError /> : null}
67
- {status === 'success' && showStatusIcon() ? <InputStatusSuccess /> : null}
68
+ {status === 'error' && showStatusIcon() ? (
69
+ <InputStatusError errorTooltip={errorTooltip} />
70
+ ) : null}
71
+ {status === 'success' && showStatusIcon() ? (
72
+ <InputStatusSuccess successTooltip={successTooltip} />
73
+ ) : null}
68
74
 
69
75
  {endElement ? <div css={S.endElement}>{endElement}</div> : null}
70
76
  </InputGroup>
@@ -13,8 +13,12 @@ export const InputError = styled.div`
13
13
  }
14
14
  `;
15
15
 
16
- export const InputStatusError = () => (
16
+ export const InputStatusError = ({
17
+ errorTooltip,
18
+ }: {
19
+ errorTooltip?: string;
20
+ }) => (
17
21
  <InputError css={inputStatus}>
18
- <Icon name="union" size={10} color="#fff" />
22
+ <Icon name="union" size={10} color="#fff" tooltip={errorTooltip} />
19
23
  </InputError>
20
24
  );
@@ -9,8 +9,12 @@ export const InputSuccess = styled.div`
9
9
  `linear-gradient(68.38deg, ${theme.colors.greenLighter}, ${theme.colors.green});`};
10
10
  `;
11
11
 
12
- export const InputStatusSuccess = () => (
12
+ export const InputStatusSuccess = ({
13
+ successTooltip,
14
+ }: {
15
+ successTooltip?: string;
16
+ }) => (
13
17
  <InputSuccess css={inputStatus}>
14
- <Icon name="check" size={10} color="#fff" />
18
+ <Icon name="check" size={10} color="#fff" tooltip={successTooltip} />
15
19
  </InputSuccess>
16
20
  );
@@ -22,6 +22,8 @@ export interface InputProps
22
22
  endElement?: React.ReactElement;
23
23
  css?: Interpolation<Theme>;
24
24
  inputProps?: ExtendedInputProps;
25
+ errorTooltip?: string;
26
+ successTooltip?: string;
25
27
  onKeyUp?: KeyboardEventHandler<HTMLInputElement>;
26
28
  onStartElementClick?: (event: BaseSyntheticEvent) => void;
27
29
  onEndElementClick?: (event: BaseSyntheticEvent) => void;
@@ -70,5 +70,17 @@ export const WithManualPageSettingAndPerPage: StoryAnnotations = {
70
70
  },
71
71
  };
72
72
 
73
+ export const WithoutPageFromCount: StoryAnnotations = {
74
+ args: {
75
+ pagesCount: 10,
76
+ isPageSettingVisible: true,
77
+ isRowPerPageVisible: true,
78
+ isPageFromCountVisible: false,
79
+ },
80
+ parameters: {
81
+ selectedPage: 1,
82
+ },
83
+ };
84
+
73
85
  WithManualPageSettingAndPerPage.storyName =
74
86
  'With records per page and page number setting';
@@ -16,7 +16,9 @@ const Pagination = ({
16
16
  ariaLabel,
17
17
  isDisabled,
18
18
  pageNumberPlaceholder = 'Page №',
19
+ errorTooltip = 'The value is out of range',
19
20
  isPageSettingVisible = false,
21
+ isPageFromCountVisible = true,
20
22
  isRowPerPageVisible = false,
21
23
  rowPerPageProps,
22
24
  manualPageNumberProps,
@@ -44,21 +46,24 @@ const Pagination = ({
44
46
  aria-label={ariaLabel || 'Pagination'}>
45
47
  {isRowPerPageVisible && <RowsPerPageDropdown {...rowPerPageProps} />}
46
48
  {isPageSettingVisible && (
47
- <Wrapper css={{ width: 'auto', marginRight: 32 }}>
49
+ <Wrapper css={{ width: 'auto', marginRight: 5 }}>
48
50
  <S.PageNumberInput
49
51
  name="page-number"
50
52
  placeholder={pageNumberPlaceholder}
51
53
  onKeyUp={handlePageNumberChange}
52
54
  status={inputStatus}
53
55
  type="number"
56
+ errorTooltip={errorTooltip}
54
57
  inputProps={{
55
58
  autoComplete: 'off',
56
59
  }}
57
60
  {...manualPageNumberProps}
58
61
  />
59
- <span css={{ textWrap: 'nowrap', fontSize: 14 }}>
60
- {page || 0} / {pagesCount}
61
- </span>
62
+ {isPageFromCountVisible && (
63
+ <span css={{ textWrap: 'nowrap', fontSize: 14, marginLeft: 16 }}>
64
+ {page || 0} / {pagesCount}
65
+ </span>
66
+ )}
62
67
  </Wrapper>
63
68
  )}
64
69
  <Wrapper>
@@ -40,7 +40,7 @@ export const RowsPerPageDropdown = ({
40
40
  onChange={onChange}
41
41
  css={{
42
42
  marginLeft: 10,
43
- marginRight: 37,
43
+ marginRight: 15,
44
44
  background: 'none',
45
45
  color: '#070821',
46
46
  gap: 5,
@@ -104,8 +104,7 @@ export const PaginationNav = styled.nav`
104
104
  `;
105
105
 
106
106
  export const PageNumberInput = styled(Input)`
107
- width: 80px;
108
- margin-right: 16px;
107
+ width: 65px;
109
108
  -moz-appearance: textfield;
110
109
  appearance: textfield;
111
110
  &::-webkit-outer-spin-button,
@@ -9,8 +9,10 @@ export interface PaginationProps extends CommonProps {
9
9
  pageNumberPlaceholder?: string;
10
10
  isPageSettingVisible?: boolean;
11
11
  isRowPerPageVisible?: boolean;
12
+ isPageFromCountVisible?: boolean;
12
13
  rowPerPageProps?: RowsPerPageDropdownProps;
13
14
  manualPageNumberProps?: InputProps;
15
+ errorTooltip?: string;
14
16
  }
15
17
 
16
18
  export interface PaginationButtonsProps {
@@ -7,7 +7,7 @@ import Card from '@components/Card';
7
7
  import CardHeader from '@components/CardHeader';
8
8
  import Typography from '@components/Typography';
9
9
 
10
- import { PieChart, PieChartLegend } from '@components/PieChart';
10
+ import { PieChart, PieChartLegend } from '@components/Charts/PieChart';
11
11
  import { ProgressInfoTotals } from './ProgressInfoTotals';
12
12
 
13
13
  import {
@@ -3,6 +3,7 @@ import {
3
3
  FloatingArrow,
4
4
  Placement,
5
5
  UseFloatingReturn,
6
+ OffsetOptions,
6
7
  } from '@floating-ui/react';
7
8
  import { PointTooltipProps, Point } from '@nivo/line';
8
9
  import { MapIconsType } from '@components/Icon/types';
@@ -17,7 +18,7 @@ export interface TooltipProps extends CommonProps {
17
18
  placement?: Placement;
18
19
  enableHover?: boolean;
19
20
  enableClick?: boolean;
20
- offsetPx?: number;
21
+ offsetOptions?: OffsetOptions;
21
22
  // TooltipContent-related props
22
23
  size?: TooltipSize;
23
24
  hasArrow?: boolean;
@@ -39,14 +40,16 @@ export type UseTooltip = (props: UseTooltipArgs) => Pick<
39
40
  > & {
40
41
  arrowRef: MutableRefObject<null>;
41
42
  isOpen: boolean;
43
+ setIsOpen: (isOpen: boolean) => void;
42
44
  } & UseFloatingReturn &
43
45
  UseInteractions;
44
46
 
45
47
  export type TooltipContextType =
46
48
  | (UseFloatingReturn &
47
49
  ReturnType<typeof useInteractions> & {
48
- isOpen: boolean;
49
50
  arrowRef: React.Ref<SVGSVGElement>;
51
+ isOpen: boolean;
52
+ setIsOpen: (isOpen: boolean) => void;
50
53
  } & Pick<TooltipProps, 'size' | 'hasArrow' | 'arrowProps'>)
51
54
  | null;
52
55
 
@@ -18,7 +18,7 @@ export const useTooltip: UseTooltip = ({
18
18
  placement,
19
19
  enableClick = true,
20
20
  enableHover = false,
21
- offsetPx = 12,
21
+ offsetOptions = 12,
22
22
  size = 'small',
23
23
  hasArrow = true,
24
24
  arrowProps = {},
@@ -32,7 +32,7 @@ export const useTooltip: UseTooltip = ({
32
32
  onOpenChange: setIsOpen,
33
33
  placement,
34
34
  middleware: [
35
- offset(offsetPx),
35
+ offset(offsetOptions),
36
36
  flip(),
37
37
  shift(),
38
38
  arrow({
@@ -54,6 +54,7 @@ export const useTooltip: UseTooltip = ({
54
54
  return useMemo(
55
55
  () => ({
56
56
  isOpen,
57
+ setIsOpen,
57
58
  arrowRef,
58
59
  size,
59
60
  hasArrow,
@@ -63,6 +64,7 @@ export const useTooltip: UseTooltip = ({
63
64
  }),
64
65
  [
65
66
  isOpen,
67
+ setIsOpen,
66
68
  arrowRef,
67
69
  size,
68
70
  hasArrow,
@@ -13,6 +13,8 @@ export const WidgetCard = ({
13
13
  headerContent,
14
14
  link,
15
15
  children,
16
+ width,
17
+ height,
16
18
  onClick,
17
19
  }: WidgetCardProps) => {
18
20
  const { isFullscreenMode } = useFullscreenMode();
@@ -21,7 +23,9 @@ export const WidgetCard = ({
21
23
  <WidgetCardBase
22
24
  className={className}
23
25
  onClick={link ? undefined : onClick}
24
- isFullscreenMode={isFullscreenMode}>
26
+ isFullscreenMode={isFullscreenMode}
27
+ width={width}
28
+ height={height}>
25
29
  <Header title={title} className={headerClassName}>
26
30
  {headerContent}
27
31
  </Header>
@@ -3,11 +3,13 @@ import Card from '@components/Card';
3
3
 
4
4
  export const WidgetCardBase = styled(Card)<{
5
5
  isFullscreenMode?: boolean;
6
+ width?: string;
7
+ height?: string;
6
8
  }>`
7
9
  border-radius: 20px;
8
10
  padding: 5px 10px;
9
- width: 100%;
10
- height: 100%;
11
+ width: ${({ width }) => width ?? '100%'};
12
+ height: ${({ height }) => height ?? '100%'};
11
13
  position: ${({ isFullscreenMode }) =>
12
14
  isFullscreenMode ? 'absolute' : 'static'};
13
15
  top: ${({ isFullscreenMode }) => isFullscreenMode && 0};
@@ -1,4 +1,4 @@
1
- import { PieChartProps } from '@components/PieChart';
1
+ import { PieChartProps } from '@components/Charts/PieChart';
2
2
  import { WidgetCard } from './WidgetCard';
3
3
 
4
4
  export const WithWidgetCard = ({
@@ -9,5 +9,7 @@ export type WidgetCardProps = {
9
9
  headerContent?: React.ReactNode;
10
10
  link?: To;
11
11
  children?: React.ReactNode;
12
+ width?: string;
13
+ height?: string;
12
14
  onClick?: () => void;
13
15
  };
@@ -82,12 +82,11 @@ export * from './NavBar';
82
82
  export * from './NotificationCard';
83
83
  export * from './NotificationMenu';
84
84
  export * from './Pagination';
85
- export * from './PieChart';
85
+ export * from './Charts';
86
86
  export * from './Popover';
87
87
  export * from './ProgressInfo';
88
88
  export * from './ResponsiveImage';
89
89
  export * from './SearchBox';
90
- export * from './SegmentedPieChart';
91
90
  export * from './Switch';
92
91
  export * from './TabBar';
93
92
  export * from './TableFilters';
@@ -0,0 +1,53 @@
1
+ import { createContext, ReactNode, useContext, useState } from 'react';
2
+ import { pathOr } from '@ssa-ui-kit/utils';
3
+ import { JSONObject } from '@global-types/json';
4
+ import { config as translationConfig } from './config';
5
+ import { TranslationContextContent } from './types';
6
+
7
+ export const TranslationContext = createContext<TranslationContextContent>({
8
+ language: translationConfig.defaultLanguage,
9
+ t() {
10
+ return '';
11
+ },
12
+ setLanguage() {
13
+ /* no-op */
14
+ },
15
+ setTranslations() {
16
+ /* no-op */
17
+ },
18
+ });
19
+
20
+ export const TranslationProvider = ({
21
+ children,
22
+ defaultTranslations = {},
23
+ }: {
24
+ children: ReactNode;
25
+ defaultTranslations?: JSONObject;
26
+ }) => {
27
+ const [language, setLanguage] = useState<string>(
28
+ translationConfig.defaultLanguage,
29
+ );
30
+ const [translations, setTranslations] =
31
+ useState<JSONObject>(defaultTranslations);
32
+ const t = (translationKey: string) => {
33
+ const translationKeyArray = translationKey.split('.');
34
+ const translation = pathOr<JSONObject, string>(translationKey, [
35
+ language,
36
+ ...translationKeyArray,
37
+ ])(translations);
38
+ return translation;
39
+ };
40
+ return (
41
+ <TranslationContext.Provider
42
+ value={{
43
+ language,
44
+ t,
45
+ setLanguage,
46
+ setTranslations,
47
+ }}>
48
+ {children}
49
+ </TranslationContext.Provider>
50
+ );
51
+ };
52
+
53
+ export const useTranslation = () => useContext(TranslationContext);
@@ -0,0 +1,3 @@
1
+ export const config = {
2
+ defaultLanguage: 'en',
3
+ };
@@ -0,0 +1,2 @@
1
+ export * from './TranslationContext';
2
+ export * from './types';
@@ -0,0 +1,9 @@
1
+ import { Dispatch, SetStateAction } from 'react';
2
+ import { JSONObject } from '@global-types/json';
3
+
4
+ export type TranslationContextContent = {
5
+ language: string;
6
+ t: (translationKey: string) => string;
7
+ setLanguage: Dispatch<SetStateAction<string>>;
8
+ setTranslations: Dispatch<SetStateAction<JSONObject>>;
9
+ };
@@ -0,0 +1 @@
1
+ export * from './Translation';
package/src/index.ts CHANGED
@@ -10,3 +10,4 @@ export { default as mainTheme } from './themes/main';
10
10
  export * as globalStyles from './styles/global';
11
11
  export * as styleUtils from './styles/safari-focus-outline';
12
12
  export * from './components';
13
+ export * from './contexts';
@@ -0,0 +1,7 @@
1
+ export type JSONValue = string | number | boolean | JSONObject | JSONArray;
2
+
3
+ export interface JSONObject {
4
+ [x: string]: JSONValue;
5
+ }
6
+
7
+ export type JSONArray = Array<JSONValue>;