@redocly/theme 0.40.6 → 0.41.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/lib/components/Dropdown/DropdownMenu.d.ts +2 -0
  2. package/lib/components/Dropdown/DropdownMenu.js +3 -1
  3. package/lib/components/Loaders/SpinnerLoader.d.ts +5 -0
  4. package/lib/components/Loaders/SpinnerLoader.js +32 -0
  5. package/lib/components/Search/FilterFields/SearchFilterFieldSelect.d.ts +12 -0
  6. package/lib/components/Search/FilterFields/SearchFilterFieldSelect.js +113 -0
  7. package/lib/components/Search/FilterFields/SearchFilterFieldTags.d.ts +10 -0
  8. package/lib/components/Search/FilterFields/SearchFilterFieldTags.js +37 -0
  9. package/lib/components/Search/Search.js +1 -1
  10. package/lib/components/Search/SearchDialog.js +103 -26
  11. package/lib/components/Search/SearchFilter.d.ts +11 -0
  12. package/lib/components/Search/SearchFilter.js +71 -0
  13. package/lib/components/Search/SearchFilterField.d.ts +11 -0
  14. package/lib/components/Search/SearchFilterField.js +43 -0
  15. package/lib/components/Search/SearchGroups.d.ts +9 -0
  16. package/lib/components/Search/SearchGroups.js +69 -0
  17. package/lib/components/Search/SearchHighlight.d.ts +1 -1
  18. package/lib/components/Search/SearchHighlight.js +28 -5
  19. package/lib/components/Search/SearchInput.d.ts +3 -2
  20. package/lib/components/Search/SearchInput.js +11 -3
  21. package/lib/components/Search/SearchItem.d.ts +2 -2
  22. package/lib/components/Search/SearchItem.js +23 -15
  23. package/lib/components/Search/variables.js +48 -2
  24. package/lib/components/Segmented/Segmented.d.ts +2 -5
  25. package/lib/components/Select/Select.d.ts +2 -36
  26. package/lib/components/Select/Select.js +134 -98
  27. package/lib/components/Select/SelectInput.d.ts +23 -0
  28. package/lib/components/Select/SelectInput.js +129 -0
  29. package/lib/components/Select/variables.js +11 -1
  30. package/lib/components/Tag/Tag.d.ts +4 -2
  31. package/lib/components/Tag/Tag.js +40 -4
  32. package/lib/components/Tag/variables.dark.js +20 -5
  33. package/lib/components/Tag/variables.js +49 -17
  34. package/lib/components/VersionPicker/VersionPicker.d.ts +2 -3
  35. package/lib/components/VersionPicker/VersionPicker.js +13 -30
  36. package/lib/core/hooks/__mocks__/index.d.ts +1 -1
  37. package/lib/core/hooks/__mocks__/index.js +1 -1
  38. package/lib/core/hooks/__mocks__/use-theme-hooks.d.ts +1 -1
  39. package/lib/core/hooks/__mocks__/use-theme-hooks.js +1 -1
  40. package/lib/core/hooks/index.d.ts +2 -1
  41. package/lib/core/hooks/index.js +2 -1
  42. package/lib/core/hooks/search/use-recent-searches.js +2 -0
  43. package/lib/core/hooks/{use-search.d.ts → search/use-search-dialog.d.ts} +1 -1
  44. package/lib/core/hooks/{use-search.js → search/use-search-dialog.js} +5 -5
  45. package/lib/core/hooks/search/use-search-filter.d.ts +9 -0
  46. package/lib/core/hooks/search/use-search-filter.js +50 -0
  47. package/lib/core/types/hooks.d.ts +16 -4
  48. package/lib/core/types/index.d.ts +1 -1
  49. package/lib/core/types/index.js +1 -1
  50. package/lib/core/types/l10n.d.ts +1 -1
  51. package/lib/core/types/search.d.ts +43 -2
  52. package/lib/core/types/select.d.ts +30 -0
  53. package/lib/core/types/{select-option.js → select.js} +1 -1
  54. package/lib/icons/ResetIcon/ResetIcon.d.ts +9 -0
  55. package/lib/icons/ResetIcon/ResetIcon.js +22 -0
  56. package/lib/icons/SettingsIcon/SettingsIcon.d.ts +9 -0
  57. package/lib/icons/SettingsIcon/SettingsIcon.js +23 -0
  58. package/lib/index.d.ts +7 -1
  59. package/lib/index.js +7 -1
  60. package/package.json +2 -2
  61. package/src/components/Dropdown/DropdownMenu.tsx +2 -1
  62. package/src/components/Filter/FilterSelect.tsx +3 -3
  63. package/src/components/Loaders/SpinnerLoader.tsx +31 -0
  64. package/src/components/Search/FilterFields/SearchFilterFieldSelect.tsx +134 -0
  65. package/src/components/Search/FilterFields/SearchFilterFieldTags.tsx +61 -0
  66. package/src/components/Search/Search.tsx +2 -2
  67. package/src/components/Search/SearchDialog.tsx +168 -42
  68. package/src/components/Search/SearchFilter.tsx +90 -0
  69. package/src/components/Search/SearchFilterField.tsx +84 -0
  70. package/src/components/Search/SearchGroups.tsx +80 -0
  71. package/src/components/Search/SearchHighlight.tsx +29 -2
  72. package/src/components/Search/SearchInput.tsx +17 -3
  73. package/src/components/Search/SearchItem.tsx +38 -24
  74. package/src/components/Search/variables.ts +48 -2
  75. package/src/components/Segmented/Segmented.tsx +2 -2
  76. package/src/components/Select/Select.tsx +200 -157
  77. package/src/components/Select/SelectInput.tsx +201 -0
  78. package/src/components/Select/variables.ts +11 -1
  79. package/src/components/Tag/Tag.tsx +57 -6
  80. package/src/components/Tag/variables.dark.ts +20 -5
  81. package/src/components/Tag/variables.ts +49 -17
  82. package/src/components/VersionPicker/VersionPicker.tsx +15 -39
  83. package/src/core/hooks/__mocks__/index.ts +1 -1
  84. package/src/core/hooks/__mocks__/use-theme-hooks.ts +1 -1
  85. package/src/core/hooks/index.ts +2 -1
  86. package/src/core/hooks/search/use-recent-searches.ts +3 -0
  87. package/src/core/hooks/{use-search.ts → search/use-search-dialog.ts} +1 -1
  88. package/src/core/hooks/search/use-search-filter.ts +57 -0
  89. package/src/core/types/hooks.ts +24 -4
  90. package/src/core/types/index.ts +1 -1
  91. package/src/core/types/l10n.ts +7 -1
  92. package/src/core/types/search.ts +54 -2
  93. package/src/core/types/select.ts +32 -0
  94. package/src/icons/ResetIcon/ResetIcon.tsx +26 -0
  95. package/src/icons/SettingsIcon/SettingsIcon.tsx +30 -0
  96. package/src/index.ts +7 -1
  97. package/lib/core/types/select-option.d.ts +0 -4
  98. package/src/core/types/select-option.ts +0 -4
  99. /package/lib/components/{Loading → Loaders}/Loading.d.ts +0 -0
  100. /package/lib/components/{Loading → Loaders}/Loading.js +0 -0
  101. /package/src/components/{Loading → Loaders}/Loading.tsx +0 -0
@@ -0,0 +1,57 @@
1
+ import { useCallback, useState } from 'react';
2
+
3
+ import type { SearchFilterItem } from '@redocly/theme/core/types';
4
+
5
+ export function useSearchFilter(
6
+ filter: SearchFilterItem[],
7
+ setFilter: React.Dispatch<React.SetStateAction<SearchFilterItem[]>>,
8
+ ) {
9
+ const [isFilterOpen, setIsFilterOpen] = useState(false);
10
+
11
+ const onFilterToggle = useCallback(() => {
12
+ setIsFilterOpen(!isFilterOpen);
13
+ }, [isFilterOpen]);
14
+
15
+ const onFilterChange = (field: string, value: string | string[] | undefined, isTop?: boolean) => {
16
+ const values = value ? (Array.isArray(value) ? value : [value]) : [];
17
+
18
+ const _filter = [...filter];
19
+ const fieldIndex = _filter.findIndex((filter) => filter.field === field);
20
+ if (fieldIndex > -1) {
21
+ // filter field already exists
22
+ _filter[fieldIndex].values = values;
23
+ } else {
24
+ if (!values.length) return;
25
+ _filter.push({ field, values, isTop });
26
+ }
27
+
28
+ setFilter(_filter.filter((item) => item.values.length));
29
+ };
30
+
31
+ const onFilterReset = () => {
32
+ setFilter([]);
33
+ };
34
+
35
+ const onTopFacetsReset = () => {
36
+ const _filter = [...filter];
37
+ setFilter(_filter.filter((item) => !item.isTop));
38
+ };
39
+
40
+ const onFacetReset = (field: string) => {
41
+ const _filter = [...filter];
42
+ const fieldIndex = _filter.findIndex((filter) => filter.field === field);
43
+ if (fieldIndex !== -1) {
44
+ _filter[fieldIndex].values = [];
45
+ }
46
+ setFilter(_filter.filter((item) => item.values.length));
47
+ };
48
+
49
+ return {
50
+ onFacetReset,
51
+ onTopFacetsReset,
52
+ onFilterChange,
53
+ onFilterReset,
54
+ onFilterToggle,
55
+ isFilterOpen,
56
+ };
57
+ }
@@ -6,11 +6,14 @@ import type {
6
6
  UserMenuData,
7
7
  FilteredCatalog,
8
8
  ItemState,
9
- SearchDocument,
9
+ SearchItemData,
10
10
  SubmitFeedbackParams,
11
11
  TFunction,
12
12
  BreadcrumbItem,
13
13
  DrilldownMenuItemDetails,
14
+ SearchFacet,
15
+ SearchFilterItem,
16
+ SearchFacetQuery,
14
17
  } from '@redocly/theme/core/types';
15
18
 
16
19
  export type ThemeHooks = {
@@ -51,11 +54,28 @@ export type ThemeHooks = {
51
54
  location: Location;
52
55
  };
53
56
  useBreadcrumbs: () => BreadcrumbItem[];
54
- useFuseSearch: (product?: string) => {
57
+ useSearch: (product?: string) => {
55
58
  query: string;
56
59
  setQuery: React.Dispatch<React.SetStateAction<string>>;
57
- items: SearchDocument[] | null;
58
- isLoading: boolean;
60
+ filter: SearchFilterItem[];
61
+ setFilter: React.Dispatch<React.SetStateAction<SearchFilterItem[]>>;
62
+ items: Record<string, SearchItemData[] | null>;
63
+ isSearchLoading: boolean;
64
+ facets: SearchFacet[];
65
+ setLoadMore: React.Dispatch<
66
+ React.SetStateAction<
67
+ | {
68
+ groupKey: string;
69
+ offset: number;
70
+ }
71
+ | undefined
72
+ >
73
+ >;
74
+ };
75
+ useFacetQuery: (field: string) => {
76
+ searchFacet: SearchFacet | null;
77
+ setSearchFacet: React.Dispatch<React.SetStateAction<SearchFacet | null>>;
78
+ setSearchFacetQuery: React.Dispatch<React.SetStateAction<SearchFacetQuery | null>>;
59
79
  };
60
80
  useSidebarItems: (activeVersion?: Version | null) => {
61
81
  currentItems: ItemState[];
@@ -6,7 +6,7 @@ export * from '@redocly/theme/core/types/hooks';
6
6
  export * from '@redocly/theme/core/types/markdown';
7
7
  export * from '@redocly/theme/core/types/navbar';
8
8
  export * from '@redocly/theme/core/types/search';
9
- export * from '@redocly/theme/core/types/select-option';
9
+ export * from '@redocly/theme/core/types/select';
10
10
  export * from '@redocly/theme/core/types/sidebar';
11
11
  export * from '@redocly/theme/core/types/filter';
12
12
  export * from '@redocly/theme/core/types/user-menu';
@@ -69,7 +69,9 @@ export type TranslationKey =
69
69
  | 'dev.app.overview.created'
70
70
  | 'dev.app.overview.visibilityToggle.hide'
71
71
  | 'dev.app.overview.visibilityToggle.show'
72
- | 'theme.search.noResults'
72
+ | 'theme.search.loading'
73
+ | 'theme.search.noResults.title'
74
+ | 'theme.search.noResults.description'
73
75
  | 'theme.search.keys.navigate'
74
76
  | 'theme.search.keys.select'
75
77
  | 'theme.search.keys.exit'
@@ -78,6 +80,10 @@ export type TranslationKey =
78
80
  | 'theme.search.recent'
79
81
  | 'theme.search.navbar.label'
80
82
  | 'theme.search.suggested'
83
+ | 'theme.search.showMore'
84
+ | 'theme.search.filter.title'
85
+ | 'theme.search.filter.reset'
86
+ | 'theme.search.filter.field.reset'
81
87
  | 'theme.toc.header'
82
88
  | 'theme.footer.copyrightText'
83
89
  | 'theme.page.homeButton'
@@ -14,9 +14,9 @@ export type SearchDocument = {
14
14
  title: string | string[];
15
15
  text: string | string[];
16
16
  path?: string[];
17
- httpVerb?: string;
17
+ httpMethod?: string;
18
+ httpPath?: string | string[];
18
19
  deprecated?: boolean;
19
- pathName?: string | string[];
20
20
  parameters?: OperationParameter[];
21
21
  metadata?: Record<string, any>;
22
22
  version?: string;
@@ -26,4 +26,56 @@ export type SearchDocument = {
26
26
  'redocly::teams-rbac'?: { [x: string]: string };
27
27
  [REDOCLY_ROUTE_RBAC]?: { slug?: string; fsPath?: string };
28
28
  badges?: ItemBadge[];
29
+ facets?: Record<string, string>;
30
+ filterTags?: string[];
31
+ parametersNames?: string[]; // this field is used only for flexsearch indexing
32
+ parametersDescriptons?: string[]; // this field is used only for flexsearch indexing
33
+ };
34
+
35
+ export type ParameterHighlight = {
36
+ name: string;
37
+ description: string;
38
+ place: string;
39
+ path: string[];
40
+ };
41
+
42
+ export type SearchItemData = {
43
+ document: SearchDocument;
44
+ highlight: Record<string, string> & { parameters?: ParameterHighlight[]; path?: string[] };
45
+ };
46
+
47
+ export type SearchFacet = {
48
+ name: string;
49
+ field: string;
50
+ type: SearchFacetType;
51
+ values: string[] | SearchFacetCount[];
52
+ isTop?: boolean;
53
+ index?: number;
54
+ };
55
+
56
+ export type SearchFacetCount = {
57
+ value: string;
58
+ count: number;
59
+ isCounterVisible?: boolean;
60
+ };
61
+
62
+ export type SearchFacetQuery = {
63
+ query: string;
64
+ filter: SearchFilterItem[];
65
+ facetQuery: string;
66
+ };
67
+
68
+ export type SearchFacetType =
69
+ | 'input'
70
+ | 'multi-select'
71
+ | 'select'
72
+ | 'switch'
73
+ | 'radio'
74
+ | 'tags'
75
+ | 'checkbox';
76
+
77
+ export type SearchFilterItem = {
78
+ field: string;
79
+ values: string[];
80
+ isTop?: boolean;
29
81
  };
@@ -0,0 +1,32 @@
1
+ import type React from 'react';
2
+
3
+ export type SelectOption<T> = {
4
+ value: T;
5
+ element?: React.ReactNode | JSX.Element | string;
6
+ label?: string;
7
+ };
8
+
9
+ export type SelectProps<T = any> = {
10
+ value?: SelectOption<T> | SelectOption<T>[] | T | T[];
11
+ options: SelectOption<T>[];
12
+ multiple?: boolean;
13
+ searchable?: boolean;
14
+ clearable?: boolean;
15
+ dataAttributes?: Record<string, string>;
16
+ className?: string;
17
+ withArrow?: boolean;
18
+ triggerEvent?: 'click' | 'hover';
19
+ placement?: 'top' | 'bottom';
20
+ alignment?: 'start' | 'end';
21
+ onlyIcon?: boolean;
22
+ placeholder?: string;
23
+ disabled?: boolean;
24
+ hideCheckmarkIcon?: boolean;
25
+ dataTestId?: string;
26
+ icon?: React.ReactNode;
27
+ footer?: React.ReactNode;
28
+ onChange?: (value: T | T[]) => void;
29
+ renderInput?: () => React.ReactElement;
30
+ renderDivider?: () => React.ReactElement;
31
+ onSearch?: (value: T | null) => void;
32
+ };
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import type { IconProps } from '@redocly/theme/icons/types';
5
+
6
+ import { getCssColorVariable } from '@redocly/theme/core/utils';
7
+
8
+ const Icon = (props: IconProps) => (
9
+ <svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}>
10
+ <path
11
+ d="M9 14C10.1867 14 11.3467 13.6481 12.3334 12.9888C13.3201 12.3295 14.0892 11.3925 14.5433 10.2961C14.9974 9.19975 15.1162 7.99335 14.8847 6.82946C14.6532 5.66558 14.0818 4.59648 13.2426 3.75736C12.4035 2.91825 11.3344 2.3468 10.1705 2.11529C9.00666 1.88378 7.80026 2.0026 6.7039 2.45673C5.60754 2.91085 4.67047 3.67989 4.01118 4.66658C3.35189 5.65328 3 6.81331 3 8V11.1L1.2 9.3L0.5 10L3.5 13L6.5 10L5.8 9.3L4 11.1V8C4 7.0111 4.29324 6.0444 4.84265 5.22215C5.39206 4.39991 6.17295 3.75904 7.08658 3.38061C8.00021 3.00217 9.00555 2.90315 9.97545 3.09608C10.9454 3.289 11.8363 3.76521 12.5355 4.46447C13.2348 5.16373 13.711 6.05465 13.9039 7.02455C14.0969 7.99446 13.9978 8.99979 13.6194 9.91342C13.241 10.8271 12.6001 11.6079 11.7779 12.1574C10.9556 12.7068 9.98891 13 9 13V14Z"
12
+ fill="#1A1C21"
13
+ />
14
+ </svg>
15
+ );
16
+
17
+ export const ResetIcon = styled(Icon).attrs(() => ({
18
+ 'data-component-name': 'icons/ResetIcon/ResetIcon',
19
+ }))<IconProps>`
20
+ path {
21
+ fill: ${({ color }) => getCssColorVariable(color)};
22
+ }
23
+
24
+ height: ${({ size }) => size || '16px'};
25
+ width: ${({ size }) => size || '16px'};
26
+ `;
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import type { IconProps } from '@redocly/theme/icons/types';
5
+
6
+ import { getCssColorVariable } from '@redocly/theme/core/utils';
7
+
8
+ const Icon = (props: IconProps) => (
9
+ <svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}>
10
+ <path
11
+ d="M15.875 2.5H13.5687C13.2875 1.20625 12.1625 0.25 10.8125 0.25C9.4625 0.25 8.3375 1.20625 8.05625 2.5H0.125V3.625H8.05625C8.3375 4.91875 9.4625 5.875 10.8125 5.875C12.1625 5.875 13.2875 4.91875 13.5687 3.625H15.875V2.5ZM10.8125 4.75C9.85625 4.75 9.125 4.01875 9.125 3.0625C9.125 2.10625 9.85625 1.375 10.8125 1.375C11.7688 1.375 12.5 2.10625 12.5 3.0625C12.5 4.01875 11.7688 4.75 10.8125 4.75Z"
12
+ fill="#22242B"
13
+ />
14
+ <path
15
+ d="M0.125 11.5H2.43125C2.7125 12.7937 3.8375 13.75 5.1875 13.75C6.5375 13.75 7.6625 12.7937 7.94375 11.5H15.875V10.375H7.94375C7.6625 9.08125 6.5375 8.125 5.1875 8.125C3.8375 8.125 2.7125 9.08125 2.43125 10.375H0.125V11.5ZM5.1875 9.25C6.14375 9.25 6.875 9.98125 6.875 10.9375C6.875 11.8938 6.14375 12.625 5.1875 12.625C4.23125 12.625 3.5 11.8938 3.5 10.9375C3.5 9.98125 4.23125 9.25 5.1875 9.25Z"
16
+ fill="#22242B"
17
+ />
18
+ </svg>
19
+ );
20
+
21
+ export const SettingsIcon = styled(Icon).attrs(() => ({
22
+ 'data-component-name': 'icons/SettingsIcon/SettingsIcon',
23
+ }))<IconProps>`
24
+ path {
25
+ fill: ${({ color }) => getCssColorVariable(color)};
26
+ }
27
+
28
+ height: ${({ size }) => size || '16px'};
29
+ width: ${({ size }) => size || '16px'};
30
+ `;
package/src/index.ts CHANGED
@@ -13,7 +13,7 @@ export * from '@redocly/theme/components/Badge/Badge';
13
13
  export * from '@redocly/theme/components/Dropdown/Dropdown';
14
14
  export * from '@redocly/theme/components/Dropdown/DropdownMenu';
15
15
  export * from '@redocly/theme/components/Dropdown/DropdownMenuItem';
16
- export * from '@redocly/theme/components/Loading/Loading';
16
+ export * from '@redocly/theme/components/Loaders/Loading';
17
17
  export * from '@redocly/theme/components/Link/Link';
18
18
  export * from '@redocly/theme/components/Portal/Portal';
19
19
  export * from '@redocly/theme/components/Segmented/Segmented';
@@ -135,6 +135,10 @@ export * from '@redocly/theme/components/Search/SearchShortcut';
135
135
  export * from '@redocly/theme/components/Search/SearchTrigger';
136
136
  export * from '@redocly/theme/components/Search/SearchRecent';
137
137
  export * from '@redocly/theme/components/Search/SearchSuggestedPages';
138
+ export * from '@redocly/theme/components/Search/SearchFilter';
139
+ export * from '@redocly/theme/components/Search/SearchFilterField';
140
+ export * from '@redocly/theme/components/Search/FilterFields/SearchFilterFieldSelect';
141
+ export * from '@redocly/theme/components/Search/FilterFields/SearchFilterFieldTags';
138
142
  /* Icons */
139
143
  export * from '@redocly/theme/icons/ArrowRightIcon/ArrowRightIcon';
140
144
  export * from '@redocly/theme/icons/ArrowUpRightIcon/ArrowUpRightIcon';
@@ -150,6 +154,7 @@ export * from '@redocly/theme/icons/FolderAddIcon/FolderAddIcon';
150
154
  export * from '@redocly/theme/icons/FolderIcon/FolderIcon';
151
155
  export * from '@redocly/theme/icons/FolderMoveToIcon/FolderMoveToIcon';
152
156
  export * from '@redocly/theme/icons/SelectIcon/SelectIcon';
157
+ export * from '@redocly/theme/icons/SettingsIcon/SettingsIcon';
153
158
  export * from '@redocly/theme/icons/CloseIcon/CloseIcon';
154
159
  export * from '@redocly/theme/icons/CloseOutlineIcon/CloseOutlineIcon';
155
160
  export * from '@redocly/theme/icons/CloseFilledIcon/CloseFilledIcon';
@@ -197,6 +202,7 @@ export * from '@redocly/theme/icons/MobileSidebarIcon/MobileSidebarIcon';
197
202
  export * from '@redocly/theme/icons/CopyLinkIcon/CopyLinkIcon';
198
203
  export * from '@redocly/theme/icons/OverflowMenuHorizontalIcon/OverflowMenuHorizontalIcon';
199
204
  export * from '@redocly/theme/icons/RenewIcon/RenewIcon';
205
+ export * from '@redocly/theme/icons/ResetIcon/ResetIcon';
200
206
  export * from '@redocly/theme/icons/WarningAltIcon/WarningAltIcon';
201
207
  export * from '@redocly/theme/icons/MoonIcon/MoonIcon';
202
208
  export * from '@redocly/theme/icons/SunIcon/SunIcon';
@@ -1,4 +0,0 @@
1
- export type SelectOption<T> = {
2
- value: T;
3
- label: string;
4
- };
@@ -1,4 +0,0 @@
1
- export type SelectOption<T> = {
2
- value: T;
3
- label: string;
4
- };
File without changes
File without changes