-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from eduzz/develop
Versão 0.52.0
- Loading branch information
Showing
24 changed files
with
406 additions
and
234 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,108 @@ | ||
import * as React from 'react'; | ||
|
||
import Grid, { GridProps } from '@mui/material/Grid'; | ||
|
||
type IOmitProps = | ||
| 'container' | ||
| 'item' | ||
| 'justify' | ||
| 'justifyContent' | ||
| 'spacing' | ||
| 'zeroMinWidth' | ||
| 'alignContent' | ||
| 'alignItems' | ||
| 'direction' | ||
| 'wrap'; | ||
|
||
export interface IColumnProps extends Omit<GridProps, IOmitProps> {} | ||
|
||
const Column = React.forwardRef<HTMLDivElement, IColumnProps>(({ className, ...rest }, ref) => { | ||
return <Grid {...rest} item className={className} ref={ref} />; | ||
import styled, { css, cx, IStyledProp, IHoustonTheme } from '@eduzz/houston-styles'; | ||
|
||
import { useRow } from '../context'; | ||
import { Spacing } from '../Row'; | ||
|
||
type ColumnSize = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | true; | ||
type BreakPoints = 'xs' | 'sm' | 'md' | 'lg' | 'xlg'; | ||
type Sizes = Partial<Record<BreakPoints, ColumnSize>>; | ||
|
||
export type IColumn = IStyledProp & | ||
Sizes & { | ||
children: React.ReactNode; | ||
}; | ||
|
||
const Column = React.forwardRef<HTMLDivElement, IColumn>(({ className, children, xs = true, sm, md, lg, xlg }, ref) => { | ||
const { spacing = 'xxs' } = useRow(); | ||
return ( | ||
<div | ||
ref={ref} | ||
className={cx( | ||
className, | ||
`--spacing-${spacing}`, | ||
xs && `--xs-${xs}`, | ||
sm && `--sm-${sm}`, | ||
md && `--md-${md}`, | ||
lg && `--lg-${lg}`, | ||
xlg && `--xlg-${xlg}` | ||
)} | ||
> | ||
{children} | ||
</div> | ||
); | ||
}); | ||
|
||
export default Column; | ||
const COLUMNS = 12; | ||
const NONE_IN_REM = '0rem'; | ||
|
||
const generateBreakAndWidth = (theme: IHoustonTheme, sizes: Sizes, spacing: Spacing) => { | ||
return Object.entries(sizes) | ||
.map(([breakpoint, size]: [BreakPoints, ColumnSize]) => { | ||
if (typeof size === 'boolean') { | ||
return ` | ||
&.--${breakpoint}-${size} { | ||
${theme.breakpoints.up(breakpoint)} { | ||
flex-grow: 1; | ||
width: auto; | ||
margin: calc(${theme.spacing.inline[spacing] ?? NONE_IN_REM} / 2); | ||
} | ||
}`; | ||
} | ||
|
||
return ` | ||
&.--${breakpoint}-${size} { | ||
${theme.breakpoints.up(breakpoint)} { | ||
width: calc(${((sizes[breakpoint] as number) / COLUMNS) * 100}% - ${ | ||
theme.spacing.inline[spacing] ?? NONE_IN_REM | ||
}); | ||
margin: calc(${theme.spacing.inline[spacing] ?? NONE_IN_REM} / 2); | ||
} | ||
}`; | ||
}) | ||
.join(''); | ||
}; | ||
|
||
export default React.memo( | ||
styled(Column, { label: 'houston-grid-column' })(({ theme, xs = true, sm, md, lg, xlg }) => { | ||
const sizes = { | ||
...(xs && { xs }), | ||
...(sm && { sm }), | ||
...(md && { md }), | ||
...(lg && { lg }), | ||
...(xlg && { xlg }) | ||
}; | ||
|
||
return css` | ||
&.--spacing-none { | ||
${generateBreakAndWidth(theme, sizes, 'none')} | ||
} | ||
&.--spacing-nano { | ||
${generateBreakAndWidth(theme, sizes, 'nano')} | ||
} | ||
&.--spacing-xxxs { | ||
margin: calc(${theme.spacing.xxxs} / 2); | ||
${generateBreakAndWidth(theme, sizes, 'xxxs')} | ||
} | ||
&.--spacing-xxs { | ||
${generateBreakAndWidth(theme, sizes, 'xxs')} | ||
} | ||
&.--spacing-xs { | ||
${generateBreakAndWidth(theme, sizes, 'xs')} | ||
} | ||
&.--spacing-md { | ||
${generateBreakAndWidth(theme, sizes, 'md')} | ||
} | ||
&.--spacing-xl { | ||
${generateBreakAndWidth(theme, sizes, 'xl')} | ||
} | ||
`; | ||
}) | ||
); |
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 |
---|---|---|
@@ -1,77 +1,35 @@ | ||
import * as React from 'react'; | ||
|
||
import MUIContainer, { ContainerProps } from '@mui/material/Container'; | ||
import styled, { css, cx, IStyledProp } from '@eduzz/houston-styles'; | ||
|
||
import { cx } from '@eduzz/houston-styles'; | ||
import createUseStyles from '@eduzz/houston-styles/createUseStyles'; | ||
|
||
import GridContextProvider from '../context'; | ||
import { IContainerType } from '../interfaces'; | ||
|
||
const useStyles = createUseStyles({ | ||
root: { | ||
width: '100%', | ||
maxWidth: 1062, | ||
margin: '0 auto' | ||
}, | ||
comfortable: { | ||
padding: '0 18px' | ||
}, | ||
cozy: { | ||
padding: '0 28px' | ||
}, | ||
compact: { | ||
padding: '0 20px' | ||
}, | ||
fluid: { | ||
maxWidth: '100%' | ||
} | ||
}); | ||
|
||
type ContainerPropsExtends = 'id' | 'className' | 'children' | 'style' | 'tabIndex'; | ||
|
||
export type IContainterLayout = 'fluid' | 'solid'; | ||
|
||
export interface IContainerProps extends Pick<ContainerProps, ContainerPropsExtends> { | ||
/** | ||
* Type container | ||
* | ||
* `comfortable` spacing big | ||
* `cozy` spacing medium | ||
* `compact` spacing small | ||
* | ||
* default `cozy` | ||
*/ | ||
spacing?: IContainerType; | ||
/** | ||
* Types layout | ||
* | ||
* `fluid` max-width ignored | ||
* `solid` limited | ||
* | ||
* default `solid` | ||
*/ | ||
layout?: IContainterLayout; | ||
export type IContainerLayout = 'fluid' | 'solid'; | ||
export interface IContainer extends IStyledProp { | ||
children: React.ReactNode; | ||
layout?: IContainerLayout; | ||
} | ||
|
||
const Container = React.forwardRef<HTMLDivElement, IContainerProps>( | ||
({ children, className, spacing = 'cozy', layout = 'solid', ...rest }, ref) => { | ||
const classes = useStyles(); | ||
|
||
const contextValue = React.useMemo(() => ({ spacing }), [spacing]); | ||
|
||
return ( | ||
<GridContextProvider value={contextValue}> | ||
<MUIContainer | ||
{...rest} | ||
ref={ref} | ||
className={cx(classes.root, classes[spacing], layout === 'fluid' && classes.fluid, className)} | ||
> | ||
{children} | ||
</MUIContainer> | ||
</GridContextProvider> | ||
); | ||
} | ||
); | ||
|
||
export default React.memo(Container); | ||
const Container = React.forwardRef<HTMLDivElement, IContainer>(({ className, children, layout }, ref) => ( | ||
<div ref={ref} className={cx(className, `--${layout ?? 'solid'}`)}> | ||
{children} | ||
</div> | ||
)); | ||
|
||
export default React.memo(styled(Container, { label: 'houston-grid-container' })` | ||
${({ theme }) => { | ||
const MAX_WIDTH_IN_PX = theme.breakpoints.xlg; | ||
return css` | ||
width: 100%; | ||
max-width: ${MAX_WIDTH_IN_PX}; | ||
margin: 0 auto; | ||
padding: 0 ${theme.spacing.xs}; | ||
${theme.breakpoints.down('sm')} { | ||
padding: 0 ${theme.spacing.xxxs}; | ||
} | ||
&.--fluid { | ||
max-width: 100%; | ||
} | ||
`; | ||
}} | ||
`); |
Oops, something went wrong.