Skip to content

Commit

Permalink
feat(components): add stack
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelmord committed Sep 1, 2020
1 parent b629e0e commit fed3f2f
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 35 deletions.
16 changes: 16 additions & 0 deletions dist/components/Stack/Stack.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ResponsiveValue, TLengthStyledSystem, GridProps } from 'styled-system';
import { StyledComponent } from '@emotion/styled';
export declare type StackProps = GridProps & {
/** Minimum width of a child, will create responsive CSS Grid layout like
* `grid-template-columns: repeat(auto-fit, minmax($minColumnWidth$)}, 1fr))`.
* (You can use either this prop or `numColumns` but not both.)
*/
minColumnWidth?: ResponsiveValue<TLengthStyledSystem>;
/** Number of columns, will create a responsive CSS Grid layout like
* `grid-template-columns: repeat($numColumns$, 1fr))`.
* (You can use either this prop or `minColumnWidth` but not both.)
*/
numColumns?: ResponsiveValue<number>;
};
export declare const Stack: StyledComponent<GridProps, any, any>;
export default Stack;
2 changes: 2 additions & 0 deletions dist/components/Stack/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Stack';
export { default } from './Stack';
61 changes: 31 additions & 30 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
export * from './theme';
export * from './components/Alert';
export * from './components/Badge';
export * from './components/Avatar';
export * from './components/Button';
export * from './components/Card';
export * from './components/Checkbox';
export * from './components/Close';
export * from './components/Divider';
export * from './components/Donut';
export * from './components/Embed';
export * from './components/Field';
export * from './components/Heading';
export * from './components/IconButton';
export * from './components/Image';
export * from './components/Input';
export * from './components/Label';
export * from './components/LandingPageSection';
export * from './components/LandingPageSectionContent';
export * from './components/Link';
export * from './components/MenuButton';
export * from './components/Message';
export * from './components/NavLink';
export * from './components/Progress';
export * from './components/Radio';
export * from './components/Select';
export * from './components/Slider';
export * from './components/Spinner';
export * from './components/Text';
export * from './components/Textarea';
export * from './theme';
export * from './components/Alert';
export * from './components/Badge';
export * from './components/Avatar';
export * from './components/Button';
export * from './components/Card';
export * from './components/Checkbox';
export * from './components/Close';
export * from './components/Divider';
export * from './components/Donut';
export * from './components/Embed';
export * from './components/Field';
export * from './components/Heading';
export * from './components/IconButton';
export * from './components/Image';
export * from './components/Input';
export * from './components/Label';
export * from './components/LandingPageSection';
export * from './components/LandingPageSectionContent';
export * from './components/Link';
export * from './components/MenuButton';
export * from './components/Message';
export * from './components/NavLink';
export * from './components/Progress';
export * from './components/Radio';
export * from './components/Select';
export * from './components/Slider';
export * from './components/Spinner';
export * from './components/Stack';
export * from './components/Text';
export * from './components/Textarea';
33 changes: 33 additions & 0 deletions dist/prestyled.cjs.development.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/prestyled.cjs.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/prestyled.cjs.production.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/prestyled.cjs.production.min.js.map

Large diffs are not rendered by default.

34 changes: 33 additions & 1 deletion dist/prestyled.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/prestyled.esm.js.map

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/components/Stack/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Stack

```js
import { Box } from 'theme-ui';
<Stack gridGap={2}>
<Box bg="#F99BE4" sx={{ height: 8 }} />
<Box bg="#F249CC" sx={{ height: 8 }} />
<Box bg="#CD009B" sx={{ height: 8 }} />
</Stack>;
```
40 changes: 40 additions & 0 deletions src/components/Stack/Stack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Box } from 'theme-ui';
import { ResponsiveValue, TLengthStyledSystem, system, grid, GridProps } from 'styled-system';
import styled, { StyledComponent } from '@emotion/styled';

const px = (value: TLengthStyledSystem): string => (typeof value === 'number' ? `${value}px` : value);

const getMinMaxValue = (value: TLengthStyledSystem, scale: TLengthStyledSystem[] = []) =>
px(scale[value as number] || value);

export type StackProps = GridProps & {
/** Minimum width of a child, will create responsive CSS Grid layout like
* `grid-template-columns: repeat(auto-fit, minmax($minColumnWidth$)}, 1fr))`.
* (You can use either this prop or `numColumns` but not both.)
*/
minColumnWidth?: ResponsiveValue<TLengthStyledSystem>;
/** Number of columns, will create a responsive CSS Grid layout like
* `grid-template-columns: repeat($numColumns$, 1fr))`.
* (You can use either this prop or `minColumnWidth` but not both.)
*/
numColumns?: ResponsiveValue<number>;
};

export const Stack: StyledComponent<GridProps, any, any> = styled(Box)<StackProps>(
{ display: 'grid' },
grid,
system({
minColumnWidth: {
property: 'gridTemplateColumns',
scale: 'space',
transform: (value, scale) =>
value ? `repeat(auto-fit, minmax(${getMinMaxValue(value, scale as TLengthStyledSystem[])}, 1fr))` : null,
},
numColumns: {
property: 'gridTemplateColumns',
transform: (value) => (value ? `repeat(${value}, 1fr)` : null),
},
})
);

export default Stack;
2 changes: 2 additions & 0 deletions src/components/Stack/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Stack';
export { default } from './Stack';
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export * from './components/Radio';
export * from './components/Select';
export * from './components/Slider';
export * from './components/Spinner';
export * from './components/Stack';
export * from './components/Text';
export * from './components/Textarea';

0 comments on commit fed3f2f

Please sign in to comment.