React Scroll button dosent change - css

I have never done alot of designing when it comes to scrolls in react but decided to try today. From my understand the way to do is to use a wrapper and the need for using a library is not needed. I dont understand why nothing happens to my scroll button?
import React, { useState } from 'react'
import ArrowCircleRightIcon from '#mui/icons-material/ArrowCircleRight';
const SendMessageUser = () => {
const styles = {
main: {
height: "100%",
position: "relative"
},
wrapper: {
height: "100%",
position: "relative",
"::-webkit-scrollbar": {
width: "20px"
},
"::-webkit-scrollbar-track": {
backgroundColor: "transparent"
},
"::-webkit-scrollbar-thumb": {
backgroundColor: "#d6dee1",
borderRadius: "20px",
border: "6px solid transparent",
backgroundClip: "content-box"
},
"::-webkit-scrollbar-thumb:hover": {
backgroundColor: "#a8bbbf"
}
},
textArea: {
height: "100%", overflowY: "auto", width: "100%", backgroundColor: "#fff", resize: "none", border: "none", outline: "none", padding: "10px 25px 10px 10px", fontSize: "15px",
}
};
const [message, setMessage] = useState("");
const handleChange = (event) => {
setMessage(event.target.value);
};
const sendMessage = (event) => {
event.preventDefault();
}
return (
<form className="send-message" onSubmit={(event) => sendMessage(event)} style={styles.main}>
<div style={styles.wrapper}>
<textarea spellcheck="false" data-gramm="false" data-gramm_editor="false" data-enable-grammarly="false" style={styles.textArea}>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed hendrerit, ipsum in hendrerit laoreet, ligula ipsum commodo nisl, eu commodo est nulla quis dolor.</textarea>
</div>
<ArrowCircleRightIcon color="primary" sx={{
position: "absolute",
top: 0,
right: 0,
transform: "rotate(-90deg)",
}} />
</form >
)
}
export default SendMessageUser

Related

Pdf generate, enable text wrap and disable break words

When generating pdf file in the table. Is it possible to set to enable text wrap, but disable to break words? Beacuse now it wraps words and added hyphen.
I would like whole word give to the new line without wrap word. How to set it up?
This css works:
flexWrap: wrap, // wrap text
Some css properties cannot be applied:
overflowWrap: "break-word", // Object literal may only specify known properties, and 'overflowWrap' does not exist in type 'Style'.
wordBreak: "normal", // Object literal may only specify known properties, and 'wordBreak' does not exist in type 'Style'.
whiteSpace: "wrap", // Object literal may only specify known properties, and 'whiteSpace' does not exist in type 'Style'.
I use reactjs 17.0.2, react-pdf/renderer 3.0.1, types/react-pdf 5.7.2.
Code:
<Page size="A4" orientation="landscape" style={styles.page}>
<View style={styles.tableContainer}>
{/* -- Table Head: -- */}
<View style={styles.head}>
<Text style={{ ...styles.headCol, width: "8%" }}>{"State"}</Text>
<Text style={{ ...styles.headColLast, width: "24%" }}>{"Subject"}</Text> */}
</View>
{/* -- Table Body: -- */}
<View key={index} style={styles.row}>
<Text style={{ ...styles.rowCol, width: "8%" }}>Ok</Text>
<Text style={{ ...styles.rowColLast, width: "24%" }}>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</Text>
</View>
</View>
</Page>
// style:
const borderColor = "#90e5fc"
const paddingTopText = 3;
const paddingLeftText = 2;
const paddingRightText = 2;
const paddingBottomText = 2;
const rowHeight = 80;
Styles = {
page: {
fontFamily: "OpenSans",
fontSize: "9px",
lineHeight: 1.3,
flexDirection: "column",
paddingTop: 30,
paddingLeft: 30,
paddingRight: 30
},
tableContainer: {
flexDirection: "row",
flexWrap: "wrap", // nowrap
marginTop: 24,
borderColor: borderColor,
borderWidth: 2
},
head: {
flexDirection: "row",
borderBottomColor: borderColor,
borderBottomWidth: 1,
height: "auto",
textAlign: "left",
fontWeight: "bold",
flexGrow: 1,
margin: 0,
padding: 0
},
headCol: {
borderRightColor: borderColor,
borderRightWidth: 1,
paddingTop: paddingTopText,
paddingLeft: paddingLeftText,
paddingRight: paddingRightText,
paddingBottom: paddingBottomText
},
headColLast: {
paddingTop: paddingTopText,
paddingLeft: paddingLeftText,
paddingRight: paddingRightText,
paddingBottom: paddingBottomText
},
row: {
flexDirection: "row",
borderBottomColor: borderColor,
borderBottomWidth: 1,
height: rowHeight,
margin: 0,
padding: 0
},
rowCol: {
textAlign: "left",
borderRightColor: borderColor,
borderRightWidth: 1,
paddingTop: paddingTopText,
paddingLeft: paddingLeftText,
paddingRight: paddingRightText,
paddingBottom: paddingBottomText
},
rowColLast: {
textAlign: "left",
paddingTop: paddingTopText,
paddingLeft: paddingLeftText,
paddingRight: paddingRightText,
paddingBottom: 0
},
}
The following solution works. It doesn't wrap words and it doesn't add hyphen "-". Maybe somebody it helps.
export const chunkSubstr = (str, size) => {
const numChunks = Math.ceil(str.length / size);
const chunks = new Array(numChunks);
for (let i = 0, o = 0; i < numChunks; ++i, o += size) {
chunks[i] = str.substr(o, size);
}
return chunks;
};
Font.registerHyphenationCallback((word) => {
if (word.length > 16) {
return chunkSubstr(word, 14);
} else {
return [word];
}
});

How to make scroll appear only the content exceeds specified width?

I am creating custom tabs using react and material UI. In these tabs, we don't have a fixed tab count, based on the data, the length of the tab might increase and decrease. So we planned to add scrollable functionality If the tabs count is not occupied in the given space.
But by default, the scroll is appearing even if we have only one data.
below is the code for it.
import { Key, useState } from "react";
import { styled } from "#mui/material/styles";
import Button from "#mui/material/Button";
import { ReactComponent as Plus } from "./plus.svg";
import React from "react";
const Tabs = styled("div")`
width: 100%;
overflow: hidden;
margin: 1em 0 2em;
`;
const TabContainer = styled("ul")(() => ({
padding: 0,
margin: 0,
display: "flex",
flex: "1 1 auto",
overflowX: "auto",
overflowY: "hidden",
"& li": {
"&:first-of-type": {
marginLeft: 0,
"#media (max-width: 991px)": {
marginLeft: 10
}
}
},
"#media (max-width: 400px)": {
display: "unset"
}
}));
const Nav = styled("nav")(() => ({
display: "flex",
"#media (max-width: 991px)": {
textAlign: "center"
}
}));
const Tab = styled("li")(({ theme }) => ({
border: `2px solid ${theme.palette.grey[900]}`,
borderBottom: "none",
margin: "0 10px",
display: "block",
float: "left",
position: "relative",
borderTopRightRadius: 5,
borderTopLeftRadius: 5,
backgroundColor: theme.palette.common.white,
"#media (max-width: 991px)": {
float: "unset",
textAlign: "center"
},
"&.tab-current": {
border: `2px solid ${theme.palette.primary.main}`,
borderBottom: "none",
zIndex: 100,
"&::before": {
content: '""',
position: "absolute",
height: "2px",
right: "100%",
bottom: 0,
width: "1000px",
background: theme.palette.primary.main
},
"&::after": {
content: '""',
position: "absolute",
height: "2px",
right: "100%",
left: "100%",
bottom: 0,
width: "4000px",
background: theme.palette.primary.main
},
"& span": {
color: theme.palette.primary.main
}
}
}));
const Span = styled("span")(({ theme }) => ({
color: theme.palette.grey[900],
display: "block",
fontSize: "24px",
lineHeight: 2.5,
padding: "0 14px",
cursor: "pointer",
fontWeight: 400,
overflow: "hidden",
maxWidth: "ch",
textOverflow: "ellipsis",
whiteSpace: "nowrap"
}));
const AddGoalCTA = styled("span")(({ theme }) => ({
color: theme.palette.grey[900],
display: "block",
fontSize: "24px",
lineHeight: 2.5,
padding: "0 24px",
cursor: "pointer",
fontWeight: 900,
overflow: "hidden",
whiteSpace: "nowrap"
}));
const ButtonContainer = styled("div")(() => ({
float: "right",
"#media (max-width: 991px)": {
display: "none"
},
"& .MuiButton-root": {
padding: "10px"
}
}));
const PlusIcon = styled("span")(() => ({
width: "24px",
color: "black"
}));
const tabsData = ["Save For College", "Retirement Saving", "Save For Bike"];
// const tabsData = ["Save For College", "Retirement Saving", "Save For Bike", "Legacy Saving", "Save For Poker", "Save For Money"]
const TabsComponent = ({ hideEditButton, showAddTab = true }: any) => {
const [toggleState, setToggleState] = useState(0);
const toggleTab = (index: any) => {
setToggleState(index);
};
return (
<>
<Tabs>
<Nav>
<TabContainer>
{tabsData?.map((value: string, index: Key | null | undefined) => (
<Tab
className={toggleState === index ? "tab-current" : ""}
onClick={() => toggleTab(index)}
key={index}
tabIndex={0}
role="tab"
>
<Span>{value}</Span>
</Tab>
))}
{showAddTab && (
<Tab
onClick={() => {}}
tabIndex={0}
role="tab"
onKeyPress={() => {}}
>
<AddGoalCTA>
<PlusIcon as={Plus} />
</AddGoalCTA>
</Tab>
)}
</TabContainer>
{!hideEditButton && (
<ButtonContainer>
<Button variant="contained" onClick={() => {}}>
Edit
</Button>
</ButtonContainer>
)}
</Nav>
</Tabs>
</>
);
};
export default TabsComponent;
Here you can find the working demo - https://codesandbox.io/s/mui-tabs-9sgt89?file=/tab.tsx:0-4092
Please help me to resolve this one.
I checked your code. Actually for the current tab &::after has fixed width width: "4000px", which is causing the issue. you can reduce it to 1000px or to your convenience.
Hope this helps!!
Thanks

MUI Modal [tabindex]?

I have tried incorporating a modal into my project, but the modal is not able to close and the height is covering the entire screen length. When I inspect element, it says:
[tabindex]:
outline: none;
height: 100%
How do I get rid of this height: 100% ?
This is the code (from MUI example + my styled component):
import React from 'react';
import Modal from '#mui/material/Modal';
import styled from 'styled-components';
import Box from '#mui/material/Box';
import Typography from '#mui/material/Typography';
const style = {
position: 'absolute' as 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 400,
bgcolor: 'background.paper',
border: '2px solid #000',
boxShadow: 24,
p: 4,
};
export function FeedbackButton() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<>
<FButton onClick={handleOpen}>FeedBack</FButton>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<Box sx={style}>
<Typography id="modal-modal-title" variant="h6" component="h2">
Text in a modal
</Typography>
<Typography id="modal-modal-description" sx={{ mt: 2 }}>
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
</Typography>
</Box>
</Modal>
</>
);
}
const FButton = styled.button`
position: absolute;
background: white;
bottom: 15px;
right: 15px;
padding: 16px;
border-radius: 10px;
font-size: 20px;
font-family: Verlag;
`;
the problems with height 100% are:
if I set the modal style to a fixed height limit, it doesn't close when I click outside of it because of the overflow
looks ugly
TLDR: How do I exempt this one element from [tabindex]?
try setting your own height like in the example
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 400,
hieght: 600,

How to apply nested styles to my react form component,only main styles are appending not nested ones

const formContainer = {
maxWidth: "300px",
backgroundColor: '#FD439B',
padding: "10px",
"& textarea" : {
width: '100%',
padding: '15px',
margin: '5px 0 22px 0',
border: "none",
background: '#F1F1F1',
resize: "none",
minHeight: '200px'
},
"& focus" : {
backgroundColor: '#ddd',
outline: 'none'
};
JS Code :
<div class="formContainer" style={formContainer}>
With this code only formContainer maxWidth,backgroundColor,padding is appending ,remaining code like textarea,focus styles are not coming.
do it with Material-UI styles :
import React from "react";
import { withStyles } from "#material-ui/core/styles";
const styles = theme => ({
root: {
maxWidth: "300px",
backgroundColor: '#FD439B',
padding: "10px",
"& textarea" : {
width: '100%',
padding: '15px',
margin: '5px 0 22px 0',
border: "none",
background: '#F1F1F1',
resize: "none",
minHeight: '200px'
},
"& textarea:focus" : {
backgroundColor: '#ddd',
outline: 'none'
}
}
});
function TypographyTheme(props) {
return (
<div className={props.classes.root} contenteditable="false">
<textarea>
"This div's text looks like that of a button.
</textarea>
</div>
);
}
export default withStyles(styles)(TypographyTheme);
Demo

flexlayout problem with mobile resolution and container

HELLO I have the following structure in my flexbox
header
main
footer
and in my main I have a container to centralize the content But when I use smaller resolutions it is problematic as in the photo:
code:
export default function App() {
return (
<div style={{ display: "flex", flexDirection: "column", height: "100%" }}>
<div style={{ flex: "none", background: "blue", height: "140px" }}>a</div>
<div
style={{
padding: "0 30px",
margin: "0 auto",
background: "red",
maxWidth: "1240px",
width: "100%"
}}
>
<h2>
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi..
</h2>
</div>
<div style={{ flex: "none", background: "yellow", height: "40px" }}>
c
</div>
</div>
);
}
css reset:
body > #root > div {
height: 100vh;
background: black;
}
body {
margin: 0;
padding: 0;
}
example:
https://codesandbox.io/s/throbbing-feather-cmxiq
The width property does not include padding, so when your middle element includes a 30px padding on left and right sides AND is also set to 100% width, it causes an x-overflow. If you want the middle element's entire bounding box to be 100% width, you can do the following styles:
<div
style={{
padding: "0 30px",
margin: "0 auto",
background: "red",
maxWidth: "1240px",
width: "calc(100% - 60px)"
}}
>

Resources