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] Add palette customizer #35741

Merged
merged 50 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b18ad99
add theme builder
siriwatknp Jan 6, 2023
943b93a
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Jan 9, 2023
775ecdf
fix default values
siriwatknp Jan 10, 2023
6c4bf4c
add GlobalVariantForm
siriwatknp Jan 10, 2023
61c4830
add disableCssVarsProvider
siriwatknp Jan 10, 2023
e472d45
complete global variant
siriwatknp Jan 10, 2023
1912699
add etc tokens
siriwatknp Jan 10, 2023
d8c4a78
update how to
siriwatknp Jan 10, 2023
81a93b3
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Jan 25, 2023
87fbbcd
temp
siriwatknp Jan 26, 2023
f301f7f
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Jan 27, 2023
e9a5bfd
fix ux/ui
siriwatknp Jan 27, 2023
9e89899
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Jan 30, 2023
8643b50
update content
siriwatknp Jan 30, 2023
899bceb
fix lint
siriwatknp Jan 30, 2023
7ecfcee
fix lint
siriwatknp Jan 31, 2023
499b9f2
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Feb 9, 2023
c1b1bd1
fix interface generation
siriwatknp Feb 9, 2023
ce105eb
tweak the copy
danilo-leal Feb 13, 2023
4147b0e
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Feb 27, 2023
a52208c
improve experience
siriwatknp Feb 27, 2023
1e5d7b5
run docs:i18n
siriwatknp Feb 27, 2023
583af62
fix lint
siriwatknp Feb 27, 2023
167972f
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Feb 28, 2023
990a926
add comment
siriwatknp Feb 28, 2023
4947e7d
add template modal
siriwatknp Feb 28, 2023
ac579c7
Finish theme builder
siriwatknp Feb 28, 2023
6d982e8
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Mar 20, 2023
2b76471
Merge branch 'joy/theme-builder' of https://github.com/siriwatknp/mat…
danilo-leal Mar 21, 2023
8e21bed
design customizations to the JoyThemeBuilder component
danilo-leal Mar 21, 2023
bfd4723
simplifying copywriting
danilo-leal Mar 21, 2023
b94b340
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Mar 21, 2023
c5e985c
Merge branch 'joy/theme-builder' of github.com:siriwatknp/material-ui…
siriwatknp Mar 21, 2023
dc28531
fix CSS variables
siriwatknp Mar 21, 2023
1c99e10
extract joy template sourcing
siriwatknp Mar 21, 2023
7bddf19
refactor open codesandbox
siriwatknp Mar 21, 2023
ef8ec87
refactor stackblitz
siriwatknp Mar 21, 2023
dd23f7c
extract generateThemeAugmentation
siriwatknp Mar 21, 2023
32e438f
extract literalToObject and minimal template string
siriwatknp Mar 21, 2023
cb1ee5d
minor style update
siriwatknp Mar 21, 2023
abca396
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Mar 21, 2023
abf580a
run prettier
siriwatknp Mar 21, 2023
bea8e53
run docs:api
siriwatknp Mar 21, 2023
45d2d0d
minor style tweaks
danilo-leal Mar 21, 2023
247e330
sync color mode with docs
siriwatknp Mar 21, 2023
a8aab54
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Mar 21, 2023
ec3bfad
Merge branch 'joy/theme-builder' of github.com:siriwatknp/material-ui…
siriwatknp Mar 21, 2023
a66b54d
remove fallback color from placeholder
siriwatknp Mar 21, 2023
47c013f
copy writing
siriwatknp Mar 22, 2023
eb73839
Merge branch 'master' of https://github.com/mui/material-ui into joy/…
siriwatknp Mar 22, 2023
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
10 changes: 10 additions & 0 deletions docs/data/joy/customization/theme-builder/theme-builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Theme builder

<p class="description">Tools for tailoring your custom Joy UI theme.</p>

## Colors

Use the visual color palette builder below to output a code snippet that you can quickly copy and poste onto your codebase.
For more details about how colors are strucured and work in Joy UI, [read the Colors page](/joy-ui/customization/theme-colors/).

{{"component": "modules/components/JoyThemeBuilder.tsx"}}
70 changes: 17 additions & 53 deletions docs/data/joy/getting-started/templates/TemplateCollection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import LZString from 'lz-string';
import startCase from 'lodash/startCase';
import NextLink from 'next/link';
import AspectRatio from '@mui/joy/AspectRatio';
Expand All @@ -13,28 +12,7 @@ import Typography from '@mui/joy/Typography';
import SvgIcon from '@mui/joy/SvgIcon';
import Visibility from '@mui/icons-material/Visibility';
import codeSandbox from 'docs/src/modules/sandbox/CodeSandbox';
import extractTemplates from 'docs/src/modules/utils/extractTemplates';

const cache = {};
const req = require.context('./?raw', true, /^\.\/[^/]+\/.*\.(js|tsx|ts)$/);
req.keys().forEach((key) => {
cache[key] = req(key);
});

function compress(object) {
return LZString.compressToBase64(JSON.stringify(object))
.replace(/\+/g, '-') // Convert '+' to '-'
.replace(/\//g, '_') // Convert '/' to '_'
.replace(/=+$/, ''); // Remove ending '='
}

function addHiddenInput(form, name, value) {
const input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = value;
form.appendChild(input);
}
import sourceJoyTemplates from 'docs/src/modules/joy/sourceJoyTemplates';

/**
* To display a template on the site:
Expand Down Expand Up @@ -77,10 +55,10 @@ const AUTHORS = {

export default function TemplateCollection() {
const newTemplates = ['order-dashboard', 'sign-in-side']; // Stay at the top of the page with `new` badge
const templates = extractTemplates(cache);
const { names: templateNames, map: templateMap } = sourceJoyTemplates();
const names = [
...newTemplates,
...Object.keys(templates).filter((name) => !newTemplates.includes(name)),
...templateNames.filter((name) => !newTemplates.includes(name)),
];
return (
<List
Expand All @@ -93,7 +71,7 @@ export default function TemplateCollection() {
}}
>
{names.map((name) => {
const item = templates[name];
const item = templateMap.get(name);
const author = AUTHORS[name];
return (
<Card
Expand Down Expand Up @@ -231,33 +209,19 @@ export default function TemplateCollection() {
data-ga-event-category="joy-template"
data-ga-event-label={name}
data-ga-event-action="codesandbox"
onClick={() => {
const { files } = codeSandbox.createJoyTemplate({
...item,
title: `${startCase(name)} Template - Joy UI`,
githubLocation: `${process.env.SOURCE_CODE_REPO}/blob/v${
process.env.LIB_VERSION
}/docs/data/joy/templates/${name}/App.${
item.codeVariant === 'TS' ? 'tsx' : 'js'
}`,
});
const parameters = compress({ files });

// ref: https://codesandbox.io/docs/api/#define-api
const form = document.createElement('form');
form.method = 'POST';
form.target = '_blank';
form.action = 'https://codesandbox.io/api/v1/sandboxes/define';
addHiddenInput(form, 'parameters', parameters);
addHiddenInput(
form,
'query',
item.codeVariant === 'TS' ? 'file=/App.tsx' : 'file=/App.js',
);
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
}}
onClick={() =>
codeSandbox
.createJoyTemplate({
...item,
title: `${startCase(name)} Template - Joy UI`,
githubLocation: `${process.env.SOURCE_CODE_REPO}/blob/v${
process.env.LIB_VERSION
}/docs/data/joy/templates/${name}/App.${
item.codeVariant === 'TS' ? 'tsx' : 'js'
}`,
})
.openSandbox()
}
>
<SvgIcon viewBox="0 0 1080 1080">
<path d="M755 140.3l0.5-0.3h0.3L512 0 268.3 140h-0.3l0.8 0.4L68.6 256v512L512 1024l443.4-256V256L755 140.3z m-30 506.4v171.2L548 920.1V534.7L883.4 341v215.7l-158.4 90z m-584.4-90.6V340.8L476 534.4v385.7L300 818.5V646.7l-159.4-90.6zM511.7 280l171.1-98.3 166.3 96-336.9 194.5-337-194.6 165.7-95.7L511.7 280z" />
Expand Down
11 changes: 9 additions & 2 deletions docs/data/joy/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const pages = [
children: [
{ pathname: '/joy-ui/customization/approaches' },
{ pathname: '/joy-ui/customization/dark-mode' },
{ pathname: '/joy-ui/customization/using-css-variables', title: 'Using CSS variables' },
{
pathname: '/joy-ui/customization/theme',
subheader: 'Theme',
Expand All @@ -117,8 +118,14 @@ const pages = [
{ pathname: '/joy-ui/customization/themed-components', title: 'Components' },
],
},
{ pathname: '/joy-ui/customization/using-css-variables', title: 'Using CSS variables' },
{ pathname: '/joy-ui/customization/default-theme-viewer' },
{
subheader: 'Tools',
pathname: '/joy-ui/customization/tool',
children: [
{ pathname: '/joy-ui/customization/default-theme-viewer' },
{ pathname: '/joy-ui/customization/theme-builder' },
],
},
],
},
{
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/joy-ui/customization/theme-builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import * as pageProps from 'docs/data/joy/customization/theme-builder/theme-builder.md?@mui/markdown';

export default function Page() {
return <MarkdownDocs {...pageProps} disableCssVarsProvider />;
}
68 changes: 2 additions & 66 deletions docs/src/modules/components/DemoToolbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import copy from 'clipboard-copy';
import LZString from 'lz-string';
import { useTheme, styled } from '@mui/material/styles';
import IconButton from '@mui/material/IconButton';
import useMediaQuery from '@mui/material/useMediaQuery';
Expand All @@ -27,21 +26,6 @@ import { useRouter } from 'next/router';
import codeSandbox from '../sandbox/CodeSandbox';
import stackBlitz from '../sandbox/StackBlitz';

function compress(object) {
return LZString.compressToBase64(JSON.stringify(object))
.replace(/\+/g, '-') // Convert '+' to '-'
.replace(/\//g, '_') // Convert '/' to '_'
.replace(/=+$/, ''); // Remove ending '='
}

function addHiddenInput(form, name, value) {
const input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = value;
form.appendChild(input);
}

const Root = styled('div')(({ theme }) => ({
display: 'none',
[theme.breakpoints.up('sm')]: {
Expand Down Expand Up @@ -264,54 +248,6 @@ export default function DemoToolbar(props) {
}
};

const handleCodeSandboxClick = () => {
const { files } = codeSandbox.createReactApp(demoData);
const parameters = compress({ files });

// ref: https://codesandbox.io/docs/api/#define-api
const form = document.createElement('form');
form.method = 'POST';
form.target = '_blank';
form.action = 'https://codesandbox.io/api/v1/sandboxes/define';
addHiddenInput(form, 'parameters', parameters);
addHiddenInput(
form,
'query',
codeVariant === CODE_VARIANTS.TS ? 'file=/demo.tsx' : 'file=/demo.js',
);
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
};

const handleStackBlitzClick = () => {
const demoConfig = stackBlitz.createReactApp(demoData);

// ref: https://developer.stackblitz.com/docs/platform/post-api/
const form = document.createElement('form');
form.method = 'POST';
form.target = '_blank';
form.action = `https://stackblitz.com/run?file=demo.${
codeVariant === CODE_VARIANTS.TS ? 'tsx' : 'js'
}`;
addHiddenInput(form, 'project[template]', 'create-react-app');
addHiddenInput(form, 'project[title]', demoConfig.title);
addHiddenInput(
form,
'project[description]',
`# ${demoConfig.title}\n${demoConfig.description}`,
);
addHiddenInput(form, 'project[dependencies]', JSON.stringify(demoConfig.dependencies));
addHiddenInput(form, 'project[devDependencies]', JSON.stringify(demoConfig.devDependencies));
Object.keys(demoConfig.files).forEach((key) => {
const value = demoConfig.files[key];
addHiddenInput(form, `project[files][${key}]`, value);
});
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
};

const [anchorEl, setAnchorEl] = React.useState(null);
const handleMoreClick = (event) => {
setAnchorEl(event.currentTarget);
Expand Down Expand Up @@ -538,7 +474,7 @@ export default function DemoToolbar(props) {
data-ga-event-category="demo"
data-ga-event-label={demo.gaLabel}
data-ga-event-action="codesandbox"
onClick={handleCodeSandboxClick}
onClick={() => codeSandbox.createReactApp(demoData).openSandbox('/demo')}
{...getControlProps(3)}
>
<SvgIcon viewBox="0 0 1024 1024">
Expand All @@ -552,7 +488,7 @@ export default function DemoToolbar(props) {
data-ga-event-category="demo"
data-ga-event-label={demo.gaLabel}
data-ga-event-action="stackblitz"
onClick={handleStackBlitzClick}
onClick={() => stackBlitz.createReactApp(demoData).openSandbox('demo')}
{...getControlProps(4)}
>
<SvgIcon viewBox="0 0 19 28">
Expand Down
Loading