-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d92f12
commit df6208d
Showing
6 changed files
with
89 additions
and
81 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
65 changes: 65 additions & 0 deletions
65
lib/public/components/common/selection/selectionOptions.js
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,65 @@ | ||
/** | ||
* @license | ||
* Copyright CERN and copyright holders of ALICE O2. This software is | ||
* distributed under the terms of the GNU General Public License v3 (GPL | ||
* Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* See http://alice-o2.web.cern.ch/license for full licensing information. | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
import { cleanPrefix } from '../../../utilities/cleanPrefix.js'; | ||
import { filterSelectionOptions } from './filterSelectionOptions.js'; | ||
import { h } from '/js/src/index.js'; | ||
|
||
/** | ||
* Display the options of the given selection model | ||
* | ||
* @param {SelectionModel} selectionModel the selection model | ||
* @param {object} [configuration] eventual configuration | ||
* @param {string} [configuration.filter] if specified, only options with label (or value if no label) including this filter will be displayed | ||
* @param {Component} [configuration.placeholder] if specified, this component will be returned if there is no option to display | ||
* @param {string} [configuration.selectorPrefix] prefix to be used to construct elements selectors | ||
* @param {string[]} [configuration.labelClasses] additional classes applied to label | ||
* @return {Component} filter component | ||
*/ | ||
export const selectionOptions = (selectionModel, configuration) => { | ||
const { filter, placeholder = null, selectorPrefix, labelClasses: additionalLabelClasses = [] } = configuration || {}; | ||
|
||
const options = filterSelectionOptions(selectionModel.options, filter); | ||
|
||
if (options.length === 0) { | ||
return placeholder; | ||
} | ||
|
||
return options.map((option) => { | ||
const selector = option.selector ?? option.value; | ||
|
||
const uniqueSelector = `${cleanPrefix(selectorPrefix)}option-${selector}`; | ||
|
||
const labelClasses = ['form-check-label', 'flex-row', 'g2', ...additionalLabelClasses]; | ||
|
||
return h( | ||
`label.${labelClasses.join('.')}`, | ||
{ key: uniqueSelector }, | ||
[ | ||
h( | ||
`input#${uniqueSelector}`, | ||
{ | ||
id: uniqueSelector, | ||
type: selectionModel.multiple || selectionModel.allowEmpty ? 'checkbox' : 'radio', | ||
name: selectionModel.multiple || selectionModel.allowEmpty | ||
? uniqueSelector | ||
: `${cleanPrefix(selectorPrefix)}option-group`, | ||
checked: selectionModel.isSelected(option), | ||
onchange: () => selectionModel.isSelected(option) ? selectionModel.deselect(option) : selectionModel.select(option), | ||
}, | ||
), | ||
option.label || option.value, | ||
], | ||
); | ||
}); | ||
}; |
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