Skip to content
Merged
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
21 changes: 9 additions & 12 deletions app/client/widgets/ChoiceListEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {CellValue} from "app/common/DocActions";
import {CompiledPredicateFormula} from 'app/common/PredicateFormula';
import {EmptyRecordView} from 'app/common/RecordView';
import {decodeObject, encodeObject} from 'app/plugin/objtypes';
import {ChoiceOptions, getRenderFillColor, getRenderTextColor} from 'app/client/widgets/ChoiceTextBox';
import {choiceToken, cssChoiceACItem, cssChoiceToken} from 'app/client/widgets/ChoiceToken';
import {ChoiceOptions} from 'app/client/widgets/ChoiceTextBox';
import {choiceToken, choiceTokenDomArgs, cssChoiceACItem} from 'app/client/widgets/ChoiceToken';
import {icon} from 'app/client/ui2018/icons';
import {dom, styled} from 'grainjs';

Expand Down Expand Up @@ -95,17 +95,14 @@ export class ChoiceListEditor extends NewBaseEditor {

this._tokenField = TokenField.ctor<ChoiceItem>().create(this, {
initialValue: startTokens,
renderToken: item => [
renderToken: item => choiceTokenDomArgs(
item.isBlank ? '[Blank]' : item.label,
dom.style('background-color', getRenderFillColor(this._choiceOptionsByName[item.label])),
dom.style('color', getRenderTextColor(this._choiceOptionsByName[item.label])),
dom.cls('font-bold', this._choiceOptionsByName[item.label]?.fontBold ?? false),
dom.cls('font-underline', this._choiceOptionsByName[item.label]?.fontUnderline ?? false),
dom.cls('font-italic', this._choiceOptionsByName[item.label]?.fontItalic ?? false),
dom.cls('font-strikethrough', this._choiceOptionsByName[item.label]?.fontStrikethrough ?? false),
cssChoiceToken.cls('-invalid', item.isInvalid),
cssChoiceToken.cls('-blank', item.isBlank),
],
{
...(this._choiceOptionsByName[item.label] || {}),
invalid: item.isInvalid,
blank: item.isBlank,
},
),
createToken: label => new ChoiceItem(label, !this._choicesSet.has(label), label.trim() === ''),
acOptions,
openAutocompleteOnFocus: true,
Expand Down
10 changes: 1 addition & 9 deletions app/client/widgets/ChoiceTextBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {cssLabel, cssRow} from 'app/client/ui/RightPanelStyles';
import {testId, theme} from 'app/client/ui2018/cssVars';
import {icon} from 'app/client/ui2018/icons';
import {ChoiceListEntry} from 'app/client/widgets/ChoiceListEntry';
import {choiceToken, DEFAULT_BACKGROUND_COLOR, DEFAULT_COLOR} from 'app/client/widgets/ChoiceToken';
import {choiceToken} from 'app/client/widgets/ChoiceToken';
import {NTextBox} from 'app/client/widgets/NTextBox';
import {Computed, dom, styled} from 'grainjs';

Expand All @@ -24,14 +24,6 @@ export type ChoiceOptionsByName = Map<string, IChoiceOptions | undefined>;

const t = makeT('ChoiceTextBox');

export function getRenderFillColor(choiceOptions?: IChoiceOptions) {
return choiceOptions?.fillColor ?? DEFAULT_BACKGROUND_COLOR;
}

export function getRenderTextColor(choiceOptions?: IChoiceOptions) {
return choiceOptions?.textColor ?? DEFAULT_COLOR;
}

/**
* ChoiceTextBox - A textbox for choice values.
*/
Expand Down
18 changes: 14 additions & 4 deletions app/client/widgets/ChoiceToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,21 @@ export function choiceToken(
options: IChoiceTokenOptions,
...args: DomElementArg[]
): DomContents {
return cssChoiceToken(choiceTokenDomArgs(label, options), ...args);
}

/**
* Exposes the choiceToken dom args outside of cssChoiceToken to allow
* easy usage of them with TokenField#renderToken, that has its own wrapper dom el.
*/
export function choiceTokenDomArgs(
label: DomElementArg,
options: IChoiceTokenOptions,
): DomElementArg {
const {fillColor, textColor, fontBold, fontItalic, fontUnderline,
fontStrikethrough, invalid, blank} = options;
fontStrikethrough, invalid, blank} = options;
const {bg, fg} = getReadableColorsCombo({fillColor, textColor});
return cssChoiceToken(
return [
label,
dom.style('background-color', bg),
dom.style('color', fg),
Expand All @@ -47,8 +58,7 @@ export function choiceToken(
dom.cls('font-strikethrough', fontStrikethrough ?? false),
invalid ? cssChoiceToken.cls('-invalid') : null,
blank ? cssChoiceToken.cls('-blank') : null,
...args
);
];
}

export const cssChoiceToken = styled('div', `
Expand Down
Loading