Skip to content

Commit

Permalink
[docs] Improve the default theme viewer design (#39049)
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo-leal authored Sep 22, 2023
1 parent 1417736 commit b305e09
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Default theme viewer

<p class="description">Here's what the theme object looks like with the default values.</p>
<p class="description">Check out how the theme object looks like with the default values.</p>

:::warning
This is a work in progress. We're still iterating on Joy UI's default theme.
:::

## Explore

Explore the default theme:
:::info
To create your own theme, start by customizing the [theme colors](/joy-ui/customization/theme-colors/).
:::

{{"demo": "JoyDefaultTheme.js", "hideToolbar": true, "bg": "inline"}}

To create your own theme, starts with customizing the [theme colors](/joy-ui/customization/theme-colors/).
130 changes: 104 additions & 26 deletions docs/data/material/customization/default-theme/DefaultTheme.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,69 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { createTheme } from '@mui/material/styles';
import Divider from '@mui/material/Divider';
import { createTheme, styled } from '@mui/material/styles';
import FormControlLabel from '@mui/material/FormControlLabel';
import Switch from '@mui/material/Switch';
import { useTranslate } from 'docs/src/modules/utils/i18n';
import ThemeViewer, {
useNodeIdsLazy,
} from 'docs/src/modules/components/ThemeViewer';
import { blue, grey } from 'docs/src/modules/brandingTheme';

const StyledSwitch = styled(Switch)(({ theme }) => [
{
display: 'flex',
padding: 0,
width: 32,
height: 20,
borderRadius: 99,
'&:active': {
'& .MuiSwitch-thumb': {
width: 16,
},
'& .MuiSwitch-switchBase.Mui-checked': {
transform: 'translateX(9px)',
},
},
'& .MuiSwitch-switchBase': {
padding: 2,
'&.Mui-checked': {
transform: 'translateX(12px)',
color: '#FFF',
'& + .MuiSwitch-track': {
opacity: 1,
backgroundColor: blue[500],
},
},
},
'& .MuiSwitch-thumb': {
width: 16,
height: 16,
borderRadius: 99,
transition: theme.transitions.create(['width'], {
duration: 200,
}),
},
'& .MuiSwitch-track': {
borderRadius: 16 / 2,
opacity: 1,
backgroundColor: grey[400],
boxSizing: 'border-box',
},
[`:where(${theme.vars ? '[data-mui-color-scheme="dark"]' : '.mode-dark'}) &`]: {
'& .MuiSwitch-switchBase': {
'&.Mui-checked': {
'& + .MuiSwitch-track': {
backgroundColor: blue[500],
},
},
},
'& .MuiSwitch-track': {
backgroundColor: grey[700],
},
},
},
]);

function DefaultTheme() {
const [checked, setChecked] = React.useState(false);
Expand Down Expand Up @@ -58,31 +115,52 @@ function DefaultTheme() {

return (
<Box sx={{ width: '100%' }}>
<FormControlLabel
sx={{ pb: 1 }}
control={
<Switch
checked={checked}
onChange={(event) => {
setChecked(event.target.checked);
setExpandPaths(event.target.checked ? allNodeIds : []);
}}
/>
}
label={t('expandAll')}
/>
<FormControlLabel
sx={{ pb: 1 }}
control={
<Switch
checked={darkTheme}
onChange={(event) => {
setDarkTheme(event.target.checked);
}}
/>
}
label={t('useDarkTheme')}
/>
<Box sx={{ display: 'flex', gap: 2, mb: 3 }}>
<FormControlLabel
label={t('expandAll')}
sx={{
m: 0,
flexDirection: 'row-reverse',
gap: 1,
'& .MuiFormControlLabel-label': {
fontFamily: 'IBM Plex Sans',
color: 'text.secondary',
},
}}
control={
<StyledSwitch
size="small"
checked={checked}
onChange={(event) => {
setChecked(event.target.checked);
setExpandPaths(event.target.checked ? allNodeIds : []);
}}
/>
}
/>
<Divider orientation="vertical" flexItem />
<FormControlLabel
label={t('useDarkTheme')}
sx={{
m: 0,
flexDirection: 'row-reverse',
gap: 1,
'& .MuiFormControlLabel-label': {
fontFamily: 'IBM Plex Sans',
color: 'text.secondary',
},
}}
control={
<StyledSwitch
size="small"
checked={darkTheme}
onChange={(event) => {
setDarkTheme(event.target.checked);
}}
/>
}
/>
</Box>
<ThemeViewer data={data} expandPaths={expandPaths} />
</Box>
);
Expand Down
16 changes: 6 additions & 10 deletions docs/data/material/customization/default-theme/default-theme.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# Default theme viewer

<p class="description">Here's what the theme object looks like with the default values.</p>
<p class="description">Check out how the theme object looks like with the default values.</p>

## Explore

Explore the default theme object:

{{"demo": "DefaultTheme.js", "hideToolbar": true, "bg": "inline"}}
If you want to learn more about how the theme is assembled, take a look at [`material-ui/style/createTheme.js`](https://github.com/mui/material-ui/blob/-/packages/mui-material/src/styles/createTheme.js),
and the related imports which `createTheme` uses.

:::success
You can play with the documentation theme object in your browser console,
as the `theme` variable is exposed on all the documentation pages.
:::

:::warning
Please note that **the documentation site is using a custom theme**.
Please note that **the documentation site is using a custom theme** (MUI's branding).
:::

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

If you want to learn more about how the theme is assembled, take a look at [`material-ui/style/createTheme.js`](https://github.com/mui/material-ui/blob/-/packages/mui-material/src/styles/createTheme.js),
and the related imports which `createTheme` uses.
{{"demo": "DefaultTheme.js", "hideToolbar": true, "bg": "inline"}}
2 changes: 1 addition & 1 deletion docs/pages/joy-ui/customization/default-theme-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import * as pageProps from 'docs/data/joy/customization/default-theme-viewer/default-theme-viewer.md?@mui/markdown';

export default function Page() {
return <MarkdownDocs {...pageProps} />;
return <MarkdownDocs {...pageProps} disableToc />;
}
2 changes: 1 addition & 1 deletion docs/pages/material-ui/customization/default-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import * as pageProps from 'docs/data/material/customization/default-theme/default-theme.md?@mui/markdown';

export default function Page() {
return <MarkdownDocs {...pageProps} />;
return <MarkdownDocs {...pageProps} disableToc />;
}
22 changes: 18 additions & 4 deletions docs/src/modules/components/ThemeViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CollapseIcon from '@mui/icons-material/ChevronRight';
import { TreeView } from '@mui/x-tree-view/TreeView';
import { TreeItem as MuiTreeItem, treeItemClasses } from '@mui/x-tree-view/TreeItem';
import { lighten } from '@mui/material/styles';
import { blue, blueDark } from 'docs/src/modules/brandingTheme';

function getType(value: any) {
if (Array.isArray(value)) {
Expand Down Expand Up @@ -99,12 +100,18 @@ function ObjectEntryLabel(props: { objectKey: string; objectValue: any }) {

const TreeItem = styled(MuiTreeItem)({
[`&:focus > .${treeItemClasses.content}`]: {
backgroundColor: lighten('#333', 0.08),
outline: `2px dashed ${lighten('#333', 0.3)}`,
backgroundColor: lighten(blue[900], 0.05),
outline: `2px dashed ${lighten(blue[900], 0.3)}`,
},
[`& .${treeItemClasses.content}`]: {
padding: 4,
borderRadius: '12px',
'&:hover': {
backgroundColor: lighten('#333', 0.08),
backgroundColor: lighten(blueDark[900], 0.1),
},
[`& .${treeItemClasses.label}`]: {
fontFamily: 'Menlo, Consolas',
fontSize: '0.825rem',
},
},
});
Expand Down Expand Up @@ -189,13 +196,20 @@ export default function ThemeViewer({

return (
<TreeView
sx={{ bgcolor: '#333', color: '#fff', borderRadius: 1, p: 1 }}
key={key}
defaultCollapseIcon={<ExpandIcon />}
defaultEndIcon={<div style={{ width: 24 }} />}
defaultExpanded={defaultExpanded}
defaultExpandIcon={<CollapseIcon />}
{...other}
sx={{
color: '#FFF',
p: 1.5,
bgcolor: '#0F1924', // one-off code container color
borderRadius: 3,
border: '1px solid',
borderColor: blueDark[700],
}}
>
{Object.keys(data).map((objectKey) => {
return (
Expand Down

0 comments on commit b305e09

Please sign in to comment.