-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
17 changed files
with
948 additions
and
238 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { TextFieldProps } from '@mui/material'; | ||
import * as React from 'react'; | ||
import { useCallback, useMemo } from 'react'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { composeValidators, NsInput } from '../validators'; | ||
import { NsLabelInput } from '../../NsLabelInput'; | ||
import uniqueId from '../../../../util/uniqueId'; | ||
import { useFormField } from 'relay-forms'; | ||
import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment'; | ||
import moment, { Moment } from 'moment'; | ||
import { PickersInputComponentLocaleText } from '@mui/x-date-pickers/locales'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { TimePicker } from '@mui/x-date-pickers'; | ||
|
||
const FMT = 'HH:mm'; | ||
|
||
export type NsTimePickerProps = NsInput<Omit<TextFieldProps, 'value'>, string> & { | ||
localeText?: PickersInputComponentLocaleText<moment.Moment>; | ||
format?: string; | ||
ampm?: boolean; | ||
}; | ||
|
||
export const NsTimePicker: React.FC<NsTimePickerProps> = ({ | ||
name, | ||
label, | ||
defaultValue, | ||
validate, | ||
errorMessage, | ||
disabled, | ||
dependsOn, | ||
onChange, | ||
ampm = false, | ||
format = FMT, | ||
localeText, | ||
...rest | ||
}) => { | ||
const key = useMemo(() => name || uniqueId('v_picker-'), [name]); | ||
const deps = useMemo(() => dependsOn, []); | ||
const { i18n } = useTranslation(); | ||
|
||
const validateCallback = useCallback( | ||
(v: string, deps: any) => composeValidators(validate, errorMessage)(v, deps), | ||
[validate, errorMessage], | ||
); | ||
|
||
const [{ value, error }, setValue] = useFormField<string>({ | ||
key, | ||
initialValue: defaultValue as string, | ||
validate: validateCallback, | ||
dependsOn: deps, | ||
}); | ||
|
||
const setPickerValueCallback = useCallback( | ||
(date: Moment | null) => { | ||
const formattedDate = date ? date.format(FMT) : ''; | ||
setValue(formattedDate); | ||
|
||
if (onChange) { | ||
const fakeEvent = { | ||
target: { value: formattedDate, name: name }, | ||
currentTarget: { value: formattedDate, name: name }, | ||
preventDefault: () => {}, | ||
stopPropagation: () => {}, | ||
} as unknown as React.ChangeEvent<HTMLInputElement>; | ||
onChange(fakeEvent); | ||
} | ||
}, | ||
[setValue, onChange], | ||
); | ||
|
||
React.useEffect(() => { | ||
if (disabled) { | ||
setValue(defaultValue as string); | ||
} | ||
}, [disabled]); | ||
|
||
return ( | ||
<NsLabelInput nameHtml={key} label={label as string}> | ||
<LocalizationProvider dateAdapter={AdapterMoment} adapterLocale={i18n.language}> | ||
<TimePicker | ||
format={format} | ||
ampm={ampm} | ||
value={moment(value, FMT)} | ||
onChange={setPickerValueCallback} | ||
disabled={disabled} | ||
slotProps={{ | ||
textField: { error: !!error, fullWidth: true, ...rest }, | ||
}} | ||
localeText={localeText} | ||
/> | ||
</LocalizationProvider> | ||
</NsLabelInput> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,89 +1,103 @@ | ||
import React, { useState } from 'react'; | ||
import { Card, CardContent, Typography } from '@mui/material'; | ||
import { Card, CardContent, Typography, SxProps, Theme } from '@mui/material'; | ||
import { styled } from '@mui/material/styles'; | ||
import { Box } from '@mui/system'; | ||
import { useTranslation } from 'react-i18next'; | ||
import CloseIcon from '@mui/icons-material/Close'; | ||
import ArrowLeftIcon from '@mui/icons-material/ArrowLeft'; | ||
import { PanelProps } from 'src/util/types'; | ||
|
||
export interface PanelProps { | ||
type?: 'primary' | 'secondary'; | ||
title: string; | ||
children: React.ReactNode; | ||
menu?: boolean; | ||
isOpen?: boolean; | ||
handleOpen: () => any; | ||
} | ||
const StyledCard = styled(Card)<any>(({ theme, type }) => ({ | ||
const StyledCard = styled(Card)<any>(({ theme }) => ({ | ||
border: '1px solid', | ||
borderColor: '#b1b4b6', | ||
margin: '0px !important', | ||
boxSizing: 'border-box', | ||
boxShadow: 'none', | ||
borderRadius: '0px', | ||
height: '100%', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
})); | ||
|
||
export const NsPanel = ({ | ||
menu = false, | ||
type = 'primary', | ||
title, | ||
subtitle, | ||
children, | ||
handleOpen: onClose, | ||
handleOpen, | ||
button, | ||
isOpen = true, | ||
...rest | ||
}: PanelProps) => { | ||
const { t } = useTranslation(); | ||
const [isHovered, setIsHovered] = useState(false); | ||
|
||
return ( | ||
<StyledCard type={type}> | ||
<Box display="flex" flexDirection="row" sx={{ height: '100%' }}> | ||
{menu && ( | ||
<Box | ||
sx={{ | ||
padding: '10px', | ||
flexGrow: 1, | ||
flexDirection: 'column', | ||
background: isHovered ? '#9c9fa1' : '#b1b4b6', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
cursor: 'pointer', | ||
maxWidth: '40px', | ||
}} | ||
onMouseEnter={() => setIsHovered(true)} | ||
onMouseLeave={() => setIsHovered(false)} | ||
onClick={onClose} | ||
> | ||
<StyledCard type={type} {...rest}> | ||
{menu && ( | ||
<Box | ||
sx={{ | ||
// padding: '10px', | ||
flexGrow: 1, | ||
flexDirection: 'column', | ||
background: isHovered ? '#9c9fa1' : '#b1b4b6', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
cursor: 'pointer', | ||
maxWidth: '40px', | ||
minWidth: '40px', | ||
}} | ||
onMouseEnter={() => setIsHovered(true)} | ||
onMouseLeave={() => setIsHovered(false)} | ||
onClick={handleOpen} | ||
> | ||
<Typography fontWeight={isHovered ? 'bold' : 'normal'}> | ||
{isOpen ? ( | ||
<> | ||
<CloseIcon fontWeight={isHovered ? 'bold' : 'normal'} /> | ||
<Typography fontWeight={isHovered ? 'bold' : 'normal'}>{t('panel.close')}</Typography> | ||
{typeof button !== 'boolean' ? ( | ||
<CloseIcon fontWeight={isHovered ? 'bold' : 'normal'} /> | ||
) : ( | ||
button | ||
)} | ||
</> | ||
) : ( | ||
<> | ||
<ArrowLeftIcon fontWeight={isHovered ? 'bold' : 'normal'} /> | ||
<Typography fontWeight={isHovered ? 'bold' : 'normal'}>{t('panel.open')}</Typography> | ||
{typeof button !== 'boolean' ? ( | ||
<ArrowLeftIcon fontWeight={isHovered ? 'bold' : 'normal'} /> | ||
) : ( | ||
button | ||
)} | ||
</> | ||
)} | ||
</Box> | ||
)} | ||
{isOpen && ( | ||
<Card | ||
sx={{ | ||
borderRadius: '0px', | ||
backgroundColor: type === 'secondary' ? '#2e5a6019' : undefined, | ||
}} | ||
> | ||
<CardContent> | ||
</Typography> | ||
</Box> | ||
)} | ||
{isOpen && ( | ||
<Card | ||
sx={{ | ||
borderRadius: '0px', | ||
margin: 0, | ||
backgroundColor: type === 'secondary' ? '#2e5a6019' : undefined, | ||
}} | ||
> | ||
<CardContent> | ||
{title && ( | ||
<Typography variant={'h3'} fontWeight={900} gutterBottom> | ||
{title} | ||
</Typography> | ||
|
||
)} | ||
{subtitle && ( | ||
<Typography variant={'h4'} fontWeight={400}> | ||
{subtitle} | ||
</Typography> | ||
)} | ||
<Box component="div" mt={title || subtitle ? 3 : 0}> | ||
{children} | ||
</CardContent> | ||
</Card> | ||
)} | ||
</Box> | ||
</Box> | ||
</CardContent> | ||
</Card> | ||
)} | ||
</StyledCard> | ||
); | ||
}; |
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
Oops, something went wrong.