1- import { Component , Inject } from '@angular/core' ;
2- import { FormBuilder , FormGroup , ReactiveFormsModule , Validators } from '@angular/forms' ;
3- import { MatDialogRef , MAT_DIALOG_DATA , MatDialogModule } from '@angular/material/dialog' ;
41import { CommonModule } from '@angular/common' ;
5- import { MatInputModule } from '@angular/material/input ' ;
6- import { MatSelectModule } from '@angular/material/select ' ;
2+ import { Component , computed , inject , signal } from '@angular/core ' ;
3+ import { FormsModule } from '@angular/forms ' ;
74import { MatButtonModule } from '@angular/material/button' ;
5+ import { MatDialogRef , MAT_DIALOG_DATA , MatDialogModule } from '@angular/material/dialog' ;
6+ import { MatRadioModule } from "@angular/material/radio" ;
87
98@Component ( {
109 selector : 'app-split-column-dialog' ,
1110 standalone : true ,
11+ imports : [ CommonModule , MatDialogModule , MatRadioModule , MatButtonModule , FormsModule ] ,
1212 template : `
13- <h2 mat-dialog-title>Split Column</h2>
14- <form [formGroup]="form" class="dialog-form">
15- <mat-form-field class="w-full">
16- <mat-label>Separator character</mat-label>
17- <input matInput formControlName="separator" maxlength="3" placeholder="e.g. /,:,-, etc.">
18- </mat-form-field>
19-
20- <div class="dialog-actions">
21- <button mat-button (click)="cancel()">Cancel</button>
22- <button mat-flat-button color="primary" (click)="confirm()" [disabled]="form.invalid">OK</button>
23- </div>
13+ <h2 mat-dialog-title class="!mb-0 text-slate-700">Split Column: {{data.originalHeader}}</h2>
14+
15+ <mat-dialog-content class="!pt-4">
16+ <div class="text-[10px] uppercase font-bold text-slate-400 mb-2 tracking-wider">Select Delimiter</div>
17+ <mat-radio-group
18+ [ngModel]="selectedDelimiter()"
19+ (ngModelChange)="selectedDelimiter.set($event)"
20+ class="grid grid-cols-2 gap-2 mb-3">
21+ <mat-radio-button value="," class="compact-radio">Comma (,)</mat-radio-button>
22+ <mat-radio-button value="/" class="compact-radio">Slash (/)</mat-radio-button>
23+ <mat-radio-button value="." class="compact-radio">Period (.)</mat-radio-button>
24+ <mat-radio-button value=" " class="compact-radio">Space</mat-radio-button>
25+ <mat-radio-button value="custom" class="compact-radio col-span-2">
26+ <span [class.text-indigo-600]="selectedDelimiter() === 'custom'" class="font-medium">Custom</span>
27+ </mat-radio-button>
28+ </mat-radio-group>
29+
30+ @if (selectedDelimiter() === 'custom') {
31+ <input
32+ class="w-full border-b border-indigo-500 outline-none py-1 mb-4 text-sm bg-transparent"
33+ [ngModel]="customValue()"
34+ (ngModelChange)="customValue.set($event)"
35+ placeholder="e.g. ; or |"
36+ autofocus>
37+ }
38+
39+ <div class="mt-4 p-3 bg-slate-900 rounded-lg shadow-inner overflow-hidden">
40+ <div class="text-[10px] text-indigo-300 uppercase font-black mb-2 tracking-widest">Row 1 Preview</div>
41+ <div class="flex-1">
42+ <div class="text-[9px] text-slate-500 mb-1 uppercase tracking-tighter font-bold">Original: </div>
43+ <div class="px-2 py-1.5 bg-slate-800 rounded text-xs font-mono text-emerald-400 truncate border border-slate-700">
44+ {{data.example }}
45+ </div>
46+ </div>
47+ <div class="flex items-center gap-2">
48+ <div class="flex-1">
49+ <div class="text-[9px] text-slate-500 mb-1 uppercase tracking-tighter font-bold">Part A</div>
50+ <div class="px-2 py-1.5 bg-slate-800 rounded text-xs font-mono text-emerald-400 truncate border border-slate-700">
51+ {{ splitExample().a }}
52+ </div>
53+ </div>
54+
55+ <div class="text-slate-600 font-bold self-end pb-1.5">→</div>
56+
57+ <div class="flex-1">
58+ <div class="text-[9px] text-slate-500 mb-1 uppercase tracking-tighter font-bold">Part B</div>
59+ <div class="px-2 py-1.5 bg-slate-800 rounded text-xs font-mono text-emerald-400 truncate border border-slate-700">
60+ {{ splitExample().b }}
61+ </div>
62+ </div>
63+ </div>
64+ </div>
65+ </mat-dialog-content>
66+
67+ <mat-dialog-actions align="end" class="!pb-4 !px-6">
68+ <button mat-button (click)="cancel()" class="text-slate-500 font-medium">Cancel</button>
69+ <button
70+ mat-flat-button
71+ (click)="confirm()"
72+ [disabled]="!finalDelimiter()"
73+ class="!rounded-md !bg-indigo-600 shadow-md !text-white disabled:!bg-slate-200">
74+ Apply Split
75+ </button>
76+ </mat-dialog-actions>
2477 ` ,
25- imports : [ CommonModule , ReactiveFormsModule , MatDialogModule , MatInputModule , MatSelectModule , MatButtonModule ] ,
2678 styles : [ `
27- .dialog-form { display: flex; flex-direction: column; gap: 1rem; width: 300px; }
28- .dialog-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 1rem; }
29- ` ]
79+ :host { display: block; width: 350px; }
80+ .compact-radio {
81+ @apply border border-slate-200 rounded-md p-1 transition-all hover:bg-slate-50;
82+ }
83+ .mat-mdc-radio-button.mat-mdc-radio-checked {
84+ @apply border-indigo-500 bg-indigo-50/50;
85+ }
86+ ::ng-deep .mdc-label { font-size: 11px !important; }
87+ ` ] ,
3088} )
3189export class SplitColumnDialogComponent {
32- form : FormGroup ;
33-
34- constructor (
35- private fb : FormBuilder ,
36- private dialogRef : MatDialogRef < SplitColumnDialogComponent > ,
37- @Inject ( MAT_DIALOG_DATA ) public data : any
38- ) {
39- this . form = this . fb . group ( {
40- separator : [ data . separator ?? '/' , Validators . required ] ,
41- } ) ;
42- }
90+ private dialogRef = inject ( MatDialogRef < SplitColumnDialogComponent > ) ;
91+ public data = inject ( MAT_DIALOG_DATA ) as { originalHeader : string , example : string } ;
92+
93+ selectedDelimiter = signal < string > ( ',' ) ;
94+ customValue = signal < string > ( '' ) ;
95+
96+ finalDelimiter = computed ( ( ) => {
97+ return this . selectedDelimiter ( ) === 'custom' ? this . customValue ( ) : this . selectedDelimiter ( ) ;
98+ } ) ;
99+
100+ splitExample = computed ( ( ) => {
101+ const sep = this . finalDelimiter ( ) ;
102+ const orig = this . data . example || '' ;
103+
104+ // If no separator is found in the string, show the whole thing in Part A and N/A in Part B
105+ if ( ! sep || ! orig . includes ( sep ) ) {
106+ return { a : orig || '---' , b : 'n/a' } ;
107+ }
108+
109+ const index = orig . indexOf ( sep ) ;
110+ return {
111+ a : orig . substring ( 0 , index ) ,
112+ b : orig . substring ( index + sep . length )
113+ } ;
114+ } ) ;
43115
44116 confirm ( ) {
45- this . dialogRef . close ( this . form . value ) ;
117+ this . dialogRef . close ( {
118+ separator : this . finalDelimiter ( )
119+ } ) ;
46120 }
47121
48122 cancel ( ) {
49123 this . dialogRef . close ( null ) ;
50124 }
51- }
125+ }
0 commit comments