Skip to content

Commit

Permalink
#144 separate shared component types
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonatai committed Jan 5, 2024
1 parent 734e81c commit 31cdb36
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 96 deletions.
25 changes: 6 additions & 19 deletions src/components/Feature/Feature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { Fragment } from 'react';

import { faHashtag } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { IRow, ResponsiveTable, SyntaxHighlighter } from '../shared';
import { ResponsiveTable, SyntaxHighlighter } from '../shared';
import { IMinimalFeature } from 'spock-react-types';
import { IWhereTable } from 'spock-react/components/feature-types';
import { IRow } from 'spock-react/shared/responsive-table-types';

/*
className === unique key for spec
Expand All @@ -14,23 +17,6 @@ feature.id === unique key for test
kind: GIVEN | WHEN | THEN | AND | CLEANUP | WHERE | EXPECT
*/

export interface IBlock {
kind: string;
text: string;
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
code: string[] | { [key: string]: string[] };
}

export interface IFeature {
id: string;
blocks: IBlock[];
}

interface IWhereTable {
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
data: { [key: string]: string[] };
}

// It gives you a responsive table with the where-table from the specs
const WhereTable = (props: IWhereTable): JSX.Element => {
const { data } = props;
Expand All @@ -56,7 +42,7 @@ const WhereTable = (props: IWhereTable): JSX.Element => {
return <ResponsiveTable headers={headers} rows={rows as IRow[]} />;
};

export const Feature = (props: IFeature): JSX.Element => {
export const Feature = (props: IMinimalFeature): JSX.Element => {
const { id, blocks } = props;

return (
Expand Down Expand Up @@ -96,6 +82,7 @@ export const Feature = (props: IFeature): JSX.Element => {
Object.keys(block.code).length !== 0 && (
<WhereTable
data={
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
block.code as {
[key: string]: string[];
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/Feature/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module 'spock-react/components/feature-types' {
interface IWhereTable {
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
data: { [key: string]: string[] };
}
}
7 changes: 1 addition & 6 deletions src/components/shared/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import './styles.css';
import { PropsWithChildren } from 'react';

import { OnPageNav } from './OnPageNav';
import { IFeature } from 'spock-react-types';

interface ILayout {
hasOnPageNav?: boolean;
features?: IFeature[];
}
import { ILayout } from 'spock-react/shared/layout-types';

export const Layout = (props: PropsWithChildren<ILayout>): JSX.Element => {
const { hasOnPageNav, children, features } = props;
Expand Down
9 changes: 3 additions & 6 deletions src/components/shared/Layout/OnPageNav.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { nanoid } from 'nanoid';

import { NavAnchor } from '..';
import { IFeature } from '../../Feature';

interface IOnPageNave {
features: IFeature[];
}
import { IOnPageNave } from 'spock-react/shared/layout-types';
import { IMinimalFeature } from 'spock-react-types';

export const OnPageNav = (props: IOnPageNave): JSX.Element => {
const { features } = props;
Expand All @@ -15,7 +12,7 @@ export const OnPageNav = (props: IOnPageNave): JSX.Element => {
<h4>On the Page</h4>
<nav>
<ul className="layout__list">
{features.map((feature: IFeature) => (
{features.map((feature: IMinimalFeature) => (
<NavAnchor href={feature.id} key={nanoid()}>
{feature.id}
</NavAnchor>
Expand Down
12 changes: 12 additions & 0 deletions src/components/shared/Layout/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare module 'spock-react/shared/layout-types' {
import { IFeature, IMinimalFeature } from 'spock-react-types';

export interface ILayout {
hasOnPageNav?: boolean;
features?: IFeature[];
}

interface IOnPageNave {
features: IMinimalFeature[];
}
}
5 changes: 1 addition & 4 deletions src/components/shared/LoadingSpinner/LoadingSpinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import './styles.css';

import { faSpinner } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

interface ILoadingSpinner {
isLoading: boolean;
}
import { ILoadingSpinner } from 'spock-react/shared/loading-spinner-types';

export const LoadingSpinner = (props: ILoadingSpinner): JSX.Element => {
const { isLoading } = props;
Expand Down
5 changes: 5 additions & 0 deletions src/components/shared/LoadingSpinner/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'spock-react/shared/loading-spinner-types' {
export interface ILoadingSpinner {
isLoading: boolean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import {
MdTableHeader,
MdTableRow,
SyntaxHighlighter,
} from '..';

interface IMarkdownRenderer {
children: string;
}
} from '../..';
import { IMarkdownRenderer } from 'spock-react/shared/markdown-renderer-types';

export const MarkdownRenderer = (props: IMarkdownRenderer) => {
const { children: content } = props;
Expand Down
1 change: 1 addition & 0 deletions src/components/shared/MarkdownRenderer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './MarkdownRenderer';
5 changes: 5 additions & 0 deletions src/components/shared/MarkdownRenderer/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'spock-react/shared/markdown-renderer-types' {
export interface IMarkdownRenderer {
children: string;
}
}
18 changes: 6 additions & 12 deletions src/components/shared/Message/Message.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import './styles.css';

import { ReactNode } from 'react';

import {
faCircleCheck,
faCircleInfo,
faCircleXmark,
faTriangleExclamation,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

type TLevel = 'error' | 'success' | 'info' | 'warning';

interface IErrorMessage {
headline: string;
level: TLevel;
children: ReactNode;
}
import { IErrorMessage, TLevel } from 'spock-react/shared/message-types';

export const Message = (props: IErrorMessage): JSX.Element => {
const { headline, level, children } = props;
Expand All @@ -25,15 +16,18 @@ export const Message = (props: IErrorMessage): JSX.Element => {
<div className="message">
{/* eslint-disable-next-line tailwindcss/no-custom-classname */}
<div className={`message__header message__${level}`}>
<FontAwesomeIcon icon={icon(level)} className="message__icon" />
<FontAwesomeIcon
icon={getIcon(level)}
className="message__icon"
/>
{headline}
</div>
<div className="message__content">{children}</div>
</div>
);
};

const icon = (level: TLevel) => {
const getIcon = (level: TLevel) => {
switch (level) {
case 'error':
return faCircleXmark;
Expand Down
11 changes: 11 additions & 0 deletions src/components/shared/Message/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module 'spock-react/shared/message-types' {
import { ReactNode } from 'react';

export type TLevel = 'error' | 'success' | 'info' | 'warning';

export interface IErrorMessage {
headline: string;
level: TLevel;
children: ReactNode;
}
}
10 changes: 2 additions & 8 deletions src/components/shared/NavLink/NavAnchor.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import './styles.css';

import { ReactNode } from 'react';

import { INavLink } from 'spock-react/shared/nav-link-types';
import { useActiveAnchor } from '../../../Hooks';

interface INavAnchor {
href: string;
children: string | ReactNode;
}

export const NavAnchor = (props: INavAnchor) => {
export const NavAnchor = (props: INavLink) => {
const { children: displayText, href } = props;

const { activeAnchor, setActiveAnchor } = useActiveAnchor();
Expand Down
7 changes: 1 addition & 6 deletions src/components/shared/NavLink/NavLink.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import './styles.css';

import { ReactNode } from 'react';
import { Link } from 'react-router-dom';

import { INavLink } from 'spock-react/shared/nav-link-types';
import { useActiveLink } from '../../../Hooks';

interface INavLink {
href: string;
children: string | ReactNode;
}

export const NavLink = (props: INavLink): JSX.Element => {
const { children: displayText, href } = props;

Expand Down
8 changes: 8 additions & 0 deletions src/components/shared/NavLink/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'spock-react/shared/nav-link-types' {
import { ReactNode } from 'react';

export interface INavLink {
href: string;
children: string | ReactNode;
}
}
5 changes: 1 addition & 4 deletions src/components/shared/PageTemplate/MarkdownPage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { IMarkdownPage } from 'spock-react/shared/page-template-types';
import { Layout, LoadingSpinner, MarkdownRenderer, Message } from '..';
import * as config from '../../../../environment.json';
import { useMarkdown, useScrollUp } from '../../../Hooks';

interface IMarkdownPage {
filePath: string;
}

export const MarkdownPage = (props: IMarkdownPage): JSX.Element => {
const { filePath } = props;

Expand Down
5 changes: 5 additions & 0 deletions src/components/shared/PageTemplate/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'spock-react/shared/page-template-types' {
export interface IMarkdownPage {
filePath: string;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Prism } from 'react-syntax-highlighter';
import { gruvboxDark } from 'react-syntax-highlighter/dist/esm/styles/prism';

interface ISyntaxHighlighter {
code: string;
language: string;
}
import { ISyntaxHighlighter } from 'spock-react/shared/syntax-highlighter-types';

/**
* Have no accessibility problems:
Expand Down
1 change: 1 addition & 0 deletions src/components/shared/SyntaxHighlighter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SyntaxHighlighter';
6 changes: 6 additions & 0 deletions src/components/shared/SyntaxHighlighter/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module 'spock-react/shared/syntax-highlighter-types' {
export interface ISyntaxHighlighter {
code: string;
language: string;
}
}
11 changes: 1 addition & 10 deletions src/components/shared/Tab/CustomTab.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import './styles.css';

import { ReactNode } from 'react';
import { Tab, TabList, TabPanel, useTabState } from 'reakit';

interface ITab {
content: ReactNode;
header: string;
}

interface ICustomTab {
tabConfigs: ITab[];
}
import { ICustomTab } from 'spock-react/shared/tab-types';

export const CustomTab = (props: ICustomTab) => {
const { tabConfigs } = props;
Expand Down
12 changes: 12 additions & 0 deletions src/components/shared/Tab/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare module 'spock-react/shared/tab-types' {
import { ReactNode } from 'react';

interface ITab {
content: ReactNode;
header: string;
}

export interface ICustomTab {
tabConfigs: ITab[];
}
}
11 changes: 1 addition & 10 deletions src/components/shared/Table/ResponsiveTable/ResponsiveTable.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import './styles.css';

import { nanoid } from 'nanoid';
import { ReactNode } from 'react';

export interface IRow {
row: Array<string | ReactNode>;
}

interface ITable {
headers: string[];
rows: IRow[];
}
import { ITable } from 'spock-react/shared/responsive-table-types';

export const ResponsiveTable = (props: ITable): JSX.Element => {
const { headers, rows } = props;
Expand Down
12 changes: 12 additions & 0 deletions src/components/shared/Table/ResponsiveTable/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare module 'spock-react/shared/responsive-table-types' {
import { ReactNode } from 'react';

export interface IRow {
row: Array<string | ReactNode>;
}

export interface ITable {
headers: string[];
rows: IRow[];
}
}
8 changes: 7 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ declare module 'spock-react-types' {
interface IBlock {
kind: string;
text: string;
code: string[];
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
code: string[] | { [key: string]: string[] };
}

export interface IFeature {
Expand All @@ -52,4 +53,9 @@ declare module 'spock-react-types' {
blocks: IBlock[];
problems: any[];
}

export interface IMinimalFeature {
id: string;
blocks: IBlock[];
}
}

0 comments on commit 31cdb36

Please sign in to comment.