Skip to content

Commit

Permalink
Merge branch 'main' into feat/animation-style-props
Browse files Browse the repository at this point in the history
  • Loading branch information
tchock authored Dec 21, 2024
2 parents d646b98 + 40ce4b4 commit 90cb5a2
Show file tree
Hide file tree
Showing 60 changed files with 1,650 additions and 657 deletions.
10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/requestidlecallback": "^0.3.1",
"@types/styled-system": "^5.1.10",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/eslint-plugin-tslint": "^7.0.2",
"@typescript-eslint/parser": "4.10.0",
Expand All @@ -92,9 +91,9 @@
"rollup-plugin-terser": "^7.0.2",
"size-limit": "^11.1.6",
"storybook": "^8.4.4",
"styled-system": "^5.1.5",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"ts-toolbelt": "^9.6.0",
"tslint": "6.1.3",
"tslint-plugin-prettier": "2.3.0",
"typescript": "^5.6.3",
Expand All @@ -105,13 +104,6 @@
},
"dependencies": {
"@react-hook/media-query": "^1.1.1",
"@styled-system/border": "^5.1.5",
"@styled-system/core": "^5.1.2",
"@styled-system/flexbox": "^5.1.2",
"@styled-system/layout": "^5.1.2",
"@styled-system/position": "^5.1.2",
"@styled-system/space": "^5.1.2",
"@styled-system/typography": "^5.1.2",
"deepmerge": "^4.2.2",
"isobject": "^4.0.0",
"nanopop": "^2.4.2",
Expand Down
8 changes: 4 additions & 4 deletions site/docs/Customization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { PropsTable } from '@site/src/components/PropsTable';
# Customization

Pablo is highly customizable with the principle of making customizations as easy as possible and
reduce boilerplate code. As Pablo is built on top of `emotion` and `styled-system` it
utilizes both libraries to achive this.
reduce boilerplate code. As Pablo is built on top of `emotion`. It uses a custom styled system implementation
to be able to customize styles via props.

## Ways of customization

Expand All @@ -15,15 +15,15 @@ to inconsistent design and code quality.

There are five different ways you can customize components:

* Overwrite single styling properties such as padding or margin with `styled-system` props
* Overwrite single styling properties such as padding or margin with styled system props
* Update the theme values to update primitives like color or typographic values globally
* Change the `componentStyles` config to update component specific values such as gaps, colors or sizes
* Overwrite styling of parts of components globally with styled-component's `css` tag literal
* Overwrite styling of parts of components in place with the `customStyles` prop

## Use styling props

The quickest way to overwrite certain styles are the styling props that `styled-system` provides.
The quickest way to overwrite certain styles is to use the styled system props.
Most of the components of Pablo support these props which mainly should be used for layouting purposes
like adding margins (the `mx` and `my` props are quite useful for this). But you can also use
them to change color on more plain components like `<Headline />`.
Expand Down
2 changes: 1 addition & 1 deletion site/docs/components/Box.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PropsTable } from '@site/src/components/PropsTable';

# Box

The `Box` component is one of the fundamentals of Pablo. It exposes the style props from `styled-system`
The `Box` component is one of the fundamentals of Pablo. It exposes styled system like props
and we also partially use it within our components.

The main purpose of the `Box` component is to build layouts without the need to create separate
Expand Down
2 changes: 1 addition & 1 deletion site/docs/components/Image.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PropsTable } from '@site/src/components/PropsTable';
# Image

The `Image` component is a plain proxy of the normal HTML `img` element but it adds support for the
styled-system layouting props (like margins, paddings, positioning, etc.).
styled system layouting props (like margins, paddings, positioning, etc.).

## Import

Expand Down
10 changes: 2 additions & 8 deletions site/src/components/PropsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ import { useDynamicImport } from 'docusaurus-plugin-react-docgen-typescript/useD
const getFilterFn = (type) => {
switch (type) {
case 'direct':
return (prop) =>
!prop.parent?.fileName.includes('styled-system') &&
!prop.parent?.fileName.includes('spacingInterpolation.ts') &&
!prop.parent?.fileName.includes('Box/color.ts');
return (prop) => !prop.parent?.fileName.includes('interpolations');
case 'box':
return (prop) =>
prop.parent?.fileName.includes('styled-system') ||
prop.parent?.fileName.includes('spacingInterpolation.ts') ||
prop.parent?.fileName.includes('Box/color.ts');
return (prop) => prop.parent?.fileName.includes('interpolations');
case 'all':
default:
return () => true;
Expand Down
8 changes: 4 additions & 4 deletions site/src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## What is Pablo?

Pablo is the design system of Bojagi built on top of `emotion` and `styled-system`.
Pablo is the design system of Bojagi built on top of `emotion`.

It's build on these three core principles:

Expand All @@ -21,8 +21,8 @@ const [name, setName] = useState('');
<Input value="name" label="Name" onChange={setName} />
```

Every component of Pablo is also extending most of the `Box` component props, which is built on
top of `styled-system`. This way there is no need for wrapping divs only for the sake of layouting.
Every component of Pablo is also extending most of the `Box` component props, which implements our
own styled system implementation. This way there is no need for wrapping divs only for the sake of layouting.

```jsx
<Box display="flex" mx={-4}>
Expand All @@ -39,7 +39,7 @@ extend. There are different ways you can customize:
* Update the theme values to update primitives like color or typographic values globally
* Change the `componentStyles` config to update component specific values such as gaps, colors or sizes
* Overwrite styling of parts of components globally with styled-component's `css` tag literal
* Overwrite single styling properties such as padding or margin with `styled-system` props
* Overwrite single styling properties such as padding or margin with styled system props
* Overwrite styling of parts of components in place with the `customStyles` prop

Get a full insight into customization in the [Customization Section](/docs/Customization).
Expand Down
46 changes: 11 additions & 35 deletions src/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,46 @@
import styled from '@emotion/styled';
import { layout } from '@styled-system/layout';
import { flexbox } from '@styled-system/flexbox';
import { position } from '@styled-system/position';
import type { LayoutProps, FlexboxProps, PositionProps } from 'styled-system';
import { system } from '@styled-system/core';

import { color, ColorProps } from './color';
import { color, ColorProps } from './interpolations/color';
import { CssFunctionReturn } from '../types';
import { baseStyle } from '../shared/baseStyle';
import { getByPath } from '../utils/getByPath';
import { themeVars } from '../theme/themeVars';
import { interpolateCssProp } from '../utils/interpolateCssProp';
import { margin, MarginProps, PaddingProps, padding } from './spacingInterpolation';
import { ifProp } from '../styleHelpers/styleProp';
import { margin, MarginProps, PaddingProps, padding } from './interpolations/spacing';
import { layout, LayoutProps } from './interpolations/layout';
import { svg, SvgProps } from './interpolations/svg';
import { position, PositionProps } from './interpolations/position';
import { flexItem, FlexItemProps } from './interpolations/flex';

export interface BoxCssProps {
css?: CssFunctionReturn;
}

export interface BoxFillableProps {
fillColor?: string;
}

export interface BoxFlexProps extends FlexboxProps {
grow?: number | boolean;
shrink?: number | boolean;
}

export type BoxProps = MarginProps &
PaddingProps &
ColorProps &
LayoutProps &
BoxFlexProps &
FlexItemProps &
PositionProps &
BoxFillableProps &
SvgProps &
BoxCssProps;

const flexGrow = ifProp('grow', (_, value) => `flex-grow: ${value};`);
const flexShrink = ifProp('shrink', (_, value) => `flex-shrink: ${value};`);
export const boxInterpolateFn = (props) =>
[margin, padding, color, layout, flexbox, position, flexGrow, flexShrink].map((fn) => fn(props));

const fill = system({
fillColor: {
property: 'fill',
transform: (value: string) => getByPath(themeVars.colors, value),
},
});
[margin, padding, color, layout, svg, position, flexItem].map((fn) => fn(props));

export const Box = styled.div<BoxProps>`
${baseStyle}
${interpolateCssProp}
${fill}
${(props) => props.css}
${boxInterpolateFn}
`;

export type LayoutBoxProps = MarginProps &
PaddingProps &
BoxFlexProps &
FlexItemProps &
LayoutProps &
PositionProps &
BoxCssProps;

export const layoutInterpolationFn = (props) =>
[margin, padding, layout, flexbox, position, flexGrow, flexShrink]
[margin, padding, layout, position, flexItem]
.map((fn) => fn(props))
.reduce((acc, styles) => ({ ...acc, ...styles }), {});

Expand Down
30 changes: 14 additions & 16 deletions src/Box/Flex.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import type * as CSS from 'csstype';
import { ifProp } from '../styleHelpers/styleProp';
import { Box, type BoxProps } from './Box';
import styled from '@emotion/styled';
import { flexContainer, FlexContainerProps } from './interpolations/flex';

export type FlexProps = BoxProps & {
center?: boolean;
equal?: boolean;
end?: boolean;
start?: boolean;
between?: boolean;
stretch?: boolean;
direction?: CSS.Property.FlexDirection;
};

const justifyContent = (where: CSS.Property.JustifyContent) => `justify-content: ${where};`;
export type FlexProps = BoxProps &
FlexContainerProps & {
center?: boolean;
equal?: boolean;
end?: boolean;
start?: boolean;
between?: boolean;
stretch?: boolean;
};

export const Flex = styled(Box)<FlexProps>`
display: flex;
${flexContainer}
${ifProp('center', 'justify-content: center; align-items: center;')}
${ifProp('equal', '> * { flex-basis: 100%; flex-grow: 1; flex-shrink: 1; }')}
${ifProp('between', justifyContent('space-between'))}
${ifProp('end', justifyContent('flex-end'))}
${ifProp('start', justifyContent('flex-start'))}
${ifProp('stretch', 'align-items: stretch;')}
${ifProp('direction', (_, value) => `flex-direction: ${value};`)}
${ifProp('between', flexContainer.justifyContent('space-between'))}
${ifProp('end', flexContainer.justifyContent('flex-end'))}
${ifProp('start', flexContainer.justifyContent('flex-start'))}
`;
24 changes: 0 additions & 24 deletions src/Box/color.ts

This file was deleted.

49 changes: 49 additions & 0 deletions src/Box/interpolations/color.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { defaultTheme } from '../../theme';
import { PabloThemeableProps } from '../../theme/types';
import { color } from './color';

let props: PabloThemeableProps = {
theme: defaultTheme,
} as any;

beforeEach(() => {
props = {
theme: defaultTheme,
} as any;
});

test('bg color', () => {
expect(color({ ...props, bgColor: 'brand.main' })).toEqual({
backgroundColor: 'var(--pbl-theme-colors-brand-main)',
});
});

test('text color', () => {
expect(color({ ...props, textColor: 'brand.main' })).toEqual({
color: 'var(--pbl-theme-colors-brand-main)',
});
});

test('opacity', () => {
expect(color({ ...props, opacity: 0.5 })).toEqual({
opacity: 0.5,
});
expect(color({ ...props, opacity: '0.4' })).toEqual({
opacity: '0.4',
});
});

test('styled interpolation functions', () => {
expect(color.bgColor('brand.main')(props)).toEqual({
backgroundColor: 'var(--pbl-theme-colors-brand-main)',
});
expect(color.textColor('brand.main')(props)).toEqual({
color: 'var(--pbl-theme-colors-brand-main)',
});
expect(color.opacity(0.5)(props)).toEqual({
opacity: 0.5,
});
expect(color.opacity('0.4')(props)).toEqual({
opacity: '0.4',
});
});
25 changes: 25 additions & 0 deletions src/Box/interpolations/color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { colorTransform, ResponsiveValue, system } from '../system';
import { CssColor, KeyMap } from '../../types';
import { Colors } from '../../theme/colors';

export interface ColorProps {
bgColor?: ResponsiveValue<KeyMap<Colors> | CssColor>;
textColor?: ResponsiveValue<KeyMap<Colors> | CssColor>;
opacity?: ResponsiveValue<number>;
}

export const color = system([
{
properties: ['color'],
fromProps: ['textColor'],
transform: colorTransform,
},
{
properties: ['backgroundColor'],
fromProps: ['bgColor'],
transform: colorTransform,
},
{
properties: ['opacity'],
},
]);
Loading

0 comments on commit 90cb5a2

Please sign in to comment.