forked from shoelace-style/shoelace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(filters): Adds switch render (#29)
Included some improvements in the filters general code
- Loading branch information
Showing
7 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
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,30 @@ | ||
import { DEFAULT_MANDATORY_PROPS, FilterAbstractRender } from './filter.abstract.render'; | ||
import { DEFAULT_PROPS_TO_IGNORE, type FilterType, type SwitchFilter } from '../filters.types'; | ||
import { html } from 'lit'; | ||
import type OFilters from '../filters'; | ||
import type OSwitch from '../../switch/switch'; | ||
|
||
export class SwitchFilterRender extends FilterAbstractRender { | ||
type: FilterType = 'switch'; | ||
|
||
render(filtersComponent: OFilters, filter: SwitchFilter) { | ||
const el = filtersComponent.createFilterElement('o-switch', filter) as OSwitch; | ||
el.innerHTML = filter.label ?? ''; | ||
|
||
return html`${el}`; | ||
} | ||
|
||
getValidPropsFromFilterConfig(filter: SwitchFilter) { | ||
const keysToIgnore = [...DEFAULT_PROPS_TO_IGNORE, 'label']; | ||
return this.removeIgnoredKeysFromFilterConfig(keysToIgnore, filter); | ||
} | ||
|
||
isPropMandatory(prop: string) { | ||
// name is mandatory for all filters | ||
return ![...DEFAULT_MANDATORY_PROPS, 'label'].includes(prop); | ||
} | ||
|
||
getElementValue(el: OSwitch) { | ||
return el.checked; | ||
} | ||
} |