Skip to content

Commit 61351ec

Browse files
committed
Add atoms heading, heading-icon and paragraph
1 parent 5a35ed6 commit 61351ec

10 files changed

Lines changed: 270 additions & 0 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { HeadingPriority } from "../constants/heading-priority";
2+
import React from "react";
3+
import { CoreUtils } from "andculturecode-javascript-core";
4+
import { select } from "@storybook/addon-knobs";
5+
import { HeadingIcon } from "./heading-icon";
6+
import { Icons } from "../constants/icons";
7+
import { IconSizes } from "../constants/icon-sizes";
8+
9+
export default {
10+
component: HeadingIcon,
11+
title: "Atoms | Typography / HeadingIcon",
12+
};
13+
14+
export const headingIconDefault = () => (
15+
<HeadingIcon type={Icons.Plus} priority={2} iconSize={IconSizes.Base}>
16+
Voluptas Expedita Magnam
17+
</HeadingIcon>
18+
);
19+
20+
export const headingIconKnobs = () => {
21+
const priorityOptions = CoreUtils.numericEnumToPojo(HeadingPriority);
22+
23+
return (
24+
<HeadingIcon
25+
type={select("type", Icons, Icons.Plus)}
26+
priority={
27+
select(
28+
"priority",
29+
priorityOptions,
30+
HeadingPriority.One
31+
) as HeadingPriority
32+
}
33+
iconSize={select("icon size", IconSizes, IconSizes.Large)}>
34+
Voluptas Expedita Magnam
35+
</HeadingIcon>
36+
);
37+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
describe("HeadingIcon", () => {
4+
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/14", () => {});
5+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import { HeadingPriority } from "../constants/heading-priority";
3+
import { Heading } from "./heading";
4+
import { Icons } from "../constants/icons";
5+
import { IconSizes } from "../constants/icon-sizes";
6+
import { Icon } from "../icons/icon";
7+
8+
// -------------------------------------------------------------------------------------------------
9+
// #region Interfaces
10+
// -------------------------------------------------------------------------------------------------
11+
12+
export interface HeadingIconProps {
13+
children?: any;
14+
iconSize?: IconSizes;
15+
priority?: HeadingPriority;
16+
type: keyof typeof Icons;
17+
}
18+
19+
// #endregion Interfaces
20+
21+
// -------------------------------------------------------------------------------------------------
22+
// #region Component
23+
// -------------------------------------------------------------------------------------------------
24+
25+
const HeadingIcon: React.FC<HeadingIconProps> = (props: HeadingIconProps) => {
26+
return (
27+
<div className="c-heading-icon">
28+
<Icon type={props.type} size={props.iconSize} />
29+
<Heading priority={props.priority}>{props.children}</Heading>
30+
</div>
31+
);
32+
};
33+
34+
// #endregion Component
35+
36+
// -------------------------------------------------------------------------------------------------
37+
// #region Exports
38+
// -------------------------------------------------------------------------------------------------
39+
40+
export { HeadingIcon };
41+
42+
// #endregion Exports
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from "react";
2+
import Faker from "faker";
3+
import { select } from "@storybook/addon-knobs";
4+
import { HeadingPriority } from "../constants/heading-priority";
5+
import { Heading } from "./heading";
6+
import { CoreUtils } from "andculturecode-javascript-core";
7+
8+
export default {
9+
component: Heading,
10+
title: "Atoms | Typography / Heading",
11+
};
12+
13+
export const headingDefault = () => <Heading>{Faker.lorem.text()}</Heading>;
14+
15+
export const headingKnobs = () => {
16+
const options = CoreUtils.numericEnumToPojo(HeadingPriority);
17+
18+
return (
19+
<Heading
20+
priority={
21+
select(
22+
"priority",
23+
options,
24+
HeadingPriority.One
25+
) as HeadingPriority
26+
}>
27+
Voluptas Expedita Magnam
28+
</Heading>
29+
);
30+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
describe("Heading", () => {
4+
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/14", () => {});
5+
});

src/atoms/typography/heading.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from "react";
2+
import { HeadingPriority } from "../constants/heading-priority";
3+
4+
// -----------------------------------------------------------------------------------------
5+
// #region Interfaces
6+
// -----------------------------------------------------------------------------------------
7+
8+
export interface HeadingProps {
9+
children?: any;
10+
cssClassName?: string;
11+
id?: string;
12+
priority?: HeadingPriority;
13+
}
14+
15+
// #endregion Interfaces
16+
17+
// -----------------------------------------------------------------------------------------
18+
// #region Component
19+
// -----------------------------------------------------------------------------------------
20+
21+
const Heading: React.FC<HeadingProps> = (props: HeadingProps) => {
22+
let cssClassNames: Array<any> = [];
23+
24+
if (props.cssClassName) {
25+
cssClassNames.push(props.cssClassName);
26+
}
27+
28+
let componentProps = {
29+
className: cssClassNames.join(" "),
30+
};
31+
32+
return React.createElement(
33+
`h${props.priority || HeadingPriority.Two}`,
34+
componentProps,
35+
props.children
36+
);
37+
};
38+
39+
// #endregion Component
40+
41+
// -----------------------------------------------------------------------------------------
42+
// #region Exports
43+
// -----------------------------------------------------------------------------------------
44+
45+
export { Heading };
46+
47+
// #endregion Exports
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from "react";
2+
import { Paragraph, ParagraphSizes } from "./paragraph";
3+
import Faker from "faker";
4+
import { select } from "@storybook/addon-knobs";
5+
6+
export default {
7+
component: Paragraph,
8+
title: "Atoms | Typography / Paragraph",
9+
};
10+
11+
export const paragraphDefault = () => (
12+
<Paragraph>{Faker.lorem.paragraph(10)}</Paragraph>
13+
);
14+
15+
export const paragraphEmpty = () => <Paragraph></Paragraph>;
16+
17+
export const paragraphWithStyles = () => (
18+
<Paragraph cssClassName="-larger">{Faker.lorem.paragraph(4)}</Paragraph>
19+
);
20+
21+
export const paragraphKnobs = () => (
22+
<Paragraph size={select("size", ParagraphSizes, ParagraphSizes.Base)}>
23+
{Faker.lorem.paragraph(10)}
24+
</Paragraph>
25+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
describe("Paragraph", () => {
4+
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/15", () => {});
5+
});

src/atoms/typography/paragraph.tsx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, { forwardRef } from "react";
2+
3+
// -------------------------------------------------------------------------------------------------
4+
// #region Enums
5+
// -------------------------------------------------------------------------------------------------
6+
7+
export enum ParagraphSizes {
8+
XLarge = "-xlarge",
9+
Large = "-large",
10+
Base = "-base",
11+
Small = "-small",
12+
XSmall = "-xsmall",
13+
}
14+
15+
// #endregion Enums
16+
17+
// -------------------------------------------------------------------------------------------------
18+
// #region Interfaces
19+
// -------------------------------------------------------------------------------------------------
20+
21+
export interface ParagraphProps {
22+
children?: any;
23+
cssClassName?: string;
24+
dangerouslySetInnerHTML?: { __html: string };
25+
id?: string;
26+
ref?: React.RefObject<HTMLParagraphElement> | null;
27+
size?: ParagraphSizes;
28+
}
29+
30+
// #endregion Interfaces
31+
32+
// -------------------------------------------------------------------------------------------------
33+
// #region Component
34+
// -------------------------------------------------------------------------------------------------
35+
36+
const Paragraph: React.RefForwardingComponent<
37+
HTMLParagraphElement,
38+
ParagraphProps
39+
> = forwardRef(
40+
(props: ParagraphProps, ref: React.Ref<HTMLParagraphElement>) => {
41+
let cssClassNames: Array<any> = [];
42+
43+
if (props.cssClassName) {
44+
cssClassNames.push(props.cssClassName);
45+
}
46+
47+
if (props.size) {
48+
cssClassNames.push(props.size);
49+
}
50+
51+
return (
52+
<p
53+
className={cssClassNames.join(" ")}
54+
dangerouslySetInnerHTML={props.dangerouslySetInnerHTML}
55+
id={props.id}
56+
ref={ref}>
57+
{props.children}
58+
</p>
59+
);
60+
}
61+
);
62+
63+
// -------------------------------------------------------------------------------------------------
64+
// #region Exports
65+
// -------------------------------------------------------------------------------------------------
66+
67+
export { Paragraph };
68+
69+
// #endregion Exports

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export { TextArea } from "./atoms/forms/text-area";
1919
export { TextInput } from "./atoms/forms/text-input";
2020
export { TextInputIcon } from "./atoms/forms/text-input-icon";
2121

22+
// Typography
23+
export { Heading } from "./atoms/typography/heading";
24+
export { HeadingIcon } from "./atoms/typography/heading-icon";
25+
export { Paragraph } from "./atoms/typography/paragraph";
26+
2227
// #endregion Atoms
2328

2429
// -----------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)