@appquality/unguess-design-system 3.1.79 → 3.1.80

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/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # v3.1.80 (Tue May 07 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Allow search in trascript [#326](https://github.com/AppQuality/unguess-design-system/pull/326) ([@cannarocks](https://github.com/cannarocks))
6
+ - feat: Add search functionality to highlight component [#325](https://github.com/AppQuality/unguess-design-system/pull/325) ([@cannarocks](https://github.com/cannarocks))
7
+
8
+ #### Authors: 1
9
+
10
+ - Luca Cannarozzo ([@cannarocks](https://github.com/cannarocks))
11
+
12
+ ---
13
+
1
14
  # v3.1.79 (Mon May 06 2024)
2
15
 
3
16
  #### 🐛 Bug Fix
package/build/index.js CHANGED
@@ -3912,6 +3912,33 @@ const UgGrid = styled__default["default"](reactGrid.Grid) `
3912
3912
  */
3913
3913
  const Grid = (props) => jsxRuntime.jsx(UgGrid, Object.assign({}, props));
3914
3914
 
3915
+ const HighlightContext = React.createContext(null);
3916
+ const HighlightContextProvider = ({ term, children, }) => {
3917
+ const [searchTerm, setsearchTerm] = React.useState(term !== null && term !== void 0 ? term : "");
3918
+ React.useEffect(() => {
3919
+ setsearchTerm(term !== null && term !== void 0 ? term : "");
3920
+ }, [term]);
3921
+ const HighlightContextValue = React.useMemo(() => ({
3922
+ searchTerm,
3923
+ }), [searchTerm]);
3924
+ return (jsxRuntime.jsx(HighlightContext.Provider, Object.assign({ value: HighlightContextValue }, { children: children })));
3925
+ };
3926
+ const useHighlightContext = () => {
3927
+ const context = React.useContext(HighlightContext);
3928
+ if (!context)
3929
+ throw new Error("Provider not found for HighlightContextProvider");
3930
+ return context; // Now we can use the context in the component, SAFELY.
3931
+ };
3932
+
3933
+ const Searchable = ({ start, text, }) => {
3934
+ const { searchTerm } = useHighlightContext();
3935
+ if (searchTerm) {
3936
+ const parts = text.split(new RegExp(`(${searchTerm})`, "gi"));
3937
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: parts.map((part, index) => part.toLowerCase() === searchTerm.toLowerCase() ? (jsxRuntime.jsx("mark", { children: part }, index)) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: part }))) }));
3938
+ }
3939
+ return jsxRuntime.jsx(jsxRuntime.Fragment, { children: text });
3940
+ };
3941
+
3915
3942
  const StyledWord = styled__default["default"](reactTypography.Span) `
3916
3943
  font-size: ${({ theme, size }) => theme.fontSizes[size !== null && size !== void 0 ? size : "md"]};
3917
3944
  padding: ${({ theme }) => theme.space.xxs} 0;
@@ -3991,7 +4018,7 @@ const Highlight = (props) => {
3991
4018
  document.removeEventListener("selectionchange", handleSelectionChange);
3992
4019
  };
3993
4020
  }, [ref, props, handleSelectionChange]);
3994
- return jsxRuntime.jsx(WordsContainer, Object.assign({ ref: ref }, { children: props.children }));
4021
+ return (jsxRuntime.jsxs(HighlightContextProvider, Object.assign({ term: props.search }, { children: [jsxRuntime.jsx(WordsContainer, Object.assign({ ref: ref }, { children: props.children })), ";"] })));
3995
4022
  };
3996
4023
  const Word = (props) => {
3997
4024
  var _a;
@@ -4000,7 +4027,7 @@ const Word = (props) => {
4000
4027
  props.currentTime < props.end;
4001
4028
  // Is there an observation that contains this word?
4002
4029
  const observation = (_a = props.observations) === null || _a === void 0 ? void 0 : _a.find((obs) => props.start >= obs.start && props.end <= obs.end);
4003
- return (jsxRuntime.jsxs(StyledWord, Object.assign({}, props, { observation: observation, "data-start": props.start, "data-end": props.end, className: !!observation ? "highlighted" : "" }, (!!observation ? { tag: "observation" } : {}), { children: [isActive ? jsxRuntime.jsx(ActiveWord, { children: props.children }) : props.children, !observation && " "] })));
4030
+ return (jsxRuntime.jsxs(StyledWord, Object.assign({}, props, { observation: observation, "data-start": props.start, "data-end": props.end, className: !!observation ? "highlighted" : "" }, (!!observation ? { tag: "observation" } : {}), { children: [isActive ? (jsxRuntime.jsx(ActiveWord, { children: jsxRuntime.jsx(Searchable, { start: props.start, text: props.text }) })) : (jsxRuntime.jsx(Searchable, { start: props.start, text: props.text })), !observation && " "] })));
4004
4031
  };
4005
4032
  Highlight.Word = Word;
4006
4033
 
@@ -18,6 +18,7 @@ export interface HighlightArgs {
18
18
  to: number;
19
19
  text: string;
20
20
  }) => void;
21
+ search?: string;
21
22
  }
22
23
  export interface Observation {
23
24
  id: number;
@@ -31,6 +32,7 @@ export interface WordProps extends ISpanProps {
31
32
  end: number;
32
33
  currentTime?: number;
33
34
  observations?: Observation[];
35
+ text: string;
34
36
  /** Adjusts the font size. By default font size is medium */
35
37
  size?: "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "xxxl";
36
38
  }
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ export type HighlightContextType = {
3
+ searchTerm: string;
4
+ };
5
+ export declare const HighlightContext: React.Context<HighlightContextType | null>;
6
+ export declare const HighlightContextProvider: ({ term, children, }: {
7
+ term?: string | undefined;
8
+ children: React.ReactNode;
9
+ }) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const useHighlightContext: () => HighlightContextType;
@@ -1,5 +1,5 @@
1
- import { HighlightArgs, WordProps } from "./_types";
2
1
  import { PropsWithChildren } from "react";
2
+ import { HighlightArgs, WordProps } from "./_types";
3
3
  /**
4
4
  * Use Highlight to use highlight interation on any text element
5
5
  */
@@ -7,9 +7,11 @@ interface StoryArgs extends HighlightArgs {
7
7
  speaker: number;
8
8
  }[];
9
9
  currentTime: number;
10
+ includeSearch?: boolean;
10
11
  }
11
12
  export declare const Default: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, StoryArgs>;
12
13
  export declare const VideoSync: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, StoryArgs>;
14
+ export declare const WithSearch: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, StoryArgs>;
13
15
  declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, HighlightArgs & {
14
16
  children?: import("react").ReactNode;
15
17
  }>;
@@ -0,0 +1,4 @@
1
+ export declare const Searchable: ({ start, text, }: {
2
+ start: number;
3
+ text: string;
4
+ }) => import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appquality/unguess-design-system",
3
- "version": "3.1.79",
3
+ "version": "3.1.80",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",