Skip to content

Commit

Permalink
feat(colouring): leverage mask-image
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
  • Loading branch information
lucagoslar committed Feb 9, 2023
1 parent 4c68e53 commit 81ea8ee
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm i phosphor-css

## Usage

By default, icons are the size of 1.5rem (24px). `width`, `height` and `line-height` can be modified when targetting the `ph` class.
By default, icons are the size of 1.5rem (24px). `width`, `height`, `background-color` (final icon colour) and `line-height` can be modified when targetting `.ph.icon`.

```css
@import 'phosphor-css/css/index.css';
Expand All @@ -33,12 +33,12 @@ By default, icons are the size of 1.5rem (24px). `width`, `height` and `line-hei

```html
<!-- regular -->
<i class="ph heart" />
<i class="ph icon heart" />
```

```html
<!-- bold -->
<i class="ph heart bold" />
<i class="ph icon heart bold" />
```

## License
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phosphor-css",
"version": "1.0.2",
"version": "2.0.0",
"description": "🧩 CSS integration of a flexible icon family for the web.",
"files": [
"assets",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ for (const icon of icons) {

fs.appendFileSync(
'less/index.less',
'.ph.' + iconName + ' { .icon(' + iconName + '); }\n'
'.ph.icon.' + iconName + ' { .icon(' + iconName + '); }\n'
);
}

Expand All @@ -120,7 +120,7 @@ for (const icon of icons) {

fs.appendFileSync(
'less/regular.less',
'.ph { .regularWeightIcon(' + iconName + '); }\n'
'.ph.icon { .regularWeightIcon(' + iconName + '); }\n'
);
}

Expand All @@ -144,7 +144,7 @@ for (const weight of weights) {

fs.appendFileSync(
'less/' + weight + '.less',
'.ph { .icon(' + iconName + '); }\n'
'.ph.icon { .icon(' + iconName + '); }\n'
);
}
}
8 changes: 5 additions & 3 deletions src/templates/less/base.less
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@phosphor-icons: '../assets';

.ph {
.ph.icon {
position: relative;
display: inline-block;

background-size: contain;
background-repeat: no-repeat;
mask-size: contain;
mask-repeat: no-repeat;

background-color: #000;

width: 1.5rem;
height: 1.5rem;
Expand Down
6 changes: 4 additions & 2 deletions src/templates/less/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
@weights: bold, duotone, fill, light, thin;

.icon(@type) {
background-image: url('@{phosphor-icons}/regular/@{type}.svg');
mask-image: url('@{phosphor-icons}/regular/@{type}.svg');
-webkit-mask-image: url('@{phosphor-icons}/regular/@{type}.svg');
each(@weights, {
&.@{value} {
background-image: url("@{phosphor-icons}/@{value}/@{type}-@{value}.svg");
mask-image: url("@{phosphor-icons}/@{value}/@{type}-@{value}.svg");
-webkit-mask-image: url("@{phosphor-icons}/@{value}/@{type}-@{value}.svg");
}
});
}
6 changes: 4 additions & 2 deletions src/templates/less/single__weight.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

.regularWeightIcon(@type) {
&.@{type} {
background-image: url('@{phosphor-icons}/regular/@{type}.svg');
mask-image: url('@{phosphor-icons}/regular/@{type}.svg');
-webkit-mask-image: url('@{phosphor-icons}/regular/@{type}.svg');
}
}

.icon(@type) {
&.@{type}.@{weight} {
background-image: url('@{phosphor-icons}/@{weight}/@{type}-@{weight}.svg');
mask-image: url('@{phosphor-icons}/@{weight}/@{type}-@{weight}.svg');
-webkit-mask-image: url('@{phosphor-icons}/@{weight}/@{type}-@{weight}.svg');
}
}
8 changes: 5 additions & 3 deletions src/templates/scss/base.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
$phosphor-icons: '../assets';

.ph {
.ph.icon {
position: relative;
display: inline-block;

background-size: contain;
background-repeat: no-repeat;
mask-size: contain;
mask-repeat: no-repeat;

background-color: #000;

width: 1.5rem;
height: 1.5rem;
Expand Down
8 changes: 5 additions & 3 deletions src/templates/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
$weights: bold, duotone, fill, light, thin;

@mixin icon($type) {
.ph.#{$type} {
background-image: url('#{$phosphor-icons}/regular/#{$type}.svg');
.ph.icon.#{$type} {
mask-image: url('#{$phosphor-icons}/regular/#{$type}.svg');
-webkit-mask-image: url('#{$phosphor-icons}/regular/#{$type}.svg');
@each $weight in $weights {
&.#{$weight} {
background-image: url('#{$phosphor-icons}/#{$weight}/#{$type}-#{$weight}.svg');
mask-image: url('#{$phosphor-icons}/#{$weight}/#{$type}-#{$weight}.svg');
-webkit-mask-image: url('#{$phosphor-icons}/#{$weight}/#{$type}-#{$weight}.svg');
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/templates/scss/single__weight.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
@import 'base';

@mixin regularWeightIcon($type) {
.ph.#{$type} {
background-image: url('#{$phosphor-icons}/regular/#{$type}.svg');
.ph.icon.#{$type} {
mask-image: url('#{$phosphor-icons}/regular/#{$type}.svg');
-webkit-mask-image: url('#{$phosphor-icons}/regular/#{$type}.svg');
}
}

@mixin icon($type) {
.ph.#{$type}.#{$weight} {
background-image: url('#{$phosphor-icons}/#{$weight}/#{$type}-#{$weight}.svg');
.ph.icon.#{$type}.#{$weight} {
mask-image: url('#{$phosphor-icons}/#{$weight}/#{$type}-#{$weight}.svg');
-webkit-mask-image: url('#{$phosphor-icons}/#{$weight}/#{$type}-#{$weight}.svg');
}
}

0 comments on commit 81ea8ee

Please sign in to comment.