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

[SignInPage] Make rememberMe optional, add form slotProp #4574

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function BrandingSignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function BrandingSignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ const BRANDING = {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function CredentialsSignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function CredentialsSignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ const providers = [{ id: 'credentials', name: 'Email and Password' }];
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function MagicLinkAlertSignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function MagicLinkAlertSignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ resolve({
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function NotificationsSignInPageError() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function NotificationsSignInPageError() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ resolve({
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function PasskeySignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function PasskeySignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
// preview-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ const providers = [{ id: 'passkey', name: 'Passkey' }];
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ emailField: { autoFocus: false } }}
slotProps={{ emailField: { autoFocus: false }, form: { noValidate: true } }}
/>
</AppProvider>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Checkbox from '@mui/material/Checkbox';
import { AppProvider } from '@toolpad/core/AppProvider';
import { SignInPage } from '@toolpad/core/SignInPage';
import { Remember, SignInPage } from '@toolpad/core/SignInPage';
import { useTheme } from '@mui/material/styles';

const providers = [{ id: 'credentials', name: 'Email and Password' }];
Expand All @@ -16,7 +16,9 @@ export default function SlotPropsSignIn() {
`Signing in with "${provider.name}" and credentials: ${formData.get('email')}, ${formData.get('password')} and checkbox value: ${formData.get('tandc')}`,
)
}
slots={{ rememberMe: Remember }}
slotProps={{
form: { noValidate: true },
emailField: { variant: 'standard', autoFocus: false },
passwordField: { variant: 'standard' },
submitButton: { variant: 'outlined' },
Expand All @@ -26,7 +28,7 @@ export default function SlotPropsSignIn() {
name="tandc"
value="true"
color="primary"
sx={{ padding: 0.5, '& .MuiSvgIcon-root': { fontSize: 20 } }}
sx={{ py: 1, px: 0.5, '& .MuiSvgIcon-root': { fontSize: 20 } }}
/>
),
color: 'textSecondary',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Checkbox from '@mui/material/Checkbox';
import { AppProvider } from '@toolpad/core/AppProvider';
import { SignInPage } from '@toolpad/core/SignInPage';
import { Remember, SignInPage } from '@toolpad/core/SignInPage';
import { useTheme } from '@mui/material/styles';

const providers = [{ id: 'credentials', name: 'Email and Password' }];
Expand All @@ -16,7 +16,9 @@ export default function SlotPropsSignIn() {
`Signing in with "${provider.name}" and credentials: ${formData.get('email')}, ${formData.get('password')} and checkbox value: ${formData.get('tandc')}`,
)
}
slots={{ rememberMe: Remember }}
slotProps={{
form: { noValidate: true },
emailField: { variant: 'standard', autoFocus: false },
passwordField: { variant: 'standard' },
submitButton: { variant: 'outlined' },
Expand All @@ -26,7 +28,7 @@ export default function SlotPropsSignIn() {
name="tandc"
value="true"
color="primary"
sx={{ padding: 0.5, '& .MuiSvgIcon-root': { fontSize: 20 } }}
sx={{ py: 1, px: 0.5, '& .MuiSvgIcon-root': { fontSize: 20 } }}
/>
),
color: 'textSecondary',
Expand Down
33 changes: 5 additions & 28 deletions docs/data/toolpad/core/components/sign-in-page/SlotsSignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as React from 'react';
import {
Button,
FormControl,
FormControlLabel,
Checkbox,
InputLabel,
OutlinedInput,
TextField,
Expand All @@ -16,7 +14,7 @@ import AccountCircle from '@mui/icons-material/AccountCircle';
import Visibility from '@mui/icons-material/Visibility';
import VisibilityOff from '@mui/icons-material/VisibilityOff';
import { AppProvider } from '@toolpad/core/AppProvider';
import { SignInPage } from '@toolpad/core/SignInPage';
import { SignInPage, Remember } from '@toolpad/core/SignInPage';
import { useTheme } from '@mui/material/styles';

const providers = [{ id: 'credentials', name: 'Email and Password' }];
Expand Down Expand Up @@ -125,42 +123,20 @@ function Title() {

function Subtitle() {
return (
<Alert sx={{ mb: 2, px: 1, py: 0.25 }} severity="warning">
<Alert sx={{ mb: 2, px: 1, py: 0.25, width: '100%' }} severity="warning">
We are investigating an ongoing outage.
</Alert>
);
}

function AgreeWithTerms() {
return (
<FormControlLabel
control={
<Checkbox
name="tandc"
value="true"
color="primary"
sx={{ padding: 0.5, '& .MuiSvgIcon-root': { fontSize: 20 } }}
/>
}
slotProps={{
typography: {
fontSize: 14,
},
}}
color="textSecondary"
label="I agree with the T&C"
/>
);
}

export default function SlotsSignIn() {
const theme = useTheme();
return (
<AppProvider theme={theme}>
<SignInPage
signIn={(provider, formData) =>
alert(
`Logging in with "${provider.name}" and credentials: ${formData.get('email')}, ${formData.get('password')}, and checkbox value: ${formData.get('tandc')}`,
`Logging in with "${provider.name}" and credentials: ${formData.get('email')}, ${formData.get('password')}, and checkbox value: ${formData.get('remember')}`,
)
}
slots={{
Expand All @@ -170,9 +146,10 @@ export default function SlotsSignIn() {
passwordField: CustomPasswordField,
submitButton: CustomButton,
signUpLink: SignUpLink,
rememberMe: AgreeWithTerms,
rememberMe: Remember,
forgotPasswordLink: ForgotPasswordLink,
}}
slotProps={{ form: { noValidate: true } }}
providers={providers}
/>
</AppProvider>
Expand Down
33 changes: 5 additions & 28 deletions docs/data/toolpad/core/components/sign-in-page/SlotsSignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as React from 'react';
import {
Button,
FormControl,
FormControlLabel,
Checkbox,
InputLabel,
OutlinedInput,
TextField,
Expand All @@ -16,7 +14,7 @@ import AccountCircle from '@mui/icons-material/AccountCircle';
import Visibility from '@mui/icons-material/Visibility';
import VisibilityOff from '@mui/icons-material/VisibilityOff';
import { AppProvider } from '@toolpad/core/AppProvider';
import { SignInPage } from '@toolpad/core/SignInPage';
import { SignInPage, Remember } from '@toolpad/core/SignInPage';
import { useTheme } from '@mui/material/styles';

const providers = [{ id: 'credentials', name: 'Email and Password' }];
Expand Down Expand Up @@ -125,42 +123,20 @@ function Title() {

function Subtitle() {
return (
<Alert sx={{ mb: 2, px: 1, py: 0.25 }} severity="warning">
<Alert sx={{ mb: 2, px: 1, py: 0.25, width: '100%' }} severity="warning">
We are investigating an ongoing outage.
</Alert>
);
}

function AgreeWithTerms() {
return (
<FormControlLabel
control={
<Checkbox
name="tandc"
value="true"
color="primary"
sx={{ padding: 0.5, '& .MuiSvgIcon-root': { fontSize: 20 } }}
/>
}
slotProps={{
typography: {
fontSize: 14,
},
}}
color="textSecondary"
label="I agree with the T&C"
/>
);
}

export default function SlotsSignIn() {
const theme = useTheme();
return (
<AppProvider theme={theme}>
<SignInPage
signIn={(provider, formData) =>
alert(
`Logging in with "${provider.name}" and credentials: ${formData.get('email')}, ${formData.get('password')}, and checkbox value: ${formData.get('tandc')}`,
`Logging in with "${provider.name}" and credentials: ${formData.get('email')}, ${formData.get('password')}, and checkbox value: ${formData.get('remember')}`,
)
}
slots={{
Expand All @@ -170,9 +146,10 @@ export default function SlotsSignIn() {
passwordField: CustomPasswordField,
submitButton: CustomButton,
signUpLink: SignUpLink,
rememberMe: AgreeWithTerms,
rememberMe: Remember,
forgotPasswordLink: ForgotPasswordLink,
}}
slotProps={{ form: { noValidate: true } }}
providers={providers}
/>
</AppProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function ThemeSignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ form: { noValidate: true } }}
sx={{
'& form > .MuiStack-root': {
marginTop: '2rem',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function ThemeSignInPage() {
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ form: { noValidate: true } }}
sx={{
'& form > .MuiStack-root': {
marginTop: '2rem',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const THEME = createTheme({
<SignInPage
signIn={signIn}
providers={providers}
slotProps={{ form: { noValidate: true } }}
sx={{
'& form > .MuiStack-root': {
marginTop: '2rem',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
productId: toolpad-core
title: Sign-in Page
components: SignInPage, Account, NotificationsProvider
components: SignInPage, Account, Remember, NotificationsProvider
---

# Sign-in Page
Expand Down Expand Up @@ -239,7 +239,7 @@ To enable deep customization beyond what is possible with custom props, the `Sig

{{"demo": "SlotsSignIn.js", "iframe": true, "height": 540 }}

You can use the `slotProps` prop to pass props to the underlying components of each slot:
You can use the `slotProps` prop to pass props to the underlying components of each slot, and also to `form` element:

{{"demo": "SlotPropsSignIn.js", "iframe": true, "height": 600 }}

Expand Down
1 change: 1 addition & 0 deletions docs/data/toolpad/core/pagesApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = [
{ pathname: '/toolpad/core/api/page-container' },
{ pathname: '/toolpad/core/api/page-header' },
{ pathname: '/toolpad/core/api/page-header-toolbar' },
{ pathname: '/toolpad/core/api/remember' },
{ pathname: '/toolpad/core/api/sign-in-button' },
{ pathname: '/toolpad/core/api/sign-in-page' },
{ pathname: '/toolpad/core/api/sign-out-button' },
Expand Down
Loading
Loading