@mui/lab#TabContext TypeScript Examples
The following examples show how to use
@mui/lab#TabContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeExamples.tsx From GTAV-NativeDB with MIT License | 6 votes |
function CodeExamples({ examples }: CodeExamplesProps) {
const [language, setLanguage] = useState(examples[0].lang)
const onTabChange = useCallback((e: SyntheticEvent<Element, Event>, language: string) => {
setLanguage(language)
}, [setLanguage])
return (
<TabContext value={language}>
<TabList onChange={onTabChange} sx={{ pl: 0 }}>
{examples.map(({ lang }) => (
<Tab
label={humanLangMap[lang] ?? lang}
value={lang}
/>
))}
</TabList>
<Divider />
{examples.map(({ lang, code }) => (
<TabPanel value={lang} sx={{ p: 0 }}>
<SyntaxHighlighter
language={langMap[lang] ?? lang}
>
{code}
</SyntaxHighlighter>
</TabPanel>
))}
</TabContext>
)
}
Example #2
Source File: ComponentPanel.tsx From mui-toolpad with MIT License | 6 votes |
export default function ComponentPanel({ className }: ComponentPanelProps) {
const state = usePageEditorState();
const api = usePageEditorApi();
const handleChange = (event: React.SyntheticEvent, newValue: ComponentPanelTab) =>
api.setComponentPanelTab(newValue);
return (
<ComponentPanelRoot className={className}>
<TabContext value={state.componentPanelTab}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<TabList onChange={handleChange} aria-label="lab API tabs example">
<Tab label="Component" value="component" />
<Tab label="Theme" value="theme" />
</TabList>
</Box>
<TabPanel value="component" className={classes.panel}>
<ComponentEditor />
</TabPanel>
<TabPanel value="theme" className={classes.panel}>
<ThemeEditor />
</TabPanel>
</TabContext>
</ComponentPanelRoot>
);
}
Example #3
Source File: GenerateCodePage.tsx From GTAV-NativeDB with MIT License | 5 votes |
function GenerateCodePage() {
const { language } = useParams<{ language: string }>()
const history = useHistory()
const onTabChange = useCallback((e: SyntheticEvent<Element, Event>, language: string) => {
history.replace(language)
}, [history])
return (
<Box sx={{ py: 2, overflow: 'hidden scroll', flexGrow: 1 }}>
<Container maxWidth="lg">
<Typography variant="h4" component="h1" gutterBottom>
Generate Code
</Typography>
<Paper>
<TabContext value={language}>
<TabList onChange={onTabChange}>
<Tab label="C++" value="cpp" />
<Tab label="Rust" value="rs" />
<Tab label="C# Enum" value="cs" />
<Tab label="SHV.NET" value="shvdn" />
<Tab label="RPH" value="rph" />
</TabList>
<Divider />
<TabPanel value="cpp">
<CPlusPlus />
</TabPanel>
<TabPanel value="rs">
<Rust />
</TabPanel>
<TabPanel value="cs">
<CSharpEnum />
</TabPanel>
<TabPanel value="shvdn">
Soon™
</TabPanel>
<TabPanel value="rph">
Soon™
</TabPanel>
</TabContext>
</Paper>
</Container>
</Box>
)
}
Example #4
Source File: VerticalTabs.tsx From console with GNU Affero General Public License v3.0 | 5 votes |
VerticalTabs = ({
children,
classes,
selectedTab = "0",
routes,
isRouteTabs,
}: VerticalTabsProps) => {
const [value, setValue] = React.useState(selectedTab);
const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down("md"));
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
setValue(newValue);
};
const headerList: TabProps[] = [];
const contentList: React.ReactNode[] = [];
if (!children) return null;
children.forEach((child) => {
headerList.push(child.tabConfig);
contentList.push(child.content);
});
return (
<TabContext value={`${value}`}>
<Box className={classes.tabsContainer}>
<Box className={classes.tabsHeaderContainer}>
<TabList
onChange={handleChange}
orientation={isSmallScreen ? "horizontal" : "vertical"}
variant={isSmallScreen ? "scrollable" : "standard"}
scrollButtons="auto"
className={classes.tabList}
>
{headerList.map((item, index) => {
if (item) {
return (
<Tab
className={classes.tabHeader}
key={`v-tab-${index}`}
value={`${index}`}
style={tabStripStyle}
{...item}
disableRipple
disableTouchRipple
focusRipple={true}
/>
);
}
return null;
})}
</TabList>
</Box>
<Box className={classes.tabContentContainer}>
{!isRouteTabs
? contentList.map((item, index) => {
return (
<TabPanel
classes={{ ...classes.tabPanel }}
key={`v-tab-p-${index}`}
value={`${index}`}
>
{item ? item : null}
</TabPanel>
);
})
: null}
{isRouteTabs ? (
<div className={classes.tabPanel}>{routes}</div>
) : null}
</Box>
</Box>
</TabContext>
);
}
Example #5
Source File: FaqPage.tsx From frontend with MIT License | 5 votes |
// Remove this when FAQ is ready
export default function FaqPage({ section }: { section: string }) {
const { t } = useTranslation()
const [value, setValue] = useState(section)
if (faqOnHold) {
return (
<Layout title={t('nav.campaigns.faq')}>
<OnHold />
</Layout>
)
}
return (
<Layout title={t('nav.campaigns.faq')}>
<FaqIntro />
<TabContext value={value}>
<Stack direction={{ xs: 'column', md: 'row' }}>
<VerticalTabs setValue={setValue} />
<TabPanel value="common-questions" sx={{ p: 0 }}>
{COMMON_QUESTIONS.flatMap(({ header, content, visible }) =>
visible ? <ExpandableListItem key={header} header={header} content={content} /> : [],
)}
</TabPanel>
<TabPanel value="campaigns" sx={{ p: 0 }}>
{CAMPAIGN_QUESTIONS.flatMap(({ header, content, visible }) =>
visible ? <ExpandableListItem key={header} header={header} content={content} /> : [],
)}
</TabPanel>
<TabPanel value="donations" sx={{ p: 0 }}>
{DONATION_QUESTIONS.flatMap(({ header, content, visible }) =>
visible ? <ExpandableListItem key={header} header={header} content={content} /> : [],
)}
</TabPanel>
<TabPanel value="recurring-donations" sx={{ p: 0 }}>
{MONTHLY_DONATION_QUESTIONS.flatMap(({ header, content, visible }) =>
visible ? <ExpandableListItem key={header} header={header} content={content} /> : [],
)}
</TabPanel>
<TabPanel value="potential-fraud" sx={{ p: 0 }}>
{POTENTION_SCAM_QUESTIONS.flatMap(({ header, content, visible }) =>
visible ? <ExpandableListItem key={header} header={header} content={content} /> : [],
)}
</TabPanel>
<TabPanel value="attracting-donators" sx={{ p: 0 }}>
{ATTRACTING_DONATORS_QUESTIONS.flatMap(({ header, content, visible }) =>
visible ? <ExpandableListItem key={header} header={header} content={content} /> : [],
)}
</TabPanel>
<TabPanel value="corporate-partnership" sx={{ p: 0 }}>
{PARTNERSHIPS_QUESTIONS.flatMap(({ header, content, visible }) =>
visible ? <ExpandableListItem key={header} header={header} content={content} /> : [],
)}
</TabPanel>
</Stack>
</TabContext>
<ContactUs />
<ScrollToTop />
</Layout>
)
}
Example #6
Source File: DepositWithdrawDialog.tsx From wrap.scrt.network with MIT License | 5 votes |
export default function DepositWithdrawDialog({
token,
secretjs,
secretAddress,
balances,
isOpen,
setIsOpen,
}: {
token: Token;
secretjs: SecretNetworkClient | null;
secretAddress: string;
balances: Map<string, string>;
isOpen: boolean;
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
}) {
const [selectedTab, setSelectedTab] = useState<string>("deposit");
const closeDialog = () => {
setIsOpen(false);
setSelectedTab("deposit");
};
return (
<Dialog open={isOpen} fullWidth={true} onClose={closeDialog}>
<TabContext value={selectedTab}>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
<Tabs
value={selectedTab}
variant="fullWidth"
onChange={(_event: React.SyntheticEvent, newSelectedTab: string) =>
setSelectedTab(newSelectedTab)
}
>
<Tab label="IBC Deposit" value={"deposit"} />
<Tab label="IBC Withdraw" value={"withdraw"} />
</Tabs>
</Box>
<TabPanel value={"deposit"}>
<Deposit
token={token}
secretAddress={secretAddress}
onSuccess={(txhash) => {
closeDialog();
console.log("success", txhash);
}}
onFailure={(error) => console.error(error)}
/>
</TabPanel>
<TabPanel value={"withdraw"}>
<Withdraw
token={token}
secretjs={secretjs}
secretAddress={secretAddress}
balances={balances}
onSuccess={(txhash) => {
closeDialog();
console.log("success", txhash);
}}
onFailure={(error) => console.error(error)}
/>
</TabPanel>
</TabContext>
</Dialog>
);
}
Example #7
Source File: Balances.tsx From abrechnung with GNU Affero General Public License v3.0 | 4 votes |
export default function Balances({ group }) {
const theme: Theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down("sm"));
const history = useHistory();
const personalAccounts = useRecoilValue(personalAccountsSeenByUser(group.id));
const clearingAccounts = useRecoilValue(clearingAccountsSeenByUser(group.id));
const balances = useRecoilValue(accountBalances(group.id));
const [selectedTab, setSelectedTab] = useState("1");
const colorGreen = theme.palette.mode === "light" ? theme.palette.success.light : theme.palette.success.dark;
const colorRed = theme.palette.mode === "light" ? theme.palette.error.light : theme.palette.error.dark;
const colorGreenInverted = theme.palette.mode === "dark" ? theme.palette.success.light : theme.palette.success.dark;
const colorRedInverted = theme.palette.mode === "dark" ? theme.palette.error.light : theme.palette.error.dark;
useTitle(`${group.name} - Balances`);
const chartData = personalAccounts.map((account) => {
return {
name: account.name,
balance: balances[account.id].balance,
totalPaid: balances[account.id].totalPaid,
totalConsumed: balances[account.id].totalConsumed,
id: account.id,
};
});
const unbalancedClearingAccounts = clearingAccounts
.filter((account) => balances[account.id].balance !== 0)
.map((account) => {
return {
name: account.name,
id: account.id,
balance: balances[account.id].balance,
};
});
const chartHeight = Object.keys(balances).length * 30 + 100;
// TODO determine the rendered width of the account names and take the maximum
const yaxiswidth = isSmallScreen
? Math.max(Math.max(...personalAccounts.map((account) => account.name.length)), 20)
: Math.max(...personalAccounts.map((account) => account.name.length)) * 7 + 5;
const handleBarClick = (data, event) => {
const id = data.activePayload[0].payload.id;
history.push(`/groups/${group.id}/accounts/${id}`);
};
return (
<MobilePaper>
<TabContext value={selectedTab}>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
<TabList onChange={(event, idx) => setSelectedTab(idx)} centered>
<Tab label="Chart" value="1" />
<Tab label="Table" value="2" />
</TabList>
</Box>
<TabPanel value="1" sx={{ padding: { xs: 1, md: 2 } }}>
{personalAccounts.length === 0 && <Alert severity="info">No Accounts</Alert>}
{unbalancedClearingAccounts.length !== 0 && (
<Alert severity="info">
<AlertTitle>Some Clearing Accounts have remaining balances.</AlertTitle>
{unbalancedClearingAccounts.map((account) => (
<Typography variant="body2" key={account.id} component="span">
<>{account.name}:</>
<Typography
variant="body2"
component="span"
sx={{ color: account.balance < 0 ? colorRedInverted : colorGreenInverted }}
>
{account.balance.toFixed(2)} {group.currency_symbol}{" "}
</Typography>
</Typography>
))}
</Alert>
)}
{isSmallScreen ? (
<List>
{personalAccounts.map((account) => (
<>
<ListItemLink key={account.id} to={`/groups/${group.id}/accounts/${account.id}`}>
<ListItemText primary={account.name} />
<Typography
align="right"
variant="body2"
sx={{
color:
balances[account.id].balance < 0
? colorRedInverted
: colorGreenInverted,
}}
>
{balances[account.id].balance.toFixed(2)} {group.currency_symbol}
</Typography>
</ListItemLink>
<Divider key={account.id * 2} component="li" />
</>
))}
</List>
) : (
<div className="area-chart-wrapper" style={{ width: "100%", height: `${chartHeight}px` }}>
<ResponsiveContainer>
<BarChart
data={chartData}
margin={{
top: 20,
right: 20,
bottom: 20,
left: 20,
}}
layout="vertical"
onClick={handleBarClick}
>
<XAxis
stroke={theme.palette.text.primary}
type="number"
unit={group.currency_symbol}
/>
<YAxis
dataKey="name"
stroke={theme.palette.text.primary}
type="category"
width={yaxiswidth}
/>
<Tooltip
formatter={(label) =>
parseFloat(label).toFixed(2) + ` ${group.currency_symbol}`
}
labelStyle={{
color: theme.palette.text.primary,
}}
itemStyle={{
color: theme.palette.text.primary,
}}
contentStyle={{
backgroundColor: theme.palette.background.paper,
borderColor: theme.palette.divider,
borderRadius: theme.shape.borderRadius,
}}
/>
<Bar dataKey="balance">
{chartData.map((entry, index) => {
return (
<Cell
key={`cell-${index}`}
fill={entry["balance"] >= 0 ? colorGreen : colorRed}
/>
);
})}
<LabelList
dataKey={(entry) =>
`${entry["balance"].toFixed(2)}${group.currency_symbol}`
}
position="insideLeft"
fill={theme.palette.text.primary}
/>
</Bar>
</BarChart>
</ResponsiveContainer>
</div>
)}
</TabPanel>
<TabPanel value="2" sx={{ padding: { xs: 1, md: 2 } }}>
<BalanceTable group={group} />
</TabPanel>
</TabContext>
</MobilePaper>
);
}
Example #8
Source File: AccountList.tsx From abrechnung with GNU Affero General Public License v3.0 | 4 votes |
export default function AccountList({ group }) {
const [speedDialOpen, setSpeedDialOpen] = useState(false);
const toggleSpeedDial = () => setSpeedDialOpen((currValue) => !currValue);
const [showPersonalAccountCreationModal, setShowPersonalAccountCreationModal] = useState(false);
const [showClearingAccountCreationModal, setShowClearingAccountCreationModal] = useState(false);
const [activeTab, setActiveTab] = useState("personal");
const [searchValuePersonal, setSearchValuePersonal] = useState("");
const [searchValueClearing, setSearchValueClearing] = useState("");
const [showPersonalAccountEditModal, setShowPersonalAccountEditModal] = useState(false);
const [showClearingAccountEditModal, setShowClearingAccountEditModal] = useState(false);
const [clearingAccountToCopy, setClearingAccountToCopy] = useState(undefined);
const [accountToEdit, setAccountToEdit] = useState(null);
const [clearingAccountToEdit, setClearingAccountToEdit] = useState(null);
const setAccounts = useSetRecoilState(groupAccounts(group.id));
const personalAccounts = useRecoilValue(personalAccountsSeenByUser(group.id));
const clearingAccounts = useRecoilValue(clearingAccountsSeenByUser(group.id));
const allAccounts = useRecoilValue(accountsSeenByUser(group.id));
const [accountToDelete, setAccountToDelete] = useState(null);
const userPermissions = useRecoilValue(currUserPermissions(group.id));
const currentUser = useRecoilValue(userData);
const memberIDToUsername = useRecoilValue(groupMemberIDsToUsername(group.id));
const [filteredPersonalAccounts, setFilteredPersonalAccounts] = useState([]);
const [filteredClearingAccounts, setFilteredClearingAccounts] = useState([]);
useEffect(() => {
if (searchValuePersonal != null && searchValuePersonal !== "") {
setFilteredPersonalAccounts(
personalAccounts.filter((t) => {
return (
t.name.toLowerCase().includes(searchValuePersonal.toLowerCase()) ||
t.description.toLowerCase().includes(searchValuePersonal.toLowerCase())
);
})
);
} else {
return setFilteredPersonalAccounts(personalAccounts);
}
}, [personalAccounts, searchValuePersonal, setFilteredPersonalAccounts]);
useEffect(() => {
if (searchValueClearing != null && searchValueClearing !== "") {
setFilteredClearingAccounts(
clearingAccounts.filter((t) => {
return (
t.name.toLowerCase().includes(searchValueClearing.toLowerCase()) ||
t.description.toLowerCase().includes(searchValueClearing.toLowerCase())
);
})
);
} else {
return setFilteredClearingAccounts(clearingAccounts);
}
}, [clearingAccounts, searchValueClearing, setFilteredClearingAccounts]);
useTitle(`${group.name} - Accounts`);
const openAccountEdit = (account) => {
setAccountToEdit(account);
setShowPersonalAccountEditModal(true);
};
const closeAccountEdit = (evt, reason) => {
if (reason !== "backdropClick") {
setShowPersonalAccountEditModal(false);
setAccountToEdit(null);
}
};
const openClearingAccountEdit = (account) => {
setClearingAccountToEdit(account);
setShowClearingAccountEditModal(true);
};
const closeClearingAccountEdit = (evt, reason) => {
if (reason !== "backdropClick") {
setShowClearingAccountEditModal(false);
setClearingAccountToEdit(null);
}
};
const confirmDeleteAccount = () => {
if (accountToDelete !== null) {
deleteAccount({ accountID: accountToDelete })
.then((account) => {
updateAccount(account, setAccounts);
setAccountToDelete(null);
})
.catch((err) => {
toast.error(err);
});
}
};
const openCreateDialog = () => {
setClearingAccountToCopy(undefined);
setShowClearingAccountCreationModal(true);
};
const copyClearingAccount = (account) => {
setClearingAccountToCopy(account);
setShowClearingAccountCreationModal(true);
};
return (
<>
<MobilePaper>
<TabContext value={activeTab}>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
<TabList onChange={(e, newValue) => setActiveTab(newValue)} centered>
<Tab
value="personal"
label={
<TextBadge badgeContent={personalAccounts.length} color="primary">
<span>Personal Accounts</span>
</TextBadge>
}
/>
<Tab
label={
<TextBadge badgeContent={clearingAccounts.length} color="primary">
<span>Clearing Accounts</span>
</TextBadge>
}
value="clearing"
/>
</TabList>
</Box>
<TabPanel value="personal">
<List>
{personalAccounts.length === 0 ? (
<Alert severity="info">No Accounts</Alert>
) : (
<>
<ListItem>
<Input
value={searchValuePersonal}
onChange={(e) => setSearchValuePersonal(e.target.value)}
placeholder="Search…"
inputProps={{
"aria-label": "search",
}}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="clear search input"
onClick={(e) => setSearchValuePersonal("")}
edge="end"
>
<Clear />
</IconButton>
</InputAdornment>
}
/>
</ListItem>
<Divider />
{filteredPersonalAccounts.map((account) => (
<ListItem sx={{ padding: 0 }} key={account.id}>
<ListItemLink to={`/groups/${group.id}/accounts/${account.id}`}>
<ListItemText
primary={
<div>
<span>{account.name}</span>
{account.owning_user_id === currentUser.id ? (
<span>
, owned by{" "}
<Chip
size="small"
component="span"
color="primary"
label="you"
/>
</span>
) : (
account.owning_user_id !== null && (
<span>
, owned by{" "}
<Chip
size="small"
component="span"
color="secondary"
label={
memberIDToUsername[
account.owning_user_id
]
}
/>
</span>
)
)}
</div>
}
secondary={account.description}
/>
</ListItemLink>
{userPermissions.can_write && (
<ListItemSecondaryAction>
<IconButton
color="primary"
onClick={() => openAccountEdit(account)}
>
<Edit />
</IconButton>
<IconButton
color="error"
onClick={() => setAccountToDelete(account.id)}
>
<Delete />
</IconButton>
</ListItemSecondaryAction>
)}
</ListItem>
))}
</>
)}
</List>
{userPermissions.can_write && (
<>
<Grid container justifyContent="center">
<Tooltip title="Create Personal Account">
<IconButton
color="primary"
onClick={() => setShowPersonalAccountCreationModal(true)}
>
<Add />
</IconButton>
</Tooltip>
</Grid>
<CreateAccountModal
show={showPersonalAccountCreationModal}
onClose={(evt, reason) => {
if (reason !== "backdropClick") {
setShowPersonalAccountCreationModal(false);
}
}}
group={group}
/>
<EditAccountModal
show={showPersonalAccountEditModal}
onClose={closeAccountEdit}
account={accountToEdit}
group={group}
/>
</>
)}
</TabPanel>
<TabPanel value="clearing">
<List>
{clearingAccounts.length === 0 ? (
<Alert severity="info">No Accounts</Alert>
) : (
<>
<ListItem>
<Input
value={searchValueClearing}
onChange={(e) => setSearchValueClearing(e.target.value)}
placeholder="Search…"
inputProps={{
"aria-label": "search",
}}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="clear search input"
onClick={(e) => setSearchValueClearing("")}
edge="end"
>
<Clear />
</IconButton>
</InputAdornment>
}
/>
</ListItem>
<Divider />
{filteredClearingAccounts.map((account) => (
<ListItem sx={{ padding: 0 }} key={account.id}>
<ListItemLink to={`/groups/${group.id}/accounts/${account.id}`}>
<ListItemText primary={account.name} secondary={account.description} />
</ListItemLink>
{userPermissions.can_write && (
<ListItemSecondaryAction>
<IconButton
color="primary"
onClick={() => openClearingAccountEdit(account)}
>
<Edit />
</IconButton>
<IconButton
color="primary"
onClick={() => copyClearingAccount(account)}
>
<ContentCopy />
</IconButton>
<IconButton
color="error"
onClick={() => setAccountToDelete(account.id)}
>
<Delete />
</IconButton>
</ListItemSecondaryAction>
)}
</ListItem>
))}
</>
)}
</List>
{userPermissions.can_write && (
<>
<Grid container justifyContent="center">
<Tooltip title="Create Clearing Account">
<IconButton color="primary" onClick={openCreateDialog}>
<Add />
</IconButton>
</Tooltip>
</Grid>
<CreateClearingAccountModal
show={showClearingAccountCreationModal}
onClose={(evt, reason) => {
if (reason !== "backdropClick") {
setShowClearingAccountCreationModal(false);
}
}}
initialValues={clearingAccountToCopy}
group={group}
/>
<EditClearingAccountModal
show={showClearingAccountEditModal}
onClose={closeClearingAccountEdit}
account={clearingAccountToEdit}
group={group}
/>
</>
)}
</TabPanel>
</TabContext>
</MobilePaper>
{userPermissions.can_write && (
<>
<SpeedDial
ariaLabel="Create Account"
sx={{ position: "fixed", bottom: 20, right: 20 }}
icon={<SpeedDialIcon />}
// onClose={() => setSpeedDialOpen(false)}
// onOpen={() => setSpeedDialOpen(true)}
onClick={toggleSpeedDial}
open={speedDialOpen}
>
<SpeedDialAction
icon={<PersonalAccountIcon />}
tooltipTitle="Personal"
tooltipOpen
onClick={() => setShowPersonalAccountCreationModal(true)}
/>
<SpeedDialAction
icon={<ClearingAccountIcon />}
tooltipTitle="Clearing"
tooltipOpen
onClick={openCreateDialog}
/>
</SpeedDial>
<Dialog maxWidth="xs" aria-labelledby="confirmation-dialog-title" open={accountToDelete !== null}>
<DialogTitle id="confirmation-dialog-title">Confirm delete account</DialogTitle>
<DialogContent dividers>
Are you sure you want to delete the account "
{allAccounts.find((acc) => acc.id === accountToDelete)?.name}"
</DialogContent>
<DialogActions>
<Button autoFocus onClick={() => setAccountToDelete(null)} color="primary">
Cancel
</Button>
<Button onClick={confirmDeleteAccount} color="error">
Ok
</Button>
</DialogActions>
</Dialog>
</>
)}
</>
);
}