Skip to content

Commit 61611cb

Browse files
authored
feat: Use sass name-spacing (#76)
## Description Updates to use SASS name-spacing to ensure it follows best practice at this time. ## Issue https://jira.dev.bbc.co.uk/browse/GEL
1 parent b9ac37e commit 61611cb

File tree

5 files changed

+90
-80
lines changed

5 files changed

+90
-80
lines changed

README.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66

77
## Breaking Change: v6.0.0
88

9-
### @import, @use and @forward
9+
v6.0.0 of GEL Typography implements the [@use](https://sass-lang.com/documentation/at-rules/use/) and [@forward](https://sass-lang.com/documentation/at-rules/forward/) approach and removes [@import](https://sass-lang.com/documentation/at-rules/import/).
1010

11-
The `@import` directive is now deprecated in favour of `@use` and `@forward`, see [SASS documentation](https://sass-lang.com/documentation/at-rules/use/) for more information.
11+
This has a number of consequences; how modules are loaded, and how to access variables. Namespaces now come into play, so please read the sass documentation links above to learn more.
1212

13-
GEL Typography has now been updated to `@use` and `@forward` to remove a large number of deprecation notices.
14-
15-
With the new @use directive, no var, function, or mixin is placed in global scope, and they are all scoped within the file.
16-
17-
This means that users will explicitly need to include the partial file in each file that may use its vars, functions or mixins.
13+
For usage of GEL Typography prior to v6.0.0 please reference the [v5.2.0 readme](https://github.com/bbc/gel-typography/tree/5.2.0).
1814

1915

2016
## What is this?
@@ -27,9 +23,11 @@ The typographic scale has been optimised based on the size of the viewport and t
2723

2824
It can used in two forms, using a Sass mixin:
2925

30-
```sass
26+
```scss
27+
@use 'gel-typography/typography' as type;
28+
3129
.my-component {
32-
@include gel-typography('canon-bold');
30+
@include type.gel-typography('canon-bold');
3331
}
3432
```
3533

@@ -53,7 +51,7 @@ $ npm install --save gel-typography
5351

5452
```sass
5553
// your-app/main.scss
56-
@use 'node_modules/gel-typography/typography';
54+
@use 'gel-typography/typography';
5755
```
5856

5957
### Install manually
@@ -62,12 +60,22 @@ You can install this component manually by downloading the content of this Git r
6260

6361
> **Note:** you will manually need to manage the dependencies below, without these this component will fail to compile.
6462
65-
## Dependencies
63+
### Loadpaths
64+
65+
Because this module depends on other modules, [GEL Sass Tools](https://github.com/bbc/gel-sass-tools) and [Sass MQ](https://github.com/sass-mq/sass-mq), when compiling your Sass it needs to know where find the referenced modules. It does this via a [loadPath](https://sass-lang.com/documentation/at-rules/use/#load-paths).
6666

67-
In order to use the component you will need the following components available:
67+
If compiling from the command line you can specify:
68+
```
69+
sass --load-path=node_modules/ <options>
70+
```
71+
72+
With nodejs you can call `compile` or `compileAsync`:
73+
```js
74+
await sass.compileAsync(file, { loadPaths: ['./node_modules'] })
75+
```
76+
77+
This ensures the dependencies can be loaded correctly.
6878

69-
- [GEL Sass Tools](https://github.com/bbc/gel-sass-tools)
70-
- [Sass MQ](https://github.com/sass-mq/sass-mq)
7179

7280
## Usage
7381

@@ -76,12 +84,14 @@ By default the GEL Typography component does not output any markup but exposes a
7684
**Example**
7785

7886
```scss
87+
@use 'gel-typography/typography' as type;
88+
7989
.my-component {
80-
@include gel-typography('pica');
90+
@include type.gel-typography('pica');
8191
}
8292

8393
.my-component__title {
84-
@include gel-typography('canon');
94+
@include type.gel-typography('canon');
8595
}
8696
```
8797

@@ -90,7 +100,7 @@ A collection of typography classes can be output by defining `$gel-type-enable--
90100
**Example:**
91101

92102
```scss
93-
@use "gel-typography/typography" with ($gel-type-enable--markup-output: true);
103+
@use "gel-typography/typography" as type with ($gel-type-enable--markup-output: true);
94104
```
95105

96106
The following configurable options are available:

lib/_settings.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@use 'sass-mq/mq' as *;
2-
@use 'gel-sass-tools/sass-tools' as *;
1+
@use 'sass-mq/mq';
2+
@use 'gel-sass-tools/sass-tools';
33

44

55
///*------------------------------------*\
@@ -18,7 +18,7 @@
1818
// @type String
1919
// @link http://bit.ly/1Z6hPfd
2020
//
21-
$gel-type-namespace: $gel-namespace !default;
21+
$gel-type-namespace: sass-tools.$gel-namespace !default;
2222

2323
// The classname used to signify if the device needs to display the no-touch group. This
2424
// class needs to be applied to high level elemet such as `body` or `html`
@@ -413,5 +413,5 @@ $gel-larger-font-sizes: (
413413
// Adds the typography specific breakpoints to the Sass MQ list
414414
// of breakpoints
415415
//
416-
@include add-breakpoint(gel-bp-type-b, 320px);
417-
@include add-breakpoint(gel-bp-type-c, 600px);
416+
@include mq.add-breakpoint(gel-bp-type-b, 320px);
417+
@include mq.add-breakpoint(gel-bp-type-c, 600px);

lib/_tools.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@use 'sass-mq/mq' as *;
2-
@use 'gel-sass-tools/sass-tools' as *;
1+
@use 'sass-mq/mq';
2+
@use 'gel-sass-tools/sass-tools' ;
33
@use 'settings';
44
@use 'sass:map';
55
@use 'sass:math';
@@ -118,13 +118,13 @@ $fixed: false !default;
118118
}
119119

120120
@if $enhanced {
121-
@include mq($from: gel-bp-type-b) {
121+
@include mq.mq($from: gel-bp-type-b) {
122122
$groupB: gel-typography($type-class, 'group-b');
123123
@include _gel-output-type-values($groupB);
124124
@include reith-letter-spacing($groupB);
125125
}
126126

127-
@include mq($from: gel-bp-type-c) {
127+
@include mq.mq($from: gel-bp-type-c) {
128128
$groupC: gel-typography($type-class, 'group-c');
129129
@include _gel-output-type-values($groupC);
130130
@include reith-letter-spacing($groupC);
@@ -151,7 +151,7 @@ $fixed: false !default;
151151
@mixin _gel-output-type-values($type-values) {
152152
@each $property, $value in $type-values {
153153
@if (meta.type-of($value) == number and math.unit($value) == 'px') {
154-
@include toRem($property, $value);
154+
@include sass-tools.toRem($property, $value);
155155
} @else {
156156
#{$property}: $value;
157157
}

package-lock.json

Lines changed: 51 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gel-typography",
3-
"version": "6.0.0-beta.2",
3+
"version": "6.0.0-beta.3",
44
"description": "A flexible code implementation of the GEL Typography",
55
"main": "_typography.scss",
66
"scripts": {
@@ -40,7 +40,7 @@
4040
"sass": "1.86.0"
4141
},
4242
"dependencies": {
43-
"gel-sass-tools": "4.0.0-beta.3",
43+
"gel-sass-tools": "4.0.0-beta.4",
4444
"sass-mq": "7.0.0-beta.1"
4545
}
4646
}

0 commit comments

Comments
 (0)