Skip to content

Commit

Permalink
fix(daffio): use new sidebar implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
damienwebdev committed Jul 21, 2023
1 parent dd6bc28 commit 22d293c
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 113 deletions.
4 changes: 2 additions & 2 deletions apps/daffio/src/app/api/api-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const apiRoutes: Routes = [
reference: DaffioApiListResolver,
},
data: {
sidebarMode: 'side',
sidebarMode: 'side-fixed',
},
},
{
Expand All @@ -27,7 +27,7 @@ export const apiRoutes: Routes = [
doc: DocsResolver,
},
data: {
sidebarMode: 'side',
sidebarMode: 'side-fixed',
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
:host {
$root: '.daffio-header';
display: block;
position: sticky;
top: 0;
z-index: 10;

::ng-deep {
#{$root}__item {
Expand Down
10 changes: 9 additions & 1 deletion apps/daffio/src/app/core/sidebar/actions/sidebar.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum SidebarActionTypes {
ToggleSidebarAction = '[Daffio-Sidebar] Toggle Sidebar Action',
OpenSidebarAction = '[Daffio-Sidebar] Open Sidebar Action',
CloseSidebarAction = '[Daffio-Sidebar] Close Sidebar Action',
SetSidebarVisibilityAction = '[Daffio-Sidebar] Set Sidebar Visibility Action',
SetSidebarStateAction = '[Daffio-Sidebar] Set Sidebar State Action',
SetSidebarModeAction = '[Daffio-Sidebar] Set Sidebar Mode Action',
ResetModeAction = '[Daffio-Sidebar] Reset Mode Action'
Expand All @@ -23,10 +24,16 @@ export class CloseSidebar implements Action {
readonly type = SidebarActionTypes.CloseSidebarAction;
}

export class SetSidebarVisibility implements Action {
readonly type = SidebarActionTypes.SetSidebarVisibilityAction;

constructor(public payload: boolean){}
}

export class SetSidebarState implements Action {
readonly type = SidebarActionTypes.SetSidebarStateAction;

constructor(public payload: boolean){}
constructor(public payload: { mode?: DaffSidebarMode; open?: boolean }){}
}

export class SetSidebarMode implements Action {
Expand All @@ -44,6 +51,7 @@ export type SidebarActions =
| ToggleSidebar
| OpenSidebar
| CloseSidebar
| SetSidebarVisibility
| SetSidebarState
| SetSidebarMode
| ResetMode;
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<daff-sidebar-viewport (backdropClicked)="close()" [mode]="mode$ | async" [opened]="showSidebar$ | async">
<daff-sidebar class="daffio-sidebar" (escapePressed)="close()">
<daff-sidebar-viewport (backdropClicked)="close()">
<daff-sidebar class="daffio-sidebar" [mode]="mode$ | async" [open]="showSidebar$ | async" (escapePressed)="close()">
<button type="button" daff-button class="daffio-sidebar__button">Get Started</button>
<daffio-guides-nav-tree [guideList]="sidebarContents$ | async"></daffio-guides-nav-tree>
<a routerLink="/api">API Index</a>
</daff-sidebar>
<ng-container daff-sidebar-viewport-nav>
<ng-content select="[daff-sidebar-viewport-nav]"></ng-content>
</ng-container>
<ng-content></ng-content>
</daff-sidebar-viewport>
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ describe('DaffioSidebarViewportContainer', () => {
expect(component).toBeTruthy();
});

it('should set the `daff-sidebar-viewport` mode to the default initialState (push)', () => {
expect(daffSidebarViewport.mode).toEqual('push');
it('should set the `daff-sidebar` mode to the default initialState (push)', () => {
expect(daffSidebar.mode).toEqual('under');
});

describe('when the `daff-sidebar-viewport` emits `backdropClicked`', () => {
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('DaffioSidebarViewportContainer', () => {
it('should call store.dispatch with a SetSidebarAction action', () => {
component.setVisibility(true);

expect(store.dispatch).toHaveBeenCalledWith(new SetSidebarState(true));
expect(store.dispatch).toHaveBeenCalledWith(new SetSidebarState({ open: true }));
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ export class DaffioSidebarViewportContainer implements OnInit{
}

setVisibility(state: boolean) {
this.store.dispatch(new SetSidebarState(state));
this.store.dispatch(new SetSidebarState({ open: state }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import {
tap,
} from 'rxjs/operators';

import { DaffBreakpoints } from '@daffodil/design';
import {
DaffBreakpoints,
DaffSidebarModeEnum,
} from '@daffodil/design';

import * as SidebarActions from '../actions/sidebar.actions';
import { computeDeepestSidebarMode } from '../helpers/computeDeepestSidebarMode';
Expand All @@ -45,9 +48,9 @@ export class DaffioSidebarRoutingModeEffects {
map(([action, state]) => {
const mode = computeDeepestSidebarMode(action.payload.routerState.root);
if(state.matches && mode){
return new SidebarActions.SetSidebarMode(mode);
return new SidebarActions.SetSidebarState({ mode, open: mode === DaffSidebarModeEnum.SideFixed ? true : false });
} else {
return new SidebarActions.ResetMode();
return new SidebarActions.SetSidebarState({ mode: 'under', open: false });
}
}),
));
Expand Down
47 changes: 0 additions & 47 deletions apps/daffio/src/app/core/sidebar/effects/sidebar.effects.spec.ts

This file was deleted.

47 changes: 0 additions & 47 deletions apps/daffio/src/app/core/sidebar/effects/sidebar.effects.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Sidebar | Sidebar Reducer', () => {
describe('when SetSidebarState is triggered', () => {
it('sets showSidebar to actions payload', () => {
const stubShowSidebar = true;
const action = new SetSidebarState(stubShowSidebar);
const action = new SetSidebarState({ open: stubShowSidebar });
const result = reducer(initialState, action);
expect(result.showSidebar).toEqual(stubShowSidebar);
});
Expand Down
10 changes: 8 additions & 2 deletions apps/daffio/src/app/core/sidebar/reducers/sidebar.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface State {

export const initialState: State = {
showSidebar: false,
mode: 'push',
mode: 'under',
};

export function reducer(state = initialState, action: SidebarActions): State {
Expand All @@ -23,8 +23,14 @@ export function reducer(state = initialState, action: SidebarActions): State {
return { ...state, showSidebar: false };
case SidebarActionTypes.OpenSidebarAction:
return { ...state, showSidebar: true };
case SidebarActionTypes.SetSidebarStateAction:
case SidebarActionTypes.SetSidebarVisibilityAction:
return { ...state, showSidebar: action.payload };
case SidebarActionTypes.SetSidebarStateAction:
return {
...state,
mode: action.payload?.mode ?? state.mode,
showSidebar: action.payload?.open ?? state.showSidebar,
};
case SidebarActionTypes.SetSidebarModeAction:
return { ...state, mode: action.payload };
case SidebarActionTypes.ResetModeAction:
Expand Down
3 changes: 1 addition & 2 deletions apps/daffio/src/app/core/sidebar/sidebar.state.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { EffectsModule } from '@ngrx/effects';
import { StoreModule } from '@ngrx/store';

import { DaffioSidebarRoutingModeEffects } from './effects/sidebar-routing-mode.effects';
import { DaffioSidebarEffects } from './effects/sidebar.effects';
import { reducers } from './reducers/index';

@NgModule({
imports: [
StoreModule.forFeature('daffioSidebar', reducers),
EffectsModule.forFeature([DaffioSidebarEffects, DaffioSidebarRoutingModeEffects]),
EffectsModule.forFeature([DaffioSidebarRoutingModeEffects]),
],
})
export class DaffioSidebarStateModule { }
2 changes: 1 addition & 1 deletion apps/daffio/src/app/core/template/template.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<daffio-header-container></daffio-header-container>
<daffio-sidebar-viewport-container>
<daffio-header-container daff-sidebar-viewport-nav></daffio-header-container>
<router-outlet></router-outlet>
<daffio-sub-footer></daffio-sub-footer>
<daffio-simple-footer></daffio-simple-footer>
Expand Down
2 changes: 1 addition & 1 deletion apps/daffio/src/app/guides/guides-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const docsRoutes: Routes = [
doc: DocsResolver,
},
data: {
sidebarMode: 'side',
sidebarMode: 'side-fixed',
},
},
];
Expand Down
5 changes: 5 additions & 0 deletions apps/daffio/src/scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
background: var(--daff-base-background);
color: var(--daff-base-text);
}


body {
--daff-sidebar-side-fixed-top-shift: 64px;
}

0 comments on commit 22d293c

Please sign in to comment.