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

[Joy] Remove private to leverage CodeSandbox #29280

Merged
merged 9 commits into from
Oct 28, 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
9 changes: 6 additions & 3 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"packages/mui-core",
"packages/mui-styled-engine",
"packages/mui-styled-engine-sc",
"packages/mui-material-next"
"packages/mui-material-next",
"packages/mui-joy"
],
"publishDirectory": {
"@mui/codemod": "packages/mui-codemod/build",
Expand All @@ -30,12 +31,14 @@
"@mui/types": "packages/mui-types/build",
"@mui/utils": "packages/mui-utils/build",
"@mui/core": "packages/mui-core/build",
"@mui/material-next": "packages/mui-material-next/build"
"@mui/material-next": "packages/mui-material-next/build",
"@mui/joy": "packages/mui-joy/build"
},
"sandboxes": [
"material-ui-issue-dh2yh",
"github/mui-org/material-ui/tree/HEAD/examples/create-react-app",
"github/mui-org/material-ui/tree/HEAD/examples/create-react-app-with-typescript"
"github/mui-org/material-ui/tree/HEAD/examples/create-react-app-with-typescript",
"github/mui-org/material-ui/tree/HEAD/examples/joy-cra-typescript"
],
"silent": true
}
27 changes: 27 additions & 0 deletions examples/joy-cra-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# IDEs and editors
/.idea
/.vscode

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
27 changes: 27 additions & 0 deletions examples/joy-cra-typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Create React App example with TypeScript

## `@mui/joy` is still in early development, DO NOT use it in production.

## How to use

Download the example [or clone the repo](https://github.com/mui-org/material-ui):

<!-- #default-branch-switch -->

```sh
curl https://codeload.github.com/mui-org/material-ui/tar.gz/master | tar -xz --strip=2 material-ui-master/examples/joy-cra-typescript
cd joy-cra-typescript
```

Install it and run:

```sh
npm install
npm start
```

or:

<!-- #default-branch-switch -->

[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/mui-org/material-ui/tree/master/examples/joy-cra-typescript)
22 changes: 22 additions & 0 deletions examples/joy-cra-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "joy-cra-typescript",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "latest",
"@emotion/styled": "latest",
"@mui/joy": "latest",
"@types/react": "latest",
"@types/react-dom": "latest",
"react": "latest",
"react-dom": "latest",
"react-scripts": "latest",
"typescript": "latest"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
}
Binary file added examples/joy-cra-typescript/public/favicon.ico
Binary file not shown.
40 changes: 40 additions & 0 deletions examples/joy-cra-typescript/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>My page</title>
<!-- Fonts to support Material Design -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions examples/joy-cra-typescript/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "Your Orders",
"name": "Your Orders",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
11 changes: 11 additions & 0 deletions examples/joy-cra-typescript/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import { CssVarsProvider } from '@mui/joy/styles';
import Button from '@mui/joy/Button';

export default function App() {
return (
<CssVarsProvider>
Copy link
Member

Choose a reason for hiding this comment

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

Would suggest removing it, to indicate that it is not necessary if no theme is provided, or provide a custom theme :)

Copy link
Member

Choose a reason for hiding this comment

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

Also, probably the theme should be required, no? Otherwise, what is the point of adding a provider without the theme?

Copy link
Member Author

@siriwatknp siriwatknp Oct 26, 2021

Choose a reason for hiding this comment

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

I think CssVarsProvider is what we will use the most, so I put it as default here. (We can change it in the future if we have a better way but for now I think it is good enough)

probably the theme should be required

The theme is not required because of the default theme. However, CssVarsProvider is required, otherwise, how do we turn the default theme to CSS variables.

Copy link
Member

Choose a reason for hiding this comment

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

Wait, I thought joy's default theme already crates the variables. Does this mean that whoever uses the joy's design system will need to wrap the app in CssVarsProvider? If yes, then this breaks the zero configuration approach we had till now.

Copy link
Member Author

@siriwatknp siriwatknp Oct 27, 2021

Choose a reason for hiding this comment

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

Does this mean that whoever uses the joy's design system will need to wrap the app in CssVarsProvider

No. You can start with plain Button same as @mui/material:

import Button from '@mui/joy/Button';

<Button> // this should work

You are still able to access the default theme as usual but you won't get the global theme CSS variables attached to your app (some components might have CSS variables because it is the component scope).

If you want to use CSS variables from your theme, you will need to wrap your app with CssVarsProvider.

You can consider CssVarsProvider as a feature on top of ThemeProvider.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am still reluctant about attaching CSS variables automatically without using CssVarsProvider. I think it can be tested in the future but not a blocker at this point.

<Button>Button</Button>
</CssVarsProvider>
);
}
5 changes: 5 additions & 0 deletions examples/joy-cra-typescript/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(<App />, document.querySelector('#root'));
1 change: 1 addition & 0 deletions examples/joy-cra-typescript/src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react-scripts" />
19 changes: 19 additions & 0 deletions examples/joy-cra-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": ["src"]
}
4 changes: 2 additions & 2 deletions packages/mui-joy/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mui/joy",
"version": "0.1.0-alpha.1",
"private": true,
"version": "0.1.0-alpha.0",
"private": false,
"author": "MUI Team",
"description": "Joy design system — React components",
"main": "./src/index.ts",
Expand Down
21 changes: 21 additions & 0 deletions packages/mui-joy/src/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';
import PropTypes from 'prop-types';

export type ButtonProps = JSX.IntrinsicElements['button'];

const Button = (props: ButtonProps) => {
return <button type="button" {...props} />;
};

Button.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* @ignore
*/
children: PropTypes.node,
} as any;

export default Button;
2 changes: 2 additions & 0 deletions packages/mui-joy/src/Button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './Button';
export * from './Button';
3 changes: 2 additions & 1 deletion packages/mui-joy/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export default {};
export { default as Button } from './Button';
export * from './Button';