@yamada-ui/highlight 1.0.42 → 1.0.43-dev-20241119122307
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-RHTZJRTC.mjs → chunk-JI2JLM73.mjs} +5 -3
- package/dist/chunk-JI2JLM73.mjs.map +1 -0
- package/dist/highlight.d.mts +9 -1
- package/dist/highlight.d.ts +9 -1
- package/dist/highlight.js +4 -2
- package/dist/highlight.js.map +1 -1
- package/dist/highlight.mjs +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-RHTZJRTC.mjs.map +0 -1
@@ -24,6 +24,7 @@ var highlightWords = ({ query, text }) => {
|
|
24
24
|
var useHighlight = ({ query, text }) => useMemo(() => highlightWords({ query, text }), [text, query]);
|
25
25
|
var Highlight = ({
|
26
26
|
children: text,
|
27
|
+
fragment,
|
27
28
|
isFragment = false,
|
28
29
|
lineHeight = "tall",
|
29
30
|
query,
|
@@ -32,9 +33,10 @@ var Highlight = ({
|
|
32
33
|
}) => {
|
33
34
|
if (typeof text !== "string")
|
34
35
|
throw new Error("The children prop of Highlight must be a string");
|
36
|
+
fragment != null ? fragment : fragment = isFragment;
|
35
37
|
const chunks = useHighlight({ query, text });
|
36
|
-
const Component =
|
37
|
-
return /* @__PURE__ */ jsx(Component, { ...!
|
38
|
+
const Component = fragment ? Fragment : Text;
|
39
|
+
return /* @__PURE__ */ jsx(Component, { ...!fragment ? { lineHeight } : {}, ...rest, children: chunks.map(
|
38
40
|
({ match, text: text2 }, i) => match ? /* @__PURE__ */ jsx(Mark, { ...markProps, children: text2 }, i) : /* @__PURE__ */ jsx(Fragment, { children: text2 }, i)
|
39
41
|
) });
|
40
42
|
};
|
@@ -66,4 +68,4 @@ export {
|
|
66
68
|
Highlight,
|
67
69
|
Mark
|
68
70
|
};
|
69
|
-
//# sourceMappingURL=chunk-
|
71
|
+
//# sourceMappingURL=chunk-JI2JLM73.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/highlight.tsx"],"sourcesContent":["import type { CSSUIObject, FC, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { TextProps } from \"@yamada-ui/typography\"\nimport type { ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentStyle,\n} from \"@yamada-ui/core\"\nimport { Text } from \"@yamada-ui/typography\"\nimport { cx, isArray } from \"@yamada-ui/utils\"\nimport { Fragment, useMemo } from \"react\"\n\ninterface Options {\n query: string | string[]\n text: string\n}\n\ninterface Chunk {\n match: boolean\n text: string\n}\n\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`)\n\nconst buildRegex = (query: string[]): RegExp | undefined => {\n query = query.filter(Boolean).map((text) => escapeRegexp(text.trim()))\n\n if (query.length) return new RegExp(`(${query.join(\"|\")})`, \"ig\")\n}\n\nconst highlightWords = ({ query, text }: Options): Chunk[] => {\n const regex = buildRegex(isArray(query) ? query : [query])\n\n if (!regex) return [{ match: false, text }]\n\n return text\n .split(regex)\n .filter(Boolean)\n .map((text) => ({ match: regex.test(text), text }))\n}\n\nexport const useHighlight = ({ query, text }: Options): Chunk[] =>\n useMemo(() => highlightWords({ query, text }), [text, query])\n\nexport interface HighlightProps extends Omit<TextProps, \"children\"> {\n /**\n * Accepts a string or a function. If it's a function, it should return a `ReactNode` and accept an array of `Chunk` objects as its argument.\n */\n children: ((props: Chunk[]) => ReactNode) | string\n /**\n * Can be a single string or an array of strings. These are the terms that are highlighted in the text.\n */\n query: string | string[]\n /**\n * If `true`, `Fragment` is used for rendering.\n *\n * @default false\n */\n fragment?: boolean\n /**\n * If `true`, `Fragment` is used for rendering.\n *\n * @default false\n *\n * @deprecated Use `fragment` instead.\n */\n isFragment?: boolean\n /**\n * Properties passed to the Mark component which is used to highlight the matched terms.\n */\n markProps?: MarkProps\n}\n\n/**\n * `Highlight` is a component that highlights specified strings within text. By default, it renders a `p` element.\n *\n * @see Docs https://yamada-ui.com/components/typography/highlight\n */\nexport const Highlight: FC<HighlightProps> = ({\n children: text,\n fragment,\n isFragment = false,\n lineHeight = \"tall\",\n query,\n markProps,\n ...rest\n}) => {\n if (typeof text !== \"string\")\n throw new Error(\"The children prop of Highlight must be a string\")\n\n fragment ??= isFragment\n\n const chunks = useHighlight({ query, text })\n\n const Component: FC = fragment ? Fragment : Text\n\n return (\n <Component {...(!fragment ? { lineHeight } : {})} {...rest}>\n {chunks.map(({ match, text }, i) =>\n match ? (\n <Mark key={i} {...markProps}>\n {text}\n </Mark>\n ) : (\n <Fragment key={i}>{text}</Fragment>\n ),\n )}\n </Component>\n )\n}\n\nHighlight.displayName = \"Highlight\"\nHighlight.__ui__ = \"Highlight\"\n\nexport interface MarkProps extends HTMLUIProps<\"mark\">, ThemeProps<\"Mark\"> {}\n\nexport const Mark = forwardRef<MarkProps, \"mark\">((props, ref) => {\n const [styles, mergedProps] = useComponentStyle(\"Mark\", props)\n const { className, ...rest } = omitThemeProps(mergedProps)\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n whiteSpace: \"nowrap\",\n ...styles,\n }\n\n return (\n <ui.mark\n ref={ref}\n className={cx(\"ui-mark\", className)}\n __css={css}\n {...rest}\n />\n )\n})\n\nMark.displayName = \"Mark\"\nMark.__ui__ = \"Mark\"\n"],"mappings":";;;AAGA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY;AACrB,SAAS,IAAI,eAAe;AAC5B,SAAS,UAAU,eAAe;AA2FxB;AA/EV,IAAM,eAAe,CAAC,SACpB,KAAK,QAAQ,wBAAwB,CAAC,SAAiB,KAAK,IAAI,EAAE;AAEpE,IAAM,aAAa,CAAC,UAAwC;AAC1D,UAAQ,MAAM,OAAO,OAAO,EAAE,IAAI,CAAC,SAAS,aAAa,KAAK,KAAK,CAAC,CAAC;AAErE,MAAI,MAAM,OAAQ,QAAO,IAAI,OAAO,I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eAAe,WAAW;AAEzD,QAAM,MAAmB;AAAA,IACvB,IAAI;AAAA,IACJ,YAAY;AAAA,IACZ,GAAG;AAAA,EACL;AAEA,SACE;AAAA,IAAC,GAAG;AAAA,IAAH;AAAA,MACC;AAAA,MACA,WAAW,GAAG,WAAW,SAAS;AAAA,MAClC,OAAO;AAAA,MACN,GAAG;AAAA;AAAA,EACN;AAEJ,CAAC;AAED,KAAK,cAAc;AACnB,KAAK,SAAS;","names":["text"]}
|
package/dist/highlight.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
2
|
-
import {
|
2
|
+
import { HTMLUIProps, ThemeProps, FC } from '@yamada-ui/core';
|
3
3
|
import { TextProps } from '@yamada-ui/typography';
|
4
4
|
import { ReactNode } from 'react';
|
5
5
|
|
@@ -26,6 +26,14 @@ interface HighlightProps extends Omit<TextProps, "children"> {
|
|
26
26
|
*
|
27
27
|
* @default false
|
28
28
|
*/
|
29
|
+
fragment?: boolean;
|
30
|
+
/**
|
31
|
+
* If `true`, `Fragment` is used for rendering.
|
32
|
+
*
|
33
|
+
* @default false
|
34
|
+
*
|
35
|
+
* @deprecated Use `fragment` instead.
|
36
|
+
*/
|
29
37
|
isFragment?: boolean;
|
30
38
|
/**
|
31
39
|
* Properties passed to the Mark component which is used to highlight the matched terms.
|
package/dist/highlight.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
2
|
-
import {
|
2
|
+
import { HTMLUIProps, ThemeProps, FC } from '@yamada-ui/core';
|
3
3
|
import { TextProps } from '@yamada-ui/typography';
|
4
4
|
import { ReactNode } from 'react';
|
5
5
|
|
@@ -26,6 +26,14 @@ interface HighlightProps extends Omit<TextProps, "children"> {
|
|
26
26
|
*
|
27
27
|
* @default false
|
28
28
|
*/
|
29
|
+
fragment?: boolean;
|
30
|
+
/**
|
31
|
+
* If `true`, `Fragment` is used for rendering.
|
32
|
+
*
|
33
|
+
* @default false
|
34
|
+
*
|
35
|
+
* @deprecated Use `fragment` instead.
|
36
|
+
*/
|
29
37
|
isFragment?: boolean;
|
30
38
|
/**
|
31
39
|
* Properties passed to the Mark component which is used to highlight the matched terms.
|
package/dist/highlight.js
CHANGED
@@ -44,6 +44,7 @@ var highlightWords = ({ query, text }) => {
|
|
44
44
|
var useHighlight = ({ query, text }) => (0, import_react.useMemo)(() => highlightWords({ query, text }), [text, query]);
|
45
45
|
var Highlight = ({
|
46
46
|
children: text,
|
47
|
+
fragment,
|
47
48
|
isFragment = false,
|
48
49
|
lineHeight = "tall",
|
49
50
|
query,
|
@@ -52,9 +53,10 @@ var Highlight = ({
|
|
52
53
|
}) => {
|
53
54
|
if (typeof text !== "string")
|
54
55
|
throw new Error("The children prop of Highlight must be a string");
|
56
|
+
fragment != null ? fragment : fragment = isFragment;
|
55
57
|
const chunks = useHighlight({ query, text });
|
56
|
-
const Component =
|
57
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...!
|
58
|
+
const Component = fragment ? import_react.Fragment : import_typography.Text;
|
59
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...!fragment ? { lineHeight } : {}, ...rest, children: chunks.map(
|
58
60
|
({ match, text: text2 }, i) => match ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Mark, { ...markProps, children: text2 }, i) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: text2 }, i)
|
59
61
|
) });
|
60
62
|
};
|
package/dist/highlight.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/highlight.tsx"],"sourcesContent":["import type { CSSUIObject, FC, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { TextProps } from \"@yamada-ui/typography\"\nimport type { ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentStyle,\n} from \"@yamada-ui/core\"\nimport { Text } from \"@yamada-ui/typography\"\nimport { cx, isArray } from \"@yamada-ui/utils\"\nimport { Fragment, useMemo } from \"react\"\n\ninterface Options {\n query: string | string[]\n text: string\n}\n\ninterface Chunk {\n match: boolean\n text: string\n}\n\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`)\n\nconst buildRegex = (query: string[]): RegExp | undefined => {\n query = query.filter(Boolean).map((text) => escapeRegexp(text.trim()))\n\n if (query.length) return new RegExp(`(${query.join(\"|\")})`, \"ig\")\n}\n\nconst highlightWords = ({ query, text }: Options): Chunk[] => {\n const regex = buildRegex(isArray(query) ? query : [query])\n\n if (!regex) return [{ match: false, text }]\n\n return text\n .split(regex)\n .filter(Boolean)\n .map((text) => ({ match: regex.test(text), text }))\n}\n\nexport const useHighlight = ({ query, text }: Options): Chunk[] =>\n useMemo(() => highlightWords({ query, text }), [text, query])\n\nexport interface HighlightProps extends Omit<TextProps, \"children\"> {\n /**\n * Accepts a string or a function. If it's a function, it should return a `ReactNode` and accept an array of `Chunk` objects as its argument.\n */\n children: ((props: Chunk[]) => ReactNode) | string\n /**\n * Can be a single string or an array of strings. These are the terms that are highlighted in the text.\n */\n query: string | string[]\n /**\n * If `true`, `Fragment` is used for rendering.\n *\n * @default false\n */\n isFragment?: boolean\n /**\n * Properties passed to the Mark component which is used to highlight the matched terms.\n */\n markProps?: MarkProps\n}\n\n/**\n * `Highlight` is a component that highlights specified strings within text. By default, it renders a `p` element.\n *\n * @see Docs https://yamada-ui.com/components/typography/highlight\n */\nexport const Highlight: FC<HighlightProps> = ({\n children: text,\n isFragment = false,\n lineHeight = \"tall\",\n query,\n markProps,\n ...rest\n}) => {\n if (typeof text !== \"string\")\n throw new Error(\"The children prop of Highlight must be a string\")\n\n const chunks = useHighlight({ query, text })\n\n const Component: FC =
|
1
|
+
{"version":3,"sources":["../src/highlight.tsx"],"sourcesContent":["import type { CSSUIObject, FC, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { TextProps } from \"@yamada-ui/typography\"\nimport type { ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentStyle,\n} from \"@yamada-ui/core\"\nimport { Text } from \"@yamada-ui/typography\"\nimport { cx, isArray } from \"@yamada-ui/utils\"\nimport { Fragment, useMemo } from \"react\"\n\ninterface Options {\n query: string | string[]\n text: string\n}\n\ninterface Chunk {\n match: boolean\n text: string\n}\n\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`)\n\nconst buildRegex = (query: string[]): RegExp | undefined => {\n query = query.filter(Boolean).map((text) => escapeRegexp(text.trim()))\n\n if (query.length) return new RegExp(`(${query.join(\"|\")})`, \"ig\")\n}\n\nconst highlightWords = ({ query, text }: Options): Chunk[] => {\n const regex = buildRegex(isArray(query) ? query : [query])\n\n if (!regex) return [{ match: false, text }]\n\n return text\n .split(regex)\n .filter(Boolean)\n .map((text) => ({ match: regex.test(text), text }))\n}\n\nexport const useHighlight = ({ query, text }: Options): Chunk[] =>\n useMemo(() => highlightWords({ query, text }), [text, query])\n\nexport interface HighlightProps extends Omit<TextProps, \"children\"> {\n /**\n * Accepts a string or a function. If it's a function, it should return a `ReactNode` and accept an array of `Chunk` objects as its argument.\n */\n children: ((props: Chunk[]) => ReactNode) | string\n /**\n * Can be a single string or an array of strings. These are the terms that are highlighted in the text.\n */\n query: string | string[]\n /**\n * If `true`, `Fragment` is used for rendering.\n *\n * @default false\n */\n fragment?: boolean\n /**\n * If `true`, `Fragment` is used for rendering.\n *\n * @default false\n *\n * @deprecated Use `fragment` instead.\n */\n isFragment?: boolean\n /**\n * Properties passed to the Mark component which is used to highlight the matched terms.\n */\n markProps?: MarkProps\n}\n\n/**\n * `Highlight` is a component that highlights specified strings within text. By default, it renders a `p` element.\n *\n * @see Docs https://yamada-ui.com/components/typography/highlight\n */\nexport const Highlight: FC<HighlightProps> = ({\n children: text,\n fragment,\n isFragment = false,\n lineHeight = \"tall\",\n query,\n markProps,\n ...rest\n}) => {\n if (typeof text !== \"string\")\n throw new Error(\"The children prop of Highlight must be a string\")\n\n fragment ??= isFragment\n\n const chunks = useHighlight({ query, text })\n\n const Component: FC = fragment ? Fragment : Text\n\n return (\n <Component {...(!fragment ? { lineHeight } : {})} {...rest}>\n {chunks.map(({ match, text }, i) =>\n match ? (\n <Mark key={i} {...markProps}>\n {text}\n </Mark>\n ) : (\n <Fragment key={i}>{text}</Fragment>\n ),\n )}\n </Component>\n )\n}\n\nHighlight.displayName = \"Highlight\"\nHighlight.__ui__ = \"Highlight\"\n\nexport interface MarkProps extends HTMLUIProps<\"mark\">, ThemeProps<\"Mark\"> {}\n\nexport const Mark = forwardRef<MarkProps, \"mark\">((props, ref) => {\n const [styles, mergedProps] = useComponentStyle(\"Mark\", props)\n const { className, ...rest } = omitThemeProps(mergedProps)\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n whiteSpace: \"nowrap\",\n ...styles,\n }\n\n return (\n <ui.mark\n ref={ref}\n className={cx(\"ui-mark\", className)}\n __css={css}\n {...rest}\n />\n )\n})\n\nMark.displayName = \"Mark\"\nMark.__ui__ = \"Mark\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAKO;AACP,wBAAqB;AACrB,mBAA4B;AAC5B,mBAAkC;AA2FxB;AA/EV,IAAM,eAAe,CAAC,SACpB,KAAK,QAAQ,wBAAwB,CAAC,SAAiB,KAAK,IAAI,EAAE;AAEpE,IAAM,aAAa,CAAC,UAAwC;AAC1D,UAAQ,MAAM,OAAO,OAAO,EAAE,IAAI,CAAC,SAAS,aAAa,KAAK,KAAK,CAAC,CAAC;AAErE,MAAI,MAAM,OAAQ,QAAO,IAAI,OAAO,IAAI,MAAM,KAAK,GAAG,CAAC,KAAK,IAAI;AAClE;AAEA,IAAM,iBAAiB,CAAC,EAAE,OAAO,KAAK,MAAwB;A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EACL;AAEA,SACE;AAAA,IAAC,eAAG;AAAA,IAAH;AAAA,MACC;AAAA,MACA,eAAW,iBAAG,WAAW,SAAS;AAAA,MAClC,OAAO;AAAA,MACN,GAAG;AAAA;AAAA,EACN;AAEJ,CAAC;AAED,KAAK,cAAc;AACnB,KAAK,SAAS;","names":["text"]}
|
package/dist/highlight.mjs
CHANGED
package/dist/index.js
CHANGED
@@ -46,6 +46,7 @@ var highlightWords = ({ query, text }) => {
|
|
46
46
|
var useHighlight = ({ query, text }) => (0, import_react.useMemo)(() => highlightWords({ query, text }), [text, query]);
|
47
47
|
var Highlight = ({
|
48
48
|
children: text,
|
49
|
+
fragment,
|
49
50
|
isFragment = false,
|
50
51
|
lineHeight = "tall",
|
51
52
|
query,
|
@@ -54,9 +55,10 @@ var Highlight = ({
|
|
54
55
|
}) => {
|
55
56
|
if (typeof text !== "string")
|
56
57
|
throw new Error("The children prop of Highlight must be a string");
|
58
|
+
fragment != null ? fragment : fragment = isFragment;
|
57
59
|
const chunks = useHighlight({ query, text });
|
58
|
-
const Component =
|
59
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...!
|
60
|
+
const Component = fragment ? import_react.Fragment : import_typography.Text;
|
61
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...!fragment ? { lineHeight } : {}, ...rest, children: chunks.map(
|
60
62
|
({ match, text: text2 }, i) => match ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Mark, { ...markProps, children: text2 }, i) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: text2 }, i)
|
61
63
|
) });
|
62
64
|
};
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/highlight.tsx"],"sourcesContent":["export { Highlight, Mark, useHighlight } from \"./highlight\"\nexport type { HighlightProps, MarkProps } from \"./highlight\"\n","import type { CSSUIObject, FC, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { TextProps } from \"@yamada-ui/typography\"\nimport type { ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentStyle,\n} from \"@yamada-ui/core\"\nimport { Text } from \"@yamada-ui/typography\"\nimport { cx, isArray } from \"@yamada-ui/utils\"\nimport { Fragment, useMemo } from \"react\"\n\ninterface Options {\n query: string | string[]\n text: string\n}\n\ninterface Chunk {\n match: boolean\n text: string\n}\n\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`)\n\nconst buildRegex = (query: string[]): RegExp | undefined => {\n query = query.filter(Boolean).map((text) => escapeRegexp(text.trim()))\n\n if (query.length) return new RegExp(`(${query.join(\"|\")})`, \"ig\")\n}\n\nconst highlightWords = ({ query, text }: Options): Chunk[] => {\n const regex = buildRegex(isArray(query) ? query : [query])\n\n if (!regex) return [{ match: false, text }]\n\n return text\n .split(regex)\n .filter(Boolean)\n .map((text) => ({ match: regex.test(text), text }))\n}\n\nexport const useHighlight = ({ query, text }: Options): Chunk[] =>\n useMemo(() => highlightWords({ query, text }), [text, query])\n\nexport interface HighlightProps extends Omit<TextProps, \"children\"> {\n /**\n * Accepts a string or a function. If it's a function, it should return a `ReactNode` and accept an array of `Chunk` objects as its argument.\n */\n children: ((props: Chunk[]) => ReactNode) | string\n /**\n * Can be a single string or an array of strings. These are the terms that are highlighted in the text.\n */\n query: string | string[]\n /**\n * If `true`, `Fragment` is used for rendering.\n *\n * @default false\n */\n isFragment?: boolean\n /**\n * Properties passed to the Mark component which is used to highlight the matched terms.\n */\n markProps?: MarkProps\n}\n\n/**\n * `Highlight` is a component that highlights specified strings within text. By default, it renders a `p` element.\n *\n * @see Docs https://yamada-ui.com/components/typography/highlight\n */\nexport const Highlight: FC<HighlightProps> = ({\n children: text,\n isFragment = false,\n lineHeight = \"tall\",\n query,\n markProps,\n ...rest\n}) => {\n if (typeof text !== \"string\")\n throw new Error(\"The children prop of Highlight must be a string\")\n\n const chunks = useHighlight({ query, text })\n\n const Component: FC =
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/highlight.tsx"],"sourcesContent":["export { Highlight, Mark, useHighlight } from \"./highlight\"\nexport type { HighlightProps, MarkProps } from \"./highlight\"\n","import type { CSSUIObject, FC, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { TextProps } from \"@yamada-ui/typography\"\nimport type { ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentStyle,\n} from \"@yamada-ui/core\"\nimport { Text } from \"@yamada-ui/typography\"\nimport { cx, isArray } from \"@yamada-ui/utils\"\nimport { Fragment, useMemo } from \"react\"\n\ninterface Options {\n query: string | string[]\n text: string\n}\n\ninterface Chunk {\n match: boolean\n text: string\n}\n\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`)\n\nconst buildRegex = (query: string[]): RegExp | undefined => {\n query = query.filter(Boolean).map((text) => escapeRegexp(text.trim()))\n\n if (query.length) return new RegExp(`(${query.join(\"|\")})`, \"ig\")\n}\n\nconst highlightWords = ({ query, text }: Options): Chunk[] => {\n const regex = buildRegex(isArray(query) ? query : [query])\n\n if (!regex) return [{ match: false, text }]\n\n return text\n .split(regex)\n .filter(Boolean)\n .map((text) => ({ match: regex.test(text), text }))\n}\n\nexport const useHighlight = ({ query, text }: Options): Chunk[] =>\n useMemo(() => highlightWords({ query, text }), [text, query])\n\nexport interface HighlightProps extends Omit<TextProps, \"children\"> {\n /**\n * Accepts a string or a function. If it's a function, it should return a `ReactNode` and accept an array of `Chunk` objects as its argument.\n */\n children: ((props: Chunk[]) => ReactNode) | string\n /**\n * Can be a single string or an array of strings. These are the terms that are highlighted in the text.\n */\n query: string | string[]\n /**\n * If `true`, `Fragment` is used for rendering.\n *\n * @default false\n */\n fragment?: boolean\n /**\n * If `true`, `Fragment` is used for rendering.\n *\n * @default false\n *\n * @deprecated Use `fragment` instead.\n */\n isFragment?: boolean\n /**\n * Properties passed to the Mark component which is used to highlight the matched terms.\n */\n markProps?: MarkProps\n}\n\n/**\n * `Highlight` is a component that highlights specified strings within text. By default, it renders a `p` element.\n *\n * @see Docs https://yamada-ui.com/components/typography/highlight\n */\nexport const Highlight: FC<HighlightProps> = ({\n children: text,\n fragment,\n isFragment = false,\n lineHeight = \"tall\",\n query,\n markProps,\n ...rest\n}) => {\n if (typeof text !== \"string\")\n throw new Error(\"The children prop of Highlight must be a string\")\n\n fragment ??= isFragment\n\n const chunks = useHighlight({ query, text })\n\n const Component: FC = fragment ? Fragment : Text\n\n return (\n <Component {...(!fragment ? { lineHeight } : {})} {...rest}>\n {chunks.map(({ match, text }, i) =>\n match ? (\n <Mark key={i} {...markProps}>\n {text}\n </Mark>\n ) : (\n <Fragment key={i}>{text}</Fragment>\n ),\n )}\n </Component>\n )\n}\n\nHighlight.displayName = \"Highlight\"\nHighlight.__ui__ = \"Highlight\"\n\nexport interface MarkProps extends HTMLUIProps<\"mark\">, ThemeProps<\"Mark\"> {}\n\nexport const Mark = forwardRef<MarkProps, \"mark\">((props, ref) => {\n const [styles, mergedProps] = useComponentStyle(\"Mark\", props)\n const { className, ...rest } = omitThemeProps(mergedProps)\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n whiteSpace: \"nowrap\",\n ...styles,\n }\n\n return (\n <ui.mark\n ref={ref}\n className={cx(\"ui-mark\", className)}\n __css={css}\n {...rest}\n />\n )\n})\n\nMark.displayName = \"Mark\"\nMark.__ui__ = \"Mark\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,kBAKO;AACP,wBAAqB;AACrB,mBAA4B;AAC5B,mBAAkC;AA2FxB;AA/EV,IAAM,eAAe,CAAC,SACpB,KAAK,QAAQ,wBAAwB,CAAC,SAAiB,KAAK,IAAI,EAAE;AAEpE,IAAM,aAAa,CAAC,UAAwC;AAC1D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,wBAA8B,CAAC,OAAO,QAAQ;AAChE,QAAM,CAAC,QAAQ,WAAW,QAAI,+BAAkB,QAAQ,KAAK;AAC7D,QAAM,EAAE,WAAW,GAAG,KAAK,QAAI,4BAAe,WAAW;AAEzD,QAAM,MAAmB;AAAA,IACvB,IAAI;AAAA,IACJ,YAAY;AAAA,IACZ,GAAG;AAAA,EACL;AAEA,SACE;AAAA,IAAC,eAAG;AAAA,IAAH;AAAA,MACC;AAAA,MACA,eAAW,iBAAG,WAAW,SAAS;AAAA,MAClC,OAAO;AAAA,MACN,GAAG;AAAA;AAAA,EACN;AAEJ,CAAC;AAED,KAAK,cAAc;AACnB,KAAK,SAAS;","names":["text"]}
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/highlight.tsx"],"sourcesContent":["import type { CSSUIObject, FC, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { TextProps } from \"@yamada-ui/typography\"\nimport type { ReactNode } from \"react\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentStyle,\n} from \"@yamada-ui/core\"\nimport { Text } from \"@yamada-ui/typography\"\nimport { cx, isArray } from \"@yamada-ui/utils\"\nimport { Fragment, useMemo } from \"react\"\n\ninterface Options {\n query: string | string[]\n text: string\n}\n\ninterface Chunk {\n match: boolean\n text: string\n}\n\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`)\n\nconst buildRegex = (query: string[]): RegExp | undefined => {\n query = query.filter(Boolean).map((text) => escapeRegexp(text.trim()))\n\n if (query.length) return new RegExp(`(${query.join(\"|\")})`, \"ig\")\n}\n\nconst highlightWords = ({ query, text }: Options): Chunk[] => {\n const regex = buildRegex(isArray(query) ? query : [query])\n\n if (!regex) return [{ match: false, text }]\n\n return text\n .split(regex)\n .filter(Boolean)\n .map((text) => ({ match: regex.test(text), text }))\n}\n\nexport const useHighlight = ({ query, text }: Options): Chunk[] =>\n useMemo(() => highlightWords({ query, text }), [text, query])\n\nexport interface HighlightProps extends Omit<TextProps, \"children\"> {\n /**\n * Accepts a string or a function. If it's a function, it should return a `ReactNode` and accept an array of `Chunk` objects as its argument.\n */\n children: ((props: Chunk[]) => ReactNode) | string\n /**\n * Can be a single string or an array of strings. These are the terms that are highlighted in the text.\n */\n query: string | string[]\n /**\n * If `true`, `Fragment` is used for rendering.\n *\n * @default false\n */\n isFragment?: boolean\n /**\n * Properties passed to the Mark component which is used to highlight the matched terms.\n */\n markProps?: MarkProps\n}\n\n/**\n * `Highlight` is a component that highlights specified strings within text. By default, it renders a `p` element.\n *\n * @see Docs https://yamada-ui.com/components/typography/highlight\n */\nexport const Highlight: FC<HighlightProps> = ({\n children: text,\n isFragment = false,\n lineHeight = \"tall\",\n query,\n markProps,\n ...rest\n}) => {\n if (typeof text !== \"string\")\n throw new Error(\"The children prop of Highlight must be a string\")\n\n const chunks = useHighlight({ query, text })\n\n const Component: FC = isFragment ? Fragment : Text\n\n return (\n <Component {...(!isFragment ? { lineHeight } : {})} {...rest}>\n {chunks.map(({ match, text }, i) =>\n match ? (\n <Mark key={i} {...markProps}>\n {text}\n </Mark>\n ) : (\n <Fragment key={i}>{text}</Fragment>\n ),\n )}\n </Component>\n )\n}\n\nHighlight.displayName = \"Highlight\"\nHighlight.__ui__ = \"Highlight\"\n\nexport interface MarkProps extends HTMLUIProps<\"mark\">, ThemeProps<\"Mark\"> {}\n\nexport const Mark = forwardRef<MarkProps, \"mark\">((props, ref) => {\n const [styles, mergedProps] = useComponentStyle(\"Mark\", props)\n const { className, ...rest } = omitThemeProps(mergedProps)\n\n const css: CSSUIObject = {\n bg: \"transparent\",\n whiteSpace: \"nowrap\",\n ...styles,\n }\n\n return (\n <ui.mark\n ref={ref}\n className={cx(\"ui-mark\", className)}\n __css={css}\n {...rest}\n />\n )\n})\n\nMark.displayName = \"Mark\"\nMark.__ui__ = \"Mark\"\n"],"mappings":";;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