[tym-modals]
tym-modals は,angular の簡易なダイアログやコンテキストメニュー表示用のラッパーです。
動作イメージ (Demo screen)
[https://shinichi-tym.github.io/tym-ng-ws-demo/index.html#tym-modals]
インストール (Installation)
次のコマンド実行します。
npm install tym-modals
目次 (Table of contents)
:
import { TymModalModule } from "tym-modals";
:
@NgModule({
declarations: [ .. ],
imports: [ TymModalModule ],
:
:
<ngx-tym-modals></ngx-tym-modals>
:
※ 画面のどこかに1つ定義します。
:
import { TymModalService } from "tym-modals";
:
constructor(private modal: TymModalService) { }
:
let component_ref = this.modal.open(<Component>, provider);
let component = (component_ref.instance as <Component>);
this.modal.close(); または component_ref.destroy();
:
(または)
:
let component_ref = await this.modal.open(
<Component>,
provider,
true,
(component_ref) => {
let component = (component_ref.instance as <Component>);
});
:
(または)
:
let promise = this.modal.open(..【省略】.., ()=>{});
promise.then(
(component_ref) => {
let component = (component_ref.instance as <Component>);
}
)
:
簡易メッセージダイアログ
簡易なメッセージダイアログを表示します。
import { TymDialogComponent } from "tym-modals";
:
constructor(private modal: TymModalService) {
TymDialogComponent.BUTTONS = [
['ok', 'OK'], ['cancel', 'キャンセル']
];
}
:
open() {
const buttons = {
'ok': (compo: TymDialogComponent) => {
const compoRef = this.modal.getComponentRef(compo);
:
compoRef.destory();
},
'cancel': (compo: TymDialogComponent) => {
const compoRef = this.modal.getComponentRef(compo);
:
compoRef.destory();
}
}
const provider = TymDialogComponent.provider(
'メッセージのタイトル',
['メッセージ1', 'メッセージ2'],
buttons
);
this.modal.open(TymDialogComponent, provider);
}
:

import { TymDialogComponent } from "tym-modals";
import { SafeHtml, DomSanitizer } from "@angular/platform-browser";
:
constructor(
private modal: TymModalService,
private sanitizer: DomSanitizer) { }
trustHtmls(vals: any[]): SafeHtml[] {
let safeHtml: SafeHtml[] = [];
vals.forEach((v) => safeHtml.push(
this.sanitizer.bypassSecurityTrustHtml(v)));
return safeHtml;
}
:
open() {
const safeHtml: SafeHtml[] = this.trustHtmls(
['<b>太字</b>', '<span style="color:red">赤字</span>']);
const provider = TymDialogComponent.provider(
'',
safeHtml as string[]
);
let component_ref = this.modal.open(
TymDialogComponent, provider, false);
let component = (component_ref.instance as <TymDialogComponent>);
}
:

ngx-tym-dialog footer button[name='cancel'] {
background-color: #f00 !important;
&:hover { background-color: #f60 !important; }
&:active { background-color: #f40 !important; }
}
ngx-tym-dialog footer button[name='ok'] {
background-color: #00f !important;
&:hover { background-color: #06f !important; }
&:active { background-color: #04f !important; }
}
※ スタイルシートはグローバルに設定します。

async open() {
:
let componentRef = await this.modal.open(
TymDialogComponent, provider, false, ()=>{});
let component = componentRef.instance as TymDialogComponent;
if (component.actionId == 'ok') { }
if (component.actionId == 'cancel' || component.actionId == '') { }
~ or ~
this.modal.open(TymDialogComponent, provider, false,
(componentRef) => {
const component = componentRef.instance as TymDialogComponent;
})
.then(
(componentRef) => {
let component = componentRef.instance as TymDialogComponent;
if (component.actionId == 'ok') { }
if (component.actionId == 'cancel' || component.actionId == '') { }
}
)
簡易コンテキストメニュー
簡易コンテキストメニューを表示します。
import { TymMenuComponent } from "tym-modals";
:
constructor(private modal: TymModalService) {
TymMenuComponent.MENU_DEFS = {
'file': {
'': 'ファイル',
'copy': 'コピー',
'remove': '削除',
:
},
'folder': {
'': 'フォルダー',
'copy': 'コピー',
'remove': '削除',
:
}, ...
};
}
:
open(event: MouseEvent) {
:
const menu: MenuItems = [
[['file', true],
['copy', true], ['remove', false]],
[['folder', false],
['copy', true], ['remove', false]],
];
const item_action = (gid: string, id: string) => {
:
}
const provider = TymMenuComponent.provider(
menu,
item_action,
event.clientX, event.clientY
);
this.modal.open(TymMenuComponent, provider, false);
:
return false;
}
:

:
this.modal.open(TymMenuComponent, provider, false, ()=>{})
.then(
(componentRef)=>{
const component = componentRef.instance as TymMenuComponent;
console.log(component.groupId, component.itemId);
}
);
:
TymMenuComponent.MENU_DEFS = {
'file': {
'': ['ファイル', 'far fa-file'],
:
},
'folder': {
:
'edit': '編集',
'remove': ['削除', 'menu remove']
}, ...
};
.menu::before {
--sz: 16px;
display: inline-block;
width: var(--sz);
height: var(--sz);
background-image: url(~/tym-menu-icon.png);
background-size: calc(var(--sz) * 8) var(--sz);
position: relative;
top: 2px;
font: var(--sz) monospace;
content: ' ';
white-space: pre-wrap;
}
.copy::before {
background-position-x: calc(var(--sz) * -0);
}
.paste::before {
background-position-x: calc(var(--sz) * -1);
}
.move::before {
background-position-x: calc(var(--sz) * -2);
}
.remove::before {
background-position-x: calc(var(--sz) * -3);
}
iconイメージ ([16px] x [16px * n])


const icons: IconItems = [
['file', 'copy'], ['file','remove']
];
:
const provider = TymMenuComponent.provider(
menu,
item_action,
event.clientX, event.clientY,
icons
);
this.modal.open(TymMenuComponent, provider, false);

ngx-tym-menu {
--bs-sz: 20px !important;
font-family: "Meiryo UI", "MS PGothic", sans-serif !important;
}
.menu::before {
--sz: 20px;
:
※ スタイルシートはグローバルに設定します。
または
this.modal.open(TymDialogComponent, provider, false,
(componentRef) => {
const element = componentRef.location.nativeElement as HTMLElement;
element.style.setProperty('--bs-sz', '20px');
});

ネストダイアログ/コンテキストメニュー
ダイアログ/コンテキストメニューを連続して表示できます。
:
const provider1 = TymDialogComponent.provider(
'メッセージのタイトル .. 長い長い長い長い',
['メッセージ1', 'メッセージ2', 'メッセージ3', 'メッセージ4'],
ok_button, cancel_button
);
this.modal.open(TymDialogComponent, provider1);
const provider2 = TymDialogComponent.provider(
'メッセージのタイトル',
['メッセージ1', 'メッセージ2'],
ok_button, cancel_button
);
this.modal.open(TymDialogComponent, provider2);
:

* supports angular 17, 18 and 19.
ライセンス (License)
The components in tym-ng-ws are released under the MIT license. Read license.
Copyrights belong to shinichi tayama (shinichi.tym).