Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Commit

Permalink
Refactoring presets (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
osequi committed Dec 12, 2020
1 parent fa14260 commit 4b33a43
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 162 deletions.
23 changes: 16 additions & 7 deletions src/theme/decorations/borders.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
export type TBorderPresetNames = "default";
import type { TPreset, TStyle } from "../";

export type TBorder = {
preset?: TBorderPresetNames;
borderStyle?: string;
borderWidth?: string;
preset?: TPreset;
styles?: TStyle[];
};

const defaultBorder: TBorder = {
preset: "default",
borderStyle: "solid",
borderWidth: "1px",
preset: {
type: "border",
name: "default",
},
styles: [
{
state: "default",
css: {
borderStyle: "solid",
borderWidth: "1px",
},
},
],
};

const borders: TBorder[] = [defaultBorder];
Expand Down
16 changes: 0 additions & 16 deletions src/theme/decorations/button.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/theme/decorations/buttons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { TPreset, TStyle } from "../";

export type TButton = {
preset?: TPreset;
styles?: TStyle[];
};

const defaultButton: TButton = {
preset: {
type: "button",
name: "default",
},
styles: [
{
state: "default",
presets: [
{
type: "border",
name: "default",
},
],
},
],
};

const buttons: TButton[] = [defaultButton];

export default buttons;
29 changes: 9 additions & 20 deletions src/theme/decorations/decorations.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
import type { TBorder, TBorderPresetNames } from "./borders";
import type { TBorder } from "./borders";
import { default as borders } from "./borders";

import type { TPatternify, TPatternifyPresetNames } from "./patternify";
import { default as patternify } from "./patternify";
import type { TButton } from "./buttons";
import { default as buttons } from "./buttons";

import type { TLinkStyle } from "./link";
import { default as linkStyles } from "./link";

/**
* // NOTE: Experimental
* Tries to achieve something like `useDecoration('link', 'default')` and `useDecoration('borders', 'heavy')`
* However link styling is so complex it needs a special hook `useLinkStyle` to put together the styles.
* For simple styling it works for now.
*/
export type TDecoration = {
type?: "borders" | "patternify";
preset?: TBorderPresetNames & TPatternifyPresetNames;
};
import type { TLink } from "./links";
import { default as links } from "./links";

export type TDecorations = {
borders?: TBorder[];
patternify?: TPatternify[];
links?: TLinkStyle[];
links?: TLink[];
buttons?: TButton[];
};

const decorations: TDecorations = {
borders: borders,
patternify: patternify,
links: linkStyles,
links: links,
buttons: buttons,
};

export default decorations;
17 changes: 10 additions & 7 deletions src/theme/decorations/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export type { TDecorations, TDecoration } from "./decorations";
export { default as decorations } from "./decorations";
export type { TBorder } from "./borders";
export { default as borders } from "./borders";

export type { TButton } from "./buttons";
export { default as buttons } from "./buttons";

export type {
TLinkStylePresetNames,
TLinkStyle,
TLinkTypePresetNames,
} from "./link";
export type { TLink } from "./links";
export { default as links } from "./links";

export type { TDecorations } from "./decorations";
export { default as decorations } from "./decorations";
81 changes: 0 additions & 81 deletions src/theme/decorations/link.ts

This file was deleted.

67 changes: 67 additions & 0 deletions src/theme/decorations/links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type { TPreset, TStyle } from "../";

export type TLink = {
preset?: TPreset;
styles?: TStyle[];
};

/**
* Defines the default link style.
*/
const defaultLink: TLink = {
preset: {
type: "link",
name: "default",
},
styles: [
{
state: "default",
presets: [
{
type: "colorPair",
name: "default",
},
],
css: {
textDecoration: "underline",
},
},
{
state: "active",
presets: [
{
type: "colorPair",
name: "inverted",
},
],
css: {
textDecoration: "line-through",
},
},
{
state: "visited",
presets: [
{
type: "colorPair",
name: "default",
},
],
css: {
textDecorationColor: "red",
},
},
{
state: "hidden",
css: {
display: "none",
},
},
],
};

/**
* Defines the available link styles.
*/
const links: TLink[] = [defaultLink];

export default links;
16 changes: 0 additions & 16 deletions src/theme/decorations/patternify.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ export type {
THeadingsSettings,
TSpacingPresetNames,
THeadingsPresetNames,
TLinkStylePresetNames,
TLinkStyle,
TColorPair,
TColorPairNames,
TLinkTypePresetNames,
TDecorations,
TDecoration,
TState,
TPreset,
TStyle,
Expand Down
12 changes: 1 addition & 11 deletions src/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ import type {
} from "./colors";
import { colors, colorPairs } from "./colors";

import type {
TDecorations,
TDecoration,
TLinkStylePresetNames,
TLinkStyle,
TLinkTypePresetNames,
} from "./decorations";
import type { TDecorations } from "./decorations";
import { decorations } from "./decorations";

/**
Expand Down Expand Up @@ -194,11 +188,7 @@ export type {
THeadings,
THeadingsSettings,
THeadingsPresetNames,
TLinkStylePresetNames,
TLinkStyle,
TColorPair,
TColorPairNames,
TLinkTypePresetNames,
TDecorations,
TDecoration,
};

0 comments on commit 4b33a43

Please sign in to comment.