Foundation for sites is a responsive framework developed by Zurb. It provides a full collection of styled components and responsive grid to build the complete layout of your site. Just follow these steps to add it to your Angular project.
I'm used to the Zurb's Foundation framework due its simplicity and I feel it less invasive than it could be other frameworks like Bootstrap. Also this week I started learning about Angular (>=2) and I found that I needed some "prebuilt" components to help me in the project I started with learning purposes. So I struggled a little bit to add Foundation for sites to it and these are the steps I followed ...
Creating an Angular project with the CLI
Angular provides a command line interface (CLI) to run the most common commands used during development. Previously to the following commands you should have installed Node.js and its package manager NPM.
You can update npm to the latest version with the following command:
And proceed installing the latest version of the Angular CLI
You can show all available commands with the
ng help command.
Once it is installed we can create the application skeleton with the following command. You can also add support to Sass, using the style parameter with the scss or sass option, depending on your preferences.
This will create a Node.js package in the foundation-ng2-app recently created. You can check the project generated by checking the content of the package.json file inside that folder.
In the file content you can see the npm commands you can use with your project. Also you can look at the dependencies needed for an Angular project. Any other required dependency, like the Foundation for sites package, will be added here too. Let's see how.
Installing Foundation for sites package
Installing Foundation for sites package with the following command inside the foundation-ng2-app folder created.
If you want to add the Motion UI library to add animations to some Foundation components only with css classes you can also install it with npm
Creating the main stylesheet
As we created the app with support for scss format it has created a styles.scss in the root of the source folder
In this file we should add all the scss we need. This include the Foundation base scss and the Motion UI scss files if you also need it. Generally you will add the scss and then you should include the defined mixin in order to use the styles.
If you want to customize your styles like colors or fonts you can copy the content of the settings file located in the
scss/settings folder of the
foundation-sites package in the project
node_modules folder and modify any value you consider.
Customizing your application
That means, if you look in the foundation-site installed package there is a settings.scss file where there are some configurations and customizations for the Foundation framework.You can find it on foundation-ng2-app/node_modules/foundation-sites/scss/settings/_settings.scss file. Ok, so then copy that file in your app source folder as _settings.scss. foundation-ng2-app/src/assets/scss/_settings.scss would be a good place. Also modify the path to the Foundation utils scss file reference relative to the package path. That is replacing the line: with
In your application main component, for instance, app.component.ts there is a definition of where there are the styles of that component:In that definition there is where is located the scss file (styleUrls: ['./app.component.scss']) for that component, in that case, the main component as we want to configure it a global style for the whole angualr application. So in that app.component.scss you should include the _settings.scss that we just copied on our assets folder. @import '../assets/scss/settings'; And now you can modify that settings file to manage all your customizations for that application. If you open that file in your editor you will see that there are a bunch of Sass variables ready to be changed, organized by components and sections.