2022-08-08 13:32:50 +00:00
|
|
|
import {allCommands} from 'app/client/components/commands';
|
2022-03-22 13:41:11 +00:00
|
|
|
import {GristDoc} from 'app/client/components/GristDoc';
|
|
|
|
import {ViewFieldRec} from 'app/client/models/entities/ViewFieldRec';
|
2022-10-14 10:07:19 +00:00
|
|
|
import {Style} from 'app/client/models/Styles';
|
2022-03-22 13:41:11 +00:00
|
|
|
import {textButton} from 'app/client/ui2018/buttons';
|
2022-04-07 14:58:16 +00:00
|
|
|
import {ColorOption, colorSelect} from 'app/client/ui2018/ColorSelect';
|
2022-09-06 01:51:57 +00:00
|
|
|
import {theme, vars} from 'app/client/ui2018/cssVars';
|
2022-08-08 13:32:50 +00:00
|
|
|
import {ConditionalStyle} from 'app/client/widgets/ConditionalStyle';
|
2022-10-14 10:07:19 +00:00
|
|
|
import {Computed, Disposable, dom, DomContents, fromKo, MultiHolder, Observable, styled} from 'grainjs';
|
2022-03-22 13:41:11 +00:00
|
|
|
|
|
|
|
export class CellStyle extends Disposable {
|
2022-08-08 13:32:50 +00:00
|
|
|
private _textColor: Observable<string|undefined>;
|
|
|
|
private _fillColor: Observable<string|undefined>;
|
|
|
|
private _fontBold: Observable<boolean|undefined>;
|
|
|
|
private _fontUnderline: Observable<boolean|undefined>;
|
|
|
|
private _fontItalic: Observable<boolean|undefined>;
|
|
|
|
private _fontStrikethrough: Observable<boolean|undefined>;
|
2022-03-22 13:41:11 +00:00
|
|
|
|
|
|
|
constructor(
|
2022-08-08 13:32:50 +00:00
|
|
|
private _field: ViewFieldRec,
|
|
|
|
private _gristDoc: GristDoc,
|
|
|
|
private _defaultTextColor: string
|
2022-03-22 13:41:11 +00:00
|
|
|
) {
|
|
|
|
super();
|
2022-10-14 10:07:19 +00:00
|
|
|
this._textColor = fromKo(this._field.config.textColor);
|
|
|
|
this._fillColor = fromKo(this._field.config.fillColor);
|
|
|
|
this._fontBold = fromKo(this._field.config.fontBold);
|
|
|
|
this._fontUnderline = fromKo(this._field.config.fontUnderline);
|
|
|
|
this._fontItalic = fromKo(this._field.config.fontItalic);
|
|
|
|
this._fontStrikethrough = fromKo(this._field.config.fontStrikethrough);
|
2022-03-22 13:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public buildDom(): DomContents {
|
|
|
|
const holder = new MultiHolder();
|
2022-10-14 10:07:19 +00:00
|
|
|
const hasMixedStyle = Computed.create(holder, use => {
|
|
|
|
if (!use(this._field.config.multiselect)) { return false; }
|
|
|
|
const commonStyle = [
|
|
|
|
use(this._field.config.options.mixed('textColor')),
|
|
|
|
use(this._field.config.options.mixed('fillColor')),
|
|
|
|
use(this._field.config.options.mixed('fontBold')),
|
|
|
|
use(this._field.config.options.mixed('fontUnderline')),
|
|
|
|
use(this._field.config.options.mixed('fontItalic')),
|
|
|
|
use(this._field.config.options.mixed('fontStrikethrough'))
|
|
|
|
];
|
|
|
|
return commonStyle.some(Boolean);
|
|
|
|
});
|
|
|
|
let state: Style[]|null = null;
|
2022-03-22 13:41:11 +00:00
|
|
|
return [
|
2022-08-08 13:32:50 +00:00
|
|
|
cssLine(
|
|
|
|
cssLabel('CELL STYLE', dom.autoDispose(holder)),
|
|
|
|
cssButton('Open row styles', dom.on('click', allCommands.viewTabOpen.run)),
|
|
|
|
),
|
2022-03-22 13:41:11 +00:00
|
|
|
cssRow(
|
|
|
|
colorSelect(
|
2022-04-07 14:58:16 +00:00
|
|
|
{
|
2022-08-08 13:32:50 +00:00
|
|
|
textColor: new ColorOption(
|
|
|
|
{ color: this._textColor, defaultColor: this._defaultTextColor, noneText: 'default'}
|
|
|
|
),
|
|
|
|
fillColor: new ColorOption(
|
|
|
|
{ color: this._fillColor, allowsNone: true, noneText: 'none'}
|
|
|
|
),
|
|
|
|
fontBold: this._fontBold,
|
|
|
|
fontItalic: this._fontItalic,
|
|
|
|
fontUnderline: this._fontUnderline,
|
|
|
|
fontStrikethrough: this._fontStrikethrough
|
2022-10-14 10:07:19 +00:00
|
|
|
}, {
|
|
|
|
// Calling `field.config.options.save()` saves all options at once.
|
|
|
|
onSave: () => this._field.config.options.save(),
|
|
|
|
onOpen: () => state = this._field.config.copyStyles(),
|
|
|
|
onRevert: () => this._field.config.setStyles(state),
|
|
|
|
placeholder: use => use(hasMixedStyle) ? 'Mixed style' : 'Default cell style'
|
|
|
|
}
|
2022-03-22 13:41:11 +00:00
|
|
|
)
|
|
|
|
),
|
2022-10-14 10:07:19 +00:00
|
|
|
dom.create(ConditionalStyle, "Cell Style", this._field, this._gristDoc, fromKo(this._field.config.multiselect))
|
2022-03-22 13:41:11 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 13:32:50 +00:00
|
|
|
const cssLine = styled('div', `
|
2022-03-22 13:41:11 +00:00
|
|
|
display: flex;
|
2022-08-08 13:32:50 +00:00
|
|
|
margin: 16px 16px 12px 16px;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: baseline;
|
2022-03-22 13:41:11 +00:00
|
|
|
`);
|
|
|
|
|
2022-08-08 13:32:50 +00:00
|
|
|
const cssLabel = styled('div', `
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.text};
|
2022-08-08 13:32:50 +00:00
|
|
|
text-transform: uppercase;
|
|
|
|
font-size: ${vars.xsmallFontSize};
|
2022-03-22 13:41:11 +00:00
|
|
|
`);
|
|
|
|
|
2022-08-08 13:32:50 +00:00
|
|
|
const cssButton = styled(textButton, `
|
|
|
|
font-size: ${vars.mediumFontSize};
|
2022-03-22 13:41:11 +00:00
|
|
|
`);
|
|
|
|
|
2022-08-08 13:32:50 +00:00
|
|
|
const cssRow = styled('div', `
|
2022-03-22 13:41:11 +00:00
|
|
|
display: flex;
|
2022-08-08 13:32:50 +00:00
|
|
|
margin: 8px 16px;
|
|
|
|
align-items: center;
|
|
|
|
&-top-space {
|
|
|
|
margin-top: 24px;
|
|
|
|
}
|
|
|
|
&-disabled {
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.disabledText};
|
2022-08-08 13:32:50 +00:00
|
|
|
}
|
2022-03-22 13:41:11 +00:00
|
|
|
`);
|