Skip to content

Commit

Permalink
Merge 93ffe24 into 9d0b7a8
Browse files Browse the repository at this point in the history
  • Loading branch information
heyjul3s committed Dec 29, 2020
2 parents 9d0b7a8 + 93ffe24 commit 56315a1
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 69 deletions.
4 changes: 2 additions & 2 deletions packages/artifak/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export {
createComponents
} from '@artifak/component-generator';

export { BlockBase, createBlockComponents } from '@artifak/block';
export { BlockBase, createBlocks } from '@artifak/block';
export { BlockBaseProps } from '@artifak/block';

export { FlexRow, FlexRowBase, FlexCol, FlexColBase } from '@artifak/flex';
Expand All @@ -13,7 +13,7 @@ export { Grid, GridBase, GridItem, GridItemBase } from '@artifak/grid';
export { GridBaseProps, GridItemBaseProps } from '@artifak/grid';

export {
createTypoComponents,
createTypography,
fontWeight,
TypographyBase
} from '@artifak/typography';
Expand Down
9 changes: 0 additions & 9 deletions packages/block/__mocks__/block.mock.ts

This file was deleted.

34 changes: 25 additions & 9 deletions packages/block/__tests__/block.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import { createBlockComponents } from '../src';
import { mockBlockStyles } from '../__mocks__/block.mock';
import { createBlocks } from '../src';

describe('@artifak/block', () => {
describe('createBlockComponents - generates Block React components based on styles object argument provided', () => {
describe('createBlocks - generates Block React components based on styles object argument provided', () => {
it('should return the base Typography system component when provided with an invalid argument', () => {
const expected = {};
expect(createBlockComponents({} as any)).toEqual(expected);
expect(createBlockComponents(null as any)).toEqual(expected);
expect(createBlockComponents(false as any)).toEqual(expected);
expect(createBlockComponents(0 as any)).toEqual(expected);
expect(createBlockComponents(void 0 as any)).toEqual(expected);
expect(createBlocks({} as any, {} as any)).toEqual(expected);
expect(createBlocks(null as any, null as any)).toEqual(expected);
expect(createBlocks(false as any, false as any)).toEqual(expected);
expect(createBlocks(0 as any, 0 as any)).toEqual(expected);
expect(createBlocks(void 0 as any, void 0 as any)).toEqual(expected);
});

it('should create React components', () => {
expect(createBlockComponents(mockBlockStyles)).toBeDefined();
expect(
createBlocks(
{
styles: {
display: 'block'
}
},
{
BlockPadSM: {
padding: [15]
},

BlockPadMD: {
padding: [15, 30]
}
}
)
).toBeDefined();
});
});
});
9 changes: 5 additions & 4 deletions packages/block/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockBase, createBlockComponents } from './src';
import { BlockBase, createBlocks } from './src';

export function BlockBaseUsage() {
return <BlockBase>A Block Base</BlockBase>;
Expand All @@ -23,9 +23,10 @@ const components = {
}
};

const { FlexContainer, UnpaddedContainer } = createBlockComponents<
typeof components
>(base, components);
const { FlexContainer, UnpaddedContainer } = createBlocks<typeof components>(
base,
components
);

export function CreateBlocksUsage() {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@artifak/component-generator';

/* eslint-disable @typescript-eslint/no-explicit-any */
export function createBlockComponents<
export function createBlocks<
Config,
ThemeType = any,
Props = Record<string, unknown>,
Expand Down
2 changes: 1 addition & 1 deletion packages/block/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { createBlockComponents } from './createBlockComponents';
export { createBlocks } from './createBlocks';
export { BlockBase } from './BlockBase';
export { BlockBaseProps } from './typings';
3 changes: 2 additions & 1 deletion packages/component-generator/src/createComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export function createComponents<
if (hasKey(settings, prop)) {
acc[prop] = createStyledComponent({
...base,
styles: { ...base.styles, ...setting }
styles: { ...base.styles, ...setting },
element: !!setting.as ? setting.as : base.element
} as StyledComponentConfig<Props & Variant<ThemeType>, ThemeType, HTMLAttributes<Element>>);

acc[prop].displayName = prop;
Expand Down
2 changes: 1 addition & 1 deletion packages/component-generator/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ export type GenericRecord<Dict, Type> = {
};

export type Settings = {
[key: string]: StyledSystemCSSObject & { as?: keyof JSX.IntrinsicElements };
[key: string]: StyledSystemCSSObject & { as?: string };
};
36 changes: 0 additions & 36 deletions packages/typography/__tests__/createTypoComponents.test.ts

This file was deleted.

28 changes: 28 additions & 0 deletions packages/typography/__tests__/createTypography.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { position } from 'styled-system';
import { createTypography, getStyleProps, fontWeight } from '../src';

describe('createTypography - generates typography React components based on styles object argument provided', () => {
it('should return the base Typography system component when provided with an invalid argument', () => {
expect(createTypography({} as any, {} as any)).toHaveProperty('Base');
expect(createTypography(null as any, null as any)).toHaveProperty('Base');
expect(createTypography(false as any, false as any)).toHaveProperty('Base');
expect(createTypography(0 as any, 0 as any)).toHaveProperty('Base');
expect(createTypography(void 0 as any, void 0 as any)).toHaveProperty(
'Base'
);
});

it('should create React components', () => {
expect(
createTypography(
{},
{
H1: {
marginBottom: [15],
as: 'h1'
}
}
)
).toBeDefined();
});
});
6 changes: 3 additions & 3 deletions packages/typography/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { createTypographyComponents, fluidSizing } from './src';
import { createTypography } from './src';
import styled from 'styled-components';
import { variant } from 'styled-system';

Expand All @@ -11,7 +11,7 @@ const base = {

const components = {
H1: {
fontSize: fluidSizing(48, 96, 300, 1200),
fontSize: [48, 96],
margin: '0 0 0.25em',
as: 'h1'
},
Expand Down Expand Up @@ -82,7 +82,7 @@ const {
SmallLead,
Paragraph,
SmallParagraph
} = createTypographyComponents<typeof components>(base, components);
} = createTypography<typeof components>(base, components);

const SysH1 = styled(H1)(
variant({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TypographyBaseProps } from './typings';
import { typographyStyleProps } from './TypographyBase';

/* eslint-disable @typescript-eslint/no-explicit-any */
export function createTypoComponents<
export function createTypography<
Config,
ThemeType = any,
Props = Record<string, unknown>,
Expand Down
2 changes: 1 addition & 1 deletion packages/typography/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { createTypoComponents, getStyleProps } from './createTypoComponents';
export { createTypography, getStyleProps } from './createTypography';
export { TypographyBase } from './TypographyBase';
export { fontWeight } from './fontWeight';
export { TypographyBaseProps } from './typings';

0 comments on commit 56315a1

Please sign in to comment.