# @hackandcraft/css-framework

> A starting point to customise Angular Material sytles, for Hack&Craft projects

Latest version **7.1.1** (published 2020-06-11) · 0 weekly downloads

## Install

```sh
npm install @hackandcraft/css-framework
pnpm add @hackandcraft/css-framework
yarn add @hackandcraft/css-framework
bun add @hackandcraft/css-framework
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.1.1 |
| Published | 2020-06-11 |
| First published | 2019-09-12 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 87.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | hackandcraft |

## Links

- npm: https://www.npmjs.com/package/@hackandcraft/css-framework
- npm.io page: https://npm.io/package/@hackandcraft/css-framework

## Dependencies (1)

- [bootstrap-4-grid](https://npm.io/package/bootstrap-4-grid.md) ^3.1.0

## Recent versions

- 7.1.1 (latest) — 2020-06-11
- 7.1.0 — 2020-01-10
- 7.0.2 — 2019-12-19
- 7.0.1 — 2019-12-05
- 7.0.0 — 2019-12-04
- 6.9.0 — 2019-12-04
- 6.8.0 — 2019-12-04
- 6.7.0 — 2019-12-03
- 6.6.0 — 2019-11-28
- 6.5.3 — 2019-11-27
- 6.5.2 — 2019-11-27
- 6.5.0 — 2019-11-25
- 6.4.1 — 2019-11-19
- 6.4.0 — 2019-11-19
- 6.3.0 — 2019-11-18
- … 70 more at https://npm.io/package/@hackandcraft/css-framework/versions

## README

# CSS Framework

[Hack&Craft](https://hackandcraft.com/insights) uses [Material Design](https://material.io/design/) as a design language on their projects, in conjunction with the [Angular Material](https://material.angular.io/guide/theming) library.

Angular Material library only provides color theming (no theming for font-size, font-weight, line-height, spacing…), so Angular Material theming is not enough.

This is why we created this CSS Framework, a starting point to customise Angular Material sytles for Hack&Craft projects.

Related resources:

- [GitHub repo](https://github.com/HackandCraft/hackandcraft-ng/tree/master/projects/css-framework)
- [npm package](https://www.npmjs.com/package/@hackandcraft/css-framework)
- [Pattern Library](https://hackandcraft-ng.hncdev.co.uk/css-framework)
- [Frontend Style Guide > CSS / Sass Style Guide](https://github.com/HackandCraft/frontend-style-guide/blob/master/css-sass-style-guide.md)

## Requirements

- npm
- Angular
- Angular Material library

## Install

1. Install CSS Framework package from your Angular project:

```
$ npm install @hackandcraft/css-framework
```

2. And then install your theme of choice<sup>(1)</sup>:

```
$ npm install @hackandcraft/theme-dulux
```

## Start the Pattern Library

In order to see the components page with the current themes available ("Pattern Library" from now on)<sup>(2)</sup>, just run this from the "hackandcraft-ng" repo:

```
$ ng serve
```

And then access the Pattern Library in: http://localhost:4200/css-framework

## How to create new themes

By default, agnostic theme settings comes out of the box with the framework. These are just "default" styles, not used in any client project.

To create a new client theme, follow these steps:

1. Create a new theme directory and the corresponding "\_settings.scss" file –with specific Sass variables– in "hackandcraft-ng/projects", overriding default theme settings (i.e. "hackandcraft-ng/projects/theme-name/scss/\_settings.scss").
2. Edit the "\_theme.scss" file in the project root, adding your new theme imports (i.e. "theme-name"):

```scss
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
@import "../projects/css-framework/scss/settings";

#css-framework {
  @import "../projects/css-framework/scss/main.scss";

  &.theme-name {
    @import "../projects/theme-name/scss/settings";
    @import "../projects/css-framework/scss/main.scss";
  }

  &.another-theme-name {
    @import "../projects/another-theme-name/scss/settings";
    @import "../projects/css-framework/scss/main.scss";
  }

  // more themes...
}
```

3. Add some Sass variables in your "hackandcraft-ng/projects/theme-name/scss/\_settings.scss" file, to fit your client styles.
4. Add your new theme in "test-css-framework.component.ts" file, in order to make the theme available from the [Pattern Library](https://hackandcraft-ng.hncdev.co.uk/css-framework):

```ts
themes: Theme[] = [
  { title: "Default theme", class: "theme-default" },
  { title: "Akzo Nobel", class: "theme-akzo-nobel" },
  { title: "Dulux theme", class: "theme-dulux" },
  { title: "Name theme", class: "theme-name" },
  // more themes...
];
```

5. Once you're done, your "@hackandcraft/theme-name" can be published as npm package.

## Publish

CSS Framework and client themes are published as npm packages.

Some examples:

- [CSS Framework](https://www.npmjs.com/package/@hackandcraft/css-framework)
- [Akzo Nobel Theme](https://www.npmjs.com/package/@hackandcraft/theme-akzo-nobel)
- [Dulux Theme](https://www.npmjs.com/package/@hackandcraft/theme-dulux)
- More themes to come...

## Using Sass settings

- Use of `!default` flag in Sass variables is only necessary for the CSS Framework default/agnostic theme settings, so there's no need to use it in your "theme-name/\_settings.scss" file.
- If a variable is declared in your theme and assigned to another variable in the same file (known as "variable mapping"), the very last variable must be defined as well in order to work. Example:

In "../projects/css-framework/scss/settings"...

```scss
$fz-small: 14px !default;
$button-fz: $fz-small !default; // 14px
```

In "theme-name/\_settings.scss"...

This **won't work as expected**:

```scss
$fz-small: 12px;
// $button-fz value is 14px :(
```

This **will work**:

```scss
$fz-small: 12px;
$button-fz: $fz-small; // $button-fz value is 12px :)
```

**Important:** Keep this in mind to avoid unexpected results in your theme.

## Modifier classes

Some Angular Material components has been extended with [BEM](http://getbem.com/)<sup>(3)</sup> modifier classes (i.e. dialog sizes).

To use different dialog sizes, add a `cdk-overlay-pane--small` or `cdk-overlay-pane--large` modifier class to the `cdk-overlay-pane` element, with JS.

Small:

```html
<div id="cdk-overlay-0" class="cdk-overlay-pane cdk-overlay-pane--small">
  ...
</div>
```

Medium (default):

```html
<div id="cdk-overlay-0" class="cdk-overlay-pane">...</div>
```

Large:

```html
<div id="cdk-overlay-0" class="cdk-overlay-pane cdk-overlay-pane--large">
  ...
</div>
```

## Fonts and icons

Fonts used in the [Pattern Library](https://hackandcraft-ng.hncdev.co.uk/css-framework) won't be propagated to themes, so you must import your fonts of choice in your project choosing one of these methods:

### Setup Method 1. Using via Google Web Fonts

The easiest way to set up fonts for use in any web page is through Google Web Fonts. All you need to do is include a single line of HTML:

```html
<link
  href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800&display=swap"
  rel="stylesheet"
/>
```

Same thing applies to Material Icons font, if you plan to use icons:

```html
<link
  href="https://fonts.googleapis.com/icon?family=Material+Icons"
  rel="stylesheet"
/>
```

### Setup Method 2. Self hosting

For those looking to self host the web font, some additional setup is necessary. Host the font in a location, for example "your-project/src/assets/fonts", and add the proper CSS rules<sup>(4)</sup>.

The easiest way to go is to create a "fonts.scss" in your "your-project/src/" folder.

Example (in "fonts.scss"):

```scss
@font-face {
  font-family: "colour_sansregular";
  src: url($fonts-path+"colour_sans-regularWEB.eot");
  src: url($fonts-path+"colour_sans-regularWEB.eot?#iefix") format("embedded-opentype"),
    url($fonts-path+"colour_sans-regularWEB.woff") format("woff"),
    url($fonts-path+"colour_sans-regularWEB.ttf") format("truetype"), url($fonts-path+"colour_sans-regularWEB.svg#colour_sansregular")
      format("svg");
  font-weight: normal;
  font-style: normal;
}
```

And then use the font like this:

```css
font-family: "colour_sansregular", Arial, sans-serif;
```

Don't forget to edit your "angular.json" file, referencing your "fonts.scss" file:

```json
"styles": [
  "src/styles.scss",
  "src/fonts.scss"
],
```

## Other resources

- [Material Design](https://material.io/design/)
- [Angular Material](https://material.angular.io/guide/theming)
- [Material theme creation](https://speakerdeck.com/nadalsol/material-theme-creation)

---

> (1) If no theme is installed you'll get default/agnostic theme settings.
>
> (2) In order to see the styles properly, `id="css-framework"` and `class="theme-name"` has been added to the `<html>` tag in the [Pattern Library](https://hackandcraft-ng.hncdev.co.uk/css-framework) page.
>
> (3) Notice how we're using BEM for CSS class names, so please refer to our [Frontend Style Guide > CSS / Sass Style Guide](https://github.com/HackandCraft/frontend-style-guide/blob/master/css-sass-style-guide.md) for more details.
>
> (4) More info in [Material Icons Guide > Icon font for the web](https://google.github.io/material-design-icons/#icon-font-for-the-web).

---
_Source: https://npm.io/package/@hackandcraft/css-framework · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
