Skip to content

Commit

Permalink
Merge pull request #12 from gabriel-gn/feature/sidebar-development
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-gn authored Sep 24, 2022
2 parents c30bf11 + eaa669f commit 2822a42
Show file tree
Hide file tree
Showing 21 changed files with 6,059 additions and 4,186 deletions.
2 changes: 1 addition & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export const parameters = {
},
},
docs: { inlineStories: true },
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Angular Version | NPM Version |
|-----------------|-------------|
| 13.2.3 | 13.0.11 |
| 13.2.3 | 13.0.15 |
| < 13.0.0 | 0.0.77 |

## Reference
Expand Down
4 changes: 4 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"styles": [
"src/styles/base_css.scss",
"src/styles/base.scss"
],
"scripts": [
"node_modules/popper.js/dist/umd/popper.js",
"node_modules/bootstrap/dist/js/bootstrap.js"
]
},
"configurations": {
Expand Down
1,247 changes: 944 additions & 303 deletions documentation.json

Large diffs are not rendered by default.

8,277 changes: 4,413 additions & 3,864 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mprisma/components",
"version": "13.0.14",
"version": "13.0.15",
"repository": {
"type": "git",
"url": "https://github.com/gabriel-gn/prisma-components.git"
Expand Down Expand Up @@ -32,9 +32,9 @@
"@angular/platform-browser": "^13.2.3",
"@angular/platform-browser-dynamic": "^13.2.3",
"@angular/router": "^13.2.3",
"@storybook/addon-docs": "^6.4.19",
"@storybook/addons": "^6.4.19",
"@storybook/components": "^6.4.19",
"@storybook/addon-docs": "^6.5.12",
"@storybook/addons": "^6.5.12",
"@storybook/components": "^6.5.12",
"@types/lodash": "^4.14.178",
"angular2-hotkeys": "^13.1.0",
"autoprefixer": "^10.3.7",
Expand Down Expand Up @@ -67,12 +67,12 @@
"@angular/elements": "^13.2.3",
"@babel/core": "^7.16.12",
"@compodoc/compodoc": "^1.1.18",
"@storybook/addon-actions": "^6.4.19",
"@storybook/addon-essentials": "^6.4.19",
"@storybook/addon-links": "^6.4.19",
"@storybook/angular": "^6.4.19",
"@storybook/builder-webpack5": "^6.4.19",
"@storybook/manager-webpack5": "^6.4.19",
"@storybook/addon-actions": "^6.5.12",
"@storybook/addon-essentials": "^6.5.12",
"@storybook/addon-links": "^6.5.12",
"@storybook/angular": "^6.5.12",
"@storybook/builder-webpack5": "^6.5.12",
"@storybook/manager-webpack5": "^6.5.12",
"@types/jasmine": "^3.10.0",
"@types/node": "^12.11.1",
"@webcomponents/custom-elements": "^1.5.0",
Expand Down
7 changes: 4 additions & 3 deletions scripts/create-component.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ echo "$ngscript"
ngscriptoutput=$(eval "$ngscript")
echo "$ngscriptoutput"

ngscript="ng generate component $componentPath --project=lib"
ngscript="ng generate component $componentPath --project=lib --export=true"
echo "$ngscript"
ngscriptoutput=$(eval "$ngscript")
echo "$ngscriptoutput"

# Copia os stories para as pastas que precisa
cp ./stories/default.mdx "${filenamePath}.stories.mdx"
cp ./stories/default.ts "${filenamePath}.stories.ts"
scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cp ${scriptDir}/stories/default.mdx "${filenamePath}.stories.mdx"
cp ${scriptDir}/stories/default.ts "${filenamePath}.stories.ts"
echo "Stories created"

# altera os stories default com os valores novos de acordo com o componente criado
Expand Down
6 changes: 2 additions & 4 deletions scripts/stories/default.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {moduleMetadata} from "@storybook/angular";
import {XXXModule} from "./XXXName.module";
import SourceStory from '!!raw-loader!./XXXName.stories';
import {
Template as storyTemplate,
defaultArgs,
DefaultXXXTitle,
} from "./XXXName.stories";
Expand Down Expand Up @@ -46,10 +47,7 @@ Descrição do componente XXXTitle padrão

Deve ser usado da seguinte forma:

```
<pm-XXXName>
</pm-XXXName>
```
<Source code={storyTemplate.template} language='html' />

<Canvas>
<Story name='Default' story={DefaultXXXTitle} />
Expand Down
10 changes: 10 additions & 0 deletions src/components/layout/sidebar/sidebar-content/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface SidebarItem {
label: string; // should be unique
iconClass: string;
path?: string | any; // router link
queryParams?: any; // queryParams router link
action?: () => void; // action to trigger
translate?: string; // if provided, use transloco pipe
badge?: any; // badge to be displayed, if not observable, turns into string
children?: SidebarItem[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<div class="app-sidebar-content"
[ngStyle]="{'min-width': minWidth}"
>
<ul class="sidebar-nav">
<ng-container *ngFor="let entry of sidebarEntries">
<ng-container *ngTemplateOutlet="entryChecker; context: {$implicit: entry, prefixId: getIdForEntry(entry)}"></ng-container>
</ng-container>
</ul>
</div>

<ng-template #entryChecker let-entry let-prefixId="prefixId">
<li routerLinkActive="active"
[routerLinkActiveOptions]="{exact: true}"
[ngClass]="{'active': currentExpandedSession.startsWith(prefixId)}"
>
<ng-container [ngSwitch]="!!entry?.children">
<!--Se for um item sem submenus-->
<ng-container *ngSwitchCase="false">
<ng-container *ngTemplateOutlet="noSubmenuEntry; context: {$implicit: entry}"></ng-container>
</ng-container>

<!--Se for um item com submenus-->
<ng-container *ngSwitchCase="true">
<ng-container *ngTemplateOutlet="submenuEntry; context: {$implicit: entry, prefixId: prefixId}"></ng-container>
</ng-container>
</ng-container>
</li>
</ng-template>

<ng-template #noSubmenuEntry let-entry>
<a (click)="executeAction($event, entry)"
[routerLink]="entry.path"
[queryParams]="entry?.queryParams"
>
<ng-container *ngTemplateOutlet="entryContent; context: {$implicit: entry}"></ng-container>
</a>
</ng-template>

<ng-template #submenuEntry let-entry let-prefixId="prefixId" let-isSub="isSub">
<a [ngClass]="{'sub': isSub}"
[attr.data-bs-toggle]="'collapse'"
[attr.data-bs-target]="'#collapse' + prefixId"
>
<ng-container *ngTemplateOutlet="entryContent; context: {$implicit: entry}"></ng-container>
</a>

<!--Exibe os itens do submenu-->
<ng-container *ngTemplateOutlet="childEntryContent; context: {$implicit: entry, prefixId: prefixId}"></ng-container>
</ng-template>

<ng-template #entryContent let-entry>
<i class="{{ entry.iconClass }}"></i>
<p class="ms-2">
{{entry.label}}
<b *ngIf="entry?.children" class="caret ms-3"></b>
</p>
</ng-template>

<ng-template #childEntryContent let-entry let-prefixId="prefixId">
<div *ngIf="entry?.children"
[attr.id]="'collapse' + prefixId"
class="{{currentExpandedSession.startsWith(getIdForEntry(entry, prefixId)) ? 'show' : 'collapse'}}"
>
<div class="d-flex">
<div class="aux-bar"></div>
<ul class="sidebar-nav">
<ng-container *ngFor="let childEntry of entry.children">
<li routerLinkActive="active"
[routerLinkActiveOptions]="{exact: true}"
(isActiveChange)="keepSessionExpanded($event, getIdForEntry(entry, prefixId))"
[ngClass]="{'active': currentExpandedSession.startsWith(getIdForEntry(childEntry, prefixId))}"
>
<ng-container [ngSwitch]="!!childEntry?.children">
<!--Se for um item sem submenus-->
<ng-container *ngSwitchCase="false">
<a class="sub"
(click)="executeAction($event, childEntry)"
[routerLink]="childEntry.path"
[queryParams]="childEntry?.queryParams"
>
<ng-container *ngTemplateOutlet="entryContent; context: {$implicit: childEntry}"></ng-container>
</a>
</ng-container>

<!--Se for um item com submenus-->
<ng-container *ngSwitchCase="true">
<ng-container *ngTemplateOutlet="submenuEntry; context: {$implicit: childEntry, prefixId: getIdForEntry(childEntry, prefixId), isSub: true}"></ng-container>
</ng-container>
</ng-container>
</li>
</ng-container>
</ul>
</div>
</div>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
.app-sidebar-content {
$main-link-margin-top: 1.2em;
$sub-link-margin-top: 0.6em;

padding: 0 1em 1em 0.5em;
list-style: none !important;

.sidebar-nav {
padding: 0px;
display: block;
transition: 0.3s;
list-style: none !important;

li {
cursor: pointer;

* {
color: var(--color-gray-dark);

&:focus-visible {
outline: none;
}

}

a {
display: flex;
justify-content: center;
align-items: center;
padding: 0.5em 1em;
border-radius: 1em;

text-decoration: none;
font-size: 0.8em;
font-weight: 500;

&.expanded {
background-color: rgba(var(--color-gray-dark-rgb), 0.15);
}

&:hover {
background-color: rgba(var(--color-gray-dark-rgb), 0.15);

* {
color: var(--color-primary) !important;
}
}
}

&.active {
> a:first-child {
background-color: rgba(var(--color-primary-rgb), 0.2);

* {
color: var(--color-primary) !important;
}
}
}
}

a {
&:first-child {
margin-top: $main-link-margin-top;
}

&.sub {
margin-top: $sub-link-margin-top;
}
}

.collapse,
.collapsing {
.nav {
margin-top: 0;
}
}

p {
margin: 0;
white-space: nowrap;
display: flex;
justify-content: space-between;
width: 100%;

> {
align-self: center;
}
}

a:not(.sub) {
p {
font-size: 14px;
font-weight: 700;
text-transform: uppercase;
}
}

i {
font-size: 24px;
float: left;
line-height: 30px;
width: 34px;
text-align: center;
color: #ffffff;
position: relative;
}

ul {
margin: 0px;
width: 100%;
}

div {
.aux-bar {
width: 2px;
min-width: 2px;
border-radius: 50px;
margin: $sub-link-margin-top $sub-link-margin-top 0 $sub-link-margin-top;
background-color: rgba(var(--color-gray-dark-rgb), 0.3);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { SidebarContentComponent } from './sidebar-content.component';

describe('SidebarContentComponent', () => {
let component: SidebarContentComponent;
let fixture: ComponentFixture<SidebarContentComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SidebarContentComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(SidebarContentComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading

1 comment on commit 2822a42

@vercel
Copy link

@vercel vercel bot commented on 2822a42 Sep 24, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.