Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(odyssey-react-mui): add overline typography variant #2349

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
26 changes: 26 additions & 0 deletions packages/odyssey-react-mui/src/Typography.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*!
* Copyright (c) 2024-present, Okta, Inc. and/or its affiliates. All rights reserved.
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import { render, screen } from "@testing-library/react";
import { Typography } from "./Typography";

describe("Typography", () => {
test("renders overline", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test("renders overline", () => {
test("renders Overline", () => {

render(
<Typography ariaLabel="overline" variant="overline">
Overline test
</Typography>,
);

expect(screen.getByLabelText("overline")).toBeVisible();
});
});
44 changes: 38 additions & 6 deletions packages/odyssey-react-mui/src/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export type TypographyVariantValue =
| "h5"
| "h6"
| "body"
| "legend"
| "overline"
| "subordinate"
| "support"
| "legend";
| "support";

export const typographyVariantMapping: Record<
TypographyVariantValue,
Expand All @@ -49,9 +50,10 @@ export const typographyVariantMapping: Record<
h5: "h5",
h6: "h6",
body: "body1",
legend: "legend",
overline: "overline",
subordinate: "subtitle1",
support: "subtitle2",
legend: "legend",
} as const;

export const typographyColorValues = [
Expand Down Expand Up @@ -102,9 +104,12 @@ const Typography = ({
}: TypographyProps) => {
const component = useMemo(() => {
if (!componentProp) {
if (variant === "body") {
return "p";
} else if (variant === "subordinate" || variant === "support") {
if (
variant === "body" ||
variant === "subordinate" ||
variant === "support" ||
variant === "overline"
) {
return "p";
} else {
return variant;
Expand Down Expand Up @@ -406,6 +411,32 @@ const Legend = ({
const MemoizedLegend = memo(Legend);
MemoizedLegend.displayName = "Legend";

const Overline = ({
ariaDescribedBy,
ariaLabel,
ariaLabelledBy,
children,
color,
component,
testId,
translate,
}: TypographyProps) => (
<Typography
ariaDescribedBy={ariaDescribedBy}
ariaLabel={ariaLabel}
ariaLabelledBy={ariaLabelledBy}
children={children}
color={color}
component={component}
testId={testId}
translate={translate}
variant="overline"
/>
);

const MemoizedOverline = memo(Overline);
MemoizedOverline.displayName = "Overline";

export {
MemoizedTypography as Typography,
MemoizedHeading1 as Heading1,
Expand All @@ -415,6 +446,7 @@ export {
MemoizedHeading5 as Heading5,
MemoizedHeading6 as Heading6,
MemoizedLegend as Legend,
MemoizedOverline as Overline,
MemoizedParagraph as Paragraph,
MemoizedSubordinate as Subordinate,
MemoizedSupport as Support,
Expand Down
13 changes: 13 additions & 0 deletions packages/odyssey-react-mui/src/theme/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3111,6 +3111,7 @@ export const components = ({
body1: "p",
inherit: "p",
legend: "legend",
overline: "p",
},
},
styleOverrides: {
Expand All @@ -3121,6 +3122,18 @@ export const components = ({
marginBlockEnd: 0,
},
},
overline: {
letterSpacing: 0.5,
textTransform: "none",

"html:lang(en) &": {
textTransform: "uppercase",
},

"html:lang(en-*) &": {
textTransform: "uppercase",
},
Copy link
Contributor

@KevinGhadyani-Okta KevinGhadyani-Okta Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this instead since we always want these to share changes?

Suggested change
"html:lang(en) &": {
textTransform: "uppercase",
},
"html:lang(en-*) &": {
textTransform: "uppercase",
},
"html:lang(en) &, html:lang(en-*) &": {
textTransform: "uppercase",
},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KevinGhadyani-Okta Strangely, this doesn't work. I had to make 2 declarations for this to work correctly. I don't know why

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to combine these selectors in quite a few ways to get it working. No luck

},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import {
Heading4,
Heading5,
Heading6,
Legend,
Overline,
Paragraph,
Subordinate,
Support,
Legend,
TypographyProps,
typographyColorValues,
typographyVariantMapping,
Expand All @@ -40,9 +41,10 @@ const variantMapping = {
h5: Heading5,
h6: Heading6,
body: Paragraph,
legend: Legend,
overline: Overline,
subordinate: Subordinate,
support: Support,
legend: Legend,
};

const storybookMeta: Meta<TypographyProps> = {
Expand Down Expand Up @@ -234,6 +236,30 @@ export const BodyStory: StoryObj<TypographyProps> = {
},
};

export const LegendStory: StoryObj<TypographyProps> = {
name: "Legend",
args: {
children: "This is a legend",
variant: "legend",
},
render: (args) => <Legend {...args} children={args.children} />,
play: async ({}) => {
await axeRun("Typopgraphy legend");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await axeRun("Typopgraphy legend");
await axeRun("Typography legend");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

},
};

export const OverlineStory: StoryObj<TypographyProps> = {
name: "Overline",
args: {
children: "This is an Overline",
variant: "overline",
},
render: (args) => <Overline {...args} children={args.children} />,
play: async ({}) => {
await axeRun("Typopgraphy Overline");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await axeRun("Typopgraphy Overline");
await axeRun("Typography Overline");

},
};

export const SubordinateStory: StoryObj<TypographyProps> = {
name: "Subordinate",
args: {
Expand All @@ -258,18 +284,6 @@ export const SupportStory: StoryObj<TypographyProps> = {
},
};

export const LegendStory: StoryObj<TypographyProps> = {
name: "Legend",
args: {
children: "This is a legend",
variant: "legend",
},
render: (args) => <Legend {...args} children={args.children} />,
play: async ({}) => {
await axeRun("Typopgraphy legend");
},
};

export const ColorStory: StoryObj<TypographyProps> = {
name: "Color",
render: ({}) => {
Expand Down