2022-03-23 17:49:10 -04:00
# Technologies
* [Styles ](#styles )
* [CSS Architecture ](#css-architecture )
* [CSS Naming Convention ](#css-naming-convention )
* [CSS Namespacing ](#css-namespacing )
* [Example ](#example-1 )
* [Scripts ](#scripts )
* [Example ](#example-2 )
* [Page transitions ](#page-transitions )
* [Example ](#example-3 )
* [Scroll detection ](#scroll-detection )
* [Example ](#example-4 )
## Styles
[SCSS][Sass] is a superset of CSS that adds many helpful features to improve
and modularize our styles.
We use [node-sass] (LibSass) for processing and minifying SCSS into CSS.
We also use [PostCSS] and [Autoprefixer] to parse our CSS and add
vendor prefixes for experimental features.
2022-03-24 13:57:28 -04:00
### CSS Architecture
2022-03-23 17:49:10 -04:00
The boilerplate's CSS architecture is based on [Inuit CSS][inuitcss] and [ITCSS].
* `settings` : Global variables, site-wide settings, config switches, etc.
* `tools` : Site-wide mixins and functions.
* `generic` : Low-specificity, far-reaching rulesets (e.g. resets).
* `elements` : Unclassed HTML elements (e.g. `a {}` , `blockquote {}` , `address {}` ).
* `objects` : Objects, abstractions, and design patterns (e.g. `.o-layout {}` ).
* `components` : Discrete, complete chunks of UI (e.g. `.c-carousel {}` ).
* `utilities` : High-specificity, very explicit selectors. Overrides and helper
classes (e.g. `.u-hidden {}` )
Learn more about [Inuit CSS ](https://github.com/inuitcss/inuitcss#css-directory-structure ).
2022-03-24 13:57:28 -04:00
### CSS Naming Convention
2022-03-23 17:49:10 -04:00
We use a simplified [BEM] (Block, Element, Modifier) syntax:
* `.block`
* `.block_element`
* `.-modifier`
2022-03-24 13:57:28 -04:00
### CSS Namespacing
2022-03-23 17:49:10 -04:00
We namespace our classes for more UI transparency:
* `o-` : Object that it may be used in any number of unrelated contexts to the one you can currently see it in. Making modifications to these types of class could potentially have knock-on effects in a lot of other unrelated places.
* `c-` : Component is a concrete, implementation-specific piece of UI. All of the changes you make to its styles should be detectable in the context you’ re currently looking at. Modifying these styles should be safe and have no side effects.
* `u-` : Utility has a very specific role (often providing only one declaration) and should not be bound onto or changed. It can be reused and is not tied to any specific piece of UI.
* `s-` : Scope creates a new styling context. Similar to a Theme, but not necessarily cosmetic, these should be used sparingly—they can be open to abuse and lead to poor CSS if not used wisely.
* `is-` , `has-` : Is currently styled a certain way because of a state or condition. It tells us that the DOM currently has a temporary, optional, or short-lived style applied to it due to a certain state being invoked.
Learn about [namespacing ](https://csswizardry.com/2015/03/more-transparent-ui-code-with-namespaces/ ).
2022-03-24 13:57:28 -04:00
### Example \#1
2022-03-23 17:49:10 -04:00
```html
<div class="c-block -large">
<div class="c-block_layout o-layout">
<div class="o-layout_item u-1/2@from -medium">
<div class="c-block_heading o-h -medium">Heading</div>
</div>
<div class="o-layout_item u-1/2@from -medium">
<a class="c-block_button o-button -outline" href="#">Button</a>
</div>
</div>
</div>
```
```scss
.c-block {
&.-large {
padding: rem(60px);
}
}
.c-block_heading {
2024-03-26 16:50:16 -04:00
@media (max-width: $to-md) {
2022-03-23 17:49:10 -04:00
.c-block.-large & {
margin-bottom: rem(40px);
2024-03-26 16:50:16 -04:00
}
2022-03-23 17:49:10 -04:00
}
}
```
## Scripts
2022-03-24 13:57:28 -04:00
We use [esbuild] for bundling and minifying JavaScript/ES modules.
2022-03-23 17:49:10 -04:00
[modularJS] is a small framework we use on top of ES modules.
* Automatically init visible modules.
* Easily call other modules methods.
* Quickly set scoped events with delegation.
* Simply select DOM elements scoped in their module.
2022-03-24 13:57:28 -04:00
[_source_ ](https://npmjs.com/package/modujs#why )
2022-03-23 17:49:10 -04:00
2022-03-24 13:57:28 -04:00
### Example \#2
2022-03-23 17:49:10 -04:00
```html
<div data-module-example>
<div data-example="main">
<h2>Example</h2>
</div>
<button data-example="load">More</button>
</div>
```
```js
import { module } from 'modujs';
export default class extends module {
constructor(m) {
super(m);
this.events = {
click: {
load: 'loadMore'
}
};
}
loadMore() {
this.$('main')[0].classList.add('is-loading');
}
}
```
Learn more about [modularJS].
## Page transitions
[modularLoad] is used for page transitions and lazy loading.
2022-03-24 13:57:28 -04:00
### Example \#3
2022-03-23 17:49:10 -04:00
```html
<nav>
<a href="/">Home</a>
<a href="/page" data-load="transitionName">Page</a>
</nav>
<div data-load-container>
<img data-load-src="assets/images/hello.jpg">
</div>
```
```js
import modularLoad from 'modularload';
this.load = new modularLoad({
enterDelay: 300,
transitions: {
transitionName: {
enterDelay: 450
}
}
});
```
Learn more about [modularLoad].
## Scroll detection
[Locomotive Scroll][locomotive-scroll] is used for elements in viewport
detection and smooth scrolling with parallax.
2022-03-24 13:57:28 -04:00
### Example \#4
2022-03-23 17:49:10 -04:00
```html
<div data-module-scroll>
<div data-scroll>Trigger</div>
<div data-scroll data-scroll-speed="1">Parallax</div>
</div>
```
```js
import LocomotiveScroll from 'locomotive-scroll';
2023-06-12 09:36:14 +02:00
this.scroll = new LocomotiveScroll({})
2022-03-23 17:49:10 -04:00
````
Learn more about [Locomotive Scroll][locomotive-scroll].
2022-03-24 13:57:28 -04:00
[Autoprefixer]: https://npmjs.com/package/autoprefixer
2022-03-23 17:49:10 -04:00
[BEM]: https://bem.info/
2022-03-24 13:57:28 -04:00
[BrowserSync]: https://npmjs.com/package/browser-sync
[esbuild]: https://npmjs.com/package/esbuild
2022-03-23 17:49:10 -04:00
[inuitcss]: https://github.com/inuitcss/inuitcss
[ITCSS]: https://itcss.io/
2022-03-24 13:57:28 -04:00
[locomotive-scroll]: https://npmjs.com/package/locomotive-scroll
[modularJS]: https://npmjs.com/package/modujs
[modularLoad]: https://npmjs.com/package/modularload
[node-sass]: https://npmjs.com/package/node-sass
[PostCSS]: https://npmjs.com/package/postcss
2022-03-23 17:49:10 -04:00
[Sass]: https://sass-lang.com/
2022-03-24 13:57:28 -04:00
[svg-mixer]: https://npmjs.com/package/svg-mixer
2022-03-23 17:49:10 -04:00
[Node]: https://nodejs.org/
[NPM]: https://npmjs.com/
[NVM]: https://github.com/nvm-sh/nvm