I'm trying to make a vertical icon toolbar. I want it to be on the right top side. It shall only occupy the width of the icon (24px and some padding).
I tried this
<div layout="column" layout-align="top end">
<md-button class="md-icon-button" aria-label="close">
<md-icon md-font-icon="zmdi zmdi-close"></md-icon>
</md-button>
<md-button class="md-icon-button" aria-label="Favorite">
<md-icon md-font-icon="fa fa-print"></md-icon>
</md-button>
<md-button class="md-icon-button" aria-label="close">
<md-icon md-font-icon="fa fa-print"></md-icon>
</md-button>
</div>
Any smart way to achive this with angular material directives? Or must I do it manually with css?
Here you go - CodePen
I did the original for this example (which was on the left hand side) for another question which I can't find for the moment. I've answered again to help yourself and others.
Markup
<div ng-controller="AppCtrl" ng-cloak="" ng-app="MyApp" layout-fill layout="column">
<md-content flex layout="row">
<div flex>
Your content
</div>
<div layout="column">
<md-whiteframe id="vericalToolBar" class="md-whiteframe-8dp" layout="column" layout-align="start center" flex>
<md-button class="md-icon-button" aria-label="More">
<md-icon md-svg-icon="img/icons/more_vert.svg"></md-icon>
</md-button>
<md-button class="md-icon-button" aria-label="Favorite">
<md-icon md-svg-icon="img/icons/favorite.svg"></md-icon>
</md-button>
<p id="toolBarTitle" class="md-title">My vertical toolbar</p>
<span flex></span>
<md-button class="md-icon-button" aria-label="Favorite">
<md-icon md-svg-icon="img/icons/cake.svg"></md-icon>
</md-button>
</md-whiteframe>
</div>
</md-content>
</div>
CSS
#vericalToolBar {
background-color: rgb(1,74,182);
width: 40px;
}
#vericalToolBar md-icon {
color: rgba(255,255,255,0.87);
}
#toolBarTitle {
writing-mode: tb-rl;
color: rgba(255,255,255,0.87);
}
Related
I build my first app with the material framework: http://thommessen.upperyard.de/ When you switch the website to mobile view, and open the RIGHT Sidebar, then you will see that he bugs in the height of the site... the left sidebar dont bug, but its exactly the same code, i kust change the id to right and the class to right. can anyone tell me how this can be?
Here the code:
<div ui-view="header">
<md-toolbar layout="row">
<div class="md-toolbar-tools">
<md-button ng-click="toggleSidenav('left')" hide-gt-sm class="md-icon-button">
<md-icon aria-label="Menu" md-svg-icon="images/icons/menu.svg"></md-icon>
</md-button>
<h1>Hello World</h1>
<span flex></span>
<md-button ng-click="toggleSidenav('right')" hide-gt-sm class="md-icon-button">
<md-icon aria-label="Menu" md-svg-icon="images/icons/student.svg"></md-icon>
</md-button>
</div>
</md-toolbar>
</div>
<div layout="row" flex>
<div ui-view="sidebar-left">
<md-sidenav layout="column"
class="md-sidenav-left md-whiteframe-z2"
md-component-id="left"
md-is-locked-open="$mdMedia('gt-sm')">
asdsd
</md-sidenav>
</div>
<div layout="column" flex id="content">
<md-content layout="column" flex class="md-padding">
<div ui-view="container"></div>
</md-content>
</div>
<div ui-view="sidebar-right">
<md-sidenav layout="column"
class="md-sidenav-right md-whiteframe-z2"
md-component-id="right"
md-is-locked-open="$mdMedia('gt-sm')">
asdsd
</md-sidenav>
</div>
</div>
I am trying to get a fixed right sidebar using angular material along with a fixed toolbar on the top. I seem to be missing something due to which it doesnt seem to work at all. I have tried to make a pen out of it, please let me know how to fix it.
Following is my md-content code
<md-content flex class='md-padding' layout="column">
<md-card ng-repeat = "card in cards">
{{card.title}}
{{card.text}}
</md-card>
<md-sidenav flex md-component-id="right" md-is-locked-open="true" class="md-sidenav-right md-whiteframe-z2">
<md-content layout="column">
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
</md-content>
</md-sidenav>
</md-content>
`
http://codepen.io/viggy_prabhu/pen/xVvQzr
Try something like this. I set the sidenav and the content to be in layout row. Removed the flex attribute from the md-sidenav and instead distributed it into a 1/3 and 2/3 layout [flex="33" and flex="66"].
<md-content layout="row">
<md-sidenav md-component-id="right" md-is-locked-open="true" class="md-sidenav-right md-whiteframe-z2" flex="33">
<md-content layout="column">
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
</md-content>
</md-sidenav>
<md-content flex="66">
<md-card ng-repeat="card in cards">
{{card.title}} {{card.text}}
</md-card>
</md-content>
</md-content>
<body ng-app="materialApp">
<div ng-controller="AppCtrl" layout='column' layout-fill>
<md-toolbar class='md-medium-tall'>
<div class="md-toolbar-tools">
<span>Fixed to Top</span>
<span flex></span>
</div>
</md-toolbar>
<md-content class='md-padding' layout="row">
<div layout="column" flex>
<md-card ng-repeat="card in cards">
{{card.title}} {{card.text}}
</md-card>
</div>
<md-sidenav flex=20 md-component-id="right" md-is-locked-open="true" class="md-sidenav-right md-whiteframe-z2" layout-fill>
<md-content style="padding-top:5%; height: 200px" layout="column">
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
<div flex>
<md-button href="http://google.com"> Button </md-button>
</div>
</md-content>
</md-sidenav>
</md-content>
</div>
</body>
Added a div around the md-card repeat and placed the md-sidenav next to it.
Also removed the layout from the body tag. This allows the side-nav to flex to the bottom of the page.
you can try using $mdSticky service from angular material
(function() {
angular.module('example', ['ngMaterial']);
})();
(function() {
angular.module('example').directive('sticky', Sticky);
Sticky.$inject = [ '$mdSticky' ];
function Sticky($mdSticky) {
return {
restrict : 'A',
link : function(scope, element) {
$mdSticky(scope, element);
}
}
}
})();
codepen example https://codepen.io/mckenzielong/pen/LpyYME
tutorial can be found here:
https://www.coditty.com/code/angular-material-how-to-make-custom-elements-sticky-using-mdsticky
$scope.addPlaylist = function(song) {
$scope.playlist.push(song);
var el = angular.element(document.body);
$mdToast.show(
$mdToast.simple()
.textContent(song.title + ' added to playlist.')
.position('bottom')
.hideDelay(3000)
.parent(el)
);
}
I am not experienced with CSS and position properties and have just started using angular material. I am trying to make use of the mdtoast service but cannot get it to position correctly at the bottom of the page.
Even after setting the element to document.body the position of the mdtoast hovers in the middle of the page when I scroll down, as shown in the attached capture. How can I make it pop out from the bottom of the page even after scrolling.
The relevant html code :
<md-toolbar class="md-theme-indigo">
<div class="md-toolbar-tools">
<a ui-sref="player.songs"><img src="assets\images\music-player.png" width="50px" height="50px"></img>
</a>
<md-button class="md-icon-button" aria-label="play" ng-click="stopSong()" ng-show="isPlaying">
<md-icon md-svg-icon="assets/icons/clear.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Stop
</md-tooltip>
</md-button>
<md-button class="md-icon-button" aria-label="play" ng-click="resumeSong()" ng-show="isPaused">
<md-icon md-svg-icon="assets/icons/play.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Resume
</md-tooltip>
</md-button>
<md-button class="md-icon-button" aria-label="pause" ng-click="pauseSong()" ng-show="isPlaying && !isPaused">
<md-icon md-svg-icon="assets/icons/pause.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Pause
</md-tooltip>
</md-button>
<md-button class="md-icon-button" aria-label="repeat" ng-click="enableLoop()">
<md-icon md-svg-icon="{{repeat_icon}}"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Repeat
</md-tooltip>
</md-button>
<span flex></span>
<h3 hide show-gt-sm>Music Player</h3>
<span flex></span>
<md-button ui-sref="player.radio" class="md-icon-button" aria-label="radio" ng-show="state === 'songs'">
<md-icon md-svg-icon="assets/icons/radio.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Go To Radio
</md-tooltip>
</md-button>
<md-button ui-sref="player.songs" class="md-icon-button" aria-label="songs" ng-show="state === 'radio'">
<md-icon md-svg-icon="assets/icons/queue_music.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Go To Songs
</md-tooltip>
</md-button>
<md-menu md-position-mode="target-right target" hide-gt-sm>
<md-button class="md-icon-button" aria-label="controls" ng-click="$mdOpenMenu($event)">
<md-icon md-svg-icon="assets/icons/settings.svg"></md-icon>
</md-button>
<md-menu-content width="6" layout-padding>
<label><md-icon md-svg-icon="assets/icons/volume_up_black.svg"></md-icon></label>
<md-slider md-discrete ng-model="player.volume" step="0.1" min="0.0" max="1" aria-label="volume"></md-slider>
<label ng-if="!isRadio"><md-icon md-svg-icon="assets/icons/fast_forward_black.svg"></md-icon></label>
<md-slider md-discrete ng-model="player.currentTime" step="1" min="1" max="{{player.duration}}" aria-label="seek" class="md-primary" ng-if=!isRadio></md-slider>
</md-menu-content>
</md-menu>
<md-menu md-position-mode="target-right target" layout="column" layout-align="center center">
<md-button class="md-icon-button" aria-label="controls" ng-click="$mdOpenMenu($event)">
<md-icon md-svg-icon="assets/icons/apps.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Apps
</md-tooltip>
</md-button>
<md-menu-content width="2">
<md-button ui-sref="reddit"><span md-menu-align-target>Reddit</span></md-button>
<md-divider></md-divider>
<md-button ui-sref="player.songs"><span md-menu-align-target>Music</span></md-button>
</md-menu-content>
</md-menu>
</div>
</md-toolbar>
<md-progress-linear class="md-warn md-hue-3" md-mode="determinate" value="{{progress}}" ng-if="!isRadio"></md-progress-linear>
<section layout="row" layout-fill>
<md-sidenav class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="$mdMedia('gt-md')">
<md-toolbar class="md-theme-indigo">
<md-sub class="md-toolbar-tools">Status<span ng-show="isPaused"> <span class="md-caption">Paused</span></span></h1>
<span flex></span>
<md-button class="md-primary" aria-label="play_all" ng-hide="!playlist.length" ng-click="nextSong()">{{isPlaying ? 'Next':'Play All'}}</md-button>
</md-toolbar>
<md-content layout="column" ng-show="isPlaying" layout-align="center center" layout-padding>
<md-subheader class="md-primary">{{playing}}</md-subheader>
</md-content>
<md-divider></md-divider>
<md-content layout="column" layout-padding>
<img src="assets/images/yeoman.png" width="130px;" height="100px;" style="margin-left: auto;margin-right: auto;" ng-hide="playlist.length">
<p class="md-caption" style="margin-left: auto;margin-right: auto; text-align: center;" " ng-hide="playlist.length">Add to this playlist by clicking the <md-icon md-svg-icon="assets/icons/menu_black.svg" style="color: #0F0;" aria-label="Alarm Icon"></md-icon> icon in the listing and selecting "Add To Playlist"</p>
<div layout="row">
<h3 class="md-title" style="color: green;" ng-show="playlist.length">Next Up</h3>
<span flex></span>
<md-button class="md-fab md-mini md-warn" aria-label="clear_all" ng-hide="!playlist.length" ng-click="clearPlaylist()">
<md-icon md-svg-icon="assets/icons/clear_all.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Clear Playlist
</md-tooltip>
</md-button>
</div>
<md-list ng-repeat="item in playlist track by $index" ng-show="playlist.length" id="toastParent">
<md-list-item class="md-list-item-text">
<p class="md-caption"><em>{{ item.title }}</em></p>
</md-list-item>
<hr/>
</md-list>
</md-content>
<md-divider></md-divider>
</md-sidenav>
<section layout="column" flex>
<md-toolbar class="md-theme-indigo" hide show-gt-sm>
<div class="md-toolbar-tools">
<md-button class="md-icon-button" aria-label="repeat" ng-click="prevSong()" ng-if="!isRadio">
<md-icon md-svg-icon="assets/icons/skip_previous.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Prev
</md-tooltip>
</md-button>
<md-slider ng-model="player.currentTime" step="1" min="1" max="{{player.duration}}" aria-label="seek" class="md-warn flex" style="padding-left: 20px; padding-right: 20px" ng-if="!isRadio"></md-slider>
<md-button class="md-icon-button" aria-label="repeat" ng-click="nextSong()" ng-if="!isRadio">
<md-icon md-svg-icon="assets/icons/skip_next.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Next
</md-tooltip>
</md-button>
<md-divider md-inset ng-if="!isRadio"></md-divider>
<md-button class="md-icon-button" aria-label="mute" ng-click="volMute()">
<md-icon md-svg-icon="assets/icons/volume_down.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Mute
</md-tooltip>
</md-button>
<md-slider ng-model="player.volume" step="0.1" min="0.0" max="1" aria-label="volume" class="md-warn md-hue-3 flex" style="padding-left: 20px; padding-right: 20px"></md-slider>
<md-button class="md-icon-button" aria-label="volfull" ng-click="volMax()">
<md-icon md-svg-icon="assets/icons/volume_up.svg"></md-icon>
<md-tooltip md-direction="bottom" md-visible="tooltipVisible" md-autohide="true">
Max
</md-tooltip>
</md-button>
</div>
</md-toolbar>
<img src="assets/play_stop.gif" alt="Loading" ng-if="loading" layout-fill>
<div ng-if="!loading" layout="column" layout-fill>
<md-button class="md-fab md-primary" style="position:fixed; bottom:0; left:0" aria-label="openSidebar" ng-click="openSidebar()" hide-gt-md>
<md-icon md-svg-src="assets/icons/featured_play_list.svg"></md-icon>
<md-tooltip md-direction="right" md-visible="tooltipVisible" md-autohide="true">
Show sidebar
</md-tooltip>
</md-button>
<md-content flex>
<section ng-cloak>
<div ui-view></div>
</section>
</md-content>
</div>
</section>
</section>
The $mdToast gets trigged when addPlaylist() is called from within the md-list-item element.
So... Angular Material has a couple of issues with $mdToast with positioning at the moment (see the Github issues). There is a workaround however: adding layout and flex directives to the parent elements should solve the issue.
I am using FAB speed dial within a toolbar. However I am unable to have it floating to the right of the toolbar. I've tried float: right with no luck. Also, tried flex offset="55", but this doesn't work when the window is resized. Essentially, regardless of the window size, I would like the button sitting on the far right within the blue toolbar container.
See photo and code below:
<md-toolbar layout-fill layout-padding layout="row" style="background-color: #3F51B5;color:white;text-align:text-center;">
<div layout="row">
<i class="fa fa-users fa-2x" flex></i>
<h1 class="md-title" style="color:white">Org Chart</h1>
</div>
<div class="lock-size" flex offset="55">
<md-fab-speed-dial md-direction="left" ng-class="md-fling">
<md-fab-trigger>
<md-button aria-label="menu" class="md-fab md-accent">
<md-tooltip>
Actions
</md-tooltip>
<md-icon md-svg-src="img/icons/ic_view_module_48px.svg"></md-icon>
</md-button>
</md-fab-trigger>
<md-fab-actions>
<md-button aria-label="view" class="md-fab md-raised md-mini" >
<md-tooltip>
View Chart
</md-tooltip>
<md-icon md-svg-src="" style="color:black" ng-show="cDP.read" ng-click="paneShowFn('read')"></md-icon>
</md-button>
<md-button aria-label="add" class="md-fab md-raised md-mini" >
<md-tooltip>
Add Chart
</md-tooltip>
<md-icon md-svg-src="img/icons/ic_add_48px.svg" style="color:black" ng-show="cDP.insert" ng-click="paneShowFn('insert')"></md-icon>
</md-button>
<md-button aria-label="Settings" class="md-fab md-raised md-mini" >
<md-tooltip>
Security Access
</md-tooltip>
<md-icon md-svg-src="img/icons/ic_add_48px.svg" style="color:black" ng-show="cDP.permission" ng-click="paneShowFn('permission')"></md-icon>
</md-button>
<md-button aria-label="edit" class="md-fab md-raised md-mini" style="color:black" ng-show="cDP.update" ng-click="paneShowFn('update')">
<md-tooltip>
Edit Chart
</md-tooltip>
<md-icon md-svg-src="img/icons/ic_edit_48px.svg" style="color:black"></md-icon>
</md-button>
</md-fab-actions>
</md-fab-speed-dial>
</div>
</md-toolbar>
Or you can use a class for that:
.fill-space {
// This fills the remaining space, by using flexbox.
// Every toolbar row uses a flexbox row layout.
flex: 1 1 auto;
}
<md-toolbar color="primary">
<span>Application Title</span>
<!-- This fills the remaining space of the current row -->
<span class="fill-space"></span>
<span>Right Aligned Text</span>
</md-toolbar>
This solution is also taken from a spec.
THIS SOLUTION IS FOR ANGULAR MATERIAL v1.X, IF YOU NEED AN UNIVERSAL/ANGULAR MATERIAL v2 SOLUTION CHECK #experimenter ANSWER
If you have a md-toolbar the easiest way to align right content is like this:
<md-toolbar>
<div class="md-toolbar-tools">
<h3>You text</h3>
<span flex></span>
<ANY>your right content</ANY>
</div>
</md-toolbar>
The flex property in span will cover the space between the contents. This is the official way in documentation.
In you example, you just need:
<md-toolbar>
<div class="md-toolbar-tools">
<div layout="row">
<i class="fa fa-users fa-2x" flex></i>
<h1 class="md-title" style="color:white">Org Chart</h1>
</div>
<span flex></span>
<md-fab-speed-dial md-direction="left" ng-class="md-fling">
<md-fab-trigger>
<md-button aria-label="menu" class="md-fab md-accent">
<md-tooltip>
Actions
</md-tooltip>
<md-icon md-svg-src="img/icons/ic_view_module_48px.svg"></md-icon>
</md-button>
</md-fab-trigger>
<md-fab-actions>
<md-button aria-label="view" class="md-fab md-raised md-mini">
<md-tooltip>
View Chart
</md-tooltip>
<md-icon md-svg-src="" style="color:black" ng-show="cDP.read" ng-click="paneShowFn('read')"></md-icon>
</md-button>
<md-button aria-label="add" class="md-fab md-raised md-mini">
<md-tooltip>
Add Chart
</md-tooltip>
<md-icon md-svg-src="img/icons/ic_add_48px.svg" style="color:black" ng-show="cDP.insert" ng-click="paneShowFn('insert')"></md-icon>
</md-button>
<md-button aria-label="Settings" class="md-fab md-raised md-mini">
<md-tooltip>
Security Access
</md-tooltip>
<md-icon md-svg-src="img/icons/ic_add_48px.svg" style="color:black" ng-show="cDP.permission" ng-click="paneShowFn('permission')"></md-icon>
</md-button>
<md-button aria-label="edit" class="md-fab md-raised md-mini" style="color:black" ng-show="cDP.update" ng-click="paneShowFn('update')">
<md-tooltip>
Edit Chart
</md-tooltip>
<md-icon md-svg-src="img/icons/ic_edit_48px.svg" style="color:black"></md-icon>
</md-button>
</md-fab-actions>
</md-fab-speed-dial>
</div>
</md-toolbar>
Without tinkering too much with my own CSS, Is there an attribute or configuration I can use to left align the text in a md-button that is stretched a bit to fit a menu for example?
This is my current view
<md-sidenav md-is-locked-open="$mdMedia('gt-md')" layout="column">
<md-toolbar>
<h1 class="md-toolbar-tools">
<a ng-href="/" layout="row" href="/">
<div class="docs-logotype">Material Design</div>
</a>
</h1>
</md-toolbar>
<md-content flex role="navigation" layout="column">
<md-button>Button1</md-button>
<md-button>Button2</md-button>
</md-content>
</md-sidenav>
<md-content flex layout="column">
<md-toolbar>
<div class="md-toolbar-tools">
<button class="md-icon-button md-button" aria-label="Settings">
<md-icon md-svg-icon="images/icons/menu.svg" aria-hidden="true"></md-icon>
<div class="md-ripple-container"></div>
</button>
<md-button>Button1</md-button> <!-- how to left align this text inside a stretched button -->
<md-button>Button2</md-button>
<span flex=""></span>
<md-button>Right side button</md-button>
<button class="md-icon-button md-button" aria-label="More">
<md-icon md-svg-icon="images/icons/more_vert.svg" aria-hidden="true"></md-icon>
<div class="md-ripple-container"></div>
</button>
</div>
</md-toolbar>
<md-content flex>
Some content !!
</md-content>
</md-content>
Use empty <span> tag with a flex attribute, as shown below. You can even specify a value to the flex attribute to get a more specific location.
<div layout="row" layout-align="start center" flex>
<md-button>button 1 </md-button>
<span flex></span>
</div>
If you just want to align text inside a button, try setting the style attribute like this:
<md-button style="text-align:left">button </md-button>
You can do this if using within md-toolbar(Angular 4) Angular 6+:
Html
<mat-toolbar id="toolbar" color="primary" >
<mat-button>button 1 </mat-button>
<span class="spacing"></span>
<mat-button>button 2 </mat-button>
</mat-toolbar>
OR
<mat-toolbar id="toolbar" color="primary">
<mat-button>button 1 </mat-button>
<span style="flex: 1 1 auto;"></span>
<mat-button>button 2 </mat-button>
</mat-toolbar>
Your CSS if no styling in HTML:
.spacing {
flex: 1 1 auto;
}
Hope this helps someone.
in VueJS (nuxt-vue-material)
.md-button .md-ripple {
justify-content: unset;
}