-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9da478a
commit ced505d
Showing
4 changed files
with
109 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {Option, Radios} from "./radios"; | ||
import * as mui from "@mui/material"; | ||
import {Tooltip, tooltipClasses, TooltipProps} from "@mui/material"; | ||
import React from "react"; | ||
import {stopPropagation} from "./utils"; | ||
import styled from "styled-components"; | ||
|
||
const SettingsIcon = styled.span` | ||
margin-right: 0.3rem; | ||
` | ||
|
||
export type HeaderSettings<T extends string> = { | ||
options: (Option<T> | T)[] | ||
choice: T | ||
cb: (choice: T) => void | ||
} | ||
|
||
export const ColumnHeaderTooltip = mui.styled( | ||
({ className, ...props }: TooltipProps) => <Tooltip {...props} classes={{ popper: className }} /> | ||
)(({ theme }) => ({ | ||
[`& .${tooltipClasses.tooltip}`]: { | ||
backgroundColor: theme.palette.common.black, | ||
color: theme.palette.common.white, | ||
fontSize: '1rem', | ||
marginBottom: '0.2rem', | ||
}, | ||
'.settings-tooltip': { | ||
margin: '0.3rem 0', | ||
}, | ||
'.control-header': { | ||
fontWeight: 'bold', | ||
marginBottom: '0.4rem', | ||
}, | ||
'.sub-control > label': { | ||
display: 'block', | ||
marginBottom: 0, | ||
} | ||
})); | ||
|
||
export function ColumnHeader<T extends string>( | ||
label: string, | ||
headerSettings?: HeaderSettings<T>, | ||
) { | ||
const body: JSX.Element = | ||
headerSettings ? | ||
<Radios label={label} {...headerSettings} /> : | ||
<div>no choices available</div> | ||
|
||
return ( | ||
<ColumnHeaderTooltip disableFocusListener arrow placement="bottom-start" title={ | ||
<div className="settings-tooltip" onClick={stopPropagation}> | ||
{body} | ||
</div> | ||
}> | ||
<span className="header-span"> | ||
<SettingsIcon>⚙️</SettingsIcon> | ||
{label} | ||
</span> | ||
</ColumnHeaderTooltip> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import moment, {Moment} from "moment"; | ||
|
||
moment.locale('en', { | ||
relativeTime: { | ||
future: 'in %s', | ||
past: '%s ago', | ||
s: 'seconds', | ||
ss: '%ss', | ||
m: 'a minute', | ||
mm: '%dm', | ||
h: 'an hour', | ||
hh: '%dh', | ||
d: 'a day', | ||
dd: '%dd', | ||
M: 'a month', | ||
MM: '%dM', | ||
y: 'a year', | ||
yy: '%dY' | ||
} | ||
}); | ||
|
||
export function renderDatetime(m: Moment, fmt: DatetimeFmt): string { | ||
if (fmt == 'relative') { | ||
return m.fromNow(true) | ||
} else { | ||
return m.format(fmt) | ||
} | ||
} | ||
|
||
export type DatetimeFmt = 'YYYY-MM-DD' | 'YYYY-MM-DD HH:mm:ss' | 'relative' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters