-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(formatters): add Bootstrap Dropdown Formatter
- add this missing Formatter that was available in Angular-Slickgrid
- Loading branch information
1 parent
1d71d59
commit 5ba9423
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/common/src/formatters/__tests__/bsDropdownFormatter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Column, SlickGrid } from '../../interfaces'; | ||
import { bsDropdownFormatter } from '../bsDropdownFormatter'; | ||
|
||
describe('the Bootstrap dropdown Formatter', () => { | ||
it('should throw an error when omitting to pass "propertyNames" to "params"', () => { | ||
expect(() => bsDropdownFormatter(0, 0, 'anything', {} as Column, {}, {} as SlickGrid)) | ||
.toThrowError('You must provide the "label" or "formatterLabel" via the generic "params"'); | ||
}); | ||
|
||
it('should always return a dropdown template with the label provided in the "label" property from "params"', () => { | ||
const input = null; | ||
const label = 'Action'; | ||
const row = 0; | ||
const cell = 0; | ||
const result = bsDropdownFormatter(row, cell, input, { field: 'user', params: { label } } as Column, {}, {} as SlickGrid); | ||
|
||
expect(result).toBe(`<div id="myDrop-r${row}-c${cell}" class="dropdown pointer"> | ||
<a class="dropdown-toggle"> | ||
${label} | ||
<span class="caret"></span> | ||
</a> | ||
</div>`); | ||
}); | ||
|
||
it('should always return a a dropdown template with the label provided in the "formatterLabel" property from "params"', () => { | ||
const input = null; | ||
const label = 'Action'; | ||
const row = 0; | ||
const cell = 0; | ||
const result = bsDropdownFormatter(row, cell, input, { field: 'user', params: { label } } as Column, {}, {} as SlickGrid); | ||
|
||
expect(result).toBe(`<div id="myDrop-r${row}-c${cell}" class="dropdown pointer"> | ||
<a class="dropdown-toggle"> | ||
${label} | ||
<span class="caret"></span> | ||
</a> | ||
</div>`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Formatter } from '../interfaces/formatter.interface'; | ||
|
||
/** A simple Bootstrap Dropdown Formatter which requires a Formatter Label */ | ||
export const bsDropdownFormatter: Formatter = (row, cell, _val, columnDef) => { | ||
const columnParams = columnDef && columnDef.params || {}; | ||
const label = columnParams.label || columnParams.formatterLabel; | ||
|
||
if (!label) { | ||
throw new Error(`You must provide the "label" or "formatterLabel" via the generic "params" options (e.g.: { formatter: Formatters.bsDropdown, params: { formatterLabel: 'Label' }}`); | ||
} | ||
|
||
return `<div id="myDrop-r${row}-c${cell}" class="dropdown pointer"> | ||
<a class="dropdown-toggle"> | ||
${label} | ||
<span class="caret"></span> | ||
</a> | ||
</div>`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters