Why invisible on the screen elements partly appear while printing? - html

I generate play-off tournament bracket...
Usually in each tour there are 2^n participants: 16, 8, 4, 2. And it's easy to adjust them in flex column. But there is a tricky thing, when in first tour (round), participants count is between 16 and 8. And I need invisible duels, just like place holder in bracket, for adjustment.
I tried to do them {visibility: hidden}, they disappear on the screen. But unexpectedly partially appears when printing.
Why it happens?
How it looks on the screen (it's good, just like I planned):
And how it looks while printing (ctrl+P):
And there is a code:
import React from 'react'
import { Checkbox, Box } from '#material-ui/core'
import { makeStyles } from '#material-ui/core/styles'
import { find } from 'lodash'
import { athletName, trainerName } from '../../config/functions'
function DuelSimple(props) {
const {
duelData,
participants,
onFighterChange,
onWinnerChange,
showScoreInput,
showWinnerCheckbox
} = props
const { id, fighterRed, fighterBlue, winner, label /* scoreRed, scoreBlue */ } = duelData
const styles = {
duelTable: props => ({
/* width: '5cm', */
border: '1px solid gray',
borderRadius: 5,
marginBottom: 5,
borderSpacing: 0,
tableLayout: 'fixed',
visibility: props.duelData.status === 'fake' ? 'hidden' : 'visible'
}),
duelNumber: {
width: 30,
borderRight: '1px solid gray',
textAlign: 'center',
color: 'slategray'
},
duelLabel: {
fontSize: 9
},
athletRed: { width: 140, height: 33, padding: '0 5px', borderBottom: '1px solid gray' },
athletBlue: { width: 140, height: 33, padding: '0 5px' },
athletInput: { width: '100%', border: 'none' },
checkboxColumn: { width: 35, height: 33 },
checkboxColumnRed: { borderBottom: '1px solid gray' },
checkboxRed: { width: 7, height: 7, marginTop: 2, color: 'red' },
checkboxBlue: { width: 7, height: 7, marginTop: 2, color: 'blue' },
trainer: { color: 'gray', fontSize: 10 },
athletColorColumn: { width: 5 },
athletColorRed: { backgroundColor: 'rgba(255,0,0,0.5)', borderBottom: ' 1px solid gray' },
athletColorBlue: { backgroundColor: 'rgba(0,0,255,0.5)' },
scoreColumn: { width: 35, borderLeft: ' 1px solid gray' },
scoreColumnRed: {
'& input': { color: 'rgba(255,0,0,0.5)', fontWeight: 'bold' },
borderBottom: ' 1px solid gray'
},
scoreColumnBlue: { '& input': { color: 'rgba(0,0,255,0.5)', fontWeight: 'bold' } },
scoreInput: { border: 'none', width: 31, height: 25, textAlign: 'center' }
}
const useStyles = makeStyles(theme => styles)
const classes = useStyles(props)
let athletRedName, athletBlueName, trainerRedName, trainerBlueName
//populate fighters data by id
if (fighterRed) {
const participantRedPopulated = find(participants, { athlet: { id: fighterRed } })
athletRedName = athletName(participantRedPopulated.athlet)
trainerRedName = trainerName(participantRedPopulated.trainer)
} else {
athletRedName = ''
}
if (fighterBlue) {
const participantBluePopulated = find(participants, { athlet: { id: fighterBlue } })
athletBlueName = athletName(participantBluePopulated.athlet)
trainerBlueName = trainerName(participantBluePopulated.trainer)
} else {
athletBlueName = ''
}
return (
<table className={classes.duelTable}>
<tbody>
<tr>
<td className={classes.duelNumber} rowSpan='2'>
{id}
{label ? <div className={classes.duelLabel}>{label}</div> : ''}
</td>
<td className={classes.athletRed}>
<input
onChange={onFighterChange(id)}
type='text'
data-id={id}
data-color='Red'
className={classes.athletInput}
value={athletRedName}
/>
<div className={classes.trainer}>{trainerRedName}</div>
</td>
{showWinnerCheckbox && (
<td className={`${classes.checkboxColumnRed} ${classes.checkboxColumn}`}>
<Box displayPrint='none'>
<Checkbox
inputProps={{ 'data-winner': fighterRed }}
onChange={onWinnerChange(id)}
className={classes.checkboxRed}
checked={winner === fighterRed && winner ? true : false}
/>
</Box>
</td>
)}
{showScoreInput && (
<td className={`${classes.scoreColumn} ${classes.scoreColumnRed}`}>
<input className={classes.scoreInput} />
</td>
)}
<td className={`${classes.athletColorRed} ${classes.athletColorColumn}`}></td>
</tr>
<tr>
<td className={classes.athletBlue}>
<input
onChange={onFighterChange(id)}
type='text'
data-id={id}
data-color='Blue'
className={classes.athletInput}
value={athletBlueName}
/>
<div className={classes.trainer}>{trainerBlueName}</div>
</td>
{showWinnerCheckbox && (
<td className={`${classes.checkboxColumn}`}>
<Box displayPrint='none'>
<Checkbox
inputProps={{ 'data-winner': fighterBlue }}
onChange={onWinnerChange(id)}
className={classes.checkboxBlue}
checked={winner === fighterBlue && winner ? true : false}
/>
</Box>
</td>
)}
{showScoreInput && (
<td className={`${classes.scoreColumn} ${classes.scoreColumnBlue}`}>
<input className={classes.scoreInput} />
</td>
)}
<td className={`${classes.athletColorBlue} ${classes.athletColorColumn}`}></td>
</tr>
</tbody>
</table>
)
}
export default DuelSimple
And dependencies of the project:
{
"#material-ui/core": "^4.5.2",
"#material-ui/icons": "^4.5.1",
"firebase": "^7.2.3",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-redux": "^7.1.1",
"react-redux-firebase": "^3.0.4",
"react-router-dom": "^5.1.2",
"react-scripts": "2.1.5",
"redux": "^4.0.4",
"redux-firestore": "^0.9.0"
}

I just set opacity:0, and it helped me )
Excuse me for troubling )

Related

How to mute remote user in Agora UI kit?

I am using AgoraUIKit from "agora-react-uikit". it is supposed to have the option to mute remote users as per their documentation, but it is not there as they showed in their demo example.
Here is the github link for controls panal which is supposed to be there by default.
https://github.com/AgoraIO-Community/VideoUIKit-Web-React/wiki/Guide#controls
Here is a code of the App.tsx file
import React, { CSSProperties, useState } from 'react'
import AgoraUIKit, { layout, VideoPlaceholderProps, BtnTemplate } from 'agora-react-uikit'
import 'agora-react-uikit/dist/index.css'
const PageComponent: React.FunctionComponent<VideoPlaceholderProps> = ({isShown=true, showButtons=true, showSwap=false}) => {
return (
<>
{showButtons}{isShown}{showSwap}
{BtnTemplate}
</>
);
};
const App: React.FunctionComponent = () => {
const [videocall, setVideocall] = useState(false)
const [isHost, setHost] = useState(true)
const [isPinned, setPinned] = useState(false)
const [username, setUsername] = useState('')
return (
<div style={styles.container}>
<div style={styles.videoContainer}>
{videocall ? (
<>
<div style={styles.nav2}>
<h3 style={styles.heading}>Online Video Call</h3>
<p style={styles.btn} onClick={() => setPinned(!isPinned)}>
Change Layout
</p>
</div>
<AgoraUIKit
rtcProps={{
appId: 'appid',
channel: 'channel name',
uid: 0,
token: 'token', // add your token if using app in secured mode
role: isHost ? 'host' : 'audience',
layout: isPinned ? layout.pin : layout.grid,
activeSpeaker: true,
disableRtm: false,
enableScreensharing: true,
CustomVideoPlaceholder: PageComponent,
}}
rtmProps={{
username: username || 'user',
displayUsername: true,
showPopUpBeforeRemoteMute: true
}}
callbacks={{
EndCall: () => setVideocall(false)
}}
styleProps={{
localBtnContainer: { backgroundColor: 'white', justifyContent: 'center', gap: "20px" },
> BtnTemplateStyles: { borderColor: 'rgb(107 107 107)' },
}}
/>
</>
) : (
<div style={styles.nav}>
<input
style={styles.input}
placeholder='nickname'
type='text'
value={username}
onChange={(e) => {
setUsername(e.target.value)
}}
/>
<h3 style={styles.btn} onClick={() => setVideocall(true)}>
Start Call
</h3>
</div>
)}
</div>
</div>
)
}
const styles = {
container: {
maxWidth: '1100px',
margin: "0 auto",
height: '100vh',
display: 'flex',
flex: 1,
},
container2: {
padding: "2px 16px"
},
heading: { textAlign: 'center' as const, marginBottom: 0 },
videoContainer: {
display: 'flex',
flexDirection: 'column',
flex: 1
} as CSSProperties,
nav: { display: 'flex', justifyContent: 'space-between' },
nav2: { display: 'flex', justifyContent: 'space-between', borderBottom: "1px solid black" },
card: {
// position:"absolute",
// left:"0",
// bottom:"0",
// transform:"translate(155px, -82px)",
// boxShadow: '0 4px 8px 0 rgba(0,0,0,0.2)',
// transition: '0.3s',
// display: 'flex',
// width:"80vw",
// height:"80vh",
// flexDirection: "column",
// justifyContent: "space-between"
} as CSSProperties,
btn: {
backgroundColor: '#007bff',
cursor: 'pointer',
borderRadius: 5,
padding: '4px 8px',
color: '#ffffff',
fontSize: 20
},
input: { display: 'flex', height: 24, alignSelf: 'center' } as CSSProperties
}
export default Apptype here

Button is moved out of the visible content

I've got a problem with my CSS styling. I've got some example headers with the possibility to add some header bookmarks with help of the "PLUS" button. You can see the code here: https://codesandbox.io/s/condescending-feather-wjxfuu?file=/src/App.js or:
import React, { useState } from "react";
export default function App() {
const [list, setList] = useState([]);
const handleAddItem = () => {
const newItem = { id: list.length, name: `Item ${list.length + 1}` };
setList([...list, newItem]);
};
const handleRemoveItem = (index) => {
setList(list.filter((item) => index !== item.id));
};
return (
<div className="App">
<div
style={{
width: "400px",
height: "50px",
display: "flex",
alignItems: "center",
gap: "8px",
overflow: "hidden",
padding: "8px",
border: "1px solid red"
}}
>
{list.map((item, i) => (
<div
key={i}
style={{
border: "1px solid blue",
borderRadius: "5px",
padding: "4px",
backgroundColor: "blue",
color: "white",
cursor: "pointer",
overflow: " hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis"
}}
onClick={() => handleRemoveItem(i)}
>
{item.name}
</div>
))}
<button onClick={handleAddItem}>+</button>
</div>
</div>
);
}
The problem is, that when I add some number of the bookmarks, then in some cases the "PLUS" button starts to overflow the div container(header) as you can see in the GIF.
I want the button not to overflow the content.
You can add another div to keep all your items separate from your button
You can try this playground
import React, { useState } from "react";
export default function App() {
const [list, setList] = useState([]);
const handleAddItem = () => {
const newItem = { id: list.length, name: `Item ${list.length + 1}` };
setList([...list, newItem]);
};
const handleRemoveItem = (index) => {
setList(list.filter((item) => index !== item.id));
};
return (
<div className="App">
<div
style={{
width: "400px",
height: "50px",
display: "flex",
alignItems: "center",
gap: "8px",
overflow: "hidden",
padding: "8px",
border: "1px solid red"
}}
>
<div
style={{
height: "50px",
display: "flex",
alignItems: "center",
gap: "8px",
overflow: "hidden"
}}
>
{list.map((item, i) => (
<div
key={i}
style={{
border: "1px solid blue",
borderRadius: "5px",
padding: "4px",
backgroundColor: "blue",
color: "white",
cursor: "pointer",
overflow: " hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis"
}}
onClick={() => handleRemoveItem(i)}
>
{item.name}
</div>
))}
</div>
<button onClick={handleAddItem}>+</button>
</div>
</div>
);
}
Hi, Simply make the button directly in the div classed app <div className="App">
import React, { useState } from "react";
export default function App() {
const [list, setList] = useState([]);
const handleAddItem = () => {
const newItem = { id: list.length, name: `Item ${list.length + 1}` };
setList([...list, newItem]);
};
const handleRemoveItem = (index) => {
setList(list.filter((item) => index !== item.id));
};
return (
<div className="App">
<div
style={{
width: "400px",
height: "50px",
display: "flex",
alignItems: "center",
gap: "8px",
overflow: "hidden",
padding: "8px",
border: "1px solid red"
}}
>
{list.map((item, i) => (
<div
key={i}
style={{
border: "1px solid blue",
borderRadius: "5px",
padding: "4px",
backgroundColor: "blue",
color: "white",
cursor: "pointer",
overflow: " hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis"
}}
onClick={() => handleRemoveItem(i)}
>
{item.name}
</div>
))}
</div>
<button onClick={handleAddItem}>+</button>
</div>
);
}

Inconsistent margins/spacing with Material UI Accordion

I'm using Material UI Accordion for creating a filter menu.
It looks like this on some devices whereas it looks likes this on other devices with different dimensions even though the margins between the items are the same and uses the same code. On resizing the dimensions of the screen, the inconsistency changes.
How to fix this inconsistency with the spacing between each filter item?
Here's my file FilterAccordion.tsx:
<Box className={classes.accordionRoot}>
<Accordion style={{ boxShadow: "none" }} defaultExpanded={true}>
<AccordionSummary
expandIcon={<ExpandMore style={{ fill: "#d3d3d3" }} />}>
<div className={classes.verticalrootcontainer}>
<Icon
onClick={(e) => e.stopPropagation()}
style={{
fill: "#d3d3d3",
width: "2rem",
marginRight: "1rem",
transform: "scale(3)",
zIndex: -1,
}}
/>
<Typography
variant="body1"
className={`titleAquire ${classes.title}`}>
{title}
</Typography>
</div>
</AccordionSummary>
<AccordionDetails>
<div className={classes.listRoot}>
{Object.keys(groupByPacks).map((item, index) => {
let checked = isChecked(item);
return (
<div
key={index}
className={`${classes.list} ${
checked ? classes.selected : ""
}`}
onClick={() => handleOnCheck(item)}>
<Typography variant="body1" className={classes.item}>
{item}
</Typography>
<Typography variant="body1" className={classes.item}>
{groupByFilteredPacks[item]
? groupByFilteredPacks[item]?.length
: 0}
</Typography>
</div>
);
})}
</div>
</AccordionDetails>
</Accordion>
</Box>
And the CSS file:
accordionRoot: {
"& .MuiAccordion-root": {
background: "transparent",
},
"& .MuiAccordionDetails-root": {
padding: "0px",
},
"& .MuiAccordionSummary-root": {
padding: "0px",
marginBottom: "-1rem",
},
"& .MuiCollapse-entered": {
marginTop: "1rem",
},
},
title: {
fontSize: "18px",
color: theme.on.dark,
},
verticalrootcontainer: {
display: "flex",
alignItems: "center",
},
list: {
display: "flex",
width: "100%",
alignItems: "center",
justifyContent: "space-between",
marginTop: "0.2rem",
padding: "0.2rem 0.5rem",
cursor: "pointer",
"&:first-child": {
marginTop: 0,
},
},
item: {
textTransform: "uppercase",
color: theme.on.dark,
opacity: "30%",
},
selected: {
background: theme.on.dark,
"& p": {
color: theme.darkMode.light,
opacity: "100%",
},
},
listRoot: {
width: "100%",
},

react how can fit div width like android wrap-content?

const SearchBar = (text, onChange) => {
return (
<div>
<div style={{flexWrap: "wrap", background: 'red', border: "1px solid", borderRadius: 10}}>
<Search style={{background: 'blue', verticalAlign: 'bottom'}}/>
<input style={{background: 'blue', verticalAlign: 'bottom'}}
text={text} onChange={onChange}/>
</div>
</div>
);
};
export default SearchBar;
Here is my search bar code.
The result is
but, I want it to appear like this.
How can I get the result?
In your Search component make the width to be 100%.
<Search style={{background: 'blue', verticalAlign: 'bottom', width:'100%'}}/>
First import FaSearch then replace your code with below mentioned.
import { FaSearch } from "react-icons/fa";
const App =(text, onChange)=> {
return (
<>
<div style={styles.mainStyle}>
<Search />
<input style={styles.inputStyle} text={"text"} onChange={null} />
</div>
</>
);
}
const Search = () => <FaSearch style={styles.search} />;
const styles = {
mainStyle: {
display: "flex",
flexWrap: "wrap",
borderRadius: 10,
alignItems: "center",
border: "1px solid",
overflow: "hidden"
},
inputStyle: {
flex: 1,
border: "none",
height: 30
},
search: {
fontSize: 30,
padding: "0px 10px",
cursor: "pointer",
borderRight: '1px solid grey'
}
};

How to change background color of ul li elements in autosuggest react component?

Iam using react Autosuggest component for city country list. When an input is given the suggested list of cities name with their respective countries is displayed. I am able to change the background color while hovering, but, I want to change when key pressed 'up' or 'down'. Following is the code for reference
Form.js
const getSuggestions = value => {
const inputValue = value.trim().toLowerCase();
const inputLength = inputValue.length;
return inputLength === 0 ? [] : cities.filter(data =>
data.name.toLowerCase().slice(0, inputLength) === inputValue
).slice(0,4);
};
// When suggestion is clicked, Autosuggest needs to populate the input
// based on the clicked suggestion.
const getSuggestionValue = suggestion => suggestion.name
const renderSuggestion = suggestion =>
(
<table className='auto-complete'>
<tbody>
<ArrowTooltip title={suggestion.name + ', ' + countries.getName(suggestion.country,"en")} placement="top">
<tr>
<td style={{ width: '88%' }} dangerouslySetInnerHTML=
{highlight(suggestion.name, suggestion.value)}></td>
<td style={{ width: '12%' }}>{suggestion.country}</td>
</tr>
</ArrowTooltip>
</tbody>
</table>
);
class Form extends React {
constructor() {
super();
this.state = {
value: '',
suggestions: []
};
}
onChange = (event, { newValue, method }) => {
this.setState({
value: newValue,
});
if(method == 'up' || method == 'down') {
// Here the value is triggered when key pressed
console.log('KEY UP/DOWN')
}
};
onSuggestionsFetchRequested = ({ value }) => {
this.setState({
suggestions: getSuggestions(value)
});
};
// Autosuggest will call this function every time you need to clear suggestions.
onSuggestionsClearRequested = () => {
this.setState({
suggestions: []
});
};
onSuggestionSelected = (event, {suggestion}) => {
const isSuggestion = true
this.props.getWeather(suggestion, isSuggestion)
}
render() {
const { value, suggestions} = this.state;
// Autosuggest will pass through all these props to the input.
const inputProps = {
placeholder: 'Search City...',
value,
onChange: this.onChange
};
<Autosuggest
suggestions={suggestions}
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
onSuggestionsClearRequested={this.onSuggestionsClearRequested}
getSuggestionValue={getSuggestionValue}
renderSuggestion={renderSuggestion}
inputProps={inputProps}
onSuggestionSelected={this.onSuggestionSelected}
/>
}
}
export default Form
CSS required for suggestions (which is to be styled)
Form.css
.react-autosuggest__suggestions-container {
display: none;
}
.react-autosuggest__suggestions-container--open {
display: block;
perspective: 1000px;
position:absolute;
top: 30px;
width: 180px;
font-family: 'Oxygen';
font-weight: 100;
font-size: 16px;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
z-index: 2;
}
#media screen and (max-width: 576px) {
.react-autosuggest__suggestions-container--open, .react-autosuggest__input {
display: block;
width: 220px;
}
}
.react-autosuggest__suggestions-container--open li{
transform-origin: top center;
margin-bottom: 2px;
background: #c7ecee;
}
/* Here the background color is changed on hovering each li */
.react-autosuggest__suggestions-container--open li:hover {
background: #95afc0;
transition: 0.1s ease-in-out;
}
As seen above, when the mouse is hovered over each elements background color changes, but, I want to change when key (up or down) is pressed. Any suggestions or changes??
Just add theme prop. Something like this:
<Autosuggest
suggestions={suggestions}
onSuggestionsFetchRequested={
this.onSuggestionsFetchRequested
}
onSuggestionsClearRequested={
this.onSuggestionsClearRequested
}
getSuggestionValue={this.getSuggestionValue}
renderSuggestion={this.renderSuggestion}
inputProps={inputProps}
focusInputOnSuggestionClick={true}
theme={{
container: {
display: "block",
width: "100%",
position: "absolute",
borderTop: "none",
borderBottom: "1px solid #aaa",
borderLeft: "1px solid #aaa",
borderRight: "1px solid #aaa",
backgroundColor: "#fff",
fontFamily: "Helvetica, sans-serif",
fontWeight: 300,
fontSize: "16px",
borderBottomLeftRadius: "4px",
borderBottomRightRadius: "4px",
zIndex: 2,
paddingLeft: 0,
paddingRight: 0,
},
input: {
marginBottom: 0,
display: "block",
width: "100%",
height: "34px",
padding: "6px 12px",
fontSize: "14px",
lineHeight: "1.4285",
color: "#555",
backgroundColor: "#fff",
backgroundImage: "none",
borderRadius: "4px",
border: "1px solid #ccc",
},
suggestionHighlighted: {
backgroundColor: "lightgrey", //magic line
cursor:'pointer'
},
}}
/>