Skip to content

Commit bf18b76

Browse files
committed
Added Molecules LinkCard and RootPortal
1 parent 3fa0ea5 commit bf18b76

File tree

6 files changed

+167
-0
lines changed

6 files changed

+167
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export { HeadingPriority } from "./atoms/constants/heading-priority";
4040
export { IconSizes } from "./atoms/constants/icon-sizes";
4141
export { Icons } from "./atoms/constants/icons";
4242
export { InputTypes } from "./atoms/constants/input-types";
43+
export { LinkCardTypes } from "./molecules/constants/link-card-types";
4344
export { KeyboardKeys } from "./constants/keyboard-keys";
4445
export { ParagraphSizes } from "./atoms/constants/paragraph-sizes";
4546
export { SvgIcons } from "./atoms/constants/svg-icons";
@@ -65,7 +66,9 @@ export { Card } from "./molecules/cards/card";
6566
export { DropdownButton } from "./molecules/dropdown-button/dropdown-button";
6667
export { ErrorBanner } from "./molecules/errors/error-banner";
6768
export { Form } from "./molecules/forms/form";
69+
export { LinkCard } from "./molecules/link-card/link-card";
6870
export { RadioList } from "./molecules/lists/radio-list";
71+
export { RootPortal } from "./molecules/portals/root-portal";
6972
export { Tooltip } from "./molecules/tooltips/tooltip";
7073
export { UnorderedList } from "./molecules/lists/unordered-list";
7174

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum LinkCardTypes {
2+
Button = "button",
3+
Link = "link",
4+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
import { text } from "@storybook/addon-knobs";
3+
import { LinkCard } from "./link-card";
4+
import { LinkCardTypes } from "../constants/link-card-types";
5+
import { MemoryRouter } from "react-router-dom";
6+
7+
export default {
8+
component: LinkCard,
9+
title: "Molecules | Cards / Link Cards",
10+
};
11+
12+
export const linkCardButton = () => (
13+
<LinkCard to="/" label="Link Card Label" type={LinkCardTypes.Button}>
14+
{text("content", "Link Card Content")}
15+
</LinkCard>
16+
);
17+
18+
export const linkCardDefault = () => (
19+
<MemoryRouter>
20+
<LinkCard to="/" label="Link Card Label">
21+
{text("content", "Link Card Content")}
22+
</LinkCard>
23+
</MemoryRouter>
24+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
describe("LinkCard", () => {
2+
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/36", () => {});
3+
});
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React from "react";
2+
import { LinkCardTypes } from "../constants/link-card-types";
3+
import { StringUtils } from "andculturecode-javascript-core";
4+
import { Anchor } from "../../atoms/anchors/anchor";
5+
import { Button } from "../../atoms/buttons/button";
6+
import { Icon } from "../../atoms/icons/icon";
7+
import { Icons } from "../../atoms/constants/icons";
8+
import { Paragraph } from "../../atoms/typography/paragraph";
9+
import { ParagraphSizes } from "../../atoms/constants/paragraph-sizes";
10+
11+
// -------------------------------------------------------------------------------------------------
12+
// #region Contants
13+
// -------------------------------------------------------------------------------------------------
14+
15+
const COMPONENT_CLASS = "c-link-card";
16+
17+
// #endregion Constants
18+
19+
// -------------------------------------------------------------------------------------------------
20+
// #region Interfaces
21+
// -------------------------------------------------------------------------------------------------
22+
23+
export interface LinkCardProps {
24+
children: any;
25+
includeIcon?: boolean;
26+
label: string;
27+
to?: any;
28+
type?: LinkCardTypes;
29+
onClick?: () => void;
30+
}
31+
32+
// #endregion Interfaces
33+
34+
// -------------------------------------------------------------------------------------------------
35+
// #region Component
36+
// -------------------------------------------------------------------------------------------------
37+
38+
const LinkCard: React.FC<LinkCardProps> = (props: LinkCardProps) => {
39+
const cssClassNames = [COMPONENT_CLASS];
40+
if (props.includeIcon) {
41+
cssClassNames.push("-with-icon");
42+
}
43+
const cssClassNamesFlat = cssClassNames.join(" ");
44+
45+
const type = props.type ?? LinkCardTypes.Link;
46+
47+
const renderChildren = () => (
48+
<React.Fragment>
49+
{// if
50+
props.includeIcon && <Icon type={Icons.Lightbulb} />}
51+
<div className={`${COMPONENT_CLASS}__content`}>
52+
<Paragraph size={ParagraphSizes.Small}>
53+
{props.children}
54+
</Paragraph>
55+
{// if
56+
StringUtils.hasValue(props.label) && (
57+
<div className={`${COMPONENT_CLASS}__label`}>
58+
<Paragraph size={ParagraphSizes.XSmall}>
59+
{props.label}
60+
</Paragraph>
61+
</div>
62+
)}
63+
</div>
64+
</React.Fragment>
65+
);
66+
67+
return (
68+
<div>
69+
{// if
70+
type === LinkCardTypes.Button && (
71+
<Button
72+
cssClassName={cssClassNamesFlat}
73+
onClick={props.onClick}>
74+
{renderChildren()}
75+
</Button>
76+
)}
77+
{// if
78+
type === LinkCardTypes.Link && (
79+
<Anchor cssClassName={cssClassNamesFlat} to={props.to}>
80+
{renderChildren()}
81+
</Anchor>
82+
)}
83+
</div>
84+
);
85+
};
86+
87+
// #endregion Component
88+
89+
// -------------------------------------------------------------------------------------------------
90+
// #region Exports
91+
// -------------------------------------------------------------------------------------------------
92+
93+
export { LinkCard };
94+
95+
// #endregion Exports
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, { HTMLAttributes, PropsWithChildren } from "react";
2+
import ReactDOM from "react-dom";
3+
4+
// -------------------------------------------------------------------------------------------------
5+
// #region Interfaces
6+
// -------------------------------------------------------------------------------------------------
7+
8+
export interface RootPortalProps extends HTMLAttributes<HTMLDivElement> {}
9+
10+
// #endregion Interfaces
11+
12+
// -------------------------------------------------------------------------------------------------
13+
// #region Component
14+
// -------------------------------------------------------------------------------------------------
15+
16+
/**
17+
* Utility component to portal children to the root div.
18+
* @param props any HTML div attributes, and children
19+
*/
20+
const RootPortal: React.FC<PropsWithChildren<RootPortalProps>> = (
21+
props: PropsWithChildren<RootPortalProps>
22+
) => {
23+
const root = ReactDOM.findDOMNode(
24+
document.getElementById("root")
25+
) as Element;
26+
27+
return ReactDOM.createPortal(<div {...props}>{props.children}</div>, root);
28+
};
29+
30+
// #endregion Component
31+
32+
// -------------------------------------------------------------------------------------------------
33+
// #region Exports
34+
// -------------------------------------------------------------------------------------------------
35+
36+
export { RootPortal };
37+
38+
// #endregion Exports

0 commit comments

Comments
 (0)