Skip to content

Commit

Permalink
[V3][RL] Improve source code display
Browse files Browse the repository at this point in the history
  • Loading branch information
Quek Ruo Ling committed Oct 1, 2024
1 parent 8c3acc4 commit 60af481
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@
{
"additionalHooks": "useIsomorphicLayoutEffect"
}
],
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_"
}
]
}
}
45 changes: 24 additions & 21 deletions src/typography/typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,44 @@ import { TypographyLinkProps, TypographyProps } from "./types";
export namespace Typography {
const createHeader = (
tag: keyof JSX.IntrinsicElements,
textStyle: TypographySizeType
textStyle: TypographySizeType,
displayName: string
) => {
const Header = styled(tag).attrs<TypographyProps>(({ inline }) => ({
as: inline ? "span" : undefined,
}))<TypographyProps>`
${(props) => createTypographyStyles(textStyle, props)}
`;
Header.displayName = `Header-${textStyle}`;
Header.displayName = `Typography.${displayName}`;
return Header;
};

export const HeaderXXL = createHeader("h1", "header-xxl");
export const HeaderXL = createHeader("h2", "header-xl");
export const HeaderLG = createHeader("h3", "header-lg");
export const HeaderMD = createHeader("h4", "header-md");
export const HeaderSM = createHeader("h5", "header-sm");
export const HeaderXS = createHeader("h6", "header-xs");
export const HeaderXXL = createHeader("h1", "header-xxl", "HeaderXXL");
export const HeaderXL = createHeader("h2", "header-xl", "HeaderXL");
export const HeaderLG = createHeader("h3", "header-lg", "HeaderLG");
export const HeaderMD = createHeader("h4", "header-md", "HeaderMD");
export const HeaderSM = createHeader("h5", "header-sm", "HeaderSM");
export const HeaderXS = createHeader("h6", "header-xs", "HeaderXS");

const createBody = (textStyle: TypographySizeType) => {
const createBody = (textStyle: TypographySizeType, displayName: string) => {
const Body = styled.p.attrs<TypographyProps>(({ inline }) => ({
as: inline ? "span" : undefined,
}))<TypographyProps>`
${(props) => createTypographyStyles(textStyle, props)}
`;
Body.displayName = `Body-${textStyle}`;
Body.displayName = `Typography.${displayName}`;
return Body;
};

export const BodyBL = createBody("body-baseline");
export const BodyLG = createBody("body-lg");
export const BodyMD = createBody("body-md");
export const BodySM = createBody("body-sm");
export const BodyBL = createBody("body-baseline", "BodyBL");
export const BodyLG = createBody("body-lg", "BodyLG");
export const BodyMD = createBody("body-md", "BodyMD");
export const BodySM = createBody("body-sm", "BodySM");

const createLinkComponent = (textStyle: TypographySizeType) => {
const createLinkComponent = (
textStyle: TypographySizeType,
displayName: string
) => {
const HyperlinkBase = styled.a<TypographyLinkProps>`
${(props) => css`
${getTextStyle(textStyle, props.weight || "regular")}
Expand All @@ -66,15 +70,14 @@ export namespace Typography {
{external && <StyledExternalIcon />}
</HyperlinkBase>
);

Component.displayName = `Link-${textStyle}`;
Component.displayName = `Typography.${displayName}`;
return Component;
};

export const LinkBL = createLinkComponent("body-baseline");
export const LinkMD = createLinkComponent("body-md");
export const LinkLG = createLinkComponent("body-lg");
export const LinkSM = createLinkComponent("body-sm");
export const LinkBL = createLinkComponent("body-baseline", "LinkBL");
export const LinkMD = createLinkComponent("body-md", "LinkMD");
export const LinkLG = createLinkComponent("body-lg", "LinkLG");
export const LinkSM = createLinkComponent("body-sm", "LinkSM");
}

const StyledExternalIcon = styled(ExternalIcon)`
Expand Down
12 changes: 6 additions & 6 deletions stories/typography/typography.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const meta: Meta = {
export default meta;

export const InlineText: StoryObj = {
render: () => (
render: (_args) => (
<Typography.BodySM>
The quick brown fox{" "}
<Typography.BodyBL inline>jumps</Typography.BodyBL> over the lazy
Expand All @@ -17,7 +17,7 @@ export const InlineText: StoryObj = {
};

export const InlineLink: StoryObj = {
render: () => (
render: (_args) => (
<Typography.BodyBL>
The quick brown fox{" "}
<Typography.LinkBL href="https://www.google.com">
Expand All @@ -29,7 +29,7 @@ export const InlineLink: StoryObj = {
};

export const MixedFontWeights: StoryObj = {
render: () => (
render: (_args) => (
<Typography.BodyBL>
The{" "}
<Typography.BodyBL weight="light" inline>
Expand All @@ -47,7 +47,7 @@ export const MixedFontWeights: StoryObj = {
};

export const Paragraphs: StoryObj = {
render: () => (
render: (_args) => (
<>
<Typography.BodyBL paragraph>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi
Expand All @@ -64,7 +64,7 @@ export const Paragraphs: StoryObj = {
};

export const ExternalLink: StoryObj = {
render: () => (
render: (_args) => (
<Typography.BodyBL>
The quick brown fox{" "}
<Typography.LinkBL href="https://www.google.com" external>
Expand All @@ -84,7 +84,7 @@ export const TypographySet: StoryObj = {
),
],
tags: ["pattern"],
render: () => (
render: (_args) => (
<>
<Typography.HeaderXXL>HeaderXXL: Lorem ipsum</Typography.HeaderXXL>
<Typography.HeaderXL>HeaderXL: Lorem ipsum</Typography.HeaderXL>
Expand Down

0 comments on commit 60af481

Please sign in to comment.