Skip to content

Commit

Permalink
Merge pull request #10 from nontangent/feat/rename-prop-names
Browse files Browse the repository at this point in the history
Feat/rename prop names
  • Loading branch information
nontangent authored Sep 10, 2022
2 parents 3230b3d + 0d9439a commit 88051f8
Show file tree
Hide file tree
Showing 41 changed files with 276 additions and 171 deletions.
7 changes: 3 additions & 4 deletions libs/common/src/models/action-item.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export interface ActionItem<ID = number | string> {
id: ID;
import { Action } from "./action";

export interface ActionItem<T = any> extends Action<T> {
name: string;
icon?: string;
color?: string;
}

export type ActionItemEvent<T = any> = [ActionItem, T];
4 changes: 4 additions & 0 deletions libs/common/src/models/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Action<T = any> {
id: string;
payload?: T;
}
1 change: 1 addition & 0 deletions libs/common/src/models/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './action';
export * from './action-item';
export * from './menu-item';
16 changes: 1 addition & 15 deletions libs/common/src/stores/entity/entity.store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ComponentStore } from '@ngrx/component-store';
import { LoadingService } from '@ng-atomic/common/services/loading';
import { SnackBarService } from '@ng-atomic/common/services/snack-bar';
import { Observable } from 'rxjs';
import { filter, switchMap, tap } from 'rxjs/operators';

Expand Down Expand Up @@ -45,28 +43,16 @@ export abstract class EntityStore<S extends EntityState<Entity>, Entity> extends

createEntity(value: Partial<Entity>) {
const entity: Entity = ({...this.entity, ...value});

this.loading.setKey('[pages/stores/pages/store] Create Store');

return tryCatch(this._createEntity(entity))
.catch(error => (console.error(error), this.snackBar.openSnackBar('作成に失敗しました。')))
.finally(() => this.loading.removeKey('[pages/stores/pages/store] Create Store'));
return tryCatch(this._createEntity(entity));
}

updateEntity(value: Partial<Entity>) {
const entity: Entity = ({...this.entity, ...value});

this.loading.setKey('[pages/stores/pages/store] Create Store');
return this._updateEntity(entity)
.catch(error => (console.error(error), this.snackBar.openSnackBar('更新に失敗しました。')))
.finally(() => this.loading.removeKey('[pages/stores/pages/store] Create Store'));
}

abstract _getEntity(idOrParams: string): Observable<Entity>;
abstract _createEntity(entity: Entity): Promise<Entity>;
abstract _updateEntity(entity: Entity): Promise<void>;

abstract get loading(): LoadingService;
abstract get snackBar(): SnackBarService;

}
4 changes: 2 additions & 2 deletions libs/common/src/utils/mat-dayjs-date/dayjs-date.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class DayjsDateAdapter extends DateAdapter<Dayjs> {
}

// TODO: Implement
setLocale(locale: string) {
override setLocale(locale: string) {
super.setLocale(locale);

const dayJsLocaleData = this.dayJs().localeData();
Expand Down Expand Up @@ -180,7 +180,7 @@ export class DayjsDateAdapter extends DateAdapter<Dayjs> {
* @returns The deserialized date object, either a valid date, null if the value can be
* deserialized into a null date (e.g. the empty string), or an invalid date.
*/
deserialize(value: any): Dayjs | null {
override deserialize(value: any): Dayjs | null {
let date;
if (value instanceof Date) {
date = this.dayJs(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<ng-container [ngSwitch]="actionItems.length">
<ng-container [ngSwitch]="items?.length ?? 0">
<ng-container *ngSwitchCase="0"></ng-container>
<ng-container *ngSwitchCase="1">
<button mat-icon-button (click)="actionItemClick.emit([actionItems[0]])">
<mat-icon>{{ actionItems[0]?.icon }}</mat-icon>
<button mat-icon-button (click)="action.emit(items[0])">
<mat-icon>{{ items[0]?.icon }}</mat-icon>
</button>
</ng-container>
<ng-container *ngSwitchDefault>
<button mat-icon-button [matMenuTriggerFor]="menu" *ngIf="actionItems.length">
<button mat-icon-button [matMenuTriggerFor]="menu" *ngIf="items.length">
<mat-icon>menu</mat-icon>
</button>
</ng-container>
</ng-container>

<mat-menu #menu="matMenu">
<button
*ngFor="let actionItem of actionItems"
*ngFor="let item of items"
mat-menu-item
(click)="actionItemClick.emit([actionItem])"
>{{ actionItem.name }}</button>
(click)="action.emit(item)"
>{{ item.name }}</button>
</mat-menu>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { ActionItem } from '@ng-atomic/common/models';
import { Action, ActionItem } from '@ng-atomic/common/models';

@Component({
selector: 'atoms-smart-menu-button',
Expand All @@ -9,8 +9,8 @@ import { ActionItem } from '@ng-atomic/common/models';
})
export class SmartMenuButtonAtom {
@Input()
actionItems: ActionItem[] = [];
items: ActionItem[] = [];

@Output()
actionItemClick = new EventEmitter<ActionItem>();
action = new EventEmitter<Action>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export default {
} as Meta;

const Template: Story = (args) => ({
props: {
...args,
...buildActions(['actionItemClick']),
},
props: {...args, ...buildActions(['action']) },
moduleMetadata: {
imports: [
BrowserModule,
Expand All @@ -25,7 +22,7 @@ const Template: Story = (args) => ({

export const Default = Template.bind({});
Default.args = {
actionItems: [
items: [
{
id: 'test-action-01',
name: 'テスト01',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<th mat-header-cell *matHeaderCellDef>操作</th>
<td mat-cell *matCellDef="let item">
<atoms-smart-menu-button
[actionItems]="actionItems"
(actionItemClick)="actionItemClick.emit([$event[0], item])"
[items]="items"
(action)="action.emit({id: $event.id, payload: item})"
></atoms-smart-menu-button>
</td>
</ng-container>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CdkCellDef, CdkColumnDef, CdkHeaderCellDef, CdkTable, TextColumnOptions, TEXT_COLUMN_OPTIONS } from '@angular/cdk/table';
import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, Optional, Output, ViewChild, ViewEncapsulation } from '@angular/core';
import { ActionItem } from '@ng-atomic/common/models';
import { Action, ActionItem } from '@ng-atomic/common/models';

@Component({
selector: 'molecules-actions-column',
Expand All @@ -21,11 +21,10 @@ export class ActionsColumnMolecule<T> {
_name!: string;

@Input()
actionItems: ActionItem[] = [];

items: ActionItem[] = [];

@Output()
actionItemClick = new EventEmitter<[ActionItem, T]>();
action = new EventEmitter<Action>();

@ViewChild(CdkColumnDef, {static: true})
columnDef!: CdkColumnDef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export default {


const Template: Story = (args) => ({
props: {...args, ...buildActions(['actionItemClick'])},
props: {...args, ...buildActions(['action'])},
template: `
<table mat-table [dataSource]="items" matSort matSortDisableClear matSortDirection="desc">
<molecules-actions-column
*ngFor="let name of displayedColumns"
[name]="name"
[actionItems]="actionItems"
[items]="items"
(action)="action($event)"
></molecules-actions-column>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let item; columns: displayedColumns;"></tr>
Expand All @@ -32,15 +33,14 @@ const Template: Story = (args) => ({
});

enum ActionId {
TEST1,
TEST2,
TEST1 = 'test 1',
TEST2 = 'test 2',
}

export const Default = Template.bind({});
Default.args = {
items: [{id: '01'}, {id: '02'}, {id: '03'}],
displayedColumns: ['__actions'],
actionItems: [
items: [
{id: ActionId.TEST1, name: 'TEST 1'},
{id: ActionId.TEST2, name: 'TEST 2'},
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<mat-form-field [appearance]="appearance">
<mat-form-field [appearance]="appearance" [floatLabel]="floatLabel">
<mat-label>{{ label }}</mat-label>
<mat-chip-list #chipList>
<mat-chip *ngFor="let chip of chipsManager.chips" (removed)="remove(chip)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class ChipsInputFieldMolecule {
@Input()
control = new FormControl<string>('');

@Input()
floatLabel = 'auto';

@Input()
label = 'label';

Expand Down
18 changes: 18 additions & 0 deletions libs/components/src/molecules/header/header.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HeaderMolecule } from './header.molecule';



@NgModule({
declarations: [
HeaderMolecule
],
imports: [
CommonModule
],
exports: [
HeaderMolecule
]
})
export class HeaderModule { }
2 changes: 2 additions & 0 deletions libs/components/src/molecules/header/header.molecule.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<span class="title">{{ title ?? '' }}</span>
<span class="description">{{ description ?? '' }}</span>
20 changes: 20 additions & 0 deletions libs/components/src/molecules/header/header.molecule.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@use 'scoped-var/strict' as * with ($host: 'header');
@use 'atomic/molecule' as *;

:host {
@include molecule($host);
}

:host {
display: flex;
flex-direction: row;
justify-content: center;
align-items: flex-end;

.description {
line-height: 1em;
font-size: 12px;
margin-bottom: 8px;
margin-left: 4px;
}
}
25 changes: 25 additions & 0 deletions libs/components/src/molecules/header/header.molecule.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { HeaderMolecule } from './header.molecule';

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

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

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
17 changes: 17 additions & 0 deletions libs/components/src/molecules/header/header.molecule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, ChangeDetectionStrategy, Input } from '@angular/core';

@Component({
selector: 'molecules-header',
templateUrl: './header.molecule.html',
styleUrls: ['./header.molecule.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class HeaderMolecule {

@Input()
title = 'title';

@Input()
description?: string;

}
26 changes: 26 additions & 0 deletions libs/components/src/molecules/header/header.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { Meta, Story } from '@storybook/angular';
import { action } from '@storybook/addon-actions';
import { HeaderMolecule, HeaderModule } from '.';

export default {
title: 'Molecules/Header',
component: HeaderMolecule,
} as Meta;

const ACTIONS = {
// eventEmitterName: action('eventEmitterName'),
};


const Template: Story = (args) => ({
props: {...args, ...ACTIONS},
moduleMetadata: {
imports: [
HeaderModule,
]
}
});

export const Default = Template.bind({});
Default.args = {};
2 changes: 2 additions & 0 deletions libs/components/src/molecules/header/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { HeaderMolecule } from './header.molecule';
export { HeaderModule } from './header.module';
11 changes: 11 additions & 0 deletions libs/components/src/molecules/header/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/libs/components",
"lib": {
"entryFile": "index.ts",
"styleIncludePaths": [
"../../../../node_modules",
"../../styles"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<ng-container *ngFor="let item of actionItems; trackBy: trackById">
<button mat-raised-button color="primary" (click)="actionItemClick.emit([item])">{{ item?.name }}</button>
<ng-container *ngFor="let item of items; trackBy: trackById">
<button mat-raised-button color="primary" (click)="action.emit(item)">{{ item?.name }}</button>
</ng-container>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { ActionItem } from '@ng-atomic/common/models';
import { Action, ActionItem } from '@ng-atomic/common/models';

@Component({
selector: 'organisms-action-buttons-section',
Expand All @@ -10,10 +10,10 @@ import { ActionItem } from '@ng-atomic/common/models';
})
export class ActionButtonsSectionOrganism {
@Input()
actionItems: ActionItem[] = [];
items: ActionItem[] = [];

@Output()
actionItemClick = new EventEmitter<[ActionItem]>();
action = new EventEmitter<Action>();

trackById = (item: ActionItem) => item.id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</div>
<div>
<atoms-smart-menu-button
[actionItems]="actionItems"
(actionItemClick)="actionItemClick.emit($event)"
[items]="items"
(action)="action.emit($event)"
></atoms-smart-menu-button>
</div>
</mat-toolbar>
Loading

0 comments on commit 88051f8

Please sign in to comment.