Skip to content

Commit

Permalink
[Snackbar][Material You] apply md3 designs
Browse files Browse the repository at this point in the history
  • Loading branch information
Best-Sardar committed Nov 10, 2023
1 parent 2f18792 commit 5ad7d52
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 154 deletions.
2 changes: 1 addition & 1 deletion docs/pages/base-ui/api/snackbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"onClose": {
"type": { "name": "func" },
"signature": {
"type": "function(event: React.SyntheticEvent<any> | Event, reason: string) => void",
"type": "function(event: React.SyntheticEvent<any> | Event | null, reason: string) => void",
"describedArgs": ["event", "reason"]
}
},
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/joy-ui/api/snackbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"onClose": {
"type": { "name": "func" },
"signature": {
"type": "function(event: React.SyntheticEvent<any> | Event, reason: string) => void",
"type": "function(event: React.SyntheticEvent<any> | Event | null, reason: string) => void",
"describedArgs": ["event", "reason"]
}
},
Expand Down
249 changes: 126 additions & 123 deletions docs/src/modules/components/MaterialYouUsageDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ interface MaterialYouUsageDemoProps<ComponentProps> {
/**
* Configuration
*/
data: Array<{
data?: Array<{
/**
* Name of the prop, e.g. 'children'
*/
Expand Down Expand Up @@ -170,7 +170,7 @@ interface MaterialYouUsageDemoProps<ComponentProps> {
export default function MaterialYouUsageDemo<T extends { [k: string]: any } = {}>({
componentName,
childrenAccepted = false,
data,
data = [],
renderDemo,
getCodeBlock = defaultGetCodeBlock,
}: MaterialYouUsageDemoProps<T>) {
Expand Down Expand Up @@ -240,138 +240,141 @@ export default function MaterialYouUsageDemo<T extends { [k: string]: any } = {}
/>
</BrandingProvider>
</Box>
<Box
sx={(theme) => ({
flexShrink: 0,
gap: 2,
borderLeft: '1px solid',
borderColor: theme.palette.grey[200],
background: alpha(theme.palette.grey[50], 0.5),
minWidth: '250px',
[`:where(${theme.vars ? '[data-mui-color-scheme="dark"]' : '.mode-dark'}) &`]: {
borderColor: alpha(theme.palette.grey[900], 0.8),
backgroundColor: alpha(theme.palette.grey[900], 0.3),
},
})}
>

{data.length > 0 && (
<Box
sx={{
px: 3,
py: 2,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
sx={(theme) => ({
flexShrink: 0,
gap: 2,
borderLeft: '1px solid',
borderColor: theme.palette.grey[200],
background: alpha(theme.palette.grey[50], 0.5),
minWidth: '250px',
[`:where(${theme.vars ? '[data-mui-color-scheme="dark"]' : '.mode-dark'}) &`]: {
borderColor: alpha(theme.palette.grey[900], 0.8),
backgroundColor: alpha(theme.palette.grey[900], 0.3),
},
})}
>
<Typography
id="usage-props"
component="h3"
fontWeight="600"
sx={{ scrollMarginTop: 160, fontFamily: 'General Sans' }}
<Box
sx={{
px: 3,
py: 2,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
Playground
</Typography>
<IconButton
aria-label="Reset all"
size="small"
onClick={() => setProps(initialProps as T)}
<Typography
id="usage-props"
component="h3"
fontWeight="600"
sx={{ scrollMarginTop: 160, fontFamily: 'General Sans' }}
>
Playground
</Typography>
<IconButton
aria-label="Reset all"
size="small"
onClick={() => setProps(initialProps as T)}
sx={{
visibility: !shallowEqual(props, initialProps) ? 'visible' : 'hidden',
}}
>
<ReplayRoundedIcon />
</IconButton>
</Box>
<Divider sx={{ opacity: 0.5 }} />
<Box
sx={{
visibility: !shallowEqual(props, initialProps) ? 'visible' : 'hidden',
p: 3,
display: 'flex',
flexDirection: 'column',
gap: 2,
[`& .${formLabelClasses.root}`]: {
fontWeight: 'lg',
},
}}
>
<ReplayRoundedIcon />
</IconButton>
</Box>
<Divider sx={{ opacity: 0.5 }} />
<Box
sx={{
p: 3,
display: 'flex',
flexDirection: 'column',
gap: 2,
[`& .${formLabelClasses.root}`]: {
fontWeight: 'lg',
},
}}
>
{data.map(({ propName, knob, options = [], defaultValue, onChange }) => {
const resolvedValue = props[propName] ?? defaultValue;
if (!knob) {
return null;
}
if (knob === 'switch') {
return (
<FormControl
key={propName}
size="small"
sx={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
<FormLabel
sx={{
textTransform: 'capitalize',
fontWeight: 'medium',
fontSize: '0.875rem',
color: 'text.secondary',
}}
>
{propName}
</FormLabel>
<Switch
{data.map(({ propName, knob, options = [], defaultValue, onChange }) => {
const resolvedValue = props[propName] ?? defaultValue;
if (!knob) {
return null;
}
if (knob === 'switch') {
return (
<FormControl
key={propName}
size="small"
checked={Boolean(resolvedValue)}
onChange={(event) => {
setProps((latestProps) => ({
...latestProps,
[propName]: event.target.checked,
}));
onChange?.(event);
}}
/>
</FormControl>
);
}
if (knob === 'select') {
return (
<FormControl key={propName} size="small">
<FormLabel
sx={{
textTransform: 'capitalize',
fontWeight: 'medium',
fontSize: '0.875rem',
mb: 0.5,
}}
>
{propName}
</FormLabel>
<Select
placeholder="Select a variant..."
value={(resolvedValue || 'none') as string}
onChange={(event) => {
setProps((latestProps) => ({
...latestProps,
[propName]: event.target.value,
}));
onChange?.(event as React.SyntheticEvent);
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
{options.map((value) => (
<MenuItem key={value} value={value}>
{value}
</MenuItem>
))}
</Select>
</FormControl>
);
}
return null;
})}
<FormLabel
sx={{
textTransform: 'capitalize',
fontWeight: 'medium',
fontSize: '0.875rem',
color: 'text.secondary',
}}
>
{propName}
</FormLabel>
<Switch
size="small"
checked={Boolean(resolvedValue)}
onChange={(event) => {
setProps((latestProps) => ({
...latestProps,
[propName]: event.target.checked,
}));
onChange?.(event);
}}
/>
</FormControl>
);
}
if (knob === 'select') {
return (
<FormControl key={propName} size="small">
<FormLabel
sx={{
textTransform: 'capitalize',
fontWeight: 'medium',
fontSize: '0.875rem',
mb: 0.5,
}}
>
{propName}
</FormLabel>
<Select
placeholder="Select a variant..."
value={(resolvedValue || 'none') as string}
onChange={(event) => {
setProps((latestProps) => ({
...latestProps,
[propName]: event.target.value,
}));
onChange?.(event as React.SyntheticEvent);
}}
>
{options.map((value) => (
<MenuItem key={value} value={value}>
{value}
</MenuItem>
))}
</Select>
</FormControl>
);
}
return null;
})}
</Box>
</Box>
</Box>
)}
</Box>
);
}
3 changes: 3 additions & 0 deletions packages/mui-material-next/src/Snackbar/Snackbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { spy } from 'sinon';
import { describeConformance, act, createRenderer, fireEvent } from '@mui-internal/test-utils';
import Snackbar, { snackbarClasses as classes } from '@mui/material-next/Snackbar';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';

describe('<Snackbar />', () => {
const { clock, render: clientRender } = createRenderer({ clock: 'fake' });
Expand All @@ -26,6 +27,8 @@ describe('<Snackbar />', () => {
describeConformance(<Snackbar open message="message" />, () => ({
classes,
inheritComponent: 'div',
ThemeProvider: CssVarsProvider,
createTheme: extendTheme,
render,
refInstanceof: window.HTMLDivElement,
muiName: 'MuiSnackbar',
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material-next/src/Snackbar/Snackbar.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { SxProps } from '@mui/system';
import { ClickAwayListenerProps } from '@mui/base/ClickAwayListener';
// eslint-disable-next-line no-restricted-imports
import { InternalStandardProps as StandardProps } from '@mui/material';
import { SnackbarContentProps } from '@mui/material/SnackbarContent';
// TODO v6: port to material-next
import { TransitionProps } from '@mui/material/transitions';
import { Theme } from '../styles';
import { SnackbarClasses } from './snackbarClasses';
import { SnackbarContentProps } from '../SnackbarContent/SnackbarContent.types';

export interface SnackbarOwnerState extends SnackbarProps {
anchorOrigin: NonNullable<SnackbarProps['anchorOrigin']>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import Paper from '@mui/material/Paper';
import SnackbarContent, {
snackbarContentClasses as classes,
} from '@mui/material-next/SnackbarContent';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';

describe('<SnackbarContent />', () => {
const { render } = createRenderer();

describeConformance(<SnackbarContent message="conform?" />, () => ({
classes,
ThemeProvider: CssVarsProvider,
createTheme: extendTheme,
inheritComponent: Paper,
render,
muiName: 'MuiSnackbarContent',
Expand Down
Loading

0 comments on commit 5ad7d52

Please sign in to comment.