-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
291 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/components/grid/__test__/__snapshots__/grid.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Grid component Should concat classname in props with Bulma classname 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="grid other-class this-is-a-test" | ||
> | ||
<p> | ||
Default | ||
</p> | ||
</div> | ||
</DocumentFragment> | ||
`; | ||
|
||
exports[`Grid component Should exist 1`] = `[Function]`; | ||
|
||
exports[`Grid component Should have grid classname 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="grid" | ||
> | ||
<img | ||
alt="placeholder" | ||
src="http://bulma.io/images/placeholders/128x128.png" | ||
/> | ||
</div> | ||
</DocumentFragment> | ||
`; | ||
|
||
exports[`Grid component Should render as Section 1`] = ` | ||
<DocumentFragment> | ||
<section | ||
class="grid" | ||
> | ||
<p> | ||
Default | ||
</p> | ||
</section> | ||
</DocumentFragment> | ||
`; | ||
|
||
exports[`Grid component Should use inline styles 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="grid" | ||
style="height: 250px;" | ||
> | ||
<p> | ||
Default | ||
</p> | ||
</div> | ||
</DocumentFragment> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { Grid } from '..'; | ||
|
||
describe('Grid component', () => { | ||
it('Should exist', () => { | ||
expect(Grid).toMatchSnapshot(); | ||
}); | ||
it('Should have grid classname', () => { | ||
const component = render( | ||
<Grid> | ||
<img | ||
alt="placeholder" | ||
src="http://bulma.io/images/placeholders/128x128.png" | ||
/> | ||
</Grid>, | ||
); | ||
expect(component.asFragment()).toMatchSnapshot(); | ||
}); | ||
it('Should concat classname in props with Bulma classname', () => { | ||
const component = render( | ||
<Grid className="other-class this-is-a-test"> | ||
<p>Default</p> | ||
</Grid>, | ||
); | ||
expect(component.asFragment()).toMatchSnapshot(); | ||
}); | ||
it('Should use inline styles', () => { | ||
const component = render( | ||
<Grid style={{ height: 250 }}> | ||
<p>Default</p> | ||
</Grid>, | ||
); | ||
expect(component.asFragment()).toMatchSnapshot(); | ||
}); | ||
it('Should render as Section', () => { | ||
const component = render( | ||
<Grid renderAs="section"> | ||
<p>Default</p> | ||
</Grid>, | ||
); | ||
expect(component.asFragment()).toMatchSnapshot(); | ||
}); | ||
it('Should set the gap', () => { | ||
render(<Grid gap={2}>Default</Grid>); | ||
const grid = screen.getByText('Default'); | ||
expect(grid).toHaveClass('gap-2'); | ||
}); | ||
it('Should set the column and row gap', () => { | ||
render(<Grid gap={[2, 3]}>Default</Grid>); | ||
const grid = screen.getByText('Default'); | ||
expect(grid).toHaveClass('column-gap-2'); | ||
expect(grid).toHaveClass('row-gap-3'); | ||
}); | ||
it('Should be fixed grid of 4 columns', () => { | ||
render(<Grid columns={4}>Default</Grid>); | ||
const grid = screen.getByText('Default'); | ||
expect(grid).toHaveClass('fixed-grid'); | ||
expect(grid).toHaveClass('has-4-cols'); | ||
}); | ||
it('Should be an auto grid', () => { | ||
render(<Grid columns="auto">Default</Grid>); | ||
const grid = screen.getByText('Default'); | ||
expect(grid).toHaveClass('has-auto-count'); | ||
}); | ||
it('Should be responsive', () => { | ||
render( | ||
<Grid | ||
breakpoints={{ | ||
tablet: 4, | ||
desktop: 6, | ||
mobile: 1, | ||
fullhd: 5, | ||
widescreen: 10, | ||
}} | ||
> | ||
Default | ||
</Grid>, | ||
); | ||
const grid = screen.getByText('Default'); | ||
expect(grid).toHaveClass('has-4-cols-tablet'); | ||
expect(grid).toHaveClass('has-6-cols-desktop'); | ||
expect(grid).toHaveClass('has-1-cols-mobile'); | ||
expect(grid).toHaveClass('has-5-cols-fullhd'); | ||
expect(grid).toHaveClass('has-10-cols-widescreen'); | ||
}); | ||
it('should render a Cell', () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import { Element } from '../../element'; | ||
|
||
/** | ||
* @type {typeof import('..').Cell | ||
*/ | ||
export const Cell = ({ | ||
children, | ||
className, | ||
column = {}, | ||
row = {}, | ||
...props | ||
}) => { | ||
return ( | ||
<Element | ||
className={clsx('cell', className, { | ||
[`is-col-start-${column.start}`]: Number.isInteger(column.start), | ||
[`is-col-from-end-${column.end}`]: Number.isInteger(column.end), | ||
[`is-col-span-${column.end}`]: Number.isInteger(column.end), | ||
[`is-row-start-${row.start}`]: Number.isInteger(row.start), | ||
[`is-row-from-end-${row.end}`]: Number.isInteger(row.end), | ||
[`is-row-span-${row.end}`]: Number.isInteger(row.end), | ||
})} | ||
{...props} | ||
> | ||
{children} | ||
</Element> | ||
); | ||
}; | ||
|
||
Element.setDisplayName(Cell, 'Grid.Cell'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
|
||
import { Element } from '../element'; | ||
|
||
/** | ||
* @type {typeof import('.').Grid | ||
*/ | ||
export const Grid = ({ | ||
children, | ||
className, | ||
minColWidth, | ||
gap, | ||
columns, | ||
breakpoints = {}, | ||
...props | ||
}) => { | ||
const [colGap, rowGap] = Array.isArray(gap) ? gap : []; | ||
const isFixed = Boolean(columns || Number.isInteger(columns)); | ||
|
||
return ( | ||
<Element | ||
{...props} | ||
className={clsx( | ||
{ | ||
grid: !isFixed, | ||
'fixed-grid': isFixed, | ||
}, | ||
className, | ||
{ | ||
[`is-col-min-${minColWidth}`]: minColWidth, | ||
[`gap-${gap}`]: gap && Number.isInteger(gap), | ||
[`column-gap-${colGap}`]: colGap, | ||
[`row-gap-${rowGap}`]: rowGap, | ||
[`has-${columns}-cols`]: Number.isInteger(columns), | ||
[`has-auto-count`]: columns === 'auto', | ||
...Object.entries(breakpoints).reduce((acc, [breakpoint, val]) => { | ||
return { | ||
...acc, | ||
[`has-${val}-cols-${breakpoint}`]: Number.isInteger(val), | ||
}; | ||
}, {}), | ||
}, | ||
)} | ||
> | ||
{children} | ||
</Element> | ||
); | ||
}; | ||
|
||
Element.setDisplayName(Grid, 'Grid'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
|
||
import { Grid, Section, Box } from '../..'; | ||
|
||
export default { | ||
title: 'Elements/Grid', | ||
}; | ||
|
||
export const Default = () => { | ||
return ( | ||
<Section> | ||
<Box> | ||
<Grid> | ||
<Grid.Cell>Cell</Grid.Cell> | ||
<Grid.Cell>Cell</Grid.Cell> | ||
<Grid.Cell>Cell</Grid.Cell> | ||
<Grid.Cell>Cell</Grid.Cell> | ||
<Grid.Cell>Cell</Grid.Cell> | ||
<Grid.Cell>Cell</Grid.Cell> | ||
</Grid> | ||
</Box> | ||
</Section> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { BulmaComponent } from '../index'; | ||
|
||
declare type CellProp = { | ||
start?: number; | ||
end?: number; | ||
span?: number; | ||
}; | ||
|
||
/** | ||
* @parent Grid | ||
* @name Grid.Cell | ||
*/ | ||
export declare const Cell: BulmaComponent<{ | ||
column?: CellProp; | ||
row?: CellProp; | ||
}> | ||
|
||
declare type GapType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; | ||
|
||
declare type ColumnsType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; | ||
|
||
export declare const Grid: BulmaComponent<{ | ||
minColWidth?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; | ||
columns?: ColumnsType | 'auto'; | ||
breakpoints?: { | ||
mobile?: ColumnsType; | ||
tablet?: ColumnsType; | ||
desktop?: ColumnsType; | ||
widescreen?: ColumnsType; | ||
fullhd?: ColumnsType; | ||
}; | ||
/** | ||
* Pass a number for setting the gap or and array with [Column, Row] gap values | ||
*/ | ||
gap?: GapType | [GapType, GapType]; | ||
}, 'div', { | ||
Cell: typeof Cell; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './grid'; |
Oops, something went wrong.