I'm trying to render 2 SVG files on my react app.
Here:
But when importing it as a component to React:
import { ReactComponent as ClosedEnvelope } from "../../close.svg";
import { ReactComponent as OpenEnvelope } from "../../open.svg";
const Envelope = ({closed) => {
return (
<div>
{closed ? <ClosedEnvelope /> : <OpenEnvelope />}
</div>
);
};
It renders the SVG incorrectly:
As you can see the "arrow" on the bottom left side is overflowing.
Seems like an issue with the method I used, because loading the SVG as an image, does work.
What may the problem be?
Thanks in advance
Here are the links to the SVG files:
Close envelope Github
Open envelope Github
Well, Apparently the 2 SVG files, had the same classes and IDs, which caused them to change a little.
If you have the same issue,
Change all the classes in one SVG file.
Change all IDs, also in the CSS like clip-path: URL(#SOME_ID)
This worked for me.
Related
I'm having this weird issue where my styling is not sticking. I have a NavBar set to be 20vh in height. I also have an image set to be 100% in width. However, when I refresh the page, the NavBar height shrinks and the image width increases significantly. I'm not sure what is causing this problem. I have pasted the relevant code below but you can also find the repo for the app at this link (dev branch).
const useStyles = makeStyles((theme) => ({
navBar: {
height: "20vh",
width: "100%",
},
}));
const NavBar = () => {
const classes = useStyles();
return <div className={classes.navBar}>NavBar</div>;
};
const useStyles = makeStyles((theme) => ({
introImg: {
width: "100%",
height: "auto",
},
}));
const Intro = () => {
const classes = useStyles();
return <img src={marco4sup} className={classes.introImg} />;
};
As you can see, the NavBar is definitely not 20vh and the image is expanding beyond 100% of the page width.
Alert: I will give a pull request on the repo on github so you can implement the code. Fast Refresh is a Next.js feature that gives you instantaneous feedback on edits made to your React components. Fast Refresh is enabled by default in all Next.js applications on 9.4 or newer. With Next.js Fast Refresh enabled, most edits should be visible within a second, without losing component state.
How It Works
If you edit a file that only exports React component(s), Fast Refresh will update the code only for that file, and re-render your component. You can edit anything in that file, including styles, rendering logic, event handlers, or effects.
If you edit a file with exports that aren't React components, Fast Refresh will re-run both that file, and the other files importing it. So if both Button.js and Modal.js import theme.js, editing theme.js will update both components.
Finally, if you edit a file that's imported by files outside of the React tree, Fast Refresh will fall back to doing a full reload. You might have a file which renders a React component but also exports a value that is imported by a non-React component. For example, maybe your component also exports a constant, and a non-React utility file imports it. In that case, consider migrating the constant to a separate file and importing it into both files. This will re-enable Fast Refresh to work. Other cases can usually be solved in a similar way.
Arrow functions aren't supported. Name your functional component.
export default function MyPage () {...
Without export defualt function MyPage() {... it won't use fast refresh therefore your code won't work, to implement it into your Code do the following(for code block1):
export default function UseStyles () {
navBar: {
height: "20vh",
width: "100%",
},
}));
const NavBar = () => {
const classes = useStyles();
return <div className={classes.navBar}>NavBar</div>;
};
Sorry if there are any grammatical errors my english isn't great.
And also if you want your navbar to be sticky set the position to sticky like the following:
position: sticky;
I am trying to change the loading logo of babylon js however all the tutorials and documentation I found on the official website are not working for me.
I am using a basic babylon viewer using
<babylon id="babylon-viewer" model="mymodel.gltf" templates.main.params.fill-screen="true" observers.on-scene-init="globalSceneInitCallback"></babylon>
and some other javascript to control the camera.
I believe there is a simple way how to just change the loading-image, but cannot figure it out!
Regards and thanks
To change the default values of the babylon viewer's loading screen, you will need to modify the loading screen's template.
The configuration object looks like this:
loadingScreen: {
html: loadingScreen,
params: {
backgroundColor: "#000000",
loadingImage: images.loading,
staticLoadingImage: images.staticLoading
}
},
Just as you changed the fillScreen's parameter of the main template, you can change on of those 3 parameters - background color, loading image, and (better - OR) static loading image. Something along the lines of this:
<babylon id="babylon-viewer" model="mymodel.gltf" templates.loading-screen.params.loadingImage="http://LINK-TO-IMAGE" templates.main.params.fill-screen="true" observers.on-scene-init="globalSceneInitCallback"></babylon>
or:
<babylon id="babylon-viewer" model="mymodel.gltf" observers.on-scene-init="globalSceneInitCallback">
<templates>
<loading-screen>
<params loadingImage="IMAGEURL">
</params>
</loading-screen>
</templates>
</babylon>
As much as I have searched about file sizing for react-file-viewer I could not find anything.
I want to use the react-file-viewer to click on a filename hyperlink and open the file (image, document or excel sheeet) in a new page. The rendering works fine, except for the image/document sizing.
I have the following example:
import React from "react";
import FileViewer from "react-file-viewer";
import { Fragment } from "react";
import imGurPic from "./MainBody/imGurPic.ts";
const MainBody = () => {
const file =imGurPic;
const type = "jpeg";
return (
<Fragment>
<FileViewer fileType={type} filePath={file} />
</Fragment>
);
};
export default MainBody;
The imGurPic is an image I picked randomly from imGur because of its large size (3024x4032 pixels) (don't worry it is a cat image... link here... I converted into a base64 string that I use in the filePath prop of the FileViewer component. Ultimately, it will be a base64 string coming from a db as a byte array.
In the following sandbox I managed to create a demo, only to find out that it is WAY too small (72*96px). I do not really understand why it would take so little space. Also, any document or excelsheet I enter, the maximum height is 96px. How can I change it? It seems to inherit from a parent element but the Mainbody takes all the available space between header and footer.
Any help on this will be appreciated.
Here is the sandbox -->sandbox demo
And in case someone cannot open it, here is a screenshot -->
Had to figure this out as well. If you want your image to scale to fit your sizing requirements, just make height=100% in the surrounding div. E.g.
<div style={{ height: '100%' }}>
<ReactFileViewer />
</div>
If you don't want the image scaled at all, then it's a little trickier. I've had to resort to some messy CSS to override the hardwired width and height settings:
.pg-viewer-wrapper {
overflow-y: unset !important;
}
.photo-viewer-container {
width: unset !important;
height: unset !important;
}
.photo-viewer-container > img {
width: unset !important;
height: unset !important;
}
It would be great if this component had features like scaling (e.g. fit, fill, percentage) but I don't think the library is being maintained any more (looking at the old PRs that are still waiting), so would recommend forking and implementing a cleaner solution than what I have done.
After a lot of searching, I can't seem to find a solution for this.
I'm using forawesome icons on my main page, and on load they are huge for a short period of time.
here is an example: https://makeyka.herokuapp.com/
I've tried
import {config} from "#fortawesome/fontawesome-svg-core";
config.autoAddCss = false;
then trying to add the css with no luck
Turn off autoAddCss:
import { config } from '#fortawesome/fontawesome-svg-core'
config.autoAddCss = false
Load in CSS directly in SCSS file:
#import 'node_modules/#fortawesome/fontawesome-svg-core/styles'
And in your style put this:
<style jsx global>{`
...
#import url('https://fonts.googleapis.com/css?family=Didact+Gothic');
${dom.css()}
...
`}</style>
please follow the link: https://fontawesome.com/how-to-use/on-the-web/other-topics/server-side-rendering
Basically this question is abut React.js. However I was stumbling over the very same issue in context of Vue.js. This solution of mine is basically meant to work with Vue.js in context of single-file components.
Insert this code in your entry code file:
import { config } from "#fortawesome/fontawesome-svg-core";
config.autoAddCss = false;
Now, prepend another block addressing the required file to any existing <style> block in your root element's component:
<style src="#fortawesome/fontawesome-svg-core/styles.css"></style>
class .hero-section-content-intro(container for all font Icons) has width: 300;
until CSS file for Icon is not loaded all icons takes width : 300 (of parent)
you need to handle this case to resolve issue.
add font-size for icons.
I am trying to use a parallax from react-materiallize for a portfolio site. I've got the images working in the parallax however it doesn't not seem to be scrolling.
I've loaded JQuery before material CSS in the index.html file
import React, { Component } from 'react'
import {Parallax, Row} from 'react-materialize'
export default class ParalaxComponent extends Component {
render(){
debugger
return (
<Row>
<Parallax imageSrc="https://www.thoughtco.com/thmb/DF3Q0T5_0O5CmGBTCWCBTcyGgmw=/768x0/filters:no_upscale():max_bytes(150000):strip_icc()/JavaScript-58acbb8a3df78c345bad32c2.jpg"></Parallax>
</Row>
)
}
}
The image shows up but the animation is not being triggered thank you for your help.
Here is the app on github if that's an easier way to debug the issue.
Ended up using 'npm react-parallax' instead.
There is great documentation and a demo app here