Skip to content

Commit

Permalink
added id to all components
Browse files Browse the repository at this point in the history
  • Loading branch information
ATHULKNAIR committed Jun 5, 2023
1 parent 956e057 commit f7dc08d
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/medblocks/boolean/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class MbCheckBox extends EhrElement {
@property({ type: Boolean }) data: boolean | undefined = undefined;
@property({ type: Boolean, reflect: true }) disabled: boolean = false;
@property({ type: Boolean, reflect: true }) required: boolean = false;
@property({ type: String, reflect: true }) id: string = 'checkbox';

_handleChange(e: CustomEvent) {
const checkbox = e.target as SlCheckbox;
Expand All @@ -27,6 +28,7 @@ export default class MbCheckBox extends EhrElement {
</div>`;
}
return html`<sl-checkbox
id=${this.id}
?required=${this.required}
?disabled=${this.disabled}
?checked=${this.data}
Expand Down
7 changes: 4 additions & 3 deletions src/medblocks/codedtext/abstractSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export default abstract class MbSearchAbstract extends CodedTextElement {

@property({ type: String, reflect: true }) placeholder = 'Type to search';

@property({ type: String, reflect: true }) id = 'search';

@property({ type: String }) textFallbackLabel = 'Add custom';

@property({ type: String }) filtersLabel = 'Filters';
Expand Down Expand Up @@ -251,9 +253,7 @@ export default abstract class MbSearchAbstract extends CodedTextElement {
_textFallback() {
return html`<sl-divider></sl-divider>
<sl-menu-item .value=${{ text: this.searchTerm }}
><span
slot="suffix"
style="font-size: small;"
><span slot="suffix" style="font-size: small;"
>${this.textFallbackLabel}</span
>${this.searchTerm}</sl-menu-item
>`;
Expand Down Expand Up @@ -368,6 +368,7 @@ export default abstract class MbSearchAbstract extends CodedTextElement {
}}
>
<sl-input
id=${this.id}
class=${classMap({ pointer: this._hasValue })}
slot="trigger"
?required=${this.required}
Expand Down
2 changes: 2 additions & 0 deletions src/medblocks/codedtext/buttons-multiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class CodedTextButtons extends CodedTextElement {
@property({ type: Boolean, reflect: true }) required: boolean = false;
@property({ type: Boolean, reflect: true }) disabled: boolean = false;
@property({ type: Boolean, reflect: true }) multiple: boolean = true;
@property({ type: String, reflect: true }) id: string='buttons-multiple';
/** @ignore */
static styles = css`
.buttons {
Expand Down Expand Up @@ -106,6 +107,7 @@ export default class CodedTextButtons extends CodedTextElement {
${this._options.map(
option =>
html` <sl-button
id=${`${this.id}-${option.label}`}
.size=${this.variant === 'small' ? 'small' : 'medium'}
?disabled=${this.disabled}
@click=${() => this._handleInput(option)}
Expand Down
3 changes: 2 additions & 1 deletion src/medblocks/codedtext/buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { property } from 'lit-element';
export default class CodedTextButtons extends CodedTextElement {
@property({ type: Boolean, reflect: true }) required: boolean = false;
@property({ type: Boolean, reflect: true }) disabled: boolean = false;
@property({ type: String, reflect: true }) id: string ='buttons';
/** @ignore */
static styles = css`
.buttons {
Expand Down Expand Up @@ -91,7 +92,7 @@ export default class CodedTextButtons extends CodedTextElement {
${this._options.map(
option =>
html` <sl-button
id=${option.value}
id=${`${this.id}-${option.label}`}
.size=${this.variant === 'small' ? 'small' : 'medium'}
?disabled=${this.disabled}
@click=${() => this._handleInput(option)}
Expand Down
7 changes: 5 additions & 2 deletions src/medblocks/codedtext/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default class MbSelect extends CodedTextElement {
@property({ type: String }) terminology: string;
@property({ type: Object }) data: CodedText | CodedText[] | undefined;

@property({ type: String, reflect: true }) placeholder: string;
@property({ type: String, reflect: true }) placeholder: string = 'Please select';

@property({ type: String, reflect: true }) id: string = 'select';

@property({ type: Boolean, reflect: true }) multiple: boolean = false;

Expand Down Expand Up @@ -115,6 +117,7 @@ export default class MbSelect extends CodedTextElement {
}
return html`
<sl-select
id=${this.id}
.size=${this.variant === 'small' ? 'small' : 'medium'}
.disabled=${this.disabled}
clearable
Expand All @@ -132,7 +135,7 @@ export default class MbSelect extends CodedTextElement {
>
${this._options.map(
option =>
html`<sl-menu-item .value=${option.value}>
html`<sl-menu-item .value=${option.value} id=${`${this.id}-${option.value}`}>
${option.label}
</sl-menu-item>`
)}
Expand Down
10 changes: 8 additions & 2 deletions src/medblocks/count/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default class MbCount extends EhrElement {

@property({ type: String }) label: string = '';

@property({ type: String }) placeholder: string = '';

@property({ type: String }) id: string = 'count';

@property({ type: Boolean, reflect: true }) required: boolean = false;

@property({ type: Boolean, reflect: true }) disabled: boolean;
Expand Down Expand Up @@ -42,11 +46,12 @@ export default class MbCount extends EhrElement {
if (this.variant === 'text') {
return html`<div>
${this._label()}
<p>${this.data>=Number(this.min || 0) ? this.data : '-'}</p>
<p>${this.data >= Number(this.min || 0) ? this.data : '-'}</p>
</div>`;
}
return html`
<sl-input
id=${this.id}
.disabled=${this.disabled}
type="number"
.size=${this.variant === 'small' ? 'small' : 'medium'}
Expand All @@ -55,7 +60,8 @@ export default class MbCount extends EhrElement {
?required=${this.required}
label=${this.label}
@sl-input=${this.handleInput}
value=${this.data>=Number(this.min || 0) ? this.data : ''}
value=${this.data >= Number(this.min || 0) ? this.data : ''}
placeholder=${this.placeholder}
></sl-input>
`;
}
Expand Down
6 changes: 5 additions & 1 deletion src/medblocks/datetime/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class MbDateTime extends EhrElement {
width: unset;
}
.placeholder::part(input) {
color: rgb(var(--sl-input-placeholder-color));
color: var(--sl-input-placeholder-color);
}
`;
@property({ type: String }) data: string | undefined;
Expand All @@ -31,6 +31,9 @@ export default class MbDateTime extends EhrElement {

@property({ type: Boolean, reflect: true }) disabled: boolean;

@property({ type: Boolean, reflect: true }) id: string = 'date';


@event('mb-input') _mbInput: EventEmitter<any>;

handleInput(e: CustomEvent) {
Expand Down Expand Up @@ -90,6 +93,7 @@ export default class MbDateTime extends EhrElement {
}
return html`
<sl-input
id=${this.id}
part="sl-input"
class=${this.data ? '' : 'placeholder'}
.size=${this.variant === 'small' ? 'small' : 'medium'}
Expand Down
4 changes: 3 additions & 1 deletion src/medblocks/duration/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export default class MbDuration extends EhrElement {
@property({ type: Boolean, reflect: true }) hidelabel: boolean = false;
@property({ type: String, reflect: true }) min = '1';
@property({ type: String, reflect: true }) placeholder = '';
@property({ type: String, reflect: true }) id = 'duration';


@state() _state: { [period: string]: string | undefined } = {};

Expand Down Expand Up @@ -142,7 +144,7 @@ export default class MbDuration extends EhrElement {
a => html`<sl-input
.disabled=${this.disabled}
.size=${this.variant === 'small' ? 'small' : 'medium'}
id=${a}
id=${`${this.id}-${this.formatDuration(a)}`}
type="number"
.min=${this.min}
?required=${this.required}
Expand Down
8 changes: 7 additions & 1 deletion src/medblocks/proportion/MbProportion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ifDefined } from 'lit-html/directives/if-defined';

export default abstract class MbProportion extends EhrElement {
static styles = css`
.no-icon::part(icon) {
display: none;
}
Expand Down Expand Up @@ -49,6 +48,10 @@ export default abstract class MbProportion extends EhrElement {

@property({ type: Boolean, reflect: true }) disabled: boolean;

@property({ type: String, reflect: true }) placeholder = '';

@property({ type: String, reflect: true }) id = 'proportion';

@property({ type: Boolean }) hideunit = false;

_handleChange(e: CustomEvent) {
Expand Down Expand Up @@ -96,6 +99,7 @@ export default abstract class MbProportion extends EhrElement {
</div>`;
}
return html`<sl-input
id=${`${this.id}-magnitude`}
.required=${this.required}
.min=${this.min}
.max=${this.max}
Expand All @@ -107,9 +111,11 @@ export default abstract class MbProportion extends EhrElement {
@sl-input=${this._handleChange}
class=${this.hideunit ? '' : 'margin-xs'}
.value=${this.data?.numerator?.toString() || ''}
placeholder=${this.placeholder}
>
</sl-input>
<sl-select
id=${`${this.id}-unit`}
style="${this.hideunit ? 'display: none' : ''}"
placeholder="Select units"
class="no-icon"
Expand Down
14 changes: 6 additions & 8 deletions src/medblocks/quantity/QuantityLike.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
css,

html,
property,
query,
state,
} from 'lit-element';
import { css, html, property, query, state } from 'lit-element';
import MbUnit from './unit';
import SlSelect from '@shoelace-style/shoelace/dist/components/select/select';
import SlInput from '@shoelace-style/shoelace/dist/components/input/input';
Expand Down Expand Up @@ -90,6 +83,8 @@ export default abstract class QuantityLike extends EhrElement {

@property({ type: String, reflect: true }) placeholder = '';

@property({ type: String, reflect: true }) id = '';

@property({ type: Boolean }) hideicon = false;

/** Automatically disables the unit if only a single unit is present */
Expand Down Expand Up @@ -170,6 +165,7 @@ export default abstract class QuantityLike extends EhrElement {
}
return html`
<sl-input
id=${`${this.id}-magnitude`}
class=${this.hideunit ? '' : 'margin-xs'}
.size=${this.variant === 'small' ? 'small' : 'medium'}
.disabled=${this.disabled}
Expand All @@ -184,6 +180,7 @@ export default abstract class QuantityLike extends EhrElement {
placeholder=${this.placeholder}
></sl-input>
<sl-select
id=${`${this.id}-unit`}
.disabled=${this._disabled()}
class="${this._disabled() || this.hideicon ? 'no-icon' : ''}"
style="${this.hideunit ? 'display: none' : ''}"
Expand All @@ -197,6 +194,7 @@ export default abstract class QuantityLike extends EhrElement {
unit =>
html`<sl-menu-item
value=${unit.unit}
id=${`${this.id}-unit-${unit.unit}`}
max=${unit.max}
min=${unit.min}
>${unit.label}</sl-menu-item
Expand Down
5 changes: 5 additions & 0 deletions src/medblocks/quantity/quantity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export default class MbQuantity extends QuantityElement {

@property({ type: String, reflect: true }) placeholder = '';

@property({ type: String, reflect: true }) id : string = 'quantity';

@property({ type: Boolean }) hideicon = false;

/** Automatically disables the unit if only a single unit is present */
Expand Down Expand Up @@ -162,6 +164,7 @@ export default class MbQuantity extends QuantityElement {
}
return html`
<sl-input
id=${`${this.id}-magnitude`}
class=${this.hideunit ? '' : 'margin-xs'}
.size=${this.variant === 'small' ? 'small' : 'medium'}
.disabled=${this.disabled}
Expand All @@ -176,6 +179,7 @@ export default class MbQuantity extends QuantityElement {
placeholder=${this.placeholder}
></sl-input>
<sl-select
id=${`${this.id}-unit`}
exportparts="menu"
.disabled=${this._disabled()}
class="${this._disabled() || this.hideicon ? 'no-icon' : ''}"
Expand All @@ -190,6 +194,7 @@ export default class MbQuantity extends QuantityElement {
unit =>
html`<sl-menu-item
value=${unit.unit}
id=${`${this.id}-unit-${unit.unit}`}
max=${unit.max}
min=${unit.min}
>${unit.label}</sl-menu-item
Expand Down
2 changes: 1 addition & 1 deletion src/medblocks/suggestionWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class SuggestWrapper extends LitElement {
.label {
font-weight: var(--sl-font-weight-light);
font-size: var(--sl-input-help-text-font-size-medium);
color: rgb(var(--sl-input-help-text-color));
color: var(--sl-input-help-text-color);
}
.suggest-buttons {
Expand Down
4 changes: 4 additions & 0 deletions src/medblocks/text/input-multiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export default class MbInputMultiple extends EhrElement {

@property({ type: String, reflect: true }) placeholder: string = '';

@property({ type: String, reflect: true }) id: string = 'input_multiple';

@property({ type: Boolean, reflect: true }) required: boolean = false;

@property({ type: Boolean, reflect: true }) disabled: boolean;
Expand Down Expand Up @@ -100,6 +102,7 @@ export default class MbInputMultiple extends EhrElement {
}
return html`
<sl-input
id=${this.id}
.size=${this.variant === 'small' ? 'small' : 'medium'}
.disabled=${this.disabled}
?required=${this.required}
Expand All @@ -119,6 +122,7 @@ export default class MbInputMultiple extends EhrElement {
${this.data.map(
(s, i) =>
html`<sl-tag
id=${`${this.id}_tag${i}`}
variant="neutral"
size=${this.variant === 'small' ? 'small' : 'medium'}
@sl-remove=${() => this.handleClear(i)}
Expand Down
4 changes: 4 additions & 0 deletions src/medblocks/text/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export default class MbInput extends EhrElement {

@property({ type: String }) label: string = '';

@property({ type: String }) id: string = 'input';

@property({ type: Boolean, reflect: true }) required: boolean = false;

@property({ type: String, reflect: true }) type: string;
Expand Down Expand Up @@ -89,6 +91,7 @@ export default class MbInput extends EhrElement {
return this.textarea
? html`
<sl-textarea
id=${this.id}
.size=${this.variant === 'small' ? 'small' : 'medium'}
.disabled=${this.disabled}
.maxlength=${this.maxlength}
Expand All @@ -105,6 +108,7 @@ export default class MbInput extends EhrElement {
`
: html`
<sl-input
id=${this.id}
.size=${this.variant === 'small' ? 'small' : 'medium'}
.disabled=${this.disabled}
.min=${this.min}
Expand Down
5 changes: 4 additions & 1 deletion src/medblocks/text/text-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export default class MbTextSelect extends EhrElement {

@property({ type: String, reflect: true }) placeholder: string;

@property({ type: String, reflect: true }) id: string = 'text_select';

@state() _options: MbOption[] = [];

get _optionElements(): NodeListOf<MbOption> {
Expand Down Expand Up @@ -67,6 +69,7 @@ export default class MbTextSelect extends EhrElement {
}
return html`
<sl-select
id=${this.id}
exportparts="menu"
.size=${this.variant === 'small' ? 'small' : 'medium'}
clearable
Expand All @@ -85,7 +88,7 @@ export default class MbTextSelect extends EhrElement {
>
${this._options.map(
option =>
html`<sl-menu-item .value=${option.value}
html`<sl-menu-item .value=${option.value} id=${`${this.id}-${option.label}`}
>${option.label}
</sl-menu-item>`
)}
Expand Down

0 comments on commit f7dc08d

Please sign in to comment.