Skip to content

Commit 082ce82

Browse files
authored
[docs-infra] Move Open in MUI Chat to Demo toolbar and adjust styles (#46579)
1 parent c3bb44c commit 082ce82

File tree

6 files changed

+60
-61
lines changed

6 files changed

+60
-61
lines changed

docs/.env

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
FEEDBACK_URL=https://hgvi836wi8.execute-api.us-east-1.amazonaws.com
2-
3-
# Enable this variable after we get enough feedbacks from X docs.
4-
# NEXT_PUBLIC_MUI_CHAT_API_BASE_URL=https://chat-backend.mui.com

docs/next.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ export default withDocsInfra({
184184
GITHUB_AUTH: process.env.GITHUB_AUTH
185185
? `Basic ${Buffer.from(process.env.GITHUB_AUTH).toString('base64')}`
186186
: '',
187+
MUI_CHAT_API_BASE_URL: 'https://chat-backend.mui.com',
188+
MUI_CHAT_SCOPES: process.env.DEPLOY_ENV === 'production' ? '' : 'material-ui', // Use comma separated list of `productId` (see `_app.js`) to enable MUI Chat on demos
187189
},
188190
// Ensure CSS from the Data Grid packages is included in the build:
189191
// https://github.com/mui/mui-x/issues/17427#issuecomment-2813967605

docs/src/modules/components/Demo.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import stylingSolutionMapping from 'docs/src/modules/utils/stylingSolutionMappin
2727
import DemoToolbarRoot from 'docs/src/modules/components/DemoToolbarRoot';
2828
import { AdCarbonInline } from '@mui/docs/Ad';
2929
import DemoAiSuggestionHero from 'docs/src/modules/components/DemoAiSuggestionHero';
30-
import OpenMuiChat from 'docs/src/modules/components/OpenMuiChat';
3130

3231
/**
3332
* Removes leading spaces (indentation) present in the `.tsx` previews
@@ -638,34 +637,6 @@ export default function Demo(props) {
638637
)}
639638
</TabPanel>
640639
))}
641-
{process.env.NEXT_PUBLIC_MUI_CHAT_API_BASE_URL && (
642-
<Box
643-
sx={(theme) => ({
644-
position: 'relative',
645-
display: 'none',
646-
[theme.breakpoints.up('sm')]: { display: 'block' },
647-
})}
648-
>
649-
{/* This extra box is to prevent hover styles of DemoEditor when mouse move from the corner to the chat button. */}
650-
<Box
651-
sx={{
652-
position: 'absolute',
653-
bottom: '0',
654-
right: '0',
655-
zIndex: 1,
656-
pr: '0.875rem',
657-
pb: '0.875rem',
658-
}}
659-
>
660-
<OpenMuiChat
661-
data-ga-event-category="mui-chat"
662-
data-ga-event-label={demo.gaLabel}
663-
data-ga-event-action="open-in-mui-chat"
664-
demoData={demoData}
665-
/>
666-
</Box>
667-
</Box>
668-
)}
669640
</Collapse>
670641
</Tabs>
671642
{/* AI Suggestion Hero UI */}

docs/src/modules/components/DemoToolbar.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useRouter } from 'next/router';
2121
import { CODE_VARIANTS } from 'docs/src/modules/constants';
2222
import { useSetCodeVariant } from 'docs/src/modules/utils/codeVariant';
2323
import { useTranslate } from '@mui/docs/i18n';
24+
import OpenMuiChat from 'docs/src/modules/components/OpenMuiChat';
2425
import stylingSolutionMapping from 'docs/src/modules/utils/stylingSolutionMapping';
2526
import codeSandbox from '../sandbox/CodeSandbox';
2627
import stackBlitz from '../sandbox/StackBlitz';
@@ -437,6 +438,12 @@ export default function DemoToolbar(props) {
437438
return (
438439
<React.Fragment>
439440
<Root aria-label={t('demoToolbarLabel')} {...toolbarProps}>
441+
<OpenMuiChat
442+
data-ga-event-category="mui-chat"
443+
data-ga-event-label={demo.gaLabel}
444+
data-ga-event-action="open-in-mui-chat"
445+
demoData={demoData}
446+
/>
440447
<Fade in={codeOpen}>
441448
<Box sx={{ display: 'flex' }}>
442449
{hasNonSystemDemos && (

docs/src/modules/components/OpenMuiChat.tsx

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Button, { ButtonProps } from '@mui/material/Button';
44
import CircularProgress from '@mui/material/CircularProgress';
55
import Snackbar from '@mui/material/Snackbar';
66
import Alert from '@mui/material/Alert';
7-
import SvgMuiLogomark from 'docs/src/icons/SvgMuiLogomark';
7+
import PageContext from 'docs/src/modules/components/PageContext';
88
import { createMuiChat } from '../sandbox/MuiChat';
99
import { DemoData } from '../sandbox/types';
1010

@@ -22,45 +22,48 @@ const rainbow = keyframes`
2222
`;
2323

2424
const RainbowButton = styled(Button)(({ theme }) => ({
25-
'--color-1': '0 100% 63%',
26-
'--color-2': '270 100% 63%',
27-
'--color-3': '210 100% 63%',
28-
'--color-4': '195 100% 63%',
29-
'--color-5': '90 100% 63%',
25+
'--color-1': '0 100% 50%',
26+
'--color-2': '270 100% 50%',
27+
'--color-3': '210 100% 50%',
28+
'--color-4': '195 100% 50%',
29+
'--color-5': '90 100% 50%',
3030
position: 'relative',
3131
display: 'inline-flex',
3232
height: 26,
3333
padding: '7px 8px 8px 8px', // 7px for optical alignment
3434
flexShrink: 0,
35-
borderRadius: '6px',
35+
borderRadius: 999,
3636
border: '1px solid transparent',
37-
borderBottomWidth: '3px',
38-
borderBottomColor: 'transparent',
39-
boxShadow: '0 -1px 4px 0px rgba(255, 255, 255, 0.32)',
37+
borderBottomWidth: '2.5px',
38+
borderColor: alpha(theme.palette.grey[200], 0.8),
4039
'&.MuiButton-loading': {
41-
boxShadow: '0 -1px 4px 0px rgba(255, 255, 255, 0.32)',
40+
'& > svg': {
41+
transform: 'translateX(36px)',
42+
},
4243
},
43-
color: '#fff',
4444
fontSize: theme.typography.pxToRem(13),
4545
fontWeight: theme.typography.fontWeightMedium,
4646
backgroundSize: '200%',
4747
backgroundClip: 'padding-box, border-box, border-box',
4848
backgroundOrigin: 'border-box',
4949
animation: `${rainbow} 2s linear infinite`,
50-
'--bg-color-raw': '16, 18, 20',
50+
'--bg-color-raw': '255,255,255',
5151
'--bg-color': 'rgb(var(--bg-color-raw))',
52-
backgroundImage: `linear-gradient(var(--bg-color), var(--bg-color)), linear-gradient(var(--bg-color) 50%, rgba(var(--bg-color-raw), 0.6) 80%, rgba(var(--bg-color-raw), 0)), linear-gradient(90deg, hsl(var(--color-1)), hsl(var(--color-5)), hsl(var(--color-3)), hsl(var(--color-4)), hsl(var(--color-2)))`,
52+
backgroundImage: `linear-gradient(var(--bg-color), var(--bg-color)), linear-gradient(var(--bg-color) 50%, rgba(var(--bg-color-raw)) 80%, rgba(var(--bg-color-raw), 0)), linear-gradient(90deg, hsl(var(--color-1)), hsl(var(--color-5)), hsl(var(--color-3)), hsl(var(--color-4)), hsl(var(--color-2)))`,
53+
'&:hover': {
54+
'--bg-color-raw': '235,245,255',
55+
},
5356
...theme.applyDarkStyles({
57+
'--bg-color-raw': '16, 18, 20',
5458
borderColor: alpha(theme.palette.primary[300], 0.2),
59+
'&:hover': {
60+
'--bg-color-raw': '13, 38, 63',
61+
},
5562
}),
56-
'&:hover': {
57-
boxShadow: '0 -1px 4px 0px rgba(255, 255, 255, 0.56)',
58-
animationPlayState: 'paused',
59-
},
6063
'&::before': {
6164
content: '""',
6265
position: 'absolute',
63-
bottom: '-20%',
66+
bottom: '-25%',
6467
left: '50%',
6568
zIndex: 0,
6669
height: '20%',
@@ -69,23 +72,29 @@ const RainbowButton = styled(Button)(({ theme }) => ({
6972
animation: `${rainbow} 3s linear infinite`,
7073
background:
7174
'linear-gradient(90deg, hsl(var(--color-1)), hsl(var(--color-5)), hsl(var(--color-3)), hsl(var(--color-4)), hsl(var(--color-2)))',
72-
filter: 'blur(0.8rem)',
75+
filter: 'blur(1.2rem)',
76+
...theme.applyDarkStyles({
77+
width: '90%',
78+
filter: 'blur(0.5rem)',
79+
}),
7380
},
7481
'& > svg': {
75-
height: 12,
76-
width: 12,
77-
margin: '1px 4px 0 4px',
78-
},
79-
'& > svg > path': {
82+
height: 18,
83+
width: 18,
84+
margin: '0 4px 0 0',
85+
stroke: (theme.vars || theme).palette.primary.main,
8086
fill: (theme.vars || theme).palette.primary.main,
87+
transition: 'transform 0.4s',
8188
},
8289
}));
8390

8491
const OpenInMUIChatButton = React.forwardRef<HTMLButtonElement, OpenInMUIChatButtonProps>(
8592
function OpenInMUIChatButton({ demoData, ...props }, ref) {
93+
const { productId } = React.useContext(PageContext);
8694
const [loading, setLoading] = React.useState(false);
8795
const [error, setError] = React.useState<Error | null>(null);
88-
const baseUrl = process.env.NEXT_PUBLIC_MUI_CHAT_API_BASE_URL;
96+
const baseUrl = process.env.MUI_CHAT_API_BASE_URL;
97+
const scopes = process.env.MUI_CHAT_SCOPES;
8998

9099
const handleClick = async () => {
91100
setLoading(true);
@@ -101,7 +110,7 @@ const OpenInMUIChatButton = React.forwardRef<HTMLButtonElement, OpenInMUIChatBut
101110
};
102111

103112
// If the base URL is not set, we can't render the button
104-
if (!baseUrl) {
113+
if (!baseUrl || !scopes || !scopes.split(',').includes(productId)) {
105114
return null;
106115
}
107116

@@ -116,7 +125,20 @@ const OpenInMUIChatButton = React.forwardRef<HTMLButtonElement, OpenInMUIChatBut
116125
onClick={handleClick}
117126
{...props}
118127
>
119-
Edit in <SvgMuiLogomark /> Chat
128+
<svg
129+
xmlns="http://www.w3.org/2000/svg"
130+
fill="none"
131+
viewBox="0 0 24 24"
132+
strokeWidth="1.5"
133+
stroke="currentColor"
134+
>
135+
<path
136+
strokeLinecap="round"
137+
strokeLinejoin="round"
138+
d="M9.813 15.904 9 18.75l-.813-2.846a4.5 4.5 0 0 0-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 0 0 3.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 0 0 3.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 0 0-3.09 3.09ZM18.259 8.715 18 9.75l-.259-1.035a3.375 3.375 0 0 0-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 0 0 2.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 0 0 2.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 0 0-2.456 2.456ZM16.894 20.567 16.5 21.75l-.394-1.183a2.25 2.25 0 0 0-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 0 0 1.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 0 0 1.423 1.423l1.183.394-1.183.394a2.25 2.25 0 0 0-1.423 1.423Z"
139+
/>
140+
</svg>{' '}
141+
Edit in Chat
120142
</RainbowButton>
121143
<Snackbar
122144
open={!!error}

docs/src/modules/sandbox/MuiChat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function createMuiChat(demoData: DemoData) {
2727
description,
2828
dependencies,
2929
openSandbox: async () => {
30-
const baseUrl = process.env.NEXT_PUBLIC_MUI_CHAT_API_BASE_URL;
30+
const baseUrl = process.env.MUI_CHAT_API_BASE_URL;
3131

3232
if (!baseUrl) {
3333
throw new Error(

0 commit comments

Comments
 (0)