2022-09-06 01:51:57 +00:00
|
|
|
import {theme, vars} from 'app/client/ui2018/cssVars';
|
2022-10-20 08:34:38 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
|
|
|
import {dom, DomElementArg, Observable, styled} from "grainjs";
|
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT(`AddNewButton`);
|
2022-10-13 10:31:26 +00:00
|
|
|
|
2023-09-08 13:05:52 +00:00
|
|
|
export function addNewButton(
|
|
|
|
{
|
|
|
|
isOpen,
|
|
|
|
isDisabled = false,
|
|
|
|
}: {
|
|
|
|
isOpen: Observable<boolean> | boolean,
|
|
|
|
isDisabled?: boolean
|
|
|
|
},
|
|
|
|
...args: DomElementArg[]
|
|
|
|
) {
|
2020-10-02 15:10:00 +00:00
|
|
|
return cssAddNewButton(
|
|
|
|
cssAddNewButton.cls('-open', isOpen),
|
2023-09-08 13:05:52 +00:00
|
|
|
cssAddNewButton.cls('-disabled', isDisabled),
|
2020-10-02 15:10:00 +00:00
|
|
|
// Setting spacing as flex items allows them to shrink faster when there isn't enough space.
|
|
|
|
cssLeftMargin(),
|
2022-12-06 13:57:29 +00:00
|
|
|
cssAddText(t("Add New")),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom('div', {style: 'flex: 1 1 16px'}),
|
2023-09-08 13:05:52 +00:00
|
|
|
cssPlusButton(
|
|
|
|
cssPlusButton.cls('-disabled', isDisabled),
|
|
|
|
cssPlusIcon('Plus')
|
|
|
|
),
|
2020-10-02 15:10:00 +00:00
|
|
|
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
|
|
|
}
|
2023-09-08 13:05:52 +00:00
|
|
|
|
|
|
|
&-disabled, &-disabled:hover {
|
|
|
|
color: ${theme.controlDisabledFg};
|
|
|
|
background-color: ${theme.controlDisabledBg}
|
|
|
|
}
|
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;
|
2023-09-08 13:05:52 +00:00
|
|
|
&-disabled {
|
|
|
|
background-color: ${theme.controlDisabledBg};
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
`);
|
|
|
|
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;
|
|
|
|
`);
|