Skip to content

Commit

Permalink
Modify the badge view to enable passing all options via config, in ad…
Browse files Browse the repository at this point in the history
…dition to data
  • Loading branch information
lahmatiy committed Feb 28, 2024
1 parent e9882fb commit d836062
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## next

- Added basic support for `TypedArray`s and `Set` values in `struct`, `signature` and `table` views
- Modified the badge view to enable passing all options via config, in addition to data
- Fixed displaying supported syntaxes in view's showcase for `source` view
- Exposed used CodeMirror for extension purposes via a static property `CodeMirror` of `QueryEditor` and `ViewEditor`, e.g. `discovery.view.QueryEditor.CodeMirror.defineMode('my-mode', ...)`

Expand Down
27 changes: 20 additions & 7 deletions src/views/text/badges.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,39 @@ function maybeFix(el, type, value) {
}

export default function(host) {
const prepareProps = host.queryFn(`{
color,
textColor,
darkColor,
darkTextColor,
text: is (string or number or boolean) ?: text,
content: #.content,
href,
external,
prefix,
postfix,
hint
} | entries().({
key,
value: #[key] != undefined ? #[key] : value
}).fromEntries()`);

function render(el, config, data, context) {
const { content } = config;
let {
const {
color,
textColor,
darkColor,
darkTextColor,
text,
content,
href,
external,
prefix,
postfix,
hint
} = data || {};
} = prepareProps(data, config);
let render;

if (typeof data === 'string' || typeof data === 'number' || typeof data === 'boolean') {
text = data;
}

if (color) {
el.style.setProperty('--discovery-view-badge-color', color);
}
Expand Down

0 comments on commit d836062

Please sign in to comment.