mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
ec157dc469
Summary: Adds initial implementation of dark mode. Preferences for dark mode are available on the account settings page. Dark mode is currently a beta feature as there are still some small bugs to squash and a few remaining UI elements to style. Test Plan: Browser tests. Reviewers: jarek Reviewed By: jarek Subscribers: paulfitz, jarek Differential Revision: https://phab.getgrist.com/D3587
89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
import {Style} from 'app/client/models/Styles';
|
|
import {colors, theme, vars} from 'app/client/ui2018/cssVars';
|
|
import {dom, DomContents, DomElementArg, styled} from 'grainjs';
|
|
|
|
export const DEFAULT_FILL_COLOR = colors.mediumGreyOpaque.value!;
|
|
export const DEFAULT_TEXT_COLOR = '#000000';
|
|
|
|
export interface IChoiceTokenOptions extends Style {
|
|
invalid?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Creates a colored token representing a choice (e.g. Choice and Choice List values).
|
|
*
|
|
* Tokens are pill-shaped boxes that contain text, with custom fill and text
|
|
* colors. If colors are not specified, a gray fill with black text will be used.
|
|
*
|
|
* Additional styles and other DOM arguments can be passed in to customize the
|
|
* appearance and behavior of the token.
|
|
*
|
|
* @param {DomElementArg} label The text that will appear inside the token.
|
|
* @param {IChoiceTokenOptions} options Options for customizing the token appearance.
|
|
* @param {DOMElementArg[]} args Additional arguments to pass to the token.
|
|
* @returns {DomContents} A colored choice token.
|
|
*/
|
|
export function choiceToken(
|
|
label: DomElementArg,
|
|
options: IChoiceTokenOptions,
|
|
...args: DomElementArg[]
|
|
): DomContents {
|
|
const {fillColor, textColor, fontBold, fontItalic, fontUnderline,
|
|
fontStrikethrough, invalid} = options;
|
|
return cssChoiceToken(
|
|
label,
|
|
dom.style('background-color', fillColor ?? DEFAULT_FILL_COLOR),
|
|
dom.style('color', textColor ?? DEFAULT_TEXT_COLOR),
|
|
dom.cls('font-bold', fontBold ?? false),
|
|
dom.cls('font-underline', fontUnderline ?? false),
|
|
dom.cls('font-italic', fontItalic ?? false),
|
|
dom.cls('font-strikethrough', fontStrikethrough ?? false),
|
|
invalid ? cssChoiceToken.cls('-invalid') : null,
|
|
...args
|
|
);
|
|
}
|
|
|
|
export const cssChoiceToken = styled('div', `
|
|
display: inline-block;
|
|
padding: 1px 4px;
|
|
border-radius: 3px;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: pre;
|
|
|
|
&-invalid {
|
|
background-color: white !important;
|
|
box-shadow: inset 0 0 0 1px ${colors.error};
|
|
}
|
|
`);
|
|
|
|
const ADD_NEW_HEIGHT = '37px';
|
|
|
|
export const cssChoiceACItem = styled('li', `
|
|
display: block;
|
|
font-family: ${vars.fontFamily};
|
|
white-space: pre;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
outline: none;
|
|
padding: var(--weaseljs-menu-item-padding, 8px 24px);
|
|
cursor: pointer;
|
|
|
|
&.selected {
|
|
background-color: ${theme.autocompleteChoiceSelectedBg};
|
|
}
|
|
&-with-new {
|
|
scroll-margin-bottom: ${ADD_NEW_HEIGHT};
|
|
}
|
|
&-new {
|
|
display: flex;
|
|
align-items: center;
|
|
position: sticky;
|
|
bottom: 0px;
|
|
height: ${ADD_NEW_HEIGHT};
|
|
background-color: ${theme.menuBg};
|
|
border-top: 1px solid ${theme.menuBorder};
|
|
scroll-margin-bottom: initial;
|
|
}
|
|
`);
|