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

Rik/core: dropdownmenu #151

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 21 additions & 15 deletions packages/klighd-core/src/options/components/option-inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,32 @@ interface ChoiceOptionProps extends BaseProps<string> {
availableValuesLabels?: string[];
}

/** This Function calls the onChange method with the current value to an event,
* so if a change has happened we need to handle this */
function handleChoiceEvent(e: Event, props: ChoiceOptionProps): void {
if (e.target == null) {
return
}
if (!(e.target instanceof HTMLSelectElement)) {
return
}
return props.onChange(e.target.value)
}

/** Render a labeled group of radio inputs. */
export function ChoiceOption(props: ChoiceOptionProps): VNode {
// The sprotty jsx function always puts an additional 'props' key around the element, requiring this hack.
props = (props as any as {props: ChoiceOptionProps}).props
return (
<div class-options__input-container="true">
<legend>{props.name}</legend>
{props.availableValues.map((value, i) => (
<label key={value} htmlFor={props.availableValuesLabels?.[i] ?? value} title={props.description ?? props.name}>
<input
class-options__input="true"
type="radio"
title={props.description ?? props.name}
id={props.availableValuesLabels?.[i] ?? value}
checked={props.value === value}
on-change={() => props.onChange(value)}
/>
{props.availableValuesLabels?.[i] ?? value}
</label>
))}
<div class-options__input-container="true">
<legend>{props.name}</legend>
<select onchange={(e: Event) => handleChoiceEvent(e, props)} class-options__selection title={props.description ?? props.name}> {props.name}
{props.availableValues.map((value, i) => (
<option selected={props.value === value}>
{props.availableValuesLabels?.[i] ?? value}
</option>
))}
</select>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/klighd-core/styles/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@

.options__selection {
padding: 4px 6px;

width: 200px;
border: 2px solid var(--kdc-color-sidebar-trigger-background-hover);
border-radius: var(--kdc-border-radius-default);
background: var(--kdc-color-sidebar-trigger-background-active);
Expand Down
Loading