Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | 92x 140x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 82x 82x 82x 82x 82x 82x 82x 82x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 120x 120x 120x 92x 163x 116x 115x 116x 116x 116x 116x 163x 163x 163x 163x 105x 105x 163x 127x 69x 69x 127x 58x 58x 69x 69x 69x 69x 69x 127x 127x 127x 127x 7x 163x 163x 92x 6x 6x 1x 1x 1x 163x 163x 10x 10x 10x 100x 100x 163x 163x 163x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 163x 163x 163x 163x 154x 10x 10x 10x 10x 163x 163x 163x 7x 76x 76x 163x 163x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x | import { TemplateResult, html, css } from 'lit';
import { FieldElement } from './FieldElement';
import { property } from 'lit/decorators.js';
import { Icon } from '../Icons';
import { renderMarkdownInline } from '../markdown';
export class Checkbox extends FieldElement {
static get styles() {
return css`
${super.styles}
:host {
color: var(--color-text);
display: inline-block;
}
:host([label]) {
width: 100%;
}
.checkbox-background {
position: absolute;
margin-top: 2px;
margin-left: 2px;
width: 12px;
height: 12px;
background: var(--checkbox-background, rgba(255, 255, 255, 0.8));
border-radius: 2px;
}
.wrapper.label {
padding: var(--checkbox-padding, 10px);
border-radius: var(--curvature);
}
.wrapper.label:hover {
background: var(--checkbox-hover-bg, #f9f9f9);
}
.checkbox-container {
position: relative;
cursor: pointer;
display: flex;
align-items: flex-start;
user-select: none;
-webkit-user-select: none;
}
.checkbox-container temba-icon {
align-self: flex-start;
vertical-align: top;
line-height: 1;
}
.label-and-help {
flex-grow: 1;
margin-left: 8px;
}
.checkbox-label {
font-family: var(--font-family);
padding: 0px;
margin: 0px;
font-size: 14px;
line-height: 19px;
}
.checkbox-help-text {
font-family: var(--font-family);
font-size: var(--help-text-size, 0.85em);
line-height: normal;
color: var(--color-text-help);
margin-top: 4px;
opacity: 1;
}
/* Checkbox help text should align with the checkbox icon, not indented */
.help-text {
margin-left: 0;
}
.far {
height: 16px;
margin-top: 1px;
}
.disabled {
cursor: not-allowed;
--icon-color: #ccc;
}
`;
}
@property({ type: String })
name = '';
@property({ type: Boolean })
checked: boolean;
@property({ type: Boolean })
partial: boolean;
@property({ type: Boolean })
disabled = false;
@property({ type: Number })
size = 1.2;
@property({ type: String })
animateChange = 'pulse';
private initialized = false;
public connectedCallback() {
super.connectedCallback();
}
public updated(changes: Map<string, any>) {
super.updated(changes);
// Normalize label property changes
if (changes.has('label')) {
// Normalize whitespace labels to empty string for proper behavior
if (
this.label &&
typeof this.label === 'string' &&
this.label.trim() === ''
) {
this.label = '';
}
// Ensure undefined labels remain as null to match test expectations
if (this.label === undefined) {
this.label = null;
}
}
if (changes.has('checked') || changes.has('value')) {
if (this.checked || this.partial) {
this.internals.setFormValue(this.value || '1');
} else {
this.internals.setFormValue(undefined);
}
// Only fire change after the initial render
if (this.initialized) {
this.fireEvent('change');
}
}
this.initialized = true;
}
public serializeValue(value: any): string {
return value;
}
private handleClick(): void {
if (!this.disabled) {
this.checked = !this.checked;
}
}
public click(): void {
this.handleClick();
super.click();
}
protected renderWidget(): TemplateResult {
const icon = html`<temba-icon
name="${this.checked
? Icon.checkbox_checked
: this.partial
? Icon.checkbox_partial
: Icon.checkbox}"
size="${this.size}"
animatechange="${this.animateChange}"
></temba-icon>`;
return html`
<div
class="wrapper ${this.label ? 'label' : ''}"
@click=${this.handleClick}
>
<div class="checkbox-container ${this.disabled ? 'disabled' : ''}">
<div class="checkbox-background"></div>
${icon}
<div class="label-and-help">
${this.label && String(this.label).trim()
? html`<div class="checkbox-label">${this.label}</div>`
: null}
${this.helpText && this.helpText !== 'None'
? html` <div class="checkbox-help-text">${this.helpText}</div> `
: null}
</div>
</div>
</div>
`;
}
protected renderField(): TemplateResult {
// Use standard FieldElement behavior but skip the field label since checkbox renders its own inline
const hasErrors = !this.hideErrors && this.errors && this.errors.length > 0;
const errors = hasErrors
? this.errors.map((error: string) => {
return html`
<div class="alert-error">${renderMarkdownInline(error)}</div>
`;
})
: [];
if (this.widgetOnly) {
return html`
<div class="${this.disabled ? 'disabled' : ''}">
${this.renderWidget()}
</div>
${errors}
`;
}
// This matches FieldElement.renderField() but without the field label
return html`
<div
class="field ${this.disabled ? 'disabled' : ''} ${hasErrors
? 'has-error'
: ''}"
>
<div class="widget">${this.renderWidget()} ${errors}</div>
</div>
`;
}
public render(): TemplateResult {
return this.renderField();
}
}
|