Skip to content

Commit

Permalink
feat(typography): add text-align prop
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteen88 committed Oct 17, 2023
1 parent 88a2a81 commit d7af436
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cypress/components/typography/typography.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ context("Tests for Typography component", () => {
}
);

it.each(VARIANT_TYPES as TypographyProps["variant"][])(
"should check text-align for %s variant prop for Typography component when set",
(variant) => {
CypressMountWithProviders(
<Typography variant={variant}>{testCypress}</Typography>
);

const variantElem = getAs(String(variant));
const textDecorationLine = getDecoration(String(variant));

cy.get(variantElem).should(
"have.css",
"text-decoration-line",
textDecorationLine
);
}
);

it.each(["ol", "ul"])(
"should check as prop set to %s for List component",
(as) => {
Expand Down Expand Up @@ -282,6 +300,18 @@ context("Tests for Typography component", () => {
}
);

it.each([["left"], ["center"], ["right"], ["justify"]])(
"should adjust the text alignment when textAlign prop is set to %s",
(textAlignment) => {
CypressMountWithProviders(
<Typography variant="h1" textAlign={textAlignment}>
{testCypress}
</Typography>
);
cy.get("h1").and("have.css", "text-align", textAlignment);
}
);

it("should display as visually hidden when screenReaderOnly prop is enabled", () => {
CypressMountWithProviders(
<Typography variant="h1" screenReaderOnly>
Expand Down
4 changes: 4 additions & 0 deletions src/components/typography/typography.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export interface TypographyProps extends SpaceProps, TagProps {
whiteSpace?: string;
/** Override the word-wrap */
wordWrap?: string;
/** Override the text-align */
textAlign?: string;
/** Override the text-overflow */
textOverflow?: string;
/** Apply truncation */
Expand Down Expand Up @@ -91,6 +93,7 @@ export const Typography = ({
listStyleType,
whiteSpace,
wordWrap,
textAlign,
textOverflow,
truncate,
color = "blackOpacity90",
Expand All @@ -116,6 +119,7 @@ export const Typography = ({
listStyleType={listStyleType}
whiteSpace={whiteSpace}
wordWrap={wordWrap}
textAlign={textAlign}
textOverflow={textOverflow}
truncate={truncate}
color={color}
Expand Down
18 changes: 18 additions & 0 deletions src/components/typography/typography.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,24 @@ describe("Typography", () => {
}
);

it.each(["left", "right", "center", "justify", "initial", "inherit"])(
"applies text-align of %s",
(prop) => {
const wrapper = mount(
<ThemeProvider theme={mintTheme}>
<Typography textAlign={prop}>FooBar</Typography>
</ThemeProvider>
);

assertStyleMatch(
{
textAlign: prop,
},
wrapper.find(Typography)
);
}
);

it.each(["clip", "ellipsis", "string", "initial", "inherit"])(
"applies text-overflow of %s",
(prop) => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/typography/typography.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const StyledTypography = styled.span.attrs(
listStyleType,
whiteSpace,
wordWrap,
textAlign,
textOverflow,
truncate,
screenReaderOnly,
Expand All @@ -176,6 +177,7 @@ const StyledTypography = styled.span.attrs(
padding: 0;
white-space: ${truncate ? "nowrap" : whiteSpace};
word-wrap: ${wordWrap};
text-align: ${textAlign};
text-overflow: ${truncate ? "ellipsis" : textOverflow};
${truncate &&
css`
Expand Down

0 comments on commit d7af436

Please sign in to comment.