2023-01-11 17:57:42 +00:00
|
|
|
import { makeT } from 'app/client/lib/localization';
|
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';
|
|
|
|
import {textButton} from 'app/client/ui2018/buttons';
|
2022-04-07 14:58:16 +00:00
|
|
|
import {ColorOption, colorSelect} from 'app/client/ui2018/ColorSelect';
|
2023-08-07 18:01:35 +00:00
|
|
|
import {testId, theme, vars} from 'app/client/ui2018/cssVars';
|
2022-08-08 13:32:50 +00:00
|
|
|
import {ConditionalStyle} from 'app/client/widgets/ConditionalStyle';
|
2022-10-24 10:06:24 +00:00
|
|
|
import {Computed, Disposable, dom, DomContents, fromKo, styled} from 'grainjs';
|
2022-03-22 13:41:11 +00:00
|
|
|
|
2023-01-11 17:57:42 +00:00
|
|
|
const t = makeT('CellStyle');
|
|
|
|
|
2022-03-22 13:41:11 +00:00
|
|
|
export class CellStyle extends Disposable {
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
public buildDom(): DomContents {
|
2023-08-07 18:01:35 +00:00
|
|
|
const isTableWidget = this._field.viewSection().parentKey() === 'record';
|
2022-03-22 13:41:11 +00:00
|
|
|
return [
|
2023-08-07 18:01:35 +00:00
|
|
|
dom.maybe(use => isTableWidget, () => {
|
|
|
|
return [
|
|
|
|
cssLine(
|
|
|
|
cssLabel(t('HEADER STYLE')),
|
|
|
|
),
|
|
|
|
cssRow(
|
|
|
|
testId('header-color-select'),
|
|
|
|
dom.domComputedOwned(fromKo(this._field.config.headerStyle), (holder, options) => {
|
|
|
|
const headerTextColor = fromKo(options.prop("headerTextColor"));
|
|
|
|
const headerFillColor = fromKo(options.prop("headerFillColor"));
|
|
|
|
const headerFontBold = fromKo(options.prop("headerFontBold"));
|
|
|
|
const headerFontUnderline = fromKo(options.prop("headerFontUnderline"));
|
|
|
|
const headerFontItalic = fromKo(options.prop("headerFontItalic"));
|
|
|
|
const headerFontStrikethrough = fromKo(options.prop("headerFontStrikethrough"));
|
|
|
|
const hasMixedStyle = Computed.create(holder, use => {
|
|
|
|
if (!use(this._field.config.multiselect)) { return false; }
|
|
|
|
const commonStyle = [
|
|
|
|
use(options.mixed('headerTextColor')),
|
|
|
|
use(options.mixed('headerFillColor')),
|
|
|
|
use(options.mixed('headerFontBold')),
|
|
|
|
use(options.mixed('headerFontUnderline')),
|
|
|
|
use(options.mixed('headerFontItalic')),
|
|
|
|
use(options.mixed('headerFontStrikethrough'))
|
|
|
|
];
|
|
|
|
return commonStyle.some(Boolean);
|
|
|
|
});
|
|
|
|
return colorSelect(
|
|
|
|
{
|
|
|
|
textColor: new ColorOption(
|
|
|
|
{ color: headerTextColor, defaultColor: this._defaultTextColor, noneText: 'default' }
|
|
|
|
),
|
|
|
|
fillColor: new ColorOption(
|
|
|
|
{ color: headerFillColor, allowsNone: true, noneText: 'none' }
|
|
|
|
),
|
|
|
|
fontBold: headerFontBold,
|
|
|
|
fontItalic: headerFontItalic,
|
|
|
|
fontUnderline: headerFontUnderline,
|
|
|
|
fontStrikethrough: headerFontStrikethrough
|
|
|
|
}, {
|
|
|
|
onSave: () => options.save(),
|
|
|
|
onRevert: () => options.revert(),
|
|
|
|
placeholder: use => use(hasMixedStyle) ? t('Mixed style') : t('Default header style')
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
)];
|
|
|
|
}),
|
2022-08-08 13:32:50 +00:00
|
|
|
cssLine(
|
2023-01-11 17:57:42 +00:00
|
|
|
cssLabel(t('CELL STYLE')),
|
|
|
|
cssButton(t('Open row styles'), dom.on('click', allCommands.viewTabOpen.run)),
|
2022-08-08 13:32:50 +00:00
|
|
|
),
|
2022-03-22 13:41:11 +00:00
|
|
|
cssRow(
|
2023-08-07 18:01:35 +00:00
|
|
|
testId('cell-color-select'),
|
2022-10-24 10:06:24 +00:00
|
|
|
dom.domComputedOwned(fromKo(this._field.config.style), (holder, options) => {
|
|
|
|
const textColor = fromKo(options.prop("textColor"));
|
|
|
|
const fillColor = fromKo(options.prop("fillColor"));
|
|
|
|
const fontBold = fromKo(options.prop("fontBold"));
|
|
|
|
const fontUnderline = fromKo(options.prop("fontUnderline"));
|
|
|
|
const fontItalic = fromKo(options.prop("fontItalic"));
|
|
|
|
const fontStrikethrough = fromKo(options.prop("fontStrikethrough"));
|
|
|
|
const hasMixedStyle = Computed.create(holder, use => {
|
|
|
|
if (!use(this._field.config.multiselect)) { return false; }
|
|
|
|
const commonStyle = [
|
|
|
|
use(options.mixed('textColor')),
|
|
|
|
use(options.mixed('fillColor')),
|
|
|
|
use(options.mixed('fontBold')),
|
|
|
|
use(options.mixed('fontUnderline')),
|
|
|
|
use(options.mixed('fontItalic')),
|
|
|
|
use(options.mixed('fontStrikethrough'))
|
|
|
|
];
|
|
|
|
return commonStyle.some(Boolean);
|
|
|
|
});
|
|
|
|
return colorSelect(
|
|
|
|
{
|
|
|
|
textColor: new ColorOption(
|
|
|
|
{ color: textColor, defaultColor: this._defaultTextColor, noneText: 'default'}
|
|
|
|
),
|
|
|
|
fillColor: new ColorOption(
|
|
|
|
{ color: fillColor, allowsNone: true, noneText: 'none'}
|
|
|
|
),
|
|
|
|
fontBold: fontBold,
|
|
|
|
fontItalic: fontItalic,
|
|
|
|
fontUnderline: fontUnderline,
|
|
|
|
fontStrikethrough: fontStrikethrough
|
|
|
|
}, {
|
|
|
|
onSave: () => options.save(),
|
|
|
|
onRevert: () => options.revert(),
|
2023-01-11 17:57:42 +00:00
|
|
|
placeholder: use => use(hasMixedStyle) ? t('Mixed style') : t('Default cell style')
|
2022-10-24 10:06:24 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}),
|
2022-03-22 13:41:11 +00:00
|
|
|
),
|
2023-01-11 17:57:42 +00:00
|
|
|
dom.create(ConditionalStyle, t("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
|
|
|
`);
|