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

Feature/local navigation #2501

Merged
merged 33 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
46f3cf5
fixed top content directive
RasmusTraeholt Sep 20, 2022
51eb332
merge - solve conflicts
RasmusTraeholt Sep 20, 2022
2ef74e0
removed cookbook example
RasmusTraeholt Sep 20, 2022
20a92da
updates
RasmusTraeholt Sep 20, 2022
31cf3e8
removed redundant style
RasmusTraeholt Sep 20, 2022
745937c
local navigation component
RasmusTraeholt Sep 21, 2022
6043fbb
update directive name
RasmusTraeholt Sep 21, 2022
e4cb57d
rollback unwanted linting changes
RasmusTraeholt Sep 21, 2022
5fdf17b
removed duplicate style value
RasmusTraeholt Sep 21, 2022
139a932
removed console log + redundant styles
RasmusTraeholt Sep 22, 2022
7018879
added console warn
RasmusTraeholt Sep 22, 2022
d686cb6
revert
RasmusTraeholt Sep 22, 2022
867b69b
Merge branch 'develop' into feature/local-navigation
RasmusTraeholt Oct 3, 2022
d6c3f14
fixed top content spacing
RasmusTraeholt Oct 3, 2022
4c7c7a6
Merge branch 'develop' into feature/local-navigation
RasmusTraeholt Oct 5, 2022
a9a663b
solve conflicts + removed unsued imports
RasmusTraeholt Oct 5, 2022
657ea8b
Merge branch 'develop' into feature/local-navigation
RasmusTraeholt Oct 11, 2022
f1cc74c
updates
RasmusTraeholt Oct 11, 2022
4678931
Merge branch 'feature/local-navigation' of https://github.com/kirbyde…
RasmusTraeholt Oct 11, 2022
107d1ea
refactor + review changes
RasmusTraeholt Oct 11, 2022
18759b0
Update package.json
RasmusTraeholt Oct 11, 2022
10ca2d6
line-height sass var
RasmusTraeholt Oct 11, 2022
155e610
unit tests + experimental examples module
RasmusTraeholt Oct 12, 2022
a91ddb2
fix module scope
RasmusTraeholt Oct 12, 2022
40a87f9
update divider widht and item spacing
RasmusTraeholt Oct 13, 2022
60a0d55
review changes
RasmusTraeholt Oct 14, 2022
f7d922d
updated styling comments
RasmusTraeholt Oct 17, 2022
e567f11
Merge branch 'develop' into feature/local-navigation
RasmusTraeholt Oct 17, 2022
a4f13ab
bump designsystem version
RasmusTraeholt Oct 17, 2022
57b6a68
Merge branch 'develop' into feature/local-navigation
RasmusTraeholt Oct 18, 2022
813edb8
Update package.json
RasmusTraeholt Oct 24, 2022
278e3ad
Merge branch 'develop' into feature/local-navigation
mictro Oct 24, 2022
7c99477
Merge branch 'develop' into feature/local-navigation
mictro Oct 24, 2022
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
3 changes: 2 additions & 1 deletion apps/cookbook/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { KirbyModule } from '@kirbydesign/designsystem';
import { KirbyExperimentalModule, KirbyModule } from '@kirbydesign/designsystem';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
Expand Down Expand Up @@ -34,6 +34,7 @@ registerLocaleData(localeData);
HttpClientModule,
FormsModule,
KirbyModule,
KirbyExperimentalModule,
],

providers: [
Expand Down
10 changes: 8 additions & 2 deletions apps/cookbook/src/app/examples/examples.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { IconRegistryService, KirbyModule } from '@kirbydesign/designsystem';
import {
IconRegistryService,
KirbyExperimentalModule,
KirbyModule,
} from '@kirbydesign/designsystem';

import { AccordionExampleModule } from './accordion-example/accordion-example.module';
import { AvatarExampleModule } from './avatar-example/avatar-example.module';
Expand All @@ -14,6 +18,7 @@ import { DataTableExampleModule } from './data-table-example/table-example.modul
import { DropdownExampleModule } from './dropdown-example/dropdown-example.module';
import { COMPONENT_DECLARATIONS } from './examples.common';
import { ExamplesSharedModule } from './examples.shared.module';
import { ExperimentalExamplesModule } from './experimental-examples/experimental-examples.module';
import { FlagExampleModule } from './flag-example/flag-example.module';
import { FormFieldExamplesModule } from './form-field-example/form-field-example.module';
import { GridLayoutExamplesModule } from './grid-layout-example/grid-layout-example.module';
Expand Down Expand Up @@ -58,11 +63,12 @@ const IMPORTS = [
ItemGroupExampleModule,
ListExperimentalExampleModule,
VirtualScrollExampleModule,
ExperimentalExamplesModule,
DataTableExampleModule,
];

@NgModule({
imports: [CommonModule, RouterModule, KirbyModule, ...IMPORTS],
imports: [CommonModule, RouterModule, KirbyModule, KirbyExperimentalModule, ...IMPORTS],
declarations: COMPONENT_DECLARATIONS,
exports: [...COMPONENT_DECLARATIONS, ...IMPORTS],
})
Expand Down
7 changes: 7 additions & 0 deletions apps/cookbook/src/app/examples/examples.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ export const routes: Routes = [
},
],
},
{
path: 'experimental',
loadChildren: () =>
import('./experimental-examples/experimental-examples.module').then(
(m) => m.ExperimentalExamplesModule
),
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PageLocalNavigationExampleComponent } from './page-local-navigation/page-local-navigation-example.component';
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Component } from '@angular/core';
import { LocalNavigationItem } from '@kirbydesign/designsystem';
import { BasePageExampleComponent } from '../../../page-example/base-page-example.component';

const config = {
template: `<kirby-page title="Simple Page" subtitle="Subtitle of simple page" defaultBackHref="/">
<kirby-page-local-navigation *kirbyPageStickyContent [items]="items" [selectedIndex]="0"></kirby-page-local-navigation>
<kirby-page-content>
<div [innerHTML]="content"></div>
</kirby-page-content>
</kirby-page>`,
};
@Component({
template: config.template,
})
export class PageLocalNavigationExampleComponent extends BasePageExampleComponent {
items: LocalNavigationItem[] = [
{
text: 'Item 1',
},
{
text: 'Item 2',
badge: {
content: { name: 'attach', isCustom: false },
themeColor: 'warning',
},
},
{
text: 'Item 3',
badge: {
themeColor: 'success',
content: { text: '2' },
},
},
{
text: 'Item 4',
},
{
text: 'Item 5 longer',
},
{
text: 'Item 6 longer',
},
];

static readonly template = config.template
.replace(' defaultBackHref="/"', '')
.replace('<div [innerHTML]="content"></div>', '...');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { KirbyExperimentalModule, KirbyModule } from '@kirbydesign/designsystem';
import { PageLocalNavigationExampleComponent } from './components';
import { ExamplesSharedModule } from '~/app/examples/examples.shared.module';

const COMPONENT_DECLARATIONS = [PageLocalNavigationExampleComponent];

const routes: Routes = [
{
path: '',
children: [
{
path: 'local-navigation',
component: PageLocalNavigationExampleComponent,
},
],
},
];

@NgModule({
imports: [
CommonModule,
RouterModule.forChild(routes),
KirbyModule,
KirbyExperimentalModule,
ExamplesSharedModule,
],
exports: COMPONENT_DECLARATIONS,
declarations: COMPONENT_DECLARATIONS,
})
export class ExperimentalExamplesModule {}
2 changes: 2 additions & 0 deletions libs/designsystem/src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ export { ToggleComponent } from './toggle/toggle.component';

export { ProgressCircleComponent } from './progress-circle/progress-circle.component';
export * from './toggle-button';

export * from './page-local-navigation';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { PageLocalNavigationComponent } from './page-local-navigation.component';
export { LocalNavigationItem } from './page-local-navigation-item';
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ThemeColor } from '@kirbydesign/core';

type BadgeIcon = {
name: string;
isCustom: boolean;
};

type BadgeText = {
text: string;
};

type ItemBadge = {
content: BadgeIcon | BadgeText;
description?: string;
themeColor: ThemeColor;
};
RasmusTraeholt marked this conversation as resolved.
Show resolved Hide resolved

export interface LocalNavigationItem {
/**
* Text of the item
*/
text: string;

/**
* Optional badge to show with the item
*/
badge?: ItemBadge;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="container">
<div class="tab-bar" #tabBar>
<div
class="tab-item"
*ngFor="let item of items; let i = index"
(click)="onTabChange(i)"
[ngClass]="i === selectedIndex ? 'selected' : ''"
[tabIndex]="0"
(keydown.enter)="onTabChange(i)"
(keydown.arrowLeft)="focusNext(i - 1)"
(keydown.arrowRight)="focusNext(i + 1)"
>
<div class="tab-item-inner" [class.extended]="!!item.badge">
<span [attr.text]="item.text">{{ item.text }}</span>
<ng-container *ngIf="item.badge; let badge">
<kirby-badge
role="text"
[attr.aria-label]="badge.description"
[themeColor]="badge.themeColor"
>
<ng-container *ngIf="badge.content.name; else badgeTextContent">
<kirby-icon
*ngIf="badge.content.isCustom; else defaultIconName"
[customName]="badge.content.name"
></kirby-icon>
<ng-template #defaultIconName>
<kirby-icon [name]="badge.content.name"></kirby-icon>
</ng-template>
</ng-container>
<ng-template #badgeTextContent>
{{ badge.content.text }}
</ng-template>
</kirby-badge>
</ng-container>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
@use '~@kirbydesign/core/src/scss/utils';

$tab-item-text-max-width: 100px;
$bottom-border-height: 1px;
$border-color-standard: utils.get-color('medium');
$border-color-selected: utils.get-color('dark');
$divider-max-width-breakpoint: utils.$page-content-max-width + (utils.size('s') * 2);

.tab-bar {
position: relative;
margin: 0 auto;
display: flex;
gap: utils.size('xs');
align-items: center;
justify-content: left;
flex-wrap: nowrap;
overflow-y: hidden;
overflow-x: scroll;

// Ensures that the .container divider pseudo-element does not overlap the .selected divider pseudo-element.
// There seems be a weird bug with the iOS browser where z-index of scrollable elements are not respected with momentum scrolling active - so we disable it for now.
-webkit-overflow-scrolling: auto;

// Hide scrollbar for Firefox
scrollbar-width: none;

// Hide scrollbar for Chrome, Edge, Safari and Opera
&::-webkit-scrollbar {
display: none;
}
}

.container {
position: relative;
background-color: utils.get-color('background-color');
max-width: var(--page-content-max-width, utils.$page-content-max-width);

// Divider
&::before {
content: '';
background-color: $border-color-standard;
position: absolute;
height: $bottom-border-height;
bottom: 0;
z-index: 1;
left: 0;
width: 100%;

@include utils.media('<=#{$divider-max-width-breakpoint}') {
left: -#{utils.size('s')};
width: calc(100% + (#{utils.size('s')} * 2));
}
}
}

.tab-item {
position: relative;
cursor: pointer;
box-sizing: border-box;
outline: none;
padding-bottom: $bottom-border-height * 2;

// Selected divider
&.selected::before {
content: '';
width: 100%;
background-color: $border-color-selected;
position: absolute;
border-radius: 1px;
height: $bottom-border-height * 2;
bottom: 0;
z-index: 2;
}

&.selected,
&:focus,
&:hover {
font-weight: utils.font-weight('bold');
}
Comment on lines +75 to +79
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment about avoiding layout shift

}

.tab-item-inner {
display: flex;
align-items: center;
justify-content: center;
white-space: nowrap;
margin: utils.size('s');

// Disable text selection on tab items
user-select: none;

kirby-badge {
margin-left: utils.size('xxxs');
}

& > span {
max-width: $tab-item-text-max-width;
overflow: hidden;
text-overflow: ellipsis;

// The larger line-height ensures no vertical layout shifts when changing the span's text content from bold to normal font-weight.
// See lines 75-79
line-height: utils.size('m');
}

// Using the before selector to insert a hidden pseudo-element with the same text content in bold,
// ensures no horizontal layout shifts when changing the visible span's text content from bold to normal font-weight.
// See lines 75-79
& > span::before {
display: block;
content: attr(text);
font-weight: bold;
height: 0;
overflow: hidden;
visibility: hidden;
}
}
Loading