Skip to content

Commit

Permalink
Update components
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonette committed Aug 12, 2018
1 parent d0441cb commit 726795d
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 138 deletions.
45 changes: 23 additions & 22 deletions src/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import * as React from "react";
import classNames from "classnames";

interface ItemProps {
className?: string;
href?: string;
isActive?: boolean;
// TODO: add icons
}

class BreadcrumbItem extends React.Component<ItemProps> {
render() {
const { children, href, isActive, className, ...props } = this.props;
return (
<li {...props} className={classNames(className, isActive && "is-active")}>
<a href={href} aria-current={isActive ? "page" : undefined}>
{children}
</a>
</li>
);
}
}

interface Props {
className?: string;
children?: React.ReactNode;
Expand All @@ -16,6 +36,7 @@ interface Props {
}

class Breadcrumb extends React.Component<Props> {
static Item = BreadcrumbItem;
render() {
const {
children,
Expand Down Expand Up @@ -46,7 +67,7 @@ class Breadcrumb extends React.Component<Props> {
isLarge && "is-large",
isMedium && "is-medium",
isRight && "is-right",
isSmall && "is-small"
isSmall && "is-small",
)}
aria-label="breadcrumbs"
>
Expand All @@ -56,24 +77,4 @@ class Breadcrumb extends React.Component<Props> {
}
}

interface ItemProps {
className?: string;
href?: string;
isActive?: boolean;
// TODO: add icons
}

class BreadcrumbItem extends React.Component<ItemProps> {
render() {
const { children, href, isActive, className, ...props } = this.props;
return (
<li {...props} className={classNames(className, isActive && "is-active")}>
<a href={href} aria-current={isActive ? "page" : undefined}>
{children}
</a>
</li>
);
}
}

export { Breadcrumb, BreadcrumbItem };
export { Breadcrumb };
2 changes: 1 addition & 1 deletion src/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Container extends React.Component<Props> {
className,
isFluid && "is-fluid",
isWidescreen && "is-widescreen",
isFullHD && "is-fullhd"
isFullHD && "is-fullhd",
)}
>
{children}
Expand Down
101 changes: 54 additions & 47 deletions src/Hero.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import classNames from "classnames";
import * as React from "react";

interface HeroBodyProps {
className?: string;
children?: Element | JSX.Element | string;
}

const HeroBody = ({ children, className, ...props }: HeroBodyProps) => (
<div {...props} className={classNames(className, "hero-body")}>
{children}
</div>
);

interface HeroProps {
className?: string;
children?: React.ReactNode;
Expand All @@ -17,53 +28,49 @@ interface HeroProps {
isFullHeight?: boolean;
}

const Hero = ({
children,
className,
isPrimary,
isInfo,
isSuccess,
isWarning,
isDanger,
isLight,
isDark,
isBold,
isMedium,
isLarge,
isFullHeight,
...props
}: HeroProps) => (
<section
{...props}
className={classNames(
class Hero extends React.Component<HeroProps> {
static Body = HeroBody;

render() {
const {
children,
className,
"hero",
isPrimary && "is-primary",
isInfo && "is-info",
isSuccess && "is-success",
isWarning && "is-warning",
isDanger && "is-danger",
isLight && "is-light",
isDark && "is-dark",
isBold && "is-bold",
isMedium && "is-medium",
isLarge && "is-large",
isFullHeight && "is-fullheight"
)}
>
{children}
</section>
);
isPrimary,
isInfo,
isSuccess,
isWarning,
isDanger,
isLight,
isDark,
isBold,
isMedium,
isLarge,
isFullHeight,
...props
} = this.props;

interface HeroBodyProps {
className?: string;
children?: Element | JSX.Element | string;
return (
<section
{...props}
className={classNames(
className,
"hero",
isPrimary && "is-primary",
isInfo && "is-info",
isSuccess && "is-success",
isWarning && "is-warning",
isDanger && "is-danger",
isLight && "is-light",
isDark && "is-dark",
isBold && "is-bold",
isMedium && "is-medium",
isLarge && "is-large",
isFullHeight && "is-fullheight",
)}
>
{children}
</section>
);
}
}

const HeroBody = ({ children, className, ...props }: HeroBodyProps) => (
<div {...props} className={classNames(className, "hero-body")}>
{children}
</div>
);

export { Hero, HeroBody };
export { Hero };
42 changes: 23 additions & 19 deletions src/Level.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import * as React from "react";
import classNames from "classnames";

interface Props {
className?: string;
children?: React.ReactNode;
isMobile?: boolean;
}

class Level extends React.Component<Props> {
render() {
const { children, className, isMobile, ...props } = this.props;

return (
<nav {...props} className={classNames("level", isMobile && "is-mobile", className)} aria-label="breadcrumbs">
{children && <ul>{children}</ul>}
</nav>
);
}
}

class LevelLeft extends React.Component<ItemProps> {
render() {
const { children, className, ...props } = this.props;
Expand Down Expand Up @@ -58,4 +40,26 @@ class LevelItem extends React.Component<ItemProps> {
}
}

export { Level, LevelItem, LevelLeft, LevelRight };
interface Props {
className?: string;
children?: React.ReactNode;
isMobile?: boolean;
}

class Level extends React.Component<Props> {
static Left = LevelLeft;
static Right = LevelRight;
static Item = LevelItem;

render() {
const { children, className, isMobile, ...props } = this.props;

return (
<nav {...props} className={classNames("level", isMobile && "is-mobile", className)} aria-label="breadcrumbs">
{children && <ul>{children}</ul>}
</nav>
);
}
}

export { Level };
24 changes: 17 additions & 7 deletions src/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ interface MediaProps {
children?: React.ReactNode;
}

const Media = ({ children, className, ...props }: MediaProps) => (
<article {...props} className={classNames(className, "media")}>
{children}
</article>
);

const MediaContent = ({ children, className, ...props }: MediaProps) => (
<div {...props} className={classNames(className, "media-content")}>
{children}
Expand All @@ -30,4 +24,20 @@ const MediaRight = ({ children, className, ...props }: MediaProps) => (
</div>
);

export { Media, MediaContent, MediaLeft, MediaRight };
class Media extends React.Component<MediaProps> {
static Left = MediaLeft;
static Right = MediaRight;
static Content = MediaContent;

render() {
const { children, className, ...props } = this.props;

return (
<article {...props} className={classNames(className, "media")}>
{children}
</article>
);
}
}

export { Media };
17 changes: 9 additions & 8 deletions src/__tests__/Breadcrumb.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from "react";
import { Breadcrumb, BreadcrumbItem as Item } from "../Breadcrumb";
import { create } from "react-test-renderer";

import { Breadcrumb } from "../";

describe("Breadcrumb", () => {
it("should generate an empty breadcrumb", () => {
const tree = create(<Breadcrumb />).toJSON();
Expand All @@ -11,18 +12,18 @@ describe("Breadcrumb", () => {

it("should generate a breadcrumb", () => {
const children = [
<Item key={0} href={"/home"} isActive={true}>
<Breadcrumb.Item key={0} href={"/home"} isActive={true}>
Home
</Item>,
<Item key={1} isActive={true}>
</Breadcrumb.Item>,
<Breadcrumb.Item key={1} isActive={true}>
About
</Item>
</Breadcrumb.Item>,
];

const tree = create(
<Breadcrumb hasArrowSeperator={true} className={"custom-class"} isCentered isLarge>
{children}
</Breadcrumb>
</Breadcrumb>,
).toJSON();

expect(tree).toMatchSnapshot();
Expand All @@ -32,9 +33,9 @@ describe("Breadcrumb", () => {
describe("Breadcrumb.Item", () => {
it("should generate an item", () => {
const tree = create(
<Item key={0} href={"/home"} isActive={true}>
<Breadcrumb.Item key={0} href={"/home"} isActive={true}>
Home
</Item>
</Breadcrumb.Item>,
).toJSON();

expect(tree).toMatchSnapshot();
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/Container.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as React from "react";
import { Container } from "../Container";
import { create } from "react-test-renderer";

import { Container } from "../";

describe("Container", () => {
it("should generate a container", () => {
const tree = create(
<Container isFluid isWidescreen isFullHD>
Sample container
</Container>
</Container>,
).toJSON();
expect(tree).toMatchSnapshot();
});
Expand Down
7 changes: 4 additions & 3 deletions src/__tests__/Hero.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from "react";
import { Hero, HeroBody } from "../Hero";
import { create } from "react-test-renderer";

import { Hero } from "..";

describe("Hero", () => {
it("should generate a hero", () => {
const tree = create(
Expand All @@ -19,8 +20,8 @@ describe("Hero", () => {
isFullHeight
className={"test-class"}
>
<HeroBody>Sample Website Title</HeroBody>
</Hero>
<Hero.Body>Sample Website Title</Hero.Body>
</Hero>,
).toJSON();
expect(tree).toMatchSnapshot();
});
Expand Down
Loading

0 comments on commit 726795d

Please sign in to comment.