Skip to content
This repository was archived by the owner on Jul 9, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/helpers/__tests__/typography.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { fontStyle, fontWeight, textAlign } from "../typography";

it("can set the font style to normal", () => {
expect(fontStyle.normal.resolve()).toEqual({ fontStyle: "normal" });
});

it("can set the font style to italic", () => {
expect(fontStyle.italic.resolve()).toEqual({ fontStyle: "italic" });
});

it("can set the font style to oblique", () => {
expect(fontStyle.oblique.resolve()).toEqual({ fontStyle: "oblique" });
});

it("can set fontWeight rules", () => {
[
["bold", "700"],
["thin", "100"],
["heavy", "900"],
["extrabold", "800"],
["none", "normal"],
].forEach(([name, weight]) => {
expect(fontWeight[name].resolve()).toEqual({ fontWeight: weight });
});
});

it("can set text to center align", () => {
expect(textAlign.center.resolve()).toEqual({ textAlign: "center" });
});

it("can set text to left align", () => {
expect(textAlign.left.resolve()).toEqual({ textAlign: "left" });
});

it("can set text to right align", () => {
expect(textAlign.right.resolve()).toEqual({ textAlign: "right" });
});
34 changes: 34 additions & 0 deletions src/helpers/typography.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//@flow
import Style from "further";

import combine from "./util/combine";
import createHelpers from "./util/createHelpers";
import weights from "./util/modifiers/weights";

const fromValue = (name: string): { name: string, reducer: Function } => ({
reducer: () => name,
name,
});

const fontStyle = createHelpers(
{
property: "fontStyle",
style: Style.empty(),
},
["normal", "italic", "oblique"].map(fromValue),
).reduce(combine, Style.empty());

const fontWeight = createHelpers(
{ property: "fontWeight", style: Style.empty() },
weights,
).reduce(combine, Style.empty());

const textAlign = createHelpers(
{
property: "textAlign",
style: Style.empty(),
},
["auto", "left", "right", "center", "justify"].map(fromValue),
).reduce(combine, Style.empty());

export { fontStyle, fontWeight, textAlign };
12 changes: 12 additions & 0 deletions src/helpers/util/modifiers/weights.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default [
{ name: "none", reducer: () => "normal" },
{ name: "thin", reducer: () => "100" },
{ name: "extralight", reducer: () => "200" },
{ name: "light", reducer: () => "300" },
{ name: "normal", reducer: () => "400" },
{ name: "medium", reducer: () => "500" },
{ name: "semibold", reducer: () => "600" },
{ name: "bold", reducer: () => "700" },
{ name: "extrabold", reducer: () => "800" },
{ name: "heavy", reducer: () => "900" },
];