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

Enable sx prop on any components #37

Merged
merged 22 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
5 changes: 3 additions & 2 deletions apps/pigment-css-next-app/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"rules": {
"import/prefer-default-export": "off",
"import/extensions": "off",
"import/no-unresolved": "off"
}
"import/no-unresolved": "off",
"react/no-unknown-property": ["error", { "ignore": ["sx"] }],
Copy link
Member Author

Choose a reason for hiding this comment

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

Ignore sx prop on JSX html tag.

},
}
2 changes: 1 addition & 1 deletion apps/pigment-css-next-app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ theme.getColorSchemeSelector = (colorScheme) => {
*/
const pigmentOptions = {
theme,
transformLibraries: ['local-ui-lib'],
transformLibraries: ['local-ui-lib', '@mui/material'],
sourceMap: true,
displayName: true,
};
Expand Down
41 changes: 38 additions & 3 deletions apps/pigment-css-next-app/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import Image from 'next/image';
import { styled, css } from '@pigment-css/react';
import Button from '@mui/material/Button';
import styles from './page.module.css';

declare global {
namespace React {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface HTMLAttributes<T> {
sx?: any;
}
Comment on lines +9 to +11
Copy link
Member Author

Choose a reason for hiding this comment

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

Just to test that we can modify the types of JSX elements.

Copy link
Member

Choose a reason for hiding this comment

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

Nice, we can use the SxProps tough, no? :) I would recommend adding a documentation about this in the README.md too, so we can test everything, including typings and make sure we haven't forgot something.

Copy link
Member Author

@siriwatknp siriwatknp Apr 26, 2024

Choose a reason for hiding this comment

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

It's for POC at this point. There is one issue to fix from Pigment side which is delegating sx logic to the theme. Currently, Pigment is using styleFunctionSx from MUI System which is impossible to customize.

Once that's done, I will add docs for it.

}
}

const visuallyHidden = css({
border: 0,
clip: 'rect(0 0 0 0)',
Expand Down Expand Up @@ -93,8 +103,16 @@ export default function Home() {
return (
<Main>
<div className={visuallyHidden}>I am invisible</div>
<Description>
<p>
<Description
sx={{
'&::before': {
content: '"🚀"',
display: 'inline-block',
border: '1px solid',
},
}}
>
<p sx={{ boxShadow: '0 0 4px 0 rgba(0 0 0 / 0.12)' }}>
Copy link
Member

Choose a reason for hiding this comment

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

I ❤️ this!

Get started by editing&nbsp;
<code className={styles.code}>src/app/page.tsx</code>
</p>
Expand All @@ -117,7 +135,12 @@ export default function Home() {
</div>
</Description>

<div className={styles.center}>
<div
className={styles.center}
sx={{
border: '1px solid',
}}
>
<Image
className={styles.logo}
src="/next.svg"
Expand Down Expand Up @@ -176,6 +199,18 @@ export default function Home() {
</h2>
<p>Instantly deploy your Next.js site to a shareable URL with Vercel.</p>
</a>
<Button
sx={{
color: 'red',
backgroundColor: 'blue',
'&:hover': {
color: 'blue',
backgroundColor: 'red',
},
}}
>
Hello
</Button>
</div>
</Main>
);
Expand Down
9 changes: 0 additions & 9 deletions apps/pigment-css-next-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"],
"references": [
{
"path": "../../packages/mui-system/tsconfig.build.json"
},
{
"path": "../../packages/mui-base/tsconfig.build.json"
},
{
"path": "../../packages/mui-material/tsconfig.build.json"
},
{
"path": "../../packages/pigment-css-react/tsconfig.json"
}
Expand Down
1 change: 0 additions & 1 deletion packages/pigment-css-react/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/processors/
/utils/
LICENSE
/private-runtime/
16 changes: 3 additions & 13 deletions packages/pigment-css-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"@emotion/styled": "^11.11.5",
"@mui/system": "^6.0.0-alpha.1",
"@mui/utils": "^6.0.0-alpha.1",
"@wyw-in-js/processor-utils": "^0.5.1",
"@wyw-in-js/shared": "^0.5.1",
"@wyw-in-js/transform": "^0.5.1",
"@wyw-in-js/processor-utils": "^0.5.3",
"@wyw-in-js/shared": "^0.5.3",
"@wyw-in-js/transform": "^0.5.3",
"clsx": "^2.1.0",
"cssesc": "^3.0.0",
"csstype": "^3.1.3",
Expand Down Expand Up @@ -91,7 +91,6 @@
"files": [
"build",
"exports",
"private-runtime",
"processors",
"theme",
"utils",
Expand Down Expand Up @@ -149,15 +148,6 @@
},
"require": "./build/RtlProvider.js",
"default": "./build/RtlProvider.js"
},
"./private-runtime": {
"types": "./private-runtime/index.d.ts",
"import": {
"types": "./private-runtime/index.d.mts",
"default": "./private-runtime/index.mjs"
},
"require": "./private-runtime/index.js",
"default": "./private-runtime/index.js"
}
},
"nx": {
Expand Down
32 changes: 0 additions & 32 deletions packages/pigment-css-react/src/private-runtime/ForwardSx.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/pigment-css-react/src/private-runtime/index.ts

This file was deleted.

Loading
Loading