Progress bar component not showing up within Group/Stack - reactjs

Whenever I try to place a progress bar inside a Group/Stack, it does not show up on my webpage. It works only when I place it outside the Group/Stack. Here is the code and results:
import { Stack, ThemeIcon, Text, Progress, Group, Button } from "#mantine/core";
interface SkillProps {
name: string;
icon: JSX.Element;
}
function Skill(props: SkillProps) {
return (
<>
<Group>
<ThemeIcon size={50} radius={25} variant="outline">
{props.icon}
</ThemeIcon>
<Stack align="center" spacing={5}>
<Text>{props.name}</Text>
</Stack>
<Progress value={50} />
</Group>
</>
);
}
export default Skill;
When placed within Group/Stack: Result
When placed outside Group/Stack: Result
Anyone has any idea why this is happening?

It seems that this might be because Progress does not have a specified width from parent container when in Group or Stack.
For use in Group, try add flex:"1" to Progress with the sx prop, which will make it take the remaining space in Group:
<Group>
<ThemeIcon size={50} radius={25} variant="outline">
{props.icon}
</ThemeIcon>
<Stack align="center" spacing={5}>
<Text>{props.name}</Text>
</Stack>
<Progress value={20} sx={{ flex: "1" }} />
</Group>
For use in Stack, try add alignSelf: "stretch" instead for similar result:
<Group>
<ThemeIcon size={50} radius={25} variant="outline">
{props.icon}
</ThemeIcon>
<Stack align="center" spacing={5}>
<Text>{props.name}</Text>
<Progress value={20} sx={{ alignSelf: "stretch" }} />
</Stack>
</Group>

Related

Add dynamic value beside label in Material UI React Tabs Component

I am creating tabs using material ui and i want to add value beside label (ex: 05 written beside Recommendation label) which will be dynamic in the tabs component just like shown in below image:
Here is my code snippet of Tabs component:
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={value} onChange={handleChange} aria-label="basic tabs example">
<Tab label="Recommendation" />
<Tab label="Ongoing" />
<Tab label="Completed" />
</Tabs>
</Box>
One option is to create your own component, pass that in as a the Tab label, and then style it as needed. For example:
const TabWithCount = ({ children, count }) => {
return (
<Box sx={{ display: "inline-flex", alignItems: "center" }}>
<Typography component="div">{children}</Typography>
{count ? (
<Typography
component="div"
variant="body2"
sx={{ marginLeft: "0.5rem" }}
>
{count}
</Typography>
) : null}
</Box>
);
};
...
<Tab
label={<TabWithCount count="05">Recommendation</TabWithCount>}
/>
I've created a quick (unstyled) example to illustrate the solution: https://codesandbox.io/s/basictabs-material-demo-forked-i9543?file=/demo.js

Menu's dropdown on Chart is being offset

I'm adding a chakra-ui menu dropdown button to a chart (from react-financial-charts, which is a library built over svg).
For some reason, when I click on the menu, there will be whitespace between the button and the dropdown menu. This only happens when I put the menu onto the chart. If I have the menu standalone in the browser, it'll work as expected.
This is the menu code:
function TestMenu() {
return (
<g className="react-financial-charts-enable-interaction">
<foreignObject
x={30}
y={30}
width={"100%"}
height={"100%"}
style={{ overflow: "auto" }}
>
<Menu>
<MenuButton as={Button} rightIcon={<ChevronDownIcon />}>
Actions
</MenuButton>
<MenuList>
<MenuItem>Download</MenuItem>
<MenuItem>Create a Copy</MenuItem>
<MenuItem>Mark as Draft</MenuItem>
<MenuItem>Delete</MenuItem>
<MenuItem>Attend a Workshop</MenuItem>
</MenuList>
</Menu>
</foreignObject>
</g>
);
}
This is the full codesandbox:
https://codesandbox.io/s/nervous-haze-3mz2c?file=/src/BasicLineSeries.tsx:511-1199
EDIT
If I remove x={0} and y={0} from foreignObject and include style={{ marginTop: "30px", marginLeft: "30px" }} into MenuButton instead, as suggested by one of the answers, this will solve the problem only if the chart is at the top of the page. Otherwise, if there is a div before the chart, then this will occur:
and here's the full codesandbox for that:
https://codesandbox.io/s/nostalgic-pare-c5rxu?file=/src/BasicLineSeries.tsx
UPDATED
According to the menu list position problem, you can make use of Portal to move the entire list options to the bottom of the DOM so that its style will not be affected by any style/component inside the Chart.
...
<Menu>
<MenuButton
as={Button}
rightIcon={<ChevronDownIcon />}
transition="all 0.001s"
borderRadius="md"
borderWidth="0px"
_hover={{ bg: "gray.400" }}
_expanded={{ bg: "blue.400" }}
_focus={{ boxShadow: "none" }}
style={{ marginTop: "30px", marginLeft: "30px" }} // better move the style to css file
>
Actions
</MenuButton>
<Portal>
<MenuList zIndex={10}>
<MenuItem>Download</MenuItem>
<MenuItem>Create a Copy</MenuItem>
<MenuItem>Mark as Draft</MenuItem>
<MenuItem>Delete</MenuItem>
<MenuItem>Attend a Workshop</MenuItem>
</MenuList>
</Portal>
</Menu>
...
The Updated Codesandbox
The white space is triggered by the foreignObject's x and y where the MenuList is respecting the space specified in foreignObject. (You can try to increase x and y, you will see a larger gap between the button and menu list)
To solve the problem, you can remove the x and y and apply the margin on MenuButton
...
<foreignObject
width={"100%"}
height={"100%"}
style={{ overflow: "auto" }}
>
<Menu>
<MenuButton
as={Button}
rightIcon={<ChevronDownIcon />}
transition="all 0.001s"
borderRadius="md"
borderWidth="0px"
_hover={{ bg: "gray.400" }}
_expanded={{ bg: "blue.400" }}
_focus={{ boxShadow: "none" }}
style={{ marginTop: "30px", marginLeft: "30px" }} // better move the style to css file
>
Actions
</MenuButton>
<MenuList>
<MenuItem>Download</MenuItem>
<MenuItem>Create a Copy</MenuItem>
<MenuItem>Mark as Draft</MenuItem>
<MenuItem>Delete</MenuItem>
<MenuItem>Attend a Workshop</MenuItem>
</MenuList>
</Menu>
</foreignObject>
...
Here is the modified codesandbox

react-infinite-scroll not working inside Material UI Drawer

I am currently using react-infinite-scroll-component to paginate the comments from a certain post. There is a button in the comment section which shows a drawer that is supposed to show the paginated comments. The problem is, the react-infinite-scroll-component doesn't work, as it does not fire
the "next" function.
Here is the code:
<div>
<Drawer
anchor={"bottom"}
open={open}
onClose={handleDrawer}
style={{ height: "100vh", overflow: "auto", margin: "0px 4px" }}
>
<Toolbar>
<Typography variant="h4" style={{ flexGrow: 1 }}>
Comments
</Typography>
<IconButton onClick={handleDrawer}>
<CloseIcon />
</IconButton>
</Toolbar>
<Divider />
<br />
<CommentForm
comment={comment}
handleChange={handleChange}
handleSubmit={handleSubmit}
/>
<InfiniteScroll
dataLength={page}
next={More}
hasMore={hasMore}
loader={
<>
<br />
<CircularProgress />
</>
}
style={{
overflow: "hidden",
}}
scrollThreshold={1}
>
<CommentList comments={comments} id={session.id} />
</InfiniteScroll>
</Drawer>
</div>
The drawer is mostly similar to Youtube's comment drawer on the mobile app. Is there anything I am missing here?
Probably, the problem is the relation with Drawer and Infinite Scroll height. The height of Infinite Scroll is not reaching the right point to trigger next function. If you provide the demo in Codesandbox would be easier to understand.
Fixed height of infinite scroll container
<Box sx={{ height: 500 }}>
<InfiniteScroll
dataLength={page}
next={More}
hasMore={hasMore}
loader={
<>
<br />
<CircularProgress />
</>
}
style={{
overflow: "hidden",
}}
scrollThreshold={1}
>
<CommentList comments={comments} id={session.id} />
</InfiniteScroll>
</Box>

How do you set the material-ui cardholder avatar?

I'm trying to use the material-ui CardHolder component -- https://material-ui.com/api/card-header/ . I have this image in my project
src/img/apple.svg
so I tried to set the avatar image like so
<Card className={classes.root} {...rest}>
<CardHeader
avatar="img/apple.svg"
title={title}
titleTypographyProps={{ variant: "h2", component: "span" }}
className={classes.cardHeader}
/>
<CardContent className={classes.cardContent}>
but instead what is printed out is just the path of my image. What's the proper way to output the avatar as a real image?
You can make use of Avatar component from Material-ui and pass it on as a avatar prop.
the problem in your code is that you are trying to pass on a src to it whereas it takes in a Node
<Card className={classes.root} {...rest}>
<CardHeader
avatar={<Avatar alt="Apple" src="img/apple.svg" />}
title={title}
titleTypographyProps={{ variant: "h2", component: "span" }}
className={classes.cardHeader}
/>
<CardContent className={classes.cardContent}>
The avatar prop accepts a node, so you can use avatar api like this one
avatar={<Avatar alt="An apple" src="img/apple.svg" />}
So your code will become
<Card className={classes.root} {...rest}>
<CardHeader
avatar={<Avatar alt="An apple" src="img/apple.svg" />}
title={title}
titleTypographyProps={{ variant: "h2", component: "span" }}
className={classes.cardHeader}
/>
<CardContent className={classes.cardContent}>
Are you sure avatar takes an image? From what I can see in the demo. In the component.
avatar={
<Avatar aria-label="recipe" className={classes.avatar}>
R
</Avatar>
}
In the styles:
avatar: {
backgroundColor: red[500],
},
Can't find an image attribute for avatar props.

Sticky content scrolling up into fixed menu header Semantic UI

So I've set up some sticky rail content using an example for the SUIR docs. However, when scrolling the main content, the rail content scrolls into my fixed header.
Do I need to set more rules on the style prop for <Rail>?
Codesandbox link here
To view the issue, navigate to Docs from the menu bar.
The <Rail> component is at the bottom of Overview.js file
export default class Overview extends Component {
contextRef = createRef();
render() {
return (
<div>
<FixedMenuLayout />
<Grid centered columns={3} style={{ marginTop: "7em" }}>
<Grid.Column>
<Ref innerRef={this.contextRef}>
<Segment>
<Docs />
<Rail position="left">
<Sticky context={this.contextRef}>
<Header as="h3">Getting Started</Header>
<List style={{ padding: "5px" }}>
<List.Item>Overview</List.Item>
<List.Item>Examples</List.Item>
<List.Item>Tutorial</List.Item>
</List>
<Header as="h3">How To</Header>
<List style={{ padding: "5px" }}>
<List.Item>Building</List.Item>
<List.Item>Standalone</List.Item>
<List.Item>Deployment</List.Item>
</List>
<Header as="h3">Development</Header>
<List style={{ padding: "5px" }}>
<List.Item>Road Map</List.Item>
<List.Item>Upcoming Features</List.Item>
</List>
</Sticky>
</Rail>
<Rail position="right">
<Sticky context={this.contextRef}>
<Header as="h3">Overview</Header>
<List style={{ padding: "5px" }}>
<List.Item>Overview</List.Item>
<List.Item>Examples</List.Item>
<List.Item>Tutorial</List.Item>
</List>
</Sticky>
</Rail>
</Segment>
</Ref>
</Grid.Column>
</Grid>
</div>
);
}
}
Well a rather easy fix just didn't see the correct prop that handles this exact issue.
The offset prop for <Sticky> needs to be set to an appropriate value.
In my case,
<Sticky offset={90} context={this.contextRef}>

Resources