@mui/material/styles#alpha TypeScript Examples
The following examples show how to use
@mui/material/styles#alpha.
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: menu-icon.tsx From tams-club-cal with MIT License | 6 votes |
MenuIcon = (props: PropsWithChildren<MenuIconProps>) => {
return (
<Tooltip title={props.title} aria-label={props['aria-label']}>
<ButtonBase
onClick={props.onClick}
sx={{
marginLeft: '0.5rem',
marginRight: '0.5rem',
padding: '0.5rem',
borderRadius: '10rem',
backgroundColor: 'transparent',
cursor: 'pointer',
transition: '0.2s',
'&:hover': {
backgroundColor: (theme) =>
alpha(darkSwitch(theme, theme.palette.common.black, theme.palette.common.white), 0.1),
},
}}
>
{props.children}
</ButtonBase>
</Tooltip>
);
}
Example #2
Source File: hitComps.tsx From usehooks-ts with MIT License | 6 votes |
Hits = styled(List)(({ theme }) => ({
overflowY: 'auto',
padding: theme.spacing(1),
[`& .${classes.hit}`]: {
paddingTop: theme.spacing(1),
flexDirection: 'column',
alignItems: 'start',
border: '1px solid',
borderColor: 'transparent',
'& em': {
fontStyle: 'normal',
background: alpha(theme.palette.primary.main, 0.3),
},
'&:hover, &:focus': {
border: '1px solid',
borderColor: theme.palette.primary.main,
borderRadius: theme.shape.borderRadius,
backgroundColor: alpha(theme.palette.primary.main, 0.1),
},
},
[`& .${classes.title}`]: {
fontFamily: 'Fira Code, monospace',
marginBottom: theme.spacing(1),
display: 'block',
},
}))
Example #3
Source File: Files.tsx From NekoMaid with MIT License | 6 votes |
StyledTreeItem = styled((props: TreeItemProps) => <TreeItem {...props} />)(({ theme }) => ({
[`& .${treeItemClasses.label}`]: {
display: 'flex',
paddingLeft: '0!important',
'& embed': {
width: 'inherit',
height: 'inherit'
},
[`& .${iconClasses.root}`]: {
margin: '-2px 4px 0 0'
}
},
[`& .${treeItemClasses.group}`]: {
marginLeft: 15,
borderLeft: `1px dashed ${alpha(theme.palette.text.primary, 0.4)}`
}
}))
Example #4
Source File: SearchBar.tsx From firecms with MIT License | 5 votes |
useStyles = makeStyles((theme: Theme) =>
createStyles({
search: {
position: "relative",
display: "flex",
alignItems: "center",
height: 40,
borderRadius: theme.shape.borderRadius,
backgroundColor: theme.palette.mode === "light" ? alpha(theme.palette.common.black, 0.05) : darken(theme.palette.background.default, 0.2),
"&:hover": {
backgroundColor: theme.palette.mode === "light" ? alpha(theme.palette.common.black, 0.10) : darken(theme.palette.background.default, 0.3)
},
marginLeft: theme.spacing(1),
[theme.breakpoints.up("sm")]: {
marginLeft: theme.spacing(1),
width: "auto"
}
},
searchIcon: {
padding: theme.spacing(0, 2),
height: "100%",
position: "absolute",
pointerEvents: "none",
display: "flex",
alignItems: "center",
justifyContent: "center"
},
inputRoot: {
color: "inherit",
minHeight: "inherit"
},
inputInput: {
padding: theme.spacing(1, 1, 1, 0),
// vertical padding + font size from searchIcon
paddingLeft: `calc(1em + ${theme.spacing(4)})`,
transition: theme.transitions.create("width"),
width: "100%",
[theme.breakpoints.up("sm")]: {
width: "12ch"
}
},
inputActive: {
[theme.breakpoints.up("sm")]: {
width: "20ch"
}
}
})
)
Example #5
Source File: calendar-day.tsx From tams-club-cal with MIT License | 5 votes |
CalendarDay = (props: CalendarDayPopup) => {
const [popupOpen, setPopupOpen] = useState(false);
// Switches the popup state to open if clicked
const togglePopup = (open: boolean) => setPopupOpen(open);
// Calculates how many extra events there are that can't fit
// and slices the array accordingly
const maxActivities = props.rows === 5 ? 3 : 4;
const extraActivities = Math.max(props.activities.length - maxActivities, 0);
const activities = extraActivities > 0 ? props.activities.slice(0, maxActivities) : props.activities;
return (
<Box
sx={{
borderBottom: (theme) =>
`1px solid ${darkSwitch(theme, theme.palette.grey[300], theme.palette.grey[700])}`,
borderRight: (theme) =>
props.noRight
? 'none'
: `1px solid ${darkSwitch(theme, theme.palette.grey[300], theme.palette.grey[700])}`,
cursor: 'pointer',
transition: '0.2s',
'&:hover': {
backgroundColor: (theme) => darkSwitch(theme, alpha(theme.palette.grey[200], 0.9), theme.palette.grey[800]),
},
}}
onClick={togglePopup.bind(this, true)}
>
<Typography
sx={{
margin: 0.5,
padding: 0.5,
minWidth: 28,
height: 28,
fontSize: '1rem',
color: (theme) =>
props.isToday
? theme.palette.primary.main
: props.otherMonth
? darkSwitch(theme, theme.palette.grey[400], theme.palette.grey[700])
: 'inherit',
}}
>
{props.date.date()}
</Typography>
<List sx={{ paddingTop: 0 }}>
{activities.map((a) => (
<CalendarEvent activity={a} key={a.id} />
))}
{extraActivities === 0 ? null : (
<ListItem sx={{ padding: 0 }}>
<Typography
sx={{
width: '100%',
fontSize: { lg: '0.8rem', xs: '0.5rem' },
textAlign: 'center',
color: (theme) => darkSwitchGrey(theme),
}}
>
{`+${extraActivities} more event(s)`}
</Typography>
</ListItem>
)}
</List>
<CalendarPopup
activities={props.activities}
date={props.date}
open={popupOpen}
close={togglePopup.bind(this, false)}
/>
</Box>
);
}
Example #6
Source File: menu-link.tsx From tams-club-cal with MIT License | 5 votes |
MenuLink = (props: MenuLinkProps) => {
const [active, setActive] = useState(false);
const router = useRouter();
// Set the active state of the link based on the current path
// If the path does not match, check if props.isActive is true and use that instead
// This is used when there are multiple paths to match and a custom function can be passed in
useEffect(() => {
setActive(
props.href === '/'
? router.pathname === '/' || router.pathname.startsWith('/events')
: router.pathname.startsWith(props.href) || props.isActive
);
}, [router.pathname]);
return (
<Link
href={props.href}
sx={{
height: '4rem',
paddingLeft: '1rem',
paddingRight: '1rem',
textDecoration: 'none',
borderColor: 'transparent',
borderBottom: (theme) =>
darkSwitch(theme, 'none', !active ? '0.2rem' : `0.2rem solid ${theme.palette.primary.light}`),
backgroundColor: (theme) => (active ? alpha(theme.palette.common.white, 0.1) : 'transparent'),
transition: '0.2s',
color: (theme) =>
!active
? darkSwitch(theme, theme.palette.grey[800], theme.palette.grey[400])
: darkSwitch(theme, theme.palette.primary.main, theme.palette.primary.light),
'&:hover': {
color: (theme) => darkSwitch(theme, theme.palette.primary.main, theme.palette.primary.light),
backgroundColor: (theme) =>
darkSwitch(theme, 'transparent', alpha(theme.palette.common.white, 0.1)),
},
}}
>
<Box
sx={{
height: '4rem',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
}}
>
<Typography
variant="h5"
sx={{
marginLeft: '0.5rem',
marginRight: '0.5rem',
}}
>
{props.children}
</Typography>
</Box>
</Link>
);
}
Example #7
Source File: App.tsx From NekoMaid with MIT License | 4 votes |
App: React.FC<{ darkMode: boolean, setDarkMode: (a: boolean) => void }> = React.memo(({ darkMode, setDarkMode }) => {
const loc = useLocation()
const his = useHistory()
const pluginRef = useRef<Plugin | null>(null)
const [mobileOpen, setMobileOpen] = useState(false)
const [globalItemsOpen, setGlobalItemsOpen] = useState(false)
const [globalData, setGlobalData] = useState<GlobalInfo>({ } as any)
const [drawerWidth, setDrawerWidth] = useState(240)
const updateF = useState(0)[1]
const create = useMemo(() => {
const io = socketIO(origin!, { path: pathname!, auth: { token } })
const map: Record<string, Plugin> = { }
const fn = (window as any).__NekoMaidAPICreate = (name: string) => map[name] || (map[name] = new Plugin(io, name))
const nekoMaid = pluginRef.current = fn('NekoMaid')
io.on('globalData', (data: GlobalInfo) => {
const his: ServerRecord[] = JSON.parse(localStorage.getItem('NekoMaid:servers') || '[]')
const curAddress = address!.replace('http://', '') + '?' + token
let cur = his.find(it => it.address === curAddress)
if (!cur) his.push((cur = { address: curAddress, time: 0 }))
cur.time = Date.now()
cur.icon = data.icon
const arr = loc.pathname.split('/')
if (!sent && arr.length > 2) io.emit('switchPage', arr[1], arr[2])
sent = true
localStorage.setItem('NekoMaid:servers', JSON.stringify(his))
new Set(Object.values(data.plugins).flat()).forEach(loadPlugin)
setGlobalData(data)
pages = { }
initPages(nekoMaid)
onGlobalDataReceived(nekoMaid, data)
update(Math.random())
if (process.env.NODE_ENV !== 'development' && data.pluginVersion !== version) toast(lang.pluginUpdate, 'warning')
}).on('!', () => {
io.close()
dialog({ content: lang.wrongToken, cancelButton: false })
// eslint-disable-next-line no-return-assign
.then(() => (location.search = location.pathname = location.hash = ''))
}).on('reconnect', () => {
toast(lang.reconnect)
setTimeout(() => location.reload(), 5000)
}).on('disconnect', () => failed(lang.disconnected)).on('connect_error', () => failed(lang.failedToConnect))
return fn
}, [])
useEffect(() => { if (!loc.pathname || loc.pathname === '/') his.replace('/NekoMaid/dashboard') }, [loc.pathname])
useEffect(() => {
update = updateF
return () => { update = undefined as any }
}, [])
const handleDrawerToggle = () => {
setDrawerWidth(240)
setMobileOpen(!mobileOpen)
}
const isExpand = drawerWidth === 240
const routes: JSX.Element[] = []
const mapToItem = (name: string, it: Page) => {
const path = Array.isArray(it.path) ? it.path[0] : it.path
const key = '/' + name + '/' + path
routes.push(<pluginCtx.Provider key={key} value={create(name)}>
<Route
path={Array.isArray(it.path) ? it.path.map(it => '/' + name + '/' + it) : key}
component={it.component}
strict={it.strict}
exact={it.exact}
sensitive={it.sensitive}
/>
</pluginCtx.Provider>)
const icon = <ListItemIcon><pluginCtx.Provider value={create(name)}>
{(typeof it.icon === 'function' ? <it.icon /> : it.icon) || <Build />}
</pluginCtx.Provider></ListItemIcon>
return it.title
? <NavLink key={key} to={'/' + name + '/' + (it.url || path)} activeClassName='actived'>
<ListItem button>
{isExpand ? icon : <Tooltip title={it.title} placement='right'>{icon}</Tooltip>}
{isExpand && <ListItemText primary={it.title} />}
</ListItem>
</NavLink>
: undefined
}
const singlePages: JSX.Element[] = []
const multiPagesPages: Array<JSX.Element | JSX.Element[]> = []
let index = 0
for (const name in pages) {
if (pages[name].length === 1) {
const elm = mapToItem(name, pages[name][0])
if (elm) singlePages.push(elm)
} else {
if (multiPagesPages.length) multiPagesPages.push(<Divider key={index++} />)
multiPagesPages.push(pages[name].map(it => mapToItem(name, it)!).filter(Boolean))
}
}
if (singlePages.length) multiPagesPages.push(<Divider key={index++} />, singlePages)
const drawer = <Box sx={{ overflowX: 'hidden' }}>
<Toolbar />
<Divider sx={{ display: { sm: 'none', xs: 'block' } }} />
<List sx={{
'& a': {
color: 'inherit',
textDecoration: 'inherit'
},
'& .actived > div': {
fontWeight: 'bold',
color: theme => theme.palette.primary.main,
backgroundColor: theme => alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity) + '!important',
'& svg': { color: theme => theme.palette.primary.main + '!important' }
}
}}>{multiPagesPages.flat()}</List>
</Box>
return <Box sx={{ display: 'flex' }}>
<CssBaseline />
<AppBar position='fixed' sx={{ zIndex: theme => theme.zIndex.drawer + 1 }}>
<Toolbar>
<IconButton
color='inherit'
edge='start'
onClick={() => setDrawerWidth(isExpand ? 57 : 240)}
sx={{ mr: 1, display: { sm: 'inline-flex', xs: 'none' } }}
><ChevronLeft sx={{ transition: '.3s', transform: isExpand ? undefined : 'rotate(-180deg)' }} /></IconButton>
<IconButton color='inherit' edge='start' onClick={handleDrawerToggle} sx={{ mr: 2, display: { sm: 'none' } }}><Menu /></IconButton>
<Typography variant='h3' noWrap component='div' sx={{ flexGrow: 1 }}>NekoMaid</Typography>
{globalData.hasNBTAPI && <IconButton
color='inherit'
onClick={() => setGlobalItemsOpen(!globalItemsOpen)}
onDragOver={() => setGlobalItemsOpen(true)}
><Backpack /></IconButton>}
<LanguageSwitch />
<IconButton color='inherit' edge='end' onClick={() => setDarkMode(!darkMode)}>
{darkMode ? <Brightness7 /> : <Brightness4 />}
</IconButton>
</Toolbar>
</AppBar>
<globalCtx.Provider value={globalData}>
<Box component='nav' sx={{ width: { sm: drawerWidth }, flexShrink: { sm: 0 } }}>
<Drawer
variant='temporary'
open={mobileOpen}
onClose={handleDrawerToggle}
ModalProps={{ keepMounted: true }}
sx={{
display: { xs: 'block', sm: 'none' },
'& .MuiDrawer-paper': {
boxSizing: 'border-box',
width: drawerWidth,
backgroundImage: theme => theme.palette.mode === 'dark'
? 'linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05))'
: undefined
}
}}
>
{drawer}
</Drawer>
<Drawer
open
variant='permanent'
sx={{
display: { xs: 'none', sm: 'block' },
'& .MuiDrawer-paper': {
boxSizing: 'border-box',
width: drawerWidth,
transition: 'width .3s',
backgroundImage: theme => theme.palette.mode === 'dark' ? 'linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05))' : undefined
}
}}
>
{drawer}
</Drawer>
</Box>
<Box component='main' sx={{ flexGrow: 1, width: '100vw' }}>
<drawerWidthCtx.Provider value={drawerWidth}>{routes}</drawerWidthCtx.Provider>
{globalData.hasNBTAPI && <pluginCtx.Provider value={pluginRef.current}>
<GlobalItems open={globalItemsOpen} onClose={() => setGlobalItemsOpen(false)} />
</pluginCtx.Provider>}
</Box>
</globalCtx.Provider>
</Box>
})