I'm trying to get the Add Server button to move to the far right side of the screen. Since float:right does not exist in React, what's the best way to go about doing this?
I made a wrapper called serverNavButtonWrapper tried adding padding to the left but this seems a bit hacky. I also tried adding a wrapper around both h3 titles then did flex-grow: 1 but this didn't work and ending up squishing them into columns. I would appreciate your help!
<div className={classes.serverNav}>
<h3 className={classes.title}>Current Servers</h3>
<h3 className={classes.title}>All Servers</h3>
<div className={classes.serverNavButtonWrapper}>
<Button
className={classes.serverNavButton}
variant="outlined"
size="medium"
color="default"
>
<AddIcon /> Server
</Button>
</div>
</div>
preview of current render
If you set the margin to auto on a flex item, it will grow to the maximum available space. So the following will do the trick:
.serverNav {
display: flex;
}
.serverNavButtonWrapper {
margin-left: auto;
}
Or, if you don't need the wrapper anymore:
.serverNav {
display: flex;
}
.serverNavButton {
margin-left: auto;
}
The float property is primary the CSS property.
You can pass the stylesheet to the React components via the style attribute, e.g.:
<p style={{fontSize: "12px"}}>Text</div>
Two curly brackets are there because the argument type of style is an object and you are initializing it there.
So your code should look like this:
<div className={classes.serverNav}>
<h3 className={classes.title}>Current Servers</h3>
<h3 className={classes.title}>All Servers</h3>
<div className={classes.serverNavButtonWrapper}>
<Button
className={classes.serverNavButton}
variant="outlined"
size="medium"
color="default"
style={{float: "right"}}
>
<AddIcon /> Server
</Button>
</div>
</div>
Related
I am having a small issue fitting an icon into a Row element.
right now the icon takes up the whole row ::
<LinkedInIcon />
I was able to make it not take up the whole row ::
<div style={{ background: "white", display: "inline-block" }}>
<LinkedInIcon />
</div>
now I have to add some text on the right side of the icon, but its not working out. I added my code to the sandbox::
<Row>
<p className="text-center text-white">Bosky</p>
{/* this icon does not behave properly, it does not allow the text'Bosky' to show in the same row */}
<div style={{ background: "white", display: "inline-block" }}>
<LinkedInIcon />
</div>
</Row>
https://codesandbox.io/s/bosky-active-ow4qs7?file=/src/Components/Footer.js:447-559
Maybe like this? It's a lot of style inline, but seem to get the job done...
https://codesandbox.io/s/bosky-active-forked-bcbd35?file=/src/Components/Footer.js
I'm currently trying to build a file upload Input field with an icon as an input adornment, using Material UI. I want to be able to click the icon to upload a file.
Following the MUI documentation here: input adornment, I have tried to follow the exact formatting except using an IconButton instead of the Password visibility icon in the demo.
Here is a sample of my code:
<FormControl className={classes.formControl}>
<InputLabel htmlFor="upload-script">Sim Script</InputLabel>
<Input
id="upload-script"
type="file"
value={values.script}
onChange={() => handleChange('script')}
endAdornment={
<InputAdornment position="end">
<IconButton aria-label="upload">
<PublishIcon /> // (here is my icon)
</IconButton>
</InputAdornment>
}
/>
</FormControl>
This works, but the result is not at all what I was intending- here is a screenshot of what it looks like in the browser:
You can see my upload icon all the way on the right, but the input field clearly has its own upload button and placeholder text ('No file chosen').
Looking online, I saw a suggestion here: (similar StackOverflow post) that says we should add style: {{ display: none }} to the Input component, and add component="span" as a property of the IconButton. When I try this, however, this is what the browser gives us:
(this is all the way scrolled... my sources icon is gone, the Input field has no line delimiter underneath, the spacing is clearly messed up...)
Clearly, neither of these is what I want haha. Can anyone help?? (I hope this description is good enough...)
Thank you so much!!
-
EDIT:
Here is what it looks like with #Shiladitya's initial solution:
But I want there to be a line for the text field! I want it to look exactly like the 'Sim Binary' text field, except with an upload icon on the right instead of a dropdown arrow.
Here you go with a solution
const handleFileUpload = () => {}
<>
<input
style={{
display: "none"
}}
accept=".json" // specify the file type that you wanted to accept
id="choose-file"
type="file"
onChange={handleFileUpload}
/>
<label htmlFor="choose-file">
<IconButton aria-label="upload">
<PublishIcon />
</IconButton>
</label>
</>
EDIT with Textfield
<TextField
className={classes.margin}
id="input-with-icon-textfield"
label="TextField"
InputProps={{
endAdornment: (
<>
<input
style={{
display: "none"
}}
accept=".json"
id="choose-file"
type="file"
onChange={handleFileUpload}
/>
<label htmlFor="choose-file">
<IconButton aria-label="upload">
<PublishIcon />
</IconButton>
</label>
</>
),
}}
/>
I've recently returned and edited my component, which was inspired by #Shiladitya but now uses a better system that I somehow missed before:
<TextField
className={classes.formControl}
id={`sim-script-${sim.uuid}`}
label="Sim Script- click the Upload Icon"
required
inputRef={scriptInputRef} // To focus on the field after clicking icon
value={sim.script}
InputProps={{
readOnly: true,
endAdornment: (
<>
<AdjustedTooltip title="Upload script" arrow>
<IconButton
aria-label="upload"
className={classes.uploadIcon}
component="label" // THIS IS THE GENIUS CHANGE
>
<PublishIcon />
<input
hidden
type="file"
onChange={(e) => scriptUpload(e)}
/>
</IconButton>
</AdjustedTooltip>
</>
),
}}
/>
This way, we can remove all the input and label wrappers, and instead just set the Material UI Button to have the attribute component="label", with the input tag inside the icon button.
Also here is my onChange/scriptUpload function, in case people are interested:
const scriptUpload = (e: ChangeEvent<HTMLInputElement>) => {
// the first/only file selected by user
if (e.target.files?.item(0)) {
onChange(sim.uuid, "script", e.target.files?.item(0)!.name);
}
// Focus textfield
if (scriptInputRef.current) {
scriptInputRef.current.focus();
}
};
Another Solution.
* {
margin: 0 auto;
font-family: Helvetica;
}
html {
background-color: #e9e9e9;
}
#choose-file {
display: none;
}
#wrapper {
display: inline-flex;
justify-content: center;
margin-left: 20px;
background-color: orange;
width: 60px;
align-items: center;
cursor: pointer;
}
<form>
<label id="first">
Sim Binary
<div id="wrapper">
<input
accept=".json"
id="choose-file"
type="file"
/>
⇪
</div>
</label>
</form>
using react-bootstrap-table2 for table and search together as below
<ToolkitProvider
bootstrap4
keyField='id'
data={data}
columns={columns}
search
>
{props=>(
<>
<SearchBar {...props.searchProps} placeholder='Start typing'/>
<br/>
<BootstrapTable condensed bordered
id='bootstrap-tr'
{...props.baseProps}
noDataIndication={() => 'There is no data to display'}
loading={loading}
overlay={overlayFactory({ spinner: true })}
pagination={paginationFactory(options)}
// rowClasses={rowClasses}
// expandRow={expandRow}
/>
</>
)}
</ToolkitProvider>
search bar looks like this
i am using FontAwesome-5 icons and want to add fa-search icon to the react-bootstrap-table2-toolkit SearchBar, like below
any suggestions on this
got this resolved by added the below styling to the fa-search icon
css
#{yourid} {
position: absolute;
width: 2.375rem;
/*height: 2.375rem;*/
line-height: 2.375rem;
text-align: center;
color: #7B7B7B;
}
js file
<i className='fas fa-search' id='filtersubmit' style={{fontSize:'15px'}}/>
<SearchBar {...props.searchProps} placeholder=''/>
Hei
Trying to get my page to display an image that is behind the text and icons.
Here is what I have currently:
import React from 'react';
import SamplePicture from '../../images/sample-picture.jpg';
class Front extends React.Component {
render() {
return (
<div className="ui segment">
<img className="ui floated image" src={SamplePicture} />
<p>
This is a front page that will have an image in the background
<br />
Sampletext
</p>
</div>
);
}
}
export default Front;
It displays the image but the text gets rendered below.
Basicly I want to create text that gets rendered on top of the image.
First time asking a question here so maybe there is some information that I should have shared, but haven't. Anyway, be harsh, tell me what is wrong about the code, the question.
You can do something like this using flexbox:
<div className="ui segment">
<div className="ui medium image">
<div
className="ui active center"
style={{
display: 'flex',
position: 'absolute',
width: '100%',
height: '100%',
justifyContent: 'center',
zIndex: 1,
}}>
<div className="content">Sampletext</div>
</div>
<img
src="https://via.placeholder.com/410x210"
className="ui floated image"
alt="alt"
/>
</div>
</div>
This solution uses flexbox to center the text over the image.
I've used via.placeholder.com as an image source to make it easy to demo, but you can change it to your image's src.
If the text isn't exactly centered, either change your container to a smaller size (from medium to small for example) or choose a bigger (wider) image.
I'm using react-slick in one of my projects and for some reason when I turn off arrows the entire slider disappears
The code is looking like this
<div className="container" style={{position: "relative", padding: 0}}>
<div className={styles.class_name}>
</div>
<Slider onSwipe={this.swipeHandler} arrows={false}>
{this.props.children}
</Slider>
</div>
I'm using customized Bootstrap with only responsive utilities and grid.
Any help, suggestion etc would be very appreciated!