forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use breakpoint by Copilot AI (ant-design#52870)
* refactor: use breakpoint * refactor: add hooks * chore: clean up * chore: fix logic * chore: fix logic * chore: fix ts * chore: fix ts
- Loading branch information
Showing
3 changed files
with
56 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Breakpoint, ScreenMap } from '../../_util/responsiveObserver'; | ||
import { responsiveArray } from '../../_util/responsiveObserver'; | ||
import type { RowProps } from '../row'; | ||
|
||
type Gap = number | undefined; | ||
|
||
export default function useGutter( | ||
gutter: RowProps['gutter'], | ||
screens: ScreenMap | null, | ||
): [Gap, Gap] { | ||
const results: [number | undefined, number | undefined] = [undefined, undefined]; | ||
const normalizedGutter = Array.isArray(gutter) ? gutter : [gutter, undefined]; | ||
|
||
// By default use as `xs` | ||
const mergedScreens = screens || { | ||
xs: true, | ||
sm: true, | ||
md: true, | ||
lg: true, | ||
xl: true, | ||
xxl: true, | ||
}; | ||
|
||
normalizedGutter.forEach((g, index) => { | ||
if (typeof g === 'object' && g !== null) { | ||
for (let i = 0; i < responsiveArray.length; i++) { | ||
const breakpoint: Breakpoint = responsiveArray[i]; | ||
if (mergedScreens[breakpoint] && g[breakpoint] !== undefined) { | ||
results[index] = g[breakpoint] as number; | ||
break; | ||
} | ||
} | ||
} else { | ||
results[index] = g; | ||
} | ||
}); | ||
return results; | ||
} |
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