Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(icons): implement ui icon set #3969

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ba2f191
dep(icons): add node-html-parser dev dependency
oliverschuerch Nov 8, 2024
a80c7e2
feat(icons): add v2 input icons
oliverschuerch Nov 8, 2024
f14a365
chore(icons): update gitignore to be able to check in v2 input icons
oliverschuerch Nov 8, 2024
b2dcec5
feat(icons): add logic for sprite generation (incomplete)
oliverschuerch Nov 8, 2024
1ea92d7
chore(icons): udpate preview
oliverschuerch Nov 8, 2024
7992fda
fix(icons): rename ui icons
oliverschuerch Nov 11, 2024
bc3f9f4
feat(icons): add ui icon generator
oliverschuerch Nov 11, 2024
9f25a16
chore(icons): ignore generated ui icon files
oliverschuerch Nov 11, 2024
ebc22b0
chore(icons): remove colored ui icons
oliverschuerch Nov 12, 2024
4532f48
chore(icons): update playground
oliverschuerch Nov 12, 2024
2c0478f
chore(icons): update ui icon generation output
oliverschuerch Nov 12, 2024
1c82cfb
chore(icons): move v1 icons from dist to src folder
oliverschuerch Nov 12, 2024
2d6eedb
chore(icons): remove report.json
oliverschuerch Nov 12, 2024
7029827
chore(icons): align v1 and ui icon processing
oliverschuerch Nov 12, 2024
826529a
chore(icons): update gitignore
oliverschuerch Nov 12, 2024
daf66d2
Merge branch 'main' into feat/3851-implement-responsive-ui-icons
oliverschuerch Nov 12, 2024
b6d22b5
fix(icons): fix issue reported by sonar
oliverschuerch Nov 12, 2024
263e5c0
refactor(icons): align uiIcons with v1 icons process
oliverschuerch Nov 12, 2024
1e94650
chore(icons): remove v1 source icons
oliverschuerch Nov 12, 2024
d59e8a7
chore(icons): remove ui source icons
oliverschuerch Nov 12, 2024
7e43887
feat(icons): add v1 source icons
oliverschuerch Nov 12, 2024
4d1f27b
chore(icons): remove v1 source icons
oliverschuerch Nov 12, 2024
af18b6c
chore(icons): add ui source icons (test)
oliverschuerch Nov 12, 2024
95c8ccb
chore(icons): update gitignore
oliverschuerch Nov 12, 2024
73fbf85
chore(icons): revert removing of post-icons
oliverschuerch Nov 12, 2024
e4d44b6
chore(icons): prepare gitignore
oliverschuerch Nov 12, 2024
622dd54
chore(icons): update gitignore
oliverschuerch Nov 12, 2024
fde17da
Revert "chore(icons): move v1 icons from dist to src folder"
oliverschuerch Nov 12, 2024
c3d0aae
fix(icons): fix issue reported by sonar
oliverschuerch Nov 12, 2024
696adbc
chore: changeset
oliverschuerch Nov 12, 2024
2540b58
chore(icons): update gitignore
oliverschuerch Nov 12, 2024
e0bbbc2
feat(components): implement svg use in post-icon component
oliverschuerch Nov 14, 2024
5893fed
chore: add changeset
oliverschuerch Nov 14, 2024
f9c5f0c
chore(components): update cdn-url
oliverschuerch Nov 14, 2024
cb3d29e
chore(icons): update v1 icons output to be backwards compatible
oliverschuerch Nov 15, 2024
51a69cc
chore(documentation): update icons package base path config
oliverschuerch Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quick-mails-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-components': minor
---

Refactored `post-icon` component, so it uses the svg `use` tag to load and show icons.
5 changes: 5 additions & 0 deletions .changeset/red-moose-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-icons': minor
---

Added ui icons set, to be used with the `post-icon` component.
38 changes: 30 additions & 8 deletions packages/components/src/components/post-icon/post-icon.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
@use 'sass:list';
@use 'sass:map';

$post-icon-sizes: (
'16': 16px,
'24': 24px,
'32': 32px,
'40': 40px,
'48': 48px,
'64': 64px,
);

$post-icon-animations: (
'cylon': icon-animation-cylon 0.75s ease-in-out infinite alternate,
'cylon-vertical': icon-animation-cylon-vertical 0.75s ease-in-out infinite alternate,
Expand All @@ -10,25 +20,37 @@ $post-icon-animations: (
);

:host {
container-name: post-icon;
container-type: inline-size;
display: inline-block;
width: 1em;
height: 1em;
vertical-align: -0.15em;
}

span {
svg {
display: block;
width: 100%;
height: 100%;
fill: currentColor;
forced-color-adjust: preserve-parent-color;
background-color: currentColor;
-webkit-mask-position: center center;
mask-position: center center;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
-webkit-mask-size: 100%;
mask-size: 100%;
}

@each $key, $value in $post-icon-sizes {
$keys: map.keys($post-icon-sizes);
$index: list.index($keys, $key);
$nextKey: if($index + 1 <= list.length($keys), list.nth($keys, $index + 1), null);
$nextValue: map.get($post-icon-sizes, $nextKey);

$min: if($index == 1, null, 'min-width: #{$value}');
$max: if($index == list.length($keys), null, 'max-width: #{$nextValue - 0.02}');
$connector: if($min and $max, ') and (', '');

@container post-icon (#{$min}#{$connector}#{$max}) {
svg {
--pis-#{$key}: block;
}
}
}

// flip
Expand Down
53 changes: 23 additions & 30 deletions packages/components/src/components/post-icon/post-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Element, Host, h, Prop, State, Watch } from '@stencil/core';
import { Component, Element, Host, h, Prop, Watch } from '@stencil/core';
import { checkNonEmpty, checkType, checkEmptyOrType, checkEmptyOrOneOf } from '@/utils';
import { version } from '@root/package.json';

Expand All @@ -25,13 +25,8 @@ type Animation = (typeof ANIMATION_NAMES)[number];
shadow: true,
})
export class PostIcon {
private path: string;

@Element() host: HTMLPostIconElement;

@State() svgStyles: string;
@State() svgOutput: string;

/**
* The name of the animation.
*/
Expand Down Expand Up @@ -110,48 +105,46 @@ export class PostIcon {
checkEmptyOrType(newValue, 'number', 'The post-icon "scale" prop should be a number.');
}

componentDidLoad() {
this.validateBase();
this.validateName();
this.validateFlipH();
this.validateFlipV();
this.validateScale();
this.validateRotate();
this.validateAnimation();
}

componentWillRender() {
this.setPath();
}

private setPath() {
private getPath() {
// Construct icon path from different possible sources
const metaBase =
document.head
.querySelector('meta[name="design-system-settings"][data-post-icon-base]')
?.getAttribute('data-post-icon-base') ?? null;

const fileBase = `${this.base ?? metaBase ?? CDN_URL}/`.replace(/\/\/$/, '/');
const fileName = `${this.name}.svg`;
const fileName = `${this.name}.svg#i-${this.name}`;
const filePath = `${fileBase}${fileName}`;

this.path = new URL(filePath, window.location.origin).toString();
return new URL(filePath, window.location.origin).toString();
}

render() {
// create inline styles for some properties
const svgStyles = Object.entries({
'-webkit-mask-image': `url('${this.path}')`,
'mask-image': `url('${this.path}')`,
'transform':
private getStyles() {
return Object.entries({
transform:
(this.scale && !isNaN(Number(this.scale)) ? 'scale(' + this.scale + ')' : '') +
(this.rotate && !isNaN(Number(this.rotate)) ? ' rotate(' + this.rotate + 'deg)' : ''),
})
.filter(([_key, value]) => value !== null)
.reduce((styles, [key, value]) => Object.assign(styles, { [key]: value }), {});
}

componentDidLoad() {
this.validateBase();
this.validateName();
this.validateFlipH();
this.validateFlipV();
this.validateScale();
this.validateRotate();
this.validateAnimation();
}

render() {
return (
<Host data-version={version}>
<span style={svgStyles}></span>
<svg style={this.getStyles()}>
<use href={this.getPath()} />
</svg>
</Host>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<html>
<head>
<meta name="design-system-settings" data-post-icon-base="/assets/post-icons" />
<meta name="design-system-settings" data-post-icon-base="/path/to/all/icons/folder" />
</head>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ You can do this with two different solutions:

<PostTabHeader panel="baseAttribute">Base-attribute solution</PostTabHeader>
<PostTabPanel name="baseAttribute">
<Source code={`<post-icon name="1000" base="/base-path/to/your/own/icon-folder"></post-icon>`} language="html"/>
<Source code={`<post-icon name="1000" base="/path/to/a/specific/icon/folder"></post-icon>`} language="html"/>
</PostTabPanel>
</PostTabs>

Expand Down
18 changes: 17 additions & 1 deletion packages/icons/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@ node_modules
# Stores password, don't check in
.env

# TODO: Remove before merge
src/icons/**/*.svg
!src/icons/v1
!src/icons/v2
!src/icons/v1/1000.svg
!src/icons/v2/Accessibility_16.svg
!src/icons/v2/Accessibility_24.svg
!src/icons/v2/Accessibility_32.svg
!src/icons/v2/Accessibility_40.svg
!src/icons/v2/Accessibility_48.svg
!src/icons/v2/Accessibility_64.svg

# Ignore generated files
icons
# TODO: Add before merge
# public/post-icons
public/report.json
public/report.v2.json

icons-optimized
icons.json
no-svgs.json
1 change: 1 addition & 0 deletions packages/icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"jest": "29.7.0",
"mock-fs": "5.2.0",
"node-fetch": "2.7.0",
"node-html-parser": "6.1.13",
"svgo": "3.3.2",
"ts-jest": "29.2.4",
"ts-node": "10.9.2",
Expand Down
Loading
Loading