2022-09-06 01:51:57 +00:00
|
|
|
import {theme, vars} from 'app/client/ui2018/cssVars';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
|
|
|
import {dom, DomElementArg, Observable, styled} from "grainjs";
|
2022-09-29 08:01:37 +00:00
|
|
|
import {t} from 'app/client/lib/localization';
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
export function addNewButton(isOpen: Observable<boolean> | boolean = true, ...args: DomElementArg[]) {
|
|
|
|
return cssAddNewButton(
|
|
|
|
cssAddNewButton.cls('-open', isOpen),
|
|
|
|
// Setting spacing as flex items allows them to shrink faster when there isn't enough space.
|
|
|
|
cssLeftMargin(),
|
2022-10-13 09:23:55 +00:00
|
|
|
cssAddText(t('AddNewButton.AddNew')),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom('div', {style: 'flex: 1 1 16px'}),
|
|
|
|
cssPlusButton(cssPlusIcon('Plus')),
|
|
|
|
dom('div', {style: 'flex: 0 1 16px'}),
|
|
|
|
...args,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const cssAddNewButton = styled('div', `
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
margin: 22px 0px 22px 0px;
|
|
|
|
height: 40px;
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.controlPrimaryFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
border: none;
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
|
|
cursor: default;
|
|
|
|
text-align: left;
|
|
|
|
font-size: ${vars.bigControlFontSize};
|
|
|
|
font-weight: bold;
|
|
|
|
overflow: hidden;
|
|
|
|
|
2022-09-06 01:51:57 +00:00
|
|
|
--circle-color: ${theme.addNewCircleSmallBg};
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
&:hover, &.weasel-popup-open {
|
2022-09-06 01:51:57 +00:00
|
|
|
--circle-color: ${theme.addNewCircleSmallHoverBg};
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
&-open {
|
|
|
|
margin: 22px 16px 22px 16px;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlPrimaryBg};
|
|
|
|
--circle-color: ${theme.addNewCircleBg};
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
&-open:hover, &-open.weasel-popup-open {
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlPrimaryHoverBg};
|
|
|
|
--circle-color: ${theme.addNewCircleHoverBg};
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
const cssLeftMargin = styled('div', `
|
|
|
|
flex: 0 1 24px;
|
|
|
|
display: none;
|
|
|
|
.${cssAddNewButton.className}-open & {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
const cssAddText = styled('div', `
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.controlPrimaryFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
flex: 0 0.5 content;
|
|
|
|
white-space: nowrap;
|
|
|
|
min-width: 0px;
|
|
|
|
display: none;
|
|
|
|
.${cssAddNewButton.className}-open & {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
const cssPlusButton = styled('div', `
|
|
|
|
flex: none;
|
|
|
|
height: 28px;
|
|
|
|
width: 28px;
|
|
|
|
border-radius: 14px;
|
|
|
|
background-color: var(--circle-color);
|
|
|
|
text-align: center;
|
|
|
|
`);
|
|
|
|
const cssPlusIcon = styled(icon, `
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.addNewCircleFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
margin-top: 6px;
|
|
|
|
`);
|