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

[core] Add LocalizationProvider #4620

Open
wants to merge 8 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
@@ -1,5 +1,5 @@
import * as React from 'react';
import { AuthenticationContext, SessionContext } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
Copy link
Member Author

@bharatkashyap bharatkashyap Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change on all demos is since none of the demos on this page were using the Account component inside the AppProvider - added that since I think that is expected use, and also allows demonstrating overriding global localization using the localeText prop.

Kept one example which still demonstrates using Account without AppProvider but the constituent context providers instead

import { Account } from '@toolpad/core/Account';

const demoSession = {
Expand Down Expand Up @@ -31,17 +31,15 @@ export default function AccountCustomLocaleText() {
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
{/* preview-start */}
<Account
localeText={{
signInLabel: 'लॉग इन',
signOutLabel: 'लॉग आउट',
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
<AppProvider authentication={authentication} session={session}>
{/* preview-start */}
<Account
localeText={{
accountSignInLabel: 'लॉग इन',
accountSignOutLabel: 'लॉग आउट',
}}
/>
{/* preview-end */}
</AppProvider>
);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import * as React from 'react';
import {
AuthenticationContext,
Session,
SessionContext,
} from '@toolpad/core/AppProvider';
import { AppProvider, type Session } from '@toolpad/core/AppProvider';
import { Account } from '@toolpad/core/Account';

const demoSession = {
Expand Down Expand Up @@ -35,17 +31,15 @@ export default function AccountCustomLocaleText() {
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
{/* preview-start */}
<Account
localeText={{
signInLabel: 'लॉग इन',
signOutLabel: 'लॉग आउट',
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
<AppProvider authentication={authentication} session={session}>
{/* preview-start */}
<Account
localeText={{
accountSignInLabel: 'लॉग इन',
accountSignOutLabel: 'लॉग आउट',
}}
/>
{/* preview-end */}
</AppProvider>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Account
localeText={{
signInLabel: 'लॉग इन',
signOutLabel: 'लॉग आउट',
accountSignInLabel: 'लॉग इन',
accountSignOutLabel: 'लॉग आउट',
}}
/>
56 changes: 27 additions & 29 deletions docs/data/toolpad/core/components/account/AccountCustomSlotProps.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Logout from '@mui/icons-material/Logout';
import { Account } from '@toolpad/core/Account';
import { AuthenticationContext, SessionContext } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';

const demoSession = {
user: {
Expand Down Expand Up @@ -32,36 +32,34 @@ export default function AccountCustomSlotProps() {
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
{/* preview-start */}
<Account
slotProps={{
signInButton: {
color: 'success',
},
signOutButton: {
color: 'success',
startIcon: <Logout />,
},
preview: {
variant: 'expanded',
slotProps: {
avatarIconButton: {
sx: {
width: 'fit-content',
margin: 'auto',
},
},
avatar: {
variant: 'rounded',
<AppProvider authentication={authentication} session={session}>
{/* preview-start */}
<Account
slotProps={{
signInButton: {
color: 'success',
},
signOutButton: {
color: 'success',
startIcon: <Logout />,
},
preview: {
variant: 'expanded',
slotProps: {
avatarIconButton: {
sx: {
width: 'fit-content',
margin: 'auto',
},
},
avatar: {
variant: 'rounded',
},
},
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
},
}}
/>
{/* preview-end */}
</AppProvider>
);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as React from 'react';
import Logout from '@mui/icons-material/Logout';
import { Account } from '@toolpad/core/Account';
import {
AuthenticationContext,
SessionContext,
Session,
} from '@toolpad/core/AppProvider';
import { AppProvider, Session } from '@toolpad/core/AppProvider';

const demoSession = {
user: {
Expand Down Expand Up @@ -36,36 +32,34 @@ export default function AccountCustomSlotProps() {
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
{/* preview-start */}
<Account
slotProps={{
signInButton: {
color: 'success',
},
signOutButton: {
color: 'success',
startIcon: <Logout />,
},
preview: {
variant: 'expanded',
slotProps: {
avatarIconButton: {
sx: {
width: 'fit-content',
margin: 'auto',
},
},
avatar: {
variant: 'rounded',
<AppProvider authentication={authentication} session={session}>
{/* preview-start */}
<Account
slotProps={{
signInButton: {
color: 'success',
},
signOutButton: {
color: 'success',
startIcon: <Logout />,
},
preview: {
variant: 'expanded',
slotProps: {
avatarIconButton: {
sx: {
width: 'fit-content',
margin: 'auto',
},
},
avatar: {
variant: 'rounded',
},
},
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
},
}}
/>
{/* preview-end */}
</AppProvider>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Account } from '@toolpad/core/Account';
import { AuthenticationContext, SessionContext } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { UserOrg } from '../UserOrg';

const demoSession = {
Expand Down Expand Up @@ -30,16 +30,14 @@ export default function AccountCustomUserDetails() {
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={customSession}>
{/* preview-start */}
<Account
slots={{
popoverContent: UserOrg,
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
<AppProvider authentication={authentication} session={customSession}>
{/* preview-start */}
<Account
slots={{
popoverContent: UserOrg,
}}
/>
{/* preview-end */}
</AppProvider>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Account } from '@toolpad/core/Account';
import { AuthenticationContext, SessionContext } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { UserOrg, CustomSession } from '../UserOrg';

const demoSession: CustomSession = {
Expand Down Expand Up @@ -32,16 +32,14 @@ export default function AccountCustomUserDetails() {
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={customSession}>
{/* preview-start */}
<Account
slots={{
popoverContent: UserOrg,
}}
/>
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
<AppProvider authentication={authentication} session={customSession}>
{/* preview-start */}
<Account
slots={{
popoverContent: UserOrg,
}}
/>
{/* preview-end */}
</AppProvider>
);
}
14 changes: 6 additions & 8 deletions docs/data/toolpad/core/components/account/AccountDemoSignedIn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { AuthenticationContext, SessionContext } from '@toolpad/core/AppProvider';
import { AppProvider } from '@toolpad/core/AppProvider';
import { Account } from '@toolpad/core/Account';

const demoSession = {
Expand All @@ -24,12 +24,10 @@ export default function AccountDemoSignedIn() {
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
{/* preview-start */}
<Account />
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
<AppProvider authentication={authentication} session={session}>
{/* preview-start */}
<Account />
{/* preview-end */}
</AppProvider>
);
}
18 changes: 6 additions & 12 deletions docs/data/toolpad/core/components/account/AccountDemoSignedIn.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import * as React from 'react';
import {
AuthenticationContext,
SessionContext,
type Session,
} from '@toolpad/core/AppProvider';
import { AppProvider, type Session } from '@toolpad/core/AppProvider';
import { Account } from '@toolpad/core/Account';

const demoSession = {
Expand All @@ -28,12 +24,10 @@ export default function AccountDemoSignedIn() {
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
{/* preview-start */}
<Account />
{/* preview-end */}
</SessionContext.Provider>
</AuthenticationContext.Provider>
<AppProvider authentication={authentication} session={session}>
{/* preview-start */}
<Account />
{/* preview-end */}
</AppProvider>
);
}
20 changes: 14 additions & 6 deletions docs/data/toolpad/core/components/account/AccountDemoSignedOut.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { AuthenticationContext, SessionContext } from '@toolpad/core/AppProvider';
import {
AuthenticationContext,
LocalizationProvider,
SessionContext,
} from '@toolpad/core/AppProvider';
import { Account } from '@toolpad/core/Account';

const demoSession = {
Expand All @@ -24,10 +28,14 @@ export default function AccountDemoSignedOut() {
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account />
</SessionContext.Provider>
</AuthenticationContext.Provider>
// preview-start
<LocalizationProvider>
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account />
</SessionContext.Provider>
</AuthenticationContext.Provider>
</LocalizationProvider>
// preview-end
);
}
Loading
Loading