Skip to content

Commit

Permalink
feat:add grid & correct disabled tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
5liwei committed Feb 16, 2023
1 parent adc2b3b commit 799db49
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/components/Grid/grid/RowContext.tsx
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
14 changes: 14 additions & 0 deletions src/components/Grid/grid/_style.scss
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;
}
35 changes: 35 additions & 0 deletions src/components/Grid/grid/col.tsx
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
4 changes: 4 additions & 0 deletions src/components/Grid/grid/index.tsx
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 }
30 changes: 30 additions & 0 deletions src/components/Grid/grid/row.tsx
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
1 change: 1 addition & 0 deletions src/components/Grid/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Grid } from './grid'
2 changes: 1 addition & 1 deletion src/components/Tabs/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
color: $nav-tabs-link-hover-color;
}
// Disabled state lightens text
&.--disabled {
&.disabled {
color: $nav-link-disabled-color;
pointer-events: none;
cursor: default;
Expand Down
2 changes: 2 additions & 0 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@

// calendar&datepicker
@import '../components/Calendar/style';

@import '../components/Grid/grid/style';

0 comments on commit 799db49

Please sign in to comment.