Applying Primevue theme - css

Edit: As I was not able to figure this out, I instead dropped Vue3 and went back to Vue2 and switched to Vuetify.
I am completely new to Vue and decided to use Vue 3 for project, which is supposed to lead into my master thesis. As there are not very many UI libraries which are updated to run on Vue 3, I decided to go with Primevue.
Currently I am trying to apply one of Primevue's themes to my project, but the result is not very satisfying. I am using a dark theme, but the background is all white, while the components use the theme for the background and general styling.
I am hoping someone is able to help apply the styling correctly.
As a bonus question I am wondering whether it would be better to downgrade to Vue 2 and use a more well-established UI library such as Vuetify or BootstrapVue.
main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import TieredMenu from 'primevue/tieredmenu';
import InputSwitch from 'primevue/inputswitch';
// import 'primevue/resources/themes/bootstrap4-light-blue/theme.css';
import 'primevue/resources/themes/bootstrap4-dark-blue/theme.css';
import 'primevue/resources/primevue.min.css';
import 'primeicons/primeicons.css';
import 'primeflex/primeflex.css';
const app = createApp(App);
app.use(store)
.use(router)
.use(VueApexCharts)
.use(VueEllipseProgress)
.component('TieredMenu', TieredMenu)
.component('InputSwitch', InputSwitch)
.mount('#app')
App.vue
<template>
<div id="namegoeshere" >
<router-view/>
<div id="nav">
<!--<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>-->
</div>
</div>
</template>
<style >
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
}
#nav a {
font-weight: bold;
color: #2c3e50;
}
#nav a.router-link-exact-active {
color: #42b983;
}
</style>

I had a similar issue, having a look at the prime-vue documentation site with the devtools shows the following code is set on the body:
body {
margin: 0;
height: 100%;
overflow-x: hidden;
overflow-y: auto;
background-color: var(--surface-a);
font-family: var(--font-family);
font-weight: 400;
color: var(--text-color);
}
The variables used here come from the loaded theme. This solved the issue for me.
I couldn't find any direct information about having to set this in the docs.

Related

How to efficiently load google fonts in Nuxt

I am using this google font font-family: 'Saira Semi Condensed', sans-serif;
Link: https://fonts.google.com/specimen/Saira+Semi+Condensed
I am working in on a NuxtJS project. I have to use this font in two different components but with different font-weight. I have imported all the google fonts links in Layout.vue.
For component A the font-weight is 600 & for component B the font-weight is 800. So I thought giving different font-weights in the respective component will work. But it is not working. The only basic font has applied i.e. Saira Semi Condensed, sans-serif; but the font-weight values are not reflected. To resolve this problem I need import two google font links with the same fonts but different font-weight in Layout.vue which makes it redundant.
For font-weight: 600
#import url('https://fonts.googleapis.com/css2?family=Saira+Semi+Condensed:wght#600&display=swap%27);
For font-weight: 800
#import url('https://fonts.googleapis.com/css2?family=Saira+Semi+Condensed:wght#800&display=swap%27);
I think my way of importing two links for the same fonts is not look good. Can you guys please help me to solve this issue?
Thank you in advanced.
Code:
Layout.vue
<template>
<div>
<Nuxt />
</div>
</template>
<style>
#import url('https://fonts.googleapis.com/css2?family=Nunito&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Saira+Semi+Condensed:wght#600&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Saira+Semi+Condensed:wght#800&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Roboto:wght#700&display=swap');
html {
font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI',
Roboto, 'Helvetica Neue', Arial, sans-serif;
font-size: 16px;
word-spacing: 1px;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
</style>
index.vue
<template>
<div>
<Navbar />
<ComponentA />
<ComponentB />
<Footer />
</div>
</template>
<script>
import Navbar from '../components/Navbar.vue'
import Clock from '../components/ComponentA.vue'
import Days from '../components/ComponentB.vue'
import Footer from '../components/Footer.vue'
export default {
components: {
Navbar,
ComponentA,
ComponentB,
Footer,
},
}
</script>
ComponentA.vue
<template>
<div>
<h1>I am component A</h1>
</div>
</template>
<script>
export default {
name: 'ComponentA',
}
</script>
<style scoped>
footer {
color: blue;
font-family: 'Saira Semi Condensed', sans-serif;
font-size: 20px;
text-align: center;
}
</style>
ComponentB.vue
<template>
<div>
<h1>I am component B</h1>
</div>
</template>
<script>
export default {
name: 'ComponentB',
}
</script>
<style scoped>
footer {
color: red;
font-family: 'Saira Semi Condensed', sans-serif;
font-size: 24px;
text-align: center;
}
</style>
You're loading your fonts from a CDN, which is not the recommended way of doing things.
Here is a quote from this awesome performance checklist 2021 written by Vitaly Friedman
Now, many of us might be using a CDN or a third-party host to load web fonts from. In general, it’s always better to self-host all your static assets if you can, so consider using google-webfonts-helper, a hassle-free way to self-host Google Fonts. And if it’s not possible, you can perhaps proxy the Google Font files through the page origin.
Looking at this, I do recommend the usage of #nuxtjs/google-fonts, this is a cool Nuxt module.
I've actually asked if my configuration of the module was okay, here is the github issue: https://github.com/nuxt-community/google-fonts-module/issues/26
And here, a usage example in nuxt.config.js
export default {
buildModules: [
[
'#nuxtjs/google-fonts',
{
families: {
Mali: {
wght: [400, 600, 700],
},
},
subsets: ['latin'],
display: 'swap',
prefetch: false,
preconnect: false,
preload: false,
download: true,
base64: false,
},
],
]
}
And don't forget to also handle the #font-face CSS side of course!
PS: in case you have some issues of specific weights not being downloaded, you can use either overwriting: true in your module configuration or bump the package version to v3.0.0-1.

SASS SCSS issue with input styles with react

Apologies to everyone to this silly question but I am stuck. Maybe because it is late. I have this SCSS file:
.login {
&__base {
height: 400px;
width: 520px;
}
&__container {
#include center;
input {
background-color: get-color(base-div);
border: 1px solid get-color(border-div);
border-radius: 3px;
color: get-color(text-color);
font-size: 18px;
font-weight: 100;
}
}
}
get-color is a function included in utils.scss and it is not relevant. It just give scss vars in code.
I have this jsx:
import React from "react"
import "./login.scss"
import {FormattedMessage} from "react-intl"
function Login({loginhandler}) {
return (
<div className="login__base wm-card">
<div className="login_container">
<h2><FormattedMessage id="SignIn"/></h2>
<input type="email" name="username"/>
</div>
</div>
)
}
export default Login
this boils down to basic CSS. I know. The input does not get styled and if I put the input on the top level it does. I really cannot see what I am doing wrong. Can somebody lend me a hand and call me blind?
Many Thanks.
You have a typo in the class name of the internal div. It should be this.
import React from "react"
import "./login.scss"
import {FormattedMessage} from "react-intl"
function Login({loginhandler}) {
return (
<div className="login__base wm-card">
<div className="login__container"> // <--- double underscore needed here
<h2><FormattedMessage id="SignIn"/></h2>
<input type="email" id="username"/>
</div>
</div>
)
}
export default Login

Vuejs - Svgs partially missing once a third is added

Not really sure how to ask this question to be honest, but recently I've started using VueJS and it's incredible!
That being said, with all the learning of Vue, I perhaps have lost a bit of my CSS skills; particularly when it comes to flex. I don't recall ever having this issue previously, but once I added a third SVG to my page, the two previous almost completely disappear, but the newest is fully visible.
Any ideas of what the heck could actually be happening here?
I'm not using SVG loader or anything, but rather a v-else-if to show svgs based on names; perhaps that's the issue? (though if that were, the two previously shown were fine until I added the third.)
Cheers!
NOTE: I'm not adding the SVG code, since I didn't want to have too much code showing in this question, but it's a simple hamburger menu svg, a search svg and the top nav stuff for an iphone.
App.vue
<template>
<div id="app">
<div class="container">
<top-nav-bar></top-nav-bar>
</div>
</div>
</template>
<script>
import TopNavBar from './components/molecules/TopNavBar.vue'
export default {
name: 'App',
components: { TopNavBar },
}
</script>
<style lang="sass">
#app
font-family: Avenir, Helvetica, Arial, sans-serif
-webkit-font-smoothing: antialiased
-moz-osx-font-smoothing: grayscale
text-align: center
color: #2c3e50
.container
position: relative
margin: 0 auto
border: 2px solid black
background-color: white
border-radius: 40px
width: 414px
height: 896px
</style>
Component:
<template>
<div class="container">
<icons name="nav-info" />
<icons name="hamburger" />
<icons name="search" />
</div>
</template>
<script>
import Icons from '../atoms/Icons.vue'
export default {
components: { Icons },
}
</script>
<style lang="sass" scoped>
.container
display: flex
flex-direction: column
align-items: center
margin: 0
</style>

React and Emotion: Specify font size

I am using emotion to style and display the equation for compound interest in my React app. My render() returns this:
<div css ={equation}>
<p>
P (1 +</p>
<p css={fraction}>
<span className="num">1</span>
<span className="symbol">/</span>
<span className="bottom">2</span>
</p>
)
<sup>(nt)</sup>
</div>
And outside of my component I have:
const fraction = css`
display: inline-block;
position: relative;
vertical-align: middle;
letter-spacing: 0.0001em;
text-align: center;
.num {
display: block;
padding: 0;
height: 12px;
line-height: 12px;
}
.bottom {
border-top: thin solid black;
}
.symbol {
display: none;
}
`
const equation = css`
font-size: 100%;
.p{
font-size:large !important;
}
`;
The fraction is correctly styled. However, I cannot get the font of the p elements to change. The only way I got it to was by switching the p to h1 elements - but I don't want to do that. I want to be able to specify the font size inside my emotion css styling.
There are a couple of things I noticed as an issue in your code.
You are passing .p { ... inside the equation which is not a class selector but should have been an element selector like p { ...
Your react div has to use a className in order to make that effect applied
Here is the sandbox code changes: https://codesandbox.io/s/emotion-xh53z?fontsize=14
Just copying here for your reference:
import React from "react";
import { render } from "react-dom";
import { css } from "react-emotion";
const fraction = css`
display: inline-block;
position: relative;
vertical-align: middle;
letter-spacing: 0.0001em;
text-align: center;
.num {
display: block;
padding: 0;
height: 30px;
line-height: 12px;
}
.bottom {
border-top: thin solid black;
}
.symbol {
display: none;
}
`;
// Notice the p inside the equation
const equation = css`
p {
font-size: large !important;
}
`;
// Rather than css={}, you should be using className={}
const App = () => (
<div className={equation}>
<p>
P (1 +
<p className={fraction}>
<span className="num">1</span>
<span className="symbol">/</span>
<span className="bottom">2</span>
</p>
)<sup>(nt)</sup>
</p>
</div>
);
render(<App />, document.getElementById("root"));
I also moved the closing </p> tag at the last to ensure it's getting applied as per inline-block
Updated 1:
Here is the latest updated version: https://codesandbox.io/s/emotion-1tjc7
As per their latest blog you should be using:
import styled from '#emotion/styled'
import { css } from 'emotion'
instead of import styled, { css } from 'react-emotion'
Update 2:
In case you cannot use vanilla emotion, then you can consider using the following:
import styled from "#emotion/styled";
/** #jsx jsx */
import { css, jsx } from "#emotion/core";
According to their documentation:
There are 2 ways to get started with the css prop.
Babel Preset (Can't use in Create-React-App or CodeSandbox)
JSX Pragma (This involves to just add the above to lines of code)
I have updated the same codesandbox: https://codesandbox.io/s/emotion-0z3vz

Angular 6 component, apply css to class applied with hostbinding?

I normally use a global SCSS file in my apps, but today I wanted to make some scss scoped to just my component.
I have set a class on the component via #HostBinding (of class.card).
I can style items inside my component, such as the caard-body, but how can I apply overrides to this component's card class?
In other words, I have several cards on the page. I have styles that I only want to apply to this card, to make it look different. So I'd like to apply css such as
.card { background-color: violet; }
So that only this card is violet. I want to make this css part of this component, so everywhere I use it it will automatically be a violet card. (In reality I want to more than a simple thing, but you get the idea)
My component TS:
import { Component, Input, HostBinding } from '#angular/core';
#Component({
selector: 'app-reviews',
templateUrl: './reviews.component.html',
styleUrls: ['./reviews.component.scss']
})
export class ReviewsComponent {
#HostBinding('class.card')
true;
#Input()
review;
constructor() {}
}
My Component SCSS:
.card-header {
border: 0;
color: #cf0989;
font-family: 'Helvetica Neue', Arial, sans-serif;
font-size: 2rem;
font-weight: normal;
}
.card-body {
...
}
My component HTML:
<div class="card-header">Testimonials</div>
<div class="card-body">
<div class="review-image">
<img class="rounded-circle"
alt="{{review.acf.article_author.post_title}}"
src="{{review.acf.article_author.acf.image}}">
</div>
<div class="review-content">
<p class="review">
<span [innerHTML]="review.content.rendered"></span>
</p>
<p class="reviewer-name">{{review.acf.article_author.post_title}}</p>
</div>
</div>
The selectors in my CSS for .card-body and .card-header work fine, but I cannot style this .card. Adding this, for example does nothing:
.card { background-color: violet: }
How can I create SCSS selectors in the component's SCSS file that also apply to the class applied to the component via #HostBinding? Can I? Should I?
It looks like I need to use :host, is that correct?
:host {
&.card {
padding: 2rem;
}
}

Resources