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

[docs] Add example for using styled-components as styled-engine #22788

Merged
merged 36 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c2d31cc
add emotion peer dependencies
mnajdova Sep 25, 2020
5ae933f
fixed types & tests
mnajdova Sep 25, 2020
18b0668
prettier
mnajdova Sep 25, 2020
f0ef95c
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 28, 2020
583d557
added example project
mnajdova Sep 28, 2020
0bdbd9d
name fix
mnajdova Sep 28, 2020
c7bebb8
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 28, 2020
92b2d6e
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 28, 2020
22e0700
prettier
mnajdova Sep 28, 2020
1598adf
changed example to use create-react-app
mnajdova Sep 28, 2020
4205477
updated project name
mnajdova Sep 28, 2020
77d956d
prettier
mnajdova Sep 28, 2020
8c85d35
removed eslintConfig
mnajdova Sep 28, 2020
3fcb447
removed App test
mnajdova Sep 28, 2020
69f6f7b
updated create-react-app package
mnajdova Sep 28, 2020
9b58298
changed version in example
mnajdova Sep 28, 2020
e4467ba
Update examples/create-react-app-with-styled-components-engine/src/Ap…
mnajdova Sep 28, 2020
735d705
Update examples/create-react-app-with-styled-components-engine/src/Ap…
mnajdova Sep 28, 2020
499c0d6
removed index.css
mnajdova Sep 28, 2020
33c7424
Update examples/create-react-app/package.json
mnajdova Sep 28, 2020
d554f85
Update examples/create-react-app-with-styled-components-engine/packag…
mnajdova Sep 28, 2020
be1c594
Update examples/create-react-app-with-styled-components-engine/packag…
mnajdova Sep 28, 2020
3d4d4c4
Update examples/create-react-app-with-styled-components-engine/public…
mnajdova Sep 28, 2020
c6f4e5b
removed index.css import
mnajdova Sep 28, 2020
56876d8
removed unreferenced aria-labelledby
mnajdova Sep 29, 2020
1fa072d
Update docs/src/pages/getting-started/example-projects/example-projec…
mnajdova Sep 29, 2020
13da531
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 29, 2020
398ccd2
Merge branch 'next' into feat/add-styled-components-example
mnajdova Sep 29, 2020
b79fb3e
prettier
mnajdova Sep 29, 2020
f679732
Merge branch 'feat/add-styled-components-example' of https://github.c…
mnajdova Sep 29, 2020
436f3a1
Update examples/create-react-app-with-styled-components-engine/packag…
mnajdova Sep 29, 2020
171efee
renamed example & improved description
mnajdova Sep 29, 2020
c97e82f
Merge branch 'feat/add-styled-components-example' of https://github.c…
mnajdova Sep 29, 2020
a3095e1
renamed project name
mnajdova Sep 29, 2020
a6fc69c
added styled-components link
mnajdova Sep 29, 2020
f314d6f
prettier
mnajdova Sep 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ You can find some example projects in the [GitHub repository](https://github.com
- [Preact](https://github.com/mui-org/material-ui/tree/next/examples/preact)
- [CDN](https://github.com/mui-org/material-ui/tree/next/examples/cdn)
- [Plain server-side](https://github.com/mui-org/material-ui/tree/next/examples/ssr)
- [Use styled-components as styled engine](https://github.com/mui-org/material-ui/tree/next/examples/create-react-app-with-styled-components-engine)
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
- And more

Create React App is an awesome project for learning React.
Expand Down
23 changes: 23 additions & 0 deletions examples/create-react-app-with-styled-components-engine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

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

npm-debug.log*
yarn-debug.log*
yarn-error.log*
68 changes: 68 additions & 0 deletions examples/create-react-app-with-styled-components-engine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `yarn build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { addWebpackAlias, override } = require('customize-cra');

module.exports = override(
addWebpackAlias({
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the part that does the aliasing

'@material-ui/styled-engine': '@material-ui/styled-engine-sc',
}),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "create-react-app-with-styled-components-engine",
"version": "0.1.0",
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
"private": true,
"dependencies": {
"@material-ui/core": "next",
"@material-ui/lab": "next",
"@material-ui/styled-engine-sc": "next",
"@testing-library/jest-dom": "latest",
"@testing-library/react": "latest",
"@testing-library/user-event": "latest",
"react": "latest",
"react-dom": "latest",
"react-scripts": "latest",
"styled-components": "latest"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"customize-cra": "latest",
"react-app-rewired": "latest"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
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>React App</title>
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
<!-- 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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
23 changes: 23 additions & 0 deletions examples/create-react-app-with-styled-components-engine/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import Slider from '@material-ui/lab/SliderStyled';
import Typography from '@material-ui/core/Typography';

export default function App() {
return (
<div>
<Typography>Styled slider powered by styled-components</Typography>
<Slider defaultValue={30} aria-labelledby="primary-slider" color="primary" />
eps1lon marked this conversation as resolved.
Show resolved Hide resolved
<Slider defaultValue={30} aria-labelledby="secondary-slider" color="secondary" />
<Slider defaultValue={30} disabled />
<Slider
defaultValue={30}
aria-labelledby="discrete-slider"
valueLabelDisplay="auto"
step={10}
marks
min={10}
max={110}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
<React.StrictMode>
Copy link
Member

Choose a reason for hiding this comment

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

Nice, can't wait to be able to add that everywhere.

<App />
</React.StrictMode>,
document.getElementById('root'),
);

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();