Vuetify, how to style/theme a button to always be "small" and "tile"? - styles

How can I change the default appearance of a button, so every time I create a button it will look the same? I understand how to i.e. use the color theme to change the i.e. "primary" color, and how to change the css for i.e. all button background colors.
But how would I go about if I for example want:
All buttons to automatically appear as "small" and "tile" by default?

Create your own component, e.g. like this one at src/components/XBtn.vue:
<template>
<v-btn
v-bind="$props"
small
tile
v-on="$listeners"
>
<slot></slot>
</v-btn>
</template>
<script>
import VBtn from 'vuetify/lib/components/VBtn/'
export default {
name: 'XBtn',
props: VBtn.options.props,
}
</script>
Then elsewhere in your app, you can import it:
<template>
<v-row>
<x-btn color="primary">Save</x-btn>
</v-row>
</template>
<script>
import XBtn from '#/components/XBtn'
export default {
name: 'SomeOtherComponent',
components: {
XBtn,
},
}
</script>
Or if you want it to be globally available without having to import it each time, you can register it in src/main.js like this:
// ... other imports ...
import XBtn from '#/components/XBtn'
Vue.component('x-btn', XBtn)
new Vue({
// ... main Vue instance config ...
})
The cool thing about doing it this way is that the XBtn component you derive from VBtn will have ALL of the same properties and events. XBtn will default to small and tile but you can still override these by doing something like: <x-btn large>. You basically use it the exact same way that you use VBtn.

Related

Tabulator: Horizontal Scrolling not working

As far as i understand Tabulator will automatically insert a horizontal scrollbar, if the rows doesn't fit the table width.
This is my Tabulator Component:
<script lang="ts">
import {
Tabulator,
PageModule,
ReactiveDataModule,
ResponsiveLayoutModule,
ResizeTableModule
} from 'tabulator-tables';
import type { ColumnDefinition } from 'tabulator-tables';
import { onMount } from 'svelte';
export let data: any[], columns: ColumnDefinition[];
let tableComponent: HTMLElement;
onMount(() => {
Tabulator.registerModule([
PageModule,
ReactiveDataModule,
ResponsiveLayoutModule,
ResizeTableModule
]);
new Tabulator(tableComponent, {
data: data, //link data to table
columns: columns, //define table columns,
height: '500px',
pagination: true,
paginationSizeSelector: [10, 25, 30], //enable page size select element with these options
responsiveLayout: true,
reactiveData: true
});
});
</script>
<div bind:this="{tableComponent}"></div>
<svelte:head>
<link
href="https://unpkg.com/tabulator-tables#4.9.1/dist/css/tabulator.min.css"
rel="stylesheet" />
</svelte:head>
I have also tried it without responsiveLayout: false and renderHorizontal: 'virtual'.
Even if i enclose the Tabulator in a div with overflow-x: scroll nothing happens.
The horizontal scrollbar doesnt appear and only the content which fits on the screen is displayed.
The content expands, if i enlarge my Browser window.
REPL: https://svelte.dev/repl/5be4cdc48a694be793d5e4a0bdbd0f15?version=3.52.0
The whole point of the responsive module is that it dynamically hides cells.
The main problem is probably that you are using an outdated stylesheet (note the version: tabulator-tables#4.9.1). You should not be referencing unpkg.com for anything that is not purely demonstrational anyway.
With Vite you can just import the CSS directly from the package:
<script>
import 'tabulator-tables/dist/css/tabulator.min.css';
// ...
You can also import it from the <style>:
<style>
#import 'tabulator-tables/dist/css/tabulator.min.css';
</style>
(Vite will probably even automatically inline this.)
Without responsiveLayout it should scroll horizontally by default.

React Responsive Media Queries Not Changing

I'm using react responsive to create media queries so an image size will change. However, it's not doing what I want. It keeps the larger 1st image on the screen and doesn't switch over to the other with the rules I specified. Is there a different way of coding this?
import React, {Component} from 'react';
import MediaQuery from 'react-responsive'
class Name extends Component {
render(){
return(
<>
<div>
<MediaQuery Nameimg={this.props.Nameimg} minWidth={900}>
<img height="15vh" className="name_image" src={this.props.Nameimg} alt="name"/>
</MediaQuery>
<MediaQuery Nameimg={this.props.Nameimg} maxWidth={899}>
<img height="8vh" className="name_image2" src={this.props.Nameimg} alt="name2"/>
</MediaQuery>
</div>
</>
)
}
}
export default Name;
This was a simple fix so hopefully this is useful to someone else as well. But I believe it wasn't working because you need to use set widths defined by the package https://github.com/contra/react-responsive/blob/master/src/mediaQuery.ts#L9
I used minWidth and maxWidth of 1224, which did the trick.

Drawer Component Backdrop blocking users from interacting with page will it is open

I have a Drawer Component anchored at the bottom but I would still like to interact with the page above the drawer but either I can click out of if but the drawer closes so I tried the variants persistent and permanent both didn't work they actually made it so nothing at all happens when I click out of if. I think it has something to do with the spacing or padding above, but if anyone knows how to disable that, it would be greatly appreciated.
I solved it slightly differently, by removing the "inset" CSS property of the .MuiDrawer-modal div:
.MuiDrawer-modal {
inset: unset !important;
}
Figured out my problem, I ended us having to do some height changes to the Paper component and it seemed to work the way I wanted. You can overrided the css with makeStyles method in the #material-ui/core/styles directory. I used the classes property example
// Outside the component
import { makeStyles } from '#material-ui/core/styles';
const useStyles = makeStyles({
drawer: {
css here ...
}
})
// Inside Component
const classes = useStyles() // the make styles returns a function and calling the useStyles returns an object with the css.
// Inside return
<Drawer
anchor="bottom"
classes={{ paper: classes.drawer }}
>
Content...
</Drawer>

How to edit style attribute on Angular six component

I'm new to Angular development.
I have started developing a web site using Angular 6 Material (material.angular.io) and kicked this off with navigation schematic that delivers a responsive toolbar and side nav component for navigation. The default HTML layout looks something like this:
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer class="sidenav"
...
<mat-toolbar color="primary">
...
</mat-toolbar>
<mat-nav-list>
<a mat-list-item routerLink='/menu1'>menu 1</a>
...
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content >
<mat-toolbar color="primary" >
<mat-toolbar color="primary" class="mat-toolbar" >
<mat-toolbar-row >
...
</mat-toolbar-row>
</mat-toolbar>
</mat-toolbar>
<!-- Application components go here-->
<router-outlet></router-outlet>
</mat-sidenav-content>
</mat-sidenav-container>
mat-sidenav-container contains the 'drawer' mat-sidenav to the left of mat-sidenav-content
I want to programmaticaly shrink the width of mat-sidenav, subsequently shifting mat-sidenav-content to the left.
I can do the first part, by using [ngClass] on mat-sidenav and changing this on demand -
However, I'm not having the same success with the content section on the right of the drawer, by just merely changing its CSS Class to have the correct width..
Looking at the source code, I see mat-sidenav-content not only has CSS Classes but also has style attribute as "margin-left:200px"
(which overrides any CSS class styling I set)
I want to programmaticaly change this margin-left value.
How do I do that ?
Thanks -
html:
<mat-sidenav #drawer [(ngStyle)]="{'width': myWidth}">
typescript:
export class HeroesComponent implements OnInit {
myWidth: 25px;
}

How to display icons in JHipster 5?

I'm trying to add/change Font Awesome icon in JHipster 5 app.
I can print only icons that already in default template.
I can change:
<fa-icon [icon]="'home'"></fa-icon>
<span>
<span jhiTranslate="global.menu.home">Home</span>
</span>
to:
<fa-icon [icon]="'asterisk'"></fa-icon>
<span>
<span jhiTranslate="global.menu.home">Home</span>
</span>
but can't change to
<fa-icon [icon]="'tv'"></fa-icon>
<span>
<span jhiTranslate="global.menu.home">Home</span>
</span>
or any other icon.
Are they defined in some place?
Icons are in src/main/webapp/app/vendor.ts, here you can add new icons.
To complete Alexandre answer ;
Example to add the twitter icon :
(in "jhipsterVersion": "5.1.0")
read node_modules/#fortawesome/angular-fontawesome/README.md
yarn add #fortawesome/free-brands-svg-icons in src/main/webapp/app/vendor.ts
declare your icon :
.
import { faTwitter } from '#fortawesome/free-brands-svg-icons';
library.add(faTwitter);
in your html, use and don't forget to tell it is from fab (Brand)
.
<fa-icon [icon]="['fab', 'twitter']"></fa-icon>
Maybe you should also re-run webpack:build. But for me it worked directly
(see the top of of src/main/webapp/app/vendor.ts)
/* after changing this file run 'yarn run webpack:build' */
For Jhipster 6 the file to define icons to be used is
src/main/webapp/app/core/icons/font-awesome-icons.ts:
import { faAmazon } from '#fortawesome/free-brands-svg-icons';
export const fontAwesomeIcons = [
faAmazon,
faUser,
...
and remember to refer to the icon with (note 'fab' instead of 'fa' for brands icons):
<fa-icon [icon]="['fab', 'amazon']"></fa-icon>
If you plan to include brands free icons (amazon icon is there) you should also install the npm package:
npm install --save #fortawesome/free-brands-svg-icons
If you tried to add your icons like so:
vendor.ts
import {
// other imports
faFileSignature,
faLock
} from '#fortawesome/free-solid-svg-icons';
// other imports
library.add(faFileSignature);
library.add(faLock);
but it didn't work and you get an error telling you that global styles are deprecated, I fixed it like this.
I created a new icon.module.ts and imported it in the shared-libs.module.ts.
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { FontAwesomeModule, FaIconLibrary } from '#fortawesome/angular-fontawesome';
import { fas } from "#fortawesome/free-solid-svg-icons";
#NgModule({
declarations: [],
imports: [
CommonModule,
FontAwesomeModule
]
})
export class IconsModule {
constructor(library: FaIconLibrary) {
library.addIconPacks(fas);
}
}
I hope I helped.

Resources