Skip to content
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
8b7db60
add Connect-related content on the documentation
danilo-leal Jan 29, 2024
8ab0f54
update content and image
danilo-leal Feb 13, 2024
55d31ba
update border color on dark mode
danilo-leal Feb 13, 2024
7e94a1a
iterate on the Design kits paragraph
danilo-leal Feb 13, 2024
36db8ab
Merge branch 'master' into connect-documentation-content
danilo-leal Feb 13, 2024
8e0ce99
add first skeleton of the documentation
danilo-leal Feb 15, 2024
fbffcd9
run pnpm docs:i18n
danilo-leal Feb 15, 2024
d2885a7
add image to the top of the page
danilo-leal Feb 15, 2024
66ca88b
continue iterating on it
danilo-leal Feb 15, 2024
b902cc1
iterating on the existing tokens section
danilo-leal Feb 16, 2024
119888c
trigger CI checks
danilo-leal Feb 19, 2024
52fba0e
add the Material UI design kit docs
danilo-leal Feb 21, 2024
28a3ff9
Merge branch 'master' into connect-documentation-content
danilo-leal Feb 21, 2024
7c8f7f8
run docs:i18n
danilo-leal Feb 21, 2024
e9a8c44
reordering the pages
danilo-leal Feb 21, 2024
db30f41
run docs:i18n
danilo-leal Feb 21, 2024
6ed171b
remove the MUI prefix from Connect
danilo-leal Feb 28, 2024
7241d3b
remove markdown image element changes from this PR
danilo-leal Feb 28, 2024
6073fb5
run docs:i18n
danilo-leal Feb 28, 2024
b8a9d49
Merge branch 'master' into connect-documentation-content
danilo-leal Feb 28, 2024
917be65
Merge branch 'master' into connect-documentation-content
danilo-leal Mar 1, 2024
0650865
update links to remove the "mui" prefix
danilo-leal Mar 1, 2024
4422995
remove dash from "plugin"
danilo-leal Mar 1, 2024
9d1ce9d
fix error regarding the muiMarkdown import
danilo-leal Mar 4, 2024
a0eaa96
add YouTube videos embeds for the design kits
danilo-leal Mar 4, 2024
bb0dcf0
update Connect images
danilo-leal Mar 4, 2024
b55e401
remove the new chip from the design kit page
danilo-leal Mar 4, 2024
43c6070
iterating on the wording
danilo-leal Mar 8, 2024
c4d320d
Sam's first pass
danilo-leal Mar 25, 2024
63d75a7
Merge branch 'next' into connect-documentation-content
danilo-leal Mar 25, 2024
4821dd4
fix Vale brand name CI check
danilo-leal Mar 25, 2024
e5a6857
Merge branch 'next' into connect-documentation-content
danilo-leal Mar 27, 2024
8000746
add beta chip on the nav drawer item
danilo-leal Mar 28, 2024
baf0238
update the Connect page description
danilo-leal Mar 29, 2024
83ec809
lint: fix non-breaking space
danilo-leal Mar 29, 2024
06f85dc
added getting started section
DavidCnoops Apr 4, 2024
cabb22d
Vale lint: non-breaking space
danilo-leal Apr 4, 2024
8dbe6a2
formatting and adjustments
danilo-leal Apr 4, 2024
5702773
edit the design resources page
danilo-leal Apr 4, 2024
4179064
update to the design kits page
danilo-leal Apr 4, 2024
d22046d
Merge branch 'next' into connect-documentation-content
danilo-leal Apr 4, 2024
0acbe09
Vale lint: fix non-breaking space
danilo-leal Apr 4, 2024
f1d2bce
iterate and fix things on the content + add images
danilo-leal Apr 5, 2024
53b589c
add video about component customization
danilo-leal Apr 5, 2024
e0ea786
extra: fix Demo border styles
danilo-leal Apr 5, 2024
7f6457a
add content about code customizations
danilo-leal Apr 5, 2024
6ffb992
rerun CI checks again
danilo-leal Apr 5, 2024
1199a00
rerun CI checks again
danilo-leal Apr 5, 2024
e549426
Sam's Connect page review
danilo-leal Apr 5, 2024
3d28b19
Sam's review of the Material UI Design Kit page
danilo-leal Apr 5, 2024
bd6f6a6
Design Resources page review
danilo-leal Apr 5, 2024
1891e88
ensure there's non-breaking space
danilo-leal Apr 5, 2024
446741c
follow-up edits
danilo-leal Apr 5, 2024
0198a40
update the Connect page
danilo-leal Apr 8, 2024
f54724a
update the Material UI for Figma page
danilo-leal Apr 9, 2024
31e4bc5
update the Design resources page
danilo-leal Apr 9, 2024
41a8875
slightly revise the Material UI for Figma page
danilo-leal Apr 9, 2024
42f81a0
Vale lint: non-breakable space
danilo-leal Apr 9, 2024
1dfc377
various changes and tweaks
DavidCnoops Apr 9, 2024
53de30a
updated connect docs
DavidCnoops Apr 10, 2024
f2b83d9
updates to the Connect page
danilo-leal Apr 10, 2024
77516db
updates to the Material UI page
danilo-leal Apr 10, 2024
2bc570d
remove unused video
danilo-leal Apr 10, 2024
eee0ae0
compress all images
danilo-leal Apr 10, 2024
33852e8
Vale lint: non-breaking space
danilo-leal Apr 10, 2024
e0f36ee
remove changes on the Demo component
danilo-leal Apr 10, 2024
42050a3
rerun CI checks
danilo-leal Apr 10, 2024
ef9506f
small tweaks
DavidCnoops Apr 11, 2024
27c7b4e
fix linting error
DavidCnoops Apr 11, 2024
dfbee60
has selector clarification + removal of last example
DavidCnoops Apr 11, 2024
34b792a
fix linting error
DavidCnoops Apr 11, 2024
6eac877
Connect page updates
danilo-leal Apr 11, 2024
c2819b5
Material UI for Figma updates
danilo-leal Apr 11, 2024
f891ea5
Design Resources updates
danilo-leal Apr 11, 2024
f41058a
additional edits
danilo-leal Apr 11, 2024
6e53321
Vale lint: non-breakable space
danilo-leal Apr 11, 2024
b3df62e
fine-tune images
danilo-leal Apr 11, 2024
7f47327
Vale lint: non-breakable space
danilo-leal Apr 11, 2024
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
298 changes: 298 additions & 0 deletions docs/data/material/design-resources/connect/connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
# Connect plugin

<p class="description">Connect is a Figma plugin that generates Material UI themes directly from design to code.</p>

## Introduction

[Connect](https://www.figma.com/community/plugin/1336346114713490235/) is a Figma plugin that lets you generate a theme from the [Material UI for Figma Design Kit](https://www.figma.com/community/file/912837788133317724/material-ui-for-figma-and-mui-x/).
Customize the Design Kit's tokens and components, and run the Connect plugin to generate a theme ready for use in your Material UI based projects.

:::warning
Connect works in combination with the Material UI for Figma Design Kit [v5.16.0 and later](https://github.com/mui/mui-design-kits/releases).
Other kits, such as the Joy UI Design Kit, are not yet supported.
:::

<img src="/static/material-ui/design-resources/connect.png" style="width: 814px;" alt="Customizing the Material UI Switch component in Figma with the Connect plugin running." width="1628" height="400" />

## Running the plugin

If you don't have [the complete and latest](/store/items/figma-react/) Material UI Design Kit version installed, you can test the plugin by using [the Community version](https://www.figma.com/community/file/912837788133317724/material-ui-for-figma-and-mui-x/) instead.

After installing it, open the Design Kit file in Figma.
Then head over to [the Connect plugin page](https://www.figma.com/community/plugin/1336346114713490235/) on Figma's Community tab and click on **Open in...** and select the Material UI for Figma Design Kit.

<img src="/static/material-ui/design-resources/connect-access.png" style="width: 814px;" alt="Accessing Connect via the Resources menu in Figma." width="1628" height="400" />

## Customizing design tokens

The Design Kit's design tokens are defined in the [local variable collections](https://help.figma.com/hc/en-us/articles/15145852043927-Create-and-manage-variables) for color palettes, breakpoints, shapes & spacing tokens, and in [local effect and text styles](https://help.figma.com/hc/en-us/articles/360039820134-Manage-and-share-styles#:~:text=Local%20styles%20are%20styles%20that,or%20from%20the%20style%20picker.) for shadow and typography tokens. You can freely alter or extend these tokens to customize the look and feel of your design system, and use Connect to generate a theme containing your customizations.

### Altering existing tokens

The Material UI Design Kit comes fully loaded with design tokens that map out to [the default theme of the Material UI React library](/material-ui/customization/default-theme/).

To customize tokens defined by Figma variables, open the local variables modal by clicking on the filter icon as shown below.
Tweak any of the variables available in the various collections (palette, breakpoints, shapes & spacing) as you see fit.

<img src="/static/material-ui/design-resources/connect-variables.png" style="width: 814px; margin-bottom: 8px;" alt="The Locals variables menu in Figma, where all design tokens are stored and new ones can be added." width="1628" height="400" />

Then open the Connect plugin and click on **Generate theme**.

<img src="/static/material-ui/design-resources/connect-generate.png" style="width: 814px" alt="The Generate theme button in the Connect plugin UI." width="1628" height="400" />

A theme containing the altered tokens is generated and displayed in the plugin's **Theme** tab.

<img src="/static/material-ui/design-resources/connect-code-editor.png" style="width: 814px" alt="The generated theme displayed in the Connect plugin UI." width="1628" height="400" />

Preview the generated theme and your customized tokens by navigating to the **Storybook preview** tab.

<img src="/static/material-ui/design-resources/connect-storybook.png" style="width: 814px" alt="The generated theme previewed in Storybook in the Connect plugin UI." width="1628" height="400" />

### Adding new tokens

You can also extend the existing tokens with your own by either adding new variables to the existing local variable collections, or by adding new elevation and typography styles.
After you've added your custom tokens, click on **Regenerate theme** to includes these tokens in your theme.

<img src="/static/material-ui/design-resources/connect-regenerate.png" style="width: 814px" alt="The 'Regenerate button' in the Connect plugin UI." width="1628" height="400" />

## Customizing components

Connect can also generate theme styles for customized components. This feature is currently limited to the **Button** and **Switch** components. Support for more components will follow soon.

:::warning
Please note that the Desing Kit's component layer hierarchy and layer names should remain unaltered in order for Connect to correctly extract the custom component styles and generate a theme for them.
:::

<video controls muted loop width="1584" height="1080" style="border-radius: 12px; border: 1px solid; border-color: hsla(0, 0%, 0%, .1);">
  <source src="/static/material-ui/design-resources/custom-component.mp4" type="video/mp4">
</video>

You can customize components by changing the look and feel of component variants in the Desing Kit.

Each variant represents a specific version of a component defined by its variant properties (e.g. color, size, state, ...). These properties map to Material UI props and states. For example, the `Checked=True, Size=Medium, Color=Primary, State=Enabled` Switch variant in Figma maps to `<Switch color="primary" size="medium" checked={true} disabled={false} />` in Material UI.

### Customizing component variants

In the example below we've customized the `Checked=True, Size=Medium, Color=Primary, State=Enabled` variant of the Switch component to look like an iOS switch.

<img src="/static/material-ui/design-resources/connect-component-variant.png" style="width: 814px" alt="A specific variant of the Switch component selected in the Design Kit" width="1628" height="400" />

Connect will generate the following theme:

```js
{
components: {
MuiSwitch: {
styleOverrides: {
root: {
'&.MuiSwitch-sizeMedium:has(.MuiSwitch-colorPrimary)': {
'&:has(.Mui-checked):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible))':
{
width: '40px',
height: '21px',
padding: '0',
'& .MuiSwitch-switchBase': {
transform: 'translateX(19px) translateY(2px)',
padding: '0',
'& .MuiSwitch-thumb': {
width: '17px',
height: '17px',
background: '#FAFAFA',
},
'& + .MuiSwitch-track': {
width: '38px',
height: '21px',
background: 'var(--mui-palette-success-light)',
opacity: '1',
},
},
},
},
},
},
},
},
}
```

As you can see, the generated theme targets the class names matching the specific variant we've altered in Figma. As we've only customized one variant in Figma the resulting theme will only apply our iOS style when the Switch component props and state exactly match those of the customized variant.

In order to deal with all the states the Switch can be in we have to alter the sibling variants in Figma as well. For example, let's say we fully want to customize Switch component of size `medium` and color `primary`. To do so we have to alter the style of the following variants in Figma:

- `Checked=True, Size=Medium, Color=Primary, State=Enabled`
- `Checked=False, Size=Medium, Color=Primary, State=Enabled`
- `Checked=True, Size=Medium, Color=Primary, State=Hovered`
- `Checked=False, Size=Medium, Color=Primary, State=Hovered`
- `Checked=True, Size=Medium, Color=Primary, State=Disabled`
- `Checked=False, Size=Medium, Color=Primary, State=Disabled`
- `Checked=True, Size=Medium, Color=Primary, State=Focused`
- `Checked=False, Size=Medium, Color=Primary, State=Focused`

To efficiently do this, you can:

1. Start by customizing a single 'base' variant (e.g. `Checked=True, Size=Medium, Color=Primary, State=Enabled`).
2. Clone this variant and rename it to target the next variant you'd like to customize (e.g. rename the cloned version of `Checked=True, Size=Medium, Color=Primary, State=Enabled` to `Checked=False, Size=Medium, Color=Primary, State=Enabled`)
3. Delete the old, now duplicate version of this variant (e.g. delete the original `Checked=False, Size=Medium, Color=Primary, State=Enabled` variant).
4. Move the new version of the variant to the correct square in the variant grid
5. Make the necessary style adjustments to the variant's child layers.

Repeat this process for each variant you want to customize. Below you can see what the result can look like.

<img src="/static/material-ui/design-resources/connect-switch-component-customized.png" style="width: 814px" alt="A fully customized Switch component in the Design Kit" width="1628" height="400" />

Now you can go ahead and run Connect to generate a new theme. For the example shown above the theme will look like this:

```js
{
components: {
MuiSwitch: {
styleOverrides: {
root: {
"&.MuiSwitch-sizeMedium:has(.MuiSwitch-colorPrimary)": {
width: "40px",
height: "21px",
padding: "0",
"& .MuiSwitch-switchBase": {
padding: "0",
"& .MuiSwitch-thumb": {
width: "17px",
height: "17px",
background: "#FAFAFA",
},
"& + .MuiSwitch-track": {
width: "38px",
height: "21px",
},
},
"&:not(:has(.Mui-checked)):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible))":
{
"& .MuiSwitch-switchBase": {
transform: "translateX(3px) translateY(2px)",
"& + .MuiSwitch-track": {
background: "#BDBDBD",
opacity: "1",
},
},
},
"&:not(:has(.Mui-checked)):has(.Mui-disabled):not(:has(.Mui-focusVisible))":
{
"& .MuiSwitch-switchBase": {
transform: "translateX(3px) translateY(2px)",
"& + .MuiSwitch-track": {
background: "rgba(229, 229, 229, 0.99)",
opacity: "1",
},
},
},
"&:not(:has(.Mui-checked)):not(:has(.Mui-disabled)):has(.Mui-focusVisible)":
{
"& .MuiSwitch-switchBase": {
transform: "translateX(3px) translateY(2px)",
"& + .MuiSwitch-track": {
border: "1px solid #000",
background: "#BDBDBD",
opacity: "1",
},
},
},
"&:has(.Mui-checked):has(.Mui-disabled):not(:has(.Mui-focusVisible))":
{
"& .MuiSwitch-switchBase": {
transform: "translateX(19px) translateY(2px)",
"& + .MuiSwitch-track": {
background: "rgba(187, 231, 188, 0.99)",
opacity: "1",
},
},
},
"&:not(:has(.Mui-checked)):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible)):hover":
{
"& .MuiSwitch-switchBase": {
transform: "translateX(3px) translateY(2px)",
"& + .MuiSwitch-track": {
background: "#616161",
opacity: "1",
},
},
},
"&:has(.Mui-checked):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible))":
{
"& .MuiSwitch-switchBase": {
transform: "translateX(19px) translateY(2px)",
"& + .MuiSwitch-track": {
background: "var(--mui-palette-success-light)",
opacity: "1",
},
},
},
"&:has(.Mui-checked):not(:has(.Mui-disabled)):not(:has(.Mui-focusVisible)):hover":
{
"& .MuiSwitch-switchBase": {
transform: "translateX(19px) translateY(2px)",
"& + .MuiSwitch-track": {
background: "var(--mui-palette-success-dark)",
opacity: "1",
},
},
},
"&:has(.Mui-checked):not(:has(.Mui-disabled)):has(.Mui-focusVisible)":
{
"& .MuiSwitch-switchBase": {
transform: "translateX(19px) translateY(2px)",
"& + .MuiSwitch-track": {
border: "1px solid #000",
background: "var(--mui-palette-success-light)",
opacity: "1",
},
},
},
},
},
},
},
},
}
```

Finally you can check out the Storybook preview to test the Material UI version of your component.

<img src="/static/material-ui/design-resources/connect-switch-component-customized-storybook.png" style="width: 814px" alt="A fully customized Switch component in Storybook" width="1628" height="400" />

## Using the generated theme

The theme generated by Connect is meant to be used in combination with Material UI's [`CssVarsProvider`](/material-ui/experimental-api/css-theme-variables/migration/). Material UI's default [`ThemeProvider`](/material-ui/customization/theming/#theme-provider) is currently not supported.

:::info
Use Material UI's [CssVarsProvider](/material-ui/experimental-api/css-theme-variables/migration/) to load a theme generated by Connect.
:::

An example of using a theme generated theme by Connect in your frontend codebase:

```ts
// Your app's root component
import {
experimental_extendTheme as extendTheme,
Experimental_CssVarsProvider as CssVarsProvider,
} from "@mui/material/styles";

export default function MyApp({ Component, pageProps }) {
// the theme object generated by Connect
const copiedConnectTheme = {
shape: {
borderRadius: 12,
}
};

const theme = extendTheme(copiedConnectTheme);

return (
<CssVarsProvider theme={theme}>
<Component {...pageProps} />
</CssVarsProvider>
);
}
```

## Feedback and bug reports

Use [the dedicated Connect feedback board](https://mui-connect.canny.io/feedback) to share feedback, report bugs, or drop feature requests.
Loading