Skip to content

Commit 4576df1

Browse files
authoredAug 6, 2024··
[TypeScript] Fix sx types and missing style prop from layout components (#191)
1 parent 69a550a commit 4576df1

13 files changed

+71
-12
lines changed
 

‎packages/pigment-css-react/src/Box.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type PolymorphicComponentProps<
77
AsTarget extends React.ElementType | undefined,
88
AsTargetProps extends object = AsTarget extends React.ElementType
99
? React.ComponentPropsWithRef<AsTarget>
10-
: BaseDefaultProps,
10+
: React.HTMLAttributes<HTMLElement>,
1111
> = NoInfer<Omit<Substitute<BaseProps, AsTargetProps>, 'as' | 'component'>> & {
1212
/**
1313
* The component used for the root node.
@@ -37,6 +37,6 @@ export interface PolymorphicComponent<BaseProps extends BaseDefaultProps>
3737
): React.JSX.Element;
3838
}
3939

40-
declare const Box: PolymorphicComponent<{}>;
40+
declare const Box: PolymorphicComponent<React.DetailsHTMLAttributes<HTMLDivElement>>;
4141

4242
export default Box;

‎packages/pigment-css-react/src/Container.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type ContainerBaseProps = {
2424
maxWidth?: Breakpoint | false;
2525
};
2626

27-
declare const Container: PolymorphicComponent<ContainerBaseProps>;
27+
declare const Container: PolymorphicComponent<
28+
ContainerBaseProps & React.DetailsHTMLAttributes<HTMLDivElement>
29+
>;
2830

2931
export default Container;

‎packages/pigment-css-react/src/Grid.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type GridBaseProps = {
1818
wrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
1919
};
2020

21-
declare const Grid: PolymorphicComponent<GridBaseProps>;
21+
declare const Grid: PolymorphicComponent<
22+
GridBaseProps & React.DetailsHTMLAttributes<HTMLDivElement>
23+
>;
2224

2325
export default Grid;

‎packages/pigment-css-react/src/Hidden.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ interface HiddenBaseProps extends HiddenUp, HiddenDown {
1313
only?: Breakpoint | Breakpoint[];
1414
}
1515

16-
declare const Hidden: PolymorphicComponent<HiddenBaseProps>;
16+
declare const Hidden: PolymorphicComponent<
17+
HiddenBaseProps & React.DetailsHTMLAttributes<HTMLDivElement>
18+
>;
1719

1820
export default Hidden;

‎packages/pigment-css-react/src/Stack.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type StackBaseProps = {
1212
className?: string;
1313
};
1414

15-
declare const Stack: PolymorphicComponent<StackBaseProps>;
15+
declare const Stack: PolymorphicComponent<
16+
StackBaseProps & React.DetailsHTMLAttributes<HTMLDivElement>
17+
>;
1618

1719
export default Stack;

‎packages/pigment-css-react/src/index.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ styled.div(({ theme }) => ({
4444
}));
4545

4646
sx({ color: 'red' });
47-
sx(({ theme }) => ({
47+
sx((theme) => ({
4848
color: theme.palette.primary.main,
4949
}));
5050
sx([
5151
{ color: 'red' },
52-
({ theme }) => ({
52+
(theme) => ({
5353
color: theme.palette.primary.main,
5454
}),
5555
]);
5656
const foo = true;
5757
sx([
5858
true && { color: 'red' },
5959
foo
60-
? ({ theme }) => ({
60+
? (theme) => ({
6161
color: theme.palette.primary.main,
6262
})
6363
: {
+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { CSSObjectNoCallback } from './base';
22
import type { ThemeArgs } from './theme';
33

4-
export type SxProp = CSSObjectNoCallback | ((themeArgs: ThemeArgs) => CSSObjectNoCallback);
4+
export type SxProp =
5+
| CSSObjectNoCallback
6+
| ((themeArgs: ThemeArgs['theme']) => CSSObjectNoCallback)
7+
| ReadonlyArray<CSSObjectNoCallback | ((themeArgs: ThemeArgs['theme']) => CSSObjectNoCallback)>;
58

69
export default function sx(arg: SxProp | Array<SxProp>, componentClass?: string): string;

‎packages/pigment-css-react/tests/Box.spec.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Box } from '@pigment-css/react/Box';
2+
import Box from '../src/Box';
33

44
export function App() {
55
return (
@@ -13,7 +13,7 @@ export function App() {
1313
Dialog
1414
</Box>
1515
{/* @ts-expect-error */}
16-
<Box component="dialog" as="button" open>
16+
<Box component="dialog" as="button" href>
1717
Dialog 2
1818
</Box>
1919
</Box>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
import Container from '../src/Container';
3+
4+
<Container maxWidth="md" />;
5+
6+
<Container
7+
className=""
8+
style={{ accentColor: 'ActiveBorder', marginTop: '1rem' }}
9+
data-testid="foo"
10+
/>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from 'react';
2+
import Grid from '../src/Grid';
3+
4+
<Grid size={{ xs: 2, md: 3, lg: 4 }} />;
5+
6+
<Grid className="" style={{ accentColor: 'ActiveBorder', marginTop: '1rem' }} data-testid="foo" />;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
import Hidden from '../src/Hidden';
3+
4+
<Hidden xsUp mdDown />;
5+
6+
<Hidden
7+
className=""
8+
style={{ accentColor: 'ActiveBorder', marginTop: '1rem' }}
9+
data-testid="foo"
10+
/>;

‎packages/pigment-css-react/tests/Stack.spec.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import * as React from 'react';
22
import Stack from '../src/Stack';
33

4+
<Stack spacing={2} direction={{ md: 'row' }} />;
5+
6+
<Stack className="" style={{ accentColor: 'ActiveBorder', marginTop: '1rem' }} data-testid="foo" />;
7+
48
<Stack
9+
// @ts-expect-error
510
display={{
611
xs: 'flex',
712
xl: 'inline-flex',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { SxProp } from '../src/sx';
2+
3+
const sx1: SxProp = { color: 'red' };
4+
5+
const sx2: SxProp = (theme) => ({
6+
color: theme.palette.primary.main,
7+
});
8+
9+
const sx3: SxProp = [{ color: 'red' }, { backgroundColor: 'blue', color: 'white' }];
10+
11+
const test = true;
12+
const sx4: SxProp = [
13+
test ? { color: 'red' } : { backgroundColor: 'blue', color: 'white' },
14+
(theme) => ({
15+
border: `1px solid ${theme.palette.primary.main}`,
16+
}),
17+
];

0 commit comments

Comments
 (0)
Please sign in to comment.