Skip to content

Commit b74e983

Browse files
author
Haider Alshamma
committed
fix: remove double props occurrence on the Heading
1 parent 390085e commit b74e983

File tree

3 files changed

+20
-37
lines changed

3 files changed

+20
-37
lines changed

src/Type/Headings.story.tsx

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
import React from "react";
22
import { Text, Heading1, Heading2, Heading3, Heading4, StatusIndicator } from "../index";
3+
import { Flex } from "../Flex";
34

45
export default {
56
title: "Components/Headings",
67
};
78

8-
export const _Heading1 = () => <Heading1>Heading 1</Heading1>;
9-
10-
_Heading1.story = {
11-
name: "Heading1",
12-
};
13-
14-
export const _Heading2 = () => <Heading2>Heading 2</Heading2>;
15-
16-
_Heading2.story = {
17-
name: "Heading2",
18-
};
19-
20-
export const _Heading3 = () => <Heading3>Heading 3</Heading3>;
21-
22-
_Heading3.story = {
23-
name: "Heading3",
24-
};
25-
26-
export const _Heading4 = () => <Heading4>Heading 4</Heading4>;
27-
28-
_Heading4.story = {
29-
name: "Heading4",
30-
};
9+
export const Headings = () => (
10+
<Flex flexDirection="column">
11+
<Heading1>Heading 1</Heading1>
12+
<Heading2>Heading 2</Heading2>
13+
<Heading3>Heading 3</Heading3>
14+
<Heading4>Heading 4</Heading4>
15+
</Flex>
16+
);
3117

3218
export const WithACustomMargin = () => (
3319
<>

src/Type/Headings.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import styled from "styled-components";
22
import { addStyledProps } from "../StyledProps";
3-
import Text from "./Text";
3+
import Text, { TextProps } from "./Text";
44

5-
export const Heading1 = styled(Text).attrs((props) => ({
5+
export const Heading1 = styled(Text).attrs(() => ({
66
as: "h1",
7-
...props,
8-
}))(
7+
}))<TextProps>(
98
({ theme }) => ({
109
fontSize: theme.fontSizes.heading1,
1110
lineHeight: theme.lineHeights.heading1,
@@ -16,9 +15,8 @@ export const Heading1 = styled(Text).attrs((props) => ({
1615
addStyledProps
1716
);
1817

19-
export const Heading2 = styled(Text).attrs((props) => ({
18+
export const Heading2 = styled(Text).attrs(() => ({
2019
as: "h2",
21-
...props,
2220
}))(
2321
({ theme }) => ({
2422
fontSize: theme.fontSizes.heading2,
@@ -30,9 +28,8 @@ export const Heading2 = styled(Text).attrs((props) => ({
3028
addStyledProps
3129
);
3230

33-
export const Heading3 = styled(Text).attrs((props) => ({
34-
as: "h3",
35-
...props,
31+
export const Heading3 = styled(Text).attrs(() => ({
32+
as: "h4",
3633
}))(
3734
({ theme }) => ({
3835
fontSize: theme.fontSizes.heading3,
@@ -44,9 +41,8 @@ export const Heading3 = styled(Text).attrs((props) => ({
4441
addStyledProps
4542
);
4643

47-
export const Heading4 = styled(Text).attrs((props) => ({
44+
export const Heading4 = styled(Text).attrs(() => ({
4845
as: "h4",
49-
...props,
5046
}))(
5147
({ theme }) => ({
5248
fontSize: theme.fontSizes.heading4,

src/Type/Text.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import styled, { CSSObject } from "styled-components";
22
import type { DefaultNDSThemeType } from "../theme.type";
33
import { addStyledProps, StyledProps } from "../StyledProps";
4-
const getAttrs = (inline?: boolean) => (inline ? { as: "span" } : null);
54

65
export type TextProps = React.HTMLAttributes<HTMLParagraphElement> & {
76
inline?: boolean;
@@ -22,18 +21,20 @@ export type TextProps = React.HTMLAttributes<HTMLParagraphElement> & {
2221
fontSize?: string;
2322
} & StyledProps & { theme?: DefaultNDSThemeType };
2423

25-
const Text = styled.p.attrs<TextProps>((props: TextProps) => getAttrs(props.inline))<TextProps>(
26-
({ disabled, textTransform, theme }: TextProps): CSSObject => ({
24+
const Text = styled.p<TextProps>(
25+
({ disabled, textTransform, inline, theme }): CSSObject => ({
2726
textTransform,
2827
color: "currentColor",
2928
marginTop: 0,
3029
marginBottom: 0,
3130
fontSize: theme.fontSizes.medium,
3231
lineHeight: theme.lineHeights.base,
3332
opacity: disabled ? "0.7" : undefined,
33+
display: inline ? "inline" : undefined,
3434
}),
3535
addStyledProps
3636
);
37+
3738
Text.defaultProps = {
3839
inline: false,
3940
disabled: false,

0 commit comments

Comments
 (0)