Skip to content

Commit

Permalink
feat: loads of little tweaks to get default styles and pseudos working
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Code-Monkey committed Apr 13, 2022
1 parent 3d5e28d commit d018334
Show file tree
Hide file tree
Showing 32 changed files with 152 additions and 50 deletions.
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@aw-web-design/react-feather": "3.1.5",
"@aw-web-design/styled-system": "3.1.5",
"@aw-web-design/tcm-cli": "3.1.5",
"@aw-web-design/theme": "3.1.5",
"@aw-web-design/theme": "3.1.13",
"classnames": "2.3.1",
"csstype": "3.0.11",
"memoize-one": "6.0.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/packages/atoms/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import React, {
ChangeEvent,
HTMLInputTypeAttribute,
useState,
useContext,
} from 'react';
import { ThemeContext } from 'styled-components';

import { BoxProps } from '../../primatives';
import { ITheme } from '../../utils';

import { StyledInput } from './styled';

Expand All @@ -25,6 +28,7 @@ const Input = ({
placeholder = 'Placeholder',
...rest
}: Props) => {
const theme = useContext<ITheme<unknown>>(ThemeContext);
const [v, setValue] = useState<string | number | undefined>(value);

const handleOnChange = useCallback(
Expand All @@ -42,6 +46,7 @@ const Input = ({
value={v}
type={type}
onChange={handleOnChange}
{...theme.defaultStyles.input}
{...rest}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,30 @@ exports[`<Input /> renders correctly 1`] = `
name="test"
>
<styled.input
_hover={
Object {
"bg": "blue",
}
}
border="1px solid #000"
borderRadius="6px"
cursor="pointer"
minHeight="24px"
name="test"
onChange={[Function]}
padding="6px"
placeholder="Placeholder"
type="text"
width="100%"
>
<input
className="sc-jSMfEi hHHIcy"
className="sc-jSMfEi eevSLp"
cursor="pointer"
name="test"
onChange={[Function]}
placeholder="Placeholder"
type="text"
width="100%"
/>
</styled.input>
</Input>
Expand Down
6 changes: 0 additions & 6 deletions packages/components/src/packages/atoms/input/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import styled from 'styled-components';
import { StyledBoxProps } from '../../primatives';

export const StyledInput = styled.input`
padding: ${(p) => p.theme.space[3]};
border-radius: ${(p) => p.theme.radii[2]};
border: ${(p) => p.theme.borders[1]} ${(p) => p.theme.colors.common.black};
cursor: pointer;
min-height: ${(p) => p.theme.sizes[7]};
${StyledBoxProps}
&::-webkit-calendar-picker-indicator {
Expand Down
26 changes: 15 additions & 11 deletions packages/components/src/packages/atoms/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React, { FC, useCallback, useContext, useMemo } from 'react';
import { Accessor, TableOptions, useTable } from 'react-table';
import { ThemeContext } from 'styled-components';

import { ITheme } from '../../utils';

import {
StyledTable,
StyledTHead,
Expand All @@ -18,8 +20,7 @@ export interface Props extends TableOptions<object> {
}

const Table: FC<Props> = ({ columns, data, className, onRowClick }: Props) => {
// @ts-ignore
const theme = useContext(ThemeContext);
const theme = useContext<ITheme<unknown>>(ThemeContext);
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } =
useTable({ columns, data });

Expand Down Expand Up @@ -47,20 +48,20 @@ const Table: FC<Props> = ({ columns, data, className, onRowClick }: Props) => {
return (
<StyledTable
{...tableProps}
{...theme.table?.table}
{...theme.defaultStyles.table}
className={cn(className, tableProps.className)}
>
<StyledTHead {...theme.table?.thead}>
<StyledTHead {...theme.defaultStyles.thead}>
{headerGroups.map((headerGroup) => (
<StyledTr
{...headerGroup.getHeaderGroupProps()}
{...theme.table?.tr}
{...theme.table?.trHead}
{...theme.defaultStyles.tr}
{...theme.defaultStyles.trHead}
>
{headerGroup.headers.map((column, index) => (
<StyledTh
{...column.getHeaderProps()}
{...theme.table?.th}
{...theme.defaultStyles.th}
onClick={() => handleColumnClick(columns[index].accessor)}
>
{column.render('Header')}
Expand All @@ -69,19 +70,22 @@ const Table: FC<Props> = ({ columns, data, className, onRowClick }: Props) => {
</StyledTr>
))}
</StyledTHead>
<StyledTBody {...getTableBodyProps()} {...theme.table?.tbody}>
<StyledTBody {...getTableBodyProps()} {...theme.defaultStyles.tbody}>
{rows.map((row) => {
prepareRow(row);
return (
<StyledTr
{...row.getRowProps()}
{...theme.table?.tr}
{...theme.table?.trBody}
{...theme.defaultStyles.tr}
{...theme.defaultStyles.trBody}
onClick={() => handleRowClick(row.id)}
>
{row.cells.map((cell) => {
return (
<StyledTd {...cell.getCellProps()} {...theme.table?.td}>
<StyledTd
{...cell.getCellProps()}
{...theme.defaultStyles.td}
>
{cell.render('Cell')}
</StyledTd>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ exports[`<Table /> should render correctly 1`] = `
>
<styled.table
className=""
height="100%"
role="table"
width="100%"
>
<table
className="sc-jSMfEi egMCEo"
className="sc-jSMfEi eVsqtd"
height="100%"
role="table"
width="100%"
>
<styled.thead>
<thead
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/packages/primatives/box/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
flexbox,
system,
get,
// pseudo,
getContrast,
} from '@aw-web-design/styled-system';
import styled from 'styled-components';
Expand Down Expand Up @@ -37,6 +38,7 @@ export const StyledBoxProps = compose(
border,
shadow,
flexbox,
// pseudo,
utilProps
);

Expand Down
5 changes: 3 additions & 2 deletions packages/components/src/packages/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IThemeColorsType, ModeThemeType } from '../../../dist';
import { ITheme } from '../utils';
import { ITheme, IThemeColorsType, ModeThemeType } from '../utils';

import colors from './colors';
import borders from './dist/borders';
import breakpoints from './dist/breakpoints';
import breakpointSizes from './dist/breakpointSizes';
import defaultStyles from './dist/defaultStyles';
import elevation from './dist/elevation';
import fonts from './dist/fonts';
import fontSizes from './dist/fontSizes';
Expand Down Expand Up @@ -41,6 +41,7 @@ const theme: ITheme<typeof variants> = {
...opacity,
...space,
...spacing,
...defaultStyles,
};

export default theme;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type IThemeColorsType = {
};
};

export interface ITheme<V extends {}> {
export interface ITheme<V extends unknown> {
colors?: ModeThemeType & IThemeColorsType;
variants?: V;
fonts: Record<string, string>;
Expand Down
5 changes: 3 additions & 2 deletions packages/styled-system/src/core/styleFunction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Properties } from 'csstype';
import { Properties, Pseudos } from 'csstype';

import { Scale } from './types';
import { get } from './util';
Expand All @@ -18,7 +18,7 @@ export interface StyleFn {
}

export interface CreateStyleFunctionArgs {
property?: keyof Properties;
property?: keyof Properties | `&${Pseudos}`;
properties?: Array<keyof Properties>;
scale?: string;
transform?: (
Expand Down Expand Up @@ -49,6 +49,7 @@ export function createStyleFunction({
}

p.forEach((prop) => {
// @ts-ignore
result[prop] = value;
});

Expand Down
8 changes: 4 additions & 4 deletions packages/styled-system/src/core/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
StyleFn,
} from './styleFunction';

export interface SystemConfig {
[key: string]: boolean | CreateStyleFunctionArgs;
}
export type SystemConfig<T extends string> = {
[key in T]: boolean | CreateStyleFunctionArgs;
};

export function system(args: SystemConfig = {}): Parser {
export function system(args: SystemConfig<string> = {}): Parser {
const config: { [key: string]: StyleFn } = {};

Object.keys(args).forEach((key) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/styled-system/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export { shadow, ShadowProps } from './parsers/shadow';
export { space, SpaceProps } from './parsers/space';
export { transition, TransitionProps } from './parsers/transition';
export { typography, TypographyProps } from './parsers/typography';
export { pseudo } from './parsers/pseudo';

// pseudo props and mixin
export { pseudoMixin, PseudoProps } from './pseudo';
// export { pseudoMixin, PseudoProps } from './pseudo';

// styled-system shouldForwardProp
export {
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface AnimationProps<ThemeType extends Theme = RequiredTheme> {
animationPlayState?: ResponsiveValue<Property.AnimationPlayState, ThemeType>;
}

const config: SystemConfig = {
const config: SystemConfig<string> = {
animation: {
property: 'animation',
scale: 'animation.animation',
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface BackgroundProps<ThemeType extends Theme = RequiredTheme> {
bgAttachment?: ResponsiveValue<Property.BackgroundAttachment, ThemeType>;
}

const config: SystemConfig = {
const config: SystemConfig<string> = {
background: {
property: 'background',
scale: 'colors',
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/border.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface BorderProps<ThemeType extends Theme = RequiredTheme> {
borderY?: ResponsiveValue<Property.Border<TLengthStyledSystem>, ThemeType>;
}

const config: SystemConfig = {
const config: SystemConfig<string> = {
border: {
property: 'border',
scale: 'borders',
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface ColorProps<
opacity?: ResponsiveValue<Property.Opacity, ThemeType>;
}

const config: SystemConfig = {
const config: SystemConfig<string> = {
backgroundColor: {
property: 'backgroundColor',
scale: 'colors',
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/extendedFlexbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ExtendedFlexboxProps<ThemeType extends Theme = RequiredTheme>
direction?: FlexboxProps['flexDirection'];
}

const extendedConfig: SystemConfig = {
const extendedConfig: SystemConfig<string> = {
align: {
property: 'alignItems',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/extendedGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ExtendedGridProps<ThemeType extends Theme = RequiredTheme>
area?: GridProps['gridArea'];
}

const extendedConfig: SystemConfig = {
const extendedConfig: SystemConfig<string> = {
row: {
property: 'gridRow',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/flexbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface FlexboxProps<ThemeType extends Theme = RequiredTheme> {
placeSelf?: ResponsiveValue<Property.PlaceSelf, ThemeType>;
}

const config: SystemConfig = {
const config: SystemConfig<string> = {
alignItems: {
property: 'alignItems',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface GridProps<ThemeType extends Theme = RequiredTheme> {
gridArea?: ResponsiveValue<Property.GridArea, ThemeType>;
}

const config: SystemConfig = {
const config: SystemConfig<string> = {
gridGap: {
property: 'gridGap',
scale: 'space',
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface LayoutProps<ThemeType extends Theme = RequiredTheme> {
overflowY?: ResponsiveValue<Property.OverflowY, ThemeType>;
}

const config: SystemConfig = {
const config: SystemConfig<string> = {
width: {
property: 'width',
scale: 'sizes',
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface OtherProps<ThemeType extends Theme = RequiredTheme> {
outlineColor?: ResponsiveValue<ThemeValue<'colors', ThemeType>, ThemeType>;
}

const config: SystemConfig = {
const config: SystemConfig<string> = {
appearance: {
property: 'appearance',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-system/src/parsers/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface PositionProps<ThemeType extends Theme = RequiredTheme> {
left?: ResponsiveValue<Property.Left<TLengthStyledSystem>, ThemeType>;
}

const config: SystemConfig = {
const config: SystemConfig<string> = {
position: {
property: 'position',
},
Expand Down
Loading

0 comments on commit d018334

Please sign in to comment.