-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(grid): react 组件同步 * test(grid): add unit test * fix: update type TNode * refactor(grid): address code review feedback * test(grid): update test snapshots * test: update csr and ssr snap --------- Co-authored-by: anlyyao <[email protected]>
- Loading branch information
Showing
26 changed files
with
6,145 additions
and
427 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
Submodule _common
updated
15 files
+66 −0 | docs/mobile/api/button.en-US.md | |
+35 −0 | docs/mobile/api/grid.en-US.md | |
+18 −2 | docs/mobile/api/grid.md | |
+29 −0 | docs/mobile/api/image.en-US.md | |
+11 −17 | docs/mobile/api/image.md | |
+64 −0 | docs/mobile/api/input.en-US.md | |
+40 −12 | docs/mobile/api/input.md | |
+17 −0 | docs/mobile/api/link.en-US.md | |
+15 −0 | docs/mobile/api/link.md | |
+31 −0 | docs/mobile/api/search.en-US.md | |
+19 −5 | docs/mobile/api/search.md | |
+3 −3 | style/mobile/components/_index.less | |
+44 −0 | style/mobile/components/image/v2/_index.less | |
+10 −5 | style/mobile/components/link/_index.less | |
+61 −15 | style/mobile/components/link/_var.less |
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,29 +1,47 @@ | ||
import React, { forwardRef } from 'react'; | ||
import { TdGridProps } from './type'; | ||
import React, { forwardRef, useMemo } from 'react'; | ||
import cls from 'classnames'; | ||
import useConfig from '../_util/useConfig'; | ||
import { StyledProps } from '../common'; | ||
import useDefaultProps from '../hooks/useDefaultProps'; | ||
|
||
import { TdGridProps } from './type'; | ||
import { GirdProvider } from './GridContext'; | ||
import { gridDefaultProps } from './defaultProps'; | ||
|
||
export interface GridProps extends TdGridProps { | ||
children: React.ReactNode; | ||
} | ||
export interface GridProps extends TdGridProps, StyledProps {} | ||
|
||
const Grid = forwardRef<HTMLDivElement, GridProps>((props, ref) => { | ||
const { children, align, border, column, gutter } = props; | ||
const { children, align, border, column, gutter, theme, className, style } = useDefaultProps(props, gridDefaultProps); | ||
const { classPrefix } = useConfig(); | ||
const name = `${classPrefix}-grid`; | ||
|
||
const rootStyle = useMemo(() => { | ||
if (column === 0) return {}; | ||
return { | ||
padding: `${gutter}px`, | ||
gridTemplateColumns: `repeat(${column}, 1fr)`, | ||
gridGap: `${gutter}px`, | ||
...style, | ||
}; | ||
}, [column, gutter, style]); | ||
|
||
return ( | ||
<GirdProvider gutter={gutter} border={border} column={column} align={align}> | ||
<div ref={ref} className={name}> | ||
<GirdProvider gutter={gutter} border={border} column={column} align={align} theme={theme}> | ||
<div | ||
ref={ref} | ||
className={cls(name, className, { | ||
[`${name}--card`]: theme === 'card', | ||
[`${name}--auto-size`]: column === 0, | ||
[`${name}--bordered`]: border && !gutter, | ||
})} | ||
style={rootStyle} | ||
> | ||
{children} | ||
</div> | ||
</GirdProvider> | ||
); | ||
}); | ||
|
||
Grid.displayName = 'Grid'; | ||
Grid.defaultProps = gridDefaultProps; | ||
|
||
export default 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
Oops, something went wrong.