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

[TypeScript] Fix sx types and missing style prop from layout components #191

Merged
merged 3 commits into from
Aug 6, 2024
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
4 changes: 2 additions & 2 deletions packages/pigment-css-react/src/Box.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type PolymorphicComponentProps<
AsTarget extends React.ElementType | undefined,
AsTargetProps extends object = AsTarget extends React.ElementType
? React.ComponentPropsWithRef<AsTarget>
: BaseDefaultProps,
: React.HTMLAttributes<HTMLElement>,
> = NoInfer<Omit<Substitute<BaseProps, AsTargetProps>, 'as' | 'component'>> & {
/**
* The component used for the root node.
Expand Down Expand Up @@ -37,6 +37,6 @@ export interface PolymorphicComponent<BaseProps extends BaseDefaultProps>
): React.JSX.Element;
}

declare const Box: PolymorphicComponent<{}>;
declare const Box: PolymorphicComponent<React.DetailsHTMLAttributes<HTMLDivElement>>;

export default Box;
4 changes: 3 additions & 1 deletion packages/pigment-css-react/src/Container.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type ContainerBaseProps = {
maxWidth?: Breakpoint | false;
};

declare const Container: PolymorphicComponent<ContainerBaseProps>;
declare const Container: PolymorphicComponent<
ContainerBaseProps & React.DetailsHTMLAttributes<HTMLDivElement>
>;

export default Container;
4 changes: 3 additions & 1 deletion packages/pigment-css-react/src/Grid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type GridBaseProps = {
wrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
};

declare const Grid: PolymorphicComponent<GridBaseProps>;
declare const Grid: PolymorphicComponent<
GridBaseProps & React.DetailsHTMLAttributes<HTMLDivElement>
>;

export default Grid;
4 changes: 3 additions & 1 deletion packages/pigment-css-react/src/Hidden.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface HiddenBaseProps extends HiddenUp, HiddenDown {
only?: Breakpoint | Breakpoint[];
}

declare const Hidden: PolymorphicComponent<HiddenBaseProps>;
declare const Hidden: PolymorphicComponent<
HiddenBaseProps & React.DetailsHTMLAttributes<HTMLDivElement>
>;

export default Hidden;
4 changes: 3 additions & 1 deletion packages/pigment-css-react/src/Stack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type StackBaseProps = {
className?: string;
};

declare const Stack: PolymorphicComponent<StackBaseProps>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a typecheck test for the change if possible ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

declare const Stack: PolymorphicComponent<
StackBaseProps & React.DetailsHTMLAttributes<HTMLDivElement>
>;

export default Stack;
6 changes: 3 additions & 3 deletions packages/pigment-css-react/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ styled.div(({ theme }) => ({
}));

sx({ color: 'red' });
sx(({ theme }) => ({
sx((theme) => ({
color: theme.palette.primary.main,
}));
sx([
{ color: 'red' },
({ theme }) => ({
(theme) => ({
color: theme.palette.primary.main,
}),
]);
const foo = true;
sx([
true && { color: 'red' },
foo
? ({ theme }) => ({
? (theme) => ({
color: theme.palette.primary.main,
})
: {
Expand Down
5 changes: 4 additions & 1 deletion packages/pigment-css-react/src/sx.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { CSSObjectNoCallback } from './base';
import type { ThemeArgs } from './theme';

export type SxProp = CSSObjectNoCallback | ((themeArgs: ThemeArgs) => CSSObjectNoCallback);
export type SxProp =
| CSSObjectNoCallback
| ((themeArgs: ThemeArgs['theme']) => CSSObjectNoCallback)
| ReadonlyArray<CSSObjectNoCallback | ((themeArgs: ThemeArgs['theme']) => CSSObjectNoCallback)>;

export default function sx(arg: SxProp | Array<SxProp>, componentClass?: string): string;
4 changes: 2 additions & 2 deletions packages/pigment-css-react/tests/Box.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Box } from '@pigment-css/react/Box';
import Box from '../src/Box';

export function App() {
return (
Expand All @@ -13,7 +13,7 @@ export function App() {
Dialog
</Box>
{/* @ts-expect-error */}
<Box component="dialog" as="button" open>
<Box component="dialog" as="button" href>
Dialog 2
</Box>
</Box>
Expand Down
10 changes: 10 additions & 0 deletions packages/pigment-css-react/tests/Container.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react';
import Container from '../src/Container';

<Container maxWidth="md" />;

<Container
className=""
style={{ accentColor: 'ActiveBorder', marginTop: '1rem' }}
data-testid="foo"
/>;
6 changes: 6 additions & 0 deletions packages/pigment-css-react/tests/Grid.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as React from 'react';
import Grid from '../src/Grid';

<Grid size={{ xs: 2, md: 3, lg: 4 }} />;

<Grid className="" style={{ accentColor: 'ActiveBorder', marginTop: '1rem' }} data-testid="foo" />;
10 changes: 10 additions & 0 deletions packages/pigment-css-react/tests/Hidden.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react';
import Hidden from '../src/Hidden';

<Hidden xsUp mdDown />;

<Hidden
className=""
style={{ accentColor: 'ActiveBorder', marginTop: '1rem' }}
data-testid="foo"
/>;
5 changes: 5 additions & 0 deletions packages/pigment-css-react/tests/Stack.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as React from 'react';
import Stack from '../src/Stack';

<Stack spacing={2} direction={{ md: 'row' }} />;

<Stack className="" style={{ accentColor: 'ActiveBorder', marginTop: '1rem' }} data-testid="foo" />;

<Stack
// @ts-expect-error
display={{
xs: 'flex',
xl: 'inline-flex',
Expand Down
17 changes: 17 additions & 0 deletions packages/pigment-css-react/tests/sx.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SxProp } from '../src/sx';

const sx1: SxProp = { color: 'red' };

const sx2: SxProp = (theme) => ({
color: theme.palette.primary.main,
});

const sx3: SxProp = [{ color: 'red' }, { backgroundColor: 'blue', color: 'white' }];

const test = true;
const sx4: SxProp = [
test ? { color: 'red' } : { backgroundColor: 'blue', color: 'white' },
(theme) => ({
border: `1px solid ${theme.palette.primary.main}`,
}),
];
Loading