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

Trailing icon now a part of utills and can use external icon #3093

Merged
merged 10 commits into from
Jun 15, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
margin-right: utils.size('s');
}
}

.trailing-icon-example {
@include utils.trailing-icon('navigation');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component } from '@angular/core';

const config = {
selector: 'cookbook-link-example-trailing-icon',
template: `<a class="trailing-icon-example" target="_blank" href="https://github.com/kirbydesign/designsystem">Trailing icon</a>`,
style: `@use '@kirbydesign/core/src/scss/utils';

.trailing-icon-example {
// Using a Kirby icon:
@include utils.trailing-icon("navigation");

// Using a URL to an svg:
@include utils.trailing-icon("https://cdn.jsdelivr.net/npm/open-iconic@1.1.1/svg/heart.svg");
}`,
};

@Component({
selector: config.selector,
template: config.template,
styleUrls: ['./link-examples.shared.scss'],
})
export class LinkExampleTrailingIconComponent {
template: string = config.template;
style: string = config.style;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import { KirbyModule } from '@kirbydesign/designsystem';

import { LinkExampleDefaultComponent } from './examples/default';
import { LinkExampleNewTabComponent } from './examples/new-tab';
import { LinkExampleTrailingIconComponent } from '~/app/examples/link-example/examples/trailing-icon';

const COMPONENT_DECLARATIONS = [LinkExampleNewTabComponent, LinkExampleDefaultComponent];
const COMPONENT_DECLARATIONS = [
LinkExampleNewTabComponent,
LinkExampleDefaultComponent,
LinkExampleTrailingIconComponent,
];

@NgModule({
imports: [CommonModule, KirbyModule, RouterModule],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ <h2>New tab</h2>
In a non-web context, i.e. an app, any link will most likely launch the device's browser and
effectively open a new tab outside the app context.
</p>

<h2>Custom trailing-icon</h2>
<p>
If you want to use a custom icon after the link instead of the external link icon then include the Kirby SCSS @mixin <code>utils.trailing-icon</code>
and the icon name of your choosing: <code>@include trailing-icon(iconName)</code>
</p>
<p>
The example below is using
<code>"navigation"</code>
as iconName. If you want to use an external svg, then you can input an URL instead of iconName.
AgreSanGit marked this conversation as resolved.
Show resolved Hide resolved
View code to see examples.
</p>

<cookbook-example-viewer [html]="trailingTab.template" [css]="trailingTab.style">
<cookbook-link-example-trailing-icon #trailingTab></cookbook-link-example-trailing-icon>
</cookbook-example-viewer>
23 changes: 7 additions & 16 deletions libs/core/src/scss/_global-styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,6 @@ ion-loading.kirby-loading-overlay {
}
}

/*
* Class to add link-icon to the right of e.g. anchor tag.
*/
.kirby-external-icon {
$icon-scaling-factor: 1.5em;

white-space: nowrap;
background-image: url('/assets/kirby/icons/svg/link.svg');
background-repeat: no-repeat;
background-position: right 50%;
background-size: $icon-scaling-factor;

// Place icon to the right of text, with icons own width + the actual spacing
padding-right: calc(#{$icon-scaling-factor} + #{utils.size('xxxs')});
}

/*
* Modal V2.
*/
Expand Down Expand Up @@ -327,3 +311,10 @@ html.ios ion-modal.kirby-modal-v2 {
display: flex;
}
}

/*
* Class to add link-icon to the right of e.g. anchor tag.
*/
.kirby-external-icon {
@include utils.trailing-icon;
}
22 changes: 22 additions & 0 deletions libs/core/src/scss/base/_functions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,25 @@
text-overflow: ellipsis;
}
}

@mixin trailing-icon($svg: 'link') {
$icon-scaling-factor: 1.5em;

@if str-index($svg, 'http') {
// External icon
background-image: url('#{$svg}');
} @else {
// Icon from library
$icon-url: '/assets/kirby/icons/svg/#{$svg}.svg';

background-image: url('#{$icon-url}');
}

white-space: nowrap;
background-repeat: no-repeat;
background-position: right 50%;
background-size: $icon-scaling-factor;

// Place icon to the right of text, with icons own width + the actual spacing
padding-right: calc(#{$icon-scaling-factor} + #{size('xxxs')});
}