-
Notifications
You must be signed in to change notification settings - Fork 11
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 #139 from 5liwei/LiWei
feat:add grid & correct disabled tabs
- Loading branch information
Showing
8 changed files
with
96 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createContext, Context } from 'react' | ||
|
||
export interface RowContextState { | ||
gutter?: number | ||
} | ||
|
||
export const RowContext: Context<RowContextState> = createContext({}) | ||
|
||
export default RowContext |
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,14 @@ | ||
$grid-columns: 24; | ||
|
||
.row { | ||
display: flex; | ||
} | ||
|
||
@for $index from 1 to 24 { | ||
.col-#{$index} { | ||
flex: 0 0 percentage($number: $index / $grid-columns); | ||
} | ||
} | ||
.col { | ||
box-sizing: border-box; | ||
} |
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,35 @@ | ||
import React, { useContext, CSSProperties } from 'react' | ||
import classNames from 'classnames' | ||
import RowContext from './RowContext' | ||
import './style.scss' | ||
|
||
export interface ColProps extends React.HTMLAttributes<HTMLDivElement> { | ||
span: number | ||
offset?: number | ||
} | ||
|
||
export function Col(props: ColProps) { | ||
const { children, span, offset } = props | ||
|
||
const classObj = { | ||
[`col-${span}`]: span !== void 0, | ||
[`col-offset-${offset}`]: offset !== void 0, | ||
} | ||
const classes = classNames('col', classObj) | ||
|
||
const { gutter } = useContext(RowContext) | ||
const styleObj: CSSProperties = {} | ||
if (gutter && gutter > 0) { | ||
const horizontalGutter = gutter / 2 | ||
styleObj.paddingLeft = horizontalGutter | ||
styleObj.paddingRight = horizontalGutter | ||
} | ||
|
||
return ( | ||
<div className={classes} style={{ ...styleObj }}> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
export default Col |
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,4 @@ | ||
import Row from './row' | ||
import Col from './col' | ||
|
||
export default { Row, Col } |
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,30 @@ | ||
import React from 'react' | ||
import RowContext from './RowContext' | ||
import './style.scss' | ||
|
||
export interface RowProps extends React.HTMLAttributes<HTMLDivElement> { | ||
gutter?: number | ||
} | ||
|
||
export function Row(props: RowProps) { | ||
const { gutter = 0, children } = props | ||
|
||
const rowContext = React.useMemo(() => ({ gutter }), [gutter]) | ||
|
||
const rowStyle: React.CSSProperties = {} | ||
|
||
if (gutter && gutter > 0) { | ||
rowStyle.marginLeft = gutter / -2 | ||
rowStyle.marginRight = gutter / -2 | ||
} | ||
|
||
return ( | ||
<RowContext.Provider value={rowContext}> | ||
<div className="row" style={{ ...rowStyle }}> | ||
{children} | ||
</div> | ||
</RowContext.Provider> | ||
) | ||
} | ||
|
||
export default Row |
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 { default as Grid } from './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
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 |
---|---|---|
|
@@ -63,3 +63,5 @@ | |
|
||
// calendar&datepicker | ||
@import '../components/Calendar/style'; | ||
|
||
@import '../components/Grid/grid/style'; |