Skip to content

Commit

Permalink
Merge pull request #1495 from skaut/default-props-arguments
Browse files Browse the repository at this point in the history
Using arguments for default props
  • Loading branch information
marekdedic authored Jun 18, 2024
2 parents 85e156d + 32c4a48 commit 0509a29
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/frontend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"react/no-unstable-nested-components": "error",
"react/prefer-stateless-function": "error",
"react/prefer-read-only-props": "error",
"react/require-default-props": "error",
"react/require-default-props": ["error", { "functions": "defaultArguments" }],
"react/sort-default-props": "error",
"react/sort-prop-types": "error",
"react/style-prop-object": "error",
Expand Down
22 changes: 8 additions & 14 deletions packages/frontend/src/components/ArticleBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import remarkGfm from "remark-gfm";
import { ColoredTag } from "./ColoredTag";
import { Article, H2, Paragraph } from "./Typography";

const emptyArray: Array<string> = [];

export const ArticleBox = ({
title,
link,
subtitle,
subtitleLink,
subtitleDescription,
link = undefined,
subtitle = undefined,
subtitleLink = undefined,
subtitleDescription = undefined,
description,
tags,
tags = emptyArray,
}: {
readonly title: string;
readonly link?: string;
Expand All @@ -36,20 +38,12 @@ export const ArticleBox = ({
<Paragraph>
<ReactMarkdown remarkPlugins={[remarkGfm]}>{description}</ReactMarkdown>
</Paragraph>
{(tags ?? []).map((tag) => (
{tags.map((tag) => (
<ColoredTag key={tag}>{tag}</ColoredTag>
))}
</ThinArticle>
);

ArticleBox.defaultProps = {
link: undefined,
subtitle: undefined,
subtitleDescription: undefined,
subtitleLink: undefined,
tags: [],
};

const ProjectName = styled("p")`
margin: 0 0 0.6em;
* {
Expand Down
14 changes: 4 additions & 10 deletions packages/frontend/src/components/ExtLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export interface LinkProps {
export const ExtLink = ({
children,
href,
title,
targetSelf,
className,
title = undefined,
targetSelf = false,
className = undefined,
}: LinkProps): React.JSX.Element => (
<a
className={className}
href={href}
title={title}
{...(targetSelf !== true
{...(!targetSelf
? {
target: "_blank",
rel: "noreferrer noopener",
Expand All @@ -34,9 +34,3 @@ export const ExtLink = ({
{children}
</a>
);

ExtLink.defaultProps = {
className: undefined,
targetSelf: false,
title: undefined,
};
8 changes: 2 additions & 6 deletions packages/frontend/src/components/Issue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ArticleBox } from "./ArticleBox";

export const Issue = ({
issue,
hideTags,
hideTags = false,
}: {
readonly issue: ProjectIssueWithProjectInfo;
readonly hideTags?: boolean;
Expand All @@ -18,11 +18,7 @@ export const Issue = ({
subtitle={issue.project.name}
subtitleDescription={issue.project["short-description"]}
subtitleLink={getProjectLink(issue.project)}
tags={hideTags !== true ? issue.project.tags : []}
tags={!hideTags ? issue.project.tags : []}
title={issue.title}
/>
);

Issue.defaultProps = {
hideTags: false,
};

0 comments on commit 0509a29

Please sign in to comment.