Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace className() method with addClassName() #2548

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/TaskFieldRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ export class TaskFieldRenderer {
}

/**
* @returns the component's CSS class describing what this component is (priority, due date etc.).
* Adds the component's CSS class describing what this component is (priority, due date etc.) to an HTML element.
*
* @param element where the class shall be added.
*
* @param component of the task.
*/
public className(component: TaskLayoutComponent) {
return this.data[component].className;
public addClassName(element: HTMLElement, component: TaskLayoutComponent) {
const componentClass = this.data[component].className;
element.classList.add(...[componentClass]);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/TaskLineRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ export class TaskLineRenderer {
this.addInternalClasses(component, internalSpan);

// Add the component's CSS class describing what this component is (priority, due date etc.)
const componentClass = fieldRenderer.className(component);
span.classList.add(...[componentClass]);
fieldRenderer.addClassName(span, component);

// Add the component's attribute ('priority-medium', 'due-past-1d' etc.)
fieldRenderer.addDataAttribute(span, task, component);
Expand Down
9 changes: 9 additions & 0 deletions tests/TaskFieldRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('Field Layouts Container tests', () => {

expect(span).toHaveDataAttributes('taskPriority: medium');
});

it('should not add any data attributes for a missing component', () => {
const task = new TaskBuilder().build();
const span = document.createElement('span');
Expand All @@ -44,6 +45,14 @@ describe('Field Layouts Container tests', () => {

expect(span).toHaveDataAttributes('');
});

it('should add a class name for a component', () => {
const span = document.createElement('span');

fieldRenderer.addClassName(span, 'startDate');

expect(span.classList.toString()).toEqual('task-start');
});
});

describe('Field Layout Detail tests', () => {
Expand Down