Skip to content

Commit

Permalink
feat(formatters): add a fake hyperlink formatter (#630)
Browse files Browse the repository at this point in the history
- Takes any text value and display it as a fake a hyperlink (only styled as an hyperlink)
  • Loading branch information
ghiscoding committed Nov 16, 2020
1 parent 0ee3421 commit 694f0ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fakeHyperlinkFormatter } from '../fakeHyperlinkFormatter';

describe('the Edit Icon Formatter', () => {
it('should return a span with the "fake-hyperlink" class when a value is provided', () => {
const value = 'Custom Value';
const result = fakeHyperlinkFormatter(0, 0, value);
expect(result).toBe('<span class="fake-hyperlink">Custom Value</span>');
});

it('should return an empty string formatter when no value is provided', () => {
const value = null;
const result = fakeHyperlinkFormatter(0, 0, value);
expect(result).toBe('');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Formatter } from '../models/formatter.interface';

export const fakeHyperlinkFormatter: Formatter = (_row: number, _cell: number, value: string) => {
return value ? `<span class="fake-hyperlink">${value}</span>` : '';
};
4 changes: 4 additions & 0 deletions src/app/modules/angular-slickgrid/formatters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { dollarColoredBoldFormatter } from './dollarColoredBoldFormatter';
import { dollarColoredFormatter } from './dollarColoredFormatter';
import { dollarFormatter } from './dollarFormatter';
import { editIconFormatter } from './editIconFormatter';
import { fakeHyperlinkFormatter } from './fakeHyperlinkFormatter';
import { hyperlinkFormatter } from './hyperlinkFormatter';
import { iconFormatter } from './iconFormatter';
import { infoIconFormatter } from './infoIconFormatter';
Expand Down Expand Up @@ -150,6 +151,9 @@ export const Formatters = {
/** Displays a Font-Awesome edit icon (fa-pencil) */
editIcon: editIconFormatter,

/** Takes any text value and display it as a fake a hyperlink (only styled as an hyperlink), this can be used in combo with "onCellClick" event */
fakeHyperlink: fakeHyperlinkFormatter,

/**
* Takes an hyperlink cell value and transforms it into a real hyperlink, given that the value starts with 1 of these (http|ftp|https).
* The structure will be "<a href="hyperlink">hyperlink</a>"
Expand Down

0 comments on commit 694f0ea

Please sign in to comment.