mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add modification for wrapping text with ellipsis
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
99b0c8639f
commit
bbb7764103
@ -3,6 +3,7 @@ import { pipeline } from "@ogre-tools/fp";
|
|||||||
import { flexParentModification } from "./prop-modifications/flex/flex-parent";
|
import { flexParentModification } from "./prop-modifications/flex/flex-parent";
|
||||||
import { classNameModification } from "./prop-modifications/class-names/class-names";
|
import { classNameModification } from "./prop-modifications/class-names/class-names";
|
||||||
import { vanillaClassNameAdapterModification } from "./prop-modifications/class-names/vanilla-class-name-adapter";
|
import { vanillaClassNameAdapterModification } from "./prop-modifications/class-names/vanilla-class-name-adapter";
|
||||||
|
import { wordWrapModification } from "./prop-modifications/word-wrap/word-wrap";
|
||||||
|
|
||||||
export const ElementFor =
|
export const ElementFor =
|
||||||
<T extends HTMLElement, Y extends HTMLAttributes<T>>(TagName: React.ElementType) =>
|
<T extends HTMLElement, Y extends HTMLAttributes<T>>(TagName: React.ElementType) =>
|
||||||
@ -11,6 +12,7 @@ export const ElementFor =
|
|||||||
props,
|
props,
|
||||||
vanillaClassNameAdapterModification,
|
vanillaClassNameAdapterModification,
|
||||||
flexParentModification,
|
flexParentModification,
|
||||||
|
wordWrapModification,
|
||||||
classNameModification,
|
classNameModification,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Div } from "../../elements";
|
||||||
|
import { render } from "@testing-library/react";
|
||||||
|
import { discoverFor } from "@k8slens/react-testing-library-discovery";
|
||||||
|
|
||||||
|
describe("word-wrap", () => {
|
||||||
|
it("given word wrap wit, renders with class name", () => {
|
||||||
|
const rendered = render(
|
||||||
|
<Div _wordWrap _className={["some-class-name"]} data-some-element-test />,
|
||||||
|
);
|
||||||
|
|
||||||
|
const discover = discoverFor(() => rendered);
|
||||||
|
|
||||||
|
const { discovered } = discover.getSingleElement("some-element");
|
||||||
|
|
||||||
|
expect(discovered.className).toBe("overflow-hidden text-ellipsis some-class-name");
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
import type { ClassName } from "../class-names/class-names";
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface ElementProps {
|
||||||
|
_className?: ClassName;
|
||||||
|
_wordWrap?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const wordWrapModification = <T extends ElementProps>({
|
||||||
|
_wordWrap,
|
||||||
|
_className,
|
||||||
|
...props
|
||||||
|
}: T) => {
|
||||||
|
if (!_wordWrap) {
|
||||||
|
return { _className, ...props };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...props,
|
||||||
|
|
||||||
|
_className: ["overflow-hidden", "text-ellipsis", _className],
|
||||||
|
};
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user