Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[system] Fix return type of createBox #29989

Merged
merged 3 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mui-system/src/Box/Box.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ function GapTest() {
function ComponentPropTest() {
<Box component="img" src="https://mui.com/" alt="Material UI" />;
<Box component={Test} test="Test string" />;
<Box maxWidth={(theme: Theme) => theme.breakpoints.values.sm} />;
}

function ThemeCallbackTest() {
<Box sx={{ background: (theme) => theme.palette.primary.main }} />;
<Box sx={{ ':hover': (theme) => ({ background: theme.palette.primary.main }) }} />;
<Box sx={{ '& .some-class': (theme) => ({ background: theme.palette.primary.main }) }} />;
<Box maxWidth={(theme) => theme.breakpoints.values.sm} />;
}
4 changes: 2 additions & 2 deletions packages/mui-system/src/createBox.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Box from './Box';

export default function createBox(options?: {
defaultTheme: object;
defaultClassName?: string;
generateClassName?: (componentName: string) => string;
}): React.ElementType;
}): typeof Box;
58 changes: 58 additions & 0 deletions packages/mui-system/src/createBox.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';
import { createBox } from '@mui/system';

const Box = createBox();

interface TestProps {
test?: string;
}

function Test(props: TestProps) {
const { test, ...other } = props;
return <span {...other}>{test}</span>;
}

function ResponsiveTest() {
<Box sx={{ p: [2, 3, 4] }} />;
<Box sx={{ p: { xs: 2, sm: 3, md: 4 } }} />;
// @ts-expect-error value for the breakpoint should be valid
<Box sx={{ p: { xs: 2, sm: { you: "are dealing with 'any' here" }, md: 4 } }} />;
<Box sx={{ fontSize: [12, 18, 24] }}>Array API</Box>;
<Box
sx={{
fontSize: {
xs: 12,
sm: 18,
md: 24,
},
}}
>
Object API
</Box>;
}

function GapTest() {
<Box
sx={{
width: '100%',
display: 'flex',
alignItems: 'center',
flex: '1 0',
gap: '16px',
}}
>
Gap
</Box>;
}

function ComponentPropTest() {
<Box component="img" src="https://mui.com/" alt="Material UI" />;
<Box component={Test} test="Test string" />;
}

function ThemeCallbackTest() {
<Box sx={{ background: (theme) => theme.palette.primary.main }} />;
<Box sx={{ ':hover': (theme) => ({ background: theme.palette.primary.main }) }} />;
<Box sx={{ '& .some-class': (theme) => ({ background: theme.palette.primary.main }) }} />;
<Box maxWidth={(theme) => theme.breakpoints.values.sm} />;
}